Preferences with conductor (#792)
* Settings with conductor WIP * Add downloads preference controller. Implement source/track login * Improve settings controllers * Backup settings controller * Delete preferences xml * Remove keys from xml * PreferenceKeys is now an object * Remove now unused dependency
This commit is contained in:
@@ -2,6 +2,7 @@ package eu.kanade.tachiyomi.widget.preference
|
||||
|
||||
import android.content.Context
|
||||
import android.graphics.Color
|
||||
import android.support.v7.preference.CheckBoxPreference
|
||||
import android.support.v7.preference.PreferenceViewHolder
|
||||
import android.util.AttributeSet
|
||||
import android.view.View
|
||||
@@ -11,7 +12,6 @@ import eu.kanade.tachiyomi.source.online.LoginSource
|
||||
import eu.kanade.tachiyomi.util.getResourceColor
|
||||
import eu.kanade.tachiyomi.util.setVectorCompat
|
||||
import kotlinx.android.synthetic.main.pref_item_source.view.*
|
||||
import net.xpece.android.support.preference.CheckBoxPreference
|
||||
|
||||
class LoginCheckBoxPreference @JvmOverloads constructor(
|
||||
context: Context,
|
||||
|
||||
@@ -1,23 +1,22 @@
|
||||
package eu.kanade.tachiyomi.widget.preference
|
||||
|
||||
import android.app.Activity
|
||||
import android.app.Dialog
|
||||
import android.content.DialogInterface
|
||||
import android.content.Intent
|
||||
import android.os.Bundle
|
||||
import android.support.v4.app.DialogFragment
|
||||
import android.text.method.PasswordTransformationMethod
|
||||
import android.view.View
|
||||
import com.afollestad.materialdialogs.MaterialDialog
|
||||
import com.bluelinelabs.conductor.ControllerChangeHandler
|
||||
import com.bluelinelabs.conductor.ControllerChangeType
|
||||
import com.dd.processbutton.iml.ActionProcessButton
|
||||
import eu.kanade.tachiyomi.R
|
||||
import eu.kanade.tachiyomi.data.preference.PreferencesHelper
|
||||
import eu.kanade.tachiyomi.ui.base.controller.DialogController
|
||||
import eu.kanade.tachiyomi.widget.SimpleTextWatcher
|
||||
import kotlinx.android.synthetic.main.pref_account_login.view.*
|
||||
import rx.Subscription
|
||||
import uy.kohesive.injekt.injectLazy
|
||||
|
||||
abstract class LoginDialogPreference : DialogFragment() {
|
||||
abstract class LoginDialogPreference(bundle: Bundle? = null) : DialogController(bundle) {
|
||||
|
||||
var v: View? = null
|
||||
private set
|
||||
@@ -27,7 +26,7 @@ abstract class LoginDialogPreference : DialogFragment() {
|
||||
var requestSubscription: Subscription? = null
|
||||
|
||||
override fun onCreateDialog(savedState: Bundle?): Dialog {
|
||||
val dialog = MaterialDialog.Builder(activity)
|
||||
val dialog = MaterialDialog.Builder(activity!!)
|
||||
.customView(R.layout.pref_account_login, false)
|
||||
.negativeText(android.R.string.cancel)
|
||||
.build()
|
||||
@@ -37,7 +36,7 @@ abstract class LoginDialogPreference : DialogFragment() {
|
||||
return dialog
|
||||
}
|
||||
|
||||
override fun onViewCreated(view: View, savedState: Bundle?) {
|
||||
fun onViewCreated(view: View, savedState: Bundle?) {
|
||||
v = view.apply {
|
||||
show_password.setOnCheckedChangeListener { v, isChecked ->
|
||||
if (isChecked)
|
||||
@@ -55,7 +54,7 @@ abstract class LoginDialogPreference : DialogFragment() {
|
||||
|
||||
password.addTextChangedListener(object : SimpleTextWatcher() {
|
||||
override fun onTextChanged(s: CharSequence, start: Int, before: Int, count: Int) {
|
||||
if (s.length == 0) {
|
||||
if (s.isEmpty()) {
|
||||
show_password.isEnabled = true
|
||||
}
|
||||
}
|
||||
@@ -64,15 +63,15 @@ abstract class LoginDialogPreference : DialogFragment() {
|
||||
|
||||
}
|
||||
|
||||
override fun onPause() {
|
||||
super.onPause()
|
||||
requestSubscription?.unsubscribe()
|
||||
override fun onChangeStarted(handler: ControllerChangeHandler, type: ControllerChangeType) {
|
||||
super.onChangeStarted(handler, type)
|
||||
if (!type.isEnter) {
|
||||
onDialogClosed()
|
||||
}
|
||||
}
|
||||
|
||||
override fun onDismiss(dialog: DialogInterface) {
|
||||
super.onDismiss(dialog)
|
||||
val intent = Intent().putExtras(arguments)
|
||||
targetFragment?.onActivityResult(targetRequestCode, Activity.RESULT_OK, intent)
|
||||
open fun onDialogClosed() {
|
||||
requestSubscription?.unsubscribe()
|
||||
}
|
||||
|
||||
protected abstract fun checkLogin()
|
||||
|
||||
@@ -10,34 +10,17 @@ import eu.kanade.tachiyomi.util.toast
|
||||
import kotlinx.android.synthetic.main.pref_account_login.view.*
|
||||
import rx.android.schedulers.AndroidSchedulers
|
||||
import rx.schedulers.Schedulers
|
||||
import uy.kohesive.injekt.injectLazy
|
||||
import uy.kohesive.injekt.Injekt
|
||||
import uy.kohesive.injekt.api.get
|
||||
|
||||
class SourceLoginDialog : LoginDialogPreference() {
|
||||
class SourceLoginDialog(bundle: Bundle? = null) : LoginDialogPreference(bundle) {
|
||||
|
||||
companion object {
|
||||
private val source = Injekt.get<SourceManager>().get(args.getLong("key")) as LoginSource
|
||||
|
||||
fun newInstance(source: Source): LoginDialogPreference {
|
||||
val fragment = SourceLoginDialog()
|
||||
val bundle = Bundle(1)
|
||||
bundle.putLong("key", source.id)
|
||||
fragment.arguments = bundle
|
||||
return fragment
|
||||
}
|
||||
}
|
||||
|
||||
val sourceManager: SourceManager by injectLazy()
|
||||
|
||||
lateinit var source: LoginSource
|
||||
|
||||
override fun onCreate(savedInstanceState: Bundle?) {
|
||||
super.onCreate(savedInstanceState)
|
||||
|
||||
val sourceId = arguments.getLong("key")
|
||||
source = sourceManager.get(sourceId) as LoginSource
|
||||
}
|
||||
constructor(source: Source) : this(Bundle().apply { putLong("key", source.id) })
|
||||
|
||||
override fun setCredentialsOnView(view: View) = with(view) {
|
||||
dialog_title.text = getString(R.string.login_title, source.toString())
|
||||
dialog_title.text = context.getString(R.string.login_title, source.toString())
|
||||
username.setText(preferences.sourceUsername(source))
|
||||
password.setText(preferences.sourcePassword(source))
|
||||
}
|
||||
@@ -60,7 +43,7 @@ class SourceLoginDialog : LoginDialogPreference() {
|
||||
username.text.toString(),
|
||||
password.text.toString())
|
||||
|
||||
dialog.dismiss()
|
||||
dialog?.dismiss()
|
||||
context.toast(R.string.login_success)
|
||||
} else {
|
||||
preferences.setSourceCredentials(source, "", "")
|
||||
@@ -74,4 +57,13 @@ class SourceLoginDialog : LoginDialogPreference() {
|
||||
}
|
||||
}
|
||||
|
||||
override fun onDialogClosed() {
|
||||
super.onDialogClosed()
|
||||
(targetController as? Listener)?.loginDialogClosed(source)
|
||||
}
|
||||
|
||||
interface Listener {
|
||||
fun loginDialogClosed(source: LoginSource)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -4,15 +4,16 @@ import android.annotation.TargetApi
|
||||
import android.content.Context
|
||||
import android.content.res.TypedArray
|
||||
import android.os.Build.VERSION_CODES.ICE_CREAM_SANDWICH
|
||||
import android.support.v7.preference.PreferenceCategory
|
||||
import android.support.v7.preference.PreferenceViewHolder
|
||||
import android.support.v7.widget.SwitchCompat
|
||||
import android.util.AttributeSet
|
||||
import android.view.View
|
||||
import android.widget.Checkable
|
||||
import android.widget.CompoundButton
|
||||
import android.widget.TextView
|
||||
import eu.kanade.tachiyomi.R
|
||||
import eu.kanade.tachiyomi.util.getResourceColor
|
||||
import net.xpece.android.support.preference.PreferenceCategory
|
||||
import net.xpece.android.support.preference.R
|
||||
|
||||
class SwitchPreferenceCategory @JvmOverloads constructor(
|
||||
context: Context,
|
||||
@@ -20,20 +21,17 @@ class SwitchPreferenceCategory @JvmOverloads constructor(
|
||||
: PreferenceCategory(
|
||||
context,
|
||||
attrs,
|
||||
R.attr.switchPreferenceCompatStyle,
|
||||
R.style.Preference_Material_SwitchPreferenceCompat),
|
||||
R.attr.switchPreferenceCompatStyle),
|
||||
CompoundButton.OnCheckedChangeListener {
|
||||
|
||||
init {
|
||||
setTitleTextColor(context.getResourceColor(R.attr.colorAccent))
|
||||
}
|
||||
|
||||
private var mChecked = false
|
||||
|
||||
private var mCheckedSet = false
|
||||
|
||||
override fun onBindViewHolder(holder: PreferenceViewHolder) {
|
||||
super.onBindViewHolder(holder)
|
||||
val titleView = holder.findViewById(android.R.id.title) as TextView
|
||||
titleView.setTextColor(context.getResourceColor(R.attr.colorAccent))
|
||||
syncSwitchView(holder)
|
||||
}
|
||||
|
||||
|
||||
@@ -9,36 +9,19 @@ import eu.kanade.tachiyomi.util.toast
|
||||
import kotlinx.android.synthetic.main.pref_account_login.view.*
|
||||
import rx.android.schedulers.AndroidSchedulers
|
||||
import rx.schedulers.Schedulers
|
||||
import uy.kohesive.injekt.injectLazy
|
||||
import uy.kohesive.injekt.Injekt
|
||||
import uy.kohesive.injekt.api.get
|
||||
|
||||
class TrackLoginDialog : LoginDialogPreference() {
|
||||
class TrackLoginDialog(bundle: Bundle? = null) : LoginDialogPreference(bundle) {
|
||||
|
||||
companion object {
|
||||
private val service = Injekt.get<TrackManager>().getService(args.getInt("key"))!!
|
||||
|
||||
fun newInstance(sync: TrackService): LoginDialogPreference {
|
||||
val fragment = TrackLoginDialog()
|
||||
val bundle = Bundle(1)
|
||||
bundle.putInt("key", sync.id)
|
||||
fragment.arguments = bundle
|
||||
return fragment
|
||||
}
|
||||
}
|
||||
|
||||
val trackManager: TrackManager by injectLazy()
|
||||
|
||||
lateinit var sync: TrackService
|
||||
|
||||
override fun onCreate(savedInstanceState: Bundle?) {
|
||||
super.onCreate(savedInstanceState)
|
||||
|
||||
val syncId = arguments.getInt("key")
|
||||
sync = trackManager.getService(syncId)!!
|
||||
}
|
||||
constructor(service: TrackService) : this(Bundle().apply { putInt("key", service.id) })
|
||||
|
||||
override fun setCredentialsOnView(view: View) = with(view) {
|
||||
dialog_title.text = getString(R.string.login_title, sync.name)
|
||||
username.setText(sync.getUsername())
|
||||
password.setText(sync.getPassword())
|
||||
dialog_title.text = context.getString(R.string.login_title, service.name)
|
||||
username.setText(service.getUsername())
|
||||
password.setText(service.getPassword())
|
||||
}
|
||||
|
||||
override fun checkLogin() {
|
||||
@@ -52,11 +35,11 @@ class TrackLoginDialog : LoginDialogPreference() {
|
||||
val user = username.text.toString()
|
||||
val pass = password.text.toString()
|
||||
|
||||
requestSubscription = sync.login(user, pass)
|
||||
requestSubscription = service.login(user, pass)
|
||||
.subscribeOn(Schedulers.io())
|
||||
.observeOn(AndroidSchedulers.mainThread())
|
||||
.subscribe({
|
||||
dialog.dismiss()
|
||||
dialog?.dismiss()
|
||||
context.toast(R.string.login_success)
|
||||
}, { error ->
|
||||
login.progress = -1
|
||||
@@ -67,4 +50,13 @@ class TrackLoginDialog : LoginDialogPreference() {
|
||||
}
|
||||
}
|
||||
|
||||
override fun onDialogClosed() {
|
||||
super.onDialogClosed()
|
||||
(targetController as? Listener)?.trackDialogClosed(service)
|
||||
}
|
||||
|
||||
interface Listener {
|
||||
fun trackDialogClosed(service: TrackService)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user