import/export settings
This commit is contained in:
parent
b559a13bab
commit
49e90a27b8
97 changed files with 1721 additions and 1441 deletions
|
@ -9,7 +9,7 @@ import ani.dantotsu.currContext
|
|||
import ani.dantotsu.isOnline
|
||||
import ani.dantotsu.logger
|
||||
import ani.dantotsu.settings.saving.PrefName
|
||||
import ani.dantotsu.settings.saving.PrefWrapper
|
||||
import ani.dantotsu.settings.saving.PrefManager
|
||||
import ani.dantotsu.subcriptions.Subscription.Companion.defaultTime
|
||||
import ani.dantotsu.subcriptions.Subscription.Companion.startSubscription
|
||||
import ani.dantotsu.subcriptions.Subscription.Companion.timeMinutes
|
||||
|
@ -44,7 +44,7 @@ class AlarmReceiver : BroadcastReceiver() {
|
|||
PendingIntent.FLAG_IMMUTABLE or PendingIntent.FLAG_UPDATE_CURRENT
|
||||
)
|
||||
val alarmManager = context.getSystemService(Context.ALARM_SERVICE) as AlarmManager
|
||||
val curTime = PrefWrapper.getVal(PrefName.SubscriptionsTimeS, defaultTime)
|
||||
val curTime = PrefManager.getVal(PrefName.SubscriptionsTimeS, defaultTime)
|
||||
|
||||
if (timeMinutes[curTime] > 0)
|
||||
alarmManager.setRepeating(
|
||||
|
|
|
@ -6,13 +6,13 @@ import android.content.Context
|
|||
import android.content.Intent
|
||||
import ani.dantotsu.INCOGNITO_CHANNEL_ID
|
||||
import ani.dantotsu.settings.saving.PrefName
|
||||
import ani.dantotsu.settings.saving.PrefWrapper
|
||||
import ani.dantotsu.settings.saving.PrefManager
|
||||
|
||||
|
||||
class NotificationClickReceiver : BroadcastReceiver() {
|
||||
override fun onReceive(context: Context, intent: Intent?) {
|
||||
|
||||
PrefWrapper.setVal(PrefName.Incognito, false)
|
||||
PrefManager.setVal(PrefName.Incognito, false)
|
||||
val notificationManager =
|
||||
context.getSystemService(Context.NOTIFICATION_SERVICE) as NotificationManager
|
||||
notificationManager.cancel(INCOGNITO_CHANNEL_ID)
|
||||
|
|
|
@ -9,7 +9,7 @@ import ani.dantotsu.*
|
|||
import ani.dantotsu.parsers.Episode
|
||||
import ani.dantotsu.parsers.MangaChapter
|
||||
import ani.dantotsu.settings.saving.PrefName
|
||||
import ani.dantotsu.settings.saving.PrefWrapper
|
||||
import ani.dantotsu.settings.saving.PrefManager
|
||||
import kotlinx.coroutines.CoroutineScope
|
||||
import kotlinx.coroutines.Dispatchers
|
||||
import kotlinx.coroutines.delay
|
||||
|
@ -37,13 +37,13 @@ class Subscription {
|
|||
currentlyPerforming = true
|
||||
App.context = context
|
||||
|
||||
val subscriptions = SubscriptionHelper.getSubscriptions(context)
|
||||
val subscriptions = SubscriptionHelper.getSubscriptions()
|
||||
var i = 0
|
||||
val index = subscriptions.map { i++; it.key to i }.toMap()
|
||||
val notificationManager = NotificationManagerCompat.from(context)
|
||||
|
||||
val progressEnabled =
|
||||
PrefWrapper.getVal(PrefName.SubscriptionCheckingNotifications, true)
|
||||
val progressEnabled: Boolean =
|
||||
PrefManager.getVal(PrefName.SubscriptionCheckingNotifications)
|
||||
val progressNotification = if (progressEnabled) getProgressNotification(
|
||||
context,
|
||||
subscriptions.size
|
||||
|
|
|
@ -3,7 +3,6 @@ package ani.dantotsu.subcriptions
|
|||
import android.content.Context
|
||||
import ani.dantotsu.R
|
||||
import ani.dantotsu.currContext
|
||||
import ani.dantotsu.loadData
|
||||
import ani.dantotsu.media.Media
|
||||
import ani.dantotsu.media.Selected
|
||||
import ani.dantotsu.media.manga.MangaNameAdapter
|
||||
|
@ -15,9 +14,8 @@ import ani.dantotsu.parsers.HMangaSources
|
|||
import ani.dantotsu.parsers.MangaChapter
|
||||
import ani.dantotsu.parsers.MangaParser
|
||||
import ani.dantotsu.parsers.MangaSources
|
||||
import ani.dantotsu.saveData
|
||||
import ani.dantotsu.settings.saving.PrefName
|
||||
import ani.dantotsu.settings.saving.PrefWrapper
|
||||
import ani.dantotsu.settings.saving.PrefManager
|
||||
import ani.dantotsu.tryWithSuspend
|
||||
import kotlinx.coroutines.withTimeoutOrNull
|
||||
|
||||
|
@ -29,16 +27,16 @@ class SubscriptionHelper {
|
|||
isAdult: Boolean,
|
||||
isAnime: Boolean
|
||||
): Selected {
|
||||
val data = loadData<Selected>("${mediaId}-select", context) ?: Selected().let {
|
||||
val data = PrefManager.getNullableCustomVal<Selected?>("${mediaId}-select", null) ?: Selected().let {
|
||||
it.sourceIndex = 0
|
||||
it.preferDub = PrefWrapper.getVal(PrefName.SettingsPreferDub, false)
|
||||
it.preferDub = PrefManager.getVal(PrefName.SettingsPreferDub)
|
||||
it
|
||||
}
|
||||
return data
|
||||
}
|
||||
|
||||
private fun saveSelected(context: Context, mediaId: Int, data: Selected) {
|
||||
saveData("$mediaId-select", data, context)
|
||||
PrefManager.setCustomVal("${mediaId}-select", data)
|
||||
}
|
||||
|
||||
fun getAnimeParser(context: Context, isAdult: Boolean, id: Int): AnimeParser {
|
||||
|
@ -125,12 +123,12 @@ class SubscriptionHelper {
|
|||
) : java.io.Serializable
|
||||
|
||||
private const val subscriptions = "subscriptions"
|
||||
fun getSubscriptions(context: Context): Map<Int, SubscribeMedia> =
|
||||
loadData(subscriptions, context)
|
||||
?: mapOf<Int, SubscribeMedia>().also { saveData(subscriptions, it, context) }
|
||||
fun getSubscriptions(): Map<Int, SubscribeMedia> =
|
||||
PrefManager.getNullableCustomVal<Map<Int, SubscribeMedia>?>(subscriptions, null)
|
||||
?: mapOf<Int, SubscribeMedia>().also { PrefManager.setCustomVal(subscriptions, it) }
|
||||
|
||||
fun saveSubscription(context: Context, media: Media, subscribed: Boolean) {
|
||||
val data = loadData<Map<Int, SubscribeMedia>>(subscriptions, context)!!.toMutableMap()
|
||||
val data = PrefManager.getNullableCustomVal<Map<Int, SubscribeMedia>?>(subscriptions, null)!!.toMutableMap()
|
||||
if (subscribed) {
|
||||
if (!data.containsKey(media.id)) {
|
||||
val new = SubscribeMedia(
|
||||
|
@ -145,7 +143,7 @@ class SubscriptionHelper {
|
|||
} else {
|
||||
data.remove(media.id)
|
||||
}
|
||||
saveData(subscriptions, data, context)
|
||||
PrefManager.setCustomVal(subscriptions, data)
|
||||
}
|
||||
}
|
||||
}
|
|
@ -8,9 +8,8 @@ import androidx.work.NetworkType
|
|||
import androidx.work.PeriodicWorkRequest
|
||||
import androidx.work.WorkManager
|
||||
import androidx.work.WorkerParameters
|
||||
import ani.dantotsu.loadData
|
||||
import ani.dantotsu.settings.saving.PrefName
|
||||
import ani.dantotsu.settings.saving.PrefWrapper
|
||||
import ani.dantotsu.settings.saving.PrefManager
|
||||
import ani.dantotsu.subcriptions.Subscription.Companion.defaultTime
|
||||
import ani.dantotsu.subcriptions.Subscription.Companion.timeMinutes
|
||||
import kotlinx.coroutines.Dispatchers
|
||||
|
@ -31,7 +30,7 @@ class SubscriptionWorker(val context: Context, params: WorkerParameters) :
|
|||
|
||||
private const val SUBSCRIPTION_WORK_NAME = "work_subscription"
|
||||
fun enqueue(context: Context) {
|
||||
val curTime = PrefWrapper.getVal(PrefName.SubscriptionsTimeS, defaultTime)
|
||||
val curTime = PrefManager.getVal(PrefName.SubscriptionsTimeS, defaultTime)
|
||||
if (timeMinutes[curTime] > 0L) {
|
||||
val constraints =
|
||||
Constraints.Builder().setRequiredNetworkType(NetworkType.CONNECTED).build()
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue