diff --git a/android/app/src/main/java/com/didvan/didvanapp/FavWidget.kt b/android/app/src/main/java/com/didvan/didvanapp/FavWidget.kt index c4bc6d0..300d3fa 100644 --- a/android/app/src/main/java/com/didvan/didvanapp/FavWidget.kt +++ b/android/app/src/main/java/com/didvan/didvanapp/FavWidget.kt @@ -5,6 +5,9 @@ import android.appwidget.AppWidgetManager import android.content.Context import android.content.SharedPreferences import android.net.Uri +import android.view.View.GONE +import android.view.View.INVISIBLE +import android.view.View.VISIBLE import android.widget.RemoteViews import com.squareup.picasso.MemoryPolicy import com.squareup.picasso.NetworkPolicy @@ -12,6 +15,7 @@ import com.squareup.picasso.Picasso import com.squareup.picasso.Transformation import es.antonborri.home_widget.HomeWidgetLaunchIntent import es.antonborri.home_widget.HomeWidgetProvider +import es.antonborri.home_widget.HomeWidgetBackgroundIntent import java.lang.Exception @@ -40,107 +44,114 @@ class FavWidget : HomeWidgetProvider() { val responses: ArrayList = ArrayList(); val token = widgetData.getString("token", "").toString() - for (i in 0..2) { - responses.add( - WidgetResponse( - id = widgetData.getString("id${i + 1}", "")?.toInt() ?: 0, - title = widgetData.getString("title${i + 1}", "").toString(), - createdAt = widgetData.getString("createdAt${i + 1}", "").toString(), - type = widgetData.getString("type${i + 1}", "").toString(), - link = widgetData.getString("link${i + 1}", "").toString(), - category = widgetData.getString("category${i + 1}", "").toString(), - image = widgetData.getString("image${i + 1}", "").toString(), + if (token.isEmpty()) { + setViewVisibility(R.id.list_lay, INVISIBLE) + setViewVisibility(R.id.setting_btn, INVISIBLE) + setViewVisibility(R.id.empty_lay, VISIBLE) + setOnClickPendingIntent(R.id.empty_lay, pendingIntent) + + + } else { + setViewVisibility(R.id.list_lay, VISIBLE) + setViewVisibility(R.id.setting_btn, VISIBLE) + setViewVisibility(R.id.empty_lay, GONE) + + for (i in 0..2) { + responses.add( + WidgetResponse( + id = widgetData.getString("id${i + 1}", "")?.toInt() ?: 0, + title = widgetData.getString("title${i + 1}", "").toString(), + createdAt = widgetData.getString("createdAt${i + 1}", "") + .toString(), + type = widgetData.getString("type${i + 1}", "").toString(), + link = widgetData.getString("link${i + 1}", "").toString(), + category = widgetData.getString("category${i + 1}", "").toString(), + image = widgetData.getString("image${i + 1}", "").toString(), + ) ) - ) - } + } - setTextViewText(R.id.first_title, responses[0].title.toString()) - setTextViewText(R.id.middle_title, responses[1].title.toString()) - setTextViewText(R.id.last_title, responses[2].title.toString()) + setTextViewText(R.id.first_title, responses[0].title.toString()) + setTextViewText(R.id.middle_title, responses[1].title.toString()) + setTextViewText(R.id.last_title, responses[2].title.toString()) // - setTextViewText(R.id.first_tag, responses[0].category) - setTextViewText(R.id.middle_tag, responses[1].category) - setTextViewText(R.id.last_tag, responses[2].category) + setTextViewText(R.id.first_tag, responses[0].category) + setTextViewText(R.id.middle_tag, responses[1].category) + setTextViewText(R.id.last_tag, responses[2].category) - setTextViewText(R.id.first_duration, responses[0].createdAt) - setTextViewText(R.id.middle_duration, responses[1].createdAt) - setTextViewText(R.id.last_duration, responses[2].createdAt) + setTextViewText(R.id.first_duration, responses[0].createdAt) + setTextViewText(R.id.middle_duration, responses[1].createdAt) + setTextViewText(R.id.last_duration, responses[2].createdAt) - try { - Picasso.get() - .load("https://api.didvan.app${responses[0].image}?accessToken=${token}") - .transform(RoundedTransformation(10, 0)) - .networkPolicy(NetworkPolicy.NO_STORE) - .memoryPolicy(MemoryPolicy.NO_STORE) - .error(R.drawable.test) - .resize(100,100) - .into(this, R.id.first_image, appWidgetIds); - } catch (e: Exception) { + try { + Picasso.get() + .load("https://api.didvan.app${responses[0].image}?accessToken=${token}") + .transform(RoundedTransformation(10, 0)) + .networkPolicy(NetworkPolicy.NO_STORE) + .memoryPolicy(MemoryPolicy.NO_STORE) + .error(R.drawable.test) + .resize(100, 100) + .into(this, R.id.first_image, appWidgetIds); + } catch (e: Exception) { + } + + try { + Picasso.get() + .load("https://api.didvan.app${responses[1].image}?accessToken=${token}") + .transform(RoundedTransformation(10, 0)) + .networkPolicy(NetworkPolicy.NO_STORE) + .memoryPolicy(MemoryPolicy.NO_STORE) + .error(R.drawable.test) + .resize(100, 100) + .into(this, R.id.middle_image, appWidgetIds); + } catch (e: Exception) { + + } + + try { + Picasso.get() + .load("https://api.didvan.app${responses[2].image}?accessToken=${token}") + .transform(RoundedTransformation(10, 0)) + .networkPolicy(NetworkPolicy.NO_STORE) + .memoryPolicy(MemoryPolicy.NO_STORE) + .error(R.drawable.test) + .resize(100, 100) + .into(this, R.id.last_image, appWidgetIds); + } catch (e: Exception) { + + } + + + // Pending intent to update counter on button click + val settingIntent = HomeWidgetBackgroundIntent.getBroadcast( + context, Uri.parse("myAppWidget://setting") + + ) + setOnClickPendingIntent(R.id.setting_btn, settingIntent) + + val rowFirst = HomeWidgetBackgroundIntent.getBroadcast( + context, + Uri.parse("myAppWidget://rowFirst") + + ) + setOnClickPendingIntent(R.id.first_row, rowFirst) + + val rowMiddle = HomeWidgetBackgroundIntent.getBroadcast( + context, + Uri.parse("myAppWidget://rowMiddle") + + ) + setOnClickPendingIntent(R.id.middle_row, rowMiddle) + + val rowLast = HomeWidgetBackgroundIntent.getBroadcast( + context, + Uri.parse("myAppWidget://rowLast") + + ) + setOnClickPendingIntent(R.id.last_row, rowLast) } - try { - Picasso.get() - .load("https://api.didvan.app${responses[1].image}?accessToken=${token}") - .transform(RoundedTransformation(10, 0)) - .networkPolicy(NetworkPolicy.NO_STORE) - .memoryPolicy(MemoryPolicy.NO_STORE) - .error(R.drawable.test) - .resize(100,100) - .into(this, R.id.middle_image, appWidgetIds); - } catch (e: Exception) { - - } - - try { - Picasso.get() - .load("https://api.didvan.app${responses[2].image}?accessToken=${token}") - .transform(RoundedTransformation(10, 0)) - .networkPolicy(NetworkPolicy.NO_STORE) - .memoryPolicy(MemoryPolicy.NO_STORE) - .error(R.drawable.test) - .resize(100,100) - .into(this, R.id.last_image, appWidgetIds); - } catch (e: Exception) { - - } - - - // Pending intent to update counter on button click - val settingIntent = HomeWidgetLaunchIntent.getActivity( - context, - MainActivity::class.java, - Uri.parse("myAppWidget://setting"), - - ) - setOnClickPendingIntent(R.id.setting_btn, settingIntent) - - val rowFirst = HomeWidgetLaunchIntent.getActivity( - context, - MainActivity::class.java, - - Uri.parse("myAppWidget://rowFirst"), - - ) - setOnClickPendingIntent(R.id.first_row, rowFirst) - - val rowMiddle = HomeWidgetLaunchIntent.getActivity( - context, - MainActivity::class.java, - - Uri.parse("myAppWidget://rowMiddle"), - - ) - setOnClickPendingIntent(R.id.middle_row, rowMiddle) - - val rowLast = HomeWidgetLaunchIntent.getActivity( - context, - MainActivity::class.java, - - Uri.parse("myAppWidget://rowLast"), - - ) - setOnClickPendingIntent(R.id.last_row, rowLast) } appWidgetManager.updateAppWidget(widgetId, views) diff --git a/android/app/src/main/res/drawable/chat_light.xml b/android/app/src/main/res/drawable/chat_light.xml new file mode 100644 index 0000000..724bf13 --- /dev/null +++ b/android/app/src/main/res/drawable/chat_light.xml @@ -0,0 +1,184 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/android/app/src/main/res/layout/favourite_widget.xml b/android/app/src/main/res/layout/favourite_widget.xml index eb628b0..785bcb1 100644 --- a/android/app/src/main/res/layout/favourite_widget.xml +++ b/android/app/src/main/res/layout/favourite_widget.xml @@ -9,7 +9,7 @@ + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - /> + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/lib/main.dart b/lib/main.dart index d81b413..af419b0 100644 --- a/lib/main.dart +++ b/lib/main.dart @@ -6,10 +6,9 @@ import 'package:didvan/providers/theme.dart'; import 'package:didvan/providers/user.dart'; import 'package:didvan/routes/route_generator.dart'; import 'package:didvan/routes/routes.dart'; -import 'package:didvan/services/network/request.dart'; +import 'package:didvan/services/app_home_widget/home_widget_repository.dart'; import 'package:didvan/services/notification/awsome/awsome_notification_handler.dart'; import 'package:didvan/services/notification/fcm/firebase_notification_handler.dart'; -import 'package:didvan/utils/action_sheet.dart'; import 'package:didvan/views/podcasts/podcasts_state.dart'; import 'package:didvan/views/podcasts/studio_details/studio_details_state.dart'; import 'package:firebase_core/firebase_core.dart'; @@ -19,12 +18,6 @@ import 'package:flutter/material.dart'; import 'package:flutter_localizations/flutter_localizations.dart'; import 'package:home_widget/home_widget.dart'; import 'package:provider/provider.dart'; -import 'package:url_launcher/url_launcher_string.dart'; - -import 'models/requests/infography.dart'; -import 'models/requests/news.dart'; -import 'models/requests/radar.dart'; -import 'models/widget_response.dart'; final GlobalKey navigatorKey = GlobalKey(); @@ -48,9 +41,20 @@ Future _firebaseMessagingBackgroundHandler(RemoteMessage message) async { projectId: 'didvan-9b7da', ), ); - - // AwsomeNotificationHandler().alarm(); AwsomeNotificationHandler().show(message); + return; +} + +@pragma('vm:entry-point') +Future _backgroundCallbackHomeWidget(Uri? uri) async { + await HomeWidget.saveWidgetData("uri", uri!.host); + AndroidIntent intent = const AndroidIntent( + action: 'android.intent.action.RUN', + package: 'com.didvan.didvanapp', + componentName: 'com.didvan.didvanapp.MainActivity', + ); + await intent.launch(); + return; } void main() async { @@ -59,10 +63,9 @@ void main() async { FirebaseMessaging.onBackgroundMessage(_firebaseMessagingBackgroundHandler); FirebaseMessaging.onMessage.listen( (RemoteMessage message) => AwsomeNotificationHandler().show(message)); - //ignore: deprecated_member_use - HomeWidget.registerBackgroundCallback(backgroundCallback); - HomeWidget.registerInteractivityCallback(backgroundCallback); + HomeWidget.registerBackgroundCallback(_backgroundCallbackHomeWidget); + HomeWidget.registerInteractivityCallback(_backgroundCallbackHomeWidget); AwsomeNotificationHandler().alarm(); FirebaseNotificationHandler().initial(); } catch (e) { @@ -72,17 +75,6 @@ void main() async { runApp(const Didvan()); } -Future backgroundCallback(Uri? uri) async { - AndroidIntent intent = const AndroidIntent( - action: 'android.intent.action.RUN', - package: 'com.didvan.didvanapp', - componentName: 'com.didvan.didvanapp.MainActivity', - ); - await intent.launch(); - HomeWidget.saveWidgetData("uri", uri!.host); - -} - class Didvan extends StatefulWidget { const Didvan({Key? key}) : super(key: key); @@ -91,17 +83,20 @@ class Didvan extends StatefulWidget { } class _DidvanState extends State with WidgetsBindingObserver { + @override + void didChangeDependencies() { + super.didChangeDependencies(); + } + @override void initState() { super.initState(); - WidgetsBinding.instance.addObserver(this); } @override void dispose() { WidgetsBinding.instance.removeObserver(this); - super.dispose(); } @@ -109,122 +104,11 @@ class _DidvanState extends State with WidgetsBindingObserver { @override void didChangeAppLifecycleState(AppLifecycleState state) async { - HomeWidget.widgetClicked.listen((event) { - print("${event!.host}--------------------------------------------------------------"); - }); - if (state == AppLifecycleState.paused) { - b = false; - } if (state == AppLifecycleState.resumed) { - - await HomeWidget.getWidgetData('uri', defaultValue: "") - .then((value) async { - if (value!.isNotEmpty) { - int row = 0; - String route = ""; - dynamic args; - switch (value) { - case 'setting': - route = Routes.favouritesStep; - args = {"toTimer": false}; - break; - case 'rowfirst': - row = 1; - break; - case 'rowmiddle': - row = 2; - break; - case 'rowlast': - row = 3; - break; - } - - if (row != 0) { - String? id = await HomeWidget.getWidgetData("id$row", - defaultValue: ""); - WidgetResponse data = WidgetResponse( - id: int.parse(id!), - title: - await HomeWidget.getWidgetData("title$row", defaultValue: ""), - createdAt: await HomeWidget.getWidgetData("createdAt$row", - defaultValue: ""), - type: - await HomeWidget.getWidgetData("type$row", defaultValue: ""), - link: - await HomeWidget.getWidgetData("link$row", defaultValue: ""), - category: await HomeWidget.getWidgetData("category$row", - defaultValue: ""), - image: - await HomeWidget.getWidgetData("image$row", defaultValue: ""), - ); - - if (data.link!.isEmpty) { - switch (data.type!) { - case "infography": - route = Routes.infography; - args = { - // 'onMarkChanged': (id, value) => - // markChangeHandler(data.type, id, value), - 'id': data.id, - 'args': const InfographyRequestArgs(page: 0), - 'hasUnmarkConfirmation': false, - }; - break; - case "news": - route = Routes.newsDetails; - args = { - // 'onMarkChanged': (id, value) => - // markChangeHandler(data.type, id, value), - 'id': data.id, - 'args': const NewsRequestArgs(page: 0), - 'hasUnmarkConfirmation': false, - }; - break; - case "radar": - route = Routes.radarDetails; - args = { - // 'onMarkChanged': (id, value) => - // markChangeHandler(data.type, id, value), - 'id': data.id, - 'args': const RadarRequestArgs(page: 0), - 'hasUnmarkConfirmation': false, - }; - break; - case "video": - route = Routes.studioDetails; - args = { - 'type': 'podcast', - 'id': data.id, - }; - break; - case "podcast": - route = Routes.podcasts; - args = { - 'type': 'podcast', - 'id': data.id, - }; - break; - } - } else { - if (data.link!.startsWith('http')) { - launchUrlString( - '${data.link}', - mode: LaunchMode.inAppWebView, - ); - } - } - } - - if (route.isNotEmpty) { - !b ? ActionSheetUtils.showLogoLoadingIndicator() : null; - await Future.delayed(Duration(seconds: b ? 10 : 2), () { - !b ? ActionSheetUtils.pop() : null; - navigatorKey.currentState!.pushNamed(route, arguments: args); - }); - } - } - }); - HomeWidget.saveWidgetData("uri", ""); + var r = await HomeWidget.getWidgetData("cRoute", defaultValue: ''); + if (r!.toString() != Routes.splash) { + await HomeWidgetRepository.decideWhereToGo(); + } } } diff --git a/lib/routes/route_generator.dart b/lib/routes/route_generator.dart index 0b39708..185fb63 100644 --- a/lib/routes/route_generator.dart +++ b/lib/routes/route_generator.dart @@ -48,15 +48,17 @@ import 'package:didvan/views/splash/splash.dart'; import 'package:didvan/routes/routes.dart'; import 'package:flutter/foundation.dart'; import 'package:flutter/material.dart'; +import 'package:home_widget/home_widget.dart'; import 'package:provider/provider.dart'; import '../views/customize_category/notification_status_step.dart'; import '../views/notification_time/notification_time.dart'; class RouteGenerator { - static Route generateRoute(RouteSettings settings) { - switch (settings.name) { + static Route generateRoute(RouteSettings settings) { + HomeWidget.saveWidgetData("cRoute", settings.name!); + switch (settings.name) { case Routes.splash: return _createRoute( const Splash(), diff --git a/lib/services/app_home_widget/home_widget_repository.dart b/lib/services/app_home_widget/home_widget_repository.dart index 5c6ec00..c965ba2 100644 --- a/lib/services/app_home_widget/home_widget_repository.dart +++ b/lib/services/app_home_widget/home_widget_repository.dart @@ -1,17 +1,23 @@ +import 'package:flutter/cupertino.dart'; import 'package:home_widget/home_widget.dart'; import 'package:persian_number_utility/persian_number_utility.dart'; +import 'package:url_launcher/url_launcher_string.dart'; +import '../../main.dart'; +import '../../models/requests/infography.dart'; +import '../../models/requests/news.dart'; +import '../../models/requests/radar.dart'; import '../../models/widget_response.dart'; +import '../../routes/routes.dart'; import '../network/request.dart'; import '../network/request_helper.dart'; class HomeWidgetRepository { - Future fetchWidget() async { + static Future fetchWidget() async { final service = RequestService( RequestHelper.widgetNews(), ); await service.httpGet(); - List responseList = []; if (service.isSuccess) { final favourites = service.data('content'); HomeWidget.saveWidgetData("token", RequestService.token.toString()); @@ -40,4 +46,109 @@ class HomeWidgetRepository { ); } } + + static Future decideWhereToGo() async { + String? uri = + await HomeWidget.getWidgetData('uri', defaultValue: ""); + if (uri!.isNotEmpty) { + int row = 0; + String route = ""; + dynamic args; + switch (uri) { + case 'setting': + route = Routes.favouritesStep; + args = {"toTimer": false}; + break; + case 'rowfirst': + row = 1; + break; + case 'rowmiddle': + row = 2; + break; + case 'rowlast': + row = 3; + break; + } + + if (row != 0) { + String? id = + await HomeWidget.getWidgetData("id$row", defaultValue: ""); + WidgetResponse data = WidgetResponse( + id: int.parse(id!), + title: await HomeWidget.getWidgetData("title$row", defaultValue: ""), + createdAt: + await HomeWidget.getWidgetData("createdAt$row", defaultValue: ""), + type: await HomeWidget.getWidgetData("type$row", defaultValue: ""), + link: await HomeWidget.getWidgetData("link$row", defaultValue: ""), + category: + await HomeWidget.getWidgetData("category$row", defaultValue: ""), + image: await HomeWidget.getWidgetData("image$row", defaultValue: ""), + ); + + if (data.link!.startsWith('http')) { + launchUrlString( + '${data.link}', + mode: LaunchMode.inAppWebView, + ); + return; + } + + switch (data.type!) { + case "infography": + route = Routes.infography; + args = { + // 'onMarkChanged': (id, value) => + // markChangeHandler(data.type, id, value), + 'id': data.id, + 'args': const InfographyRequestArgs(page: 0), + 'hasUnmarkConfirmation': false, + }; + break; + case "news": + route = Routes.newsDetails; + args = { + // 'onMarkChanged': (id, value) => + // markChangeHandler(data.type, id, value), + 'id': data.id, + 'args': const NewsRequestArgs(page: 0), + 'hasUnmarkConfirmation': false, + }; + break; + case "radar": + route = Routes.radarDetails; + args = { + // 'onMarkChanged': (id, value) => + // markChangeHandler(data.type, id, value), + 'id': data.id, + 'args': const RadarRequestArgs(page: 0), + 'hasUnmarkConfirmation': false, + }; + break; + case "video": + route = Routes.studioDetails; + args = { + 'type': 'podcast', + 'id': data.id, + }; + break; + case "podcast": + route = Routes.podcasts; + args = { + 'type': 'podcast', + 'id': data.id, + }; + break; + } + } + + if (route.isNotEmpty) { + Future.delayed( + const Duration(milliseconds: 500), + () => Navigator.of(navigatorKey.currentContext!) + .pushNamed(route.toString(), arguments: args)); + } + } + await HomeWidget.saveWidgetData("uri", ""); + return; + } } diff --git a/lib/services/network/request.dart b/lib/services/network/request.dart index f0cbe90..e0bc80a 100644 --- a/lib/services/network/request.dart +++ b/lib/services/network/request.dart @@ -1,7 +1,6 @@ import 'dart:convert'; import 'dart:developer'; import 'package:didvan/services/storage/storage.dart'; -import 'package:home_widget/home_widget.dart'; // ignore: depend_on_referenced_packages import 'package:http/http.dart' as http; diff --git a/lib/services/notification/awsome/awsome_notification_controller.dart b/lib/services/notification/awsome/awsome_notification_controller.dart index e264924..74bbb40 100644 --- a/lib/services/notification/awsome/awsome_notification_controller.dart +++ b/lib/services/notification/awsome/awsome_notification_controller.dart @@ -7,7 +7,6 @@ import '../../../models/requests/infography.dart'; import '../../../models/requests/news.dart'; import '../../../models/requests/radar.dart'; import '../../../routes/routes.dart'; -import '../../network/request.dart'; class NotificationController { /// Use this method to detect when a new notification or a schedule is created @@ -90,6 +89,13 @@ class NotificationController { 'goToComment': openComments }; break; + case "podcast": + route = Routes.podcasts; + args = { + 'type': 'podcast', + 'id': data.id, + }; + break; } } else { if (data.link!.startsWith('http')) { diff --git a/lib/services/notification/awsome/awsome_notification_handler.dart b/lib/services/notification/awsome/awsome_notification_handler.dart index d712468..67c53a4 100644 --- a/lib/services/notification/awsome/awsome_notification_handler.dart +++ b/lib/services/notification/awsome/awsome_notification_handler.dart @@ -12,7 +12,6 @@ import 'awsome_notification_controller.dart'; class AwsomeNotificationHandler { alarm() async { - late ReceivedAction? initialAction; AwesomeNotifications().initialize( // set the icon to null if you want to use the default app icon @@ -40,8 +39,6 @@ class AwsomeNotificationHandler { // ], debug: true); - initialAction = await AwesomeNotifications() - .getInitialNotificationAction(removeFromActionEvents: false); AwesomeNotifications().setListeners( onActionReceivedMethod: NotificationController.onActionReceivedMethod, @@ -85,7 +82,7 @@ class AwsomeNotificationHandler { break; case "3": - await HomeWidgetRepository().fetchWidget(); + await HomeWidgetRepository.fetchWidget(); break; @@ -162,9 +159,7 @@ class AwsomeNotificationHandler { payload: message.toPayload(), notificationLayout: NotificationLayout.BigPicture, color: const Color(0xFF007EA7)), - schedule: time.year != null - ? null - : NotificationCalendar( + schedule: NotificationCalendar( hour: time.hour, minute: time.minute, )); @@ -221,13 +216,13 @@ class AwsomeNotificationHandler { if (time.toString().isNotEmpty) { DateFormat format = DateFormat("HH:mm"); DateTime dateTime = format.parse(time); - result = DateTime.now() - .copyWith(hour: dateTime.hour, minute: dateTime.minute); + result = DateTime.now().copyWith(hour: dateTime.hour, minute: dateTime.minute); } return result; } }); + return null; } showNotificationScheduled(NotificationMessage message) async { diff --git a/lib/services/notification/fcm/firebase_notification_handler.dart b/lib/services/notification/fcm/firebase_notification_handler.dart index 066881c..69bb1a0 100644 --- a/lib/services/notification/fcm/firebase_notification_handler.dart +++ b/lib/services/notification/fcm/firebase_notification_handler.dart @@ -1,4 +1,3 @@ -import 'package:didvan/services/notification/awsome/awsome_notification_handler.dart'; import 'package:firebase_core/firebase_core.dart'; import 'package:firebase_messaging/firebase_messaging.dart'; import 'package:flutter/cupertino.dart'; @@ -51,69 +50,11 @@ class FirebaseNotificationHandler { debugPrint( 'User granted notifications permission: ${settings.authorizationStatus}'); - // String? token = await FirebaseMessaging.instance.getToken(); - // print("Firebase Token : ${token.toString()}"); - - // Handling background messages using the specified handler - // FirebaseMessaging.onBackgroundMessage( - // _firebaseMessagingBackgroundHandler); - - // Listening for incoming messages while the app is in the foreground - - // Handling the initial message received when the app is launched from dead (killed state) - // When the app is killed and a new notification arrives when user clicks on it - // It gets the data to which screen to open - // FirebaseMessaging.instance.getInitialMessage().then((message) { - // if (message != null) { - // _handleNotificationClick(message); - // } - // }); - // - // // Handling a notification click event when the app is in the background - // FirebaseMessaging.onMessageOpenedApp.listen((RemoteMessage message) { - // _handleNotificationClick(message); - // }); } catch (e) { - print(e.toString()); + if (kDebugMode) { + print(e.toString()); + } } } - // Handling a notification click event by navigating to the specified screen - void _handleNotificationClick(RemoteMessage message) { - final notificationData = message.data; - - if (notificationData.containsKey('screen')) { - final screen = notificationData['screen']; - // Navigator.of(context).pushNamed(screen); - } - } } - -// Handler for background messages -// @pragma('vm:entry-point') -// Future _firebaseMessagingBackgroundHandler(RemoteMessage message) async { -// await Firebase.initializeApp( -// options: kIsWeb -// ? const FirebaseOptions( -// apiKey: "AIzaSyA0HZjKpRuPOi1SC3f_EZTvlS3mcj9UVo0", -// authDomain: "didvan-9b7da.firebaseapp.com", -// projectId: "didvan-9b7da", -// storageBucket: "didvan-9b7da.appspot.com", -// messagingSenderId: "935017686266", -// appId: "1:935017686266:web:a93f7a19bed23c51d2d543", -// measurementId: "G-80B4H9E8Y0") -// : const FirebaseOptions( -// apiKey: 'AIzaSyBp-UHjWeM0H0UHtX5yguFKG-riMzvvCzw', -// appId: '1:935017686266:android:f9cbc9aba8e3d65ed2d543', -// messagingSenderId: '935017686266', -// projectId: 'didvan-9b7da', -// ), -// ); -// -// LocalNotificationService.initialize(); -// LocalNotificationService.display(message); -// // AwsomeNotificationHandler().main(); -// // AwsomeNotificationHandler().show(message); -// -// return Future.value(); -// } diff --git a/lib/views/customize_category/customize_category_state.dart b/lib/views/customize_category/customize_category_state.dart index 75452f7..019e107 100644 --- a/lib/views/customize_category/customize_category_state.dart +++ b/lib/views/customize_category/customize_category_state.dart @@ -87,7 +87,7 @@ class CustomizeCategoryState extends CoreProvier { Navigator.of(context).pushNamed(Routes.notificationStatusStep, arguments: {"toTimer": toTimer}); appState = AppState.idle; - await HomeWidgetRepository().fetchWidget(); + await HomeWidgetRepository.fetchWidget(); return; } @@ -116,7 +116,7 @@ class CustomizeCategoryState extends CoreProvier { } appState = AppState.idle; - await HomeWidgetRepository().fetchWidget(); + await HomeWidgetRepository.fetchWidget(); return; } diff --git a/lib/views/home/home.dart b/lib/views/home/home.dart index d34f3ee..1316c34 100644 --- a/lib/views/home/home.dart +++ b/lib/views/home/home.dart @@ -11,7 +11,6 @@ import 'package:didvan/views/widgets/logo_app_bar.dart'; import 'package:didvan/views/widgets/didvan/bnb.dart'; import 'package:flutter/material.dart'; import 'package:provider/provider.dart'; - import '../../services/app_home_widget/home_widget_repository.dart'; class Home extends StatefulWidget { @@ -35,7 +34,8 @@ class _HomeState extends State state.currentPageIndex = _tabController.index; }); Future.delayed(Duration.zero, () { - HomeWidgetRepository().fetchWidget(); + HomeWidgetRepository.fetchWidget(); + HomeWidgetRepository.decideWhereToGo(); AppInitializer.handleCLick(state, _tabController); }); state.refresh(); @@ -46,11 +46,8 @@ class _HomeState extends State super.initState(); } - - @override Widget build(BuildContext context) { - return Scaffold( appBar: const LogoAppBar(), body: Consumer( diff --git a/lib/views/splash/splash.dart b/lib/views/splash/splash.dart index f2bdfb9..972b0bf 100644 --- a/lib/views/splash/splash.dart +++ b/lib/views/splash/splash.dart @@ -1,3 +1,4 @@ + import 'package:didvan/config/design_config.dart'; import 'package:didvan/constants/assets.dart'; import 'package:didvan/main.dart'; @@ -18,6 +19,7 @@ import 'package:flutter_svg/flutter_svg.dart'; import 'package:provider/provider.dart'; import 'package:universal_html/html.dart' as html; + class Splash extends StatefulWidget { const Splash({Key? key}) : super(key: key); @@ -135,10 +137,22 @@ class _SplashState extends State { await ServerDataProvider.getData(); } if (mounted) { - Navigator.of(context).pushReplacementNamed( + Navigator.of(context).pushReplacementNamed( token == null ? Routes.authenticaion : Routes.home, arguments: token == null ? false : null, ); + + + + return; + // await HomeWidget.getWidgetData("cRouteGoTo", defaultValue: '') + // .then((cRouteGoTo) async { + // if (cRouteGoTo!.isNotEmpty) { + // navigatorKey.currentState! + // .pushNamed(cRouteGoTo.toString(), arguments:cRouteArgs ); + // HomeWidget.saveWidgetData("cRouteGoTo", ''); + // } + // }); } } catch (e) { setState(() {