Fix login activity crashes, repeated re-authentications,
layout when keyboard appears
This commit is contained in:
parent
71162dd650
commit
3798f9a803
5 changed files with 60 additions and 53 deletions
|
@ -22,7 +22,6 @@ import android.graphics.Color;
|
|||
import android.graphics.PorterDuff;
|
||||
import android.graphics.drawable.Drawable;
|
||||
import android.os.Bundle;
|
||||
import android.preference.PreferenceManager;
|
||||
import android.support.annotation.Nullable;
|
||||
import android.support.v7.app.AppCompatActivity;
|
||||
import android.text.Spanned;
|
||||
|
@ -68,7 +67,7 @@ public class BaseActivity extends AppCompatActivity {
|
|||
|
||||
@Override
|
||||
protected void onDestroy() {
|
||||
mastodonApiDispatcher.cancelAll();
|
||||
if(mastodonApiDispatcher != null) mastodonApiDispatcher.cancelAll();
|
||||
super.onDestroy();
|
||||
}
|
||||
|
||||
|
|
|
@ -55,6 +55,11 @@ public class LoginActivity extends BaseActivity {
|
|||
@BindView(R.id.button_login) Button button;
|
||||
@BindView(R.id.no_account) TextView noAccount;
|
||||
|
||||
@Override
|
||||
protected void createMastodonAPI() {
|
||||
// Don't do this in this activity, since we don't know a domain yet
|
||||
}
|
||||
|
||||
/**
|
||||
* Chain together the key-value pairs into a query string, for either appending to a URL or
|
||||
* as the content of an HTTP request.
|
||||
|
@ -76,7 +81,7 @@ public class LoginActivity extends BaseActivity {
|
|||
private String validateDomain(String s) {
|
||||
s = s.replaceFirst("http://", "");
|
||||
s = s.replaceFirst("https://", "");
|
||||
return s;
|
||||
return s.trim();
|
||||
}
|
||||
|
||||
private String getOauthRedirectUri() {
|
||||
|
@ -241,6 +246,17 @@ public class LoginActivity extends BaseActivity {
|
|||
Uri uri = getIntent().getData();
|
||||
String redirectUri = getOauthRedirectUri();
|
||||
|
||||
preferences = getSharedPreferences(
|
||||
getString(R.string.preferences_file_key), Context.MODE_PRIVATE);
|
||||
|
||||
if (preferences.getString("accessToken", null) != null && preferences.getString("domain", null) != null) {
|
||||
// We are already logged in, go to MainActivity
|
||||
Intent intent = new Intent(this, MainActivity.class);
|
||||
startActivity(intent);
|
||||
finish();
|
||||
return;
|
||||
}
|
||||
|
||||
if (uri != null && uri.toString().startsWith(redirectUri)) {
|
||||
// This should either have returned an authorization code or an error.
|
||||
String code = uri.getQueryParameter("code");
|
||||
|
@ -250,8 +266,6 @@ public class LoginActivity extends BaseActivity {
|
|||
/* During the redirect roundtrip this Activity usually dies, which wipes out the
|
||||
* instance variables, so they have to be recovered from where they were saved in
|
||||
* SharedPreferences. */
|
||||
preferences = getSharedPreferences(
|
||||
getString(R.string.preferences_file_key), Context.MODE_PRIVATE);
|
||||
domain = preferences.getString("domain", null);
|
||||
clientId = preferences.getString("clientId", null);
|
||||
clientSecret = preferences.getString("clientSecret", null);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue