Simplify settings

This commit is contained in:
Koitharu
2020-03-28 19:40:43 +02:00
parent c5970c5606
commit 1314c601b2
14 changed files with 120 additions and 171 deletions

View File

@@ -15,7 +15,7 @@ android {
minSdkVersion 21 minSdkVersion 21
targetSdkVersion 29 targetSdkVersion 29
versionCode gitCommits versionCode gitCommits
versionName '0.1.1' versionName '0.1.2'
buildConfigField 'String', 'GIT_BRANCH', "\"${gitBranch}\"" buildConfigField 'String', 'GIT_BRANCH', "\"${gitBranch}\""

View File

@@ -6,8 +6,8 @@ import android.os.Bundle
import androidx.fragment.app.commit import androidx.fragment.app.commit
import org.koitharu.kotatsu.R import org.koitharu.kotatsu.R
import org.koitharu.kotatsu.ui.common.BaseActivity 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.ReaderSettingsFragment
import org.koitharu.kotatsu.ui.settings.SettingsHeadersFragment
class SimpleSettingsActivity : BaseActivity() { class SimpleSettingsActivity : BaseActivity() {
@@ -19,7 +19,7 @@ class SimpleSettingsActivity : BaseActivity() {
supportFragmentManager.commit { supportFragmentManager.commit {
replace(R.id.container, when(section) { replace(R.id.container, when(section) {
SECTION_READER -> ReaderSettingsFragment() SECTION_READER -> ReaderSettingsFragment()
else -> SettingsHeadersFragment() else -> MainSettingsFragment()
}) })
} }
} }

View File

@@ -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)
}
}

View File

@@ -5,21 +5,24 @@ import android.os.Bundle
import android.view.View import android.view.View
import androidx.appcompat.app.AppCompatDelegate import androidx.appcompat.app.AppCompatDelegate
import androidx.collection.arrayMapOf import androidx.collection.arrayMapOf
import androidx.preference.MultiSelectListPreference
import androidx.preference.Preference import androidx.preference.Preference
import androidx.preference.PreferenceScreen
import androidx.preference.SeekBarPreference import androidx.preference.SeekBarPreference
import org.koitharu.kotatsu.R import org.koitharu.kotatsu.R
import org.koitharu.kotatsu.core.model.MangaSource
import org.koitharu.kotatsu.core.prefs.ListMode import org.koitharu.kotatsu.core.prefs.ListMode
import org.koitharu.kotatsu.ui.common.BasePreferenceFragment import org.koitharu.kotatsu.ui.common.BasePreferenceFragment
import org.koitharu.kotatsu.ui.main.list.ListModeSelectDialog 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 { SharedPreferences.OnSharedPreferenceChangeListener {
override fun onCreatePreferences(savedInstanceState: Bundle?, rootKey: String?) { 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 = 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 { findPreference<SeekBarPreference>(R.string.key_grid_size)?.run {
summary = "%d%%".format(value) summary = "%d%%".format(value)
setOnPreferenceChangeListener { preference, newValue -> setOnPreferenceChangeListener { preference, newValue ->
@@ -27,6 +30,24 @@ class AppearanceSettingsFragment : BasePreferenceFragment(R.string.appearance),
true 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?) { 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 { private companion object {
val listModes = arrayMapOf( val LIST_MODES = arrayMapOf(
ListMode.DETAILED_LIST to R.string.detailed_list, ListMode.DETAILED_LIST to R.string.detailed_list,
ListMode.GRID to R.string.grid, ListMode.GRID to R.string.grid,
ListMode.LIST to R.string.list ListMode.LIST to R.string.list

View File

@@ -3,11 +3,9 @@ package org.koitharu.kotatsu.ui.settings
import android.content.Context import android.content.Context
import android.content.Intent import android.content.Intent
import android.os.Bundle import android.os.Bundle
import androidx.fragment.app.FragmentManager
import androidx.fragment.app.commit import androidx.fragment.app.commit
import androidx.preference.Preference import androidx.preference.Preference
import androidx.preference.PreferenceFragmentCompat import androidx.preference.PreferenceFragmentCompat
import kotlinx.android.synthetic.main.activity_settings.*
import org.koitharu.kotatsu.R import org.koitharu.kotatsu.R
import org.koitharu.kotatsu.core.model.MangaSource import org.koitharu.kotatsu.core.model.MangaSource
import org.koitharu.kotatsu.ui.common.BaseActivity import org.koitharu.kotatsu.ui.common.BaseActivity
@@ -20,48 +18,25 @@ class SettingsActivity : BaseActivity(),
setContentView(R.layout.activity_settings) setContentView(R.layout.activity_settings)
supportActionBar?.setDisplayHomeAsUpEnabled(true) supportActionBar?.setDisplayHomeAsUpEnabled(true)
val isTablet = container_side != null
if (supportFragmentManager.findFragmentById(R.id.container) == null) { if (supportFragmentManager.findFragmentById(R.id.container) == null) {
supportFragmentManager.commit { supportFragmentManager.commit {
if (isTablet) { replace(R.id.container, MainSettingsFragment())
replace(R.id.container_side, SettingsHeadersFragment())
replace(R.id.container, AppearanceSettingsFragment())
} else {
replace(R.id.container, SettingsHeadersFragment())
}
} }
} }
} }
override fun onPreferenceStartFragment(caller: PreferenceFragmentCompat, pref: Preference): Boolean { override fun onPreferenceStartFragment(caller: PreferenceFragmentCompat, pref: Preference): Boolean {
val fm = supportFragmentManager 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) val fragment = fm.fragmentFactory.instantiate(classLoader, pref.fragment)
fragment.arguments = pref.extras fragment.arguments = pref.extras
fragment.setTargetFragment(caller, 0) fragment.setTargetFragment(caller, 0)
fm.commit { fm.commit {
replace(R.id.container, fragment) replace(R.id.container, fragment)
if (container_side == null || caller !is SettingsHeadersFragment) { addToBackStack(null)
addToBackStack(null)
}
} }
return true 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) { fun openMangaSourceSettings(mangaSource: MangaSource) {
supportFragmentManager.commit { supportFragmentManager.commit {
replace(R.id.container, SourceSettingsFragment.newInstance(mangaSource)) replace(R.id.container, SourceSettingsFragment.newInstance(mangaSource))

View File

@@ -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)
}
}

View File

@@ -1,19 +1,18 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<RelativeLayout <androidx.constraintlayout.widget.ConstraintLayout
xmlns:android="http://schemas.android.com/apk/res/android" xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto" xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent" android:layout_height="match_parent"
android:background="?attr/colorButtonNormal"
android:orientation="vertical"> android:orientation="vertical">
<com.google.android.material.appbar.AppBarLayout <com.google.android.material.appbar.AppBarLayout
android:id="@+id/appbar" 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_height="wrap_content"
android:layout_alignParentStart="true"
android:layout_alignParentTop="true"
android:layout_alignParentEnd="true"
android:background="?colorPrimary" android:background="?colorPrimary"
android:theme="@style/AppToolbarTheme"> android:theme="@style/AppToolbarTheme">
@@ -26,23 +25,16 @@
</com.google.android.material.appbar.AppBarLayout> </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 <com.google.android.material.card.MaterialCardView
android:layout_width="wrap_content" app:layout_constraintStart_toStartOf="parent"
android:layout_height="wrap_content" app:layout_constraintEnd_toEndOf="parent"
android:layout_below="@id/appbar" app:layout_constraintBottom_toBottomOf="parent"
android:layout_alignParentEnd="true" app:layout_constraintTop_toBottomOf="@id/appbar"
android:layout_alignParentBottom="true" app:layout_constraintWidth_percent="0.6"
android:layout_margin="16dp" android:layout_marginTop="12dp"
android:layout_toEndOf="@id/container_side" android:layout_marginBottom="12dp"
app:cardBackgroundColor="?android:windowBackground"> android:layout_width="0dp"
android:layout_height="0dp">
<androidx.fragment.app.FragmentContainerView <androidx.fragment.app.FragmentContainerView
android:id="@id/container" android:id="@id/container"
@@ -51,4 +43,4 @@
</com.google.android.material.card.MaterialCardView> </com.google.android.material.card.MaterialCardView>
</RelativeLayout> </androidx.constraintlayout.widget.ConstraintLayout>

View File

@@ -111,4 +111,6 @@
<string name="open_in_browser">Открыть в браузере</string> <string name="open_in_browser">Открыть в браузере</string>
<string name="large_manga_save_confirm">В этой манге %d глав. Вы уверены, что хотите сохранить их все?</string> <string name="large_manga_save_confirm">В этой манге %d глав. Вы уверены, что хотите сохранить их все?</string>
<string name="save_manga">Сохранить мангу</string> <string name="save_manga">Сохранить мангу</string>
<string name="notifications">Уведомления</string>
<string name="enabled_d_from_d">Включено %1$d из %2$d</string>
</resources> </resources>

View File

@@ -10,6 +10,7 @@
<string name="key_search_history_clear">search_history_clear</string> <string name="key_search_history_clear">search_history_clear</string>
<string name="key_reading_history_clear">reading_history_clear</string> <string name="key_reading_history_clear">reading_history_clear</string>
<string name="key_grid_size">grid_size</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_reader_switchers">reader_switchers</string>
<string name="key_app_update">app_update</string> <string name="key_app_update">app_update</string>
<string name="key_app_update_auto">app_update_auto</string> <string name="key_app_update_auto">app_update_auto</string>

View File

@@ -112,4 +112,6 @@
<string name="open_in_browser">Open in browser</string> <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="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="save_manga">Save manga</string>
<string name="notifications">Notifications</string>
<string name="enabled_d_from_d">Enabled %1$d from %2$d</string>
</resources> </resources>

View File

@@ -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>

View File

@@ -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>

View File

@@ -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>

View 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>