remove default anime/manga sources

This commit is contained in:
rebelonion 2024-01-27 13:33:50 -06:00
parent 73be639397
commit 1e6041f99e
6 changed files with 16 additions and 183 deletions

View file

@ -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<SharedPreferences>()
.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() {

View file

@ -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<SharedPreferences>()
.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
}
}
}

View file

@ -47,12 +47,8 @@ class MediaDetailsViewModel : ViewModel() {
fun loadSelected(media: Media, isDownload: Boolean = false): Selected {
val sharedPreferences = Injekt.get<SharedPreferences>()
val data = loadData<Selected>("${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

View file

@ -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<Int>("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()

View file

@ -27,15 +27,8 @@ class SubscriptionHelper {
isAdult: Boolean,
isAnime: Boolean
): Selected {
val sharedPreferences = context.getSharedPreferences("Dantotsu", Context.MODE_PRIVATE)
val data = loadData<Selected>("${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
}