From c242fedfeea2330cd0450eb8c63f0b58a3a12967 Mon Sep 17 00:00:00 2001 From: aayush262 Date: Tue, 30 Jan 2024 17:34:01 +0530 Subject: [PATCH] imported more settings --- .../main/java/ani/dantotsu/MainActivity.kt | 7 +-- .../connections/anilist/AnilistQueries.kt | 2 +- .../connections/anilist/AnilistViewModel.kt | 2 +- .../dantotsu/media/MediaDetailsActivity.kt | 2 +- .../dantotsu/media/MediaDetailsViewModel.kt | 4 +- .../java/ani/dantotsu/media/SearchActivity.kt | 4 +- .../java/ani/dantotsu/media/SearchAdapter.kt | 5 +-- .../media/anime/SelectorDialogFragment.kt | 4 +- .../main/java/ani/dantotsu/others/Download.kt | 8 ++-- .../InstalledAnimeExtensionsFragment.kt | 4 +- .../InstalledMangaExtensionsFragment.kt | 4 +- .../InstalledNovelExtensionsFragment.kt | 4 +- .../ani/dantotsu/settings/SettingsActivity.kt | 43 ++++++++++--------- .../settings/paging/AnimePagingSource.kt | 7 +-- .../settings/paging/MangaPagingSource.kt | 6 ++- .../settings/paging/NovelPagingSource.kt | 6 ++- .../dantotsu/settings/saving/Preferences.kt | 13 +++++- .../dantotsu/subcriptions/AlarmReceiver.kt | 5 ++- .../ani/dantotsu/subcriptions/Subscription.kt | 4 +- .../subcriptions/SubscriptionHelper.kt | 4 +- .../subcriptions/SubscriptionWorker.kt | 4 +- 21 files changed, 90 insertions(+), 52 deletions(-) diff --git a/app/src/main/java/ani/dantotsu/MainActivity.kt b/app/src/main/java/ani/dantotsu/MainActivity.kt index 878a704036..137fbc8ac0 100644 --- a/app/src/main/java/ani/dantotsu/MainActivity.kt +++ b/app/src/main/java/ani/dantotsu/MainActivity.kt @@ -299,7 +299,7 @@ class MainActivity : AppCompatActivity() { } if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.S) { - if (loadData("allow_opening_links", this) != true) { + if (!PrefWrapper.getVal(PrefName.AllowOpeningLinks, true)) { CustomBottomDialog.newInstance().apply { title = "Allow Dantotsu to automatically open Anilist & MAL Links?" val md = "Open settings & click +Add Links & select Anilist & Mal urls" @@ -311,18 +311,19 @@ class MainActivity : AppCompatActivity() { }) setNegativeButton(this@MainActivity.getString(R.string.no)) { - saveData("allow_opening_links", true, this@MainActivity) + PrefWrapper.setVal(PrefName.AllowOpeningLinks, true) dismiss() } setPositiveButton(this@MainActivity.getString(R.string.yes)) { - saveData("allow_opening_links", true, this@MainActivity) + PrefWrapper.setVal(PrefName.AllowOpeningLinks, true) tryWith(true) { startActivity( Intent(Settings.ACTION_APP_OPEN_BY_DEFAULT_SETTINGS) .setData(Uri.parse("package:$packageName")) ) } + dismiss() } }.show(supportFragmentManager, "dialog") } diff --git a/app/src/main/java/ani/dantotsu/connections/anilist/AnilistQueries.kt b/app/src/main/java/ani/dantotsu/connections/anilist/AnilistQueries.kt index 4fea9569bf..5086cb17fe 100644 --- a/app/src/main/java/ani/dantotsu/connections/anilist/AnilistQueries.kt +++ b/app/src/main/java/ani/dantotsu/connections/anilist/AnilistQueries.kt @@ -719,7 +719,7 @@ Page(page:$page,perPage:50) { if (smaller) { val response = execute()?.airingSchedules ?: return null val idArr = mutableListOf() - val listOnly = loadData("recently_list_only") ?: false + val listOnly = PrefWrapper.getVal(PrefName.RecentlyListOnly, false) return response.mapNotNull { i -> i.media?.let { if (!idArr.contains(it.id)) diff --git a/app/src/main/java/ani/dantotsu/connections/anilist/AnilistViewModel.kt b/app/src/main/java/ani/dantotsu/connections/anilist/AnilistViewModel.kt index b93d905261..825b982d5b 100644 --- a/app/src/main/java/ani/dantotsu/connections/anilist/AnilistViewModel.kt +++ b/app/src/main/java/ani/dantotsu/connections/anilist/AnilistViewModel.kt @@ -101,7 +101,7 @@ class AnilistHomeViewModel : ViewModel() { Anilist.getSavedToken(context) MAL.getSavedToken(context) Discord.getSavedToken(context) - if (loadData("check_update") != false) AppUpdater.check(context) + if (PrefWrapper.getVal(PrefName.CheckUpdate, false)) AppUpdater.check(context) genres.postValue(Anilist.query.getGenresAndTags(context)) } diff --git a/app/src/main/java/ani/dantotsu/media/MediaDetailsActivity.kt b/app/src/main/java/ani/dantotsu/media/MediaDetailsActivity.kt index 8d357514b4..07ff41cda2 100644 --- a/app/src/main/java/ani/dantotsu/media/MediaDetailsActivity.kt +++ b/app/src/main/java/ani/dantotsu/media/MediaDetailsActivity.kt @@ -355,7 +355,7 @@ class MediaDetailsActivity : AppCompatActivity(), AppBarLayout.OnOffsetChangedLi viewPager.setCurrentItem(selected, false) if (model.continueMedia == null && media.cameFromContinue) { - model.continueMedia = loadData("continue_media") ?: true + model.continueMedia = PrefWrapper.getVal(PrefName.ContinueMedia, true) selected = 1 } diff --git a/app/src/main/java/ani/dantotsu/media/MediaDetailsViewModel.kt b/app/src/main/java/ani/dantotsu/media/MediaDetailsViewModel.kt index 7c45180bd3..498227a0aa 100644 --- a/app/src/main/java/ani/dantotsu/media/MediaDetailsViewModel.kt +++ b/app/src/main/java/ani/dantotsu/media/MediaDetailsViewModel.kt @@ -28,6 +28,8 @@ import ani.dantotsu.parsers.ShowResponse import ani.dantotsu.parsers.VideoExtractor import ani.dantotsu.parsers.WatchSources import ani.dantotsu.saveData +import ani.dantotsu.settings.saving.PrefName +import ani.dantotsu.settings.saving.PrefWrapper import ani.dantotsu.snackString import ani.dantotsu.tryWithSuspend import com.bumptech.glide.load.resource.bitmap.BitmapTransformation @@ -48,7 +50,7 @@ class MediaDetailsViewModel : ViewModel() { fun loadSelected(media: Media, isDownload: Boolean = false): Selected { val data = loadData("${media.id}-select") ?: Selected().let { it.sourceIndex = 0 - it.preferDub = loadData("settings_prefer_dub") ?: false + it.preferDub = PrefWrapper.getVal(PrefName.SettingsPreferDub, false) saveSelected(media.id, it) it } diff --git a/app/src/main/java/ani/dantotsu/media/SearchActivity.kt b/app/src/main/java/ani/dantotsu/media/SearchActivity.kt index 8542b745e8..5e72c9bbb7 100644 --- a/app/src/main/java/ani/dantotsu/media/SearchActivity.kt +++ b/app/src/main/java/ani/dantotsu/media/SearchActivity.kt @@ -16,6 +16,8 @@ import ani.dantotsu.connections.anilist.Anilist import ani.dantotsu.connections.anilist.AnilistSearch import ani.dantotsu.connections.anilist.SearchResults import ani.dantotsu.databinding.ActivitySearchBinding +import ani.dantotsu.settings.saving.PrefName +import ani.dantotsu.settings.saving.PrefWrapper import ani.dantotsu.themes.ThemeManager import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.launch @@ -51,7 +53,7 @@ class SearchActivity : AppCompatActivity() { bottom = navBarHeight + 80f.px ) - style = loadData("searchStyle") ?: 0 + style = PrefWrapper.getVal(PrefName.SearchStyle,0) var listOnly: Boolean? = intent.getBooleanExtra("listOnly", false) if (!listOnly!!) listOnly = null diff --git a/app/src/main/java/ani/dantotsu/media/SearchAdapter.kt b/app/src/main/java/ani/dantotsu/media/SearchAdapter.kt index 1359ebe87f..d8c803eea6 100644 --- a/app/src/main/java/ani/dantotsu/media/SearchAdapter.kt +++ b/app/src/main/java/ani/dantotsu/media/SearchAdapter.kt @@ -22,7 +22,6 @@ import ani.dantotsu.R import ani.dantotsu.connections.anilist.Anilist import ani.dantotsu.databinding.ItemChipBinding import ani.dantotsu.databinding.ItemSearchHeaderBinding -import ani.dantotsu.saveData import ani.dantotsu.settings.saving.PrefName import ani.dantotsu.settings.saving.PrefWrapper import com.google.android.material.checkbox.MaterialCheckBox.* @@ -149,14 +148,14 @@ class SearchAdapter(private val activity: SearchActivity, private val type: Stri it.alpha = 1f binding.searchResultList.alpha = 0.33f activity.style = 0 - saveData("searchStyle", 0) + PrefWrapper.setVal(PrefName.SearchStyle, 0) activity.recycler() } binding.searchResultList.setOnClickListener { it.alpha = 1f binding.searchResultGrid.alpha = 0.33f activity.style = 1 - saveData("searchStyle", 1) + PrefWrapper.setVal(PrefName.SearchStyle, 1) activity.recycler() } diff --git a/app/src/main/java/ani/dantotsu/media/anime/SelectorDialogFragment.kt b/app/src/main/java/ani/dantotsu/media/anime/SelectorDialogFragment.kt index 7c5fbdfeca..f7945fb85b 100644 --- a/app/src/main/java/ani/dantotsu/media/anime/SelectorDialogFragment.kt +++ b/app/src/main/java/ani/dantotsu/media/anime/SelectorDialogFragment.kt @@ -27,6 +27,8 @@ import ani.dantotsu.others.Download.download import ani.dantotsu.parsers.Subtitle import ani.dantotsu.parsers.VideoExtractor import ani.dantotsu.parsers.VideoType +import ani.dantotsu.settings.saving.PrefName +import ani.dantotsu.settings.saving.PrefWrapper import com.google.firebase.crashlytics.FirebaseCrashlytics import kotlinx.coroutines.CoroutineScope import kotlinx.coroutines.Dispatchers @@ -299,7 +301,7 @@ class SelectorDialogFragment : BottomSheetDialogFragment() { extractor.server.name media!!.anime!!.episodes!![media!!.anime!!.selectedEpisode!!]!!.selectedVideo = position - if ((loadData("settings_download_manager") ?: 0) != 0) { + if (PrefWrapper.getVal(PrefName.DownloadManager, 0) != 0) { download( requireActivity(), media!!.anime!!.episodes!![media!!.anime!!.selectedEpisode!!]!!, diff --git a/app/src/main/java/ani/dantotsu/others/Download.kt b/app/src/main/java/ani/dantotsu/others/Download.kt index 8a8b496ab9..f176c62981 100644 --- a/app/src/main/java/ani/dantotsu/others/Download.kt +++ b/app/src/main/java/ani/dantotsu/others/Download.kt @@ -17,6 +17,8 @@ import ani.dantotsu.defaultHeaders import ani.dantotsu.loadData import ani.dantotsu.media.anime.Episode import ani.dantotsu.parsers.Book +import ani.dantotsu.settings.saving.PrefName +import ani.dantotsu.settings.saving.PrefWrapper import ani.dantotsu.toast import kotlinx.coroutines.CoroutineScope import kotlinx.coroutines.Dispatchers @@ -36,7 +38,7 @@ object Download { private fun getDownloadDir(context: Context): File { val direct: File - if (loadData("sd_dl") == true) { + if (PrefWrapper.getVal(PrefName.SdDl, false)) { val arrayOfFiles = ContextCompat.getExternalFilesDirs(context, null) val parentDirectory = arrayOfFiles[1].toString() direct = File(parentDirectory) @@ -92,7 +94,7 @@ object Download { if (!file.url.startsWith("http")) toast(context.getString(R.string.invalid_url)) else - when (loadData("settings_download_manager", context, false) ?: 0) { + when (PrefWrapper.getVal(PrefName.DownloadManager, 0)) { 1 -> oneDM(context, file, notif ?: fileName) 2 -> adm(context, file, fileName, folder) else -> defaultDownload(context, file, fileName, folder, notif ?: fileName) @@ -117,7 +119,7 @@ object Download { request.setNotificationVisibility(DownloadManager.Request.VISIBILITY_VISIBLE_NOTIFY_COMPLETED) val arrayOfFiles = ContextCompat.getExternalFilesDirs(context, null) - if (loadData("sd_dl") == true && arrayOfFiles.size > 1 && arrayOfFiles[0] != null && arrayOfFiles[1] != null) { + if (PrefWrapper.getVal(PrefName.SdDl, false) && arrayOfFiles.size > 1 && arrayOfFiles[0] != null && arrayOfFiles[1] != null) { val parentDirectory = arrayOfFiles[1].toString() + folder val direct = File(parentDirectory) if (!direct.exists()) direct.mkdirs() diff --git a/app/src/main/java/ani/dantotsu/settings/InstalledAnimeExtensionsFragment.kt b/app/src/main/java/ani/dantotsu/settings/InstalledAnimeExtensionsFragment.kt index 6f83009a7f..dab800c709 100644 --- a/app/src/main/java/ani/dantotsu/settings/InstalledAnimeExtensionsFragment.kt +++ b/app/src/main/java/ani/dantotsu/settings/InstalledAnimeExtensionsFragment.kt @@ -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 -> diff --git a/app/src/main/java/ani/dantotsu/settings/InstalledMangaExtensionsFragment.kt b/app/src/main/java/ani/dantotsu/settings/InstalledMangaExtensionsFragment.kt index 1ad5228a54..90fbe618ad 100644 --- a/app/src/main/java/ani/dantotsu/settings/InstalledMangaExtensionsFragment.kt +++ b/app/src/main/java/ani/dantotsu/settings/InstalledMangaExtensionsFragment.kt @@ -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 -> diff --git a/app/src/main/java/ani/dantotsu/settings/InstalledNovelExtensionsFragment.kt b/app/src/main/java/ani/dantotsu/settings/InstalledNovelExtensionsFragment.kt index 76b84bca55..2f951376f9 100644 --- a/app/src/main/java/ani/dantotsu/settings/InstalledNovelExtensionsFragment.kt +++ b/app/src/main/java/ani/dantotsu/settings/InstalledNovelExtensionsFragment.kt @@ -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 -> diff --git a/app/src/main/java/ani/dantotsu/settings/SettingsActivity.kt b/app/src/main/java/ani/dantotsu/settings/SettingsActivity.kt index 3f36f15b4e..d99867ee3b 100644 --- a/app/src/main/java/ani/dantotsu/settings/SettingsActivity.kt +++ b/app/src/main/java/ani/dantotsu/settings/SettingsActivity.kt @@ -208,14 +208,14 @@ 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("settings_download_manager") ?: 0 + 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("subscriptions_time_s") ?: defaultTime + var curTime = PrefWrapper.getVal(PrefName.SubscriptionsTimeS, defaultTime) val timeNames = timeMinutes.map { val mins = it % 60 val hours = it / 60 @@ -615,7 +615,7 @@ class SettingsActivity : AppCompatActivity(), SimpleDialog.OnDialogResultListene 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)) } diff --git a/app/src/main/java/ani/dantotsu/settings/paging/AnimePagingSource.kt b/app/src/main/java/ani/dantotsu/settings/paging/AnimePagingSource.kt index 46efaf5a9d..e5d446c0dd 100644 --- a/app/src/main/java/ani/dantotsu/settings/paging/AnimePagingSource.kt +++ b/app/src/main/java/ani/dantotsu/settings/paging/AnimePagingSource.kt @@ -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,7 +93,7 @@ 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 @@ -126,7 +127,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() { diff --git a/app/src/main/java/ani/dantotsu/settings/paging/MangaPagingSource.kt b/app/src/main/java/ani/dantotsu/settings/paging/MangaPagingSource.kt index ed95c2be64..3025ba527e 100644 --- a/app/src/main/java/ani/dantotsu/settings/paging/MangaPagingSource.kt +++ b/app/src/main/java/ani/dantotsu/settings/paging/MangaPagingSource.kt @@ -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,7 +94,7 @@ 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 { @@ -125,7 +127,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() { diff --git a/app/src/main/java/ani/dantotsu/settings/paging/NovelPagingSource.kt b/app/src/main/java/ani/dantotsu/settings/paging/NovelPagingSource.kt index 91dcffd600..c9f2a01f23 100644 --- a/app/src/main/java/ani/dantotsu/settings/paging/NovelPagingSource.kt +++ b/app/src/main/java/ani/dantotsu/settings/paging/NovelPagingSource.kt @@ -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() { diff --git a/app/src/main/java/ani/dantotsu/settings/saving/Preferences.kt b/app/src/main/java/ani/dantotsu/settings/saving/Preferences.kt index 59f97ec844..3e686b5c9c 100644 --- a/app/src/main/java/ani/dantotsu/settings/saving/Preferences.kt +++ b/app/src/main/java/ani/dantotsu/settings/saving/Preferences.kt @@ -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,14 @@ 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)), //Protected DiscordToken(Pref(Location.Protected, String::class)), diff --git a/app/src/main/java/ani/dantotsu/subcriptions/AlarmReceiver.kt b/app/src/main/java/ani/dantotsu/subcriptions/AlarmReceiver.kt index a326c531de..2529c41828 100644 --- a/app/src/main/java/ani/dantotsu/subcriptions/AlarmReceiver.kt +++ b/app/src/main/java/ani/dantotsu/subcriptions/AlarmReceiver.kt @@ -7,8 +7,9 @@ import android.content.Context import android.content.Intent import ani.dantotsu.currContext import ani.dantotsu.isOnline -import ani.dantotsu.loadData import ani.dantotsu.logger +import ani.dantotsu.settings.saving.PrefName +import ani.dantotsu.settings.saving.PrefWrapper import ani.dantotsu.subcriptions.Subscription.Companion.defaultTime import ani.dantotsu.subcriptions.Subscription.Companion.startSubscription import ani.dantotsu.subcriptions.Subscription.Companion.timeMinutes @@ -43,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 = loadData("subscriptions_time_s", context) ?: defaultTime + val curTime = PrefWrapper.getVal(PrefName.SubscriptionsTimeS, defaultTime) if (timeMinutes[curTime] > 0) alarmManager.setRepeating( diff --git a/app/src/main/java/ani/dantotsu/subcriptions/Subscription.kt b/app/src/main/java/ani/dantotsu/subcriptions/Subscription.kt index 83b3bd7059..c0551f7dce 100644 --- a/app/src/main/java/ani/dantotsu/subcriptions/Subscription.kt +++ b/app/src/main/java/ani/dantotsu/subcriptions/Subscription.kt @@ -8,6 +8,8 @@ import androidx.core.app.NotificationManagerCompat 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 kotlinx.coroutines.CoroutineScope import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.delay @@ -41,7 +43,7 @@ class Subscription { val notificationManager = NotificationManagerCompat.from(context) val progressEnabled = - loadData("subscription_checking_notifications", context) ?: true + PrefWrapper.getVal(PrefName.SubscriptionCheckingNotifications, true) val progressNotification = if (progressEnabled) getProgressNotification( context, subscriptions.size diff --git a/app/src/main/java/ani/dantotsu/subcriptions/SubscriptionHelper.kt b/app/src/main/java/ani/dantotsu/subcriptions/SubscriptionHelper.kt index 9593a5b8eb..9aeda2e588 100644 --- a/app/src/main/java/ani/dantotsu/subcriptions/SubscriptionHelper.kt +++ b/app/src/main/java/ani/dantotsu/subcriptions/SubscriptionHelper.kt @@ -16,6 +16,8 @@ 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.tryWithSuspend import kotlinx.coroutines.withTimeoutOrNull @@ -29,7 +31,7 @@ class SubscriptionHelper { ): Selected { val data = loadData("${mediaId}-select", context) ?: Selected().let { it.sourceIndex = 0 - it.preferDub = loadData("settings_prefer_dub", context) ?: false + it.preferDub = PrefWrapper.getVal(PrefName.SettingsPreferDub, false) it } return data diff --git a/app/src/main/java/ani/dantotsu/subcriptions/SubscriptionWorker.kt b/app/src/main/java/ani/dantotsu/subcriptions/SubscriptionWorker.kt index bed58b211a..4286d438be 100644 --- a/app/src/main/java/ani/dantotsu/subcriptions/SubscriptionWorker.kt +++ b/app/src/main/java/ani/dantotsu/subcriptions/SubscriptionWorker.kt @@ -9,6 +9,8 @@ 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.subcriptions.Subscription.Companion.defaultTime import ani.dantotsu.subcriptions.Subscription.Companion.timeMinutes import kotlinx.coroutines.Dispatchers @@ -29,7 +31,7 @@ class SubscriptionWorker(val context: Context, params: WorkerParameters) : private const val SUBSCRIPTION_WORK_NAME = "work_subscription" fun enqueue(context: Context) { - val curTime = loadData("subscriptions_time_s") ?: defaultTime + val curTime = PrefWrapper.getVal(PrefName.SubscriptionsTimeS, defaultTime) if (timeMinutes[curTime] > 0L) { val constraints = Constraints.Builder().setRequiredNetworkType(NetworkType.CONNECTED).build()