From 9ac5594ecf107780bc89d63ac255fc3140588367 Mon Sep 17 00:00:00 2001 From: "H. Kamran" Date: Tue, 6 Feb 2024 23:16:44 -0800 Subject: [PATCH 1/6] Add migration system --- .vscode/settings.json | 5 +++++ MIGRATIONS.md | 10 +++++++++ lib/constants.dart | 3 +++ lib/screens/home.dart | 48 ++++++++++++++++++++++++++++++++++++++++--- 4 files changed, 63 insertions(+), 3 deletions(-) create mode 100644 .vscode/settings.json create mode 100644 MIGRATIONS.md diff --git a/.vscode/settings.json b/.vscode/settings.json new file mode 100644 index 0000000..74a2a63 --- /dev/null +++ b/.vscode/settings.json @@ -0,0 +1,5 @@ +{ + "languageToolLinter.languageTool.ignoredWordsInWorkspace": [ + "hijri" + ] +} \ No newline at end of file diff --git a/MIGRATIONS.md b/MIGRATIONS.md new file mode 100644 index 0000000..a471725 --- /dev/null +++ b/MIGRATIONS.md @@ -0,0 +1,10 @@ +# Migrations + +This document contains a list of migrations that were undertaken by Ramadan Taskminder +to update the data structure. The migration index prior to version 1.2.0 was `-1`. +The following list is in descending order. + +- `0`: Add the hijri date to the date field of Qur'an entries to support hijri date + offsets + + `[ "date", [ ... ] ]` => `[ [ "gregorian", "hijri" ], [ ... ] ]` diff --git a/lib/constants.dart b/lib/constants.dart index e11f0e8..cdcddf6 100644 --- a/lib/constants.dart +++ b/lib/constants.dart @@ -1,5 +1,8 @@ const appName = "Ramadan Taskminder"; +/// The current index of migrations to be compared to `SharedPreferences.migrationIndex`. +const int currentMigrationIndex = 0; + Uri feedbackUrl = Uri.parse( "https://docs.google.com/forms/d/e/1FAIpQLScqajYl3qmnkdb48voPwN88LENp6XPxPh4eYQzgZUhAluqGWg/viewform?usp=sf_link", ); diff --git a/lib/screens/home.dart b/lib/screens/home.dart index 78ea211..8ff9cf8 100644 --- a/lib/screens/home.dart +++ b/lib/screens/home.dart @@ -6,6 +6,7 @@ import 'package:hive_flutter/hive_flutter.dart'; import 'package:intl/intl.dart'; import 'package:ramadan_taskminder/constants.dart'; import 'package:ramadan_taskminder/extensions/date.dart'; +import 'package:ramadan_taskminder/extensions/int.dart'; import 'package:ramadan_taskminder/prayers.dart'; import 'package:ramadan_taskminder/quran.dart'; import 'package:ramadan_taskminder/theme.dart'; @@ -41,19 +42,59 @@ class _HomeScreenState extends State { @override void initState() { super.initState(); - firstRun(); + + startup(); initializeTasks(); initializeHistory(); initializePrayers(); } - void firstRun() async { + void startup() async { SharedPreferences preferences = await SharedPreferences.getInstance(); bool firstRun = preferences.getBool("firstRun") ?? true; if (firstRun) { tasksBox.put("allTasks", initialTasks); preferences.setBool("firstRun", false); } + + int migrationIndex = preferences.getInt("migrationIndex") ?? -1; + // print("Migration Index (setting): $migrationIndex, migration index (app): $currentMigrationIndex"); + if (migrationIndex < currentMigrationIndex) { + // print("Running migrations..."); + final migrations = migrationIndex.upTo(currentMigrationIndex).skip(1); + for (final migration in migrations) { + // print("Running migration #$migration..."); + migrate(migration); + } + } + } + + void migrate(int migrationIndex) { + if (migrationIndex == 0) { + List? quranHistory = quran.get("history"); + if (quranHistory != null) { + List newHistory = quranHistory.map((entry) { + if (entry[0].runtimeType == List) { + return entry; + } + + final gregorianDate = DateTime.parse(entry[0].toString()); + final hijriDate = HijriCalendar.fromDate(gregorianDate); + + return [ + [ + entry[0], + "${hijriDate.hYear}-${hijriDate.hMonth}-${hijriDate.hDay}" + ], + entry[1] + ]; + }).toList(); + + // print("Old: $quranHistory"); + // print("New: $newHistory"); + quran.put("history", newHistory); + } + } } void initializeTasks() { @@ -306,7 +347,8 @@ class _HomeScreenState extends State { ), WideCard( content: "Eid Takbeers", - onTap: () => GoRouter.of(context).push("/eid-takbeer"), + onTap: () => + GoRouter.of(context).push("/eid-takbeer"), ), const SizedBox(height: 15), WideCard( From 628ebeec18d283c82153abf1c3c13ceeba718c86 Mon Sep 17 00:00:00 2001 From: "H. Kamran" Date: Thu, 8 Feb 2024 18:07:25 -0800 Subject: [PATCH 2/6] Switch to `jhijri` instead `hijri` --- lib/date.dart | 36 ++++++++++++++++++++++++++++++++++++ lib/extensions/date.dart | 40 ++++++++++++++++++++++++++++++++++++++++ lib/screens/home.dart | 26 ++++++++++++++++++++++---- lib/screens/quran.dart | 12 +++++++----- pubspec.lock | 8 ++++++++ pubspec.yaml | 1 + 6 files changed, 114 insertions(+), 9 deletions(-) create mode 100644 lib/date.dart diff --git a/lib/date.dart b/lib/date.dart new file mode 100644 index 0000000..7a9118c --- /dev/null +++ b/lib/date.dart @@ -0,0 +1,36 @@ +import 'package:hijri/hijri_calendar.dart'; +import 'package:jhijri/jHijri.dart'; + +HijriCalendar fromIso8601Style(String iso8601) { + final components = iso8601.split("-"); + if (components.length != 3) { + print("Invalid ISO-8601 style string — \"$iso8601\""); + throw Error(); + } + + final numericalComponents = components.map((e) => int.parse(e)); + + var newDate = HijriCalendar(); + newDate.hYear = numericalComponents.elementAt(0); + newDate.hMonth = numericalComponents.elementAt(1); + newDate.hDay = numericalComponents.elementAt(2); + + return newDate; +} + +JHijri jHijriFromIso8601Style(String iso8601) { + final components = iso8601.split("-"); + if (components.length != 3) { + print("Invalid ISO-8601 style string — \"$iso8601\""); + throw Error(); + } + + final numericalComponents = components.map((e) => int.parse(e)); + + return JHijri( + fYear: numericalComponents.elementAt(0), + fMonth: numericalComponents.elementAt(1), + fDay: numericalComponents.elementAt(2), + fDisplay: DisplayFormat.MMMDDYYYY, + ); +} diff --git a/lib/extensions/date.dart b/lib/extensions/date.dart index e34cdae..1c0046f 100644 --- a/lib/extensions/date.dart +++ b/lib/extensions/date.dart @@ -1,3 +1,43 @@ +import 'package:hijri/hijri_calendar.dart'; +import 'package:jhijri/jHijri.dart'; + extension Date on DateTime { String getYMD() => toIso8601String().split("T")[0]; } + +extension Hijri on HijriCalendar { + String toIso8601Style() => "$hYear-$hMonth-$hDay"; +} + +extension JHijriDateTime on JHijri { + String hijriMonth() { + switch (month) { + case 1: + return "Muharram"; + case 2: + return "Safar"; + case 3: + return "Rabi' Al-Awwal"; + case 4: + return "Rabi' Al-Thani"; + case 5: + return "Jumada Al-Awwal"; + case 6: + return "Jumada Al-Thani"; + case 7: + return "Rajab"; + case 8: + return "Sha'aban"; + case 9: + return "Ramadan"; + case 10: + return "Shawwal"; + case 11: + return "Dhu Al-Qi'dah"; + case 12: + return "Dhu Al-Hijjah"; + default: + return ""; + } + } +} diff --git a/lib/screens/home.dart b/lib/screens/home.dart index 8ff9cf8..8213932 100644 --- a/lib/screens/home.dart +++ b/lib/screens/home.dart @@ -5,6 +5,7 @@ import 'package:hijri/hijri_calendar.dart'; import 'package:hive_flutter/hive_flutter.dart'; import 'package:intl/intl.dart'; import 'package:ramadan_taskminder/constants.dart'; +import 'package:ramadan_taskminder/date.dart'; import 'package:ramadan_taskminder/extensions/date.dart'; import 'package:ramadan_taskminder/extensions/int.dart'; import 'package:ramadan_taskminder/prayers.dart'; @@ -82,10 +83,7 @@ class _HomeScreenState extends State { final hijriDate = HijriCalendar.fromDate(gregorianDate); return [ - [ - entry[0], - "${hijriDate.hYear}-${hijriDate.hMonth}-${hijriDate.hDay}" - ], + [entry[0], hijriDate.toIso8601Style()], entry[1] ]; }).toList(); @@ -125,6 +123,26 @@ class _HomeScreenState extends State { List? quranHistory = quran.get("history"); if (quranHistory == null) { quran.put("history", []); + } else { + // print(HijriCalendar.fromDate( + // DateTime.parse((quran.get("history")[0][0][0])))); + // print(fromIso8601Style(quran.get("history")[0][0][1])); + // print(HijriCalendar.fromDate( + // DateTime.parse((quran.get("history")[0][0][0]))) + // .longMonthName); + // print(fromIso8601Style(quran.get("history")[0][0][1]).longMonthName); + print(quranHistory); + print(quranHistory.map((entry) { + final date = DateTime.parse(entry[0][0].toString()); + final hijriDate = fromIso8601Style(entry[0][1]); + final altHijriDate = jHijriFromIso8601Style(entry[0][1]); + + print(altHijriDate.hijri.monthName); + + return [ + [date, hijriDate.toIso8601Style(), "${altHijriDate.year}-${altHijriDate.month}-${altHijriDate.day}"] + ]; + }).toList()); } } diff --git a/lib/screens/quran.dart b/lib/screens/quran.dart index a7e3ffa..1b3b63f 100644 --- a/lib/screens/quran.dart +++ b/lib/screens/quran.dart @@ -2,6 +2,8 @@ import 'package:flutter/material.dart'; import 'package:hijri/hijri_calendar.dart'; import 'package:hive_flutter/hive_flutter.dart'; import 'package:intl/intl.dart'; +import 'package:ramadan_taskminder/date.dart'; +import 'package:ramadan_taskminder/extensions/date.dart'; import 'package:ramadan_taskminder/theme.dart'; import 'package:ramadan_taskminder/quran.dart'; import 'package:ramadan_taskminder/widgets/page_footer.dart'; @@ -53,8 +55,8 @@ class _QuranScreenState extends State { } else { history = quranHistory; history.sort( - (a, b) => DateTime.parse(a[0].toString()) - .compareTo(DateTime.parse(b[0].toString())), + (a, b) => DateTime.parse(a[0][0].toString()) + .compareTo(DateTime.parse(b[0][0].toString())), ); } } @@ -304,9 +306,9 @@ class _QuranScreenState extends State { children: history.reversed.map( (entry) { final date = - DateTime.parse(entry[0].toString()); + DateTime.parse(entry[0][0].toString()); final hijriDate = - HijriCalendar.fromDate(date); + jHijriFromIso8601Style(entry[0][1]); final starting = (entry[1] as List)[0] @@ -317,7 +319,7 @@ class _QuranScreenState extends State { return StackedCard( header: - "${DateFormat.MMMMd().format(date)} / ${hijriDate.longMonthName} ${hijriDate.hDay}", + "${DateFormat.MMMMd().format(date)} / ${hijriDate.hijriMonth()} ${hijriDate.day}", title: "${surahs[int.parse(starting[0]) - 1]["name"].toString()} ${starting[1]} - ${surahs[int.parse(ending[0]) - 1]["name"].toString()} ${ending[1]}", fullWidth: true, diff --git a/pubspec.lock b/pubspec.lock index 764fc94..b865a50 100644 --- a/pubspec.lock +++ b/pubspec.lock @@ -216,6 +216,14 @@ packages: url: "https://pub.dev" source: hosted version: "0.19.0" + jhijri: + dependency: "direct main" + description: + name: jhijri + sha256: c2a28e803b1d07513a29953c6685b933235511a1f57966fd5bf66bfdae131f70 + url: "https://pub.dev" + source: hosted + version: "1.0.0" js: dependency: transitive description: diff --git a/pubspec.yaml b/pubspec.yaml index 882dee8..9b7f083 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -42,6 +42,7 @@ dependencies: package_info_plus: ^5.0.1 google_fonts: ^6.1.0 go_router: ^13.1.0 + jhijri: ^1.0.0 dev_dependencies: flutter_test: From 65609534f7579dd00f429424dcdb13c8707e07e8 Mon Sep 17 00:00:00 2001 From: "H. Kamran" Date: Thu, 21 Mar 2024 18:11:59 -0700 Subject: [PATCH 3/6] Add offset setting --- lib/main.dart | 16 ++++-- lib/screens/settings.dart | 118 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 130 insertions(+), 4 deletions(-) diff --git a/lib/main.dart b/lib/main.dart index 8082cd6..ed6ae30 100644 --- a/lib/main.dart +++ b/lib/main.dart @@ -18,6 +18,7 @@ Future main() async { await Hive.openBox("tasks"); await Hive.openBox("quran"); await Hive.openBox("prayers"); + await Hive.openBox("settings"); runApp(const RamadanTaskminder()); } @@ -71,9 +72,9 @@ class RamadanTaskminder extends StatelessWidget { return MaterialApp.router( title: appName, theme: ThemeData( + useMaterial3: true, primaryColor: getPrimaryColor(context), scaffoldBackgroundColor: backgroundColor, - useMaterial3: true, textTheme: GoogleFonts.mPlus1pTextTheme(), ), darkTheme: ThemeData( @@ -81,9 +82,11 @@ class RamadanTaskminder extends StatelessWidget { brightness: Brightness.dark, scaffoldBackgroundColor: Colors.black, colorScheme: const ColorScheme.dark( - primary: Colors.black, - onPrimary: Colors.black, - secondary: primaryDarkColor, + primary: primaryDarkColor, + onPrimary: Colors.white, + surface: Colors.black, + onSurface: Colors.white, + secondary: primaryLightColor, ), cardTheme: const CardTheme( color: Colors.black87, @@ -103,6 +106,11 @@ class RamadanTaskminder extends StatelessWidget { ), ), ), + textButtonTheme: TextButtonThemeData( + style: TextButton.styleFrom( + foregroundColor: buttonTextDarkColor, + ), + ), textSelectionTheme: const TextSelectionThemeData( cursorColor: primaryDarkColor, selectionColor: primaryDarkColor, diff --git a/lib/screens/settings.dart b/lib/screens/settings.dart index 0928b59..0f99fa6 100644 --- a/lib/screens/settings.dart +++ b/lib/screens/settings.dart @@ -20,12 +20,16 @@ class SettingsScreen extends StatefulWidget { class _SettingsScreenState extends State { Box tasksBox = Hive.box("tasks"); + Box settingsBox = Hive.box("settings"); + late List allTasks; + late int dateOffset; @override void initState() { super.initState(); initializeTasks(); + calculateOffset(); } void initializeTasks() { @@ -33,6 +37,101 @@ class _SettingsScreenState extends State { tasksBox.get("allTasks", defaultValue: initialTasks) as List; } + void calculateOffset() { + setState(() => dateOffset = settingsBox.get("dateOffset", defaultValue: 0)); + } + + void editDateOffset() { + showDialog( + context: context, + builder: (BuildContext context) { + return AlertDialog( + title: const Text("Edit Hijri Date Offset"), + content: StatefulBuilder( + builder: ( + BuildContext context, + StateSetter setState, + ) { + return Column( + mainAxisSize: MainAxisSize.min, + mainAxisAlignment: MainAxisAlignment.start, + children: [ + RadioListTile( + title: const Text("-1 day"), + value: -1, + groupValue: dateOffset, + visualDensity: const VisualDensity( + horizontal: VisualDensity.minimumDensity, + vertical: VisualDensity.minimumDensity, + ), + contentPadding: const EdgeInsets.all(0.0), + onChanged: (value) { + setState(() { + if (value != null) { + settingsBox.put("dateOffset", value); + calculateOffset(); + } + }); + }, + ), + RadioListTile( + title: const Text("0 days"), + value: 0, + groupValue: dateOffset, + visualDensity: const VisualDensity( + horizontal: VisualDensity.minimumDensity, + vertical: VisualDensity.minimumDensity, + ), + contentPadding: const EdgeInsets.all(0.0), + onChanged: (value) { + setState(() { + if (value != null) { + settingsBox.put("dateOffset", value); + calculateOffset(); + } + }); + }, + ), + RadioListTile( + title: const Text("1 day"), + value: 1, + groupValue: dateOffset, + visualDensity: const VisualDensity( + horizontal: VisualDensity.minimumDensity, + vertical: VisualDensity.minimumDensity, + ), + contentPadding: const EdgeInsets.all(0.0), + onChanged: (value) { + setState(() { + if (value != null) { + settingsBox.put("dateOffset", value); + calculateOffset(); + } + }); + }, + ), + ], + ); + }, + ), + actions: [ + TextButton( + child: Text( + "Set", + style: TextStyle( + color: isDark(context) ? primaryLightColor : primaryDarkColor, + ), + ), + onPressed: () { + Navigator.of(context).pop(); + }, + ), + ], + ); + }, + ); + } + @override Widget build(BuildContext context) { return Material( @@ -84,6 +183,25 @@ class _SettingsScreenState extends State { ), ], ), + const SizedBox( + height: 15, + ), + Column( + mainAxisSize: MainAxisSize.min, + crossAxisAlignment: CrossAxisAlignment.start, + children: [ + SectionHeader( + title: "Hijri Date Offset", + buttonText: "Edit", + onClick: () => editDateOffset(), + ), + const SizedBox(height: 5), + Statistic( + statistic: + "$dateOffset day${dateOffset == 0 ? "s" : ""}", + ), + ], + ), const SizedBox( height: 50, ), From 43a6a29485b1166a9912c35ab53a7c902c9bf74b Mon Sep 17 00:00:00 2001 From: "H. Kamran" Date: Thu, 21 Mar 2024 18:14:04 -0700 Subject: [PATCH 4/6] Add fixes for iOS development --- ios/Podfile | 2 +- ios/Podfile.lock | 20 ++++---- ios/Runner.xcodeproj/project.pbxproj | 3 +- .../xcshareddata/xcschemes/Runner.xcscheme | 2 +- pubspec.lock | 48 +++++++++++++++---- pubspec.yaml | 2 +- 6 files changed, 55 insertions(+), 22 deletions(-) diff --git a/ios/Podfile b/ios/Podfile index 88359b2..279576f 100644 --- a/ios/Podfile +++ b/ios/Podfile @@ -1,5 +1,5 @@ # Uncomment this line to define a global platform for your project -# platform :ios, '11.0' +# platform :ios, '12.0' # CocoaPods analytics sends network stats synchronously affecting flutter build latency. ENV['COCOAPODS_DISABLE_STATS'] = 'true' diff --git a/ios/Podfile.lock b/ios/Podfile.lock index 4bb5fbf..ddf946a 100644 --- a/ios/Podfile.lock +++ b/ios/Podfile.lock @@ -14,8 +14,8 @@ PODS: DEPENDENCIES: - Flutter (from `Flutter`) - package_info_plus (from `.symlinks/plugins/package_info_plus/ios`) - - path_provider_foundation (from `.symlinks/plugins/path_provider_foundation/ios`) - - shared_preferences_foundation (from `.symlinks/plugins/shared_preferences_foundation/ios`) + - path_provider_foundation (from `.symlinks/plugins/path_provider_foundation/darwin`) + - shared_preferences_foundation (from `.symlinks/plugins/shared_preferences_foundation/darwin`) - url_launcher_ios (from `.symlinks/plugins/url_launcher_ios/ios`) EXTERNAL SOURCES: @@ -24,19 +24,19 @@ EXTERNAL SOURCES: package_info_plus: :path: ".symlinks/plugins/package_info_plus/ios" path_provider_foundation: - :path: ".symlinks/plugins/path_provider_foundation/ios" + :path: ".symlinks/plugins/path_provider_foundation/darwin" shared_preferences_foundation: - :path: ".symlinks/plugins/shared_preferences_foundation/ios" + :path: ".symlinks/plugins/shared_preferences_foundation/darwin" url_launcher_ios: :path: ".symlinks/plugins/url_launcher_ios/ios" SPEC CHECKSUMS: - Flutter: f04841e97a9d0b0a8025694d0796dd46242b2854 - package_info_plus: 6c92f08e1f853dc01228d6f553146438dafcd14e + Flutter: e0871f40cf51350855a761d2e70bf5af5b9b5de7 + package_info_plus: 115f4ad11e0698c8c1c5d8a689390df880f47e85 path_provider_foundation: c68054786f1b4f3343858c1e1d0caaded73f0be9 - shared_preferences_foundation: 986fc17f3d3251412d18b0265f9c64113a8c2472 - url_launcher_ios: 08a3dfac5fb39e8759aeb0abbd5d9480f30fc8b4 + shared_preferences_foundation: b4c3b4cddf1c21f02770737f147a3f5da9d39695 + url_launcher_ios: bbd758c6e7f9fd7b5b1d4cde34d2b95fcce5e812 -PODFILE CHECKSUM: ef19549a9bc3046e7bb7d2fab4d021637c0c58a3 +PODFILE CHECKSUM: c4c93c5f6502fe2754f48404d3594bf779584011 -COCOAPODS: 1.12.0 +COCOAPODS: 1.15.2 diff --git a/ios/Runner.xcodeproj/project.pbxproj b/ios/Runner.xcodeproj/project.pbxproj index e27c273..cc954ff 100644 --- a/ios/Runner.xcodeproj/project.pbxproj +++ b/ios/Runner.xcodeproj/project.pbxproj @@ -155,7 +155,7 @@ 97C146E61CF9000F007C117D /* Project object */ = { isa = PBXProject; attributes = { - LastUpgradeCheck = 1300; + LastUpgradeCheck = 1510; ORGANIZATIONNAME = ""; TargetAttributes = { 97C146ED1CF9000F007C117D = { @@ -221,6 +221,7 @@ files = ( ); inputPaths = ( + "${TARGET_BUILD_DIR}/${INFOPLIST_PATH}", ); name = "Thin Binary"; outputPaths = ( diff --git a/ios/Runner.xcodeproj/xcshareddata/xcschemes/Runner.xcscheme b/ios/Runner.xcodeproj/xcshareddata/xcschemes/Runner.xcscheme index c87d15a..5e31d3d 100644 --- a/ios/Runner.xcodeproj/xcshareddata/xcschemes/Runner.xcscheme +++ b/ios/Runner.xcodeproj/xcshareddata/xcschemes/Runner.xcscheme @@ -1,6 +1,6 @@ =2.18.4 <3.0.0" From b70d66d53703878f2eeeb54ee8582987c65043aa Mon Sep 17 00:00:00 2001 From: "H. Kamran" Date: Thu, 21 Mar 2024 18:14:45 -0700 Subject: [PATCH 5/6] Add hijri offset to Qur'an entries --- lib/screens/quran.dart | 22 +++++++++++++++++----- 1 file changed, 17 insertions(+), 5 deletions(-) diff --git a/lib/screens/quran.dart b/lib/screens/quran.dart index 1b3b63f..83a3c8b 100644 --- a/lib/screens/quran.dart +++ b/lib/screens/quran.dart @@ -2,6 +2,7 @@ import 'package:flutter/material.dart'; import 'package:hijri/hijri_calendar.dart'; import 'package:hive_flutter/hive_flutter.dart'; import 'package:intl/intl.dart'; +import 'package:jhijri/jHijri.dart'; import 'package:ramadan_taskminder/date.dart'; import 'package:ramadan_taskminder/extensions/date.dart'; import 'package:ramadan_taskminder/theme.dart'; @@ -264,9 +265,19 @@ class _QuranScreenState extends State { onTap: () => setState( () { final entry = [ - DateTime.now() - .toIso8601String() - .split("T")[0], + [ + DateTime.now() + .toIso8601String() + .split("T")[0], + JHijri( + fDate: + DateTime.now().subtract( + const Duration(days: 1), + ), + fDisplay: + DisplayFormat.YYYYMMDD, + ).fullDate, + ], [ "${startingSurah + 1}-$startingAyah", "${endingSurah + 1}-$endingAyah" @@ -305,8 +316,9 @@ class _QuranScreenState extends State { runSpacing: 10, children: history.reversed.map( (entry) { - final date = - DateTime.parse(entry[0][0].toString()); + final date = DateTime.parse( + entry[0][0].toString(), + ); final hijriDate = jHijriFromIso8601Style(entry[0][1]); From 57064ccda53a76d1bdc39c93c3d6f4f385af50dd Mon Sep 17 00:00:00 2001 From: "H. Kamran" Date: Thu, 21 Mar 2024 18:33:05 -0700 Subject: [PATCH 6/6] Remove `hijri` references, patch migration system --- lib/date.dart | 19 ---------------- lib/extensions/date.dart | 13 +++++++---- lib/screens/home.dart | 49 ++++++++++++++++------------------------ lib/screens/quran.dart | 7 +++--- pubspec.lock | 8 ------- pubspec.yaml | 1 - 6 files changed, 32 insertions(+), 65 deletions(-) diff --git a/lib/date.dart b/lib/date.dart index 7a9118c..bf32e3c 100644 --- a/lib/date.dart +++ b/lib/date.dart @@ -1,23 +1,5 @@ -import 'package:hijri/hijri_calendar.dart'; import 'package:jhijri/jHijri.dart'; -HijriCalendar fromIso8601Style(String iso8601) { - final components = iso8601.split("-"); - if (components.length != 3) { - print("Invalid ISO-8601 style string — \"$iso8601\""); - throw Error(); - } - - final numericalComponents = components.map((e) => int.parse(e)); - - var newDate = HijriCalendar(); - newDate.hYear = numericalComponents.elementAt(0); - newDate.hMonth = numericalComponents.elementAt(1); - newDate.hDay = numericalComponents.elementAt(2); - - return newDate; -} - JHijri jHijriFromIso8601Style(String iso8601) { final components = iso8601.split("-"); if (components.length != 3) { @@ -31,6 +13,5 @@ JHijri jHijriFromIso8601Style(String iso8601) { fYear: numericalComponents.elementAt(0), fMonth: numericalComponents.elementAt(1), fDay: numericalComponents.elementAt(2), - fDisplay: DisplayFormat.MMMDDYYYY, ); } diff --git a/lib/extensions/date.dart b/lib/extensions/date.dart index 1c0046f..d3a7671 100644 --- a/lib/extensions/date.dart +++ b/lib/extensions/date.dart @@ -1,12 +1,17 @@ -import 'package:hijri/hijri_calendar.dart'; import 'package:jhijri/jHijri.dart'; extension Date on DateTime { String getYMD() => toIso8601String().split("T")[0]; -} -extension Hijri on HijriCalendar { - String toIso8601Style() => "$hYear-$hMonth-$hDay"; + DateTime offset(int offset) { + if (offset == 1) { + return add(const Duration(days: 1)); + } else if (offset == -1) { + return subtract(const Duration(days: 1)); + } + + return this; + } } extension JHijriDateTime on JHijri { diff --git a/lib/screens/home.dart b/lib/screens/home.dart index 8213932..2b791a1 100644 --- a/lib/screens/home.dart +++ b/lib/screens/home.dart @@ -1,11 +1,10 @@ import 'package:flutter/material.dart'; import 'package:go_router/go_router.dart'; import 'package:google_fonts/google_fonts.dart'; -import 'package:hijri/hijri_calendar.dart'; import 'package:hive_flutter/hive_flutter.dart'; import 'package:intl/intl.dart'; +import 'package:jhijri/jHijri.dart'; import 'package:ramadan_taskminder/constants.dart'; -import 'package:ramadan_taskminder/date.dart'; import 'package:ramadan_taskminder/extensions/date.dart'; import 'package:ramadan_taskminder/extensions/int.dart'; import 'package:ramadan_taskminder/prayers.dart'; @@ -29,22 +28,24 @@ class HomeScreen extends StatefulWidget { } class _HomeScreenState extends State { - DateTime current = DateTime.now(); - HijriCalendar hijriCurrent = HijriCalendar.now(); - Box tasksBox = Hive.box("tasks"); Box prayersBox = Hive.box("prayers"); Box quran = Hive.box("quran"); + Box settingsBox = Hive.box("settings"); late List allTasks; late Map tasks; late Map prayers; + DateTime current = DateTime.now(); + late JHijri hijriCurrent; + @override void initState() { super.initState(); startup(); + initializeSettings(); initializeTasks(); initializeHistory(); initializePrayers(); @@ -75,15 +76,16 @@ class _HomeScreenState extends State { List? quranHistory = quran.get("history"); if (quranHistory != null) { List newHistory = quranHistory.map((entry) { - if (entry[0].runtimeType == List) { + if (entry[0].runtimeType == List) { return entry; } final gregorianDate = DateTime.parse(entry[0].toString()); - final hijriDate = HijriCalendar.fromDate(gregorianDate); + final hijriDate = + JHijri(fDate: gregorianDate, fDisplay: DisplayFormat.YYYYMMDD); return [ - [entry[0], hijriDate.toIso8601Style()], + [entry[0], hijriDate.fullDate], entry[1] ]; }).toList(); @@ -95,6 +97,15 @@ class _HomeScreenState extends State { } } + void initializeSettings() { + hijriCurrent = JHijri( + fDate: DateTime.now().offset( + settingsBox.get("dateOffset", defaultValue: 0), + ), + fDisplay: DisplayFormat.YYYYMMDD, + ); + } + void initializeTasks() { allTasks = tasksBox.get("allTasks", defaultValue: initialTasks) as List; @@ -123,26 +134,6 @@ class _HomeScreenState extends State { List? quranHistory = quran.get("history"); if (quranHistory == null) { quran.put("history", []); - } else { - // print(HijriCalendar.fromDate( - // DateTime.parse((quran.get("history")[0][0][0])))); - // print(fromIso8601Style(quran.get("history")[0][0][1])); - // print(HijriCalendar.fromDate( - // DateTime.parse((quran.get("history")[0][0][0]))) - // .longMonthName); - // print(fromIso8601Style(quran.get("history")[0][0][1]).longMonthName); - print(quranHistory); - print(quranHistory.map((entry) { - final date = DateTime.parse(entry[0][0].toString()); - final hijriDate = fromIso8601Style(entry[0][1]); - final altHijriDate = jHijriFromIso8601Style(entry[0][1]); - - print(altHijriDate.hijri.monthName); - - return [ - [date, hijriDate.toIso8601Style(), "${altHijriDate.year}-${altHijriDate.month}-${altHijriDate.day}"] - ]; - }).toList()); } } @@ -231,7 +222,7 @@ class _HomeScreenState extends State { PageHeader( header: appName, title: - "${hijriCurrent.hDay} ${hijriCurrent.longMonthName} ${hijriCurrent.hYear}", + "${hijriCurrent.day} ${hijriCurrent.hijriMonth()} ${hijriCurrent.year}", rightAlign: Column( crossAxisAlignment: CrossAxisAlignment.center, mainAxisSize: MainAxisSize.min, diff --git a/lib/screens/quran.dart b/lib/screens/quran.dart index 83a3c8b..dbb50f2 100644 --- a/lib/screens/quran.dart +++ b/lib/screens/quran.dart @@ -1,5 +1,4 @@ import 'package:flutter/material.dart'; -import 'package:hijri/hijri_calendar.dart'; import 'package:hive_flutter/hive_flutter.dart'; import 'package:intl/intl.dart'; import 'package:jhijri/jHijri.dart'; @@ -93,8 +92,8 @@ class _QuranScreenState extends State { context: context, builder: (BuildContext context) { final entry = history[deletingHistoryEntry]; - final date = DateTime.parse(entry[0].toString()); - final hijriDate = HijriCalendar.fromDate(date); + final date = DateTime.parse(entry[0][0].toString()); + final hijriDate = jHijriFromIso8601Style(entry[0][1]); final starting = (entry[1] as List)[0].split("-"); final ending = (entry[1] as List)[1].split("-"); @@ -109,7 +108,7 @@ class _QuranScreenState extends State { "Are you sure you want to delete the following entry?"), StackedCard( header: - "${DateFormat.MMMMd().format(date)} / ${hijriDate.longMonthName} ${hijriDate.hDay}", + "${DateFormat.MMMMd().format(date)} / ${hijriDate.hijriMonth()} ${hijriDate.day}", title: "${surahs[int.parse(starting[0]) - 1]["name"].toString()} ${starting[1]} - ${surahs[int.parse(ending[0]) - 1]["name"].toString()} ${ending[1]}", fullWidth: true, diff --git a/pubspec.lock b/pubspec.lock index 41755ba..079b370 100644 --- a/pubspec.lock +++ b/pubspec.lock @@ -160,14 +160,6 @@ packages: url: "https://pub.dev" source: hosted version: "6.1.0" - hijri: - dependency: "direct main" - description: - name: hijri - sha256: "203eb7341e32789af6429877e88411b1526ef44c5d157ce4d3b930dd32c37ef1" - url: "https://pub.dev" - source: hosted - version: "3.0.0" hive: dependency: "direct main" description: diff --git a/pubspec.yaml b/pubspec.yaml index 00ed066..07ad403 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -32,7 +32,6 @@ dependencies: flutter: sdk: flutter - hijri: ^3.0.0 hive: ^2.2.3 hive_flutter: ^1.1.0 lucide_icons_flutter: ^1.0.3