aboutsummaryrefslogtreecommitdiff
path: root/app
diff options
context:
space:
mode:
authorAllan Wang <me@allanwang.ca>2021-11-19 21:47:22 -0800
committerAllan Wang <me@allanwang.ca>2021-11-19 21:47:22 -0800
commit2febf338614e318ad39ed4a2960a351fb3875c43 (patch)
treeb2fdca4b31a5aa9001e97094e2639d06f475ea90 /app
parent9a3f7861a798ce3c195915b5fb9dc7f63bdb4aac (diff)
downloadfrost-2febf338614e318ad39ed4a2960a351fb3875c43.tar.gz
frost-2febf338614e318ad39ed4a2960a351fb3875c43.tar.bz2
frost-2febf338614e318ad39ed4a2960a351fb3875c43.zip
Remove image purging
Diffstat (limited to 'app')
-rw-r--r--app/src/main/AndroidManifest.xml5
-rw-r--r--app/src/main/kotlin/com/pitchedapps/frost/activities/ImageActivity.kt21
-rw-r--r--app/src/main/kotlin/com/pitchedapps/frost/services/LocalService.kt90
3 files changed, 2 insertions, 114 deletions
diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml
index 5485ac15..eeab750f 100644
--- a/app/src/main/AndroidManifest.xml
+++ b/app/src/main/AndroidManifest.xml
@@ -173,11 +173,6 @@
android:enabled="true"
android:label="@string/frost_notifications"
android:permission="android.permission.BIND_JOB_SERVICE" />
- <service
- android:name=".services.LocalService"
- android:enabled="true"
- android:label="@string/local_service_name"
- android:permission="android.permission.BIND_JOB_SERVICE" />
<receiver
android:name=".services.UpdateReceiver"
diff --git a/app/src/main/kotlin/com/pitchedapps/frost/activities/ImageActivity.kt b/app/src/main/kotlin/com/pitchedapps/frost/activities/ImageActivity.kt
index d8f5a46e..2700f1b4 100644
--- a/app/src/main/kotlin/com/pitchedapps/frost/activities/ImageActivity.kt
+++ b/app/src/main/kotlin/com/pitchedapps/frost/activities/ImageActivity.kt
@@ -16,7 +16,6 @@
*/
package com.pitchedapps.frost.activities
-import android.content.Context
import android.content.Intent
import android.content.res.ColorStateList
import android.graphics.Color
@@ -50,11 +49,9 @@ import com.mikepenz.iconics.typeface.IIcon
import com.mikepenz.iconics.typeface.library.googlematerial.GoogleMaterial
import com.pitchedapps.frost.R
import com.pitchedapps.frost.databinding.ActivityImageBinding
-import com.pitchedapps.frost.facebook.get
import com.pitchedapps.frost.facebook.requests.getFullSizedImageUrl
import com.pitchedapps.frost.injectors.ThemeProvider
import com.pitchedapps.frost.prefs.Prefs
-import com.pitchedapps.frost.services.LocalService
import com.pitchedapps.frost.utils.ARG_COOKIE
import com.pitchedapps.frost.utils.ARG_IMAGE_URL
import com.pitchedapps.frost.utils.ARG_TEXT
@@ -101,19 +98,6 @@ class ImageActivity : KauBaseActivity() {
private lateinit var dragHelper: ViewDragHelper
- companion object {
- /**
- * Cache folder to store images
- * Linked to the uri provider
- */
- private const val IMAGE_FOLDER = "images"
- const val PURGE_TIME: Long = 10 * 60 * 1000 // 10 min block
- private val L = KauLoggerExtension("Image", com.pitchedapps.frost.utils.L)
-
- fun cacheDir(context: Context): File =
- File(context.cacheDir, IMAGE_FOLDER)
- }
-
private val cookie: String? by lazy { intent.getStringExtra(ARG_COOKIE) }
val imageUrl: String by lazy { intent.getStringExtra(ARG_IMAGE_URL)?.trim('"') ?: "" }
@@ -318,9 +302,8 @@ class ImageActivity : KauBaseActivity() {
frostDownload(cookie = cookie, url = trueImageUrl.await())
}
- override fun onDestroy() {
- LocalService.schedule(this, LocalService.Flag.PURGE_IMAGE)
- super.onDestroy()
+ companion object {
+ private val L = KauLoggerExtension("Image", com.pitchedapps.frost.utils.L)
}
}
diff --git a/app/src/main/kotlin/com/pitchedapps/frost/services/LocalService.kt b/app/src/main/kotlin/com/pitchedapps/frost/services/LocalService.kt
deleted file mode 100644
index 3d66f1ee..00000000
--- a/app/src/main/kotlin/com/pitchedapps/frost/services/LocalService.kt
+++ /dev/null
@@ -1,90 +0,0 @@
-/*
- * Copyright 2018 Allan Wang
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation, either version 3 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-package com.pitchedapps.frost.services
-
-import android.app.job.JobInfo
-import android.app.job.JobParameters
-import android.app.job.JobScheduler
-import android.content.ComponentName
-import android.content.Context
-import android.os.PersistableBundle
-import com.pitchedapps.frost.activities.ImageActivity
-import com.pitchedapps.frost.utils.L
-import kotlinx.coroutines.Dispatchers
-import kotlinx.coroutines.launch
-import kotlinx.coroutines.withContext
-import java.io.FileFilter
-
-class LocalService : BaseJobService() {
-
- enum class Flag {
- PURGE_IMAGE
- }
-
- companion object {
- private const val FLAG = "extra_local_flag"
-
- /**
- * Launches a local service with the provided flag
- */
- fun schedule(context: Context, flag: Flag): Boolean {
- val scheduler = context.getSystemService(Context.JOB_SCHEDULER_SERVICE) as JobScheduler
- val serviceComponent = ComponentName(context, LocalService::class.java)
- val bundle = PersistableBundle()
- bundle.putString(FLAG, flag.name)
-
- val builder = JobInfo.Builder(LOCAL_SERVICE_BASE + flag.ordinal, serviceComponent)
- .setMinimumLatency(0L)
- .setExtras(bundle)
- .setOverrideDeadline(2000L)
-
- val result = scheduler.schedule(builder.build())
- if (result <= 0) {
- L.eThrow("FrostRequestService scheduler failed for ${flag.name}")
- return false
- }
- L.d { "Scheduled ${flag.name}" }
- return true
- }
- }
-
- override fun onStartJob(params: JobParameters?): Boolean {
- super.onStartJob(params)
- val flagString = params?.extras?.getString(FLAG)
- val flag: Flag = try {
- Flag.valueOf(flagString!!)
- } catch (e: Exception) {
- L.e { "Local service with invalid flag $flagString" }
- return true
- }
- launch {
- when (flag) {
- Flag.PURGE_IMAGE -> purgeImages()
- }
- }
- return false
- }
-
- private suspend fun purgeImages() {
- withContext(Dispatchers.IO) {
- val purge = System.currentTimeMillis() - ImageActivity.PURGE_TIME
- ImageActivity.cacheDir(this@LocalService)
- .listFiles(FileFilter { it.isFile && it.lastModified() < purge })
- ?.forEach { it.delete() }
- }
- }
-}