Commit 61284c15 authored by Yusuke Iwaki's avatar Yusuke Iwaki

fix RETRY button

parent 1994e656
...@@ -201,8 +201,7 @@ public class MainActivity extends AbstractAuthedActivity { ...@@ -201,8 +201,7 @@ public class MainActivity extends AbstractAuthedActivity {
Snackbar.make(findViewById(getLayoutContainerForFragment()), Snackbar.make(findViewById(getLayoutContainerForFragment()),
R.string.fragment_retry_login_error_title, Snackbar.LENGTH_INDEFINITE) R.string.fragment_retry_login_error_title, Snackbar.LENGTH_INDEFINITE)
.setAction(R.string.fragment_retry_login_retry_title, view -> .setAction(R.string.fragment_retry_login_retry_title, view ->
ConnectivityManager.getInstance(getApplicationContext()) Session.retryLogin(RealmStore.get(hostname))));
.connect(hostname).subscribe()));
} else if (!session.isTokenVerified()) { } else if (!session.isTokenVerified()) {
statusTicker.updateStatus(StatusTicker.STATUS_TOKEN_LOGIN, statusTicker.updateStatus(StatusTicker.STATUS_TOKEN_LOGIN,
Snackbar.make(findViewById(getLayoutContainerForFragment()), Snackbar.make(findViewById(getLayoutContainerForFragment()),
......
...@@ -55,6 +55,24 @@ public class Session extends RealmObject { ...@@ -55,6 +55,24 @@ public class Session extends RealmObject {
} }
} }
/**
* retry authentication.
*/
@DebugLog
public static void retryLogin(RealmHelper realmHelper) {
final Session session = realmHelper.executeTransactionForRead(realm ->
queryDefaultSession(realm).isNotNull(TOKEN).findFirst());
if (!session.isTokenVerified() || !TextUtils.isEmpty(session.getError())) {
realmHelper.executeTransaction(
realm -> realm.createOrUpdateObjectFromJson(Session.class, new JSONObject()
.put(ID, Session.DEFAULT_ID)
.put(TOKEN_VERIFIED, false)
.put(ERROR, JSONObject.NULL)))
.continueWith(new LogcatIfError());
}
}
public int getSessionId() { public int getSessionId() {
return sessionId; return sessionId;
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment