Skip to content

Commit

Permalink
Tried some notification tweaks
Browse files Browse the repository at this point in the history
  • Loading branch information
JobinBiju committed Mar 21, 2021
1 parent d3059a4 commit a4241c7
Show file tree
Hide file tree
Showing 14 changed files with 155 additions and 9 deletions.
23 changes: 23 additions & 0 deletions android/app/proguard-rules.pro
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
## Gson rules
# Gson uses generic type information stored in a class file when working with fields. Proguard
# removes such information by default, so configure it to keep all of it.
-keepattributes Signature

# For using GSON @Expose annotation
-keepattributes *Annotation*

# Gson specific classes
-dontwarn sun.misc.**
#-keep class com.google.gson.stream.** { *; }

# Prevent proguard from stripping interface information from TypeAdapter, TypeAdapterFactory,
# JsonSerializer, JsonDeserializer instances (so they can be used in @JsonAdapter)
-keep class * extends com.google.gson.TypeAdapter
-keep class * implements com.google.gson.TypeAdapterFactory
-keep class * implements com.google.gson.JsonSerializer
-keep class * implements com.google.gson.JsonDeserializer

# Prevent R8 from leaving Data object members always null
-keepclassmembers,allowobfuscation class * {
@com.google.gson.annotations.SerializedName <fields>;
}
3 changes: 3 additions & 0 deletions android/app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
additional functionality it is fine to subclass or reimplement
FlutterApplication and put your custom class here. -->
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.REQUEST_IGNORE_BATTERY_OPTIMIZATIONS" />
<application
android:name="io.flutter.app.FlutterApplication"
android:label="Taskly"
Expand All @@ -16,6 +17,8 @@
android:theme="@style/LaunchTheme"
android:configChanges="orientation|keyboardHidden|keyboard|screenSize|smallestScreenSize|locale|layoutDirection|fontScale|screenLayout|density|uiMode"
android:hardwareAccelerated="true"
android:showWhenLocked="true"
android:turnScreenOn="true"
android:windowSoftInputMode="adjustResize">
<!-- Specifies an Android theme to apply to this Activity as soon as
the Android process has started. This theme is visible to the user
Expand Down
Binary file added android/app/src/main/res/drawable/app_icon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion android/app/src/main/res/drawable/launch_background.xml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<!-- Modify this file to customize your launch splash screen -->
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item android:drawable="@android:color/white" />
<item android:drawable="?android:colorBackground" />

<!-- You can insert your own image assets here -->
<!-- <item>
Expand Down
3 changes: 3 additions & 0 deletions android/app/src/main/res/raw/keep.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<?xml version="1.0" encoding="utf-8"?>
<resources xmlns:tools="http://schemas.android.com/tools"
tools:keep="@drawable/*,@raw/slow_spring_board" />
Binary file not shown.
18 changes: 18 additions & 0 deletions android/app/src/main/res/values-night/styles.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<!-- Theme applied to the Android Window while the process is starting when the OS's Dark Mode setting is on -->
<style name="LaunchTheme" parent="@android:style/Theme.Black.NoTitleBar">
<!-- Show a splash screen on the activity. Automatically removed when
Flutter draws its first frame -->
<item name="android:windowBackground">@drawable/launch_background</item>
</style>
<!-- Theme applied to the Android Window as soon as the process has started.
This theme determines the color of the Android Window while your
Flutter UI initializes, as well as behind your Flutter UI while its
running.
This Theme is only used starting with V2 of Flutter's Android embedding. -->
<style name="NormalTheme" parent="@android:style/Theme.Black.NoTitleBar">
<item name="android:windowBackground">?android:colorBackground</item>
</style>
</resources>
10 changes: 5 additions & 5 deletions android/app/src/main/res/values/styles.xml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<!-- Theme applied to the Android Window while the process is starting -->
<style name="LaunchTheme" parent="@android:style/Theme.Black.NoTitleBar">
<!-- Theme applied to the Android Window while the process is starting when the OS's Dark Mode setting is off -->
<style name="LaunchTheme" parent="@android:style/Theme.Light.NoTitleBar">
<!-- Show a splash screen on the activity. Automatically removed when
Flutter draws its first frame -->
<item name="android:windowBackground">@drawable/launch_background</item>
Expand All @@ -12,7 +12,7 @@
running.
This Theme is only used starting with V2 of Flutter's Android embedding. -->
<style name="NormalTheme" parent="@android:style/Theme.Black.NoTitleBar">
<item name="android:windowBackground">@android:color/white</item>
<style name="NormalTheme" parent="@android:style/Theme.Light.NoTitleBar">
<item name="android:windowBackground">?android:colorBackground</item>
</style>
</resources>
</resources>
22 changes: 22 additions & 0 deletions lib/app/data/services/time_zone.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
// import 'package:timezone/data/latest.dart';
// import 'package:timezone/timezone.dart' as t;
// import 'package:flutter_native_timezone/flutter_native_timezone.dart';

// class TimeZone {
// factory TimeZone() => _this ?? TimeZone._();

// TimeZone._() {
// initializeTimeZones();
// }
// static TimeZone _this;

// Future<String> getTimeZoneName() async =>
// FlutterNativeTimezone.getLocalTimezone();

// Future<t.Location> getLocation([String timeZoneName]) async {
// if (timeZoneName == null || timeZoneName.isEmpty) {
// timeZoneName = await getTimeZoneName();
// }
// return t.getLocation(timeZoneName);
// }
// }
66 changes: 66 additions & 0 deletions lib/app/modules/home/controllers/home_controller.dart
Original file line number Diff line number Diff line change
@@ -1,14 +1,20 @@
import 'package:flutter/material.dart';
import 'package:flutter_local_notifications/flutter_local_notifications.dart';
import 'package:get/get.dart';
import 'package:taskly/app/data/services/time_zone.dart';
import 'package:taskly/app/modules/home/views/dashboard_view.dart';
import 'package:taskly/app/modules/home/views/today_task_view.dart';
import 'package:timezone/timezone.dart' as tz;

class HomeController extends GetxController {
// bottom nav current index.
var _currentIndex = 0.obs;
get currentIndex => this._currentIndex.value;
set currentIndex(index) => this._currentIndex.value = index;

// Notification controller
FlutterLocalNotificationsPlugin fNotification;

// the list of screens switched by bottom navBar
final List<Widget> homeViews = [
DashboardView(),
Expand All @@ -20,9 +26,69 @@ class HomeController extends GetxController {
return homeViews.elementAt(currentIndex);
}

Future notificationSelected(String payload) {
showDialog(
context: Get.context,
builder: (context) => AlertDialog(
content: Text('Notify $payload'),
));
}

Future showNotification() async {
var scheduledTime = DateTime.now().add(Duration(seconds: 5));

var androidDetails = AndroidNotificationDetails(
'Channel ID 1',
'Test Notify',
'Hello! My first notification',
importance: Importance.max,
priority: Priority.high,
timeoutAfter: 3000,
sound: RawResourceAndroidNotificationSound('slow_spring_board'),
enableLights: true,
enableVibration: true,
ledColor: Color.fromARGB(255, 255, 0, 255),
ledOnMs: 1000,
ledOffMs: 500,
);
var iOSDetails = IOSNotificationDetails();
var generalNotificationDetails = NotificationDetails(
android: androidDetails,
iOS: iOSDetails,
);

await fNotification.periodicallyShow(
0,
'Drink Water',
'Keep yourself hydrated',
RepeatInterval.everyMinute,
generalNotificationDetails,
payload: "Tasks",
);

// await fNotification.schedule(
// 1,
// "Drink",
// "Drink Water",
// scheduledTime,
// generalNotificationDetails,
// );
}

@override
void onInit() {
super.onInit();

// notification config
var androidInitialize = AndroidInitializationSettings('app_icon');
var iOSInitialize = IOSInitializationSettings();
var initializationSetting =
InitializationSettings(android: androidInitialize, iOS: iOSInitialize);
fNotification = FlutterLocalNotificationsPlugin();
fNotification.initialize(
initializationSetting,
onSelectNotification: notificationSelected,
);
}

@override
Expand Down
3 changes: 2 additions & 1 deletion lib/app/modules/home/views/home_view.dart
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ class HomeView extends GetView<HomeController> {
body: Obx(() => controller.navBarSwitcher()),
floatingActionButton: FloatingActionButton(
onPressed: () {
Get.to(() => LoginView());
// Get.to(() => LoginView());
controller.showNotification();
},
child: Icon(
Icons.add,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,11 @@ class SplashScreenController extends GetxController

@override
void onInit() {
super.onInit();
userData.writeIfNull('theme', "Yellow Light");
userData.writeIfNull('drinkWater', false);
userData.writeIfNull('drinkWater', false);

// spalsh animation config
animationController = AnimationController(
duration: Duration(seconds: 3),
vsync: this,
Expand All @@ -41,7 +44,6 @@ class SplashScreenController extends GetxController
Duration(milliseconds: 8200),
() => Get.offNamed('/home'),
);
super.onInit();
}

@override
Expand Down
7 changes: 7 additions & 0 deletions pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,13 @@ packages:
url: "https://pub.dartlang.org"
source: hosted
version: "2.0.0+1"
flutter_native_timezone:
dependency: "direct main"
description:
name: flutter_native_timezone
url: "https://pub.dartlang.org"
source: hosted
version: "1.0.10"
flutter_svg:
dependency: "direct main"
description:
Expand Down
1 change: 1 addition & 0 deletions pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ dependencies:
get_storage: ^1.4.0
google_fonts: ^1.1.1
lottie: ^1.0.1
flutter_native_timezone: ^1.0.10

dev_dependencies:
flutter_test:
Expand Down

0 comments on commit a4241c7

Please sign in to comment.