Option to disable app updates
This commit is contained in:
@@ -47,7 +47,7 @@
|
|||||||
<service
|
<service
|
||||||
android:name=".ui.download.DownloadService"
|
android:name=".ui.download.DownloadService"
|
||||||
android:foregroundServiceType="dataSync" />
|
android:foregroundServiceType="dataSync" />
|
||||||
<service android:name=".ui.settings.UpdateService" />
|
<service android:name=".ui.settings.AppUpdateService" />
|
||||||
|
|
||||||
<provider
|
<provider
|
||||||
android:name=".ui.search.MangaSuggestionsProvider"
|
android:name=".ui.search.MangaSuggestionsProvider"
|
||||||
|
|||||||
@@ -40,25 +40,27 @@ class KotatsuApp : Application() {
|
|||||||
startKoin {
|
startKoin {
|
||||||
androidLogger()
|
androidLogger()
|
||||||
androidContext(applicationContext)
|
androidContext(applicationContext)
|
||||||
module {
|
modules(
|
||||||
factory {
|
module {
|
||||||
okHttp()
|
factory {
|
||||||
.cache(CacheUtils.createHttpCache(applicationContext))
|
okHttp()
|
||||||
.build()
|
.cache(CacheUtils.createHttpCache(applicationContext))
|
||||||
|
.build()
|
||||||
|
}
|
||||||
|
single {
|
||||||
|
mangaDb().build()
|
||||||
|
}
|
||||||
|
single {
|
||||||
|
MangaLoaderContext()
|
||||||
|
}
|
||||||
|
factory {
|
||||||
|
AppSettings(applicationContext)
|
||||||
|
}
|
||||||
|
single {
|
||||||
|
PagesCache(applicationContext)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
single {
|
)
|
||||||
mangaDb().build()
|
|
||||||
}
|
|
||||||
single {
|
|
||||||
MangaLoaderContext()
|
|
||||||
}
|
|
||||||
factory {
|
|
||||||
AppSettings(applicationContext)
|
|
||||||
}
|
|
||||||
single {
|
|
||||||
PagesCache(applicationContext)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -35,10 +35,11 @@ data class VersionId(
|
|||||||
@JvmStatic
|
@JvmStatic
|
||||||
private fun variantWeight(variantType: String) =
|
private fun variantWeight(variantType: String) =
|
||||||
when (variantType.toLowerCase(Locale.ROOT)) {
|
when (variantType.toLowerCase(Locale.ROOT)) {
|
||||||
"a" -> 1
|
"a", "alpha" -> 1
|
||||||
"b" -> 2
|
"b", "beta" -> 2
|
||||||
"rc" -> 4
|
"rc" -> 4
|
||||||
else -> 8
|
"" -> 8
|
||||||
|
else -> 0
|
||||||
}
|
}
|
||||||
|
|
||||||
@JvmStatic
|
@JvmStatic
|
||||||
|
|||||||
@@ -42,6 +42,16 @@ class AppSettings private constructor(resources: Resources, private val prefs: S
|
|||||||
true
|
true
|
||||||
)
|
)
|
||||||
|
|
||||||
|
val appUpdateAuto by BoolPreferenceDelegate(
|
||||||
|
resources.getString(R.string.key_app_update_auto),
|
||||||
|
true
|
||||||
|
)
|
||||||
|
|
||||||
|
var appUpdate by LongPreferenceDelegate(
|
||||||
|
resources.getString(R.string.key_app_update),
|
||||||
|
0L
|
||||||
|
)
|
||||||
|
|
||||||
private var sourcesOrderStr by NullableStringPreferenceDelegate(resources.getString(R.string.key_sources_order))
|
private var sourcesOrderStr by NullableStringPreferenceDelegate(resources.getString(R.string.key_sources_order))
|
||||||
|
|
||||||
var sourcesOrder: List<Int>
|
var sourcesOrder: List<Int>
|
||||||
|
|||||||
@@ -29,7 +29,7 @@ import org.koitharu.kotatsu.ui.main.list.remote.RemoteListFragment
|
|||||||
import org.koitharu.kotatsu.ui.reader.ReaderActivity
|
import org.koitharu.kotatsu.ui.reader.ReaderActivity
|
||||||
import org.koitharu.kotatsu.ui.reader.ReaderState
|
import org.koitharu.kotatsu.ui.reader.ReaderState
|
||||||
import org.koitharu.kotatsu.ui.settings.SettingsActivity
|
import org.koitharu.kotatsu.ui.settings.SettingsActivity
|
||||||
import org.koitharu.kotatsu.ui.settings.UpdateService
|
import org.koitharu.kotatsu.ui.settings.AppUpdateService
|
||||||
import org.koitharu.kotatsu.utils.ext.getDisplayMessage
|
import org.koitharu.kotatsu.utils.ext.getDisplayMessage
|
||||||
import org.koitharu.kotatsu.utils.ext.resolveDp
|
import org.koitharu.kotatsu.utils.ext.resolveDp
|
||||||
|
|
||||||
@@ -67,7 +67,7 @@ class MainActivity : BaseActivity(), NavigationView.OnNavigationItemSelectedList
|
|||||||
setPrimaryFragment(HistoryListFragment.newInstance())
|
setPrimaryFragment(HistoryListFragment.newInstance())
|
||||||
}
|
}
|
||||||
drawer.postDelayed(4000) {
|
drawer.postDelayed(4000) {
|
||||||
UpdateService.startIfRequired(applicationContext)
|
AppUpdateService.startIfRequired(applicationContext)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -9,8 +9,6 @@ import android.graphics.BitmapFactory
|
|||||||
import android.net.Uri
|
import android.net.Uri
|
||||||
import android.os.Build
|
import android.os.Build
|
||||||
import androidx.core.app.NotificationCompat
|
import androidx.core.app.NotificationCompat
|
||||||
import androidx.core.content.edit
|
|
||||||
import androidx.preference.PreferenceManager
|
|
||||||
import kotlinx.coroutines.CancellationException
|
import kotlinx.coroutines.CancellationException
|
||||||
import kotlinx.coroutines.Dispatchers
|
import kotlinx.coroutines.Dispatchers
|
||||||
import kotlinx.coroutines.launch
|
import kotlinx.coroutines.launch
|
||||||
@@ -20,11 +18,12 @@ import org.koitharu.kotatsu.R
|
|||||||
import org.koitharu.kotatsu.core.github.AppVersion
|
import org.koitharu.kotatsu.core.github.AppVersion
|
||||||
import org.koitharu.kotatsu.core.github.GithubRepository
|
import org.koitharu.kotatsu.core.github.GithubRepository
|
||||||
import org.koitharu.kotatsu.core.github.VersionId
|
import org.koitharu.kotatsu.core.github.VersionId
|
||||||
|
import org.koitharu.kotatsu.core.prefs.AppSettings
|
||||||
import org.koitharu.kotatsu.ui.common.BaseService
|
import org.koitharu.kotatsu.ui.common.BaseService
|
||||||
import org.koitharu.kotatsu.utils.FileSizeUtils
|
import org.koitharu.kotatsu.utils.FileSizeUtils
|
||||||
import java.util.concurrent.TimeUnit
|
import java.util.concurrent.TimeUnit
|
||||||
|
|
||||||
class UpdateService : BaseService() {
|
class AppUpdateService : BaseService() {
|
||||||
|
|
||||||
override fun onStartCommand(intent: Intent?, flags: Int, startId: Int): Int {
|
override fun onStartCommand(intent: Intent?, flags: Int, startId: Int): Int {
|
||||||
launch(Dispatchers.IO) {
|
launch(Dispatchers.IO) {
|
||||||
@@ -38,9 +37,7 @@ class UpdateService : BaseService() {
|
|||||||
showUpdateNotification(version)
|
showUpdateNotification(version)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
PreferenceManager.getDefaultSharedPreferences(this@UpdateService).edit(true) {
|
AppSettings(this@AppUpdateService).appUpdate = System.currentTimeMillis()
|
||||||
putLong(getString(R.string.key_app_update), System.currentTimeMillis())
|
|
||||||
}
|
|
||||||
} catch (_: CancellationException) {
|
} catch (_: CancellationException) {
|
||||||
} catch (e: Throwable) {
|
} catch (e: Throwable) {
|
||||||
if (BuildConfig.DEBUG) {
|
if (BuildConfig.DEBUG) {
|
||||||
@@ -72,7 +69,7 @@ class UpdateService : BaseService() {
|
|||||||
builder.setContentText(buildString {
|
builder.setContentText(buildString {
|
||||||
append(newVersion.name)
|
append(newVersion.name)
|
||||||
append(" (")
|
append(" (")
|
||||||
append(FileSizeUtils.formatBytes(this@UpdateService, newVersion.apkSize))
|
append(FileSizeUtils.formatBytes(this@AppUpdateService, newVersion.apkSize))
|
||||||
append(')')
|
append(')')
|
||||||
})
|
})
|
||||||
builder.setContentIntent(
|
builder.setContentIntent(
|
||||||
@@ -96,13 +93,15 @@ class UpdateService : BaseService() {
|
|||||||
private val PERIOD = TimeUnit.HOURS.toMillis(10)
|
private val PERIOD = TimeUnit.HOURS.toMillis(10)
|
||||||
|
|
||||||
fun start(context: Context) =
|
fun start(context: Context) =
|
||||||
context.startService(Intent(context, UpdateService::class.java))
|
context.startService(Intent(context, AppUpdateService::class.java))
|
||||||
|
|
||||||
fun startIfRequired(context: Context) {
|
fun startIfRequired(context: Context) {
|
||||||
val lastUpdate = PreferenceManager.getDefaultSharedPreferences(context)
|
val settings = AppSettings(context)
|
||||||
.getLong(context.getString(R.string.key_app_update), 0)
|
if (settings.appUpdateAuto) {
|
||||||
if (lastUpdate + PERIOD < System.currentTimeMillis()) {
|
val lastUpdate = settings.appUpdate
|
||||||
start(context)
|
if (lastUpdate + PERIOD < System.currentTimeMillis()) {
|
||||||
|
start(context)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -0,0 +1,20 @@
|
|||||||
|
package org.koitharu.kotatsu.utils.delegates.prefs
|
||||||
|
|
||||||
|
import android.content.SharedPreferences
|
||||||
|
import androidx.core.content.edit
|
||||||
|
import kotlin.properties.ReadWriteProperty
|
||||||
|
import kotlin.reflect.KProperty
|
||||||
|
|
||||||
|
class LongPreferenceDelegate(private val key: String, private val defValue: Long) :
|
||||||
|
ReadWriteProperty<SharedPreferences, Long> {
|
||||||
|
|
||||||
|
override fun getValue(thisRef: SharedPreferences, property: KProperty<*>): Long {
|
||||||
|
return thisRef.getLong(key, defValue)
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun setValue(thisRef: SharedPreferences, property: KProperty<*>, value: Long) {
|
||||||
|
thisRef.edit {
|
||||||
|
putLong(key, value)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -107,4 +107,5 @@
|
|||||||
<string name="application_update">Обновление приложения</string>
|
<string name="application_update">Обновление приложения</string>
|
||||||
<string name="app_update_available">Доступно обновление приложения</string>
|
<string name="app_update_available">Доступно обновление приложения</string>
|
||||||
<string name="about_app">О программе</string>
|
<string name="about_app">О программе</string>
|
||||||
|
<string name="show_notification_app_update">Показывать уведомление при наличии новой версии</string>
|
||||||
</resources>
|
</resources>
|
||||||
@@ -11,6 +11,7 @@
|
|||||||
<string name="key_grid_size">grid_size</string>
|
<string name="key_grid_size">grid_size</string>
|
||||||
<string name="key_reader_switchers">reader_switchers</string>
|
<string name="key_reader_switchers">reader_switchers</string>
|
||||||
<string name="key_app_update">app_update</string>
|
<string name="key_app_update">app_update</string>
|
||||||
|
<string name="key_app_update_auto">app_update_auto</string>
|
||||||
|
|
||||||
<string name="key_parser_domain">domain</string>
|
<string name="key_parser_domain">domain</string>
|
||||||
<string-array name="values_theme">
|
<string-array name="values_theme">
|
||||||
|
|||||||
@@ -108,4 +108,5 @@
|
|||||||
<string name="application_update">Application update</string>
|
<string name="application_update">Application update</string>
|
||||||
<string name="app_update_available">Application update is available</string>
|
<string name="app_update_available">Application update is available</string>
|
||||||
<string name="about_app">About</string>
|
<string name="about_app">About</string>
|
||||||
|
<string name="show_notification_app_update">Show notification if update is available</string>
|
||||||
</resources>
|
</resources>
|
||||||
@@ -1,6 +1,14 @@
|
|||||||
<?xml version="1.0" encoding="utf-8"?>
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android">
|
<PreferenceScreen
|
||||||
|
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
|
xmlns:app="http://schemas.android.com/apk/res-auto">
|
||||||
|
|
||||||
|
<SwitchPreference
|
||||||
|
android:defaultValue="true"
|
||||||
|
android:key="@string/key_app_update_auto"
|
||||||
|
android:summary="@string/show_notification_app_update"
|
||||||
|
android:title="@string/application_update"
|
||||||
|
app:allowDividerBelow="true"
|
||||||
|
app:iconSpaceReserved="false" />
|
||||||
|
|
||||||
</PreferenceScreen>
|
</PreferenceScreen>
|
||||||
Reference in New Issue
Block a user