Skip to content

Commit

Permalink
Better error handling during auth
Browse files Browse the repository at this point in the history
  • Loading branch information
Alexander-- committed Apr 30, 2017
1 parent c7e6515 commit 0973ed6
Showing 1 changed file with 22 additions and 3 deletions.
25 changes: 22 additions & 3 deletions app/src/main/java/ru/drom/gitgrep/AuthActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@
import android.text.TextUtils;
import android.util.Log;

import com.trello.rxlifecycle.ActivityEvent;
import com.trello.rxlifecycle.RxLifecycle;

import butterknife.ButterKnife;
import butterknife.OnClick;
import ru.drom.gitgrep.server.AuthResults;
Expand All @@ -22,10 +25,13 @@
import ru.drom.gitgrep.util.Utils;
import ru.drom.gitgrep.view.PasswordPromptFragment;
import rx.Observable;
import rx.subjects.PublishSubject;

public final class AuthActivity extends Activity implements PasswordPromptFragment.CredentialsReceiver {
private static final String TAG = "AuthActivity";

private final PublishSubject<ActivityEvent> lifecycle = PublishSubject.create();

private Bundle transport;
private AccountAuthenticatorResponse response;
private Context appContext;
Expand Down Expand Up @@ -84,15 +90,16 @@ protected void onNewIntent(Intent intent) {
Observable.fromCallable(() -> login(code))
.subscribeOn(RxAndroid.bgLooperThread())
.observeOn(RxAndroid.mainThread())
.subscribe(this::returnResult);
.compose(RxLifecycle.bindUntilActivityEvent(lifecycle, ActivityEvent.DESTROY))
.subscribe(this::returnResult, err -> Utils.logError(appContext, err));

return;
}

final String error = uri.getQueryParameter("error");

if (!TextUtils.isEmpty(code)) {
handleGithubAuthError(uri, code);
if (!TextUtils.isEmpty(error)) {
handleGithubAuthError(uri, error);
}
}

Expand All @@ -105,6 +112,11 @@ private void handleGithubAuthError(Uri uri, String errorCode) {
finish();
break;
default:
final String desc = uri.getQueryParameter("error_description");
if (desc != null) {
Log.w(TAG, "Login failed: " + desc);
}

Utils.toast(this, getString(R.string.auth_err_unknown));
}
}
Expand Down Expand Up @@ -207,4 +219,11 @@ public void finish() {
}
super.finish();
}

@Override
protected void onDestroy() {
lifecycle.onNext(ActivityEvent.DESTROY);

super.onDestroy();
}
}

0 comments on commit 0973ed6

Please sign in to comment.