aboutsummaryrefslogtreecommitdiff
path: root/app/src/main/kotlin/com/pitchedapps/frost/utils/Utils.kt
diff options
context:
space:
mode:
authorAllan Wang <me@allanwang.ca>2017-06-19 15:31:10 -0700
committerAllan Wang <me@allanwang.ca>2017-06-19 15:31:10 -0700
commit382433780c3f4403723a78e409cb161c9fad5034 (patch)
tree1138696bdd6e04d2227acaa4ab19ee8b85b4d2f8 /app/src/main/kotlin/com/pitchedapps/frost/utils/Utils.kt
parent0720413ee859762fc4c2d8748ba10402dffd0be7 (diff)
downloadfrost-382433780c3f4403723a78e409cb161c9fad5034.tar.gz
frost-382433780c3f4403723a78e409cb161c9fad5034.tar.bz2
frost-382433780c3f4403723a78e409cb161c9fad5034.zip
Parse header badges
Diffstat (limited to 'app/src/main/kotlin/com/pitchedapps/frost/utils/Utils.kt')
-rw-r--r--app/src/main/kotlin/com/pitchedapps/frost/utils/Utils.kt28
1 files changed, 27 insertions, 1 deletions
diff --git a/app/src/main/kotlin/com/pitchedapps/frost/utils/Utils.kt b/app/src/main/kotlin/com/pitchedapps/frost/utils/Utils.kt
index abbd8366..52922822 100644
--- a/app/src/main/kotlin/com/pitchedapps/frost/utils/Utils.kt
+++ b/app/src/main/kotlin/com/pitchedapps/frost/utils/Utils.kt
@@ -1,11 +1,13 @@
package com.pitchedapps.frost.utils
import android.app.Activity
+import android.app.job.JobInfo
+import android.app.job.JobScheduler
+import android.content.ComponentName
import android.content.Context
import android.content.Intent
import android.graphics.Color
import android.graphics.drawable.ColorDrawable
-import android.support.v4.app.ActivityOptionsCompat
import android.support.v4.content.ContextCompat
import android.support.v7.widget.Toolbar
import android.view.View
@@ -18,6 +20,7 @@ import com.pitchedapps.frost.WebOverlayActivity
import com.pitchedapps.frost.dbflow.CookieModel
import com.pitchedapps.frost.facebook.FB_URL_BASE
import com.pitchedapps.frost.facebook.FbTab
+import com.pitchedapps.frost.services.NotificationService
/**
* Created by Allan Wang on 2017-06-03.
@@ -99,4 +102,27 @@ fun Activity.setFrostColors(toolbar: Toolbar? = null, themeWindow: Boolean = tru
texts.forEach { it.setTextColor(Prefs.textColor) }
headers.forEach { it.setBackgroundColor(darkAccent) }
backgrounds.forEach { it.setBackgroundColor(Prefs.bgColor) }
+}
+
+
+const val NOTIFICATION_JOB = 7
+/**
+ * [interval] is # of min, which must be at least 15
+ * returns false if an error occurs; true otherwise
+ */
+fun Context.scheduleNotifications(minutes: Long): Boolean {
+ val scheduler = getSystemService(Context.JOB_SCHEDULER_SERVICE) as JobScheduler
+ scheduler.cancel(NOTIFICATION_JOB)
+ if (minutes < 0L) return true
+ val serviceComponent = ComponentName(this, NotificationService::class.java)
+ val builder = JobInfo.Builder(NOTIFICATION_JOB, serviceComponent)
+ .setPeriodic(minutes * 60000)
+ .setPersisted(true)
+ .setRequiredNetworkType(JobInfo.NETWORK_TYPE_ANY) //TODO add options
+ val result = scheduler.schedule(builder.build())
+ if (result <= 0) {
+ L.e("Notification scheduler failed")
+ return false
+ }
+ return true
} \ No newline at end of file