Preferences ported to support library

This commit is contained in:
len 2016-03-07 23:48:43 +01:00
parent bcbd541d48
commit 70e557575f
26 changed files with 488 additions and 440 deletions

View file

@ -118,6 +118,8 @@ dependencies {
compile "com.android.support:recyclerview-v7:$SUPPORT_LIBRARY_VERSION" compile "com.android.support:recyclerview-v7:$SUPPORT_LIBRARY_VERSION"
compile "com.android.support:support-annotations:$SUPPORT_LIBRARY_VERSION" compile "com.android.support:support-annotations:$SUPPORT_LIBRARY_VERSION"
compile "com.android.support:percent:$SUPPORT_LIBRARY_VERSION" compile "com.android.support:percent:$SUPPORT_LIBRARY_VERSION"
compile "com.android.support:preference-v7:$SUPPORT_LIBRARY_VERSION"
compile "com.android.support:preference-v14:$SUPPORT_LIBRARY_VERSION"
compile "com.squareup.okhttp3:okhttp:$OKHTTP_VERSION" compile "com.squareup.okhttp3:okhttp:$OKHTTP_VERSION"
compile "com.squareup.okhttp3:okhttp-urlconnection:$OKHTTP_VERSION" compile "com.squareup.okhttp3:okhttp-urlconnection:$OKHTTP_VERSION"
compile 'com.squareup.okio:okio:1.6.0' compile 'com.squareup.okio:okio:1.6.0'

View file

@ -1,8 +1,12 @@
package eu.kanade.tachiyomi.ui.setting package eu.kanade.tachiyomi.ui.setting
import android.content.Context
import android.os.Bundle import android.os.Bundle
import android.preference.PreferenceCategory import android.support.v7.preference.DialogPreference
import android.support.v7.preference.Preference
import android.support.v7.preference.PreferenceCategory
import android.view.View import android.view.View
import eu.kanade.tachiyomi.R
import eu.kanade.tachiyomi.data.source.base.Source import eu.kanade.tachiyomi.data.source.base.Source
import eu.kanade.tachiyomi.widget.preference.MangaSyncLoginDialog import eu.kanade.tachiyomi.widget.preference.MangaSyncLoginDialog
import eu.kanade.tachiyomi.widget.preference.SourceLoginDialog import eu.kanade.tachiyomi.widget.preference.SourceLoginDialog
@ -18,29 +22,32 @@ class SettingsAccountsFragment : SettingsNestedFragment() {
} }
} }
val sourceCategory by lazy { findPreference("pref_category_source_accounts") as PreferenceCategory }
val syncCategory by lazy { findPreference("pref_category_manga_sync_accounts") as PreferenceCategory }
override fun onViewCreated(view: View, savedInstanceState: Bundle?) { override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
PreferenceCategory(activity).apply { val themedContext = preferenceManager.context
preferenceScreen.addPreference(this)
title = "Sources"
for (source in getSourcesWithLogin()) { for (source in getSourcesWithLogin()) {
val dialog = SourceLoginDialog(activity, preferences, source) val pref = SourcePreference(themedContext).apply {
dialog.title = source.name isPersistent = false
title = source.name
addPreference(dialog) key = source.id.toString()
dialogLayoutResource = R.layout.pref_account_login
} }
sourceCategory.addPreference(pref)
} }
PreferenceCategory(activity).apply { for (sync in settingsActivity.syncManager.services) {
preferenceScreen.addPreference(this) val pref = SyncPreference(themedContext).apply {
title = "Sync" isPersistent = false
title = sync.name
for (sync in settingsActivity.syncManager.services) { key = sync.id.toString()
val dialog = MangaSyncLoginDialog(activity, preferences, sync) dialogLayoutResource = R.layout.pref_account_login
dialog.title = sync.name
addPreference(dialog)
} }
syncCategory.addPreference(pref)
} }
} }
@ -48,4 +55,22 @@ class SettingsAccountsFragment : SettingsNestedFragment() {
return settingsActivity.sourceManager.sources.filter { it.isLoginRequired } return settingsActivity.sourceManager.sources.filter { it.isLoginRequired }
} }
override fun onDisplayPreferenceDialog(preference: Preference) {
if (preference is SourcePreference) {
val fragment = SourceLoginDialog.newInstance(preference)
fragment.setTargetFragment(this, 0)
fragment.show(childFragmentManager, null)
} else if (preference is SyncPreference) {
val fragment = MangaSyncLoginDialog.newInstance(preference)
fragment.setTargetFragment(this, 0)
fragment.show(childFragmentManager, null)
} else {
super.onDisplayPreferenceDialog(preference)
}
}
class SourcePreference(context: Context) : DialogPreference(context) {}
class SyncPreference(context: Context) : DialogPreference(context) {}
} }

View file

@ -1,7 +1,7 @@
package eu.kanade.tachiyomi.ui.setting package eu.kanade.tachiyomi.ui.setting
import android.os.Bundle import android.os.Bundle
import android.preference.PreferenceFragment import android.support.v7.preference.PreferenceFragmentCompat
import eu.kanade.tachiyomi.R import eu.kanade.tachiyomi.R
import eu.kanade.tachiyomi.data.cache.ChapterCache import eu.kanade.tachiyomi.data.cache.ChapterCache
import eu.kanade.tachiyomi.data.database.DatabaseHelper import eu.kanade.tachiyomi.data.database.DatabaseHelper
@ -28,46 +28,46 @@ class SettingsActivity : BaseActivity() {
setupToolbar(toolbar) setupToolbar(toolbar)
if (savedState == null) { if (savedState == null) {
fragmentManager.beginTransaction().replace(R.id.settings_content, supportFragmentManager.beginTransaction()
SettingsMainFragment()).commit() .replace(R.id.settings_content,SettingsMainFragment())
.commit()
} }
} }
override fun onBackPressed() { override fun onBackPressed() {
if (!fragmentManager.popBackStackImmediate()) { if (!supportFragmentManager.popBackStackImmediate()) {
super.onBackPressed() super.onBackPressed()
} }
} }
class SettingsMainFragment : PreferenceFragment() { class SettingsMainFragment : PreferenceFragmentCompat() {
override fun onCreate(savedInstanceState: Bundle?) { override fun onCreatePreferences(savedState: Bundle?, s: String?) {
super.onCreate(savedInstanceState)
addPreferencesFromResource(R.xml.pref_main) addPreferencesFromResource(R.xml.pref_main)
registerSubpreference(R.string.pref_category_general_key, registerSubpreference(R.string.pref_category_general_key) {
SettingsGeneralFragment.newInstance( SettingsGeneralFragment.newInstance(R.xml.pref_general, R.string.pref_category_general)
R.xml.pref_general, R.string.pref_category_general)) }
registerSubpreference(R.string.pref_category_reader_key, registerSubpreference(R.string.pref_category_reader_key) {
SettingsNestedFragment.newInstance( SettingsNestedFragment.newInstance(R.xml.pref_reader, R.string.pref_category_reader)
R.xml.pref_reader, R.string.pref_category_reader)) }
registerSubpreference(R.string.pref_category_downloads_key, registerSubpreference(R.string.pref_category_downloads_key) {
SettingsDownloadsFragment.newInstance( SettingsDownloadsFragment.newInstance(R.xml.pref_downloads, R.string.pref_category_downloads)
R.xml.pref_downloads, R.string.pref_category_downloads)) }
registerSubpreference(R.string.pref_category_accounts_key, registerSubpreference(R.string.pref_category_accounts_key) {
SettingsAccountsFragment.newInstance( SettingsAccountsFragment.newInstance(R.xml.pref_accounts, R.string.pref_category_accounts)
R.xml.pref_accounts, R.string.pref_category_accounts)) }
registerSubpreference(R.string.pref_category_advanced_key, registerSubpreference(R.string.pref_category_advanced_key) {
SettingsAdvancedFragment.newInstance( SettingsAdvancedFragment.newInstance(R.xml.pref_advanced, R.string.pref_category_advanced)
R.xml.pref_advanced, R.string.pref_category_advanced)) }
registerSubpreference(R.string.pref_category_about_key, registerSubpreference(R.string.pref_category_about_key) {
SettingsAboutFragment.newInstance( SettingsAboutFragment.newInstance(R.xml.pref_about, R.string.pref_category_about)
R.xml.pref_about, R.string.pref_category_about)) }
} }
override fun onResume() { override fun onResume() {
@ -75,8 +75,9 @@ class SettingsActivity : BaseActivity() {
(activity as BaseActivity).setToolbarTitle(getString(R.string.label_settings)) (activity as BaseActivity).setToolbarTitle(getString(R.string.label_settings))
} }
private fun registerSubpreference(preferenceResource: Int, fragment: PreferenceFragment) { private fun registerSubpreference(preferenceResource: Int, func: () -> PreferenceFragmentCompat) {
findPreference(getString(preferenceResource)).setOnPreferenceClickListener { findPreference(getString(preferenceResource)).setOnPreferenceClickListener {
val fragment = func()
fragmentManager.beginTransaction() fragmentManager.beginTransaction()
.replace(R.id.settings_content, fragment) .replace(R.id.settings_content, fragment)
.addToBackStack(fragment.javaClass.simpleName) .addToBackStack(fragment.javaClass.simpleName)

View file

@ -1,7 +1,7 @@
package eu.kanade.tachiyomi.ui.setting package eu.kanade.tachiyomi.ui.setting
import android.os.Bundle import android.os.Bundle
import android.preference.Preference import android.support.v7.preference.Preference
import android.view.View import android.view.View
import com.afollestad.materialdialogs.MaterialDialog import com.afollestad.materialdialogs.MaterialDialog
import eu.kanade.tachiyomi.R import eu.kanade.tachiyomi.R

View file

@ -1,11 +1,15 @@
package eu.kanade.tachiyomi.ui.setting package eu.kanade.tachiyomi.ui.setting
import android.os.Bundle import android.os.Bundle
import android.support.v7.preference.Preference
import android.view.View import android.view.View
import eu.kanade.tachiyomi.R import eu.kanade.tachiyomi.R
import eu.kanade.tachiyomi.data.library.LibraryUpdateAlarm import eu.kanade.tachiyomi.data.library.LibraryUpdateAlarm
import eu.kanade.tachiyomi.widget.preference.IntListPreference import eu.kanade.tachiyomi.widget.preference.IntListPreference
import eu.kanade.tachiyomi.widget.preference.LibraryColumnsDialog import eu.kanade.tachiyomi.widget.preference.LibraryColumnsDialog
import eu.kanade.tachiyomi.widget.preference.SimpleDialogPreference
import rx.Observable
import rx.Subscription
class SettingsGeneralFragment : SettingsNestedFragment() { class SettingsGeneralFragment : SettingsNestedFragment() {
@ -17,19 +21,56 @@ class SettingsGeneralFragment : SettingsNestedFragment() {
} }
} }
val columnsPreference by lazy {
findPreference(getString(R.string.pref_library_columns_dialog_key)) as SimpleDialogPreference
}
val updateInterval by lazy {
findPreference(getString(R.string.pref_library_update_interval_key)) as IntListPreference
}
var columnsSubscription: Subscription? = null
override fun onViewCreated(view: View, savedInstanceState: Bundle?) { override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
val columnsDialog = findPreference(
getString(R.string.pref_library_columns_dialog_key)) as LibraryColumnsDialog
columnsDialog.setPreferencesHelper(preferences)
val updateInterval = findPreference(
getString(R.string.pref_library_update_interval_key)) as IntListPreference
updateInterval.setOnPreferenceChangeListener { preference, newValue -> updateInterval.setOnPreferenceChangeListener { preference, newValue ->
LibraryUpdateAlarm.startAlarm(activity, (newValue as String).toInt()) LibraryUpdateAlarm.startAlarm(activity, (newValue as String).toInt())
true true
} }
} }
override fun onResume() {
super.onResume()
columnsSubscription = Observable.combineLatest(preferences.portraitColumns().asObservable(),
preferences.landscapeColumns().asObservable(),
{ portraitColumns, landscapeColumns -> Pair(portraitColumns, landscapeColumns) })
.subscribe { updateColumnsSummary(it.first, it.second) }
}
override fun onPause() {
columnsSubscription?.unsubscribe()
super.onPause()
}
override fun onDisplayPreferenceDialog(preference: Preference) {
if (preference === columnsPreference) {
val fragment = LibraryColumnsDialog.newInstance(preference)
fragment.setTargetFragment(this, 0)
fragment.show(childFragmentManager, null)
} else {
super.onDisplayPreferenceDialog(preference)
}
}
private fun updateColumnsSummary(portraitColumns: Int, landscapeColumns: Int) {
val portrait = getColumnValue(portraitColumns)
val landscape = getColumnValue(landscapeColumns)
val msg = "${getString(R.string.portrait)}: $portrait, ${getString(R.string.landscape)}: $landscape"
columnsPreference.summary = msg
}
private fun getColumnValue(value: Int): String {
return if (value == 0) getString(R.string.default_columns) else value.toString()
}
} }

View file

@ -1,10 +1,10 @@
package eu.kanade.tachiyomi.ui.setting package eu.kanade.tachiyomi.ui.setting
import android.os.Bundle import android.os.Bundle
import android.preference.PreferenceFragment import android.support.v7.preference.PreferenceFragmentCompat
import eu.kanade.tachiyomi.data.preference.PreferencesHelper import eu.kanade.tachiyomi.data.preference.PreferencesHelper
open class SettingsNestedFragment : PreferenceFragment() { open class SettingsNestedFragment : PreferenceFragmentCompat() {
companion object { companion object {
@ -19,8 +19,7 @@ open class SettingsNestedFragment : PreferenceFragment() {
} }
override fun onCreate(savedState: Bundle?) { override fun onCreatePreferences(savedState: Bundle?, s: String?) {
super.onCreate(savedState)
addPreferencesFromResource(arguments.getInt(RESOURCE_FILE)) addPreferencesFromResource(arguments.getInt(RESOURCE_FILE))
} }

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

@ -1,14 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
<item name="colorPrimary">@color/colorPrimary</item>
<item name="colorPrimaryDark">@color/colorPrimaryDark</item>
<item name="colorAccent">@color/colorAccent</item>
<item name="alertDialogTheme">@style/AlertDialogStyle</item>
<item name="android:textColor">@color/primary_text</item>
<item name="windowActionModeOverlay">true</item>
<item name="android:navigationBarColor">@color/colorPrimaryDark</item>
</style>
</resources>

View file

@ -1,4 +1,4 @@
<resources> <resources xmlns:tools="http://schemas.android.com/tools">
<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar"> <style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
<item name="colorPrimary">@color/colorPrimary</item> <item name="colorPrimary">@color/colorPrimary</item>
@ -7,6 +7,8 @@
<item name="alertDialogTheme">@style/AlertDialogStyle</item> <item name="alertDialogTheme">@style/AlertDialogStyle</item>
<item name="android:textColor">@color/primary_text</item> <item name="android:textColor">@color/primary_text</item>
<item name="windowActionModeOverlay">true</item> <item name="windowActionModeOverlay">true</item>
<item name="android:navigationBarColor" tools:targetApi="lollipop">@color/colorPrimaryDark</item>
<item name="preferenceTheme">@style/PreferenceThemeOverlay.v14.Material</item>
</style> </style>
<style name="AppTheme.ActionBar" parent="ThemeOverlay.AppCompat.Dark.ActionBar"> <style name="AppTheme.ActionBar" parent="ThemeOverlay.AppCompat.Dark.ActionBar">

View file

@ -1,7 +1,8 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android"> <android.support.v7.preference.PreferenceScreen
xmlns:android="http://schemas.android.com/apk/res/android">
<SwitchPreference <SwitchPreferenceCompat
android:key="acra.enable" android:key="acra.enable"
android:title="@string/pref_enable_acra" android:title="@string/pref_enable_acra"
android:summary="@string/pref_acra_summary" android:summary="@string/pref_acra_summary"
@ -17,4 +18,4 @@
android:title="@string/build_time" android:title="@string/build_time"
android:persistent="false" /> android:persistent="false" />
</PreferenceScreen> </android.support.v7.preference.PreferenceScreen>

View file

@ -1,5 +1,16 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android" <android.support.v7.preference.PreferenceScreen
xmlns:android="http://schemas.android.com/apk/res/android"
android:orderingFromXml="true"> android:orderingFromXml="true">
</PreferenceScreen> <PreferenceCategory
android:key="pref_category_source_accounts"
android:title="Sources"
android:persistent="false"/>
<PreferenceCategory
android:key="pref_category_manga_sync_accounts"
android:title="Sync"
android:persistent="false"/>
</android.support.v7.preference.PreferenceScreen>

View file

@ -1,5 +1,6 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android"> <android.support.v7.preference.PreferenceScreen
xmlns:android="http://schemas.android.com/apk/res/android">
<Preference <Preference
android:title="@string/pref_clear_chapter_cache" android:title="@string/pref_clear_chapter_cache"
@ -10,4 +11,4 @@
android:key="@string/pref_clear_database_key" android:key="@string/pref_clear_database_key"
android:summary="@string/pref_clear_database_summary"/> android:summary="@string/pref_clear_database_summary"/>
</PreferenceScreen> </android.support.v7.preference.PreferenceScreen>

View file

@ -1,11 +1,12 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android"> <android.support.v7.preference.PreferenceScreen
xmlns:android="http://schemas.android.com/apk/res/android">
<Preference <Preference
android:title="@string/pref_download_directory" android:title="@string/pref_download_directory"
android:key="@string/pref_download_directory_key"/> android:key="@string/pref_download_directory_key"/>
<SwitchPreference <SwitchPreferenceCompat
android:title="@string/pref_download_only_over_wifi" android:title="@string/pref_download_only_over_wifi"
android:key="@string/pref_download_only_over_wifi_key" android:key="@string/pref_download_only_over_wifi_key"
android:defaultValue="true"/> android:defaultValue="true"/>
@ -18,4 +19,4 @@
android:defaultValue="1" android:defaultValue="1"
android:summary="%s"/> android:summary="%s"/>
</PreferenceScreen> </android.support.v7.preference.PreferenceScreen>

View file

@ -1,10 +1,12 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android"> <android.support.v7.preference.PreferenceScreen
xmlns:android="http://schemas.android.com/apk/res/android">
<eu.kanade.tachiyomi.widget.preference.LibraryColumnsDialog <eu.kanade.tachiyomi.widget.preference.SimpleDialogPreference
android:key="@string/pref_library_columns_dialog_key" android:key="@string/pref_library_columns_dialog_key"
android:persistent="false" android:persistent="false"
android:title="@string/pref_library_columns"/> android:title="@string/pref_library_columns"
android:dialogLayout="@layout/pref_library_columns"/>
<eu.kanade.tachiyomi.widget.preference.IntListPreference <eu.kanade.tachiyomi.widget.preference.IntListPreference
android:key="@string/pref_library_update_interval_key" android:key="@string/pref_library_update_interval_key"
@ -14,20 +16,20 @@
android:defaultValue="0" android:defaultValue="0"
android:summary="%s"/> android:summary="%s"/>
<SwitchPreference <SwitchPreferenceCompat
android:key="@string/pref_update_only_non_completed_key" android:key="@string/pref_update_only_non_completed_key"
android:title="@string/pref_update_only_non_completed" android:title="@string/pref_update_only_non_completed"
android:defaultValue="false"/> android:defaultValue="false"/>
<SwitchPreference <SwitchPreferenceCompat
android:key="@string/pref_auto_update_manga_sync_key" android:key="@string/pref_auto_update_manga_sync_key"
android:title="@string/pref_auto_update_manga_sync" android:title="@string/pref_auto_update_manga_sync"
android:defaultValue="true"/> android:defaultValue="true"/>
<SwitchPreference <SwitchPreferenceCompat
android:key="@string/pref_ask_update_manga_sync_key" android:key="@string/pref_ask_update_manga_sync_key"
android:title="@string/pref_ask_update_manga_sync" android:title="@string/pref_ask_update_manga_sync"
android:defaultValue="false" android:defaultValue="false"
android:dependency="@string/pref_auto_update_manga_sync_key"/> android:dependency="@string/pref_auto_update_manga_sync_key"/>
</PreferenceScreen> </android.support.v7.preference.PreferenceScreen>

View file

@ -1,5 +1,6 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android" > <android.support.v7.preference.PreferenceScreen
xmlns:android="http://schemas.android.com/apk/res/android" >
<Preference <Preference
android:key="@string/pref_category_general_key" android:key="@string/pref_category_general_key"
@ -31,4 +32,4 @@
android:persistent="false" android:persistent="false"
android:title="@string/pref_category_about" /> android:title="@string/pref_category_about" />
</PreferenceScreen> </android.support.v7.preference.PreferenceScreen>

View file

@ -1,27 +1,28 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android"> <android.support.v7.preference.PreferenceScreen
xmlns:android="http://schemas.android.com/apk/res/android">
<SwitchPreference android:title="@string/pref_hide_status_bar" <SwitchPreferenceCompat android:title="@string/pref_hide_status_bar"
android:key="@string/pref_hide_status_bar_key" android:key="@string/pref_hide_status_bar_key"
android:defaultValue="true" /> android:defaultValue="true" />
<SwitchPreference android:title="@string/pref_enable_transitions" <SwitchPreferenceCompat android:title="@string/pref_enable_transitions"
android:key="@string/pref_enable_transitions_key" android:key="@string/pref_enable_transitions_key"
android:defaultValue="true" /> android:defaultValue="true" />
<SwitchPreference android:title="@string/pref_show_page_number" <SwitchPreferenceCompat android:title="@string/pref_show_page_number"
android:key="@string/pref_show_page_number_key" android:key="@string/pref_show_page_number_key"
android:defaultValue="true" /> android:defaultValue="true" />
<SwitchPreference android:title="@string/pref_custom_brightness" <SwitchPreferenceCompat android:title="@string/pref_custom_brightness"
android:key="@string/pref_custom_brightness_key" android:key="@string/pref_custom_brightness_key"
android:defaultValue="false" /> android:defaultValue="false" />
<SwitchPreference android:title="@string/pref_keep_screen_on" <SwitchPreferenceCompat android:title="@string/pref_keep_screen_on"
android:key="@string/pref_keep_screen_on_key" android:key="@string/pref_keep_screen_on_key"
android:defaultValue="true" /> android:defaultValue="true" />
<SwitchPreference android:title="@string/pref_seamless_mode" <SwitchPreferenceCompat android:title="@string/pref_seamless_mode"
android:key="@string/pref_seamless_mode_key" android:key="@string/pref_seamless_mode_key"
android:defaultValue="true" /> android:defaultValue="true" />
@ -73,4 +74,4 @@
android:defaultValue="0" android:defaultValue="0"
android:summary="%s" /> android:summary="%s" />
</PreferenceScreen> </android.support.v7.preference.PreferenceScreen>