Skip to content

Commit

Permalink
Merge branch 'development' into dev/feat/final_ui_fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
ChuufMaster authored Sep 30, 2024
2 parents 81fb75a + a1d9b60 commit 5eb6ce6
Show file tree
Hide file tree
Showing 9 changed files with 261 additions and 154 deletions.
65 changes: 0 additions & 65 deletions .github/workflows/main_beakpeekbirdapi.yml

This file was deleted.

Binary file added beakpeek/assets/Legal/combinepdf.pdf
Binary file not shown.
40 changes: 40 additions & 0 deletions beakpeek/lib/Controller/DB/life_list_provider.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import 'dart:convert';

import 'package:beakpeek/Model/BirdInfo/bird.dart';
import 'package:beakpeek/Model/BirdInfo/province_data.dart';
import 'package:beakpeek/Model/UserProfile/achievment_list.dart';
import 'package:beakpeek/Model/UserProfile/user_model.dart';
import 'package:beakpeek/config_azure.dart';
import 'package:http/http.dart';
Expand Down Expand Up @@ -166,6 +167,8 @@ class LifeListProvider {

Future<void> insertBird(int birdId) async {
final bird = await getBirdInByID(birdId);
print(bird);
await updateLifeListAchievments(bird.commonGroup, birdId);
final db = await instance.database;
if (!await isDuplicate(bird)) {
await db
Expand Down Expand Up @@ -196,6 +199,19 @@ class LifeListProvider {
return encodedString;
}

Future<String> fetchUserLifelistString() async {
final db = await instance.database;
final List<Map<String, Object?>> birdMap = await db.query(
'birds',
orderBy: 'commonGroup DESC',
columns: ['id'],
);
final String encodedString = jsonEncode(birdMap);
// user.lifelist = encodedString;
// storeUserLocally(user);
return encodedString;
}

Future<List<Bird>> fetchLifeList() async {
final db = await instance.database;

Expand Down Expand Up @@ -291,6 +307,30 @@ class LifeListProvider {
return count;
}

Future<int> allBirdCount(String commonGroup) async {
final db = await instance.database;
final int count = Sqflite.firstIntValue(
await db.query('allBirds',
columns: ['COUNT(*)'],
where: 'commonGroup = ?',
whereArgs: [commonGroup]),
) ??
0;
return count;
}

Future<int> lifeBirdCount(String commonGroup) async {
final db = await instance.database;
final int count = Sqflite.firstIntValue(
await db.query('birds',
columns: ['COUNT(*)'],
where: 'commonGroup = ?',
whereArgs: [commonGroup]),
) ??
0;
return count;
}

Future<int> containsProvData() async {
final db = await instance.database;
final int count = Sqflite.firstIntValue(
Expand Down
87 changes: 87 additions & 0 deletions beakpeek/lib/Model/UserProfile/achievment_list.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import 'dart:convert';
import 'dart:io';
import 'package:beakpeek/Controller/DB/life_list_provider.dart';
import 'package:beakpeek/Model/UserProfile/user_achievment.dart';
import 'package:beakpeek/Model/UserProfile/user_model.dart';
import 'package:beakpeek/config_azure.dart';
Expand Down Expand Up @@ -97,3 +98,89 @@ AchievementList? getLocalAchievmentList() {
}
return AchievementList.fromJson(userString);
}

Future<void> updateLifeListAchievments(String commonGroup, int id) async {
switch (commonGroup.toLowerCase()) {
case 'weaver':
updateAchievmentProgressBirds('Weaver Believer', 'weaver');
updateProvinces(id);
break;
case 'duck':
updateAchievmentProgressBirds('Duck Hunter', 'duck');
updateProvinces(id);
break;
case 'egale':
updateAchievmentProgressBirds('USA', 'egale');
updateProvinces(id);
break;
case 'kingfisher':
updateAchievmentProgressBirds('Fisherman', 'kingfisher');
updateProvinces(id);
break;
case 'hawk':
updateAchievmentProgressBirds('Hawk Spotter', 'hawk');
updateProvinces(id);
break;
case 'heron':
updateAchievmentProgressBirds('Heron Horror', 'heron');

break;
}
updateProvinces(id);
}

Future<void> updateProvinces(int id) async {
final List<String> achivementNames = [
'Risk it for the Biscuits',
'Gauteng Explorer',
'Watch The Waves',
'Limpopo Hoopoe',
'Mpumalanga Adventurer',
'Dimond Hunter',
'Directionally challanged',
'Western Cape Wanderer',
'Freesest Alive'
];
final LifeListProvider lifeList = LifeListProvider.instance;
final List<double> progress = await lifeList.precentLifeListBirds();
for (int i = 0; i < achivementNames.length; i++) {
final Achievement? provMaster = getAchievementByName(achivementNames[i]);

if (provMaster != null) {
await updateUsersAchievement(provMaster.id, progress[i]);
//print('progress at $i ${progress[i]}');
for (UserAchievement ua in user.achievements) {
print(ua.toJson());
}
print(achivementNames[i]);
}
}
}

/// All checks for user progress should go here
Future<void> updateAchievmentProgressBirds(
String achievemntName, String commonGroup) async {
/// Quiz Master
final Achievement? birdMaster = getAchievementByName(achievemntName);
final LifeListProvider lifeList = LifeListProvider.instance;
if (birdMaster != null) {
final int countBird = await lifeList.lifeBirdCount(commonGroup);
final int totalBird = await lifeList.allBirdCount(commonGroup);
double progress = countBird / totalBird;
progress = progress < 1 ? progress : 1;
await updateUsersAchievement(birdMaster.id, progress);
for (UserAchievement ua in user.achievements) {
print(ua.toJson());
}
print(achievemntName);
}

for (UserAchievement userAchievement in user.achievements) {
achievementList
.achievements[achievementList.achievements
.indexWhere((element) => element.id == userAchievement.id)]
.progress = userAchievement.progress;
}

storeAchievementListLocally(achievementList);
}
19 changes: 11 additions & 8 deletions beakpeek/lib/Model/UserProfile/user_model.dart
Original file line number Diff line number Diff line change
Expand Up @@ -97,12 +97,12 @@ Future<UserModel> getOnlineUser() async {
return user;
}
user = UserModel.fromJson(response.body);

final String localLife = await lifelist.updateUserLifelist();
final String localLife = await lifelist.fetchUserLifelistString();
if (localLife.length < user.lifelist.length) {
final Map<String, int> valueMap = json.decode(localLife);
valueMap.forEach((key, value) {
lifelist.insertBird(value);
final List<dynamic> valueList = json.decode(user.lifelist);
valueList.forEach((element) {
final int birdId = element['id'];
lifelist.insertBird(birdId);
});
} else {
user.lifelist = localLife;
Expand Down Expand Up @@ -134,16 +134,19 @@ void deleteLocalUser() {

Future<void> updateOnline(
{LifeListProvider? lifelist, bool logout = false}) async {
// if (lifelist != null) {
// await lifelist.updateUserLifelist();
// }
lifelist = LifeListProvider.instance;
if (lifelist != null) {
String list = await lifelist.updateUserLifelist();
user.set('lifelist', list);
}
final response = await http.post(Uri.parse('$userApiUrl/User/UpdateProfile'),
headers: {
HttpHeaders.authorizationHeader: 'Bearer $accessToken',
HttpHeaders.contentTypeHeader: 'application/json'
},
body: user.toJson());

// print(json.decode(response.body));
if (logout) {
return;
}
Expand Down
2 changes: 0 additions & 2 deletions beakpeek/lib/View/Sightings/sightings.dart
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,6 @@ class _SightingsState extends State<Sightings> {
context.goNamed(
'birdInfo',
pathParameters: {
'group': bird.commonGroup,
'species': bird.commonSpecies,
'id': bird.id.toString(),
},
);
Expand Down
4 changes: 2 additions & 2 deletions beakpeek/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -118,10 +118,10 @@ flutter:
- assets/province_limpopo.kml
- assets/province_northerncape.kml
- assets/province_northwest.kml
# - assets/Legal/combinepdf.pdf
- assets/Legal/combinepdf.pdf
- assets/Legal/BeakPeekTermsOfUse.pdf
- assets/Legal/BeakPeekPrivacyPolicy.pdf
- assets/Legal/BeakPeekCookiePolicy.pdf
- assets/Legal/BeakPeekCookiePolicy.pdf
# - images/a_dot_ham.jpeg

# An image asset can refer to one or more resolution-specific "variants", see
Expand Down
Loading

0 comments on commit 5eb6ce6

Please sign in to comment.