diff options
author | Allan Wang <me@allanwang.ca> | 2017-10-15 15:07:23 -0400 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-10-15 15:07:23 -0400 |
commit | d08fd6f8d24430594d63e808740289d395f7227d (patch) | |
tree | 9dd5befd270427413a2735d88b4897532b66d7a6 | |
parent | a4b3e990228c90c53eaf3ca1424a1e5f6d582d07 (diff) | |
download | frost-d08fd6f8d24430594d63e808740289d395f7227d.tar.gz frost-d08fd6f8d24430594d63e808740289d395f7227d.tar.bz2 frost-d08fd6f8d24430594d63e808740289d395f7227d.zip |
Enhancement/notifications (#416)
* Update notification defaults
* Setup initial channel test
-rw-r--r-- | app/src/main/kotlin/com/pitchedapps/frost/FrostApp.kt | 3 | ||||
-rw-r--r-- | app/src/main/kotlin/com/pitchedapps/frost/services/FrostNotifications.kt | 19 | ||||
-rw-r--r-- | app/src/main/kotlin/com/pitchedapps/frost/utils/Prefs.kt | 4 | ||||
-rw-r--r-- | build.gradle | 2 | ||||
-rw-r--r-- | gradle.properties | 2 |
5 files changed, 23 insertions, 7 deletions
diff --git a/app/src/main/kotlin/com/pitchedapps/frost/FrostApp.kt b/app/src/main/kotlin/com/pitchedapps/frost/FrostApp.kt index 2de04187..ad06f3a6 100644 --- a/app/src/main/kotlin/com/pitchedapps/frost/FrostApp.kt +++ b/app/src/main/kotlin/com/pitchedapps/frost/FrostApp.kt @@ -16,6 +16,7 @@ import com.mikepenz.materialdrawer.util.AbstractDrawerImageLoader import com.mikepenz.materialdrawer.util.DrawerImageLoader import com.pitchedapps.frost.facebook.FbCookie import com.pitchedapps.frost.services.scheduleNotifications +import com.pitchedapps.frost.services.setupNotificationChannels import com.pitchedapps.frost.utils.FrostPglAdBlock import com.pitchedapps.frost.utils.L import com.pitchedapps.frost.utils.Prefs @@ -61,6 +62,8 @@ class FrostApp : Application() { applicationContext.scheduleNotifications(Prefs.notificationFreq) + setupNotificationChannels(applicationContext) + /** * Drawer profile loading logic * Reload the image on every version update diff --git a/app/src/main/kotlin/com/pitchedapps/frost/services/FrostNotifications.kt b/app/src/main/kotlin/com/pitchedapps/frost/services/FrostNotifications.kt index d296b5f3..9bef9170 100644 --- a/app/src/main/kotlin/com/pitchedapps/frost/services/FrostNotifications.kt +++ b/app/src/main/kotlin/com/pitchedapps/frost/services/FrostNotifications.kt @@ -1,14 +1,20 @@ package com.pitchedapps.frost.services import android.app.Notification +import android.app.NotificationChannel +import android.app.NotificationManager import android.app.PendingIntent import android.app.job.JobInfo import android.app.job.JobScheduler import android.content.ComponentName import android.content.Context +import android.content.ContextWrapper import android.content.Intent import android.graphics.Bitmap +import android.graphics.Color import android.net.Uri +import android.os.Build +import android.support.annotation.RequiresApi import android.support.v4.app.NotificationCompat import android.support.v4.app.NotificationManagerCompat import ca.allanwang.kau.utils.color @@ -33,7 +39,14 @@ import org.jetbrains.anko.runOnUiThread * * Logic for build notifications, scheduling notifications, and showing notifications */ - +fun setupNotificationChannels(c: Context) { + if (Build.VERSION.SDK_INT < Build.VERSION_CODES.O) return + val manager = c.getSystemService(Context.NOTIFICATION_SERVICE) as NotificationManager + val mainChannel = NotificationChannel(BuildConfig.APPLICATION_ID, c.getString(R.string.frost_name), NotificationManager.IMPORTANCE_DEFAULT) + mainChannel.lightColor = c.color(R.color.facebook_blue) + mainChannel.lockscreenVisibility = Notification.VISIBILITY_PUBLIC + manager.createNotificationChannel(mainChannel) +} val Context.frostNotification: NotificationCompat.Builder get() = NotificationCompat.Builder(this, BuildConfig.APPLICATION_ID).apply { @@ -161,8 +174,8 @@ data class NotificationContent(val data: CookieModel, val text: String, val timestamp: Long, val profileUrl: String) { - constructor(data:CookieModel, thread: FrostThread) - :this(data, thread.id, thread.url, thread.title, thread.content ?: "", thread.time, thread.img) + constructor(data: CookieModel, thread: FrostThread) + : this(data, thread.id, thread.url, thread.title, thread.content ?: "", thread.time, thread.img) } const val NOTIFICATION_PERIODIC_JOB = 7 diff --git a/app/src/main/kotlin/com/pitchedapps/frost/utils/Prefs.kt b/app/src/main/kotlin/com/pitchedapps/frost/utils/Prefs.kt index 46830e65..dbace074 100644 --- a/app/src/main/kotlin/com/pitchedapps/frost/utils/Prefs.kt +++ b/app/src/main/kotlin/com/pitchedapps/frost/utils/Prefs.kt @@ -39,7 +39,7 @@ object Prefs : KPref() { var exitConfirmation: Boolean by kpref("exit_confirmation", true) - var notificationFreq: Long by kpref("notification_freq", -1L) + var notificationFreq: Long by kpref("notification_freq", 60L) var versionCode: Int by kpref("version_code", -1) @@ -104,7 +104,7 @@ object Prefs : KPref() { var notificationAllAccounts: Boolean by kpref("notification_all_accounts", true) - var notificationsInstantMessages: Boolean by kpref("notification_im", false) + var notificationsInstantMessages: Boolean by kpref("notification_im", true) var notificationsImAllAccounts: Boolean by kpref("notification_im_all_accounts", false) diff --git a/build.gradle b/build.gradle index d4b4c3dc..b2944b05 100644 --- a/build.gradle +++ b/build.gradle @@ -7,7 +7,7 @@ buildscript { maven { url 'https://maven.fabric.io/public' } } dependencies { - classpath 'com.android.tools.build:gradle:3.0.0-beta7' + classpath 'com.android.tools.build:gradle:3.0.0-rc1' classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:${KOTLIN}" classpath 'io.fabric.tools:gradle:1.+' classpath 'com.github.triplet.gradle:play-publisher:1.2.0' diff --git a/gradle.properties b/gradle.properties index fcea33c4..bd7b8ce1 100644 --- a/gradle.properties +++ b/gradle.properties @@ -17,7 +17,7 @@ MIN_SDK=21 TARGET_SDK=26 BUILD_TOOLS=26.0.2 -KAU=afc1a02 +KAU=7513227 KOTLIN=1.1.51 COMMONS_TEXT=1.1 |