Albirew/tachiyomi
Archivé
1
0
Bifurcation 0

Ignore the first spinner selection

Cette révision appartient à :
len 2016-06-30 12:56:14 +02:00
Parent 72811e59f5
révision 1553ce973f
2 fichiers modifiés avec 24 ajouts et 18 suppressions

Voir le fichier

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

Voir le fichier

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