Merge branch 'Pangoraw-master'

This commit is contained in:
Vavassor 2017-05-08 15:45:44 -04:00
commit 6f038cc23b
4 changed files with 77 additions and 27 deletions

View File

@ -32,6 +32,7 @@ import android.text.method.LinkMovementMethod;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.LinearLayout;
import android.widget.TextView;
import com.keylesspalace.tusky.entity.AccessToken;
@ -62,6 +63,9 @@ public class LoginActivity extends AppCompatActivity {
private String clientId;
private String clientSecret;
@BindView(R.id.login_input) LinearLayout input;
@BindView(R.id.login_loading) LinearLayout loading;
@BindView(R.id.edit_text_domain) EditText editText;
@BindView(R.id.button_login) Button button;
@BindView(R.id.whats_an_instance) TextView whatsAnInstance;
@ -326,6 +330,8 @@ public class LoginActivity extends AppCompatActivity {
domain = preferences.getString("domain", null);
clientId = preferences.getString("clientId", null);
clientSecret = preferences.getString("clientSecret", null);
setLoading(true);
/* Since authorization has succeeded, the final step to log in is to exchange
* the authorization code for an access token. */
Callback<AccessToken> callback = new Callback<AccessToken>() {
@ -334,6 +340,8 @@ public class LoginActivity extends AppCompatActivity {
if (response.isSuccessful()) {
onLoginSuccess(response.body().accessToken);
} else {
setLoading(false);
editText.setError(getString(R.string.error_retrieving_oauth_token));
Log.e(TAG, String.format("%s %s",
getString(R.string.error_retrieving_oauth_token),
@ -343,6 +351,7 @@ public class LoginActivity extends AppCompatActivity {
@Override
public void onFailure(Call<AccessToken> call, Throwable t) {
setLoading(false);
editText.setError(getString(R.string.error_retrieving_oauth_token));
Log.e(TAG, String.format("%s %s",
getString(R.string.error_retrieving_oauth_token),
@ -355,21 +364,34 @@ public class LoginActivity extends AppCompatActivity {
} else if (error != null) {
/* Authorization failed. Put the error response where the user can read it and they
* can try again. */
setLoading(false);
editText.setError(getString(R.string.error_authorization_denied));
Log.e(TAG, getString(R.string.error_authorization_denied) + error);
} else {
setLoading(false);
// This case means a junk response was received somehow.
editText.setError(getString(R.string.error_authorization_unknown));
}
}
}
private void setLoading(boolean loadingState) {
if (loadingState) {
loading.setVisibility(View.VISIBLE);
input.setVisibility(View.GONE);
} else {
loading.setVisibility(View.GONE);
input.setVisibility(View.VISIBLE);
}
}
private void onLoginSuccess(String accessToken) {
boolean committed = preferences.edit()
.putString("domain", domain)
.putString("accessToken", accessToken)
.commit();
if (!committed) {
setLoading(false);
editText.setError(getString(R.string.error_retrieving_oauth_token));
return;
}

View File

@ -20,39 +20,63 @@
android:src="@drawable/elephant_friend"
android:contentDescription="@null" />
<android.support.design.widget.TextInputLayout
<LinearLayout
android:id="@+id/login_input"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_width="250dp">
<android.support.design.widget.TextInputEditText
android:layout_width="match_parent"
android:orientation="vertical">
<android.support.design.widget.TextInputLayout
android:layout_height="wrap_content"
android:inputType="textUri"
android:hint="@string/hint_domain"
android:ems="10"
android:id="@+id/edit_text_domain" />
</android.support.design.widget.TextInputLayout>
android:layout_width="250dp">
<android.support.design.widget.TextInputEditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:inputType="textUri"
android:hint="@string/hint_domain"
android:ems="10"
android:id="@+id/edit_text_domain" />
</android.support.design.widget.TextInputLayout>
<Button
android:id="@+id/button_login"
android:layout_width="250dp"
android:layout_height="wrap_content"
android:layout_marginTop="4dp"
android:textColor="@android:color/white"
android:text="@string/action_login" />
<Button
android:id="@+id/button_login"
android:layout_width="250dp"
android:layout_height="wrap_content"
android:layout_marginTop="4dp"
android:textColor="@android:color/white"
android:text="@string/action_login" />
<TextView
android:layout_width="250dp"
android:layout_height="wrap_content"
<TextView
android:layout_width="250dp"
android:layout_height="wrap_content"
android:visibility="gone"
android:id="@+id/text_error" />
<TextView
android:layout_width="250dp"
android:layout_height="wrap_content"
android:paddingTop="5dp"
android:textAlignment="center"
android:id="@+id/whats_an_instance"
android:text="@string/link_whats_an_instance" />
</LinearLayout>
<LinearLayout
android:id="@+id/login_loading"
android:visibility="gone"
android:id="@+id/text_error" />
android:orientation="vertical"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<ProgressBar
android:layout_gravity="center"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<TextView
android:paddingTop="10dp"
android:textAlignment="center"
android:layout_width="250dp"
android:layout_height="wrap_content"
android:text="@string/login_connection"/>
</LinearLayout>
<TextView
android:layout_width="250dp"
android:layout_height="wrap_content"
android:paddingTop="5dp"
android:textAlignment="center"
android:id="@+id/whats_an_instance"
android:text="@string/link_whats_an_instance" />
</LinearLayout>
</ScrollView>

View File

@ -111,6 +111,8 @@
<string name="link_whats_an_instance">Quest-ce quune instance ?</string>
<string name="login_connection">Connexion en cours…</string>
<string name="dialog_whats_an_instance">Indiquer ici ladresse ou le domaine dune instance, comme mastodon.social, icosahedron.website, social.tchncs.de,
<a href="https://github.com/tootsuite/mastodon/blob/master/docs/Using-Mastodon/List-of-Mastodon-instances.md">et bien dautres encore</a> (en anglais) !
\n\nSi vous ne disposez daucun compte, vous pouvez renseigner le nom de linstance que vous souhaitez rejoindre et y créer un compte.\n\nUne instance est lendroit où votre compte est

View File

@ -122,6 +122,8 @@
<string name="link_whats_an_instance">What\'s an instance?</string>
<string name="login_connection">Connecting…</string>
<string name="dialog_whats_an_instance">The address or domain of any instance can be entered
here, such as mastodon.social, icosahedron.website, social.tchncs.de, and
<a href="https://github.com/tootsuite/mastodon/blob/master/docs/Using-Mastodon/List-of-Mastodon-instances.md">more!</a>