diff --git a/lib/CONSTANTS.dart b/lib/CONSTANTS.dart index b723945..7275d59 100644 --- a/lib/CONSTANTS.dart +++ b/lib/CONSTANTS.dart @@ -15,6 +15,7 @@ const kStoredNotificationLimit = "storedNotificationLimit"; const kNumberOfNotifsScheduled = "numnotifscheduled"; const kIsDebugMode = "debugModeSet"; const kForceUpdateNotif = "storedForceUpdateNotif"; +const kDiscoveredDeveloperOption = "storedDevDiscovered"; //Network image const kAppIconUrl = diff --git a/lib/main.dart b/lib/main.dart index 554899d..931f5be 100644 --- a/lib/main.dart +++ b/lib/main.dart @@ -112,6 +112,7 @@ void initGetStorage() { GetStorage().writeIfNull(kStoredNotificationLimit, false); GetStorage().writeIfNull(kIsDebugMode, false); GetStorage().writeIfNull(kForceUpdateNotif, false); + GetStorage().writeIfNull(kDiscoveredDeveloperOption, false); } Future _configureLocalTimeZone() async { @@ -135,5 +136,7 @@ void readAllGetStorage() { 'kStoredNotificationLimit is ${GetStorage().read(kStoredNotificationLimit)}'); print('kIsDebugMode is ${GetStorage().read(kIsDebugMode)}'); print('kForceUpdateNotif is ${GetStorage().read(kForceUpdateNotif)}'); + print( + 'kDiscoveredDeveloperOption is ${GetStorage().read(kDiscoveredDeveloperOption)}'); print('-----------------------'); } diff --git a/lib/views/Settings part/AboutPage.dart b/lib/views/Settings part/AboutPage.dart index 4c5dba4..d062959 100644 --- a/lib/views/Settings part/AboutPage.dart +++ b/lib/views/Settings part/AboutPage.dart @@ -3,7 +3,9 @@ import 'package:flutter/material.dart'; import 'package:flutter/services.dart'; import 'package:fluttertoast/fluttertoast.dart'; import 'package:get_storage/get_storage.dart'; +import 'package:provider/provider.dart'; import 'package:timezone/timezone.dart' as tz; +import 'package:waktusolatmalaysia/views/Settings%20part/settingsProvider.dart'; import '../../CONSTANTS.dart'; import '../../main.dart'; @@ -25,245 +27,264 @@ class AboutAppPage extends StatelessWidget { body: SingleChildScrollView( child: Padding( padding: const EdgeInsets.all(16.0), - child: Column( - mainAxisAlignment: MainAxisAlignment.start, - crossAxisAlignment: CrossAxisAlignment.stretch, - children: [ - GestureDetector( - onLongPress: () { - if (isFirstTry && !GetStorage().read(kIsDebugMode)) { - Fluttertoast.showToast(msg: '(⌐■_■)'); - isFirstTry = false; - } else { - print('Show debug dialog'); - var prayApiCalled = - GetStorage().read(kStoredApiPrayerCall) ?? - 'no calls yet'; - var locApiCalled = - GetStorage().read(kStoredApiLocationCall) ?? - 'no calls yet'; - showDialog( - context: context, - builder: (context) => Dialog( - child: ListView( - shrinkWrap: true, - padding: EdgeInsets.all(8.0), - children: [ - Text( - 'Debug dialog (for dev)', - textAlign: TextAlign.center, - ), - ListTile( - title: Text('Prayer time API calls'), - subtitle: Text(prayApiCalled), - onLongPress: () { - Clipboard.setData( - ClipboardData(text: prayApiCalled)) - .then((value) => Fluttertoast.showToast( - msg: 'Copied url')); - }, - ), - ListTile( - title: Text('Prayer location API calls'), - subtitle: Text(locApiCalled), - onLongPress: () { - Clipboard.setData( - ClipboardData(text: locApiCalled)) - .then((value) => Fluttertoast.showToast( - msg: 'Copied url')); - }, - ), - ListTile( - title: Text('Send immediate test notification'), - onTap: () async { - await showDebugNotification(); - }, - ), - ListTile( - title: Text('Send alert test in one miniute'), - subtitle: Text('Payload: $kPayloadDebug'), - onTap: () async { - await scheduleAlertNotification( - notifsPlugin: notifsPlugin, - title: 'debug payload', - id: 219, //randrom int haha - body: 'With payload', - payload: kPayloadDebug, - scheduledTime: - tz.TZDateTime.now(tz.local).add( - Duration(minutes: 1), - )); - }, - ), - ListTile( - title: Text('Global location index'), - subtitle: Text( - '${GetStorage().read(kStoredGlobalIndex)}')), - ListTile( - title: Text('Last update notification'), - subtitle: Text( - DateTime.fromMillisecondsSinceEpoch( - GetStorage() - .read(kStoredLastUpdateNotif)) + child: Consumer( + builder: (context, setting, child) { + return Column( + mainAxisAlignment: MainAxisAlignment.start, + crossAxisAlignment: CrossAxisAlignment.stretch, + children: [ + GestureDetector( + onLongPress: () { + if (isFirstTry && + !GetStorage().read(kDiscoveredDeveloperOption)) { + Fluttertoast.showToast(msg: '(⌐■_■)'); + isFirstTry = false; + } else { + if (!GetStorage().read(kDiscoveredDeveloperOption)) { + Fluttertoast.showToast( + msg: 'Developer mode discovered', + toastLength: Toast.LENGTH_LONG, + backgroundColor: Colors.teal); + GetStorage().write(kDiscoveredDeveloperOption, true); + setting.isDeveloperOption = true; + } else { + print('Dev mode already enabled'); + } + + print('Show debug dialog'); + var prayApiCalled = + GetStorage().read(kStoredApiPrayerCall) ?? + 'no calls yet'; + var locApiCalled = + GetStorage().read(kStoredApiLocationCall) ?? + 'no calls yet'; + showDialog( + context: context, + builder: (context) => Dialog( + child: ListView( + shrinkWrap: true, + padding: EdgeInsets.all(8.0), + children: [ + Text( + 'Debug dialog (for dev)', + textAlign: TextAlign.center, + ), + ListTile( + title: Text('Prayer time API calls'), + subtitle: Text(prayApiCalled), + onLongPress: () { + Clipboard.setData( + ClipboardData(text: prayApiCalled)) + .then((value) => Fluttertoast.showToast( + msg: 'Copied url')); + }, + ), + ListTile( + title: Text('Prayer location API calls'), + subtitle: Text(locApiCalled), + onLongPress: () { + Clipboard.setData( + ClipboardData(text: locApiCalled)) + .then((value) => Fluttertoast.showToast( + msg: 'Copied url')); + }, + ), + ListTile( + title: + Text('Send immediate test notification'), + onTap: () async { + await showDebugNotification(); + }, + ), + ListTile( + title: Text('Send alert test in one miniute'), + subtitle: Text('Payload: $kPayloadDebug'), + onTap: () async { + await scheduleAlertNotification( + notifsPlugin: notifsPlugin, + title: 'debug payload', + id: 219, //randrom int haha + body: 'With payload', + payload: kPayloadDebug, + scheduledTime: + tz.TZDateTime.now(tz.local).add( + Duration(minutes: 1), + )); + }, + ), + ListTile( + title: Text('Global location index'), + subtitle: Text( + '${GetStorage().read(kStoredGlobalIndex)}')), + ListTile( + title: Text('Last update notification'), + subtitle: Text( + DateTime.fromMillisecondsSinceEpoch( + GetStorage() + .read(kStoredLastUpdateNotif)) + .toString()), + onLongPress: () { + Clipboard.setData(ClipboardData( + text: GetStorage() + .read(kStoredLastUpdateNotif) + .toString())) + .then((value) => Fluttertoast.showToast( + msg: 'Copied millis')); + }, + ), + ListTile( + title: + Text('Number of scheduled notification'), + subtitle: Text(GetStorage() + .read(kNumberOfNotifsScheduled) .toString()), - onLongPress: () { - Clipboard.setData(ClipboardData( - text: GetStorage() - .read(kStoredLastUpdateNotif) - .toString())) - .then((value) => Fluttertoast.showToast( - msg: 'Copied millis')); - }, + ) + ], ), - ListTile( - title: Text('Number of scheduled notification'), - subtitle: Text(GetStorage() - .read(kNumberOfNotifsScheduled) - .toString()), - ) - ], + ), + ); + } + }, + child: FittedBox( + fit: BoxFit.scaleDown, + child: Hero( + tag: kAppIconTag, + child: CachedNetworkImage( + width: 70, + imageUrl: kAppIconUrl, + progressIndicatorBuilder: + (context, url, downloadProgress) => + CircularProgressIndicator( + value: downloadProgress.progress), + errorWidget: (context, url, error) => + Icon(Icons.error), ), ), - ); - } - }, - child: FittedBox( - fit: BoxFit.scaleDown, - child: Hero( - tag: kAppIconTag, - child: CachedNetworkImage( - width: 70, - imageUrl: kAppIconUrl, - progressIndicatorBuilder: - (context, url, downloadProgress) => - CircularProgressIndicator( - value: downloadProgress.progress), - errorWidget: (context, url, error) => Icon(Icons.error), ), ), - ), - ), - Text( - '\nMPT 2020', - textAlign: TextAlign.center, - ), - GestureDetector( - onLongPress: () { - Clipboard.setData(ClipboardData(text: appInfo.version)).then( - (value) => - Fluttertoast.showToast(msg: 'Copied version info')); - }, - child: Text( - '\nVersion ${appInfo.version}', - textAlign: TextAlign.center, - style: TextStyle(fontWeight: FontWeight.bold), - ), - ), - Text( - '\n© Copyright 2020-2021 Fareez Iqmal\n', - textAlign: TextAlign.center, - ), - Container( - padding: EdgeInsets.all(8), - decoration: BoxDecoration( - color: Theme.of(context).bottomAppBarColor, - borderRadius: BorderRadius.circular(10)), - child: Text( - 'Prayer time data are provided by Jabatan Kemajuan Islam Malaysia (JAKIM)', - style: TextStyle( - fontStyle: FontStyle.italic, - ), - textAlign: TextAlign.center, - ), - ), - SizedBox( - height: 8, - ), - Card( - child: ListTile( - title: Text( - 'Contribution and Support', + Text( + '\nMPT 2020', textAlign: TextAlign.center, ), - onTap: () { - Navigator.push( - context, - MaterialPageRoute( - builder: (BuildContext context) => - ContributionPage())); - }, - ), - ), - Card( - child: ListTile( - title: Text( - 'Privacy Policy', - textAlign: TextAlign.center, + GestureDetector( + onLongPress: () { + Clipboard.setData(ClipboardData(text: appInfo.version)) + .then((value) => Fluttertoast.showToast( + msg: 'Copied version info')); + }, + child: Text( + '\nVersion ${appInfo.version}', + textAlign: TextAlign.center, + style: TextStyle(fontWeight: FontWeight.bold), + ), ), - onTap: () { - LaunchUrl.normalLaunchUrl( - url: kPrivacyPolicyLink, useCustomTabs: true); - }, - ), - ), - Card( - child: ListTile( - title: Text( - 'Release Notes', + Text( + '\n© Copyright 2020-2021 Fareez Iqmal\n', textAlign: TextAlign.center, ), - onTap: () { - LaunchUrl.normalLaunchUrl( - url: kReleaseNotesLink, useCustomTabs: true); - }, - ), - ), - Card( - child: ListTile( - title: Text( - 'Open Source Licenses', - textAlign: TextAlign.center, + Container( + padding: EdgeInsets.all(8), + decoration: BoxDecoration( + color: Theme.of(context).bottomAppBarColor, + borderRadius: BorderRadius.circular(10)), + child: Text( + 'Prayer time data are provided by Jabatan Kemajuan Islam Malaysia (JAKIM)', + style: TextStyle( + fontStyle: FontStyle.italic, + ), + textAlign: TextAlign.center, + ), ), - onTap: () { - showLicensePage( - context: context, - applicationIcon: Hero( - tag: kAppIconTag, - child: CachedNetworkImage( - width: 70, - imageUrl: kAppIconUrl, - progressIndicatorBuilder: - (context, url, downloadProgress) => - CircularProgressIndicator( - value: downloadProgress.progress), - errorWidget: (context, url, error) => - Icon(Icons.error), - ), - )); - }, - ), - ), - Divider(height: 8), - Card( - child: ListTile( - title: Text('Twitter', textAlign: TextAlign.center), - onTap: () { - LaunchUrl.normalLaunchUrl(url: kDevTwitter); - }, - ), - ), - Card( - child: ListTile( - title: Text( - 'Dev logs', - textAlign: TextAlign.center, + SizedBox( + height: 8, ), - onTap: () { - LaunchUrl.normalLaunchUrl(url: kInstaStoryDevlog); - }, - ), - ) - ], + Card( + child: ListTile( + title: Text( + 'Contribution and Support', + textAlign: TextAlign.center, + ), + onTap: () { + Navigator.push( + context, + MaterialPageRoute( + builder: (BuildContext context) => + ContributionPage())); + }, + ), + ), + Card( + child: ListTile( + title: Text( + 'Privacy Policy', + textAlign: TextAlign.center, + ), + onTap: () { + LaunchUrl.normalLaunchUrl( + url: kPrivacyPolicyLink, useCustomTabs: true); + }, + ), + ), + Card( + child: ListTile( + title: Text( + 'Release Notes', + textAlign: TextAlign.center, + ), + onTap: () { + LaunchUrl.normalLaunchUrl( + url: kReleaseNotesLink, useCustomTabs: true); + }, + ), + ), + Card( + child: ListTile( + title: Text( + 'Open Source Licenses', + textAlign: TextAlign.center, + ), + onTap: () { + showLicensePage( + context: context, + applicationIcon: Hero( + tag: kAppIconTag, + child: CachedNetworkImage( + width: 70, + imageUrl: kAppIconUrl, + progressIndicatorBuilder: + (context, url, downloadProgress) => + CircularProgressIndicator( + value: downloadProgress.progress), + errorWidget: (context, url, error) => + Icon(Icons.error), + ), + )); + }, + ), + ), + Divider(height: 8), + Card( + child: ListTile( + title: Text('Twitter', textAlign: TextAlign.center), + onTap: () { + LaunchUrl.normalLaunchUrl(url: kDevTwitter); + }, + ), + ), + Card( + child: ListTile( + title: Text( + 'Dev logs', + textAlign: TextAlign.center, + ), + onTap: () { + LaunchUrl.normalLaunchUrl(url: kInstaStoryDevlog); + }, + ), + ) + ], + ); + }, ), ), ), diff --git a/lib/views/Settings part/SettingsPage.dart b/lib/views/Settings part/SettingsPage.dart index 17694b3..6f8b3bf 100644 --- a/lib/views/Settings part/SettingsPage.dart +++ b/lib/views/Settings part/SettingsPage.dart @@ -5,6 +5,7 @@ import 'package:provider/provider.dart'; import 'package:waktusolatmalaysia/utils/navigator_pop.dart'; import '../../CONSTANTS.dart' as Constants; +import '../../CONSTANTS.dart'; import '../../utils/AppInformation.dart'; import '../../utils/cupertinoSwitchListTile.dart'; import '../Settings%20part/AboutPage.dart'; @@ -53,56 +54,10 @@ class _SettingsPageState extends State { Padding(padding: const EdgeInsets.all(8.0), child: Text('More')), // SizedBox(height: 5), buildAboutApp(context), - Opacity( - opacity: .4, - child: Card( - child: ListTile( - title: Text('Verbose debug mode (IGNORE)'), - subtitle: Text('For developer purposes'), - onTap: () { - print('VERBOSE DEBUG MODE'); - showDialog( - context: context, - builder: (context) { - return AlertDialog( - title: Text( - GetStorage().read(Constants.kIsDebugMode) - ? 'Verbose debug mode is ON' - : 'Verbose debug mode is OFF'), - content: Text( - 'Toast message or similar will show throughout usage of the app'), - actions: [ - TextButton( - onPressed: () { - Navigator.of(context, rootNavigator: true) - .pop(); - }, - child: Text('Cancel')), - TextButton( - onPressed: () { - print('PROCEED'); - //inverse if false then become true & vice versa - GetStorage().write( - Constants.kIsDebugMode, - !GetStorage() - .read(Constants.kIsDebugMode)); - CustomNavigatorPop.popTo(context, 2); - }, - child: GetStorage() - .read(Constants.kIsDebugMode) - ? Text('Turn off') - : Text( - 'Turn on', - style: TextStyle(color: Colors.red), - )) - ], - ); - }, - ); - }, - ), - ), - ) + + setting.isDeveloperOption + ? buildVerboseDebugMode(context) + : Container(), ], ); }, @@ -110,6 +65,51 @@ class _SettingsPageState extends State { ); } + Card buildVerboseDebugMode(BuildContext context) { + return Card( + child: ListTile( + title: Text('Verbose debug mode'), + subtitle: Text('For developer purposes'), + onTap: () { + print('VERBOSE DEBUG MODE'); + showDialog( + context: context, + builder: (context) { + return AlertDialog( + title: Text(GetStorage().read(Constants.kIsDebugMode) + ? 'Verbose debug mode is ON' + : 'Verbose debug mode is OFF'), + content: Text( + 'Toast message or similar will show throughout usage of the app'), + actions: [ + TextButton( + onPressed: () { + Navigator.of(context, rootNavigator: true).pop(); + }, + child: Text('Cancel')), + TextButton( + onPressed: () { + print('PROCEED'); + //inverse if false then become true & vice versa + GetStorage().write(Constants.kIsDebugMode, + !GetStorage().read(Constants.kIsDebugMode)); + CustomNavigatorPop.popTo(context, 2); + }, + child: GetStorage().read(Constants.kIsDebugMode) + ? Text('Turn off') + : Text( + 'Turn on', + style: TextStyle(color: Colors.red), + )) + ], + ); + }, + ); + }, + ), + ); + } + Card buildAboutApp(BuildContext context) { return Card( child: ListTile( diff --git a/lib/views/Settings part/settingsProvider.dart b/lib/views/Settings part/settingsProvider.dart index 80d4001..52e8307 100644 --- a/lib/views/Settings part/settingsProvider.dart +++ b/lib/views/Settings part/settingsProvider.dart @@ -6,6 +6,7 @@ import '../../CONSTANTS.dart'; class SettingProvider with ChangeNotifier { bool _use12hour = GetStorage().read(kStoredTimeIs12); bool _showOtherPrayerTime = GetStorage().read(kStoredShowOtherPrayerTime); + bool _isDeveloperOption = GetStorage().read(kDiscoveredDeveloperOption); set use12hour(newValue) { _use12hour = newValue; @@ -20,4 +21,11 @@ class SettingProvider with ChangeNotifier { } bool get showOtherPrayerTime => _showOtherPrayerTime; + + set isDeveloperOption(newValue) { + _isDeveloperOption = newValue; + notifyListeners(); + } + + bool get isDeveloperOption => _isDeveloperOption; }