Issue #127 auto-login on first launch

This commit is contained in:
Sergey Eremin
2017-04-11 00:50:38 +03:00
parent 713992cd4c
commit 0073b6ffd3
5 changed files with 71 additions and 24 deletions

View File

@@ -18,7 +18,9 @@ android {
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
debug {
initWith release
shrinkResources true
minifyEnabled true
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}
lintOptions {

View File

@@ -43,7 +43,7 @@ public class AccountTypeDialogBuilder extends CredentialsDialogBuilder {
return builder.show();
}
private void logInWithPredefinedAccount() {
public void logInWithPredefinedAccount() {
AppProvidedCredentialsTask task = new AppProvidedCredentialsTask();
task.setTaskClone(taskClone);
task.setContext(context);

View File

@@ -0,0 +1,27 @@
package com.github.yeriomin.yalpstore;
import android.content.Context;
import android.content.SharedPreferences;
import android.preference.PreferenceManager;
public class FirstLaunchChecker {
static private final String FIRST_LAUNCH = "FIRST_LAUNCH";
private SharedPreferences prefs;
public FirstLaunchChecker(Context context) {
prefs = PreferenceManager.getDefaultSharedPreferences(context);
}
public boolean isFirstLaunch() {
return prefs.getBoolean(FIRST_LAUNCH, true);
}
public void setLaunched() {
prefs.edit()
.putBoolean(FIRST_LAUNCH, false)
.commit()
;
}
}

View File

@@ -74,36 +74,53 @@ abstract class GoogleApiAsyncTask extends AsyncTask<String, Void, Throwable> {
e = result.getCause();
}
if (e != null) {
Log.d(getClass().getName(), e.getClass().getName() + " caught during a google api request: " + e.getMessage());
processException(e);
}
}
private void processException(Throwable e) {
Log.d(getClass().getName(), e.getClass().getName() + " caught during a google api request: " + e.getMessage());
if (e instanceof AuthException) {
if (e instanceof CredentialsEmptyException) {
Log.w(getClass().getName(), "Credentials empty");
} else {
toast(this.context, R.string.error_incorrect_password);
new PlayStoreApiAuthenticator(context).logout();
}
AccountTypeDialogBuilder builder = new AccountTypeDialogBuilder(this.context);
builder.setTaskClone(this.taskClone);
builder.show();
processAuthException((AuthException) e);
} else if (e instanceof IOException) {
String message;
if (noNetwork(e)) {
message = this.context.getString(R.string.error_no_network);
} else {
message = this.context.getString(R.string.error_network_other, e.getClass().getName() + " " + e.getMessage());
}
if (null != this.errorView) {
this.errorView.setText(message);
} else {
toast(this.context, message);
}
} else if (e != null) {
processIOException((IOException) e);
} else {
Log.e(getClass().getName(), "Unknown exception " + e.getClass().getName() + " " + e.getMessage());
e.printStackTrace();
}
}
private void processIOException(IOException e) {
String message;
if (noNetwork(e)) {
message = this.context.getString(R.string.error_no_network);
} else {
message = this.context.getString(R.string.error_network_other, e.getClass().getName() + " " + e.getMessage());
}
if (null != this.errorView) {
this.errorView.setText(message);
} else {
toast(this.context, message);
}
}
private void processAuthException(AuthException e) {
AccountTypeDialogBuilder builder = new AccountTypeDialogBuilder(this.context);
builder.setTaskClone(this.taskClone);
if (e instanceof CredentialsEmptyException) {
Log.i(getClass().getName(), "Credentials empty");
if (new FirstLaunchChecker(context).isFirstLaunch()) {
Log.i(getClass().getName(), "First launch, so using built-in account");
builder.logInWithPredefinedAccount();
return;
}
} else {
toast(this.context, R.string.error_incorrect_password);
new PlayStoreApiAuthenticator(context).logout();
}
builder.show();
}
static public boolean noNetwork(Throwable e) {
return e instanceof UnknownHostException
|| e instanceof SSLHandshakeException

View File

@@ -85,6 +85,7 @@ public class UpdatableAppsActivity extends AppListActivity {
}
toggleUpdateAll(this.updatableApps.size() > 0);
new CategoryManager(UpdatableAppsActivity.this).downloadCategoryNames();
new FirstLaunchChecker(context).setLaunched();
}
};
task.setErrorView((TextView) getListView().getEmptyView());