Ignore the first spinner selection

This commit is contained in:
len 2016-06-30 12:56:14 +02:00
parent 72811e59f5
commit 1553ce973f
2 changed files with 24 additions and 18 deletions

View File

@ -10,7 +10,7 @@ import eu.kanade.tachiyomi.R
import eu.kanade.tachiyomi.data.preference.PreferencesHelper import eu.kanade.tachiyomi.data.preference.PreferencesHelper
import eu.kanade.tachiyomi.data.preference.getOrDefault import eu.kanade.tachiyomi.data.preference.getOrDefault
import eu.kanade.tachiyomi.util.plusAssign 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 eu.kanade.tachiyomi.widget.SimpleSeekBarListener
import kotlinx.android.synthetic.main.dialog_reader_settings.view.* import kotlinx.android.synthetic.main.dialog_reader_settings.view.*
import rx.Observable import rx.Observable
@ -39,8 +39,7 @@ class ReaderSettingsDialog : DialogFragment() {
} }
override fun onViewCreated(view: View, savedState: Bundle?) = with(view) { override fun onViewCreated(view: View, savedState: Bundle?) = with(view) {
viewer.setSelection((activity as ReaderActivity).presenter.manga.viewer, false) viewer.onItemSelectedListener = IgnoreFirstSpinnerListener { position ->
viewer.onItemSelectedListener = SimpleItemSelectedListener { position ->
subscriptions += Observable.timer(250, MILLISECONDS) subscriptions += Observable.timer(250, MILLISECONDS)
.observeOn(AndroidSchedulers.mainThread()) .observeOn(AndroidSchedulers.mainThread())
.subscribe { .subscribe {
@ -48,35 +47,36 @@ class ReaderSettingsDialog : DialogFragment() {
activity.recreate() activity.recreate()
} }
} }
viewer.setSelection((activity as ReaderActivity).presenter.manga.viewer, false)
rotation_mode.setSelection(preferences.rotation().getOrDefault() - 1, false) rotation_mode.onItemSelectedListener = IgnoreFirstSpinnerListener { position ->
rotation_mode.onItemSelectedListener = SimpleItemSelectedListener { position ->
subscriptions += Observable.timer(250, MILLISECONDS) subscriptions += Observable.timer(250, MILLISECONDS)
.observeOn(AndroidSchedulers.mainThread()) .observeOn(AndroidSchedulers.mainThread())
.subscribe { .subscribe {
preferences.rotation().set(position + 1) preferences.rotation().set(position + 1)
} }
} }
rotation_mode.setSelection(preferences.rotation().getOrDefault() - 1, false)
scale_type.setSelection(preferences.imageScaleType().getOrDefault() - 1, false) scale_type.onItemSelectedListener = IgnoreFirstSpinnerListener { position ->
scale_type.onItemSelectedListener = SimpleItemSelectedListener { position ->
preferences.imageScaleType().set(position + 1) preferences.imageScaleType().set(position + 1)
} }
scale_type.setSelection(preferences.imageScaleType().getOrDefault() - 1, false)
zoom_start.setSelection(preferences.zoomStart().getOrDefault() - 1, false) zoom_start.onItemSelectedListener = IgnoreFirstSpinnerListener { position ->
zoom_start.onItemSelectedListener = SimpleItemSelectedListener { position ->
preferences.zoomStart().set(position + 1) preferences.zoomStart().set(position + 1)
} }
zoom_start.setSelection(preferences.zoomStart().getOrDefault() - 1, false)
image_decoder.setSelection(preferences.imageDecoder().getOrDefault(), false) image_decoder.onItemSelectedListener = IgnoreFirstSpinnerListener { position ->
image_decoder.onItemSelectedListener = SimpleItemSelectedListener { position ->
preferences.imageDecoder().set(position) preferences.imageDecoder().set(position)
} }
image_decoder.setSelection(preferences.imageDecoder().getOrDefault(), false)
background_color.setSelection(preferences.readerTheme().getOrDefault(), false) background_color.onItemSelectedListener = IgnoreFirstSpinnerListener { position ->
background_color.onItemSelectedListener = SimpleItemSelectedListener { position ->
preferences.readerTheme().set(position) preferences.readerTheme().set(position)
} }
background_color.setSelection(preferences.readerTheme().getOrDefault(), false)
enable_transitions.isChecked = preferences.enableTransitions().getOrDefault() enable_transitions.isChecked = preferences.enableTransitions().getOrDefault()
enable_transitions.setOnCheckedChangeListener { v, isChecked -> enable_transitions.setOnCheckedChangeListener { v, isChecked ->

View File

@ -4,13 +4,19 @@ import android.view.View
import android.widget.AdapterView import android.widget.AdapterView
import android.widget.AdapterView.OnItemSelectedListener 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 onNothingSelected(parent: AdapterView<*>?) {
} }
override fun onItemSelected(parent: AdapterView<*>?, view: View?, position: Int, id: Long) {
callback(position)
}
} }