Fix login activity crashes, repeated re-authentications,
layout when keyboard appears
This commit is contained in:
parent
71162dd650
commit
3798f9a803
|
@ -21,7 +21,9 @@
|
||||||
<category android:name="android.intent.category.LAUNCHER" />
|
<category android:name="android.intent.category.LAUNCHER" />
|
||||||
</intent-filter>
|
</intent-filter>
|
||||||
</activity>
|
</activity>
|
||||||
<activity android:name=".LoginActivity">
|
<activity
|
||||||
|
android:name=".LoginActivity"
|
||||||
|
android:windowSoftInputMode="adjustResize">
|
||||||
<intent-filter>
|
<intent-filter>
|
||||||
<action android:name="android.intent.action.VIEW" />
|
<action android:name="android.intent.action.VIEW" />
|
||||||
|
|
||||||
|
|
|
@ -22,7 +22,6 @@ import android.graphics.Color;
|
||||||
import android.graphics.PorterDuff;
|
import android.graphics.PorterDuff;
|
||||||
import android.graphics.drawable.Drawable;
|
import android.graphics.drawable.Drawable;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.preference.PreferenceManager;
|
|
||||||
import android.support.annotation.Nullable;
|
import android.support.annotation.Nullable;
|
||||||
import android.support.v7.app.AppCompatActivity;
|
import android.support.v7.app.AppCompatActivity;
|
||||||
import android.text.Spanned;
|
import android.text.Spanned;
|
||||||
|
@ -68,7 +67,7 @@ public class BaseActivity extends AppCompatActivity {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onDestroy() {
|
protected void onDestroy() {
|
||||||
mastodonApiDispatcher.cancelAll();
|
if(mastodonApiDispatcher != null) mastodonApiDispatcher.cancelAll();
|
||||||
super.onDestroy();
|
super.onDestroy();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -55,6 +55,11 @@ public class LoginActivity extends BaseActivity {
|
||||||
@BindView(R.id.button_login) Button button;
|
@BindView(R.id.button_login) Button button;
|
||||||
@BindView(R.id.no_account) TextView noAccount;
|
@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
|
* Chain together the key-value pairs into a query string, for either appending to a URL or
|
||||||
* as the content of an HTTP request.
|
* as the content of an HTTP request.
|
||||||
|
@ -76,7 +81,7 @@ public class LoginActivity extends BaseActivity {
|
||||||
private String validateDomain(String s) {
|
private String validateDomain(String s) {
|
||||||
s = s.replaceFirst("http://", "");
|
s = s.replaceFirst("http://", "");
|
||||||
s = s.replaceFirst("https://", "");
|
s = s.replaceFirst("https://", "");
|
||||||
return s;
|
return s.trim();
|
||||||
}
|
}
|
||||||
|
|
||||||
private String getOauthRedirectUri() {
|
private String getOauthRedirectUri() {
|
||||||
|
@ -241,6 +246,17 @@ public class LoginActivity extends BaseActivity {
|
||||||
Uri uri = getIntent().getData();
|
Uri uri = getIntent().getData();
|
||||||
String redirectUri = getOauthRedirectUri();
|
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)) {
|
if (uri != null && uri.toString().startsWith(redirectUri)) {
|
||||||
// This should either have returned an authorization code or an error.
|
// This should either have returned an authorization code or an error.
|
||||||
String code = uri.getQueryParameter("code");
|
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
|
/* 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
|
* instance variables, so they have to be recovered from where they were saved in
|
||||||
* SharedPreferences. */
|
* SharedPreferences. */
|
||||||
preferences = getSharedPreferences(
|
|
||||||
getString(R.string.preferences_file_key), Context.MODE_PRIVATE);
|
|
||||||
domain = preferences.getString("domain", null);
|
domain = preferences.getString("domain", null);
|
||||||
clientId = preferences.getString("clientId", null);
|
clientId = preferences.getString("clientId", null);
|
||||||
clientSecret = preferences.getString("clientSecret", null);
|
clientSecret = preferences.getString("clientSecret", null);
|
||||||
|
|
Binary file not shown.
Before Width: | Height: | Size: 25 KiB After Width: | Height: | Size: 24 KiB |
|
@ -1,63 +1,55 @@
|
||||||
<?xml version="1.0" encoding="utf-8"?>
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
<android.support.design.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
xmlns:tools="http://schemas.android.com/tools"
|
xmlns:tools="http://schemas.android.com/tools"
|
||||||
android:orientation="vertical"
|
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="match_parent"
|
android:layout_height="match_parent"
|
||||||
android:padding="16dp"
|
android:fillViewport="true"
|
||||||
tools:context="com.keylesspalace.tusky.LoginActivity">
|
tools:context="com.keylesspalace.tusky.LoginActivity">
|
||||||
|
|
||||||
<RelativeLayout
|
<LinearLayout
|
||||||
|
android:orientation="vertical"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="match_parent">
|
android:padding="16dp"
|
||||||
|
android:gravity="center"
|
||||||
|
android:layout_height="wrap_content">
|
||||||
|
|
||||||
<LinearLayout
|
<ImageView
|
||||||
android:orientation="vertical"
|
|
||||||
android:layout_width="wrap_content"
|
android:layout_width="wrap_content"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:layout_centerInParent="true"
|
android:layout_marginBottom="50dp"
|
||||||
android:gravity="center">
|
android:src="@drawable/elephant_friend"/>
|
||||||
|
|
||||||
<ImageView
|
<android.support.design.widget.TextInputLayout
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_width="250dp">
|
||||||
|
<EditText
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:src="@drawable/elephant_friend"/>
|
android:inputType="textUri"
|
||||||
|
android:hint="@string/hint_domain"
|
||||||
|
android:ems="10"
|
||||||
|
android:id="@+id/edit_text_domain" />
|
||||||
|
</android.support.design.widget.TextInputLayout>
|
||||||
|
|
||||||
<android.support.design.widget.TextInputLayout
|
<Button
|
||||||
android:layout_height="match_parent"
|
android:id="@+id/button_login"
|
||||||
android:layout_width="wrap_content">
|
android:layout_width="250dp"
|
||||||
<EditText
|
android:layout_height="wrap_content"
|
||||||
android:layout_width="match_parent"
|
android:layout_marginTop="4dp"
|
||||||
android:layout_height="wrap_content"
|
android:elevation="0dp"
|
||||||
android:inputType="textUri"
|
android:text="@string/action_login" />
|
||||||
android:hint="@string/hint_domain"
|
|
||||||
android:ems="10"
|
|
||||||
android:id="@+id/edit_text_domain" />
|
|
||||||
</android.support.design.widget.TextInputLayout>
|
|
||||||
|
|
||||||
<Button
|
<TextView
|
||||||
android:id="@+id/button_login"
|
android:layout_width="250dp"
|
||||||
android:layout_width="match_parent"
|
android:layout_height="wrap_content"
|
||||||
android:layout_height="wrap_content"
|
android:visibility="gone"
|
||||||
android:layout_marginTop="4dp"
|
android:id="@+id/text_error" />
|
||||||
android:elevation="0dp"
|
|
||||||
android:text="@string/action_login" />
|
|
||||||
|
|
||||||
<TextView
|
<TextView
|
||||||
android:layout_width="match_parent"
|
android:layout_width="250dp"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:visibility="gone"
|
android:textAlignment="center"
|
||||||
android:id="@+id/text_error" />
|
android:id="@+id/no_account"
|
||||||
|
android:text="@string/link_no_account" />
|
||||||
<TextView
|
</LinearLayout>
|
||||||
android:layout_width="match_parent"
|
</ScrollView>
|
||||||
android:layout_height="wrap_content"
|
|
||||||
android:textAlignment="center"
|
|
||||||
android:id="@+id/no_account"
|
|
||||||
android:text="@string/link_no_account" />
|
|
||||||
|
|
||||||
</LinearLayout>
|
|
||||||
|
|
||||||
</RelativeLayout>
|
|
||||||
|
|
||||||
</android.support.design.widget.CoordinatorLayout>
|
|
Loading…
Reference in New Issue