Rename project
This commit is contained in:
@@ -0,0 +1,35 @@
|
||||
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,80 @@
|
||||
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,78 @@
|
||||
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,74 @@
|
||||
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,74 @@
|
||||
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);
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user