From 1e6041f99e63e3914503d47d475cc098647dc499 Mon Sep 17 00:00:00 2001 From: rebelonion <87634197+rebelonion@users.noreply.github.com> Date: Sat, 27 Jan 2024 13:33:50 -0600 Subject: [PATCH] remove default anime/manga sources --- .../java/ani/dantotsu/home/AnimeFragment.kt | 23 ++---- .../java/ani/dantotsu/home/MangaFragment.kt | 23 ++---- .../dantotsu/media/MediaDetailsViewModel.kt | 6 +- .../ani/dantotsu/settings/SettingsActivity.kt | 70 ------------------- .../subcriptions/SubscriptionHelper.kt | 9 +-- app/src/main/res/layout/activity_settings.xml | 68 ------------------ 6 files changed, 16 insertions(+), 183 deletions(-) diff --git a/app/src/main/java/ani/dantotsu/home/AnimeFragment.kt b/app/src/main/java/ani/dantotsu/home/AnimeFragment.kt index 9ff74f22..7aecd40b 100644 --- a/app/src/main/java/ani/dantotsu/home/AnimeFragment.kt +++ b/app/src/main/java/ani/dantotsu/home/AnimeFragment.kt @@ -4,6 +4,7 @@ import android.animation.ObjectAnimator import android.annotation.SuppressLint import android.content.Context import android.content.Intent +import android.content.SharedPreferences import android.os.Build import android.os.Bundle import android.view.LayoutInflater @@ -41,6 +42,8 @@ import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.delay import kotlinx.coroutines.launch import kotlinx.coroutines.withContext +import uy.kohesive.injekt.Injekt +import uy.kohesive.injekt.api.get import kotlin.math.max import kotlin.math.min @@ -268,26 +271,14 @@ class AnimeFragment : Fragment() { model.loaded = true model.loadTrending(1) model.loadUpdated() + model.loadPopular("ANIME", sort = Anilist.sortBy[1], onList = Injekt.get() + .getBoolean("popular_list", false)) } - withContext(Dispatchers.Main) { - if (isAdded) { // Check if the fragment is still attached - model.loadPopular( - "ANIME", - sort = Anilist.sortBy[1], - onList = requireContext().getSharedPreferences( - "Dantotsu", - Context.MODE_PRIVATE - ) - .getBoolean("popular_list", false) - ) - } - live.postValue(false) - _binding?.animeRefresh?.isRefreshing = false - } + live.postValue(false) + _binding?.animeRefresh?.isRefreshing = false } } } - } override fun onResume() { diff --git a/app/src/main/java/ani/dantotsu/home/MangaFragment.kt b/app/src/main/java/ani/dantotsu/home/MangaFragment.kt index 26b9c622..07c7479e 100644 --- a/app/src/main/java/ani/dantotsu/home/MangaFragment.kt +++ b/app/src/main/java/ani/dantotsu/home/MangaFragment.kt @@ -3,6 +3,7 @@ package ani.dantotsu.home import android.animation.ObjectAnimator import android.annotation.SuppressLint import android.content.Context +import android.content.SharedPreferences import android.os.Build import android.os.Bundle import android.view.LayoutInflater @@ -38,6 +39,8 @@ import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.delay import kotlinx.coroutines.launch import kotlinx.coroutines.withContext +import uy.kohesive.injekt.Injekt +import uy.kohesive.injekt.api.get import kotlin.math.max import kotlin.math.min @@ -242,23 +245,11 @@ class MangaFragment : Fragment() { model.loaded = true model.loadTrending() model.loadTrendingNovel() + model.loadPopular("MANGA", sort = Anilist.sortBy[1], onList = Injekt.get() + .getBoolean("popular_list", false) ) } - withContext(Dispatchers.Main) { - if (isAdded) { - val sharedPrefs = requireContext().getSharedPreferences( - "Dantotsu", - Context.MODE_PRIVATE - ) - val isPopularList = sharedPrefs.getBoolean("popular_list", false) - model.loadPopular( - "MANGA", - sort = Anilist.sortBy[1], - onList = isPopularList - ) - } - live.postValue(false) - _binding?.mangaRefresh?.isRefreshing = false - } + live.postValue(false) + _binding?.mangaRefresh?.isRefreshing = false } } } diff --git a/app/src/main/java/ani/dantotsu/media/MediaDetailsViewModel.kt b/app/src/main/java/ani/dantotsu/media/MediaDetailsViewModel.kt index cb530472..a0c6002f 100644 --- a/app/src/main/java/ani/dantotsu/media/MediaDetailsViewModel.kt +++ b/app/src/main/java/ani/dantotsu/media/MediaDetailsViewModel.kt @@ -47,12 +47,8 @@ class MediaDetailsViewModel : ViewModel() { fun loadSelected(media: Media, isDownload: Boolean = false): Selected { - val sharedPreferences = Injekt.get() val data = loadData("${media.id}-select") ?: Selected().let { - it.sourceIndex = if (media.isAdult) 0 else when (media.anime != null) { - true -> sharedPreferences.getInt("settings_def_anime_source_s_r", 0) - else -> sharedPreferences.getInt(("settings_def_manga_source_s_r"), 0) - } + it.sourceIndex = 0 it.preferDub = loadData("settings_prefer_dub") ?: false saveSelected(media.id, it) it diff --git a/app/src/main/java/ani/dantotsu/settings/SettingsActivity.kt b/app/src/main/java/ani/dantotsu/settings/SettingsActivity.kt index 2a9a25d9..bc665cd4 100644 --- a/app/src/main/java/ani/dantotsu/settings/SettingsActivity.kt +++ b/app/src/main/java/ani/dantotsu/settings/SettingsActivity.kt @@ -190,30 +190,6 @@ class SettingsActivity : AppCompatActivity(), SimpleDialog.OnDialogResultListene .show(this, tag) } - val animeSource = getSharedPreferences( - "Dantotsu", - Context.MODE_PRIVATE - ).getInt("settings_def_anime_source_s_r", 0) - if (AnimeSources.names.isNotEmpty() && animeSource in 0 until AnimeSources.names.size) { - binding.animeSource.setText(AnimeSources.names[animeSource], false) - - } - - binding.animeSource.setAdapter( - ArrayAdapter( - this, - R.layout.item_dropdown, - AnimeSources.names - ) - ) - - binding.animeSource.setOnItemClickListener { _, _, i, _ -> - //saveData("settings_def_anime_source_s", i) - getSharedPreferences("Dantotsu", Context.MODE_PRIVATE).edit() - .putInt("settings_def_anime_source_s_r", i).apply() - binding.animeSource.clearFocus() - } - binding.settingsPinnedAnimeSources.setOnClickListener { val animeSourcesWithoutDownloadsSource = AnimeSources.list.filter { it.name != "Downloaded" } @@ -238,20 +214,10 @@ class SettingsActivity : AppCompatActivity(), SimpleDialog.OnDialogResultListene } } .setPositiveButton("OK") { dialog, _ -> - val oldDefaultSourceIndex = getSharedPreferences( - "Dantotsu", - Context.MODE_PRIVATE - ).getInt("settings_def_anime_source_s_r", 0) - val oldName = - if (oldDefaultSourceIndex >= AnimeSources.names.size) "" else AnimeSources.names[oldDefaultSourceIndex] getSharedPreferences("Dantotsu", Context.MODE_PRIVATE).edit() .putStringSet("pinned_anime_sources", pinnedSources).apply() AnimeSources.pinnedAnimeSources = pinnedSources AnimeSources.performReorderAnimeSources() - val newDefaultSourceIndex = - if (oldName == "") 0 else AnimeSources.names.indexOf(oldName) - getSharedPreferences("Dantotsu", Context.MODE_PRIVATE).edit() - .putInt("settings_def_anime_source_s_r", newDefaultSourceIndex).apply() dialog.dismiss() } .create() @@ -445,32 +411,6 @@ class SettingsActivity : AppCompatActivity(), SimpleDialog.OnDialogResultListene saveData("settings_prefer_dub", isChecked) } - //val mangaSource = loadData("settings_def_manga_source_s")?.let { if (it >= MangaSources.names.size) 0 else it } ?: 0 - val mangaSource = getSharedPreferences( - "Dantotsu", - Context.MODE_PRIVATE - ).getInt("settings_def_manga_source_s_r", 0) - if (MangaSources.names.isNotEmpty() && mangaSource in 0 until MangaSources.names.size) { - binding.mangaSource.setText(MangaSources.names[mangaSource], false) - } - - // Set up the dropdown adapter. - binding.mangaSource.setAdapter( - ArrayAdapter( - this, - R.layout.item_dropdown, - MangaSources.names - ) - ) - - // Set up the item click listener for the dropdown. - binding.mangaSource.setOnItemClickListener { _, _, i, _ -> - //saveData("settings_def_manga_source_s", i) - getSharedPreferences("Dantotsu", Context.MODE_PRIVATE).edit() - .putInt("settings_def_manga_source_s_r", i).apply() - binding.mangaSource.clearFocus() - } - binding.settingsPinnedMangaSources.setOnClickListener { val mangaSourcesWithoutDownloadsSource = MangaSources.list.filter { it.name != "Downloaded" } @@ -495,20 +435,10 @@ class SettingsActivity : AppCompatActivity(), SimpleDialog.OnDialogResultListene } } .setPositiveButton("OK") { dialog, _ -> - val oldDefaultSourceIndex = getSharedPreferences( - "Dantotsu", - Context.MODE_PRIVATE - ).getInt("settings_def_manga_source_s_r", 0) - val oldName = - if (oldDefaultSourceIndex >= MangaSources.names.size) "" else MangaSources.names[oldDefaultSourceIndex] getSharedPreferences("Dantotsu", Context.MODE_PRIVATE).edit() .putStringSet("pinned_manga_sources", pinnedSources).apply() MangaSources.pinnedMangaSources = pinnedSources MangaSources.performReorderMangaSources() - val newDefaultSourceIndex = - if (oldName == "") 0 else MangaSources.names.indexOf(oldName) - getSharedPreferences("Dantotsu", Context.MODE_PRIVATE).edit() - .putInt("settings_def_manga_source_s_r", newDefaultSourceIndex).apply() dialog.dismiss() } .create() diff --git a/app/src/main/java/ani/dantotsu/subcriptions/SubscriptionHelper.kt b/app/src/main/java/ani/dantotsu/subcriptions/SubscriptionHelper.kt index 14ee72b0..9593a5b8 100644 --- a/app/src/main/java/ani/dantotsu/subcriptions/SubscriptionHelper.kt +++ b/app/src/main/java/ani/dantotsu/subcriptions/SubscriptionHelper.kt @@ -27,15 +27,8 @@ class SubscriptionHelper { isAdult: Boolean, isAnime: Boolean ): Selected { - val sharedPreferences = context.getSharedPreferences("Dantotsu", Context.MODE_PRIVATE) val data = loadData("${mediaId}-select", context) ?: Selected().let { - it.sourceIndex = - if (isAdult) 0 - else if (isAnime) { - sharedPreferences.getInt("settings_def_anime_source_s_r", 0) - } else { - sharedPreferences.getInt("settings_def_manga_source_s_r", 0) - } + it.sourceIndex = 0 it.preferDub = loadData("settings_prefer_dub", context) ?: false it } diff --git a/app/src/main/res/layout/activity_settings.xml b/app/src/main/res/layout/activity_settings.xml index 8a8fa7c4..6c595fb0 100644 --- a/app/src/main/res/layout/activity_settings.xml +++ b/app/src/main/res/layout/activity_settings.xml @@ -1134,40 +1134,6 @@ app:drawableEndCompat="@drawable/ic_round_arrow_drop_down_24" tools:ignore="TextContrastCheck" /> - - - - - - - - - - - - - -