diff --git a/app/build.gradle b/app/build.gradle
index 2f6ce5b934..e48ff9f2a0 100644
--- a/app/build.gradle
+++ b/app/build.gradle
@@ -87,6 +87,7 @@ dependencies {
compile 'com.davemorrissey.labs:subsampling-scale-image-view:3.4.1'
compile "frankiesardo:icepick:$ICEPICK_VERSION"
provided "frankiesardo:icepick-processor:$ICEPICK_VERSION"
+ compile 'com.github.dmytrodanylyk.android-process-button:library:1.0.4'
compile "com.google.dagger:dagger:$DAGGER_VERSION"
apt "com.google.dagger:dagger-compiler:$DAGGER_VERSION"
diff --git a/app/src/main/java/eu/kanade/mangafeed/ui/dialog/LoginDialogPreference.java b/app/src/main/java/eu/kanade/mangafeed/ui/dialog/LoginDialogPreference.java
new file mode 100644
index 0000000000..507bd4d17b
--- /dev/null
+++ b/app/src/main/java/eu/kanade/mangafeed/ui/dialog/LoginDialogPreference.java
@@ -0,0 +1,127 @@
+package eu.kanade.mangafeed.ui.dialog;
+
+import android.app.AlertDialog;
+import android.content.Context;
+import android.content.DialogInterface;
+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.mangafeed.R;
+import eu.kanade.mangafeed.data.helpers.PreferencesHelper;
+import eu.kanade.mangafeed.sources.base.Source;
+import rx.Subscription;
+import rx.android.schedulers.AndroidSchedulers;
+import rx.schedulers.Schedulers;
+
+public 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;
+
+ private PreferencesHelper preferences;
+ private Source source;
+ private AlertDialog dialog;
+ private Subscription requestSubscription;
+
+ public LoginDialogPreference(Context context, PreferencesHelper preferences, Source source) {
+ super(context, null);
+ this.preferences = preferences;
+ this.source = source;
+
+ setDialogLayoutResource(R.layout.pref_account_login);
+ }
+
+ @Override
+ protected void onBindDialogView(View view) {
+ ButterKnife.bind(this, view);
+
+ title.setText(getContext().getString(R.string.accounts_login_title, source.getName()));
+
+ username.setText(preferences.getSourceUsername(source));
+ password.setText(preferences.getSourcePassword(source));
+ showPassword.setOnCheckedChangeListener((buttonView, isChecked) -> {
+ if (isChecked)
+ password.setTransformationMethod(null);
+ else
+ password.setTransformationMethod(new PasswordTransformationMethod());
+ });
+
+ loginBtn.setMode(ActionProcessButton.Mode.ENDLESS);
+ loginBtn.setOnClickListener(v -> checkLogin());
+
+ super.onBindDialogView(view);
+ }
+
+ @Override
+ public void showDialog(Bundle state) {
+ super.showDialog(state);
+ dialog = ((AlertDialog) getDialog());
+ setSubmitButtonEnabled(false);
+ }
+
+ @Override
+ protected void onDialogClosed(boolean positiveResult) {
+ if (requestSubscription != null)
+ requestSubscription.unsubscribe();
+
+ if(!positiveResult)
+ return;
+
+ preferences.setSourceCredentials(source,
+ username.getText().toString(),
+ password.getText().toString());
+
+ super.onDialogClosed(true);
+ }
+
+ private void setSubmitButtonEnabled(boolean enabled) {
+ if (dialog != null) {
+ dialog.getButton(DialogInterface.BUTTON_POSITIVE)
+ .setEnabled(enabled);
+ }
+ }
+
+ private void checkLogin() {
+ if (requestSubscription != null)
+ requestSubscription.unsubscribe();
+
+ loginBtn.setProgress(1);
+
+ requestSubscription = source.login(username.getText().toString(),
+ password.getText().toString())
+ .subscribeOn(Schedulers.io())
+ .observeOn(AndroidSchedulers.mainThread())
+ .subscribe(logged -> {
+ if (logged) {
+ loginBtn.setProgress(100);
+ loginBtn.setEnabled(false);
+ username.setEnabled(false);
+ password.setEnabled(false);
+ setSubmitButtonEnabled(true);
+ } else {
+ loginBtn.setProgress(-1);
+ }
+ }, throwable -> {
+ loginBtn.setProgress(-1);
+ loginBtn.setText("Unknown error");
+ });
+
+ }
+
+}
diff --git a/app/src/main/java/eu/kanade/mangafeed/ui/fragment/SettingsAccountsFragment.java b/app/src/main/java/eu/kanade/mangafeed/ui/fragment/SettingsAccountsFragment.java
index 80789207b7..0b96c20526 100644
--- a/app/src/main/java/eu/kanade/mangafeed/ui/fragment/SettingsAccountsFragment.java
+++ b/app/src/main/java/eu/kanade/mangafeed/ui/fragment/SettingsAccountsFragment.java
@@ -1,33 +1,21 @@
package eu.kanade.mangafeed.ui.fragment;
-import android.content.Context;
import android.os.Bundle;
-import android.preference.DialogPreference;
import android.preference.PreferenceFragment;
import android.preference.PreferenceScreen;
-import android.text.method.PasswordTransformationMethod;
-import android.util.AttributeSet;
-import android.view.View;
-import android.widget.CheckBox;
-import android.widget.EditText;
-import android.widget.TextView;
import java.util.List;
import javax.inject.Inject;
-import butterknife.Bind;
-import butterknife.ButterKnife;
import eu.kanade.mangafeed.App;
import eu.kanade.mangafeed.R;
import eu.kanade.mangafeed.data.helpers.PreferencesHelper;
import eu.kanade.mangafeed.data.helpers.SourceManager;
import eu.kanade.mangafeed.sources.base.Source;
import eu.kanade.mangafeed.ui.activity.base.BaseActivity;
+import eu.kanade.mangafeed.ui.dialog.LoginDialogPreference;
import rx.Observable;
-import rx.android.schedulers.AndroidSchedulers;
-import rx.schedulers.Schedulers;
-import timber.log.Timber;
public class SettingsAccountsFragment extends PreferenceFragment {
@@ -50,7 +38,7 @@ public class SettingsAccountsFragment extends PreferenceFragment {
for (Source source : sourceAccounts) {
LoginDialogPreference dialog = new LoginDialogPreference(
- screen.getContext(), null, source);
+ screen.getContext(), preferences, source);
dialog.setTitle(source.getName());
screen.addPreference(dialog);
@@ -72,60 +60,4 @@ public class SettingsAccountsFragment extends PreferenceFragment {
.single();
}
- public 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;
-
- private Source source;
-
- public LoginDialogPreference(Context context, AttributeSet attrs, Source source) {
- super(context, attrs);
- this.source = source;
-
- setDialogLayoutResource(R.layout.pref_account_login);
- }
-
- @Override
- protected void onBindDialogView(View view) {
- ButterKnife.bind(this, view);
-
- title.setText(getString(R.string.accounts_login_title, source.getName()));
-
- username.setText(preferences.getSourceUsername(source));
- password.setText(preferences.getSourcePassword(source));
- showPassword.setOnCheckedChangeListener((buttonView, isChecked) -> {
- if (isChecked)
- password.setTransformationMethod(null);
- else
- password.setTransformationMethod(new PasswordTransformationMethod());
- });
-
- super.onBindDialogView(view);
- }
-
- @Override
- protected void onDialogClosed(boolean positiveResult) {
- if(!positiveResult)
- return;
-
- preferences.setSourceCredentials(source,
- username.getText().toString(),
- password.getText().toString());
-
- source.login(username.getText().toString(), password.getText().toString())
- .subscribeOn(Schedulers.io())
- .observeOn(AndroidSchedulers.mainThread())
- .subscribe(result -> {
- Timber.e("Result is " + result);
- });
-
-
- super.onDialogClosed(true);
- }
-
- }
-
}
diff --git a/app/src/main/res/layout/pref_account_login.xml b/app/src/main/res/layout/pref_account_login.xml
index 6dc7f8a70a..db4677483e 100644
--- a/app/src/main/res/layout/pref_account_login.xml
+++ b/app/src/main/res/layout/pref_account_login.xml
@@ -1,6 +1,8 @@
@@ -50,12 +52,15 @@
android:id="@+id/show_password"
android:layout_marginTop="10dp"/>
-
-
-
+ android:textColor="@android:color/white"
+ android:text="@string/login"
+ android:id="@+id/login"
+ app:pb_textComplete="@string/success"
+ app:pb_textProgress="@string/loading"
+ app:pb_textError="@string/invalid_login"
+ android:layout_marginTop="20dp"/>
\ No newline at end of file
diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml
index 331241d268..48848ff9db 100644
--- a/app/src/main/res/values/strings.xml
+++ b/app/src/main/res/values/strings.xml
@@ -67,5 +67,9 @@
Password
Show password
Check credentials
+ Login
+ Success
+ Login error
+ Loading…