aboutsummaryrefslogtreecommitdiff
path: root/app/src/main/kotlin/com
diff options
context:
space:
mode:
Diffstat (limited to 'app/src/main/kotlin/com')
-rw-r--r--app/src/main/kotlin/com/pitchedapps/frost/FrostApp.kt20
-rw-r--r--app/src/main/kotlin/com/pitchedapps/frost/StartActivity.kt61
-rw-r--r--app/src/main/kotlin/com/pitchedapps/frost/activities/AboutActivity.kt4
-rw-r--r--app/src/main/kotlin/com/pitchedapps/frost/activities/SettingsActivity.kt14
-rw-r--r--app/src/main/kotlin/com/pitchedapps/frost/activities/UpdateActivity.kt31
-rw-r--r--app/src/main/kotlin/com/pitchedapps/frost/dbflow/NotificationDb.kt4
-rw-r--r--app/src/main/kotlin/com/pitchedapps/frost/facebook/FbUrlFormatter.kt2
-rw-r--r--app/src/main/kotlin/com/pitchedapps/frost/iitems/ReleaseIItem.kt38
-rw-r--r--app/src/main/kotlin/com/pitchedapps/frost/rx/RxFlyweight.kt2
-rw-r--r--app/src/main/kotlin/com/pitchedapps/frost/services/FrostNotifications.kt2
-rw-r--r--app/src/main/kotlin/com/pitchedapps/frost/services/NotificationService.kt2
-rw-r--r--app/src/main/kotlin/com/pitchedapps/frost/services/NotificationUtils.kt6
-rw-r--r--app/src/main/kotlin/com/pitchedapps/frost/services/UpdateService.kt146
-rw-r--r--app/src/main/kotlin/com/pitchedapps/frost/utils/Prefs.kt2
-rw-r--r--app/src/main/kotlin/com/pitchedapps/frost/utils/ReleasePrefs.kt13
15 files changed, 66 insertions, 281 deletions
diff --git a/app/src/main/kotlin/com/pitchedapps/frost/FrostApp.kt b/app/src/main/kotlin/com/pitchedapps/frost/FrostApp.kt
index dec22e88..ae4360a5 100644
--- a/app/src/main/kotlin/com/pitchedapps/frost/FrostApp.kt
+++ b/app/src/main/kotlin/com/pitchedapps/frost/FrostApp.kt
@@ -18,12 +18,14 @@ import com.pitchedapps.frost.dbflow.FbTabsDb
import com.pitchedapps.frost.dbflow.NotificationDb
import com.pitchedapps.frost.facebook.FbCookie
import com.pitchedapps.frost.glide.GlideApp
-import com.pitchedapps.frost.services.*
+import com.pitchedapps.frost.services.scheduleNotifications
+import com.pitchedapps.frost.services.setupNotificationChannels
import com.pitchedapps.frost.utils.*
import com.raizlabs.android.dbflow.config.DatabaseConfig
import com.raizlabs.android.dbflow.config.FlowConfig
import com.raizlabs.android.dbflow.config.FlowManager
import com.raizlabs.android.dbflow.runtime.ContentResolverNotifier
+import io.reactivex.exceptions.UndeliverableException
import io.reactivex.plugins.RxJavaPlugins
import java.net.SocketTimeoutException
import java.util.*
@@ -60,7 +62,6 @@ class FrostApp : Application() {
.build())
Showcase.initialize(this, "${BuildConfig.APPLICATION_ID}.showcase")
Prefs.initialize(this, "${BuildConfig.APPLICATION_ID}.prefs")
- ReleasePrefs.initialize(this, "${BuildConfig.APPLICATION_ID}.manager")
// if (LeakCanary.isInAnalyzerProcess(this)) return
// refWatcher = LeakCanary.install(this)
if (!BuildConfig.DEBUG) {
@@ -84,7 +85,11 @@ class FrostApp : Application() {
KL.shouldLog = { BuildConfig.DEBUG }
Prefs.verboseLogging = false
L.i { "Begin Frost for Facebook" }
- FbCookie()
+ try {
+ FbCookie()
+ } catch (e: Exception) {
+ // no webview found; error will be handled in start activity
+ }
FrostPglAdBlock.init(this)
if (Prefs.installDate == -1L) Prefs.installDate = System.currentTimeMillis()
if (Prefs.identifier == -1) Prefs.identifier = Random().nextInt(Int.MAX_VALUE)
@@ -95,7 +100,6 @@ class FrostApp : Application() {
setupNotificationChannels(applicationContext)
applicationContext.scheduleNotifications(Prefs.notificationFreq)
- applicationContext.scheduleUpdater(ReleasePrefs.enableUpdater)
/**
* Drawer profile loading logic
@@ -132,12 +136,14 @@ class FrostApp : Application() {
RxJavaPlugins.setErrorHandler {
when (it) {
- is SocketTimeoutException -> Unit
- else -> L.e(it) { "RxJava error" }
+ is SocketTimeoutException, is UndeliverableException ->
+ L.e { "RxJava common error ${it.message}" }
+ else ->
+ L.e(it) { "RxJava error" }
}
}
}
-} \ No newline at end of file
+}
diff --git a/app/src/main/kotlin/com/pitchedapps/frost/StartActivity.kt b/app/src/main/kotlin/com/pitchedapps/frost/StartActivity.kt
index 54a48112..034dabe2 100644
--- a/app/src/main/kotlin/com/pitchedapps/frost/StartActivity.kt
+++ b/app/src/main/kotlin/com/pitchedapps/frost/StartActivity.kt
@@ -10,6 +10,7 @@ import ca.allanwang.kau.internal.KauBaseActivity
import ca.allanwang.kau.utils.buildIsLollipopAndUp
import ca.allanwang.kau.utils.setIcon
import ca.allanwang.kau.utils.startActivity
+import ca.allanwang.kau.utils.string
import com.mikepenz.google_material_typeface_library.GoogleMaterial
import com.pitchedapps.frost.activities.LoginActivity
import com.pitchedapps.frost.activities.MainActivity
@@ -35,37 +36,49 @@ class StartActivity : KauBaseActivity() {
return
}
- FbCookie.switchBackUser {
- loadFbCookiesAsync {
- val cookies = ArrayList(it)
- L.i { "Cookies loaded at time ${System.currentTimeMillis()}" }
- L._d { "Cookies: ${cookies.joinToString("\t")}" }
- if (cookies.isNotEmpty()) {
- if (Prefs.userId != -1L)
- startActivity<MainActivity>(intentBuilder = {
- putParcelableArrayListExtra(EXTRA_COOKIES, cookies)
- flags = Intent.FLAG_ACTIVITY_NEW_TASK or Intent.FLAG_ACTIVITY_CLEAR_TOP or Intent.FLAG_ACTIVITY_SINGLE_TOP
- })
- else
- launchNewTask<SelectorActivity>(cookies)
- } else
- launchNewTask<LoginActivity>()
+ try {
+ FbCookie.switchBackUser {
+ loadFbCookiesAsync {
+ val cookies = ArrayList(it)
+ L.i { "Cookies loaded at time ${System.currentTimeMillis()}" }
+ L._d { "Cookies: ${cookies.joinToString("\t")}" }
+ if (cookies.isNotEmpty()) {
+ if (Prefs.userId != -1L)
+ startActivity<MainActivity>(intentBuilder = {
+ putParcelableArrayListExtra(EXTRA_COOKIES, cookies)
+ flags = Intent.FLAG_ACTIVITY_NEW_TASK or Intent.FLAG_ACTIVITY_CLEAR_TOP or Intent.FLAG_ACTIVITY_SINGLE_TOP
+ })
+ else
+ launchNewTask<SelectorActivity>(cookies)
+ } else
+ launchNewTask<LoginActivity>()
+ }
}
+ } catch (e: Exception) {
+ showInvalidWebView()
}
}
+ private fun showInvalidWebView() =
+ showInvalidView(R.string.error_webview)
+
private fun showInvalidSdkView() {
- setContentView(R.layout.activity_invalid_sdk)
+ val text = try {
+ String.format(getString(R.string.error_sdk), Build.VERSION.SDK_INT)
+ } catch (e: IllegalFormatException) {
+ string(R.string.error_sdk)
+ }
+ showInvalidView(text)
+ }
+
+ private fun showInvalidView(textRes: Int) =
+ showInvalidView(string(textRes))
+
+ private fun showInvalidView(text: String) {
+ setContentView(R.layout.activity_invalid)
findViewById<ImageView>(R.id.invalid_icon)
.setIcon(GoogleMaterial.Icon.gmd_adb, -1, Color.WHITE)
-
- findViewById<TextView>(R.id.invalid_text).apply {
- try {
- text = String.format(getString(R.string.error_sdk), Build.VERSION.SDK_INT)
- } catch (e: IllegalFormatException) {
- setText(R.string.error_sdk)
- }
- }
+ findViewById<TextView>(R.id.invalid_text).text = text
}
} \ No newline at end of file
diff --git a/app/src/main/kotlin/com/pitchedapps/frost/activities/AboutActivity.kt b/app/src/main/kotlin/com/pitchedapps/frost/activities/AboutActivity.kt
index ce306acc..9db1747b 100644
--- a/app/src/main/kotlin/com/pitchedapps/frost/activities/AboutActivity.kt
+++ b/app/src/main/kotlin/com/pitchedapps/frost/activities/AboutActivity.kt
@@ -18,6 +18,7 @@ import com.mikepenz.aboutlibraries.entity.License
import com.mikepenz.community_material_typeface_library.CommunityMaterial
import com.mikepenz.fastadapter.IItem
import com.mikepenz.fastadapter.items.AbstractItem
+import com.mikepenz.google_material_typeface_library.GoogleMaterial
import com.mikepenz.iconics.typeface.IIcon
import com.pitchedapps.frost.BuildConfig
import com.pitchedapps.frost.R
@@ -135,9 +136,10 @@ class AboutActivity : AboutActivityBase(null, {
val c = itemView.context
val size = c.dimenPixelSize(R.dimen.kau_avatar_bounds)
images = arrayOf<Pair<IIcon, () -> Unit>>(
-// GoogleMaterial.Icon.gmd_star to { c.startPlayStoreLink(R.string.play_store_package_id) },
+ GoogleMaterial.Icon.gmd_star to { c.startLink(R.string.xda_labs_url) },
CommunityMaterial.Icon.cmd_reddit to { c.startLink(R.string.reddit_url) },
CommunityMaterial.Icon.cmd_github_circle to { c.startLink(R.string.github_url) },
+ CommunityMaterial.Icon.cmd_slack to { c.startLink(R.string.slack_url) },
CommunityMaterial.Icon.cmd_xda to { c.startLink(R.string.xda_url) }
).mapIndexed { i, (icon, onClick) ->
ImageView(c).apply {
diff --git a/app/src/main/kotlin/com/pitchedapps/frost/activities/SettingsActivity.kt b/app/src/main/kotlin/com/pitchedapps/frost/activities/SettingsActivity.kt
index 02f5bc49..237780b8 100644
--- a/app/src/main/kotlin/com/pitchedapps/frost/activities/SettingsActivity.kt
+++ b/app/src/main/kotlin/com/pitchedapps/frost/activities/SettingsActivity.kt
@@ -113,11 +113,6 @@ class SettingsActivity : KPrefActivity() {
// iicon = GoogleMaterial.Icon.gmd_network_cell
// }
- subItems(R.string.experimental, getExperimentalPrefs()) {
- descRes = R.string.experimental_desc
- iicon = CommunityMaterial.Icon.cmd_flask_outline
- }
-
// todo add donation?
plainText(R.string.about_frost) {
@@ -141,11 +136,10 @@ class SettingsActivity : KPrefActivity() {
onClick = { launchNewTask<IntroActivity>(cookies(), true) }
}
-// plainText(R.string.updates) {
-// descRes = R.string.updates_desc
-// iicon = CommunityMaterial.Icon.cmd_github_circle
-// onClick = { launchNewTask<UpdateActivity>() }
-// }
+ subItems(R.string.experimental, getExperimentalPrefs()) {
+ descRes = R.string.experimental_desc
+ iicon = CommunityMaterial.Icon.cmd_flask_outline
+ }
subItems(R.string.debug_frost, getDebugPrefs()) {
descRes = R.string.debug_frost_desc
diff --git a/app/src/main/kotlin/com/pitchedapps/frost/activities/UpdateActivity.kt b/app/src/main/kotlin/com/pitchedapps/frost/activities/UpdateActivity.kt
deleted file mode 100644
index 28569e6d..00000000
--- a/app/src/main/kotlin/com/pitchedapps/frost/activities/UpdateActivity.kt
+++ /dev/null
@@ -1,31 +0,0 @@
-package com.pitchedapps.frost.activities
-
-import android.os.Bundle
-import ca.allanwang.kau.ui.activities.SwipeRecyclerActivity
-import ca.allanwang.kau.ui.views.SwipeRecyclerView
-import com.mikepenz.fastadapter.FastAdapter
-import com.pitchedapps.frost.iitems.ReleaseIItem
-import com.pitchedapps.frost.services.UpdateManager
-import org.jetbrains.anko.AnkoAsyncContext
-import org.jetbrains.anko.uiThread
-
-/**
- * Created by Allan Wang on 07/04/18.
- */
-class UpdateActivity : SwipeRecyclerActivity<ReleaseIItem>() {
-
- override fun onCreate(savedInstanceState: Bundle?, fastAdapter: FastAdapter<ReleaseIItem>) {
- fastAdapter.withOnClickListener { _, _, item, _ ->
- if (item is ReleaseIItem) {
- // todo download
- }
- true
- }
- }
-
- override fun AnkoAsyncContext<SwipeRecyclerView>.onRefresh() {
- val release = UpdateManager.getLatestGithubRelease() ?: return
- uiThread { adapter.set(listOf(ReleaseIItem(release))) }
- }
-
-} \ No newline at end of file
diff --git a/app/src/main/kotlin/com/pitchedapps/frost/dbflow/NotificationDb.kt b/app/src/main/kotlin/com/pitchedapps/frost/dbflow/NotificationDb.kt
index 60f8c5a2..b61fc218 100644
--- a/app/src/main/kotlin/com/pitchedapps/frost/dbflow/NotificationDb.kt
+++ b/app/src/main/kotlin/com/pitchedapps/frost/dbflow/NotificationDb.kt
@@ -27,7 +27,9 @@ class NotificationMigration2(modelClass: Class<NotificationModel>) : AlterTableM
}
@Table(database = NotificationDb::class, allFields = true, primaryKeyConflict = ConflictAction.REPLACE)
-data class NotificationModel(@PrimaryKey var id: Long = -1L, var epoch: Long = -1L, var epochIm: Long = -1) : BaseModel()
+data class NotificationModel(@PrimaryKey var id: Long = -1L,
+ var epoch: Long = -1L,
+ var epochIm: Long = -1L) : BaseModel()
fun lastNotificationTime(id: Long): NotificationModel = (select from NotificationModel::class where (NotificationModel_Table.id eq id)).querySingle()
?: NotificationModel(id = id)
diff --git a/app/src/main/kotlin/com/pitchedapps/frost/facebook/FbUrlFormatter.kt b/app/src/main/kotlin/com/pitchedapps/frost/facebook/FbUrlFormatter.kt
index 4386d0c9..f21c03e9 100644
--- a/app/src/main/kotlin/com/pitchedapps/frost/facebook/FbUrlFormatter.kt
+++ b/app/src/main/kotlin/com/pitchedapps/frost/facebook/FbUrlFormatter.kt
@@ -49,7 +49,7 @@ class FbUrlFormatter(url: String) {
if (qm > -1) {
cleanedUrl.substring(qm + 1).split("&").forEach {
val p = it.split("=")
- queries.put(p[0], p.elementAtOrNull(1) ?: "")
+ queries[p[0]] = p.elementAtOrNull(1) ?: ""
}
cleanedUrl = cleanedUrl.substring(0, qm)
}
diff --git a/app/src/main/kotlin/com/pitchedapps/frost/iitems/ReleaseIItem.kt b/app/src/main/kotlin/com/pitchedapps/frost/iitems/ReleaseIItem.kt
deleted file mode 100644
index abba63b5..00000000
--- a/app/src/main/kotlin/com/pitchedapps/frost/iitems/ReleaseIItem.kt
+++ /dev/null
@@ -1,38 +0,0 @@
-package com.pitchedapps.frost.iitems
-
-import android.view.View
-import android.widget.ImageView
-import android.widget.TextView
-import ca.allanwang.kau.iitems.KauIItem
-import ca.allanwang.kau.utils.*
-import com.mikepenz.fastadapter.FastAdapter
-import com.mikepenz.fastadapter.IItem
-import com.mikepenz.fastadapter_extensions.drag.IDraggable
-import com.pitchedapps.frost.R
-import com.pitchedapps.frost.facebook.FbItem
-import com.pitchedapps.frost.services.FrostRelease
-import com.pitchedapps.frost.utils.Prefs
-
-/**
- * Created by Allan Wang on 26/11/17.
- */
-class ReleaseIItem(val item: FrostRelease) : KauIItem<ReleaseIItem, ReleaseIItem.ViewHolder>(
- R.layout.iitem_tab_preview,
- { ViewHolder(it) }
-) {
-
- class ViewHolder(itemView: View) : FastAdapter.ViewHolder<ReleaseIItem>(itemView) {
-
- val image: ImageView by bindView(R.id.image)
- val text: TextView by bindView(R.id.text)
-
- override fun bindView(item: ReleaseIItem, payloads: MutableList<Any>) {
-
- }
-
- override fun unbindView(item: ReleaseIItem) {
-
- }
-
- }
-} \ No newline at end of file
diff --git a/app/src/main/kotlin/com/pitchedapps/frost/rx/RxFlyweight.kt b/app/src/main/kotlin/com/pitchedapps/frost/rx/RxFlyweight.kt
index d174cfec..e8373dd6 100644
--- a/app/src/main/kotlin/com/pitchedapps/frost/rx/RxFlyweight.kt
+++ b/app/src/main/kotlin/com/pitchedapps/frost/rx/RxFlyweight.kt
@@ -71,7 +71,7 @@ abstract class RxFlyweight<in T : Any, C : Any, R : Any> {
* If you don't have a need for cache,
* you likely won't have a need for flyweights
*/
- open protected fun createNewSource(input: T): Single<R> =
+ protected open fun createNewSource(input: T): Single<R> =
Single.fromCallable { call(input) }
.timeout(15, TimeUnit.SECONDS)
.subscribeOn(Schedulers.io())
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 0af76b31..bc2e66a5 100644
--- a/app/src/main/kotlin/com/pitchedapps/frost/services/FrostNotifications.kt
+++ b/app/src/main/kotlin/com/pitchedapps/frost/services/FrostNotifications.kt
@@ -120,6 +120,8 @@ enum class NotificationType(
if (newLatestEpoch > prevLatestEpoch)
putTime(prevNotifTime, newLatestEpoch).save()
L.d { "Notif $name new epoch ${getTime(lastNotificationTime(userId))}" }
+ if (prevLatestEpoch == -1L)
+ return 0 // do not notify the first time
frostEvent("Notifications", "Type" to name, "Count" to notifs.size)
if (notifs.size > 1)
summaryNotification(context, userId, notifs.size).notify(context)
diff --git a/app/src/main/kotlin/com/pitchedapps/frost/services/NotificationService.kt b/app/src/main/kotlin/com/pitchedapps/frost/services/NotificationService.kt
index 22477eab..35dd9571 100644
--- a/app/src/main/kotlin/com/pitchedapps/frost/services/NotificationService.kt
+++ b/app/src/main/kotlin/com/pitchedapps/frost/services/NotificationService.kt
@@ -55,8 +55,6 @@ class NotificationService : JobService() {
override fun onStartJob(params: JobParameters?): Boolean {
L.i { "Fetching notifications" }
future = doAsync {
- val context = weakRef.get()
- ?: return@doAsync L.eThrow("NotificationService had null weakRef to self")
val currentId = Prefs.userId
val cookies = loadFbCookiesSync()
val jobId = params?.extras?.getInt(NOTIFICATION_PARAM_ID, -1) ?: -1
diff --git a/app/src/main/kotlin/com/pitchedapps/frost/services/NotificationUtils.kt b/app/src/main/kotlin/com/pitchedapps/frost/services/NotificationUtils.kt
index 7014cb78..59352f8e 100644
--- a/app/src/main/kotlin/com/pitchedapps/frost/services/NotificationUtils.kt
+++ b/app/src/main/kotlin/com/pitchedapps/frost/services/NotificationUtils.kt
@@ -24,24 +24,20 @@ import com.pitchedapps.frost.utils.Prefs
*/
const val NOTIF_CHANNEL_GENERAL = "general"
const val NOTIF_CHANNEL_MESSAGES = "messages"
-const val NOTIF_CHANNEL_UPDATES = "updates"
fun setupNotificationChannels(c: Context) {
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.O) return
val manager = c.getSystemService(Context.NOTIFICATION_SERVICE) as NotificationManager
val appName = c.string(R.string.frost_name)
val msg = c.string(R.string.messages)
- val updates = c.string(R.string.updates)
manager.notificationChannels
.filter {
it.id != NOTIF_CHANNEL_GENERAL
&& it.id != NOTIF_CHANNEL_MESSAGES
- && it.id != NOTIF_CHANNEL_UPDATES
}
.forEach { manager.deleteNotificationChannel(it.id) }
manager.createNotificationChannel(NOTIF_CHANNEL_GENERAL, appName)
manager.createNotificationChannel(NOTIF_CHANNEL_MESSAGES, "$appName: $msg")
- manager.createNotificationChannel(NOTIF_CHANNEL_UPDATES, "$appName: $updates")
L.d { "Created notification channels: ${manager.notificationChannels.size} channels, ${manager.notificationChannelGroups.size} groups" }
}
@@ -144,4 +140,4 @@ inline fun <reified T : JobService> Context.fetchJob(id: Int): Boolean {
return false
}
return true
-} \ No newline at end of file
+}
diff --git a/app/src/main/kotlin/com/pitchedapps/frost/services/UpdateService.kt b/app/src/main/kotlin/com/pitchedapps/frost/services/UpdateService.kt
deleted file mode 100644
index 0a528a0f..00000000
--- a/app/src/main/kotlin/com/pitchedapps/frost/services/UpdateService.kt
+++ /dev/null
@@ -1,146 +0,0 @@
-package com.pitchedapps.frost.services
-
-import android.app.job.JobParameters
-import android.app.job.JobService
-import android.content.Context
-import android.support.v4.app.NotificationManagerCompat
-import ca.allanwang.kau.kotlin.firstOrNull
-import ca.allanwang.kau.utils.string
-import com.fasterxml.jackson.databind.JsonNode
-import com.fasterxml.jackson.databind.ObjectMapper
-import com.pitchedapps.frost.BuildConfig
-import com.pitchedapps.frost.R
-import com.pitchedapps.frost.facebook.requests.httpClient
-import com.pitchedapps.frost.utils.L
-import com.pitchedapps.frost.utils.Prefs
-import com.pitchedapps.frost.utils.ReleasePrefs
-import com.pitchedapps.frost.utils.frostEvent
-import okhttp3.Request
-import org.jetbrains.anko.doAsync
-import org.joda.time.DateTime
-import java.util.concurrent.Future
-
-/**
- * Created by Allan Wang on 07/04/18.
- */
-data class FrostRelease(val versionName: String,
- val timestamp: Long,
- val apk: FrostApkRelease? = null,
- val category: String = "")
-
-data class FrostApkRelease(val size: Long,
- val name: String,
- val url: String,
- val timestamp: Long,
- val downloadCount: Long = -1)
-
-object UpdateManager {
- internal fun getLatestGithubRelease(): FrostRelease? {
- try {
- val data = getGithubReleaseJsonV3() ?: return null
- return parseGithubReleaseV3(data)
- } catch (e: Exception) {
- L.e(e) {
- "Failed to get github release"
- }
- return null
- }
- }
-
- private fun JsonNode.asMillis(): Long = DateTime(asText()).millis
-
- private fun getGithubReleaseJsonV3(): JsonNode? {
- val mapper = ObjectMapper()
- val response = httpClient.newCall(Request.Builder()
- .url("https://api.github.com/repos/AllanWang/Frost-for-Facebook/releases/latest")
- .get().build()).execute().body()?.string() ?: return null
- return mapper.readTree(response)
- }
-
- private fun parseGithubReleaseV3(data: JsonNode): FrostRelease? {
- val versionName = data.get("tag_name").asText()
- if (versionName.isEmpty()) return null
- val release = FrostRelease(
- versionName = versionName,
- timestamp = data.get("created_at").asMillis(),
- category = "Github")
- val assets = data.get("assets")
- if (!assets.isArray) return release
- val apkRelease = assets.elements().firstOrNull {
- it.get("content_type").asText().contains("android")
- } ?: return release
- val apk = FrostApkRelease(size = apkRelease.get("size").asLong(),
- name = apkRelease.get("name").asText(),
- url = apkRelease.get("browser_download_url").asText(),
- timestamp = apkRelease.get("updated_at").asMillis(),
- downloadCount = apkRelease.get("download_count").asLong())
- return release.copy(apk = apk)
- }
-}
-
-class UpdateService : JobService() {
-
- private var future: Future<Unit>? = null
-
- private val startTime = System.currentTimeMillis()
-
- override fun onStopJob(params: JobParameters?): Boolean {
- val time = System.currentTimeMillis() - startTime
- L.d { "Update service has finished abruptly in $time ms" }
- frostEvent("UpdateTime",
- "Type" to "Service force stop",
- "Duration" to time)
- future?.cancel(true)
- future = null
- return false
- }
-
- fun finish(params: JobParameters?) {
- val time = System.currentTimeMillis() - startTime
- L.i { "Update service has finished in $time ms" }
- frostEvent("UpdateTime",
- "Type" to "Service",
- "Duration" to time)
- jobFinished(params, false)
- future?.cancel(true)
- future = null
- }
-
- override fun onStartJob(params: JobParameters?): Boolean {
-// L.i { "Fetching update" }
-// future = doAsync {
-// fetch()
-// finish(params)
-// }
-// return true
- return false
- }
-
- private fun fetch() {
- val release = UpdateManager.getLatestGithubRelease() ?: return
- val timestamp = release.apk?.timestamp ?: return
- if (ReleasePrefs.lastTimeStamp >= timestamp) return
- ReleasePrefs.lastTimeStamp = timestamp
- if (BuildConfig.VERSION_NAME.contains(release.apk.name)) return
- updateNotification(release)
- }
-
- private fun updateNotification(release: FrostRelease) {
- val notifBuilder = frostNotification(NOTIF_CHANNEL_UPDATES)
- .setFrostAlert(true, Prefs.notificationRingtone)
- .setContentTitle(string(R.string.frost_name))
- .setContentText(string(R.string.update_notif_message))
- NotificationManagerCompat.from(this).notify(release.versionName.hashCode(), notifBuilder.build())
- }
-
-}
-
-const val UPDATE_PERIODIC_JOB = 7
-
-fun Context.scheduleUpdater(enable: Boolean): Boolean =
- scheduleJob<UpdateService>(UPDATE_PERIODIC_JOB, if (enable) 1440 else -1)
-
-const val UPDATE_JOB_NOW = 6
-
-fun Context.fetchUpdates(): Boolean =
- fetchJob<UpdateService>(UPDATE_JOB_NOW) \ No newline at end of file
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 59112e70..a89fdc54 100644
--- a/app/src/main/kotlin/com/pitchedapps/frost/utils/Prefs.kt
+++ b/app/src/main/kotlin/com/pitchedapps/frost/utils/Prefs.kt
@@ -107,7 +107,7 @@ object Prefs : KPref() {
var showSuggestedGroups: Boolean by kpref("suggested_groups_feed", true)
- var showFacebookAds: Boolean by kpref("facebook_ads", true)
+ var showFacebookAds: Boolean by kpref("facebook_ads", false)
var animate: Boolean by kpref("fancy_animations", true)
diff --git a/app/src/main/kotlin/com/pitchedapps/frost/utils/ReleasePrefs.kt b/app/src/main/kotlin/com/pitchedapps/frost/utils/ReleasePrefs.kt
deleted file mode 100644
index 1e9dd763..00000000
--- a/app/src/main/kotlin/com/pitchedapps/frost/utils/ReleasePrefs.kt
+++ /dev/null
@@ -1,13 +0,0 @@
-package com.pitchedapps.frost.utils
-
-import ca.allanwang.kau.kpref.KPref
-import ca.allanwang.kau.kpref.kpref
-import com.pitchedapps.frost.BuildConfig
-
-/**
- * Created by Allan Wang on 07/04/18.
- */
-object ReleasePrefs : KPref() {
- var lastTimeStamp: Long by kpref("last_time_stamp", -1L)
- var enableUpdater: Boolean by kpref("enable_updater", BuildConfig.FLAVOR == FLAVOUR_GITHUB)
-} \ No newline at end of file