01-02-1403 / Rhmn / release test 3.
This commit is contained in:
parent
c6e07bbb2e
commit
6520dc89c5
|
|
@ -10,7 +10,6 @@ import com.squareup.picasso.MemoryPolicy
|
|||
import com.squareup.picasso.NetworkPolicy
|
||||
import com.squareup.picasso.Picasso
|
||||
import com.squareup.picasso.Transformation
|
||||
import es.antonborri.home_widget.HomeWidgetBackgroundIntent
|
||||
import es.antonborri.home_widget.HomeWidgetLaunchIntent
|
||||
import es.antonborri.home_widget.HomeWidgetProvider
|
||||
import java.lang.Exception
|
||||
|
|
@ -108,29 +107,36 @@ class FavWidget : HomeWidgetProvider() {
|
|||
|
||||
|
||||
// Pending intent to update counter on button click
|
||||
val settingIntent = HomeWidgetBackgroundIntent.getBroadcast(
|
||||
val settingIntent = HomeWidgetLaunchIntent.getActivity(
|
||||
context,
|
||||
Uri.parse("myAppWidget://setting"),
|
||||
MainActivity::class.java,
|
||||
Uri.parse("myAppWidget://setting"),
|
||||
|
||||
)
|
||||
setOnClickPendingIntent(R.id.setting_btn, settingIntent)
|
||||
|
||||
val rowFirst = HomeWidgetBackgroundIntent.getBroadcast(
|
||||
val rowFirst = HomeWidgetLaunchIntent.getActivity(
|
||||
context,
|
||||
MainActivity::class.java,
|
||||
|
||||
Uri.parse("myAppWidget://rowFirst"),
|
||||
|
||||
)
|
||||
setOnClickPendingIntent(R.id.first_row, rowFirst)
|
||||
|
||||
val rowMiddle = HomeWidgetBackgroundIntent.getBroadcast(
|
||||
val rowMiddle = HomeWidgetLaunchIntent.getActivity(
|
||||
context,
|
||||
MainActivity::class.java,
|
||||
|
||||
Uri.parse("myAppWidget://rowMiddle"),
|
||||
|
||||
)
|
||||
setOnClickPendingIntent(R.id.middle_row, rowMiddle)
|
||||
|
||||
val rowLast = HomeWidgetBackgroundIntent.getBroadcast(
|
||||
val rowLast = HomeWidgetLaunchIntent.getActivity(
|
||||
context,
|
||||
MainActivity::class.java,
|
||||
|
||||
Uri.parse("myAppWidget://rowLast"),
|
||||
|
||||
)
|
||||
|
|
|
|||
|
|
@ -49,16 +49,22 @@ Future<void> _firebaseMessagingBackgroundHandler(RemoteMessage message) async {
|
|||
),
|
||||
);
|
||||
|
||||
AwsomeNotificationHandler().alarm();
|
||||
// AwsomeNotificationHandler().alarm();
|
||||
AwsomeNotificationHandler().show(message);
|
||||
}
|
||||
|
||||
void main() async {
|
||||
try {
|
||||
WidgetsFlutterBinding.ensureInitialized();
|
||||
FirebaseNotificationHandler().initial();
|
||||
FirebaseMessaging.onBackgroundMessage(_firebaseMessagingBackgroundHandler);
|
||||
FirebaseMessaging.onMessage.listen(
|
||||
(RemoteMessage message) => AwsomeNotificationHandler().show(message));
|
||||
|
||||
//ignore: deprecated_member_use
|
||||
HomeWidget.registerBackgroundCallback(backgroundCallback);
|
||||
HomeWidget.registerInteractivityCallback(backgroundCallback);
|
||||
AwsomeNotificationHandler().alarm();
|
||||
FirebaseNotificationHandler().initial();
|
||||
} catch (e) {
|
||||
debugPrintStack();
|
||||
}
|
||||
|
|
@ -74,6 +80,7 @@ Future<void> backgroundCallback(Uri? uri) async {
|
|||
);
|
||||
await intent.launch();
|
||||
HomeWidget.saveWidgetData("uri", uri!.host);
|
||||
|
||||
}
|
||||
|
||||
class Didvan extends StatefulWidget {
|
||||
|
|
@ -102,10 +109,14 @@ class _DidvanState extends State<Didvan> 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<String>('uri', defaultValue: "")
|
||||
.then((value) async {
|
||||
if (value!.isNotEmpty) {
|
||||
|
|
@ -186,11 +197,18 @@ class _DidvanState extends State<Didvan> with WidgetsBindingObserver {
|
|||
'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}?accessToken=${RequestService.token}',
|
||||
'${data.link}',
|
||||
mode: LaunchMode.inAppWebView,
|
||||
);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -7,40 +7,37 @@ import '../network/request_helper.dart';
|
|||
|
||||
class HomeWidgetRepository {
|
||||
Future<void> fetchWidget() async {
|
||||
if (RequestService.token != null && RequestService.token.isNotEmpty) {
|
||||
final service = RequestService(
|
||||
RequestHelper.widgetNews(),
|
||||
);
|
||||
await service.httpGet();
|
||||
List<WidgetResponse> responseList = [];
|
||||
if (service.isSuccess) {
|
||||
final favourites = service.data('content');
|
||||
HomeWidget.saveWidgetData("token", RequestService.token.toString());
|
||||
for (var i = 0; i < favourites.length; i++) {
|
||||
HomeWidget.saveWidgetData("id${i + 1}",
|
||||
WidgetResponse.fromJson(favourites[i]).id.toString());
|
||||
HomeWidget.saveWidgetData("title${i + 1}",
|
||||
WidgetResponse.fromJson(favourites[i]).title.toString());
|
||||
HomeWidget.saveWidgetData(
|
||||
"createdAt${i + 1}",
|
||||
DateTime.parse(WidgetResponse.fromJson(favourites[i])
|
||||
.createdAt
|
||||
.toString())
|
||||
.toPersianDateStr());
|
||||
HomeWidget.saveWidgetData("type${i + 1}",
|
||||
WidgetResponse.fromJson(favourites[i]).type.toString());
|
||||
HomeWidget.saveWidgetData("link${i + 1}",
|
||||
WidgetResponse.fromJson(favourites[i]).link.toString());
|
||||
HomeWidget.saveWidgetData("category${i + 1}",
|
||||
WidgetResponse.fromJson(favourites[i]).category.toString());
|
||||
HomeWidget.saveWidgetData("image${i + 1}",
|
||||
WidgetResponse.fromJson(favourites[i]).image.toString());
|
||||
}
|
||||
|
||||
HomeWidget.updateWidget(
|
||||
androidName: "FavWidget",
|
||||
);
|
||||
final service = RequestService(
|
||||
RequestHelper.widgetNews(),
|
||||
);
|
||||
await service.httpGet();
|
||||
List<WidgetResponse> responseList = [];
|
||||
if (service.isSuccess) {
|
||||
final favourites = service.data('content');
|
||||
HomeWidget.saveWidgetData("token", RequestService.token.toString());
|
||||
for (var i = 0; i < favourites.length; i++) {
|
||||
HomeWidget.saveWidgetData(
|
||||
"id${i + 1}", WidgetResponse.fromJson(favourites[i]).id.toString());
|
||||
HomeWidget.saveWidgetData("title${i + 1}",
|
||||
WidgetResponse.fromJson(favourites[i]).title.toString());
|
||||
HomeWidget.saveWidgetData(
|
||||
"createdAt${i + 1}",
|
||||
DateTime.parse(
|
||||
WidgetResponse.fromJson(favourites[i]).createdAt.toString())
|
||||
.toPersianDateStr());
|
||||
HomeWidget.saveWidgetData("type${i + 1}",
|
||||
WidgetResponse.fromJson(favourites[i]).type.toString());
|
||||
HomeWidget.saveWidgetData("link${i + 1}",
|
||||
WidgetResponse.fromJson(favourites[i]).link.toString());
|
||||
HomeWidget.saveWidgetData("category${i + 1}",
|
||||
WidgetResponse.fromJson(favourites[i]).category.toString());
|
||||
HomeWidget.saveWidgetData("image${i + 1}",
|
||||
WidgetResponse.fromJson(favourites[i]).image.toString());
|
||||
}
|
||||
|
||||
HomeWidget.updateWidget(
|
||||
androidName: "FavWidget",
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,6 +1,7 @@
|
|||
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;
|
||||
|
|
|
|||
|
|
@ -1,4 +1,3 @@
|
|||
|
||||
import 'package:awesome_notifications/awesome_notifications.dart';
|
||||
import 'package:didvan/main.dart';
|
||||
import 'package:url_launcher/url_launcher_string.dart';
|
||||
|
|
@ -95,13 +94,13 @@ class NotificationController {
|
|||
} else {
|
||||
if (data.link!.startsWith('http')) {
|
||||
launchUrlString(
|
||||
'${data.link}?accessToken=${RequestService.token}',
|
||||
'${data.link}',
|
||||
mode: LaunchMode.inAppWebView,
|
||||
);
|
||||
}
|
||||
}
|
||||
if (route.isNotEmpty) {
|
||||
navigatorKey.currentState!.pushNamedIfNotCurrent(route, arguments: args);
|
||||
navigatorKey.currentState!.pushNamed(route, arguments: args);
|
||||
}
|
||||
|
||||
// MyApp.navigatorKey.currentState?.pushNamedAndRemoveUntil('/notification-page',
|
||||
|
|
|
|||
|
|
@ -1,6 +1,7 @@
|
|||
import 'package:awesome_notifications/awesome_notifications.dart';
|
||||
import 'package:firebase_messaging/firebase_messaging.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:home_widget/home_widget.dart';
|
||||
import 'package:intl/intl.dart';
|
||||
|
||||
import '../../../models/notification_message.dart';
|
||||
|
|
@ -37,7 +38,7 @@ class AwsomeNotificationHandler {
|
|||
// channelGroupKey: 'basic_channel_group',
|
||||
// channelGroupName: 'Basic group')
|
||||
// ],
|
||||
debug: false);
|
||||
debug: true);
|
||||
|
||||
initialAction = await AwesomeNotifications()
|
||||
.getInitialNotificationAction(removeFromActionEvents: false);
|
||||
|
|
@ -96,9 +97,9 @@ class AwsomeNotificationHandler {
|
|||
}
|
||||
|
||||
showNotificationTypeNews(NotificationMessage message) async {
|
||||
DateTime time = await _getTime();
|
||||
|
||||
AwesomeNotifications().createNotification(
|
||||
DateTime? time = await _getTime();
|
||||
if (time == null) {
|
||||
AwesomeNotifications().createNotification(
|
||||
content: NotificationContent(
|
||||
id: DateTime.now().millisecondsSinceEpoch ~/ 1000,
|
||||
channelKey: 'alerts',
|
||||
|
|
@ -109,18 +110,31 @@ class AwsomeNotificationHandler {
|
|||
largeIcon: message.image.toString(),
|
||||
payload: message.toPayload(),
|
||||
color: const Color(0xFF007EA7)),
|
||||
schedule: time.year != null
|
||||
? null
|
||||
: NotificationCalendar(
|
||||
hour: time.hour,
|
||||
minute: time.minute,
|
||||
));
|
||||
);
|
||||
} else {
|
||||
AwesomeNotifications().createNotification(
|
||||
content: NotificationContent(
|
||||
id: DateTime.now().millisecondsSinceEpoch ~/ 1000,
|
||||
channelKey: 'alerts',
|
||||
actionType: ActionType.Default,
|
||||
title: "\u200f ${message.title} \u200f",
|
||||
// body: message.body.toString(),
|
||||
notificationLayout: NotificationLayout.Default,
|
||||
largeIcon: message.image.toString(),
|
||||
payload: message.toPayload(),
|
||||
color: const Color(0xFF007EA7)),
|
||||
schedule: NotificationCalendar(
|
||||
hour: time.hour,
|
||||
minute: time.minute,
|
||||
));
|
||||
}
|
||||
}
|
||||
|
||||
showNotificationTypeMessage(NotificationMessage message) async {
|
||||
DateTime time = await _getTime();
|
||||
DateTime? time = await _getTime();
|
||||
|
||||
AwesomeNotifications().createNotification(
|
||||
if (time == null) {
|
||||
AwesomeNotifications().createNotification(
|
||||
content: NotificationContent(
|
||||
id: DateTime.now().millisecondsSinceEpoch ~/ 1000,
|
||||
channelKey: 'alerts',
|
||||
|
|
@ -133,25 +147,41 @@ class AwsomeNotificationHandler {
|
|||
payload: message.toPayload(),
|
||||
notificationLayout: NotificationLayout.BigPicture,
|
||||
color: const Color(0xFF007EA7)),
|
||||
schedule: time.year != null
|
||||
? null
|
||||
: NotificationCalendar(
|
||||
hour: time.hour,
|
||||
minute: time.minute,
|
||||
)
|
||||
// actionButtons: [
|
||||
// NotificationActionButton(
|
||||
// key: 'REPLY',
|
||||
// label: 'جواب دادن',
|
||||
// requireInputText: true,
|
||||
// actionType: ActionType.SilentAction),
|
||||
// NotificationActionButton(
|
||||
// key: 'DISMISS',
|
||||
// label: 'خوانده شده',
|
||||
// actionType: ActionType.DismissAction,
|
||||
// isDangerousOption: true)
|
||||
// ]
|
||||
);
|
||||
);
|
||||
} else {
|
||||
AwesomeNotifications().createNotification(
|
||||
content: NotificationContent(
|
||||
id: DateTime.now().millisecondsSinceEpoch ~/ 1000,
|
||||
channelKey: 'alerts',
|
||||
actionType: ActionType.Default,
|
||||
body:
|
||||
"<b>${message.title.toString()}</b> ${message.body.toString()}",
|
||||
largeIcon: message.photo.toString(),
|
||||
roundedLargeIcon: true,
|
||||
bigPicture: message.image.toString(),
|
||||
payload: message.toPayload(),
|
||||
notificationLayout: NotificationLayout.BigPicture,
|
||||
color: const Color(0xFF007EA7)),
|
||||
schedule: time.year != null
|
||||
? null
|
||||
: NotificationCalendar(
|
||||
hour: time.hour,
|
||||
minute: time.minute,
|
||||
));
|
||||
}
|
||||
|
||||
// actionButtons: [
|
||||
// NotificationActionButton(
|
||||
// key: 'REPLY',
|
||||
// label: 'جواب دادن',
|
||||
// requireInputText: true,
|
||||
// actionType: ActionType.SilentAction),
|
||||
// NotificationActionButton(
|
||||
// key: 'DISMISS',
|
||||
// label: 'خوانده شده',
|
||||
// actionType: ActionType.DismissAction,
|
||||
// isDangerousOption: true)
|
||||
// ]
|
||||
}
|
||||
|
||||
showNotificationTypeEmoji(NotificationMessage message) async {
|
||||
|
|
@ -174,30 +204,36 @@ class AwsomeNotificationHandler {
|
|||
}));
|
||||
}
|
||||
|
||||
Future<DateTime> _getTime() async {
|
||||
final service = RequestService(
|
||||
RequestHelper.notificationTime(),
|
||||
);
|
||||
await service.httpGet();
|
||||
if (service.isSuccess) {
|
||||
final time = service.data('time');
|
||||
DateTime result = DateTime.now();
|
||||
if (time.toString().isNotEmpty) {
|
||||
DateFormat format = DateFormat("HH:mm");
|
||||
DateTime dateTime = format.parse(time);
|
||||
result = DateTime.now()
|
||||
.copyWith(hour: dateTime.hour, minute: dateTime.minute);
|
||||
}
|
||||
Future<DateTime?> _getTime() async {
|
||||
await HomeWidget.getWidgetData<String>('token', defaultValue: "")
|
||||
.then((value) async {
|
||||
final service = RequestService(RequestHelper.notificationTime(),
|
||||
useAutherization: false,
|
||||
requestHeaders: {
|
||||
"accept": "*/*",
|
||||
"Content-Type": "application/json; charset=UTF-8",
|
||||
'Authorization': 'Bearer $value'
|
||||
});
|
||||
await service.httpGet();
|
||||
if (service.isSuccess) {
|
||||
final time = service.data('time');
|
||||
DateTime result = DateTime.now();
|
||||
if (time.toString().isNotEmpty) {
|
||||
DateFormat format = DateFormat("HH:mm");
|
||||
DateTime dateTime = format.parse(time);
|
||||
result = DateTime.now()
|
||||
.copyWith(hour: dateTime.hour, minute: dateTime.minute);
|
||||
}
|
||||
|
||||
return result;
|
||||
} else {
|
||||
return DateTime.now();
|
||||
}
|
||||
return result;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
showNotificationScheduled(NotificationMessage message) async {
|
||||
DateTime time = await _getTime();
|
||||
AwesomeNotifications().createNotification(
|
||||
DateTime? time = await _getTime();
|
||||
if (time == null) {
|
||||
AwesomeNotifications().createNotification(
|
||||
content: NotificationContent(
|
||||
id: DateTime.now().millisecondsSinceEpoch ~/ 1000,
|
||||
channelKey: 'alerts',
|
||||
|
|
@ -216,10 +252,32 @@ class AwsomeNotificationHandler {
|
|||
'image': 'path/to/smallImage.png', // Path to small image
|
||||
'largeImage': 'path/to/largeImage.png', // Path to large image
|
||||
}),
|
||||
schedule: NotificationCalendar(
|
||||
hour: time.hour,
|
||||
minute: time.minute,
|
||||
// timezone: await AwesomeNotifications().getLocalTimeZoneIdentifier()
|
||||
));
|
||||
);
|
||||
} else {
|
||||
AwesomeNotifications().createNotification(
|
||||
content: NotificationContent(
|
||||
id: DateTime.now().millisecondsSinceEpoch ~/ 1000,
|
||||
channelKey: 'alerts',
|
||||
title: 'Emojis are awes'
|
||||
'ome too! ${Emojis.animals_lady_beetle}${Emojis.activites_balloon}${Emojis.emotion_red_heart}',
|
||||
body:
|
||||
'Simple body with a bunch of Emojis! ${Emojis.transport_police_car} ${Emojis.animals_dog} ${Emojis.flag_UnitedStates} ${Emojis.person_baby}',
|
||||
largeIcon:
|
||||
'https://cdn.britannica.com/72/232772-050-4E3D86CC/mind-blown-emoji-head-exploding-emoticon.jpg',
|
||||
notificationLayout: NotificationLayout.BigPicture,
|
||||
wakeUpScreen: true,
|
||||
category: NotificationCategory.Alarm,
|
||||
payload: {
|
||||
'title': 'Notification Title',
|
||||
'body': 'Notification Body',
|
||||
'image': 'path/to/smallImage.png', // Path to small image
|
||||
'largeImage': 'path/to/largeImage.png', // Path to large image
|
||||
}),
|
||||
schedule: NotificationCalendar(
|
||||
hour: time.hour,
|
||||
minute: time.minute,
|
||||
// timezone: await AwesomeNotifications().getLocalTimeZoneIdentifier()
|
||||
));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -59,47 +59,6 @@ class FirebaseNotificationHandler {
|
|||
// _firebaseMessagingBackgroundHandler);
|
||||
|
||||
// Listening for incoming messages while the app is in the foreground
|
||||
FirebaseMessaging.onMessage.listen((RemoteMessage message) {
|
||||
/* if (message.notification!.title != null &&
|
||||
message.notification!.body != null) {
|
||||
final notificationData = message.data;
|
||||
final screen = notificationData['screen'];
|
||||
|
||||
// Showing an alert dialog when a notification is received (Foreground state)
|
||||
// showDialog(
|
||||
// context: context,
|
||||
// barrierDismissible: false,
|
||||
// builder: (BuildContext context) {
|
||||
// return WillPopScope(
|
||||
// onWillPop: () async => false,
|
||||
// child: AlertDialog(
|
||||
// title: Text(message.notification!.title!),
|
||||
// content: Text(message.notification!.body!),
|
||||
// actions: [
|
||||
// if (notificationData.containsKey('screen'))
|
||||
// TextButton(
|
||||
// onPressed: () {
|
||||
// Navigator.pop(context);
|
||||
// Navigator.of(context).pushNamed(screen);
|
||||
// },
|
||||
// child: const Text('Open Screen'),
|
||||
// ),
|
||||
// TextButton(
|
||||
// onPressed: () => Navigator.of(context).pop(),
|
||||
// child: const Text('Dismiss'),
|
||||
// ),
|
||||
// ],
|
||||
// ),
|
||||
// );
|
||||
// },
|
||||
// );
|
||||
}*/
|
||||
// LocalNotificationService.initialize();
|
||||
// LocalNotificationService.showBigPictureNotification();
|
||||
// LocalNotificationService.display(message);
|
||||
AwsomeNotificationHandler().alarm();
|
||||
AwsomeNotificationHandler().show(message);
|
||||
});
|
||||
|
||||
// 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
|
||||
|
|
|
|||
|
|
@ -5,6 +5,7 @@ import 'package:didvan/providers/user.dart';
|
|||
import 'package:didvan/services/network/request.dart';
|
||||
import 'package:didvan/services/network/request_helper.dart';
|
||||
import 'package:didvan/utils/action_sheet.dart';
|
||||
import 'package:home_widget/home_widget.dart';
|
||||
|
||||
class AuthenticationState extends CoreProvier {
|
||||
int _currentPageIndex = 0;
|
||||
|
|
@ -50,6 +51,7 @@ class AuthenticationState extends CoreProvier {
|
|||
appState = AppState.idle;
|
||||
await userProvider.setAndGetToken(newToken: token);
|
||||
RequestService.token = token;
|
||||
HomeWidget.saveWidgetData("token", token.toString());
|
||||
await userProvider.getUserInfo();
|
||||
return token;
|
||||
} else {
|
||||
|
|
|
|||
Loading…
Reference in New Issue