diff options
Diffstat (limited to 'app/src')
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() } - } - } -} |