Fix default value for some preferences

pull/26/head
Koitharu 5 years ago
parent 9b5510ac59
commit 6b529f806f

@ -30,7 +30,10 @@ class ChaptersAdapter(
return oldItem.chapter.id == newItem.chapter.id return oldItem.chapter.id == newItem.chapter.id
} }
override fun areContentsTheSame(oldItem: ChapterListItem, newItem: ChapterListItem): Boolean { override fun areContentsTheSame(
oldItem: ChapterListItem,
newItem: ChapterListItem
): Boolean {
return Intrinsics.areEqual(oldItem, newItem) return Intrinsics.areEqual(oldItem, newItem)
} }

@ -84,7 +84,11 @@ class HistoryListViewModel(
settings.historyGrouping = isGroupingEnabled settings.historyGrouping = isGroupingEnabled
} }
private fun mapList(list: List<MangaWithHistory>, grouped: Boolean, mode: ListMode): List<ListModel> { private fun mapList(
list: List<MangaWithHistory>,
grouped: Boolean,
mode: ListMode
): List<ListModel> {
val result = ArrayList<ListModel>(if (grouped) (list.size * 1.4).toInt() else list.size) val result = ArrayList<ListModel>(if (grouped) (list.size * 1.4).toInt() else list.size)
var prevDate: DateTimeAgo? = null var prevDate: DateTimeAgo? = null
for ((manga, history) in list) { for ((manga, history) in list) {

@ -30,17 +30,18 @@ fun Manga.toGridModel() = MangaGridModel(
manga = this manga = this
) )
fun List<Manga>.toUi(mode: ListMode): List<ListModel> = when(mode) { fun List<Manga>.toUi(mode: ListMode): List<ListModel> = when (mode) {
ListMode.LIST -> map(Manga::toListModel) ListMode.LIST -> map(Manga::toListModel)
ListMode.DETAILED_LIST -> map(Manga::toListDetailedModel) ListMode.DETAILED_LIST -> map(Manga::toListDetailedModel)
ListMode.GRID -> map(Manga::toGridModel) ListMode.GRID -> map(Manga::toGridModel)
} }
fun <C : MutableCollection<ListModel>> List<Manga>.toUi(destination: C, mode: ListMode): C = when(mode) { fun <C : MutableCollection<ListModel>> List<Manga>.toUi(destination: C, mode: ListMode): C =
ListMode.LIST -> mapTo(destination, Manga::toListModel) when (mode) {
ListMode.DETAILED_LIST -> mapTo(destination, Manga::toListDetailedModel) ListMode.LIST -> mapTo(destination, Manga::toListModel)
ListMode.GRID -> mapTo(destination, Manga::toGridModel) ListMode.DETAILED_LIST -> mapTo(destination, Manga::toListDetailedModel)
} ListMode.GRID -> mapTo(destination, Manga::toGridModel)
}
fun Throwable.toErrorState(canRetry: Boolean = true) = ErrorState( fun Throwable.toErrorState(canRetry: Boolean = true) = ErrorState(
exception = this, exception = this,

@ -23,10 +23,7 @@ import org.koitharu.kotatsu.core.prefs.AppSettings
import org.koitharu.kotatsu.core.prefs.ListMode import org.koitharu.kotatsu.core.prefs.ListMode
import org.koitharu.kotatsu.settings.utils.MultiSummaryProvider import org.koitharu.kotatsu.settings.utils.MultiSummaryProvider
import org.koitharu.kotatsu.tracker.work.TrackWorker import org.koitharu.kotatsu.tracker.work.TrackWorker
import org.koitharu.kotatsu.utils.ext.getStorageName import org.koitharu.kotatsu.utils.ext.*
import org.koitharu.kotatsu.utils.ext.md5
import org.koitharu.kotatsu.utils.ext.names
import org.koitharu.kotatsu.utils.ext.viewLifecycleScope
import java.io.File import java.io.File
@ -43,22 +40,18 @@ class MainSettingsFragment : BasePreferenceFragment(R.string.settings),
true true
} }
} }
findPreference<MultiSelectListPreference>(AppSettings.KEY_READER_SWITCHERS)?.summaryProvider =
MultiSummaryProvider(R.string.gestures_only)
findPreference<MultiSelectListPreference>(AppSettings.KEY_TRACK_SOURCES)?.summaryProvider =
MultiSummaryProvider(R.string.dont_check)
}
override fun setPreferenceScreen(preferenceScreen: PreferenceScreen?) {
preferenceScreen?.findPreference<ListPreference>(AppSettings.KEY_ZOOM_MODE)?.run { preferenceScreen?.findPreference<ListPreference>(AppSettings.KEY_ZOOM_MODE)?.run {
entryValues = ZoomMode.values().names() entryValues = ZoomMode.values().names()
setDefaultValue(ZoomMode.FIT_CENTER.name) setDefaultValueCompat(ZoomMode.FIT_CENTER.name)
} }
preferenceScreen?.findPreference<ListPreference>(AppSettings.KEY_LIST_MODE)?.run { preferenceScreen?.findPreference<ListPreference>(AppSettings.KEY_LIST_MODE)?.run {
entryValues = ListMode.values().names() entryValues = ListMode.values().names()
setDefaultValue(ListMode.GRID.name) setDefaultValueCompat(ListMode.GRID.name)
} }
super.setPreferenceScreen(preferenceScreen) findPreference<MultiSelectListPreference>(AppSettings.KEY_READER_SWITCHERS)?.summaryProvider =
MultiSummaryProvider(R.string.gestures_only)
findPreference<MultiSelectListPreference>(AppSettings.KEY_TRACK_SOURCES)?.summaryProvider =
MultiSummaryProvider(R.string.dont_check)
} }
override fun onViewCreated(view: View, savedInstanceState: Bundle?) { override fun onViewCreated(view: View, savedInstanceState: Bundle?) {

@ -9,6 +9,7 @@ import org.koitharu.kotatsu.core.model.ZoomMode
import org.koitharu.kotatsu.core.prefs.AppSettings import org.koitharu.kotatsu.core.prefs.AppSettings
import org.koitharu.kotatsu.settings.utils.MultiSummaryProvider import org.koitharu.kotatsu.settings.utils.MultiSummaryProvider
import org.koitharu.kotatsu.utils.ext.names import org.koitharu.kotatsu.utils.ext.names
import org.koitharu.kotatsu.utils.ext.setDefaultValueCompat
class ReaderSettingsFragment : BasePreferenceFragment(R.string.reader_settings) { class ReaderSettingsFragment : BasePreferenceFragment(R.string.reader_settings) {
@ -19,7 +20,7 @@ class ReaderSettingsFragment : BasePreferenceFragment(R.string.reader_settings)
} }
findPreference<ListPreference>(AppSettings.KEY_ZOOM_MODE)?.let { findPreference<ListPreference>(AppSettings.KEY_ZOOM_MODE)?.let {
it.entryValues = ZoomMode.values().names() it.entryValues = ZoomMode.values().names()
it.setDefaultValue(ZoomMode.FIT_CENTER.name) it.setDefaultValueCompat(ZoomMode.FIT_CENTER.name)
} }
} }
} }

@ -0,0 +1,9 @@
package org.koitharu.kotatsu.utils.ext
import androidx.preference.ListPreference
fun ListPreference.setDefaultValueCompat(defaultValue: String) {
if (value == null) {
value = defaultValue
}
}

@ -1,7 +1,6 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<FrameLayout <FrameLayout
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"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent" android:layout_height="match_parent"
android:orientation="vertical"> android:orientation="vertical">

@ -10,11 +10,11 @@
android:padding="4dp"> android:padding="4dp">
<ImageView <ImageView
android:contentDescription="@null"
android:id="@+id/imageView_icon" android:id="@+id/imageView_icon"
tools:src="@drawable/ic_alert_outline"
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" /> android:layout_height="wrap_content"
android:contentDescription="@null"
tools:src="@drawable/ic_alert_outline" />
<LinearLayout <LinearLayout
android:layout_width="wrap_content" android:layout_width="wrap_content"

@ -1,7 +1,6 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<FrameLayout <FrameLayout
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"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="@dimen/list_footer_height" android:layout_height="@dimen/list_footer_height"
android:padding="6dp"> android:padding="6dp">

@ -1,10 +1,10 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<resources> <resources>
<dimen name="grid_spacing">5dp</dimen> <dimen name="grid_spacing">5dp</dimen>
<dimen name="manga_list_item_height">84dp</dimen> <dimen name="manga_list_item_height">84dp</dimen>
<dimen name="manga_list_details_item_height">120dp</dimen> <dimen name="manga_list_details_item_height">120dp</dimen>
<dimen name="chapter_list_item_height">46dp</dimen> <dimen name="chapter_list_item_height">46dp</dimen>
<dimen name="preferred_grid_width">120dp</dimen> <dimen name="preferred_grid_width">120dp</dimen>
<dimen name="header_height">34dp</dimen> <dimen name="header_height">34dp</dimen>
<dimen name="elevation_large">16dp</dimen> <dimen name="elevation_large">16dp</dimen>
<dimen name="list_footer_height">48dp</dimen> <dimen name="list_footer_height">48dp</dimen>

Loading…
Cancel
Save