From 1553ce973ffb890732042fc512f203d8ffdac7dc Mon Sep 17 00:00:00 2001 From: len Date: Thu, 30 Jun 2016 12:56:14 +0200 Subject: [PATCH] Ignore the first spinner selection --- .../ui/reader/ReaderSettingsDialog.kt | 26 +++++++++---------- ...tener.kt => IgnoreFirstSpinnerListener.kt} | 16 ++++++++---- 2 files changed, 24 insertions(+), 18 deletions(-) rename app/src/main/java/eu/kanade/tachiyomi/widget/{SimpleItemSelectedListener.kt => IgnoreFirstSpinnerListener.kt} (57%) diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/reader/ReaderSettingsDialog.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/reader/ReaderSettingsDialog.kt index ec668ac822..9ccaae4781 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/reader/ReaderSettingsDialog.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/reader/ReaderSettingsDialog.kt @@ -10,7 +10,7 @@ import eu.kanade.tachiyomi.R import eu.kanade.tachiyomi.data.preference.PreferencesHelper import eu.kanade.tachiyomi.data.preference.getOrDefault import eu.kanade.tachiyomi.util.plusAssign -import eu.kanade.tachiyomi.widget.SimpleItemSelectedListener +import eu.kanade.tachiyomi.widget.IgnoreFirstSpinnerListener import eu.kanade.tachiyomi.widget.SimpleSeekBarListener import kotlinx.android.synthetic.main.dialog_reader_settings.view.* import rx.Observable @@ -39,8 +39,7 @@ class ReaderSettingsDialog : DialogFragment() { } override fun onViewCreated(view: View, savedState: Bundle?) = with(view) { - viewer.setSelection((activity as ReaderActivity).presenter.manga.viewer, false) - viewer.onItemSelectedListener = SimpleItemSelectedListener { position -> + viewer.onItemSelectedListener = IgnoreFirstSpinnerListener { position -> subscriptions += Observable.timer(250, MILLISECONDS) .observeOn(AndroidSchedulers.mainThread()) .subscribe { @@ -48,35 +47,36 @@ class ReaderSettingsDialog : DialogFragment() { activity.recreate() } } + viewer.setSelection((activity as ReaderActivity).presenter.manga.viewer, false) - rotation_mode.setSelection(preferences.rotation().getOrDefault() - 1, false) - rotation_mode.onItemSelectedListener = SimpleItemSelectedListener { position -> + rotation_mode.onItemSelectedListener = IgnoreFirstSpinnerListener { position -> subscriptions += Observable.timer(250, MILLISECONDS) .observeOn(AndroidSchedulers.mainThread()) .subscribe { preferences.rotation().set(position + 1) } } + rotation_mode.setSelection(preferences.rotation().getOrDefault() - 1, false) - scale_type.setSelection(preferences.imageScaleType().getOrDefault() - 1, false) - scale_type.onItemSelectedListener = SimpleItemSelectedListener { position -> + scale_type.onItemSelectedListener = IgnoreFirstSpinnerListener { position -> preferences.imageScaleType().set(position + 1) } + scale_type.setSelection(preferences.imageScaleType().getOrDefault() - 1, false) - zoom_start.setSelection(preferences.zoomStart().getOrDefault() - 1, false) - zoom_start.onItemSelectedListener = SimpleItemSelectedListener { position -> + zoom_start.onItemSelectedListener = IgnoreFirstSpinnerListener { position -> preferences.zoomStart().set(position + 1) } + zoom_start.setSelection(preferences.zoomStart().getOrDefault() - 1, false) - image_decoder.setSelection(preferences.imageDecoder().getOrDefault(), false) - image_decoder.onItemSelectedListener = SimpleItemSelectedListener { position -> + image_decoder.onItemSelectedListener = IgnoreFirstSpinnerListener { position -> preferences.imageDecoder().set(position) } + image_decoder.setSelection(preferences.imageDecoder().getOrDefault(), false) - background_color.setSelection(preferences.readerTheme().getOrDefault(), false) - background_color.onItemSelectedListener = SimpleItemSelectedListener { position -> + background_color.onItemSelectedListener = IgnoreFirstSpinnerListener { position -> preferences.readerTheme().set(position) } + background_color.setSelection(preferences.readerTheme().getOrDefault(), false) enable_transitions.isChecked = preferences.enableTransitions().getOrDefault() enable_transitions.setOnCheckedChangeListener { v, isChecked -> diff --git a/app/src/main/java/eu/kanade/tachiyomi/widget/SimpleItemSelectedListener.kt b/app/src/main/java/eu/kanade/tachiyomi/widget/IgnoreFirstSpinnerListener.kt similarity index 57% rename from app/src/main/java/eu/kanade/tachiyomi/widget/SimpleItemSelectedListener.kt rename to app/src/main/java/eu/kanade/tachiyomi/widget/IgnoreFirstSpinnerListener.kt index 00a18c92b3..eab856562a 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/widget/SimpleItemSelectedListener.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/widget/IgnoreFirstSpinnerListener.kt @@ -4,13 +4,19 @@ import android.view.View import android.widget.AdapterView import android.widget.AdapterView.OnItemSelectedListener -class SimpleItemSelectedListener(private val callback: (Int) -> Unit): OnItemSelectedListener { +class IgnoreFirstSpinnerListener(private val block: (Int) -> Unit): OnItemSelectedListener { + + private var firstEvent = true + + override fun onItemSelected(parent: AdapterView<*>?, view: View?, position: Int, id: Long) { + if (!firstEvent) { + block(position) + } else { + firstEvent = false + } + } override fun onNothingSelected(parent: AdapterView<*>?) { } - - override fun onItemSelected(parent: AdapterView<*>?, view: View?, position: Int, id: Long) { - callback(position) - } } \ No newline at end of file