aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAllan Wang <me@allanwang.ca>2019-08-06 22:16:33 -0700
committerAllan Wang <me@allanwang.ca>2019-08-06 22:16:33 -0700
commit81d357ce0a17a5b11bfb17d3762540c2bd7f11be (patch)
treec8e452cdffef61b267b9ad2b06d2cd9af3848cdb
parent281124b649304741dd1ad508b90bf056dba1192e (diff)
downloadfrost-81d357ce0a17a5b11bfb17d3762540c2bd7f11be.tar.gz
frost-81d357ce0a17a5b11bfb17d3762540c2bd7f11be.tar.bz2
frost-81d357ce0a17a5b11bfb17d3762540c2bd7f11be.zip
Reduce notification update frequency
-rw-r--r--app/src/main/kotlin/com/pitchedapps/frost/FrostApp.kt3
-rw-r--r--app/src/main/kotlin/com/pitchedapps/frost/activities/BaseMainActivity.kt5
-rw-r--r--app/src/main/kotlin/com/pitchedapps/frost/services/FrostNotifications.kt7
-rw-r--r--app/src/main/kotlin/com/pitchedapps/frost/settings/Behaviour.kt5
-rw-r--r--app/src/main/kotlin/com/pitchedapps/frost/settings/Notifications.kt19
-rw-r--r--app/src/main/kotlin/com/pitchedapps/frost/utils/Const.kt1
6 files changed, 27 insertions, 13 deletions
diff --git a/app/src/main/kotlin/com/pitchedapps/frost/FrostApp.kt b/app/src/main/kotlin/com/pitchedapps/frost/FrostApp.kt
index d6d6faea..41a755d1 100644
--- a/app/src/main/kotlin/com/pitchedapps/frost/FrostApp.kt
+++ b/app/src/main/kotlin/com/pitchedapps/frost/FrostApp.kt
@@ -36,6 +36,7 @@ import com.pitchedapps.frost.db.FrostDatabase
import com.pitchedapps.frost.db.NotificationDb
import com.pitchedapps.frost.glide.GlideApp
import com.pitchedapps.frost.services.scheduleNotifications
+import com.pitchedapps.frost.services.scheduleNotificationsFromPrefs
import com.pitchedapps.frost.services.setupNotificationChannels
import com.pitchedapps.frost.utils.BuildUtils
import com.pitchedapps.frost.utils.FrostPglAdBlock
@@ -96,7 +97,7 @@ class FrostApp : Application() {
setupNotificationChannels(applicationContext)
- applicationContext.scheduleNotifications(Prefs.notificationFreq)
+ scheduleNotificationsFromPrefs()
/**
* Drawer profile loading logic
diff --git a/app/src/main/kotlin/com/pitchedapps/frost/activities/BaseMainActivity.kt b/app/src/main/kotlin/com/pitchedapps/frost/activities/BaseMainActivity.kt
index 292db7cc..521049e7 100644
--- a/app/src/main/kotlin/com/pitchedapps/frost/activities/BaseMainActivity.kt
+++ b/app/src/main/kotlin/com/pitchedapps/frost/activities/BaseMainActivity.kt
@@ -83,6 +83,7 @@ import com.pitchedapps.frost.facebook.parsers.SearchParser
import com.pitchedapps.frost.facebook.profilePictureUrl
import com.pitchedapps.frost.fragments.BaseFragment
import com.pitchedapps.frost.fragments.WebFragment
+import com.pitchedapps.frost.services.scheduleNotificationsFromPrefs
import com.pitchedapps.frost.utils.ACTIVITY_SETTINGS
import com.pitchedapps.frost.utils.EXTRA_COOKIES
import com.pitchedapps.frost.utils.L
@@ -90,6 +91,7 @@ import com.pitchedapps.frost.utils.MAIN_TIMEOUT_DURATION
import com.pitchedapps.frost.utils.Prefs
import com.pitchedapps.frost.utils.REQUEST_FAB
import com.pitchedapps.frost.utils.REQUEST_NAV
+import com.pitchedapps.frost.utils.REQUEST_NOTIFICATION
import com.pitchedapps.frost.utils.REQUEST_REFRESH
import com.pitchedapps.frost.utils.REQUEST_RESTART
import com.pitchedapps.frost.utils.REQUEST_RESTART_APPLICATION
@@ -493,6 +495,9 @@ abstract class BaseMainActivity : BaseActivity(), MainActivityContract,
if (hasRequest(REQUEST_FAB)) {
fragmentChannel.offer(lastPosition)
}
+ if (hasRequest(REQUEST_NOTIFICATION)) {
+ scheduleNotificationsFromPrefs()
+ }
}
}
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 bb5594fe..cab1311c 100644
--- a/app/src/main/kotlin/com/pitchedapps/frost/services/FrostNotifications.kt
+++ b/app/src/main/kotlin/com/pitchedapps/frost/services/FrostNotifications.kt
@@ -43,6 +43,7 @@ import com.pitchedapps.frost.facebook.parsers.NotifParser
import com.pitchedapps.frost.facebook.parsers.ParseNotification
import com.pitchedapps.frost.glide.FrostGlide
import com.pitchedapps.frost.glide.GlideApp
+import com.pitchedapps.frost.settings.hasNotifications
import com.pitchedapps.frost.utils.ARG_USER_ID
import com.pitchedapps.frost.utils.L
import com.pitchedapps.frost.utils.Prefs
@@ -321,6 +322,12 @@ data class FrostNotification(
NotificationManagerCompat.from(context).notify(tag, id, notif.build())
}
+fun Context.scheduleNotificationsFromPrefs(): Boolean {
+ val shouldSchedule = Prefs.hasNotifications
+ return if (shouldSchedule) scheduleNotifications(Prefs.notificationFreq)
+ else scheduleNotifications(-1)
+}
+
fun Context.scheduleNotifications(minutes: Long): Boolean =
scheduleJob<NotificationService>(NOTIFICATION_PERIODIC_JOB, minutes)
diff --git a/app/src/main/kotlin/com/pitchedapps/frost/settings/Behaviour.kt b/app/src/main/kotlin/com/pitchedapps/frost/settings/Behaviour.kt
index c4fa4c4d..1ab53a56 100644
--- a/app/src/main/kotlin/com/pitchedapps/frost/settings/Behaviour.kt
+++ b/app/src/main/kotlin/com/pitchedapps/frost/settings/Behaviour.kt
@@ -83,7 +83,10 @@ fun SettingsActivity.getBehaviourPrefs(): KPrefAdapterBuilder.() -> Unit = {
descRes = R.string.exit_confirmation_desc
}
- checkbox(R.string.web_only, Prefs::webOnly, { Prefs.webOnly = it }) {
+ checkbox(R.string.web_only, Prefs::webOnly, {
+ Prefs.webOnly = it
+ shouldRestartMain()
+ }) {
descRes = R.string.web_only_desc
}
diff --git a/app/src/main/kotlin/com/pitchedapps/frost/settings/Notifications.kt b/app/src/main/kotlin/com/pitchedapps/frost/settings/Notifications.kt
index baf2949f..ccf04935 100644
--- a/app/src/main/kotlin/com/pitchedapps/frost/settings/Notifications.kt
+++ b/app/src/main/kotlin/com/pitchedapps/frost/settings/Notifications.kt
@@ -36,8 +36,8 @@ import com.pitchedapps.frost.activities.SettingsActivity
import com.pitchedapps.frost.db.FrostDatabase
import com.pitchedapps.frost.db.deleteAll
import com.pitchedapps.frost.services.fetchNotifications
-import com.pitchedapps.frost.services.scheduleNotifications
import com.pitchedapps.frost.utils.Prefs
+import com.pitchedapps.frost.utils.REQUEST_NOTIFICATION
import com.pitchedapps.frost.utils.frostSnackbar
import com.pitchedapps.frost.utils.frostUri
import com.pitchedapps.frost.views.Keywords
@@ -46,6 +46,10 @@ import kotlinx.coroutines.launch
/**
* Created by Allan Wang on 2017-06-29.
*/
+
+val Prefs.hasNotifications: Boolean
+ get() = !webOnly && (notificationsGeneral || notificationsInstantMessages)
+
@SuppressLint("InlinedApi")
fun SettingsActivity.getNotificationPrefs(): KPrefAdapterBuilder.() -> Unit = {
@@ -56,7 +60,7 @@ fun SettingsActivity.getNotificationPrefs(): KPrefAdapterBuilder.() -> Unit = {
message(R.string.leave_web_only_desc)
positiveButton(R.string.kau_yes) {
Prefs.webOnly = false
- reloadList()
+ reload()
}
negativeButton(R.string.kau_no)
}
@@ -78,21 +82,14 @@ fun SettingsActivity.getNotificationPrefs(): KPrefAdapterBuilder.() -> Unit = {
initialSelection = options.indexOf(item.pref)
) { _, index, _ ->
item.pref = options[index]
- scheduleNotifications(item.pref)
+ setFrostResult(REQUEST_NOTIFICATION)
}
}
}
onDisabledClick = {
leaveWebOnlyDialog()
}
- enabler = {
- val enabled =
- !Prefs.webOnly && (Prefs.notificationsGeneral || Prefs.notificationsInstantMessages)
- if (!enabled) {
- scheduleNotifications(-1)
- }
- enabled
- }
+ enabler = { Prefs.hasNotifications }
textGetter = { minuteToText(it) }
}
diff --git a/app/src/main/kotlin/com/pitchedapps/frost/utils/Const.kt b/app/src/main/kotlin/com/pitchedapps/frost/utils/Const.kt
index daca9676..5f65bba1 100644
--- a/app/src/main/kotlin/com/pitchedapps/frost/utils/Const.kt
+++ b/app/src/main/kotlin/com/pitchedapps/frost/utils/Const.kt
@@ -32,5 +32,6 @@ const val REQUEST_TEXT_ZOOM = 1 shl 8
const val REQUEST_NAV = 1 shl 9
const val REQUEST_SEARCH = 1 shl 10
const val REQUEST_FAB = 1 shl 11
+const val REQUEST_NOTIFICATION = 1 shl 12
const val MAIN_TIMEOUT_DURATION = 30 * 60 * 1000 // 30 min