2017-01-20 19:09:10 +11:00
|
|
|
/* Copyright 2017 Andrew Dawson
|
|
|
|
*
|
2017-04-10 10:12:31 +10:00
|
|
|
* This file is a part of Tusky.
|
2017-01-20 19:09:10 +11:00
|
|
|
*
|
2017-04-10 10:12:31 +10:00
|
|
|
* This program is free software; you can redistribute it and/or modify it under the terms of the
|
|
|
|
* GNU General Public License as published by the Free Software Foundation; either version 3 of the
|
|
|
|
* License, or (at your option) any later version.
|
2017-01-20 19:09:10 +11:00
|
|
|
*
|
|
|
|
* Tusky is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even
|
2017-04-10 10:12:31 +10:00
|
|
|
* the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
|
|
|
|
* Public License for more details.
|
2017-01-20 19:09:10 +11:00
|
|
|
*
|
2017-04-10 10:12:31 +10:00
|
|
|
* You should have received a copy of the GNU General Public License along with Tusky; if not,
|
|
|
|
* see <http://www.gnu.org/licenses>. */
|
2017-01-20 19:09:10 +11:00
|
|
|
|
2017-01-03 10:30:27 +11:00
|
|
|
package com.keylesspalace.tusky;
|
|
|
|
|
2017-02-05 15:20:19 +11:00
|
|
|
import android.app.AlertDialog;
|
2017-04-25 21:30:57 +10:00
|
|
|
import android.content.ActivityNotFoundException;
|
2017-01-03 10:30:27 +11:00
|
|
|
import android.content.Context;
|
2017-02-05 15:20:19 +11:00
|
|
|
import android.content.DialogInterface;
|
2017-01-03 10:30:27 +11:00
|
|
|
import android.content.Intent;
|
|
|
|
import android.content.SharedPreferences;
|
|
|
|
import android.net.Uri;
|
|
|
|
import android.os.Bundle;
|
2017-03-29 15:22:14 +11:00
|
|
|
import android.preference.PreferenceManager;
|
2017-04-12 07:07:56 +10:00
|
|
|
import android.support.annotation.NonNull;
|
2017-04-25 21:30:57 +10:00
|
|
|
import android.support.customtabs.CustomTabsIntent;
|
|
|
|
import android.support.v4.content.ContextCompat;
|
2017-03-16 06:27:49 +11:00
|
|
|
import android.support.v7.app.AppCompatActivity;
|
2017-03-16 11:01:23 +11:00
|
|
|
import android.text.method.LinkMovementMethod;
|
2017-01-03 10:30:27 +11:00
|
|
|
import android.view.View;
|
|
|
|
import android.widget.Button;
|
|
|
|
import android.widget.EditText;
|
2017-05-08 20:17:41 +10:00
|
|
|
import android.widget.LinearLayout;
|
2017-01-03 10:30:27 +11:00
|
|
|
import android.widget.TextView;
|
|
|
|
|
2017-03-10 13:55:07 +11:00
|
|
|
import com.keylesspalace.tusky.entity.AccessToken;
|
|
|
|
import com.keylesspalace.tusky.entity.AppCredentials;
|
2017-05-05 08:55:34 +10:00
|
|
|
import com.keylesspalace.tusky.network.MastodonAPI;
|
|
|
|
import com.keylesspalace.tusky.util.CustomTabsHelper;
|
|
|
|
import com.keylesspalace.tusky.util.Log;
|
|
|
|
import com.keylesspalace.tusky.util.OkHttpUtils;
|
2017-01-03 10:30:27 +11:00
|
|
|
|
|
|
|
import java.util.HashMap;
|
|
|
|
import java.util.Map;
|
|
|
|
|
2017-03-14 22:59:52 +11:00
|
|
|
import butterknife.BindView;
|
|
|
|
import butterknife.ButterKnife;
|
2017-03-10 13:55:07 +11:00
|
|
|
import retrofit2.Call;
|
|
|
|
import retrofit2.Callback;
|
|
|
|
import retrofit2.Response;
|
2017-03-14 05:13:49 +11:00
|
|
|
import retrofit2.Retrofit;
|
|
|
|
import retrofit2.converter.gson.GsonConverterFactory;
|
2017-03-10 13:55:07 +11:00
|
|
|
|
2017-03-16 06:27:49 +11:00
|
|
|
public class LoginActivity extends AppCompatActivity {
|
2017-03-14 11:49:12 +11:00
|
|
|
private static final String TAG = "LoginActivity"; // logging tag
|
2017-01-08 09:24:02 +11:00
|
|
|
private static String OAUTH_SCOPES = "read write follow";
|
|
|
|
|
2017-01-03 10:30:27 +11:00
|
|
|
private SharedPreferences preferences;
|
2017-03-14 22:59:52 +11:00
|
|
|
|
2017-01-03 10:30:27 +11:00
|
|
|
private String domain;
|
|
|
|
private String clientId;
|
|
|
|
private String clientSecret;
|
2017-03-14 22:59:52 +11:00
|
|
|
|
2017-05-08 20:17:41 +10:00
|
|
|
@BindView(R.id.login_input) LinearLayout input;
|
|
|
|
@BindView(R.id.login_loading) LinearLayout loading;
|
|
|
|
|
2017-03-14 22:59:52 +11:00
|
|
|
@BindView(R.id.edit_text_domain) EditText editText;
|
|
|
|
@BindView(R.id.button_login) Button button;
|
2017-04-03 09:55:41 +10:00
|
|
|
@BindView(R.id.whats_an_instance) TextView whatsAnInstance;
|
2017-01-03 10:30:27 +11:00
|
|
|
|
2017-04-12 07:07:56 +10:00
|
|
|
@Override
|
|
|
|
protected void onCreate(Bundle savedInstanceState) {
|
|
|
|
super.onCreate(savedInstanceState);
|
|
|
|
|
|
|
|
if (PreferenceManager.getDefaultSharedPreferences(this).getBoolean("lightTheme", false)) {
|
|
|
|
setTheme(R.style.AppTheme_Light);
|
2017-01-03 10:30:27 +11:00
|
|
|
}
|
2017-04-12 07:07:56 +10:00
|
|
|
|
|
|
|
setContentView(R.layout.activity_login);
|
|
|
|
ButterKnife.bind(this);
|
|
|
|
|
|
|
|
if (savedInstanceState != null) {
|
|
|
|
domain = savedInstanceState.getString("domain");
|
|
|
|
clientId = savedInstanceState.getString("clientId");
|
|
|
|
clientSecret = savedInstanceState.getString("clientSecret");
|
|
|
|
} else {
|
|
|
|
domain = null;
|
|
|
|
clientId = null;
|
|
|
|
clientSecret = null;
|
|
|
|
}
|
|
|
|
|
|
|
|
preferences = getSharedPreferences(
|
|
|
|
getString(R.string.preferences_file_key), Context.MODE_PRIVATE);
|
|
|
|
|
|
|
|
button.setOnClickListener(new View.OnClickListener() {
|
|
|
|
@Override
|
|
|
|
public void onClick(View v) {
|
|
|
|
onButtonClick(editText);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
final Context context = this;
|
|
|
|
|
|
|
|
whatsAnInstance.setOnClickListener(new View.OnClickListener() {
|
|
|
|
@Override
|
|
|
|
public void onClick(View v) {
|
|
|
|
AlertDialog dialog = new AlertDialog.Builder(context)
|
|
|
|
.setMessage(R.string.dialog_whats_an_instance)
|
|
|
|
.setPositiveButton(R.string.action_close,
|
|
|
|
new DialogInterface.OnClickListener() {
|
|
|
|
@Override
|
|
|
|
public void onClick(DialogInterface dialog, int which) {
|
|
|
|
dialog.dismiss();
|
|
|
|
}
|
|
|
|
})
|
|
|
|
.show();
|
|
|
|
TextView textView = (TextView) dialog.findViewById(android.R.id.message);
|
|
|
|
textView.setMovementMethod(LinkMovementMethod.getInstance());
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
protected void onSaveInstanceState(Bundle outState) {
|
|
|
|
outState.putString("domain", domain);
|
|
|
|
outState.putString("clientId", clientId);
|
|
|
|
outState.putString("clientSecret", clientSecret);
|
|
|
|
super.onSaveInstanceState(outState);
|
2017-01-03 10:30:27 +11:00
|
|
|
}
|
|
|
|
|
|
|
|
/** Make sure the user-entered text is just a fully-qualified domain name. */
|
2017-04-12 07:07:56 +10:00
|
|
|
@NonNull
|
2017-03-20 14:15:36 +11:00
|
|
|
private static String validateDomain(String s) {
|
2017-04-07 11:16:40 +10:00
|
|
|
// Strip any schemes out.
|
2017-01-03 10:30:27 +11:00
|
|
|
s = s.replaceFirst("http://", "");
|
|
|
|
s = s.replaceFirst("https://", "");
|
2017-04-07 11:16:40 +10:00
|
|
|
// If a username was included (e.g. username@example.com), just take what's after the '@'.
|
|
|
|
int at = s.indexOf('@');
|
|
|
|
if (at != -1) {
|
|
|
|
s = s.substring(at + 1);
|
|
|
|
}
|
2017-03-16 06:32:26 +11:00
|
|
|
return s.trim();
|
2017-01-03 10:30:27 +11:00
|
|
|
}
|
|
|
|
|
|
|
|
private String getOauthRedirectUri() {
|
|
|
|
String scheme = getString(R.string.oauth_scheme);
|
|
|
|
String host = getString(R.string.oauth_redirect_host);
|
|
|
|
return scheme + "://" + host + "/";
|
|
|
|
}
|
|
|
|
|
2017-03-14 05:13:49 +11:00
|
|
|
private MastodonAPI getApiFor(String domain) {
|
|
|
|
Retrofit retrofit = new Retrofit.Builder()
|
|
|
|
.baseUrl("https://" + domain)
|
2017-04-10 08:36:55 +10:00
|
|
|
.client(OkHttpUtils.getCompatibleClient())
|
2017-03-14 05:13:49 +11:00
|
|
|
.addConverterFactory(GsonConverterFactory.create())
|
|
|
|
.build();
|
|
|
|
|
|
|
|
return retrofit.create(MastodonAPI.class);
|
|
|
|
}
|
|
|
|
|
2017-01-03 10:30:27 +11:00
|
|
|
/**
|
|
|
|
* Obtain the oauth client credentials for this app. This is only necessary the first time the
|
|
|
|
* app is run on a given server instance. So, after the first authentication, they are
|
|
|
|
* saved in SharedPreferences and every subsequent run they are simply fetched from there.
|
|
|
|
*/
|
|
|
|
private void onButtonClick(final EditText editText) {
|
|
|
|
domain = validateDomain(editText.getText().toString());
|
|
|
|
/* Attempt to get client credentials from SharedPreferences, and if not present
|
|
|
|
* (such as in the case that the domain has never been accessed before)
|
|
|
|
* authenticate with the server and store the received credentials to use next
|
|
|
|
* time. */
|
2017-02-20 11:27:15 +11:00
|
|
|
String prefClientId = preferences.getString(domain + "/client_id", null);
|
|
|
|
String prefClientSecret = preferences.getString(domain + "/client_secret", null);
|
2017-03-14 22:59:52 +11:00
|
|
|
|
2017-02-20 11:27:15 +11:00
|
|
|
if (prefClientId != null && prefClientSecret != null) {
|
|
|
|
clientId = prefClientId;
|
|
|
|
clientSecret = prefClientSecret;
|
2017-04-05 12:29:15 +10:00
|
|
|
redirectUserToAuthorizeAndLogin(editText);
|
2017-01-03 10:30:27 +11:00
|
|
|
} else {
|
2017-03-10 13:55:07 +11:00
|
|
|
Callback<AppCredentials> callback = new Callback<AppCredentials>() {
|
|
|
|
@Override
|
2017-04-12 07:07:56 +10:00
|
|
|
public void onResponse(Call<AppCredentials> call,
|
|
|
|
Response<AppCredentials> response) {
|
2017-03-14 11:49:12 +11:00
|
|
|
if (!response.isSuccessful()) {
|
2017-03-14 22:59:52 +11:00
|
|
|
editText.setError(getString(R.string.error_failed_app_registration));
|
2017-03-14 11:49:12 +11:00
|
|
|
Log.e(TAG, "App authentication failed. " + response.message());
|
|
|
|
return;
|
|
|
|
}
|
2017-03-10 13:55:07 +11:00
|
|
|
AppCredentials credentials = response.body();
|
|
|
|
clientId = credentials.clientId;
|
|
|
|
clientSecret = credentials.clientSecret;
|
2017-04-21 08:56:36 +10:00
|
|
|
preferences.edit()
|
|
|
|
.putString(domain + "/client_id", clientId)
|
|
|
|
.putString(domain + "/client_secret", clientSecret)
|
|
|
|
.apply();
|
2017-04-05 12:29:15 +10:00
|
|
|
redirectUserToAuthorizeAndLogin(editText);
|
2017-03-10 13:55:07 +11:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onFailure(Call<AppCredentials> call, Throwable t) {
|
2017-03-14 22:59:52 +11:00
|
|
|
editText.setError(getString(R.string.error_failed_app_registration));
|
2017-03-10 13:55:07 +11:00
|
|
|
t.printStackTrace();
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2017-03-14 22:59:52 +11:00
|
|
|
try {
|
2017-04-10 08:36:55 +10:00
|
|
|
getApiFor(domain)
|
|
|
|
.authenticateApp(getString(R.string.app_name), getOauthRedirectUri(),
|
|
|
|
OAUTH_SCOPES, getString(R.string.app_website))
|
|
|
|
.enqueue(callback);
|
2017-03-14 22:59:52 +11:00
|
|
|
} catch (IllegalArgumentException e) {
|
|
|
|
editText.setError(getString(R.string.error_invalid_domain));
|
|
|
|
}
|
2017-01-03 10:30:27 +11:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-04-12 07:07:56 +10:00
|
|
|
/**
|
|
|
|
* Chain together the key-value pairs into a query string, for either appending to a URL or
|
|
|
|
* as the content of an HTTP request.
|
|
|
|
*/
|
|
|
|
@NonNull
|
|
|
|
private static String toQueryString(Map<String, String> parameters) {
|
|
|
|
StringBuilder s = new StringBuilder();
|
|
|
|
String between = "";
|
|
|
|
for (Map.Entry<String, String> entry : parameters.entrySet()) {
|
|
|
|
s.append(between);
|
|
|
|
s.append(Uri.encode(entry.getKey()));
|
|
|
|
s.append("=");
|
|
|
|
s.append(Uri.encode(entry.getValue()));
|
|
|
|
between = "&";
|
2017-03-29 15:22:14 +11:00
|
|
|
}
|
2017-04-12 07:07:56 +10:00
|
|
|
return s.toString();
|
|
|
|
}
|
2017-03-29 15:22:14 +11:00
|
|
|
|
2017-04-25 21:30:57 +10:00
|
|
|
private static boolean openInCustomTab(Uri uri, Context context) {
|
|
|
|
boolean lightTheme = PreferenceManager.getDefaultSharedPreferences(context)
|
|
|
|
.getBoolean("lightTheme", false);
|
|
|
|
int toolbarColorRes;
|
|
|
|
if (lightTheme) {
|
|
|
|
toolbarColorRes = R.color.custom_tab_toolbar_light;
|
|
|
|
} else {
|
|
|
|
toolbarColorRes = R.color.custom_tab_toolbar_dark;
|
|
|
|
}
|
|
|
|
int toolbarColor = ContextCompat.getColor(context, toolbarColorRes);
|
|
|
|
CustomTabsIntent.Builder builder = new CustomTabsIntent.Builder();
|
|
|
|
builder.setToolbarColor(toolbarColor);
|
|
|
|
CustomTabsIntent customTabsIntent = builder.build();
|
|
|
|
try {
|
|
|
|
String packageName = CustomTabsHelper.getPackageNameToUse(context);
|
|
|
|
/* If we cant find a package name, it means theres no browser that supports
|
|
|
|
* Chrome Custom Tabs installed. So, we fallback to the webview */
|
|
|
|
if (packageName == null) {
|
|
|
|
return false;
|
|
|
|
} else {
|
|
|
|
customTabsIntent.intent.setPackage(packageName);
|
|
|
|
customTabsIntent.launchUrl(context, uri);
|
|
|
|
}
|
|
|
|
} catch (ActivityNotFoundException e) {
|
|
|
|
Log.w("URLSpan", "Activity was not found for intent, " + customTabsIntent.toString());
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2017-04-12 07:07:56 +10:00
|
|
|
private void redirectUserToAuthorizeAndLogin(EditText editText) {
|
|
|
|
/* To authorize this app and log in it's necessary to redirect to the domain given,
|
|
|
|
* activity_login there, and the server will redirect back to the app with its response. */
|
|
|
|
String endpoint = MastodonAPI.ENDPOINT_AUTHORIZE;
|
|
|
|
String redirectUri = getOauthRedirectUri();
|
|
|
|
Map<String, String> parameters = new HashMap<>();
|
|
|
|
parameters.put("client_id", clientId);
|
|
|
|
parameters.put("redirect_uri", redirectUri);
|
|
|
|
parameters.put("response_type", "code");
|
|
|
|
parameters.put("scope", OAUTH_SCOPES);
|
|
|
|
String url = "https://" + domain + endpoint + "?" + toQueryString(parameters);
|
2017-04-25 21:30:57 +10:00
|
|
|
Uri uri = Uri.parse(url);
|
|
|
|
if (!openInCustomTab(uri, this)) {
|
|
|
|
Intent viewIntent = new Intent(Intent.ACTION_VIEW, uri);
|
|
|
|
if (viewIntent.resolveActivity(getPackageManager()) != null) {
|
|
|
|
startActivity(viewIntent);
|
|
|
|
} else {
|
|
|
|
editText.setError(getString(R.string.error_no_web_browser_found));
|
|
|
|
}
|
2017-04-05 12:29:15 +10:00
|
|
|
}
|
2017-01-03 10:30:27 +11:00
|
|
|
}
|
|
|
|
|
2017-04-01 10:16:10 +11:00
|
|
|
@Override
|
|
|
|
protected void onStop() {
|
|
|
|
super.onStop();
|
|
|
|
if (domain != null) {
|
2017-04-21 08:56:36 +10:00
|
|
|
preferences.edit()
|
|
|
|
.putString("domain", domain)
|
|
|
|
.putString("clientId", clientId)
|
|
|
|
.putString("clientSecret", clientSecret)
|
|
|
|
.apply();
|
2017-04-01 10:16:10 +11:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-01-03 10:30:27 +11:00
|
|
|
@Override
|
2017-03-28 13:13:55 +11:00
|
|
|
protected void onStart() {
|
|
|
|
super.onStart();
|
2017-01-03 10:30:27 +11:00
|
|
|
/* Check if we are resuming during authorization by seeing if the intent contains the
|
|
|
|
* redirect that was given to the server. If so, its response is here! */
|
|
|
|
Uri uri = getIntent().getData();
|
|
|
|
String redirectUri = getOauthRedirectUri();
|
2017-03-14 22:59:52 +11:00
|
|
|
|
2017-03-16 06:32:26 +11:00
|
|
|
preferences = getSharedPreferences(
|
|
|
|
getString(R.string.preferences_file_key), Context.MODE_PRIVATE);
|
|
|
|
|
2017-03-20 14:15:36 +11:00
|
|
|
if (preferences.getString("accessToken", null) != null
|
|
|
|
&& preferences.getString("domain", null) != null) {
|
2017-03-16 06:32:26 +11:00
|
|
|
// We are already logged in, go to MainActivity
|
|
|
|
Intent intent = new Intent(this, MainActivity.class);
|
|
|
|
startActivity(intent);
|
|
|
|
finish();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2017-01-03 10:30:27 +11:00
|
|
|
if (uri != null && uri.toString().startsWith(redirectUri)) {
|
|
|
|
// This should either have returned an authorization code or an error.
|
|
|
|
String code = uri.getQueryParameter("code");
|
|
|
|
String error = uri.getQueryParameter("error");
|
2017-03-14 22:59:52 +11:00
|
|
|
|
2017-01-03 10:30:27 +11:00
|
|
|
if (code != null) {
|
|
|
|
/* 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. */
|
|
|
|
domain = preferences.getString("domain", null);
|
|
|
|
clientId = preferences.getString("clientId", null);
|
|
|
|
clientSecret = preferences.getString("clientSecret", null);
|
2017-05-08 20:17:41 +10:00
|
|
|
|
|
|
|
setLoading(true);
|
2017-01-03 10:30:27 +11:00
|
|
|
/* Since authorization has succeeded, the final step to log in is to exchange
|
|
|
|
* the authorization code for an access token. */
|
2017-03-10 13:55:07 +11:00
|
|
|
Callback<AccessToken> callback = new Callback<AccessToken>() {
|
|
|
|
@Override
|
|
|
|
public void onResponse(Call<AccessToken> call, Response<AccessToken> response) {
|
2017-03-14 11:49:12 +11:00
|
|
|
if (response.isSuccessful()) {
|
|
|
|
onLoginSuccess(response.body().accessToken);
|
|
|
|
} else {
|
2017-05-08 20:17:41 +10:00
|
|
|
setLoading(false);
|
|
|
|
|
2017-03-20 14:15:36 +11:00
|
|
|
editText.setError(getString(R.string.error_retrieving_oauth_token));
|
|
|
|
Log.e(TAG, String.format("%s %s",
|
|
|
|
getString(R.string.error_retrieving_oauth_token),
|
|
|
|
response.message()));
|
2017-03-14 11:49:12 +11:00
|
|
|
}
|
2017-03-10 13:55:07 +11:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onFailure(Call<AccessToken> call, Throwable t) {
|
2017-05-08 20:17:41 +10:00
|
|
|
setLoading(false);
|
2017-03-20 14:15:36 +11:00
|
|
|
editText.setError(getString(R.string.error_retrieving_oauth_token));
|
|
|
|
Log.e(TAG, String.format("%s %s",
|
|
|
|
getString(R.string.error_retrieving_oauth_token),
|
|
|
|
t.getMessage()));
|
2017-03-10 13:55:07 +11:00
|
|
|
}
|
|
|
|
};
|
2017-03-14 22:59:52 +11:00
|
|
|
|
2017-03-14 05:13:49 +11:00
|
|
|
getApiFor(domain).fetchOAuthToken(clientId, clientSecret, redirectUri, code,
|
2017-03-10 13:55:07 +11:00
|
|
|
"authorization_code").enqueue(callback);
|
2017-01-03 10:30:27 +11:00
|
|
|
} else if (error != null) {
|
|
|
|
/* Authorization failed. Put the error response where the user can read it and they
|
|
|
|
* can try again. */
|
2017-05-08 20:17:41 +10:00
|
|
|
setLoading(false);
|
2017-03-20 14:15:36 +11:00
|
|
|
editText.setError(getString(R.string.error_authorization_denied));
|
|
|
|
Log.e(TAG, getString(R.string.error_authorization_denied) + error);
|
2017-01-03 10:30:27 +11:00
|
|
|
} else {
|
2017-05-08 20:17:41 +10:00
|
|
|
setLoading(false);
|
2017-01-03 10:30:27 +11:00
|
|
|
// This case means a junk response was received somehow.
|
2017-03-14 22:59:52 +11:00
|
|
|
editText.setError(getString(R.string.error_authorization_unknown));
|
2017-01-03 10:30:27 +11:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2017-04-12 07:07:56 +10:00
|
|
|
|
2017-05-08 20:17:41 +10:00
|
|
|
private void setLoading(boolean loadingState) {
|
|
|
|
if (loadingState) {
|
|
|
|
loading.setVisibility(View.VISIBLE);
|
|
|
|
input.setVisibility(View.GONE);
|
|
|
|
} else {
|
|
|
|
loading.setVisibility(View.GONE);
|
|
|
|
input.setVisibility(View.VISIBLE);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-04-12 07:07:56 +10:00
|
|
|
private void onLoginSuccess(String accessToken) {
|
2017-04-21 08:56:36 +10:00
|
|
|
boolean committed = preferences.edit()
|
|
|
|
.putString("domain", domain)
|
|
|
|
.putString("accessToken", accessToken)
|
|
|
|
.commit();
|
|
|
|
if (!committed) {
|
2017-05-08 20:17:41 +10:00
|
|
|
setLoading(false);
|
2017-04-21 08:56:36 +10:00
|
|
|
editText.setError(getString(R.string.error_retrieving_oauth_token));
|
|
|
|
return;
|
|
|
|
}
|
2017-04-12 07:07:56 +10:00
|
|
|
Intent intent = new Intent(this, MainActivity.class);
|
|
|
|
startActivity(intent);
|
|
|
|
finish();
|
|
|
|
}
|
2017-01-03 10:30:27 +11:00
|
|
|
}
|