Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

🔀 Fixed the ui in multiple areas #367

Merged
merged 6 commits into from
Oct 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
50 changes: 48 additions & 2 deletions beakpeek/lib/Controller/DB/life_list_provider.dart
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import 'package:beakpeek/Model/UserProfile/user_model.dart';
import 'package:beakpeek/config_azure.dart';
import 'package:http/http.dart';
import 'package:localstorage/localstorage.dart';
import 'package:path/path.dart';
import 'package:sqflite/sqflite.dart';

Expand Down Expand Up @@ -166,7 +167,26 @@

Future<void> insertBird(int birdId) async {
final bird = await getBirdInByID(birdId);
print(bird);
switch (bird.commonGroup.toLowerCase()) {
case 'weaver':
updateProgress(bird.commonGroup, 'Weaver Believer');

Check warning on line 172 in beakpeek/lib/Controller/DB/life_list_provider.dart

View check run for this annotation

Codecov / codecov/patch

beakpeek/lib/Controller/DB/life_list_provider.dart#L170-L172

Added lines #L170 - L172 were not covered by tests
break;
case 'duck':
updateProgress(bird.commonGroup, 'Duck Hunter');

Check warning on line 175 in beakpeek/lib/Controller/DB/life_list_provider.dart

View check run for this annotation

Codecov / codecov/patch

beakpeek/lib/Controller/DB/life_list_provider.dart#L174-L175

Added lines #L174 - L175 were not covered by tests
break;
case 'eagle':
updateProgress(bird.commonGroup, 'USA');

Check warning on line 178 in beakpeek/lib/Controller/DB/life_list_provider.dart

View check run for this annotation

Codecov / codecov/patch

beakpeek/lib/Controller/DB/life_list_provider.dart#L177-L178

Added lines #L177 - L178 were not covered by tests
break;
case 'kingfisher':
updateProgress(bird.commonGroup, 'Fisherman');

Check warning on line 181 in beakpeek/lib/Controller/DB/life_list_provider.dart

View check run for this annotation

Codecov / codecov/patch

beakpeek/lib/Controller/DB/life_list_provider.dart#L180-L181

Added lines #L180 - L181 were not covered by tests
break;
case 'hawk':
updateProgress(bird.commonGroup, 'Hawk Spotter');

Check warning on line 184 in beakpeek/lib/Controller/DB/life_list_provider.dart

View check run for this annotation

Codecov / codecov/patch

beakpeek/lib/Controller/DB/life_list_provider.dart#L183-L184

Added lines #L183 - L184 were not covered by tests
break;
case 'heron':
updateProgress(bird.commonGroup, 'Heron Horror');

Check warning on line 187 in beakpeek/lib/Controller/DB/life_list_provider.dart

View check run for this annotation

Codecov / codecov/patch

beakpeek/lib/Controller/DB/life_list_provider.dart#L186-L187

Added lines #L186 - L187 were not covered by tests
break;
}
//await updateLifeListAchievments(bird.commonGroup, birdId);
final db = await instance.database;
if (!await isDuplicate(bird)) {
Expand Down Expand Up @@ -315,10 +335,36 @@
whereArgs: [commonGroup]),
) ??
0;
print('count $count');
return count;
}

Future<void> updateProgress(String commonGroup, String achievmentName) async {
final int countBird = await lifeBirdCount(commonGroup);
final int totalBird = await allBirdCount(commonGroup);
double progress = countBird / totalBird;
progress = progress < 1 ? progress : 1;
localStorage.setItem(achievmentName, progress.toString());
updateProvinces();

Check warning on line 347 in beakpeek/lib/Controller/DB/life_list_provider.dart

View check run for this annotation

Codecov / codecov/patch

beakpeek/lib/Controller/DB/life_list_provider.dart#L341-L347

Added lines #L341 - L347 were not covered by tests
}

Future<void> updateProvinces() async {
final List<String> achivementNamesProvinces = [

Check warning on line 351 in beakpeek/lib/Controller/DB/life_list_provider.dart

View check run for this annotation

Codecov / codecov/patch

beakpeek/lib/Controller/DB/life_list_provider.dart#L350-L351

Added lines #L350 - L351 were not covered by tests
'Risk it for the Biscuits',
'Gauteng Explorer',
'Watch The Waves',
'Limpopo Hoopoe',
'Mpumalanga Adventurer',
'Diamond Hunter',
'Directionally challenged',
'Western Cape Wanderer',
'Freesest Alive'
];
final List<double> progress = await precentLifeListBirds();
for (int i = 0; i < achivementNamesProvinces.length; i++) {
localStorage.setItem(achivementNamesProvinces[i], progress.toString());

Check warning on line 364 in beakpeek/lib/Controller/DB/life_list_provider.dart

View check run for this annotation

Codecov / codecov/patch

beakpeek/lib/Controller/DB/life_list_provider.dart#L362-L364

Added lines #L362 - L364 were not covered by tests
}
}

Future<int> lifeBirdCount(String commonGroup) async {
final db = await instance.database;
final int count = Sqflite.firstIntValue(
Expand Down
74 changes: 68 additions & 6 deletions beakpeek/lib/Model/Globals/globals.dart
Original file line number Diff line number Diff line change
Expand Up @@ -6,27 +6,39 @@
import 'package:beakpeek/Controller/Home/search.dart';
import 'package:beakpeek/Controller/Main/color_palette_functions.dart';
import 'package:beakpeek/Model/BirdInfo/bird.dart';
import 'package:beakpeek/Model/UserProfile/achievment_list.dart';
import 'package:beakpeek/View/Home/home.dart';
import 'package:beakpeek/View/Map/bird_sheet.dart';
import 'package:geolocator/geolocator.dart';
import 'package:localstorage/localstorage.dart';
import 'package:http/http.dart' as http;

Globals global = Globals();

class Globals {
final LifeListProvider lifeList = LifeListProvider.instance;
late List<Bird> birdList = [];
late List<Bird> allBirdsList = [];
String? cachedPentadId;
late Future<String> cachedPentadId;
List<Bird>? cachedBirds;
ColorPalette palette = greenRedPalette;

void init() {
lifeList.fetchLifeList().then((result) {
birdList = result;
void init() async {

Check warning on line 26 in beakpeek/lib/Model/Globals/globals.dart

View check run for this annotation

Codecov / codecov/patch

beakpeek/lib/Model/Globals/globals.dart#L26

Added line #L26 was not covered by tests
// Fetch cached Pentad ID and birds if available

cachedPentadId = getPentadId();

Check warning on line 29 in beakpeek/lib/Model/Globals/globals.dart

View check run for this annotation

Codecov / codecov/patch

beakpeek/lib/Model/Globals/globals.dart#L29

Added line #L29 was not covered by tests

// Fetch birds using the cached or newly fetched Pentad ID
cachedPentadId.then((pentadId) {
fetchBirds(pentadId, http.Client());

Check warning on line 33 in beakpeek/lib/Model/Globals/globals.dart

View check run for this annotation

Codecov / codecov/patch

beakpeek/lib/Model/Globals/globals.dart#L32-L33

Added lines #L32 - L33 were not covered by tests
});

// Load bird data from assets and insert into lifeList
listBirdFromAssets().then((result) {
allBirdsList = result;
lifeList.initialInsert(result);
lifeList.initialProvInsert(result);
});
//lifeList.deleteDatabaseFile();
}

Future<List<Bird>> updateLife() async {
Expand All @@ -37,5 +49,55 @@
return allBirdsList.firstWhere((bird) => bird.id == id);
}

late File image;
void getAchievments() {
getAchivementList().then((result) {
for (int i = 0; i < result.achievements.length; i++) {
if (localStorage.getItem(result.achievements[i].name) != null) {

Check warning on line 55 in beakpeek/lib/Model/Globals/globals.dart

View check run for this annotation

Codecov / codecov/patch

beakpeek/lib/Model/Globals/globals.dart#L52-L55

Added lines #L52 - L55 were not covered by tests
final double localProgress =
double.parse(localStorage.getItem(result.achievements[i].name)!);

Check warning on line 57 in beakpeek/lib/Model/Globals/globals.dart

View check run for this annotation

Codecov / codecov/patch

beakpeek/lib/Model/Globals/globals.dart#L57

Added line #L57 was not covered by tests

if (result.achievements[i].progress > localProgress) {
localStorage.setItem(result.achievements[i].name,
result.achievements[i].progress.toString());

Check warning on line 61 in beakpeek/lib/Model/Globals/globals.dart

View check run for this annotation

Codecov / codecov/patch

beakpeek/lib/Model/Globals/globals.dart#L59-L61

Added lines #L59 - L61 were not covered by tests
}
} else {
localStorage.setItem(result.achievements[i].name,
result.achievements[i].progress.toString());

Check warning on line 65 in beakpeek/lib/Model/Globals/globals.dart

View check run for this annotation

Codecov / codecov/patch

beakpeek/lib/Model/Globals/globals.dart#L64-L65

Added lines #L64 - L65 were not covered by tests
}
}
});
}

Future<String> getPentadId() async {
final Position position = await Geolocator.getCurrentPosition();
final latitude = position.latitude;
final longitude = position.longitude;

Check warning on line 74 in beakpeek/lib/Model/Globals/globals.dart

View check run for this annotation

Codecov / codecov/patch

beakpeek/lib/Model/Globals/globals.dart#L71-L74

Added lines #L71 - L74 were not covered by tests

// Check if the location is within South Africa's boundaries
if (latitude < -35.0 ||
latitude > -22.0 ||
longitude < 16.0 ||
longitude > 33.0) {
throw Exception('Location is outside South Africa.');

Check warning on line 81 in beakpeek/lib/Model/Globals/globals.dart

View check run for this annotation

Codecov / codecov/patch

beakpeek/lib/Model/Globals/globals.dart#L77-L81

Added lines #L77 - L81 were not covered by tests
}

final latDegrees = latitude.ceil();
final lonDegrees = longitude.floor();

Check warning on line 85 in beakpeek/lib/Model/Globals/globals.dart

View check run for this annotation

Codecov / codecov/patch

beakpeek/lib/Model/Globals/globals.dart#L84-L85

Added lines #L84 - L85 were not covered by tests

final latDecimal = (latitude - latDegrees).abs();
final lonDecimal = longitude - lonDegrees;

Check warning on line 88 in beakpeek/lib/Model/Globals/globals.dart

View check run for this annotation

Codecov / codecov/patch

beakpeek/lib/Model/Globals/globals.dart#L87-L88

Added lines #L87 - L88 were not covered by tests

// Convert decimal part to minutes
final latMinutes = ((latDecimal * 60) - (latDecimal * 60) % 5).toInt();
final lonMinutes = ((lonDecimal * 60) - (lonDecimal * 60) % 5).toInt();

Check warning on line 92 in beakpeek/lib/Model/Globals/globals.dart

View check run for this annotation

Codecov / codecov/patch

beakpeek/lib/Model/Globals/globals.dart#L91-L92

Added lines #L91 - L92 were not covered by tests

// Format the result
final formattedLat =
'${latDegrees.abs()}${latMinutes.toString().padLeft(2, "0")}';

Check warning on line 96 in beakpeek/lib/Model/Globals/globals.dart

View check run for this annotation

Codecov / codecov/patch

beakpeek/lib/Model/Globals/globals.dart#L96

Added line #L96 was not covered by tests
final formattedLon =
'${lonDegrees.abs()}${lonMinutes.toString().padLeft(2, "0")}';

Check warning on line 98 in beakpeek/lib/Model/Globals/globals.dart

View check run for this annotation

Codecov / codecov/patch

beakpeek/lib/Model/Globals/globals.dart#L98

Added line #L98 was not covered by tests

// Combine with underscore
return '${formattedLat}_${formattedLon}';

Check warning on line 101 in beakpeek/lib/Model/Globals/globals.dart

View check run for this annotation

Codecov / codecov/patch

beakpeek/lib/Model/Globals/globals.dart#L101

Added line #L101 was not covered by tests
}
}
4 changes: 1 addition & 3 deletions beakpeek/lib/Model/UserProfile/achievment_list.dart
Original file line number Diff line number Diff line change
Expand Up @@ -138,9 +138,7 @@
return AchievementList.fromJson(userString);
}

Future<void> updateLifeListAchievments(String commonGroup) async {

}
Future<void> updateLifeListAchievments(String commonGroup) async {}

Check warning on line 141 in beakpeek/lib/Model/UserProfile/achievment_list.dart

View check run for this annotation

Codecov / codecov/patch

beakpeek/lib/Model/UserProfile/achievment_list.dart#L141

Added line #L141 was not covered by tests

Future<void> updateProvinces(int id) async {
final List<String> achivementNames = [
Expand Down
4 changes: 3 additions & 1 deletion beakpeek/lib/Model/UserProfile/user_model.dart
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@
final String localLife = await lifelist.fetchUserLifelistString();
if (localLife.length < user.lifelist.length) {
final List<dynamic> valueList = json.decode(user.lifelist);
// ignore: avoid_function_literals_in_foreach_calls
valueList.forEach((element) {
final int birdId = element['id'];
lifelist.insertBird(birdId);
Expand Down Expand Up @@ -135,8 +136,9 @@
Future<void> updateOnline(
{LifeListProvider? lifelist, bool logout = false}) async {
lifelist = LifeListProvider.instance;
// ignore: unnecessary_null_comparison
if (lifelist != null) {
String list = await lifelist.updateUserLifelist();
final String list = await lifelist.updateUserLifelist();

Check warning on line 141 in beakpeek/lib/Model/UserProfile/user_model.dart

View check run for this annotation

Codecov / codecov/patch

beakpeek/lib/Model/UserProfile/user_model.dart#L141

Added line #L141 was not covered by tests
user.set('lifelist', list);
}
final response = await http.post(Uri.parse('$userApiUrl/User/UpdateProfile'),
Expand Down
6 changes: 6 additions & 0 deletions beakpeek/lib/Styles/colors.dart
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,12 @@
: primaryColorLight;
}

static Color secondaryButtonColor(BuildContext context) {
return Theme.of(context).brightness == Brightness.dark

Check warning on line 54 in beakpeek/lib/Styles/colors.dart

View check run for this annotation

Codecov / codecov/patch

beakpeek/lib/Styles/colors.dart#L53-L54

Added lines #L53 - L54 were not covered by tests
? popupColorDark
: primaryColorLight;
}

// Get secondary color
static Color secondaryColor(BuildContext context) {
return Theme.of(context).brightness == Brightness.dark
Expand Down
9 changes: 5 additions & 4 deletions beakpeek/lib/View/Achievements/achievements_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ class AchievementsPageState extends State<AchievementsPage> {
actions: const [
HelpIcon(
content:
'Follow the instructions to get the achievement! \n\nThis will earn you some profile experience points and helps you unlock ultimate bragging rights.'),
'''Follow the instructions to get the achievement! \n\nThis will earn you some profile experience points and helps you unlock ultimate bragging rights.'''),
SizedBox(width: 14.0)
],
),
Expand All @@ -61,7 +61,10 @@ class AchievementsPageState extends State<AchievementsPage> {
future: _achievementlist,
builder: (context, snapshot) {
if (snapshot.connectionState == ConnectionState.waiting) {
return const Center(child: CircularProgressIndicator());
return Center(
child: CircularProgressIndicator(
color: AppColors.iconColor(context),
));
} else if (snapshot.hasError) {
return Center(
child: Text('Error loading achievements: ${snapshot.error}'),
Expand Down Expand Up @@ -130,8 +133,6 @@ class AchievementTile extends StatelessWidget {

@override
Widget build(BuildContext context) {
print(achievement.name);
print(achievement.progress);
return Card(
color: AppColors.popupColor(context),
shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(10)),
Expand Down
2 changes: 1 addition & 1 deletion beakpeek/lib/View/Home/home.dart
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@
return global.cachedPentadId!;
}

global.cachedPentadId = await getPentadId(); // Cache pentadId
global.cachedPentadId = getPentadId(); // Cache pentadId

Check warning on line 58 in beakpeek/lib/View/Home/home.dart

View check run for this annotation

Codecov / codecov/patch

beakpeek/lib/View/Home/home.dart#L58

Added line #L58 was not covered by tests
return global.cachedPentadId!;
}

Expand Down
5 changes: 4 additions & 1 deletion beakpeek/lib/View/Map/bird_sheet.dart
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,10 @@
future: _birdList,
builder: (context, snapshot) {
if (snapshot.connectionState == ConnectionState.waiting) {
return const Center(child: CircularProgressIndicator());
return Center(
child: CircularProgressIndicator(
color: AppColors.iconColor(context),

Check warning on line 215 in beakpeek/lib/View/Map/bird_sheet.dart

View check run for this annotation

Codecov / codecov/patch

beakpeek/lib/View/Map/bird_sheet.dart#L213-L215

Added lines #L213 - L215 were not covered by tests
));
} else if (snapshot.hasError) {
return const Center(child: Text('No birds found.'));
}
Expand Down
Loading
Loading