Skip to content

Commit

Permalink
Merge pull request #37 from opxdelwin/dev
Browse files Browse the repository at this point in the history
merge for version 1.1.0+6
  • Loading branch information
opxdelwin authored Jan 13, 2024
2 parents 1fbac9b + e78732e commit 9dba51e
Show file tree
Hide file tree
Showing 12 changed files with 494 additions and 56 deletions.
61 changes: 57 additions & 4 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,16 +21,17 @@ We appreciate your interest in contributing to Plan Sync and helping to make it
## JSON Template
Copy and modify this template for your contribution
<details>
<summary>Template</summary>
<summary>Normal Class Template</summary>

```
```json
{
"meta": {
"section": "b17", //replace with your section here
"type": "norm-class", // default value, need not to change
"revision": "Revision 1.0", // default value, need not to change
"revision": "Revision 1.0", // default value, need not to change
"effective-date": "Aug 31, 2023",
"contributor": "Legendary Contributor", //replace with your name here
"contributor": "PlanSync Wizard", //replace with your name here
"isTimetableUpdating": false, // default value, need not to change

// add day-wise classroom here
"room": {
Expand Down Expand Up @@ -88,6 +89,58 @@ Copy and modify this template for your contribution

</details>

<details>
<summary>Electives Template</summary>

```json
{
"meta": {
"type": "electives",
"revision": "Revision 1.0",
"effective-date": "Aug 31, 2023",
"name": "Electives Configuration for B14 - B23",
"contributor": "PlanSync Wizard", //replace with your name here
"isTimetableUpdating": false
},
"data": {
"monday": {
"***": "***"
},
"tuesday": {
"CIE6": "Room 304",
"CIE7": "Room 305",
"CIE8": "Room 301",
"CIE9": "Room 306",
"CIE10": "Room 307",
"SST3": "Room 401",
"SOE5": "Room 302",
"SOE6": "Room 402",
"SOE7": "Room 404",
"SOE8": "Room 303"
},
"wednesday": {
"***": "***"
},
"thursday": {
"CIE6": "Room 404",
"CIE7": "Room 302",
"CIE8": "Room 306",
"CIE9": "Room 303",
"CIE10": "Room 304",
"SST3": "Room 307",
"SOE5": "Room 401",
"SOE6": "Room 305",
"SOE7": "Room 402",
"SOE8": "Room 403"
},
"friday": {
"***": "***"
}
}
}
```
</details>

## Guidelines for submission

- Please use the provided JSON template to input your class schedule details.
Expand Down
35 changes: 35 additions & 0 deletions client-app/lib/controllers/app_preferences_controller.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import 'package:get/get.dart';
import 'package:shared_preferences/shared_preferences.dart';

class AppPreferencesController extends GetxController {
late SharedPreferences perfs;

@override
Future<void> onInit() async {
perfs = await SharedPreferences.getInstance();
super.onInit();
}

String? getPrimarySectionPreference() => perfs.getString('primary-section');

Future<bool> savePrimarySectionPreference(String data) async =>
await perfs.setString('primary-section', data);

String? getPrimarySemesterPreference() => perfs.getString('primary-semester');

Future<bool> savePrimarySemesterPreference(String data) async =>
await perfs.setString('primary-semester', data);

String? getPrimaryYearPreference() => perfs.getString('primary-year');

Future<bool> savePrimaryYearPreference(String data) async =>
await perfs.setString('primary-year', data);

// In app tutorial
/// Returns `true` if tutorial has already been completed.
bool? getTutorialStatus() => perfs.getBool('app-tutorial-status');

/// Save tutorial status as `true` if completed.
Future<bool> saveTutorialStatus(bool status) async =>
await perfs.setBool('app-tutorial-status', status);
}
124 changes: 124 additions & 0 deletions client-app/lib/controllers/app_tour_controller.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,124 @@
import 'dart:ui';
import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:plan_sync/controllers/app_preferences_controller.dart';
import 'package:plan_sync/util/logger.dart';
import 'package:plan_sync/widgets/bottom-sheets/bottom_sheets_wrapper.dart';
import 'package:plan_sync/widgets/tutorials/app_target_focus.dart';
import 'package:tutorial_coach_mark/tutorial_coach_mark.dart';

class AppTourController extends GetxController {
late AppPreferencesController appPreferencesController;

late GlobalKey _schedulePreferencesButtonKey;
GlobalKey get schedulePreferencesButtonKey => _schedulePreferencesButtonKey;

late GlobalKey _sectionBarKey;
GlobalKey get sectionBarKey => _sectionBarKey;

late GlobalKey _savePreferenceSwitchKey;
GlobalKey get savePreferenceSwitchKey => _savePreferenceSwitchKey;

@override
void onInit() {
appPreferencesController = Get.find();
super.onInit();
_schedulePreferencesButtonKey = GlobalKey();
_sectionBarKey = GlobalKey();
_savePreferenceSwitchKey = GlobalKey();
}

Future<void> startAppTour(BuildContext context) async {
final colorScheme = Theme.of(context).colorScheme;

if (await tourAlreadyCompleted()) {
return;
} else if (!context.mounted) {
return;
}

List<TargetFocus> targets = getTutorialTargets(context);

TutorialCoachMark tutorial = TutorialCoachMark(
targets: targets,
colorShadow: colorScheme.onBackground,
textSkip: "SKIP",
textStyleSkip: TextStyle(color: colorScheme.background),
paddingFocus: 0,
focusAnimationDuration: const Duration(milliseconds: 500),
unFocusAnimationDuration: const Duration(milliseconds: 500),
pulseAnimationDuration: const Duration(milliseconds: 750),
showSkipInLastTarget: true,
imageFilter: ImageFilter.blur(sigmaX: 4, sigmaY: 4),
initialFocus: 0,
useSafeArea: true,
onFinish: onTourComplete,
onSkip: () {
onTourComplete();
return true;
},
onClickTargetWithTapPosition: onClickHandler,
);

if (!context.mounted) {
return;
}

tutorial.show(context: context, rootOverlay: true);
}

Future<void> onClickHandler(
TargetFocus target, TapDownDetails tapDownDetails) async {
if (target.identify == schedulePreferencesButtonKey.hashCode) {
Logger.i('key match with schedule button');

await Future.delayed(const Duration(milliseconds: 250));
BottomSheets.changeSectionPreference(
context: schedulePreferencesButtonKey.currentContext!,
);
}
return;
}

Future<bool> tourAlreadyCompleted() async {
return appPreferencesController.getTutorialStatus() ?? false;
}

List<TargetFocus> getTutorialTargets(BuildContext context) {
List<TargetFocus> targets = [];
final colorScheme = Theme.of(context).colorScheme;

targets.add(
AppTargetFocus.schedulePreferencesButton(
colorScheme: colorScheme,
buttonKey: schedulePreferencesButtonKey,
),
);
targets.add(
AppTargetFocus.savePreferenceSwitch(
colorScheme: colorScheme,
buttonKey: savePreferenceSwitchKey,
),
);
targets.add(
AppTargetFocus.sectionBarButton(
colorScheme: colorScheme,
buttonKey: sectionBarKey,
),
);

return targets;
}

Future<void> onTourComplete() async {
final res = await appPreferencesController.saveTutorialStatus(true);
if (res != true) {
final err = {
'origin': 'AppTourController.onTourComplete',
'message': 'error saving to shared preferences'
};
return Future.error(err);
}
return;
}
}
65 changes: 45 additions & 20 deletions client-app/lib/controllers/filter_controller.dart
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import 'package:get/get.dart';
import 'package:plan_sync/controllers/app_preferences_controller.dart';
import 'package:plan_sync/controllers/git_service.dart';
import 'package:plan_sync/util/logger.dart';
import 'package:plan_sync/util/snackbar.dart';
import 'package:shared_preferences/shared_preferences.dart';
import 'package:collection/collection.dart';

class FilterController extends GetxController {
Expand Down Expand Up @@ -72,13 +72,13 @@ class FilterController extends GetxController {
}

late GitService service;
late SharedPreferences preferences;
late AppPreferencesController preferences;

@override
onInit() async {
super.onInit();
preferences = await SharedPreferences.getInstance();
service = Get.find();
preferences = Get.find();
super.onInit();
}

Future<String> getShortCode() async {
Expand All @@ -97,9 +97,7 @@ class FilterController extends GetxController {
}

/// returns primary section from shared-preferences
String? get primarySection {
return preferences.getString('primary-section');
}
String? get primarySection => preferences.getPrimarySectionPreference();

/// saves the section code into shared-preferences
Future<void> storePrimarySection() async {
Expand All @@ -112,15 +110,26 @@ class FilterController extends GetxController {
return;
}

await preferences.setString('primary-section', activeSectionCode!);
final res =
await preferences.savePrimarySectionPreference(activeSectionCode!);

if (res == false) {
Logger.i("Could not save preference");
CustomSnackbar.error(
'Error',
'Primary Section wasn\'t saved. Try again',
);
return;
}

Logger.i("set ${activeSectionCode!} as primary");
update();
}

/// sets the section code while runtime
Future<void> setPrimarySection() async {
activeSection = null;
final String? primarySection = preferences.getString('primary-section');
final String? primarySection = preferences.getPrimarySectionPreference();
Logger.i("primary section: $primarySection");

if (primarySection != null &&
Expand All @@ -131,9 +140,7 @@ class FilterController extends GetxController {
}

/// returns primary semester from shared-preferences
String? get primarySemester {
return preferences.getString('primary-semester');
}
String? get primarySemester => preferences.getPrimarySemesterPreference();

/// saves the semester code into shared-preferences
Future<void> storePrimarySemester() async {
Expand All @@ -145,15 +152,26 @@ class FilterController extends GetxController {
Logger.i("select a semester to be set as primary.");
return;
}
await preferences.setString('primary-semester', activeSemester!);
final res =
await preferences.savePrimarySemesterPreference(activeSemester!);

if (res == false) {
Logger.i("Could not save preference");
CustomSnackbar.error(
'Error',
'Primary Semester wasn\'t saved. Try again',
);
return;
}

Logger.i("set ${activeSemester!} as primary semester");
update();
}

/// sets the semester code while runtime
Future<void> setPrimarySemester() async {
// activeSemester = null;
final String? primarySemester = preferences.getString('primary-semester');
final String? primarySemester = preferences.getPrimarySemesterPreference();
Logger.i("primary semester: $primarySemester");

if (service.semesters?.contains(primarySemester) != false &&
Expand All @@ -163,9 +181,7 @@ class FilterController extends GetxController {
}

/// returns primary semester from shared-preferences
String? get primaryYear {
return preferences.getString('primary-year');
}
String? get primaryYear => preferences.getPrimaryYearPreference();

/// saves the semester code into shared-preferences
Future<void> storePrimaryYear() async {
Expand All @@ -177,18 +193,27 @@ class FilterController extends GetxController {
Logger.i("select a year to be set as primary.");
return;
}
await preferences.setString(
'primary-year',
final res = await preferences.savePrimaryYearPreference(
service.selectedYear!.toString(),
);

if (res == false) {
Logger.i("Could not save preference");
CustomSnackbar.error(
'Error',
'Primary Year wasn\'t saved. Try again',
);
return;
}

Logger.i("set ${service.selectedYear!} as primary year");
update();
}

/// sets the semester code while runtime
Future<void> setPrimaryYear() async {
// activeSemester = null;
final String? primaryYear = preferences.getString('primary-year');
final String? primaryYear = preferences.getPrimaryYearPreference();
Logger.i("primary year: $primaryYear");

if (service.years?.contains(primaryYear) != false && primaryYear != null) {
Expand Down
Loading

0 comments on commit 9dba51e

Please sign in to comment.