Simplify settings
This commit is contained in:
@@ -6,8 +6,8 @@ import android.os.Bundle
|
||||
import androidx.fragment.app.commit
|
||||
import org.koitharu.kotatsu.R
|
||||
import org.koitharu.kotatsu.ui.common.BaseActivity
|
||||
import org.koitharu.kotatsu.ui.settings.MainSettingsFragment
|
||||
import org.koitharu.kotatsu.ui.settings.ReaderSettingsFragment
|
||||
import org.koitharu.kotatsu.ui.settings.SettingsHeadersFragment
|
||||
|
||||
class SimpleSettingsActivity : BaseActivity() {
|
||||
|
||||
@@ -19,7 +19,7 @@ class SimpleSettingsActivity : BaseActivity() {
|
||||
supportFragmentManager.commit {
|
||||
replace(R.id.container, when(section) {
|
||||
SECTION_READER -> ReaderSettingsFragment()
|
||||
else -> SettingsHeadersFragment()
|
||||
else -> MainSettingsFragment()
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,12 +0,0 @@
|
||||
package org.koitharu.kotatsu.ui.settings
|
||||
|
||||
import android.os.Bundle
|
||||
import org.koitharu.kotatsu.R
|
||||
import org.koitharu.kotatsu.ui.common.BasePreferenceFragment
|
||||
|
||||
class AboutSettingsFragment : BasePreferenceFragment(R.string.about_app) {
|
||||
|
||||
override fun onCreatePreferences(savedInstanceState: Bundle?, rootKey: String?) {
|
||||
addPreferencesFromResource(R.xml.pref_about)
|
||||
}
|
||||
}
|
||||
@@ -5,21 +5,24 @@ import android.os.Bundle
|
||||
import android.view.View
|
||||
import androidx.appcompat.app.AppCompatDelegate
|
||||
import androidx.collection.arrayMapOf
|
||||
import androidx.preference.MultiSelectListPreference
|
||||
import androidx.preference.Preference
|
||||
import androidx.preference.PreferenceScreen
|
||||
import androidx.preference.SeekBarPreference
|
||||
import org.koitharu.kotatsu.R
|
||||
import org.koitharu.kotatsu.core.model.MangaSource
|
||||
import org.koitharu.kotatsu.core.prefs.ListMode
|
||||
import org.koitharu.kotatsu.ui.common.BasePreferenceFragment
|
||||
import org.koitharu.kotatsu.ui.main.list.ListModeSelectDialog
|
||||
import org.koitharu.kotatsu.ui.settings.utils.MultiSummaryProvider
|
||||
|
||||
class AppearanceSettingsFragment : BasePreferenceFragment(R.string.appearance),
|
||||
class MainSettingsFragment : BasePreferenceFragment(R.string.settings),
|
||||
SharedPreferences.OnSharedPreferenceChangeListener {
|
||||
|
||||
override fun onCreatePreferences(savedInstanceState: Bundle?, rootKey: String?) {
|
||||
addPreferencesFromResource(R.xml.pref_appearance)
|
||||
|
||||
addPreferencesFromResource(R.xml.pref_main)
|
||||
findPreference<Preference>(R.string.key_list_mode)?.summary =
|
||||
listModes[settings.listMode]?.let(::getString)
|
||||
LIST_MODES[settings.listMode]?.let(::getString)
|
||||
findPreference<SeekBarPreference>(R.string.key_grid_size)?.run {
|
||||
summary = "%d%%".format(value)
|
||||
setOnPreferenceChangeListener { preference, newValue ->
|
||||
@@ -27,6 +30,24 @@ class AppearanceSettingsFragment : BasePreferenceFragment(R.string.appearance),
|
||||
true
|
||||
}
|
||||
}
|
||||
findPreference<MultiSelectListPreference>(R.string.key_reader_switchers)?.summaryProvider =
|
||||
MultiSummaryProvider(R.string.gestures_only)
|
||||
findPreference<PreferenceScreen>(R.string.key_remote_sources)?.run {
|
||||
val total = MangaSource.values().size - 1
|
||||
summary = getString(
|
||||
R.string.enabled_d_from_d, total - settings.hiddenSources.size, total
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
override fun onSharedPreferenceChanged(sharedPreferences: SharedPreferences?, key: String?) {
|
||||
when (key) {
|
||||
getString(R.string.key_list_mode) -> findPreference<Preference>(R.string.key_list_mode)?.summary =
|
||||
LIST_MODES[settings.listMode]?.let(::getString)
|
||||
getString(R.string.key_theme) -> {
|
||||
AppCompatDelegate.setDefaultNightMode(settings.theme)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
|
||||
@@ -49,19 +70,9 @@ class AppearanceSettingsFragment : BasePreferenceFragment(R.string.appearance),
|
||||
}
|
||||
}
|
||||
|
||||
override fun onSharedPreferenceChanged(sharedPreferences: SharedPreferences?, key: String?) {
|
||||
when (key) {
|
||||
getString(R.string.key_list_mode) -> findPreference<Preference>(R.string.key_list_mode)?.summary =
|
||||
listModes[settings.listMode]?.let(::getString)
|
||||
getString(R.string.key_theme) -> {
|
||||
AppCompatDelegate.setDefaultNightMode(settings.theme)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private companion object {
|
||||
|
||||
val listModes = arrayMapOf(
|
||||
val LIST_MODES = arrayMapOf(
|
||||
ListMode.DETAILED_LIST to R.string.detailed_list,
|
||||
ListMode.GRID to R.string.grid,
|
||||
ListMode.LIST to R.string.list
|
||||
@@ -3,11 +3,9 @@ package org.koitharu.kotatsu.ui.settings
|
||||
import android.content.Context
|
||||
import android.content.Intent
|
||||
import android.os.Bundle
|
||||
import androidx.fragment.app.FragmentManager
|
||||
import androidx.fragment.app.commit
|
||||
import androidx.preference.Preference
|
||||
import androidx.preference.PreferenceFragmentCompat
|
||||
import kotlinx.android.synthetic.main.activity_settings.*
|
||||
import org.koitharu.kotatsu.R
|
||||
import org.koitharu.kotatsu.core.model.MangaSource
|
||||
import org.koitharu.kotatsu.ui.common.BaseActivity
|
||||
@@ -20,48 +18,25 @@ class SettingsActivity : BaseActivity(),
|
||||
setContentView(R.layout.activity_settings)
|
||||
supportActionBar?.setDisplayHomeAsUpEnabled(true)
|
||||
|
||||
val isTablet = container_side != null
|
||||
if (supportFragmentManager.findFragmentById(R.id.container) == null) {
|
||||
supportFragmentManager.commit {
|
||||
if (isTablet) {
|
||||
replace(R.id.container_side, SettingsHeadersFragment())
|
||||
replace(R.id.container, AppearanceSettingsFragment())
|
||||
} else {
|
||||
replace(R.id.container, SettingsHeadersFragment())
|
||||
}
|
||||
replace(R.id.container, MainSettingsFragment())
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
override fun onPreferenceStartFragment(caller: PreferenceFragmentCompat, pref: Preference): Boolean {
|
||||
val fm = supportFragmentManager
|
||||
if (container_side != null && caller is SettingsHeadersFragment) {
|
||||
fm.popBackStackImmediate(null, FragmentManager.POP_BACK_STACK_INCLUSIVE)
|
||||
}
|
||||
val fragment = fm.fragmentFactory.instantiate(classLoader, pref.fragment)
|
||||
fragment.arguments = pref.extras
|
||||
fragment.setTargetFragment(caller, 0)
|
||||
fm.commit {
|
||||
replace(R.id.container, fragment)
|
||||
if (container_side == null || caller !is SettingsHeadersFragment) {
|
||||
addToBackStack(null)
|
||||
}
|
||||
addToBackStack(null)
|
||||
}
|
||||
return true
|
||||
}
|
||||
|
||||
override fun onTitleChanged(title: CharSequence?, color: Int) {
|
||||
if (container_side == null) {
|
||||
super.onTitleChanged(title, color)
|
||||
} else {
|
||||
if (supportFragmentManager.backStackEntryCount == 0) {
|
||||
supportActionBar?.subtitle = null
|
||||
} else {
|
||||
supportActionBar?.subtitle = title
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fun openMangaSourceSettings(mangaSource: MangaSource) {
|
||||
supportFragmentManager.commit {
|
||||
replace(R.id.container, SourceSettingsFragment.newInstance(mangaSource))
|
||||
|
||||
@@ -1,13 +0,0 @@
|
||||
package org.koitharu.kotatsu.ui.settings
|
||||
|
||||
import android.os.Bundle
|
||||
import org.koitharu.kotatsu.R
|
||||
import org.koitharu.kotatsu.ui.common.BasePreferenceFragment
|
||||
|
||||
class SettingsHeadersFragment : BasePreferenceFragment(R.string.settings) {
|
||||
|
||||
override fun onCreatePreferences(savedInstanceState: Bundle?, rootKey: String?) {
|
||||
addPreferencesFromResource(R.xml.pref_headers)
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,19 +1,18 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<RelativeLayout
|
||||
<androidx.constraintlayout.widget.ConstraintLayout
|
||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:background="?attr/colorButtonNormal"
|
||||
android:orientation="vertical">
|
||||
|
||||
<com.google.android.material.appbar.AppBarLayout
|
||||
android:id="@+id/appbar"
|
||||
android:layout_width="match_parent"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintTop_toTopOf="parent"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_alignParentStart="true"
|
||||
android:layout_alignParentTop="true"
|
||||
android:layout_alignParentEnd="true"
|
||||
android:background="?colorPrimary"
|
||||
android:theme="@style/AppToolbarTheme">
|
||||
|
||||
@@ -26,23 +25,16 @@
|
||||
|
||||
</com.google.android.material.appbar.AppBarLayout>
|
||||
|
||||
<androidx.fragment.app.FragmentContainerView
|
||||
android:id="@+id/container_side"
|
||||
android:layout_width="340dp"
|
||||
android:layout_height="match_parent"
|
||||
android:layout_below="@id/appbar"
|
||||
android:layout_alignParentStart="true"
|
||||
android:layout_alignParentBottom="true" />
|
||||
|
||||
<com.google.android.material.card.MaterialCardView
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_below="@id/appbar"
|
||||
android:layout_alignParentEnd="true"
|
||||
android:layout_alignParentBottom="true"
|
||||
android:layout_margin="16dp"
|
||||
android:layout_toEndOf="@id/container_side"
|
||||
app:cardBackgroundColor="?android:windowBackground">
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintBottom_toBottomOf="parent"
|
||||
app:layout_constraintTop_toBottomOf="@id/appbar"
|
||||
app:layout_constraintWidth_percent="0.6"
|
||||
android:layout_marginTop="12dp"
|
||||
android:layout_marginBottom="12dp"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="0dp">
|
||||
|
||||
<androidx.fragment.app.FragmentContainerView
|
||||
android:id="@id/container"
|
||||
@@ -51,4 +43,4 @@
|
||||
|
||||
</com.google.android.material.card.MaterialCardView>
|
||||
|
||||
</RelativeLayout>
|
||||
</androidx.constraintlayout.widget.ConstraintLayout>
|
||||
@@ -111,4 +111,6 @@
|
||||
<string name="open_in_browser">Открыть в браузере</string>
|
||||
<string name="large_manga_save_confirm">В этой манге %d глав. Вы уверены, что хотите сохранить их все?</string>
|
||||
<string name="save_manga">Сохранить мангу</string>
|
||||
<string name="notifications">Уведомления</string>
|
||||
<string name="enabled_d_from_d">Включено %1$d из %2$d</string>
|
||||
</resources>
|
||||
@@ -10,6 +10,7 @@
|
||||
<string name="key_search_history_clear">search_history_clear</string>
|
||||
<string name="key_reading_history_clear">reading_history_clear</string>
|
||||
<string name="key_grid_size">grid_size</string>
|
||||
<string name="key_remote_sources">remote_sources</string>
|
||||
<string name="key_reader_switchers">reader_switchers</string>
|
||||
<string name="key_app_update">app_update</string>
|
||||
<string name="key_app_update_auto">app_update_auto</string>
|
||||
|
||||
@@ -112,4 +112,6 @@
|
||||
<string name="open_in_browser">Open in browser</string>
|
||||
<string name="large_manga_save_confirm">This manga has %d chapters. Are you want to save all of it?</string>
|
||||
<string name="save_manga">Save manga</string>
|
||||
<string name="notifications">Notifications</string>
|
||||
<string name="enabled_d_from_d">Enabled %1$d from %2$d</string>
|
||||
</resources>
|
||||
@@ -1,14 +0,0 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<PreferenceScreen
|
||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:app="http://schemas.android.com/apk/res-auto">
|
||||
|
||||
<SwitchPreference
|
||||
android:defaultValue="true"
|
||||
android:key="@string/key_app_update_auto"
|
||||
android:summary="@string/show_notification_app_update"
|
||||
android:title="@string/application_update"
|
||||
app:allowDividerBelow="true"
|
||||
app:iconSpaceReserved="false" />
|
||||
|
||||
</PreferenceScreen>
|
||||
@@ -1,34 +0,0 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<PreferenceScreen
|
||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:app="http://schemas.android.com/apk/res-auto">
|
||||
|
||||
<ListPreference
|
||||
android:defaultValue="-1"
|
||||
android:entries="@array/themes"
|
||||
android:entryValues="@array/values_theme"
|
||||
android:key="@string/key_theme"
|
||||
android:title="@string/theme"
|
||||
app:useSimpleSummaryProvider="true"
|
||||
app:iconSpaceReserved="false" />
|
||||
|
||||
<Preference
|
||||
android:key="@string/key_list_mode"
|
||||
android:persistent="false"
|
||||
android:title="@string/list_mode"
|
||||
app:allowDividerAbove="true"
|
||||
app:iconSpaceReserved="false" />
|
||||
|
||||
<SeekBarPreference
|
||||
android:key="@string/key_grid_size"
|
||||
android:title="@string/grid_size"
|
||||
app:iconSpaceReserved="false"
|
||||
app:defaultValue="100"
|
||||
app:min="50"
|
||||
app:showSeekBarValue="false"
|
||||
app:updatesContinuously="true"
|
||||
app:seekBarIncrement="10"
|
||||
app:allowDividerBelow="true"
|
||||
android:max="150" />
|
||||
|
||||
</PreferenceScreen>
|
||||
@@ -1,30 +0,0 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<PreferenceScreen
|
||||
xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
|
||||
<PreferenceScreen
|
||||
android:fragment="org.koitharu.kotatsu.ui.settings.AppearanceSettingsFragment"
|
||||
android:icon="@drawable/ic_palette"
|
||||
android:title="@string/appearance" />
|
||||
|
||||
<PreferenceScreen
|
||||
android:fragment="org.koitharu.kotatsu.ui.settings.sources.SourcesSettingsFragment"
|
||||
android:icon="@drawable/ic_web"
|
||||
android:title="@string/remote_sources" />
|
||||
|
||||
<PreferenceScreen
|
||||
android:fragment="org.koitharu.kotatsu.ui.settings.ReaderSettingsFragment"
|
||||
android:icon="@drawable/ic_book"
|
||||
android:title="@string/reader_settings" />
|
||||
|
||||
<PreferenceScreen
|
||||
android:fragment="org.koitharu.kotatsu.ui.settings.HistorySettingsFragment"
|
||||
android:icon="@drawable/ic_history"
|
||||
android:title="@string/history_and_cache" />
|
||||
|
||||
<PreferenceScreen
|
||||
android:fragment="org.koitharu.kotatsu.ui.settings.AboutSettingsFragment"
|
||||
android:icon="@drawable/ic_information"
|
||||
android:title="@string/about_app" />
|
||||
|
||||
</PreferenceScreen>
|
||||
69
app/src/main/res/xml/pref_main.xml
Normal file
69
app/src/main/res/xml/pref_main.xml
Normal file
@@ -0,0 +1,69 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<PreferenceScreen
|
||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:app="http://schemas.android.com/apk/res-auto">
|
||||
|
||||
<ListPreference
|
||||
android:defaultValue="-1"
|
||||
android:entries="@array/themes"
|
||||
android:entryValues="@array/values_theme"
|
||||
android:key="@string/key_theme"
|
||||
android:title="@string/theme"
|
||||
app:iconSpaceReserved="false"
|
||||
app:useSimpleSummaryProvider="true" />
|
||||
|
||||
<Preference
|
||||
android:key="@string/key_list_mode"
|
||||
android:persistent="false"
|
||||
android:title="@string/list_mode"
|
||||
app:allowDividerAbove="true"
|
||||
app:iconSpaceReserved="false" />
|
||||
|
||||
<SeekBarPreference
|
||||
android:key="@string/key_grid_size"
|
||||
android:max="150"
|
||||
android:title="@string/grid_size"
|
||||
app:defaultValue="100"
|
||||
app:iconSpaceReserved="false"
|
||||
app:min="50"
|
||||
app:seekBarIncrement="10"
|
||||
app:showSeekBarValue="false"
|
||||
app:updatesContinuously="true" />
|
||||
|
||||
<PreferenceScreen
|
||||
android:fragment="org.koitharu.kotatsu.ui.settings.sources.SourcesSettingsFragment"
|
||||
android:title="@string/remote_sources"
|
||||
app:allowDividerAbove="true"
|
||||
android:key="@string/key_remote_sources"
|
||||
app:iconSpaceReserved="false" />
|
||||
|
||||
<PreferenceScreen
|
||||
android:fragment="org.koitharu.kotatsu.ui.settings.HistorySettingsFragment"
|
||||
android:title="@string/history_and_cache"
|
||||
app:iconSpaceReserved="false" />
|
||||
|
||||
<MultiSelectListPreference
|
||||
android:defaultValue="@array/values_reader_switchers_default"
|
||||
android:entries="@array/reader_switchers"
|
||||
android:entryValues="@array/values_reader_switchers"
|
||||
android:key="@string/key_reader_switchers"
|
||||
android:title="@string/switch_pages"
|
||||
app:allowDividerAbove="true"
|
||||
app:iconSpaceReserved="false" />
|
||||
|
||||
<PreferenceCategory
|
||||
android:title="@string/notifications"
|
||||
app:allowDividerAbove="true"
|
||||
app:iconSpaceReserved="false">
|
||||
|
||||
<SwitchPreference
|
||||
android:defaultValue="true"
|
||||
android:key="@string/key_app_update_auto"
|
||||
android:summary="@string/show_notification_app_update"
|
||||
android:title="@string/application_update"
|
||||
app:allowDividerBelow="true"
|
||||
app:iconSpaceReserved="false" />
|
||||
|
||||
</PreferenceCategory>
|
||||
|
||||
</PreferenceScreen>
|
||||
Reference in New Issue
Block a user