Skip to content

Commit

Permalink
Get sources from sourceSelector
Browse files Browse the repository at this point in the history
  • Loading branch information
fakeyatogod committed Oct 28, 2023
1 parent a6acbf7 commit 1e5b39a
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import com.talent.animescrap_common.source.AnimeSource
import com.talent.animescrapsources.animesources.*

class SourceSelector(context: Context) {
private val sourceMap: Map<String, AnimeSource> = hashMapOf(
val sourceMap: Map<String, AnimeSource> = mapOf(
"yugen" to YugenSource(),
"allanime" to AllAnimeSource(),
"enime" to EnimeSource(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,26 +7,52 @@ import android.os.Build
import android.os.Bundle
import android.widget.Toast
import androidx.appcompat.app.AppCompatActivity
import androidx.appcompat.app.AppCompatDelegate.*
import androidx.appcompat.app.AppCompatDelegate.MODE_NIGHT_FOLLOW_SYSTEM
import androidx.appcompat.app.AppCompatDelegate.MODE_NIGHT_NO
import androidx.appcompat.app.AppCompatDelegate.MODE_NIGHT_YES
import androidx.appcompat.app.AppCompatDelegate.setDefaultNightMode
import androidx.lifecycle.ViewModelProvider
import androidx.preference.ListPreference
import androidx.preference.Preference
import androidx.preference.PreferenceCategory
import androidx.preference.PreferenceFragmentCompat
import androidx.preference.SwitchPreferenceCompat
import com.google.android.material.snackbar.Snackbar
import com.talent.animescrap.R
import com.talent.animescrap.ui.activities.MainActivity
import com.talent.animescrap.ui.viewmodels.UpdateViewModel
import com.talent.animescrap_common.utils.Utils
import com.talent.animescrap_common.utils.Utils.httpClient
import com.talent.animescrapsources.SourceSelector
import dagger.hilt.android.AndroidEntryPoint
import java.util.Locale
import kotlin.system.exitProcess

@AndroidEntryPoint
class SettingsFragment : PreferenceFragmentCompat() {

override fun onCreatePreferences(savedInstanceState: Bundle?, rootKey: String?) {
setPreferencesFromResource(R.xml.root_preferences, rootKey)

val sourceCategory = preferenceScreen.findPreference<PreferenceCategory>("source_pref_category")

val sourcePreference = ListPreference(requireContext())
sourcePreference.key = "source"
sourcePreference.title = getString(R.string.source_list_pref_title)
val sourceList = SourceSelector(requireContext()).sourceMap.keys
sourcePreference.entryValues = sourceList.toTypedArray()
sourcePreference.entries = sourceList.map {
it.replaceFirstChar { str -> if (str.isLowerCase()) str.titlecase(Locale.ROOT) else str.toString() }
.replace("_", " ")
}.toTypedArray()
sourcePreference.setDefaultValue("yugen")
sourcePreference.summaryProvider = Preference.SummaryProvider<ListPreference> { preference ->
val newValue = preference.value
"Source set to ${newValue?.uppercase()?.replace("_", " ")}"
}
// preferenceScreen.addPreference(sourceCategory)
sourceCategory?.addPreference(sourcePreference)


val dynamicColorsPref = findPreference<SwitchPreferenceCompat>("dynamic_colors")
dynamicColorsPref?.setOnPreferenceChangeListener { _, newValue ->
view?.let {
Expand Down
17 changes: 9 additions & 8 deletions app/src/main/res/xml/root_preferences.xml
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,15 @@

</PreferenceCategory>

<PreferenceCategory app:title="@string/source_cat_title">
<ListPreference
app:defaultValue="yugen"
app:entries="@array/sources_entries"
app:entryValues="@array/sources_values"
app:key="source"
app:title="@string/source_list_pref_title"
app:useSimpleSummaryProvider="true" />
<PreferenceCategory app:title="@string/source_cat_title"
app:key="source_pref_category">
<!-- <ListPreference-->
<!-- app:defaultValue="yugen"-->
<!-- app:entries="@array/sources_entries"-->
<!-- app:entryValues="@array/sources_values"-->
<!-- app:key="source"-->
<!-- app:title="@string/source_list_pref_title"-->
<!-- app:useSimpleSummaryProvider="true" />-->
</PreferenceCategory>

<PreferenceCategory app:title="@string/player_cat_title">
Expand Down

0 comments on commit 1e5b39a

Please # to comment.