mirror of
https://github.com/mihonapp/mihon.git
synced 2025-10-28 12:57:57 +01:00
Preferences ported to support library
This commit is contained in:
@@ -1,35 +0,0 @@
|
||||
package eu.kanade.tachiyomi.widget.preference;
|
||||
|
||||
import android.content.Context;
|
||||
import android.preference.ListPreference;
|
||||
import android.util.AttributeSet;
|
||||
|
||||
public class IntListPreference extends ListPreference
|
||||
{
|
||||
public IntListPreference(Context context, AttributeSet attrs) {
|
||||
super(context, attrs);
|
||||
}
|
||||
|
||||
public IntListPreference(Context context) {
|
||||
super(context);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean persistString(String value) {
|
||||
if(value == null) {
|
||||
return false;
|
||||
} else {
|
||||
return persistInt(Integer.valueOf(value));
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String getPersistedString(String defaultReturnValue) {
|
||||
if(getSharedPreferences().contains(getKey())) {
|
||||
int intValue = getPersistedInt(0);
|
||||
return String.valueOf(intValue);
|
||||
} else {
|
||||
return defaultReturnValue;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
package eu.kanade.tachiyomi.widget.preference
|
||||
|
||||
import android.content.Context
|
||||
import android.support.v7.preference.ListPreference
|
||||
import android.util.AttributeSet
|
||||
|
||||
class IntListPreference : ListPreference {
|
||||
constructor(context: Context, attrs: AttributeSet) : super(context, attrs) {
|
||||
}
|
||||
|
||||
constructor(context: Context) : super(context) {
|
||||
}
|
||||
|
||||
override fun persistString(value: String?): Boolean {
|
||||
return value != null && persistInt(value.toInt())
|
||||
}
|
||||
|
||||
override fun getPersistedString(defaultReturnValue: String?): String? {
|
||||
if (sharedPreferences.contains(key)) {
|
||||
return getPersistedInt(0).toString()
|
||||
} else {
|
||||
return defaultReturnValue
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,80 +0,0 @@
|
||||
package eu.kanade.tachiyomi.widget.preference;
|
||||
|
||||
import android.content.Context;
|
||||
import android.preference.DialogPreference;
|
||||
import android.util.AttributeSet;
|
||||
import android.view.View;
|
||||
import android.widget.NumberPicker;
|
||||
|
||||
import butterknife.Bind;
|
||||
import butterknife.ButterKnife;
|
||||
import eu.kanade.tachiyomi.R;
|
||||
import eu.kanade.tachiyomi.data.preference.PreferencesHelper;
|
||||
|
||||
public class LibraryColumnsDialog extends DialogPreference {
|
||||
|
||||
private Context context;
|
||||
private PreferencesHelper preferences;
|
||||
|
||||
@Bind(R.id.portrait_columns) NumberPicker portraitColumns;
|
||||
@Bind(R.id.landscape_columns) NumberPicker landscapeColumns;
|
||||
|
||||
public LibraryColumnsDialog(Context context, AttributeSet attrs) {
|
||||
super(context, attrs);
|
||||
init(context);
|
||||
}
|
||||
|
||||
public LibraryColumnsDialog(Context context, AttributeSet attrs, int defStyle) {
|
||||
super(context, attrs, defStyle);
|
||||
init(context);
|
||||
}
|
||||
|
||||
private void init(Context context) {
|
||||
this.context = context;
|
||||
setDialogLayoutResource(R.layout.pref_library_columns);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onBindDialogView(View view) {
|
||||
super.onBindDialogView(view);
|
||||
ButterKnife.bind(this, view);
|
||||
|
||||
portraitColumns.setValue(preferences.portraitColumns().get());
|
||||
landscapeColumns.setValue(preferences.landscapeColumns().get());
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onDialogClosed(boolean positiveResult) {
|
||||
super.onDialogClosed(positiveResult);
|
||||
|
||||
if (positiveResult) {
|
||||
preferences.portraitColumns().set(portraitColumns.getValue());
|
||||
preferences.landscapeColumns().set(landscapeColumns.getValue());
|
||||
updateSummary();
|
||||
}
|
||||
}
|
||||
|
||||
private void updateSummary() {
|
||||
setSummary(getColumnsSummary());
|
||||
}
|
||||
|
||||
private String getColumnsSummary() {
|
||||
return String.format("%s: %s, %s: %s",
|
||||
context.getString(R.string.portrait),
|
||||
getColumnValue(preferences.portraitColumns().get()),
|
||||
context.getString(R.string.landscape),
|
||||
getColumnValue(preferences.landscapeColumns().get()));
|
||||
}
|
||||
|
||||
private String getColumnValue(int value) {
|
||||
return value == 0 ? context.getString(R.string.default_columns) : value + "";
|
||||
}
|
||||
|
||||
public void setPreferencesHelper(PreferencesHelper preferences) {
|
||||
this.preferences = preferences;
|
||||
|
||||
// Set initial summary when the preferences helper is provided
|
||||
updateSummary();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,56 @@
|
||||
package eu.kanade.tachiyomi.widget.preference
|
||||
|
||||
import android.os.Bundle
|
||||
import android.support.v7.preference.Preference
|
||||
import android.support.v7.preference.PreferenceDialogFragmentCompat
|
||||
import android.view.View
|
||||
import eu.kanade.tachiyomi.data.preference.PreferencesHelper
|
||||
import eu.kanade.tachiyomi.data.preference.getOrDefault
|
||||
import eu.kanade.tachiyomi.ui.setting.SettingsActivity
|
||||
import kotlinx.android.synthetic.main.pref_library_columns.view.*
|
||||
|
||||
class LibraryColumnsDialog : PreferenceDialogFragmentCompat() {
|
||||
|
||||
companion object {
|
||||
|
||||
fun newInstance(preference: Preference): LibraryColumnsDialog {
|
||||
val fragment = LibraryColumnsDialog()
|
||||
val bundle = Bundle(1)
|
||||
bundle.putString("key", preference.key)
|
||||
fragment.arguments = bundle
|
||||
return fragment
|
||||
}
|
||||
}
|
||||
|
||||
var portrait: Int = 0
|
||||
var landscape: Int = 0
|
||||
|
||||
val preferences: PreferencesHelper
|
||||
get() = (activity as SettingsActivity).preferences
|
||||
|
||||
override fun onBindDialogView(view: View) {
|
||||
super.onBindDialogView(view)
|
||||
|
||||
portrait = preferences.portraitColumns().getOrDefault()
|
||||
landscape = preferences.landscapeColumns().getOrDefault()
|
||||
|
||||
view.portrait_columns.value = portrait
|
||||
view.landscape_columns.value = landscape
|
||||
|
||||
view.portrait_columns.setOnValueChangedListener { picker, oldValue, newValue ->
|
||||
portrait = newValue
|
||||
}
|
||||
|
||||
view.landscape_columns.setOnValueChangedListener { picker, oldValue, newValue ->
|
||||
landscape = newValue
|
||||
}
|
||||
}
|
||||
|
||||
override fun onDialogClosed(positiveResult: Boolean) {
|
||||
if (positiveResult) {
|
||||
preferences.portraitColumns().set(portrait)
|
||||
preferences.landscapeColumns().set(landscape)
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,78 +0,0 @@
|
||||
package eu.kanade.tachiyomi.widget.preference;
|
||||
|
||||
import android.app.AlertDialog;
|
||||
import android.content.Context;
|
||||
import android.os.Bundle;
|
||||
import android.preference.DialogPreference;
|
||||
import android.text.method.PasswordTransformationMethod;
|
||||
import android.view.View;
|
||||
import android.widget.CheckBox;
|
||||
import android.widget.EditText;
|
||||
import android.widget.TextView;
|
||||
|
||||
import com.dd.processbutton.iml.ActionProcessButton;
|
||||
|
||||
import butterknife.Bind;
|
||||
import butterknife.ButterKnife;
|
||||
import eu.kanade.tachiyomi.R;
|
||||
import eu.kanade.tachiyomi.data.preference.PreferencesHelper;
|
||||
import rx.Subscription;
|
||||
|
||||
public abstract class LoginDialogPreference extends DialogPreference {
|
||||
|
||||
@Bind(R.id.accounts_login) TextView title;
|
||||
@Bind(R.id.username) EditText username;
|
||||
@Bind(R.id.password) EditText password;
|
||||
@Bind(R.id.show_password) CheckBox showPassword;
|
||||
@Bind(R.id.login) ActionProcessButton loginBtn;
|
||||
|
||||
protected PreferencesHelper preferences;
|
||||
protected AlertDialog dialog;
|
||||
protected Subscription requestSubscription;
|
||||
protected Context context;
|
||||
|
||||
public LoginDialogPreference(Context context, PreferencesHelper preferences) {
|
||||
super(context, null);
|
||||
this.context = context;
|
||||
this.preferences = preferences;
|
||||
|
||||
setDialogLayoutResource(R.layout.pref_account_login);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onPrepareDialogBuilder(AlertDialog.Builder builder) {
|
||||
// Hide positive button
|
||||
builder.setPositiveButton("", this);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onBindDialogView(View view) {
|
||||
super.onBindDialogView(view);
|
||||
ButterKnife.bind(this, view);
|
||||
|
||||
showPassword.setOnCheckedChangeListener((buttonView, isChecked) -> {
|
||||
if (isChecked)
|
||||
password.setTransformationMethod(null);
|
||||
else
|
||||
password.setTransformationMethod(new PasswordTransformationMethod());
|
||||
});
|
||||
|
||||
loginBtn.setMode(ActionProcessButton.Mode.ENDLESS);
|
||||
loginBtn.setOnClickListener(click -> checkLogin());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void showDialog(Bundle state) {
|
||||
super.showDialog(state);
|
||||
dialog = ((AlertDialog) getDialog());
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onDialogClosed(boolean positiveResult) {
|
||||
if (requestSubscription != null)
|
||||
requestSubscription.unsubscribe();
|
||||
}
|
||||
|
||||
protected abstract void checkLogin();
|
||||
|
||||
}
|
||||
@@ -0,0 +1,70 @@
|
||||
package eu.kanade.tachiyomi.widget.preference
|
||||
|
||||
import android.support.v7.app.AlertDialog
|
||||
import android.support.v7.preference.PreferenceDialogFragmentCompat
|
||||
import android.text.Editable
|
||||
import android.text.TextWatcher
|
||||
import android.text.method.PasswordTransformationMethod
|
||||
import android.view.View
|
||||
import com.dd.processbutton.iml.ActionProcessButton
|
||||
import eu.kanade.tachiyomi.data.preference.PreferencesHelper
|
||||
import eu.kanade.tachiyomi.ui.setting.SettingsActivity
|
||||
import kotlinx.android.synthetic.main.pref_account_login.view.*
|
||||
import rx.Subscription
|
||||
|
||||
abstract class LoginDialogPreference : PreferenceDialogFragmentCompat() {
|
||||
|
||||
var v: View? = null
|
||||
private set
|
||||
|
||||
val preferences: PreferencesHelper
|
||||
get() = (activity as SettingsActivity).preferences
|
||||
|
||||
var requestSubscription: Subscription? = null
|
||||
|
||||
override fun onPrepareDialogBuilder(builder: AlertDialog.Builder) {
|
||||
// Hide positive button
|
||||
builder.setPositiveButton("", this)
|
||||
}
|
||||
|
||||
override fun onBindDialogView(view: View) {
|
||||
super.onBindDialogView(view)
|
||||
v = view.apply {
|
||||
show_password.setOnCheckedChangeListener { v, isChecked ->
|
||||
if (isChecked)
|
||||
password.transformationMethod = null
|
||||
else
|
||||
password.transformationMethod = PasswordTransformationMethod()
|
||||
}
|
||||
|
||||
login.setMode(ActionProcessButton.Mode.ENDLESS)
|
||||
login.setOnClickListener { checkLogin() }
|
||||
|
||||
setCredentialsOnView(this)
|
||||
|
||||
show_password.isEnabled = password.text.isNullOrEmpty()
|
||||
|
||||
password.addTextChangedListener(object : TextWatcher {
|
||||
override fun beforeTextChanged(s: CharSequence, start: Int, count: Int, after: Int) {}
|
||||
|
||||
override fun afterTextChanged(s: Editable) {}
|
||||
|
||||
override fun onTextChanged(s: CharSequence, start: Int, before: Int, count: Int) {
|
||||
if (s.length == 0) {
|
||||
show_password.isEnabled = true
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
override fun onDialogClosed(positiveResult: Boolean) {
|
||||
requestSubscription?.unsubscribe()
|
||||
}
|
||||
|
||||
protected abstract fun checkLogin()
|
||||
|
||||
protected abstract fun setCredentialsOnView(view: View)
|
||||
|
||||
}
|
||||
@@ -1,74 +0,0 @@
|
||||
package eu.kanade.tachiyomi.widget.preference;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.DialogInterface;
|
||||
import android.view.View;
|
||||
|
||||
import eu.kanade.tachiyomi.R;
|
||||
import eu.kanade.tachiyomi.data.mangasync.base.MangaSyncService;
|
||||
import eu.kanade.tachiyomi.data.preference.PreferencesHelper;
|
||||
import eu.kanade.tachiyomi.util.ToastUtil;
|
||||
import rx.android.schedulers.AndroidSchedulers;
|
||||
import rx.schedulers.Schedulers;
|
||||
|
||||
public class MangaSyncLoginDialog extends LoginDialogPreference {
|
||||
|
||||
private MangaSyncService sync;
|
||||
|
||||
public MangaSyncLoginDialog(Context context, PreferencesHelper preferences, MangaSyncService sync) {
|
||||
super(context, preferences);
|
||||
this.sync = sync;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onBindDialogView(View view) {
|
||||
super.onBindDialogView(view);
|
||||
|
||||
title.setText(getContext().getString(R.string.accounts_login_title, sync.getName()));
|
||||
|
||||
username.setText(preferences.getMangaSyncUsername(sync));
|
||||
password.setText(preferences.getMangaSyncPassword(sync));
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onDialogClosed(boolean positiveResult) {
|
||||
super.onDialogClosed(positiveResult);
|
||||
|
||||
if (positiveResult) {
|
||||
preferences.setMangaSyncCredentials(sync,
|
||||
username.getText().toString(),
|
||||
password.getText().toString());
|
||||
}
|
||||
}
|
||||
|
||||
protected void checkLogin() {
|
||||
if (requestSubscription != null)
|
||||
requestSubscription.unsubscribe();
|
||||
|
||||
if (username.getText().length() == 0 || password.getText().length() == 0)
|
||||
return;
|
||||
|
||||
loginBtn.setProgress(1);
|
||||
|
||||
requestSubscription = sync
|
||||
.login(username.getText().toString(), password.getText().toString())
|
||||
.subscribeOn(Schedulers.io())
|
||||
.observeOn(AndroidSchedulers.mainThread())
|
||||
.subscribe(logged -> {
|
||||
if (logged) {
|
||||
// Simulate a positive button click and dismiss the dialog
|
||||
onClick(dialog, DialogInterface.BUTTON_POSITIVE);
|
||||
dialog.dismiss();
|
||||
ToastUtil.showShort(context, R.string.login_success);
|
||||
} else {
|
||||
preferences.setMangaSyncCredentials(sync, "", "");
|
||||
loginBtn.setProgress(-1);
|
||||
}
|
||||
}, error -> {
|
||||
loginBtn.setProgress(-1);
|
||||
loginBtn.setText(R.string.unknown_error);
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,77 @@
|
||||
package eu.kanade.tachiyomi.widget.preference
|
||||
|
||||
import android.content.DialogInterface
|
||||
import android.os.Bundle
|
||||
import android.support.v7.preference.Preference
|
||||
import android.view.View
|
||||
import eu.kanade.tachiyomi.R
|
||||
import eu.kanade.tachiyomi.data.mangasync.base.MangaSyncService
|
||||
import eu.kanade.tachiyomi.ui.setting.SettingsActivity
|
||||
import eu.kanade.tachiyomi.util.toast
|
||||
import kotlinx.android.synthetic.main.pref_account_login.view.*
|
||||
import rx.android.schedulers.AndroidSchedulers
|
||||
import rx.schedulers.Schedulers
|
||||
|
||||
class MangaSyncLoginDialog : LoginDialogPreference() {
|
||||
|
||||
companion object {
|
||||
|
||||
fun newInstance(preference: Preference): LoginDialogPreference {
|
||||
val fragment = MangaSyncLoginDialog()
|
||||
val bundle = Bundle(1)
|
||||
bundle.putString("key", preference.key)
|
||||
fragment.arguments = bundle
|
||||
return fragment
|
||||
}
|
||||
}
|
||||
|
||||
lateinit var sync: MangaSyncService
|
||||
|
||||
override fun onCreate(savedInstanceState: Bundle?) {
|
||||
super.onCreate(savedInstanceState)
|
||||
|
||||
val syncId = Integer.parseInt(arguments.getString("key"))
|
||||
sync = (activity as SettingsActivity).syncManager.getService(syncId)
|
||||
}
|
||||
|
||||
override fun setCredentialsOnView(view: View) {
|
||||
view.accounts_login.text = getString(R.string.accounts_login_title, sync.name)
|
||||
view.username.setText(preferences.getMangaSyncUsername(sync))
|
||||
view.password.setText(preferences.getMangaSyncPassword(sync))
|
||||
}
|
||||
|
||||
override fun checkLogin() {
|
||||
requestSubscription?.unsubscribe()
|
||||
|
||||
v?.apply {
|
||||
if (username.text.length == 0 || password.text.length == 0)
|
||||
return
|
||||
|
||||
login.progress = 1
|
||||
|
||||
requestSubscription = sync.login(username.text.toString(), password.text.toString())
|
||||
.subscribeOn(Schedulers.io())
|
||||
.observeOn(AndroidSchedulers.mainThread())
|
||||
.subscribe({ logged ->
|
||||
if (logged) {
|
||||
preferences.setMangaSyncCredentials(sync,
|
||||
username.text.toString(),
|
||||
password.text.toString())
|
||||
|
||||
// Simulate a positive button click and dismiss the dialog
|
||||
onClick(dialog, DialogInterface.BUTTON_POSITIVE)
|
||||
dialog.dismiss()
|
||||
context.toast(R.string.login_success)
|
||||
} else {
|
||||
preferences.setMangaSyncCredentials(sync, "", "")
|
||||
login.progress = -1
|
||||
}
|
||||
}, { error ->
|
||||
login.progress = -1
|
||||
login.setText(R.string.unknown_error)
|
||||
})
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
package eu.kanade.tachiyomi.widget.preference
|
||||
|
||||
import android.content.Context
|
||||
import android.support.v7.preference.DialogPreference
|
||||
import android.support.v7.preference.R.attr
|
||||
import android.util.AttributeSet
|
||||
|
||||
open class SimpleDialogPreference @JvmOverloads constructor(context: Context, attrs: AttributeSet? = null, defStyleAttr: Int = attr.dialogPreferenceStyle, defStyleRes: Int = 0) :
|
||||
DialogPreference(context, attrs, defStyleAttr, defStyleRes) {
|
||||
|
||||
}
|
||||
@@ -1,74 +0,0 @@
|
||||
package eu.kanade.tachiyomi.widget.preference;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.DialogInterface;
|
||||
import android.view.View;
|
||||
|
||||
import eu.kanade.tachiyomi.R;
|
||||
import eu.kanade.tachiyomi.data.preference.PreferencesHelper;
|
||||
import eu.kanade.tachiyomi.data.source.base.Source;
|
||||
import eu.kanade.tachiyomi.util.ToastUtil;
|
||||
import rx.android.schedulers.AndroidSchedulers;
|
||||
import rx.schedulers.Schedulers;
|
||||
|
||||
public class SourceLoginDialog extends LoginDialogPreference {
|
||||
|
||||
private Source source;
|
||||
|
||||
public SourceLoginDialog(Context context, PreferencesHelper preferences, Source source) {
|
||||
super(context, preferences);
|
||||
this.source = source;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onBindDialogView(View view) {
|
||||
super.onBindDialogView(view);
|
||||
|
||||
title.setText(getContext().getString(R.string.accounts_login_title, source.getName()));
|
||||
|
||||
username.setText(preferences.getSourceUsername(source));
|
||||
password.setText(preferences.getSourcePassword(source));
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onDialogClosed(boolean positiveResult) {
|
||||
super.onDialogClosed(positiveResult);
|
||||
|
||||
if (positiveResult) {
|
||||
preferences.setSourceCredentials(source,
|
||||
username.getText().toString(),
|
||||
password.getText().toString());
|
||||
}
|
||||
}
|
||||
|
||||
protected void checkLogin() {
|
||||
if (requestSubscription != null)
|
||||
requestSubscription.unsubscribe();
|
||||
|
||||
if (username.getText().length() == 0 || password.getText().length() == 0)
|
||||
return;
|
||||
|
||||
loginBtn.setProgress(1);
|
||||
|
||||
requestSubscription = source
|
||||
.login(username.getText().toString(), password.getText().toString())
|
||||
.subscribeOn(Schedulers.io())
|
||||
.observeOn(AndroidSchedulers.mainThread())
|
||||
.subscribe(logged -> {
|
||||
if (logged) {
|
||||
// Simulate a positive button click and dismiss the dialog
|
||||
onClick(dialog, DialogInterface.BUTTON_POSITIVE);
|
||||
dialog.dismiss();
|
||||
ToastUtil.showShort(context, R.string.login_success);
|
||||
} else {
|
||||
preferences.setSourceCredentials(source, "", "");
|
||||
loginBtn.setProgress(-1);
|
||||
}
|
||||
}, error -> {
|
||||
loginBtn.setProgress(-1);
|
||||
loginBtn.setText(R.string.unknown_error);
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,76 @@
|
||||
package eu.kanade.tachiyomi.widget.preference
|
||||
|
||||
import android.content.DialogInterface
|
||||
import android.os.Bundle
|
||||
import android.support.v7.preference.Preference
|
||||
import android.view.View
|
||||
import eu.kanade.tachiyomi.R
|
||||
import eu.kanade.tachiyomi.data.source.base.Source
|
||||
import eu.kanade.tachiyomi.ui.setting.SettingsActivity
|
||||
import eu.kanade.tachiyomi.util.toast
|
||||
import kotlinx.android.synthetic.main.pref_account_login.view.*
|
||||
import rx.android.schedulers.AndroidSchedulers
|
||||
import rx.schedulers.Schedulers
|
||||
|
||||
class SourceLoginDialog : LoginDialogPreference() {
|
||||
|
||||
companion object {
|
||||
|
||||
fun newInstance(preference: Preference): LoginDialogPreference {
|
||||
val fragment = SourceLoginDialog()
|
||||
val bundle = Bundle(1)
|
||||
bundle.putString("key", preference.key)
|
||||
fragment.arguments = bundle
|
||||
return fragment
|
||||
}
|
||||
}
|
||||
|
||||
lateinit var source: Source
|
||||
|
||||
override fun onCreate(savedInstanceState: Bundle?) {
|
||||
super.onCreate(savedInstanceState)
|
||||
|
||||
val sourceId = Integer.parseInt(arguments.getString("key"))
|
||||
source = (activity as SettingsActivity).sourceManager.get(sourceId)!!
|
||||
}
|
||||
|
||||
override fun setCredentialsOnView(view: View) {
|
||||
view.accounts_login.text = getString(R.string.accounts_login_title, source.name)
|
||||
view.username.setText(preferences.getSourceUsername(source))
|
||||
view.password.setText(preferences.getSourcePassword(source))
|
||||
}
|
||||
|
||||
override fun checkLogin() {
|
||||
requestSubscription?.unsubscribe()
|
||||
|
||||
v?.apply {
|
||||
if (username.text.length == 0 || password.text.length == 0)
|
||||
return
|
||||
|
||||
login.progress = 1
|
||||
|
||||
requestSubscription = source.login(username.text.toString(), password.text.toString())
|
||||
.subscribeOn(Schedulers.io())
|
||||
.observeOn(AndroidSchedulers.mainThread())
|
||||
.subscribe({ logged ->
|
||||
if (logged) {
|
||||
preferences.setSourceCredentials(source,
|
||||
username.text.toString(),
|
||||
password.text.toString())
|
||||
|
||||
// Simulate a positive button click and dismiss the dialog
|
||||
onClick(dialog, DialogInterface.BUTTON_POSITIVE)
|
||||
dialog.dismiss()
|
||||
context.toast(R.string.login_success)
|
||||
} else {
|
||||
preferences.setSourceCredentials(source, "", "")
|
||||
login.progress = -1
|
||||
}
|
||||
}, { error ->
|
||||
login.progress = -1
|
||||
login.setText(R.string.unknown_error)
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user