Skip to content

Commit

Permalink
➕ auto_start_flutter. Attempt to fix #89 #106 etc.
Browse files Browse the repository at this point in the history
Added package to detect if autostart setting is available in app. Show necessary UI
  • Loading branch information
iqfareez committed May 7, 2022
1 parent 749834e commit 3dcd167
Show file tree
Hide file tree
Showing 6 changed files with 134 additions and 26 deletions.
21 changes: 19 additions & 2 deletions lib/l10n/app_en.arb
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@
"qiblaWarnBody": "- Users must understand that Qibla Compass feature utilises the sensors of the user's device and does not use any data from JAKIM. Therefore, users should **wisely evaluate** the information obtained.\n- MPT app provides this function as a **guide** only. MPT app is not responsible if the information obtained is inaccurate. Please refer to the recommended way to get the exact Qibla direction.\n- To improve the accuracy, make sure the internet and GPS connection are stable and perform the calibration by rotating your device in an **8** or **infinity** shape as below:",
"qiblaWarnProceed": "I understood",
"qiblaTitle": "Qibla Compass",
"qiblaOverheadWarn": "Align both arrow head.\nDo not put device close to metal object.",
"qiblaOverheadWarn": "Avoid placing the device close to metal object or electrical appliances.",
"qiblaCopyUrl": "URL copied :)",
"qiblaCalibrationTip": "Calibration tip",
"qiblaCalibrate": "Move your phone in 'figure 8 pattern'",
Expand Down Expand Up @@ -203,6 +203,15 @@
"onboardingNotifOption": "Select notification preferences",
"onboardingNotifDefault": "Default notification sound",
"onboardingNotifAzan": "Azan notification",
"onboardingNotifAutostart": "**Autostart** need to be enabled for the app to send notifications. [Learn more...]({link})",
"@onboardingNotifAutostart": {
"placeholders": {
"link": {
"type": "String"
}
}
},
"onboardingNotifAutostartSetting": "Open Settings",
"onboardingFinish": "Alhamdulillah. All set",
"onboardingFinishDesc": "Welcome abroad. Do explore other features and tweak other settings as well.",
"onboardingDone": "Done",
Expand Down Expand Up @@ -270,10 +279,18 @@
"contributeSourceDesc": "MPT app is open source. Report any bugs or contribute directly to the source code. It is licensed under GNU GPLv3.",
"contributeOpenGh": "Open GitHub",
"contributeCopied": "Copied to clipboard",
"notifTsAdmonition": "Your device may not be affected with this particular issue.",
"notifTsPara1": "Some apps installed from the **Google Play Store** will disable **Autostart** by default. Due to this behaviour, prayer notification (sometimes) will not appear on your phone.",
"notifTsPara2": "The solution is to enable **Autostart** for this app. Tap the button below to open App Setting, then find the Autostart option there to enable it.",
"notifTsPara3": "To learn more, kindly read [this article]({link}).",
"@notifTsPara3": {
"placeholders": {
"link": {
"type": "String"
}
}
},
"notifTsOpenSetting": "Open App Setting",
"notifTsRelatedArticle": "Related Article:",
"notifMonthlyReminderTitle": "Monthly refresh reminder",
"notifMonthlyReminderDesc": "To continue receive prayer notification, open app at least once every month.",
"notifItsTime": "It's {name}",
Expand Down
7 changes: 5 additions & 2 deletions lib/l10n/app_ms.arb
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@
"qiblaWarnBody": "- Pengguna harus faham yang fungsi ini menggunakan penderia peranti pengguna sepenuhnya dan tidak menggunakan apa apa data atau maklumat dari JAKIM. Jadi, pengguna seharusnya **arif menilai** maklumat yang diperolehi.\n- Apl MPT menyediakan fungsi ini sebagai **panduan** sahaja. Apl MPT tidak bertanggungjawab sekiranya maklumat yang diperolehi tidak tepat. Sila rujuk cara yang disyorkan untuk mendapatkan arah Qiblat yang tepat.\n- Untuk meningkatkan ketepatan fungsi ini, sila pastikan sambungan internet dan GPS yang stabil dan laksanakan kalibrasi dengan memusingkan peranti anda dalam bentuk **8** atau **infiniti** seperti di bawah.",
"qiblaWarnProceed": "Saya faham",
"qiblaTitle": "Kompas kiblat",
"qiblaOverheadWarn": "Selarikan kedua-dua kepala anak panah.\nJangan letakkan peranti berdekatan dengan objek logam.",
"qiblaOverheadWarn": "Elakkan meletakkan peranti berdekatan dengan objek logam atau peralatan elektrik.",
"qiblaCopyUrl": "Pautan disalin :)",
"qiblaCalibrationTip": "Tip kalibrasi",
"qiblaCalibrate": "Gerakkan telefon anda dalam 'corak angka 8'",
Expand Down Expand Up @@ -128,6 +128,8 @@
"onboardingNotifOption": "Pilih jenis pemberitahuan",
"onboardingNotifDefault": "Bunyi pemberitahuan lalai",
"onboardingNotifAzan": "Pemberitahuan azan",
"onboardingNotifAutostart": "**Autostart** perlu dihidupkan untuk apl menghantar pemberitahuan. [Ketahui lebih lanjut..]({link})",
"onboardingNotifAutostartSetting": "Buka Settings",
"onboardingFinish": "Alhamdulillah. Selesai tetapan.",
"onboardingFinishDesc": "Selamat datang. Terokai ciri dan ubah suai tetapan lain mengikut citarasa anda.",
"onboardingDone": "Selesai",
Expand Down Expand Up @@ -181,10 +183,11 @@
"contributeSourceDesc": "Apl MPT ialah sumber terbuka. Laporkan sebarang pepijat atau sumbangkan terus kepada kod sumber. Ia dilesenkan di bawah GNU GPLv3.",
"contributeOpenGh": "Buka GitHub",
"contributeCopied": "Disalin ke papan keratan",
"notifTsAdmonition": "Peranti anda mungkin tidak terjejas dengan isu khusus ini.",
"notifTsPara1": "Sesetengah apl yang dipasang daripada **Gedung Google Play**, **Autostart** akan dilumpuhkan secara lalai. Disebabkan hal ini, pemberitahuan (kadang-kadang) tidak akan keluar pada telefon anda.",
"notifTsPara2": "Penyelesaiannya adalah untuk menghidupkan **Autostart** untuk apl ini. Ketik butang di bawah untuk membuka Tetapan Apl, kemudian cari pilihan Autostart untuk menghidupkannya.",
"notifTsPara3": "Untuk ketahui lebih lanjut, sila ikuti [artikel ini]({link}).",
"notifTsOpenSetting": "Buka Tetapan Apl",
"notifTsRelatedArticle": "Artikel Berkaitan:",
"notifMonthlyReminderTitle": "Peringatan bulanan segar semula",
"notifMonthlyReminderDesc": "Untuk terus menerima pemberitahuan, buka aplikasi sekurang-kurangnya sekali setiap bulan.",
"notifItsTime": "Telah masuk waktu {name}",
Expand Down
68 changes: 47 additions & 21 deletions lib/views/Settings part/troubleshoot_notif.dart
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
import 'package:app_settings/app_settings.dart';
import 'package:auto_start_flutter/auto_start_flutter.dart';
import 'package:flutter/material.dart';
import 'package:flutter_gen/gen_l10n/app_localizations.dart';
import 'package:flutter_markdown/flutter_markdown.dart';
import 'package:font_awesome_flutter/font_awesome_flutter.dart';

import '../../utils/launchUrl.dart';
final _mdStyleSheet = MarkdownStyleSheet(
textAlign: WrapAlignment.spaceAround, textScaleFactor: 1.1);

class TroubleshootNotif extends StatelessWidget {
const TroubleshootNotif({Key? key}) : super(key: key);
Expand All @@ -17,17 +20,23 @@ class TroubleshootNotif extends StatelessWidget {
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
MarkdownBody(
data: AppLocalizations.of(context)!.notifTsPara1,
styleSheet: MarkdownStyleSheet(
textAlign: WrapAlignment.spaceAround, textScaleFactor: 1.2),
FutureBuilder<bool?>(
future: isAutoStartAvailable,
builder: (_, snapshot) {
if (snapshot.hasData && snapshot.data!) {
return const SizedBox.shrink();
}

return const _DeviceOKAdmonition();
},
),
MarkdownBody(
data: AppLocalizations.of(context)!.notifTsPara1,
styleSheet: _mdStyleSheet),
const SizedBox(height: 5),
MarkdownBody(
data: AppLocalizations.of(context)!.notifTsPara2,
styleSheet: MarkdownStyleSheet(
textAlign: WrapAlignment.spaceAround, textScaleFactor: 1.2),
),
data: AppLocalizations.of(context)!.notifTsPara2,
styleSheet: _mdStyleSheet),
const SizedBox(height: 5),
Card(
child: ListTile(
Expand All @@ -36,23 +45,40 @@ class TroubleshootNotif extends StatelessWidget {
trailing: const Icon(Icons.launch_rounded),
),
),
const SizedBox(height: 10),
Text(
AppLocalizations.of(context)!.notifTsRelatedArticle,
style: const TextStyle(fontWeight: FontWeight.bold),
const SizedBox(height: 5),
MarkdownBody(
data: AppLocalizations.of(context)!.notifTsPara3(
'https://mywaktusolat.vercel.com/notifications'),
),
TextButton(
onPressed: () {
LaunchUrl.normalLaunchUrl(
url:
'https://telegra.ph/Notification-didnt-show-on-some-devices-07-31');
},
child:
const Text('Notification didn\'t show on some devices'))
],
),
),
),
);
}
}

class _DeviceOKAdmonition extends StatelessWidget {
const _DeviceOKAdmonition({Key? key}) : super(key: key);

@override
Widget build(BuildContext context) {
return Container(
padding: const EdgeInsets.all(14),
margin: const EdgeInsets.only(bottom: 10),
decoration: BoxDecoration(
color: Colors.green.withOpacity(.3),
borderRadius: BorderRadius.circular(16)),
child: Row(
mainAxisSize: MainAxisSize.min,
children: [
const FaIcon(FontAwesomeIcons.check),
const SizedBox(width: 15),
Flexible(
child: Text(AppLocalizations.of(context)!.notifTsAdmonition),
)
],
),
);
}
}
54 changes: 54 additions & 0 deletions lib/views/onboarding_page.dart
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
import 'package:flutter/material.dart';
import 'package:flutter_gen/gen_l10n/app_localizations.dart';
import 'package:flutter_markdown/flutter_markdown.dart';
import 'package:get_storage/get_storage.dart';
import 'package:introduction_screen/introduction_screen.dart';
import 'package:auto_start_flutter/auto_start_flutter.dart';
import 'package:provider/provider.dart';
import '../providers/locale_provider.dart';

import '../CONSTANTS.dart';
import '../main.dart';
import '../utils/launchUrl.dart';
import 'Settings part/NotificationSettingPage.dart';
import 'Settings%20part/ThemePage.dart';
import 'ZoneChooser.dart';
Expand All @@ -28,6 +31,7 @@ class _OnboardingPageState extends State<OnboardingPage>
);

bool _isDoneSetLocation = false;

AnimationController? _animController;
MyNotificationType _notificationType =
MyNotificationType.values.elementAt(GetStorage().read(kNotificationType));
Expand Down Expand Up @@ -139,6 +143,15 @@ class _OnboardingPageState extends State<OnboardingPage>
GetStorage().write(kNotificationType, type?.index);
setState(() => _notificationType = type!);
}),
FutureBuilder<bool?>(
future: isAutoStartAvailable,
builder: (_, snapshot) {
if (snapshot.hasData && snapshot.data!) {
return const _AutostartAdmonition();
}

return const SizedBox.shrink();
})
]),
),
PageViewModel(
Expand Down Expand Up @@ -176,3 +189,44 @@ class _OnboardingPageState extends State<OnboardingPage>
});
}
}

class _AutostartAdmonition extends StatelessWidget {
const _AutostartAdmonition({
Key? key,
}) : super(key: key);

@override
Widget build(BuildContext context) {
return Container(
padding: const EdgeInsets.fromLTRB(14, 14, 14, 2),
margin: const EdgeInsets.only(top: 15),
decoration: BoxDecoration(
color: Colors.amber.withOpacity(.3),
borderRadius: BorderRadius.circular(16)),
child: Column(
children: [
MarkdownBody(
data: AppLocalizations.of(context)!.onboardingNotifAutostart(
'https://mywaktusolat.vercel.com/notifications'),
onTapLink: (_, href, __) {
LaunchUrl.normalLaunchUrl(url: href!);
},
),
Align(
alignment: Alignment.topRight,
child: TextButton(
style: TextButton.styleFrom(
tapTargetSize: MaterialTapTargetSize.shrinkWrap,
primary: Theme.of(context).textTheme.bodyLarge!.color),
onPressed: () {
// open auto start setting
getAutoStartPermission();
},
child: Text(AppLocalizations.of(context)!
.onboardingNotifAutostartSetting)),
),
],
),
);
}
}
7 changes: 7 additions & 0 deletions pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,13 @@ packages:
url: "https://pub.dartlang.org"
source: hosted
version: "2.8.2"
auto_start_flutter:
dependency: "direct main"
description:
name: auto_start_flutter
url: "https://pub.dartlang.org"
source: hosted
version: "0.1.0"
boolean_selector:
dependency: transitive
description:
Expand Down
3 changes: 2 additions & 1 deletion pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ description: App waktu solat seluruh Malaysia

publish_to: "none" # Remove this line if you wish to publish to pub.dev

version: 2.4.2-pre.1+99
version: 2.4.2-pre.2+100

environment:
sdk: ">=2.12.0 <3.0.0"
Expand Down Expand Up @@ -46,6 +46,7 @@ dependencies:
grouped_list: ^4.1.0
flutter_markdown: ^0.6.9
firebase_analytics: ^9.1.2
auto_start_flutter: ^0.1.0

dependency_overrides:
# flutter compass in pub.dev is not updated
Expand Down

0 comments on commit 3dcd167

Please sign in to comment.