This commit is contained in:
rebelonion 2024-02-01 14:54:27 -06:00
commit b559a13bab
39 changed files with 859 additions and 864 deletions

View file

@ -1,12 +1,12 @@
package ani.dantotsu.settings
import android.annotation.SuppressLint
import android.app.AlertDialog
import android.os.Build.*
import android.os.Build.VERSION.*
import android.os.Bundle
import android.text.Editable
import android.text.TextWatcher
import android.view.View
import android.view.ViewGroup
import android.widget.AutoCompleteTextView
import androidx.appcompat.app.AppCompatActivity
@ -16,6 +16,9 @@ import androidx.viewpager2.adapter.FragmentStateAdapter
import androidx.viewpager2.widget.ViewPager2
import ani.dantotsu.*
import ani.dantotsu.databinding.ActivityExtensionsBinding
import ani.dantotsu.others.LanguageMapper
import ani.dantotsu.settings.saving.PrefName
import ani.dantotsu.settings.saving.PrefWrapper
import ani.dantotsu.themes.ThemeManager
import com.google.android.material.tabs.TabLayout
import com.google.android.material.tabs.TabLayoutMediator
@ -111,20 +114,20 @@ class ExtensionsActivity : AppCompatActivity() {
}
})
initActivity(this)
binding.languageselect.visibility = View.GONE
/* TODO
binding.languageselect.setOnClickListener {
val popup = PopupMenu(this, it)
popup.inflate(R.menu.launguage_selector_menu)
popup.setOnMenuItemClickListener { menuItem ->
true
}
popup.setOnDismissListener {
}
popup.show()
}*/
binding.languageselect.setOnClickListener {
val languageOptions = LanguageMapper.Companion.Language.entries.map{ it.name }.toTypedArray()
val builder = AlertDialog.Builder(currContext(), R.style.MyPopup)
val listOrder = PrefWrapper.getVal(PrefName.LangSort,"all")
val index = LanguageMapper.Companion.Language.entries.toTypedArray().indexOfFirst{it.code == listOrder}
builder.setTitle("Language")
builder.setSingleChoiceItems(languageOptions, index){ dialog, i ->
PrefWrapper.setVal(PrefName.LangSort, LanguageMapper.Companion.Language.entries[i].code)
dialog.dismiss()
}
val dialog = builder.show()
dialog.window?.setDimAmount(0.8f)
}
binding.settingsContainer.updateLayoutParams<ViewGroup.MarginLayoutParams> {
topMargin = statusBarHeight
bottomMargin = navBarHeight

View file

@ -26,6 +26,8 @@ import ani.dantotsu.databinding.FragmentAnimeExtensionsBinding
import ani.dantotsu.loadData
import ani.dantotsu.others.LanguageMapper
import ani.dantotsu.settings.extensionprefs.AnimeSourcePreferencesFragment
import ani.dantotsu.settings.saving.PrefName
import ani.dantotsu.settings.saving.PrefWrapper
import ani.dantotsu.snackString
import com.google.android.material.tabs.TabLayout
import com.google.android.material.textfield.TextInputLayout
@ -46,7 +48,7 @@ class InstalledAnimeExtensionsFragment : Fragment(), SearchQueryHandler {
private var _binding: FragmentAnimeExtensionsBinding? = null
private val binding get() = _binding!!
private lateinit var extensionsRecyclerView: RecyclerView
private val skipIcons = loadData("skip_extension_icons") ?: false
private val skipIcons = PrefWrapper.getVal(PrefName.SkipExtensionIcons, false)
private val animeExtensionManager: AnimeExtensionManager = Injekt.get()
private val extensionsAdapter = AnimeExtensionsAdapter(
{ pkg ->

View file

@ -27,6 +27,8 @@ import ani.dantotsu.databinding.FragmentMangaExtensionsBinding
import ani.dantotsu.loadData
import ani.dantotsu.others.LanguageMapper
import ani.dantotsu.settings.extensionprefs.MangaSourcePreferencesFragment
import ani.dantotsu.settings.saving.PrefName
import ani.dantotsu.settings.saving.PrefWrapper
import ani.dantotsu.snackString
import com.google.android.material.tabs.TabLayout
import com.google.android.material.textfield.TextInputLayout
@ -45,7 +47,7 @@ class InstalledMangaExtensionsFragment : Fragment(), SearchQueryHandler {
private var _binding: FragmentMangaExtensionsBinding? = null
private val binding get() = _binding!!
private lateinit var extensionsRecyclerView: RecyclerView
private val skipIcons = loadData("skip_extension_icons") ?: false
private val skipIcons = PrefWrapper.getVal(PrefName.SkipExtensionIcons, false)
private val mangaExtensionManager: MangaExtensionManager = Injekt.get()
private val extensionsAdapter = MangaExtensionsAdapter(
{ pkg ->

View file

@ -24,6 +24,8 @@ import ani.dantotsu.loadData
import ani.dantotsu.others.LanguageMapper
import ani.dantotsu.parsers.novel.NovelExtension
import ani.dantotsu.parsers.novel.NovelExtensionManager
import ani.dantotsu.settings.saving.PrefName
import ani.dantotsu.settings.saving.PrefWrapper
import ani.dantotsu.snackString
import com.google.firebase.crashlytics.FirebaseCrashlytics
import eu.kanade.tachiyomi.data.notification.Notifications
@ -37,7 +39,7 @@ class InstalledNovelExtensionsFragment : Fragment(), SearchQueryHandler {
private var _binding: FragmentNovelExtensionsBinding? = null
private val binding get() = _binding!!
private lateinit var extensionsRecyclerView: RecyclerView
val skipIcons = loadData("skip_extension_icons") ?: false
val skipIcons = PrefWrapper.getVal(PrefName.SkipExtensionIcons, false)
private val novelExtensionManager: NovelExtensionManager = Injekt.get()
private val extensionsAdapter = NovelExtensionsAdapter(
{ pkg ->

View file

@ -95,7 +95,7 @@ class PlayerSettingsActivity : AppCompatActivity() {
var speedsName = curSpeedArr.map { "${it}x" }.toTypedArray()
binding.playerSettingsSpeed.text =
getString(R.string.default_playback_speed, speedsName[settings.defaultSpeed])
val speedDialog = AlertDialog.Builder(this, R.style.DialogTheme)
val speedDialog = AlertDialog.Builder(this, R.style.MyPopup)
.setTitle(getString(R.string.default_speed))
binding.playerSettingsSpeed.setOnClickListener {
val dialog =
@ -246,7 +246,7 @@ class PlayerSettingsActivity : AppCompatActivity() {
}
val resizeModes = arrayOf("Original", "Zoom", "Stretch")
val resizeDialog = AlertDialog.Builder(this, R.style.DialogTheme)
val resizeDialog = AlertDialog.Builder(this, R.style.MyPopup)
.setTitle(getString(R.string.default_resize_mode))
binding.playerResizeMode.setOnClickListener {
val dialog =
@ -332,7 +332,7 @@ class PlayerSettingsActivity : AppCompatActivity() {
"Blue",
"Magenta"
)
val primaryColorDialog = AlertDialog.Builder(this, R.style.DialogTheme)
val primaryColorDialog = AlertDialog.Builder(this, R.style.MyPopup)
.setTitle(getString(R.string.primary_sub_color))
binding.videoSubColorPrimary.setOnClickListener {
val dialog = primaryColorDialog.setSingleChoiceItems(
@ -359,7 +359,7 @@ class PlayerSettingsActivity : AppCompatActivity() {
"Magenta",
"Transparent"
)
val secondaryColorDialog = AlertDialog.Builder(this, R.style.DialogTheme)
val secondaryColorDialog = AlertDialog.Builder(this, R.style.MyPopup)
.setTitle(getString(R.string.outline_sub_color))
binding.videoSubColorSecondary.setOnClickListener {
val dialog = secondaryColorDialog.setSingleChoiceItems(
@ -373,7 +373,7 @@ class PlayerSettingsActivity : AppCompatActivity() {
dialog.window?.setDimAmount(0.8f)
}
val typesOutline = arrayOf("Outline", "Shine", "Drop Shadow", "None")
val outlineDialog = AlertDialog.Builder(this, R.style.DialogTheme)
val outlineDialog = AlertDialog.Builder(this, R.style.MyPopup)
.setTitle(getString(R.string.outline_type))
binding.videoSubOutline.setOnClickListener {
val dialog = outlineDialog.setSingleChoiceItems(
@ -400,7 +400,7 @@ class PlayerSettingsActivity : AppCompatActivity() {
"Blue",
"Magenta"
)
val subBackgroundDialog = AlertDialog.Builder(this, R.style.DialogTheme)
val subBackgroundDialog = AlertDialog.Builder(this, R.style.MyPopup)
.setTitle(getString(R.string.outline_sub_color))
binding.videoSubColorBackground.setOnClickListener {
val dialog = subBackgroundDialog.setSingleChoiceItems(
@ -428,7 +428,7 @@ class PlayerSettingsActivity : AppCompatActivity() {
"Blue",
"Magenta"
)
val subWindowDialog = AlertDialog.Builder(this, R.style.DialogTheme)
val subWindowDialog = AlertDialog.Builder(this, R.style.MyPopup)
.setTitle(getString(R.string.outline_sub_color))
binding.videoSubColorWindow.setOnClickListener {
val dialog = subWindowDialog.setSingleChoiceItems(
@ -449,7 +449,7 @@ class PlayerSettingsActivity : AppCompatActivity() {
"Century Gothic",
"Century Gothic Bold"
)
val fontDialog = AlertDialog.Builder(this, R.style.DialogTheme)
val fontDialog = AlertDialog.Builder(this, R.style.MyPopup)
.setTitle(getString(R.string.subtitle_font))
binding.videoSubFont.setOnClickListener {
val dialog = fontDialog.setSingleChoiceItems(fonts, settings.font) { dialog, count ->

View file

@ -207,15 +207,15 @@ class SettingsActivity : AppCompatActivity(), SimpleDialog.OnDialogResultListene
val managers = arrayOf("Default", "1DM", "ADM")
val downloadManagerDialog =
AlertDialog.Builder(this, R.style.DialogTheme).setTitle("Download Manager")
var downloadManager = loadData<Int>("settings_download_manager") ?: 0
AlertDialog.Builder(this, R.style.MyPopup).setTitle("Download Manager")
var downloadManager = PrefWrapper.getVal(PrefName.DownloadManager, 0)
binding.settingsDownloadManager.setOnClickListener {
val dialog = downloadManagerDialog.setSingleChoiceItems(
managers,
downloadManager
) { dialog, count ->
downloadManager = count
saveData("settings_download_manager", downloadManager)
PrefWrapper.setVal(PrefName.DownloadManager, downloadManager)
dialog.dismiss()
}.show()
dialog.window?.setDimAmount(0.8f)
@ -287,13 +287,13 @@ class SettingsActivity : AppCompatActivity(), SimpleDialog.OnDialogResultListene
}
}
binding.skipExtensionIcons.isChecked = loadData("skip_extension_icons") ?: false
binding.skipExtensionIcons.isChecked = PrefWrapper.getVal(PrefName.SkipExtensionIcons, false)
binding.skipExtensionIcons.setOnCheckedChangeListener { _, isChecked ->
saveData("skip_extension_icons", isChecked)
PrefWrapper.getVal(PrefName.SkipExtensionIcons, isChecked)
}
binding.NSFWExtension.isChecked = loadData("NSFWExtension") ?: true
binding.NSFWExtension.isChecked = PrefWrapper.getVal(PrefName.NSFWExtension, true)
binding.NSFWExtension.setOnCheckedChangeListener { _, isChecked ->
saveData("NSFWExtension", isChecked)
PrefWrapper.setVal(PrefName.NSFWExtension,isChecked)
}
@ -348,37 +348,37 @@ class SettingsActivity : AppCompatActivity(), SimpleDialog.OnDialogResultListene
Toast.makeText(this, "Restart app to apply changes", Toast.LENGTH_LONG).show()
}
binding.settingsDownloadInSd.isChecked = loadData("sd_dl") ?: false
binding.settingsDownloadInSd.isChecked = PrefWrapper.getVal(PrefName.SdDl, false)
binding.settingsDownloadInSd.setOnCheckedChangeListener { _, isChecked ->
if (isChecked) {
val arrayOfFiles = ContextCompat.getExternalFilesDirs(this, null)
if (arrayOfFiles.size > 1 && arrayOfFiles[1] != null) {
saveData("sd_dl", true)
PrefWrapper.setVal(PrefName.SdDl, true)
} else {
binding.settingsDownloadInSd.isChecked = false
saveData("sd_dl", false)
PrefWrapper.setVal(PrefName.SdDl, true)
snackString(getString(R.string.noSdFound))
}
} else saveData("sd_dl", false)
} else PrefWrapper.setVal(PrefName.SdDl, true)
}
binding.settingsContinueMedia.isChecked = loadData("continue_media") ?: true
binding.settingsContinueMedia.isChecked = PrefWrapper.getVal(PrefName.ContinueMedia, true)
binding.settingsContinueMedia.setOnCheckedChangeListener { _, isChecked ->
saveData("continue_media", isChecked)
PrefWrapper.setVal(PrefName.ContinueMedia, isChecked)
}
binding.settingsRecentlyListOnly.isChecked = loadData("recently_list_only") ?: false
binding.settingsRecentlyListOnly.isChecked = PrefWrapper.getVal(PrefName.RecentlyListOnly, false)
binding.settingsRecentlyListOnly.setOnCheckedChangeListener { _, isChecked ->
saveData("recently_list_only", isChecked)
PrefWrapper.setVal(PrefName.RecentlyListOnly, isChecked)
}
binding.settingsShareUsername.isChecked = PrefWrapper.getVal(PrefName.SharedUserID, true)
binding.settingsShareUsername.setOnCheckedChangeListener { _, isChecked ->
PrefWrapper.setVal(PrefName.SharedUserID, isChecked)
}
binding.settingsPreferDub.isChecked = loadData("settings_prefer_dub") ?: false
binding.settingsPreferDub.isChecked = PrefWrapper.getVal(PrefName.SettingsPreferDub, false)
binding.settingsPreferDub.setOnCheckedChangeListener { _, isChecked ->
saveData("settings_prefer_dub", isChecked)
PrefWrapper.setVal(PrefName.SettingsPreferDub, isChecked)
}
binding.settingsPinnedMangaSources.setOnClickListener {
@ -599,7 +599,7 @@ class SettingsActivity : AppCompatActivity(), SimpleDialog.OnDialogResultListene
}
}
var curTime = loadData<Int>("subscriptions_time_s") ?: defaultTime
var curTime = PrefWrapper.getVal(PrefName.SubscriptionsTimeS, defaultTime)
val timeNames = timeMinutes.map {
val mins = it % 60
val hours = it / 60
@ -608,14 +608,14 @@ class SettingsActivity : AppCompatActivity(), SimpleDialog.OnDialogResultListene
}.toTypedArray()
binding.settingsSubscriptionsTime.text =
getString(R.string.subscriptions_checking_time_s, timeNames[curTime])
val speedDialog = AlertDialog.Builder(this, R.style.DialogTheme)
val speedDialog = AlertDialog.Builder(this, R.style.MyPopup)
.setTitle(R.string.subscriptions_checking_time)
binding.settingsSubscriptionsTime.setOnClickListener {
val dialog = speedDialog.setSingleChoiceItems(timeNames, curTime) { dialog, i ->
curTime = i
binding.settingsSubscriptionsTime.text =
getString(R.string.subscriptions_checking_time_s, timeNames[i])
saveData("subscriptions_time_s", curTime)
PrefWrapper.setVal(PrefName.SubscriptionsTimeS, curTime)
dialog.dismiss()
startSubscription(true)
}.show()
@ -628,9 +628,9 @@ class SettingsActivity : AppCompatActivity(), SimpleDialog.OnDialogResultListene
}
binding.settingsNotificationsCheckingSubscriptions.isChecked =
loadData("subscription_checking_notifications") ?: true
PrefWrapper.getVal(PrefName.SubscriptionCheckingNotifications, true)
binding.settingsNotificationsCheckingSubscriptions.setOnCheckedChangeListener { _, isChecked ->
saveData("subscription_checking_notifications", isChecked)
PrefWrapper.setVal(PrefName.SubscriptionCheckingNotifications, isChecked)
if (isChecked)
Notifications.createChannel(
this,
@ -648,9 +648,10 @@ class SettingsActivity : AppCompatActivity(), SimpleDialog.OnDialogResultListene
}
binding.settingsCheckUpdate.isChecked = loadData("check_update") ?: true
binding.settingsCheckUpdate.isChecked = PrefWrapper.getVal(PrefName.CheckUpdate, true)
binding.settingsCheckUpdate.setOnCheckedChangeListener { _, isChecked ->
saveData("check_update", isChecked)
PrefWrapper.setVal(PrefName.CheckUpdate, isChecked)
if (!isChecked) {
snackString(getString(R.string.long_click_to_check_update))
}

View file

@ -41,7 +41,7 @@ class UserInterfaceSettingsActivity : AppCompatActivity() {
val views = resources.getStringArray(R.array.home_layouts)
binding.uiSettingsHomeLayout.setOnClickListener {
val dialog = AlertDialog.Builder(this, R.style.DialogTheme)
val dialog = AlertDialog.Builder(this, R.style.MyPopup)
.setTitle(getString(R.string.home_layout_show)).apply {
setMultiChoiceItems(
views,

View file

@ -19,8 +19,9 @@ import androidx.recyclerview.widget.DiffUtil
import androidx.recyclerview.widget.RecyclerView
import ani.dantotsu.R
import ani.dantotsu.databinding.ItemExtensionAllBinding
import ani.dantotsu.loadData
import ani.dantotsu.others.LanguageMapper
import ani.dantotsu.settings.saving.PrefName
import ani.dantotsu.settings.saving.PrefWrapper
import com.bumptech.glide.Glide
import eu.kanade.tachiyomi.extension.anime.AnimeExtensionManager
import eu.kanade.tachiyomi.extension.anime.model.AnimeExtension
@ -92,15 +93,16 @@ class AnimeExtensionPagingSource(
val availableExtensions =
availableExtensionsFlow.filterNot { it.pkgName in installedExtensions }
val query = searchQuery
val isNsfwEnabled: Boolean = loadData("NSFWExtension") ?: true
val isNsfwEnabled: Boolean = PrefWrapper.getVal(PrefName.NSFWExtension,true)
val filteredExtensions = if (query.isEmpty()) {
availableExtensions
} else {
availableExtensions.filter { it.name.contains(query, ignoreCase = true) }
}
val filternfsw =
if (isNsfwEnabled) filteredExtensions else filteredExtensions.filterNot { it.isNsfw }
val lang = PrefWrapper.getVal(PrefName.LangSort, "all")
val langFilter = if (lang != "all") filteredExtensions.filter { it.lang == lang } else filteredExtensions
val filternfsw = if (isNsfwEnabled) langFilter else langFilter.filterNot { it.isNsfw }
return try {
val sublist = filternfsw.subList(
fromIndex = position,
@ -126,7 +128,7 @@ class AnimeExtensionAdapter(private val clickListener: OnAnimeInstallClickListen
DIFF_CALLBACK
) {
private val skipIcons = loadData("skip_extension_icons") ?: false
private val skipIcons = PrefWrapper.getVal(PrefName.SkipExtensionIcons, false)
companion object {
private val DIFF_CALLBACK = object : DiffUtil.ItemCallback<AnimeExtension.Available>() {

View file

@ -21,6 +21,8 @@ import ani.dantotsu.R
import ani.dantotsu.databinding.ItemExtensionAllBinding
import ani.dantotsu.loadData
import ani.dantotsu.others.LanguageMapper
import ani.dantotsu.settings.saving.PrefName
import ani.dantotsu.settings.saving.PrefWrapper
import com.bumptech.glide.Glide
import eu.kanade.tachiyomi.extension.manga.MangaExtensionManager
import eu.kanade.tachiyomi.extension.manga.model.MangaExtension
@ -92,14 +94,15 @@ class MangaExtensionPagingSource(
val availableExtensions =
availableExtensionsFlow.filterNot { it.pkgName in installedExtensions }
val query = searchQuery
val isNsfwEnabled: Boolean = loadData("NSFWExtension") ?: true
val isNsfwEnabled: Boolean = PrefWrapper.getVal(PrefName.NSFWExtension,true)
val filteredExtensions = if (query.isEmpty()) {
availableExtensions
} else {
availableExtensions.filter { it.name.contains(query, ignoreCase = true) }
}
val filternfsw =
if (isNsfwEnabled) filteredExtensions else filteredExtensions.filterNot { it.isNsfw }
val lang = PrefWrapper.getVal(PrefName.LangSort, "all")
val langFilter = if (lang != "all") filteredExtensions.filter { it.lang == lang } else filteredExtensions
val filternfsw = if (isNsfwEnabled) langFilter else langFilter.filterNot { it.isNsfw }
return try {
val sublist = filternfsw.subList(
fromIndex = position,
@ -125,7 +128,7 @@ class MangaExtensionAdapter(private val clickListener: OnMangaInstallClickListen
DIFF_CALLBACK
) {
private val skipIcons = loadData("skip_extension_icons") ?: false
private val skipIcons = PrefWrapper.getVal(PrefName.SkipExtensionIcons, false)
companion object {
private val DIFF_CALLBACK = object : DiffUtil.ItemCallback<MangaExtension.Available>() {

View file

@ -22,6 +22,8 @@ import ani.dantotsu.loadData
import ani.dantotsu.others.LanguageMapper
import ani.dantotsu.parsers.novel.NovelExtension
import ani.dantotsu.parsers.novel.NovelExtensionManager
import ani.dantotsu.settings.saving.PrefName
import ani.dantotsu.settings.saving.PrefWrapper
import com.bumptech.glide.Glide
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Dispatchers
@ -93,7 +95,7 @@ class NovelExtensionPagingSource(
val availableExtensions =
availableExtensionsFlow.filterNot { it.pkgName in installedExtensions }
val query = searchQuery
val isNsfwEnabled: Boolean = loadData("NFSWExtension") ?: true
val isNsfwEnabled: Boolean = PrefWrapper.getVal(PrefName.NSFWExtension,true)
val filteredExtensions = if (query.isEmpty()) {
availableExtensions
} else {
@ -130,7 +132,7 @@ class NovelExtensionAdapter(private val clickListener: OnNovelInstallClickListen
DIFF_CALLBACK
) {
private val skipIcons = loadData("skip_extension_icons") ?: false
private val skipIcons = PrefWrapper.getVal(PrefName.SkipExtensionIcons, false)
companion object {
private val DIFF_CALLBACK = object : DiffUtil.ItemCallback<NovelExtension.Available>() {

View file

@ -1,8 +1,11 @@
package ani.dantotsu.settings.saving
import android.annotation.SuppressLint
import android.content.Context
import android.content.SharedPreferences
import ani.dantotsu.settings.saving.internal.Compat
import ani.dantotsu.settings.saving.internal.Location
import ani.dantotsu.snackString
object PrefWrapper {
@ -15,7 +18,7 @@ object PrefWrapper {
private var animeDownloadsPreferences: SharedPreferences? = null
private var protectedPreferences: SharedPreferences? = null
fun init(context: Context) {
fun init(context: Context) { //must be called in Application class or will crash
generalPreferences = context.getSharedPreferences(Location.General.location, Context.MODE_PRIVATE)
animePreferences = context.getSharedPreferences(Location.Anime.location, Context.MODE_PRIVATE)
mangaPreferences = context.getSharedPreferences(Location.Manga.location, Context.MODE_PRIVATE)
@ -24,27 +27,19 @@ object PrefWrapper {
irrelevantPreferences = context.getSharedPreferences(Location.Irrelevant.location, Context.MODE_PRIVATE)
animeDownloadsPreferences = context.getSharedPreferences(Location.AnimeDownloads.location, Context.MODE_PRIVATE)
protectedPreferences = context.getSharedPreferences(Location.Protected.location, Context.MODE_PRIVATE)
Compat.importOldPrefs(context)
}
@Suppress("UNCHECKED_CAST")
fun <T> setVal(prefName: PrefName, value: T) {
val pref = when (prefName.data.prefLocation) {
Location.General -> generalPreferences
Location.Anime -> animePreferences
Location.Manga -> mangaPreferences
Location.Player -> playerPreferences
Location.Reader -> readerPreferences
Location.Irrelevant -> irrelevantPreferences
Location.AnimeDownloads -> animeDownloadsPreferences
Location.Protected -> protectedPreferences
}
with(pref!!.edit()) {
val pref = getPrefLocation(prefName)
with(pref.edit()) {
when (prefName.data.type) {
Boolean::class -> putBoolean(prefName.name, value as Boolean)
Int::class -> putInt(prefName.name, value as Int)
Float::class -> putFloat(prefName.name, value as Float)
Long::class -> putLong(prefName.name, value as Long)
String::class -> putString(prefName.name, value as String)
String::class -> putString(prefName.name, value as String?)
Set::class -> putStringSet(prefName.name, value as Set<String>)
else -> throw IllegalArgumentException("Type not supported")
}
@ -55,70 +50,53 @@ object PrefWrapper {
@Suppress("UNCHECKED_CAST")
fun <T> getVal(prefName: PrefName, default: T) : T {
return try {
val pref = when (prefName.data.prefLocation) {
Location.General -> generalPreferences
Location.Anime -> animePreferences
Location.Manga -> mangaPreferences
Location.Player -> playerPreferences
Location.Reader -> readerPreferences
Location.Irrelevant -> irrelevantPreferences
Location.AnimeDownloads -> animeDownloadsPreferences
Location.Protected -> protectedPreferences
}
val pref = getPrefLocation(prefName)
when (prefName.data.type) {
Boolean::class -> pref!!.getBoolean(prefName.name, default as Boolean) as T
Int::class -> pref!!.getInt(prefName.name, default as Int) as T
Float::class -> pref!!.getFloat(prefName.name, default as Float) as T
Long::class -> pref!!.getLong(prefName.name, default as Long) as T
String::class -> pref!!.getString(prefName.name, default as String) as T
Set::class -> pref!!.getStringSet(prefName.name, default as Set<String>) as T
Boolean::class -> pref.getBoolean(prefName.name, default as Boolean) as T
Int::class -> pref.getInt(prefName.name, default as Int) as T
Float::class -> pref.getFloat(prefName.name, default as Float) as T
Long::class -> pref.getLong(prefName.name, default as Long) as T
String::class -> pref.getString(prefName.name, default as String?) as T
Set::class -> pref.getStringSet(prefName.name, default as Set<String>) as T
else -> throw IllegalArgumentException("Type not supported")
}
} catch (e: Exception) {
snackString("Error getting preference: ${e.message}")
default
}
}
@Suppress("UNCHECKED_CAST")
fun <T> getLiveVal(prefName: PrefName, default: T) : SharedPreferenceLiveData<T> {
val pref = when (prefName.data.prefLocation) {
Location.General -> generalPreferences
Location.Anime -> animePreferences
Location.Manga -> mangaPreferences
Location.Player -> playerPreferences
Location.Reader -> readerPreferences
Location.Irrelevant -> irrelevantPreferences
Location.AnimeDownloads -> animeDownloadsPreferences
Location.Protected -> protectedPreferences
}
val pref = getPrefLocation(prefName)
return when (prefName.data.type) {
Boolean::class -> SharedPreferenceBooleanLiveData(
pref!!,
pref,
prefName.name,
default as Boolean
) as SharedPreferenceLiveData<T>
Int::class -> SharedPreferenceIntLiveData(
pref!!,
pref,
prefName.name,
default as Int
) as SharedPreferenceLiveData<T>
Float::class -> SharedPreferenceFloatLiveData(
pref!!,
pref,
prefName.name,
default as Float
) as SharedPreferenceLiveData<T>
Long::class -> SharedPreferenceLongLiveData(
pref!!,
pref,
prefName.name,
default as Long
) as SharedPreferenceLiveData<T>
String::class -> SharedPreferenceStringLiveData(
pref!!,
pref,
prefName.name,
default as String
) as SharedPreferenceLiveData<T>
Set::class -> SharedPreferenceStringSetLiveData(
pref!!,
pref,
prefName.name,
default as Set<String>
) as SharedPreferenceLiveData<T>
@ -127,17 +105,8 @@ object PrefWrapper {
}
fun removeVal(prefName: PrefName) {
val pref = when (prefName.data.prefLocation) {
Location.General -> generalPreferences
Location.Anime -> animePreferences
Location.Manga -> mangaPreferences
Location.Player -> playerPreferences
Location.Reader -> readerPreferences
Location.Irrelevant -> irrelevantPreferences
Location.AnimeDownloads -> animeDownloadsPreferences
Location.Protected -> protectedPreferences
}
with(pref!!.edit()) {
val pref = getPrefLocation(prefName)
with(pref.edit()) {
remove(prefName.name)
apply()
}
@ -211,4 +180,17 @@ object PrefWrapper {
?: throw ClassCastException("Cannot cast to SharedPreferenceLiveData<Set<String>>")
fun getAnimeDownloadPreferences(): SharedPreferences = animeDownloadsPreferences!! //needs to be used externally
private fun getPrefLocation(prefName: PrefName): SharedPreferences {
return when (prefName.data.prefLocation) {
Location.General -> generalPreferences
Location.Anime -> animePreferences
Location.Manga -> mangaPreferences
Location.Player -> playerPreferences
Location.Reader -> readerPreferences
Location.Irrelevant -> irrelevantPreferences
Location.AnimeDownloads -> animeDownloadsPreferences
Location.Protected -> protectedPreferences
}!!
}
}

View file

@ -13,6 +13,16 @@ enum class PrefName(val data: Pref) {
UseSourceTheme(Pref(Location.General, Boolean::class)),
UseMaterialYou(Pref(Location.General, Boolean::class)),
Theme(Pref(Location.General, String::class)),
DownloadManager(Pref(Location.General, Int::class)),
NSFWExtension(Pref(Location.General, Boolean::class)),
SkipExtensionIcons(Pref(Location.General, Boolean::class)),
SdDl(Pref(Location.General, Boolean::class)),
ContinueMedia(Pref(Location.General, Boolean::class)),
RecentlyListOnly(Pref(Location.General, Boolean::class)),
SettingsPreferDub(Pref(Location.General, Boolean::class)),
SubscriptionsTimeS(Pref(Location.General, Int::class)),
SubscriptionCheckingNotifications(Pref(Location.General, Boolean::class)),
CheckUpdate(Pref(Location.General, Boolean::class)),
//Anime
AnimeListSortOrder(Pref(Location.Anime, String::class)),
@ -26,13 +36,16 @@ enum class PrefName(val data: Pref) {
PopularMangaList(Pref(Location.Manga, Boolean::class)),
MangaSearchHistory(Pref(Location.Manga, Set::class)),
//Irrelevant
Incognito(Pref(Location.Irrelevant, Boolean::class)),
OfflineMode(Pref(Location.Irrelevant, Boolean::class)),
DownloadsKeys(Pref(Location.Irrelevant, String::class)),
NovelLastExtCheck(Pref(Location.Irrelevant, Long::class)),
SomethingSpecial(Pref(Location.Irrelevant, Boolean::class)),
AllowOpeningLinks(Pref(Location.Irrelevant, Boolean::class)),
SearchStyle(Pref(Location.Irrelevant, Int::class)),
HasUpdatedPrefs(Pref(Location.Irrelevant, Boolean::class)),
LangSort(Pref(Location.Irrelevant, String::class)),
//Protected
DiscordToken(Pref(Location.Protected, String::class)),

View file

@ -0,0 +1,18 @@
package ani.dantotsu.settings.saving.internal
import android.content.Context
import ani.dantotsu.settings.saving.PrefName
import ani.dantotsu.settings.saving.PrefWrapper
class Compat {
companion object {
fun importOldPrefs(context: Context) {
if (PrefWrapper.getVal(PrefName.HasUpdatedPrefs, false)) return
val oldPrefs = context.getSharedPreferences("downloads_pref", Context.MODE_PRIVATE)
val jsonString = oldPrefs.getString("downloads_key", null)
PrefWrapper.setVal(PrefName.DownloadsKeys, jsonString)
oldPrefs.edit().clear().apply()
PrefWrapper.setVal(PrefName.HasUpdatedPrefs, true)
}
}
}