mirror of
https://github.com/whyorean/AuroraStore.git
synced 2026-06-19 13:08:59 -04:00
Fix Accounts Activity
- GoogleAccount Info was broken and forgotten - Reload fragment on changing accounts
This commit is contained in:
@@ -13,7 +13,7 @@ public class GoogleAccountInfo extends AsyncTask<Void, Void, String> {
|
||||
private String URL;
|
||||
|
||||
protected GoogleAccountInfo(String URL) {
|
||||
this.URL = "http://picasaweb.google.com/data/entry/api/user/" +URL;
|
||||
this.URL = "http://picasaweb.google.com/data/entry/api/user/" + URL;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -23,7 +23,6 @@ public class AccountsActivity extends GalaxyActivity {
|
||||
getSupportFragmentManager()
|
||||
.beginTransaction()
|
||||
.replace(R.id.content_frame, new AccountsFragment())
|
||||
.addToBackStack(null)
|
||||
.commit();
|
||||
}
|
||||
|
||||
@@ -38,4 +37,11 @@ public class AccountsActivity extends GalaxyActivity {
|
||||
onBackPressed();
|
||||
return true;
|
||||
}
|
||||
|
||||
public void userChanged() {
|
||||
this.getSupportFragmentManager()
|
||||
.beginTransaction()
|
||||
.replace(R.id.content_frame, new AccountsFragment())
|
||||
.commit();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -41,9 +41,6 @@ public abstract class BaseActivity extends RxAppCompatActivity {
|
||||
|
||||
abstract public void loadInstalledApps();
|
||||
|
||||
protected String Email, Name, Url;
|
||||
protected SharedPreferences sharedPreferences;
|
||||
|
||||
protected ListView listView;
|
||||
protected Map<String, ListItem> listItems = new HashMap<>();
|
||||
|
||||
@@ -55,10 +52,7 @@ public abstract class BaseActivity extends RxAppCompatActivity {
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
|
||||
sharedPreferences = PreferenceManager.getDefaultSharedPreferences(this);
|
||||
|
||||
logout = false;
|
||||
Email = sharedPreferences.getString(PlayStoreApiAuthenticator.PREFERENCE_EMAIL, "");
|
||||
}
|
||||
|
||||
protected boolean isConnected() {
|
||||
|
||||
@@ -14,9 +14,9 @@ import android.widget.TextView;
|
||||
import java.util.Properties;
|
||||
import java.util.TimeZone;
|
||||
|
||||
import in.dragons.galaxy.builders.AccountTypeDialogBuilder;
|
||||
import in.dragons.galaxy.R;
|
||||
import in.dragons.galaxy.SpoofDeviceManager;
|
||||
import in.dragons.galaxy.builders.AccountTypeDialogBuilder;
|
||||
import in.dragons.galaxy.fragment.PreferenceFragment;
|
||||
|
||||
public class DeviceActivity extends GalaxyActivity {
|
||||
@@ -33,7 +33,7 @@ public class DeviceActivity extends GalaxyActivity {
|
||||
FrameLayout contentFrameLayout = (FrameLayout) findViewById(R.id.content_frame);
|
||||
getLayoutInflater().inflate(R.layout.app_device_inc, contentFrameLayout);
|
||||
|
||||
deviceName = sharedPreferences.getString(PreferenceFragment.PREFERENCE_DEVICE_TO_PRETEND_TO_BE, "");
|
||||
deviceName = PreferenceFragment.getString(this, PreferenceFragment.PREFERENCE_DEVICE_TO_PRETEND_TO_BE);
|
||||
spoofed = (ImageView) findViewById(R.id.spoofed_indicator);
|
||||
mDisplay = (this).getWindowManager().getDefaultDisplay();
|
||||
|
||||
@@ -70,8 +70,8 @@ public class DeviceActivity extends GalaxyActivity {
|
||||
setText(R.id.device_manufacturer, R.string.device_manufacturer, properties.getProperty("Build.MANUFACTURER"));
|
||||
setText(R.id.device_architect, R.string.device_board, properties.getProperty("Build.HARDWARE"));
|
||||
setText(R.id.device_timezone, R.string.device_timezone, properties.getProperty("TimeZone"));
|
||||
setText(R.id.device_resolution, R.string.device_res, properties.getProperty("Screen.Width"),properties.getProperty("Screen.Height"));
|
||||
setText(R.id.device_api, R.string.device_api,properties.getProperty("Build.VERSION.SDK_INT"));
|
||||
setText(R.id.device_resolution, R.string.device_res, properties.getProperty("Screen.Width"), properties.getProperty("Screen.Height"));
|
||||
setText(R.id.device_api, R.string.device_api, properties.getProperty("Build.VERSION.SDK_INT"));
|
||||
String Platforms = properties.getProperty("Platforms");
|
||||
setText(R.id.device_cpu, R.string.device_cpu, Platforms.substring(0, Platforms.indexOf(',')));
|
||||
}
|
||||
|
||||
@@ -16,9 +16,12 @@ import android.support.v7.widget.SearchView;
|
||||
import android.support.v7.widget.Toolbar;
|
||||
import android.view.MenuItem;
|
||||
import android.view.View;
|
||||
import android.widget.ImageView;
|
||||
import android.widget.ListView;
|
||||
import android.widget.TextView;
|
||||
|
||||
import com.percolate.caffeine.ViewUtils;
|
||||
import com.squareup.picasso.Picasso;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
@@ -28,10 +31,12 @@ import java.util.Set;
|
||||
import butterknife.BindView;
|
||||
import butterknife.ButterKnife;
|
||||
import in.dragons.galaxy.AppListIterator;
|
||||
import in.dragons.galaxy.CircleTransform;
|
||||
import in.dragons.galaxy.PlayStoreApiAuthenticator;
|
||||
import in.dragons.galaxy.R;
|
||||
import in.dragons.galaxy.adapters.AppListAdapter;
|
||||
import in.dragons.galaxy.adapters.ViewPagerAdapter;
|
||||
import in.dragons.galaxy.fragment.PreferenceFragment;
|
||||
import in.dragons.galaxy.model.App;
|
||||
import in.dragons.galaxy.view.ListItem;
|
||||
import in.dragons.galaxy.view.ProgressIndicator;
|
||||
@@ -70,7 +75,18 @@ public class GalaxyActivity extends BaseActivity implements
|
||||
ActionBarDrawerToggle toggle = new ActionBarDrawerToggle(
|
||||
this, drawerLayout, toolbar,
|
||||
R.string.navigation_drawer_open,
|
||||
R.string.navigation_drawer_close);
|
||||
R.string.navigation_drawer_close) {
|
||||
|
||||
@Override
|
||||
public void onDrawerOpened(View drawerView) {
|
||||
super.onDrawerOpened(drawerView);
|
||||
if (isLoggedIn())
|
||||
setUser();
|
||||
else
|
||||
resetUser();
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
drawerLayout.addDrawerListener(toggle);
|
||||
toggle.syncState();
|
||||
@@ -81,20 +97,39 @@ public class GalaxyActivity extends BaseActivity implements
|
||||
viewPager.setOffscreenPageLimit(3);
|
||||
slidingTabs.setupWithViewPager(viewPager);
|
||||
|
||||
if (isLoggedIn())
|
||||
setUser();
|
||||
|
||||
ActivityCompat.requestPermissions(this,
|
||||
new String[]{Manifest.permission.WRITE_EXTERNAL_STORAGE}, 1);
|
||||
}
|
||||
|
||||
public void setUser() {
|
||||
View header = navView.getHeaderView(0);
|
||||
if (isGoogle() && isConnected())
|
||||
if (isGoogle()) {
|
||||
ViewUtils.setText(header, R.id.usr_email, PreferenceFragment
|
||||
.getString(this, PlayStoreApiAuthenticator.PREFERENCE_EMAIL));
|
||||
ViewUtils.setText(header, R.id.usr_name,
|
||||
PreferenceFragment.getString(this, "GOOGLE_NAME"));
|
||||
Picasso.with(this)
|
||||
.load(PreferenceFragment.getString(this, "GOOGLE_URL"))
|
||||
.placeholder(R.drawable.ic_user_placeholder)
|
||||
.transform(new CircleTransform())
|
||||
.into(((ImageView) header.findViewById(R.id.usr_img)));
|
||||
} else if (isDummy()) {
|
||||
((TextView) header.findViewById(R.id.usr_name)).setText(R.string.header_usr_name);
|
||||
ViewUtils.setText(header, R.id.usr_email,
|
||||
sharedPreferences.getString(PlayStoreApiAuthenticator.PREFERENCE_EMAIL, ""));
|
||||
else if (isDummy())
|
||||
ViewUtils.setText(header, R.id.usr_email, getResources().getString(R.string.header_usr_email));
|
||||
getResources().getString(R.string.header_usr_email));
|
||||
((ImageView) header.findViewById(R.id.usr_img))
|
||||
.setImageDrawable(getResources()
|
||||
.getDrawable(R.drawable.ic_dummy_avatar));
|
||||
}
|
||||
}
|
||||
|
||||
public void resetUser() {
|
||||
View header = navView.getHeaderView(0);
|
||||
((TextView) header.findViewById(R.id.usr_name)).setText(R.string.header_usr_name);
|
||||
((TextView) header.findViewById(R.id.usr_email)).setText(R.string.header_usr_noEmail);
|
||||
((ImageView) header.findViewById(R.id.usr_img))
|
||||
.setImageDrawable(getResources()
|
||||
.getDrawable(R.drawable.ic_user_placeholder));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
package in.dragons.galaxy.builders;
|
||||
|
||||
import android.annotation.SuppressLint;
|
||||
import android.app.AlertDialog;
|
||||
import android.app.Dialog;
|
||||
import android.content.Context;
|
||||
@@ -67,18 +66,12 @@ abstract public class CredentialsDialogBuilder {
|
||||
@Override
|
||||
protected void processException(Throwable e) {
|
||||
super.processException(e);
|
||||
if ((e instanceof GooglePlayException && ((GooglePlayException) e).getCode() == 500)
|
||||
|| (e instanceof AuthException && !TextUtils.isEmpty(((AuthException) e).getTwoFactorUrl()))
|
||||
) {
|
||||
if ((e instanceof GooglePlayException
|
||||
&& ((GooglePlayException) e).getCode() == 500)
|
||||
|| (e instanceof AuthException
|
||||
&& !TextUtils.isEmpty(((AuthException) e).getTwoFactorUrl()))) {
|
||||
return;
|
||||
}
|
||||
CredentialsDialogBuilder builder = getDialogBuilder();
|
||||
if (null != caller) {
|
||||
builder.setCaller(caller);
|
||||
}
|
||||
if (ContextUtil.isAlive(context)) {
|
||||
builder.show();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -87,7 +80,7 @@ abstract public class CredentialsDialogBuilder {
|
||||
if (e instanceof TokenDispenserException) {
|
||||
ContextUtil.toast(context, R.string.error_token_dispenser_problem);
|
||||
} else if (e instanceof GooglePlayException && ((GooglePlayException) e).getCode() == 500) {
|
||||
PreferenceManager.getDefaultSharedPreferences(context).edit().putString(PreferenceFragment.PREFERENCE_BACKGROUND_UPDATE_INTERVAL, "-1").commit();
|
||||
PreferenceManager.getDefaultSharedPreferences(context).edit().putString(PreferenceFragment.PREFERENCE_BACKGROUND_UPDATE_INTERVAL, "-1").apply();
|
||||
ContextUtil.toast(context, R.string.error_invalid_device_definition);
|
||||
context.startActivity(new Intent(context, PreferenceFragment.class));
|
||||
}
|
||||
@@ -127,12 +120,7 @@ abstract public class CredentialsDialogBuilder {
|
||||
)
|
||||
.setNegativeButton(
|
||||
R.string.dialog_two_factor_cancel,
|
||||
new DialogInterface.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(DialogInterface dialog, int which) {
|
||||
android.os.Process.killProcess(android.os.Process.myPid());
|
||||
}
|
||||
}
|
||||
(dialog, which) -> android.os.Process.killProcess(android.os.Process.myPid())
|
||||
)
|
||||
.create();
|
||||
}
|
||||
|
||||
@@ -5,10 +5,8 @@ import android.content.Context;
|
||||
import android.preference.PreferenceManager;
|
||||
import android.text.InputType;
|
||||
import android.text.TextUtils;
|
||||
import android.view.View;
|
||||
import android.widget.ArrayAdapter;
|
||||
import android.widget.AutoCompleteTextView;
|
||||
import android.widget.Button;
|
||||
import android.widget.EditText;
|
||||
import android.widget.ImageView;
|
||||
|
||||
@@ -50,36 +48,25 @@ public class UserProvidedAccountDialogBuilder extends CredentialsDialogBuilder {
|
||||
final AutoCompleteTextView editEmail = getEmailInput(ad);
|
||||
final EditText editPassword = (EditText) ad.findViewById(R.id.password);
|
||||
|
||||
ad.findViewById(R.id.button_exit).setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
android.os.Process.killProcess(android.os.Process.myPid());
|
||||
ad.findViewById(R.id.button_exit).setOnClickListener(v -> ad.dismiss());
|
||||
|
||||
ad.findViewById(R.id.button_ok).setOnClickListener(view -> {
|
||||
Context c = view.getContext();
|
||||
String email = editEmail.getText().toString();
|
||||
String password = editPassword.getText().toString();
|
||||
if (TextUtils.isEmpty(email) || TextUtils.isEmpty(password)) {
|
||||
ContextUtil.toast(c.getApplicationContext(), R.string.error_credentials_empty);
|
||||
return;
|
||||
}
|
||||
ad.dismiss();
|
||||
getUserCredentialsTask().execute(email, password);
|
||||
});
|
||||
|
||||
ad.findViewById(R.id.button_ok).setOnClickListener(new Button.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View view) {
|
||||
Context c = view.getContext();
|
||||
String email = editEmail.getText().toString();
|
||||
String password = editPassword.getText().toString();
|
||||
if (TextUtils.isEmpty(email) || TextUtils.isEmpty(password)) {
|
||||
ContextUtil.toast(c.getApplicationContext(), R.string.error_credentials_empty);
|
||||
return;
|
||||
}
|
||||
ad.dismiss();
|
||||
getUserCredentialsTask().execute(email, password);
|
||||
}
|
||||
});
|
||||
|
||||
ad.findViewById(R.id.toggle_password_visibility).setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
boolean passwordVisible = !TextUtils.isEmpty((String) v.getTag());
|
||||
v.setTag(passwordVisible ? null : "tag");
|
||||
((ImageView) v).setImageResource(passwordVisible ? R.drawable.ic_visibility_on : R.drawable.ic_visibility_off);
|
||||
editPassword.setInputType(passwordVisible ? InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_VARIATION_PASSWORD : InputType.TYPE_CLASS_TEXT);
|
||||
}
|
||||
ad.findViewById(R.id.toggle_password_visibility).setOnClickListener(v -> {
|
||||
boolean passwordVisible = !TextUtils.isEmpty((String) v.getTag());
|
||||
v.setTag(passwordVisible ? null : "tag");
|
||||
((ImageView) v).setImageResource(passwordVisible ? R.drawable.ic_visibility_on : R.drawable.ic_visibility_off);
|
||||
editPassword.setInputType(passwordVisible ? InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_VARIATION_PASSWORD : InputType.TYPE_CLASS_TEXT);
|
||||
});
|
||||
|
||||
ad.show();
|
||||
@@ -145,13 +132,5 @@ public class UserProvidedAccountDialogBuilder extends CredentialsDialogBuilder {
|
||||
emailsSet.add(email);
|
||||
Util.putStringSet(context, USED_EMAILS_SET, emailsSet);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onPostExecute(Void result) {
|
||||
super.onPostExecute(result);
|
||||
PreferenceManager.getDefaultSharedPreferences(context).edit().putBoolean("LOGGED_IN", true).apply();
|
||||
PreferenceManager.getDefaultSharedPreferences(context).edit().putBoolean("GOOGLE_ACC", true).apply();
|
||||
PreferenceManager.getDefaultSharedPreferences(context).edit().putBoolean("DUMMY_ACC", false).apply();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -15,7 +15,6 @@ import android.widget.Button;
|
||||
import android.widget.ImageView;
|
||||
import android.widget.TextView;
|
||||
|
||||
import com.percolate.caffeine.PhoneUtils;
|
||||
import com.percolate.caffeine.ViewUtils;
|
||||
import com.squareup.picasso.Picasso;
|
||||
|
||||
@@ -49,7 +48,7 @@ public class AccountsFragment extends UtilFragment {
|
||||
sharedPreferences = PreferenceManager.getDefaultSharedPreferences(getActivity());
|
||||
Email = sharedPreferences.getString(PlayStoreApiAuthenticator.PREFERENCE_EMAIL, "");
|
||||
|
||||
if (isLoggedIn() && isGoogle() && isConnected()) {
|
||||
if (isLoggedIn() && isGoogle()) {
|
||||
drawGoogle();
|
||||
} else if (isLoggedIn() && isDummy())
|
||||
drawDummy();
|
||||
@@ -69,7 +68,9 @@ public class AccountsFragment extends UtilFragment {
|
||||
TextView dummyEmail = ViewUtils.findViewById(v, R.id.dummy_email);
|
||||
dummyEmail.setText(Email);
|
||||
|
||||
setText(R.id.dummy_gsf, R.string.device_gsfID, sharedPreferences.getString(PlayStoreApiAuthenticator.PREFERENCE_GSF_ID, ""));
|
||||
setText(R.id.dummy_gsf, R.string.device_gsfID,
|
||||
PreferenceFragment.getString(getActivity(),
|
||||
PlayStoreApiAuthenticator.PREFERENCE_GSF_ID));
|
||||
|
||||
Button logout = ViewUtils.findViewById(v, R.id.account_logout);
|
||||
logout.setOnClickListener(v -> showLogOutDialog());
|
||||
@@ -85,12 +86,14 @@ public class AccountsFragment extends UtilFragment {
|
||||
ViewUtils.setText(v, R.id.google_name, sharedPreferences.getString("GOOGLE_NAME", ""));
|
||||
ViewUtils.setText(v, R.id.google_email, Email);
|
||||
|
||||
setText(R.id.google_gsf, R.string.device_gsfID, sharedPreferences.getString(PlayStoreApiAuthenticator.PREFERENCE_GSF_ID, ""));
|
||||
setText(R.id.google_gsf, R.string.device_gsfID,
|
||||
PreferenceFragment.getString(getActivity(), PlayStoreApiAuthenticator.PREFERENCE_GSF_ID));
|
||||
|
||||
Button button = ViewUtils.findViewById(v, R.id.google_logout);
|
||||
button.setOnClickListener(v -> showLogOutDialog());
|
||||
|
||||
//loadAvatar(sharedPreferences.getString("GOOGLE_URL", ""));
|
||||
if (isConnected())
|
||||
loadAvatar(PreferenceFragment.getString(getActivity(), "GOOGLE_URL"));
|
||||
}
|
||||
|
||||
public void setFab() {
|
||||
@@ -124,7 +127,7 @@ public class AccountsFragment extends UtilFragment {
|
||||
.setMessage(R.string.dialog_message_logout)
|
||||
.setTitle(R.string.dialog_title_logout)
|
||||
.setPositiveButton(android.R.string.yes, (dialogInterface, i) -> {
|
||||
PreferenceManager.getDefaultSharedPreferences(getActivity()).edit().putBoolean("LOGGED_IN", false).apply();
|
||||
checkOut();
|
||||
new PlayStoreApiAuthenticator(getActivity().getApplicationContext()).logout();
|
||||
dialogInterface.dismiss();
|
||||
getActivity().finish();
|
||||
@@ -132,8 +135,4 @@ public class AccountsFragment extends UtilFragment {
|
||||
.setNegativeButton(android.R.string.cancel, null)
|
||||
.show();
|
||||
}
|
||||
|
||||
protected boolean isConnected() {
|
||||
return PhoneUtils.isNetworkAvailable(this.getActivity());
|
||||
}
|
||||
}
|
||||
@@ -1,8 +1,8 @@
|
||||
package in.dragons.galaxy.fragment;
|
||||
|
||||
import android.annotation.SuppressLint;
|
||||
import android.app.Dialog;
|
||||
import android.content.Context;
|
||||
import android.content.DialogInterface;
|
||||
import android.content.Intent;
|
||||
import android.preference.PreferenceManager;
|
||||
import android.support.v7.app.AlertDialog;
|
||||
@@ -14,6 +14,7 @@ import android.widget.EditText;
|
||||
import android.widget.ImageView;
|
||||
|
||||
import com.github.yeriomin.playstoreapi.AuthException;
|
||||
import com.percolate.caffeine.PhoneUtils;
|
||||
import com.trello.rxlifecycle2.components.support.RxFragment;
|
||||
|
||||
import java.io.IOException;
|
||||
@@ -24,6 +25,7 @@ import java.util.Set;
|
||||
|
||||
import in.dragons.galaxy.ContextUtil;
|
||||
import in.dragons.galaxy.CredentialsEmptyException;
|
||||
import in.dragons.galaxy.GoogleAccountInfo;
|
||||
import in.dragons.galaxy.PlayStoreApiAuthenticator;
|
||||
import in.dragons.galaxy.R;
|
||||
import in.dragons.galaxy.Util;
|
||||
@@ -38,6 +40,7 @@ public abstract class UtilFragment extends RxFragment {
|
||||
protected PlayStoreTask playStoreTask;
|
||||
static private final String USED_EMAILS_SET = "USED_EMAILS_SET";
|
||||
|
||||
|
||||
private AutoCompleteTextView getEmailInput(Dialog ad) {
|
||||
AutoCompleteTextView editEmail = (AutoCompleteTextView) ad.findViewById(R.id.email);
|
||||
editEmail.setAdapter(new ArrayAdapter<>(getActivity(), android.R.layout.simple_dropdown_item_1line, getUsedEmails()));
|
||||
@@ -68,13 +71,13 @@ public abstract class UtilFragment extends RxFragment {
|
||||
}
|
||||
|
||||
public Dialog logInWithGoogleAccount() {
|
||||
final Dialog ad = new Dialog(getActivity());
|
||||
Dialog ad = new Dialog(getActivity());
|
||||
ad.setContentView(R.layout.credentials_dialog_layout);
|
||||
ad.setTitle(getActivity().getString(R.string.credentials_title));
|
||||
ad.setCancelable(false);
|
||||
|
||||
final AutoCompleteTextView editEmail = getEmailInput(ad);
|
||||
final EditText editPassword = (EditText) ad.findViewById(R.id.password);
|
||||
AutoCompleteTextView editEmail = getEmailInput(ad);
|
||||
EditText editPassword = (EditText) ad.findViewById(R.id.password);
|
||||
|
||||
editEmail.setText("");
|
||||
|
||||
@@ -90,7 +93,6 @@ public abstract class UtilFragment extends RxFragment {
|
||||
ad.dismiss();
|
||||
getUserCredentialsTask().execute(email, password);
|
||||
});
|
||||
|
||||
ad.findViewById(R.id.toggle_password_visibility).setOnClickListener(v -> {
|
||||
boolean passwordVisible = !TextUtils.isEmpty((String) v.getTag());
|
||||
v.setTag(passwordVisible ? null : "tag");
|
||||
@@ -106,16 +108,8 @@ public abstract class UtilFragment extends RxFragment {
|
||||
return new AlertDialog.Builder(getActivity())
|
||||
.setTitle("Logged Out ?")
|
||||
.setMessage(R.string.header_usr_noEmail)
|
||||
.setPositiveButton("Login", new DialogInterface.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(DialogInterface dialogInterface, int i) {
|
||||
startActivity(new Intent(getActivity(), AccountsActivity.class));
|
||||
}
|
||||
})
|
||||
.setNegativeButton("Dismiss", new DialogInterface.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(DialogInterface dialogInterface, int i) {
|
||||
}
|
||||
.setPositiveButton("Login", (dialogInterface, i) -> startActivity(new Intent(getActivity(), AccountsActivity.class)))
|
||||
.setNegativeButton("Dismiss", (dialogInterface, i) -> {
|
||||
})
|
||||
.show();
|
||||
}
|
||||
@@ -128,7 +122,8 @@ public abstract class UtilFragment extends RxFragment {
|
||||
return task;
|
||||
}
|
||||
|
||||
private static class LoginTask extends AccountTypeDialogBuilder.AppProvidedCredentialsTask {
|
||||
@SuppressLint("StaticFieldLeak")
|
||||
private class LoginTask extends AccountTypeDialogBuilder.AppProvidedCredentialsTask {
|
||||
|
||||
@Override
|
||||
protected void payload() throws IOException {
|
||||
@@ -141,6 +136,9 @@ public abstract class UtilFragment extends RxFragment {
|
||||
PreferenceManager.getDefaultSharedPreferences(context).edit().putBoolean("LOGGED_IN", true).apply();
|
||||
PreferenceManager.getDefaultSharedPreferences(context).edit().putBoolean("DUMMY_ACC", true).apply();
|
||||
PreferenceManager.getDefaultSharedPreferences(context).edit().putBoolean("GOOGLE_ACC", false).apply();
|
||||
|
||||
AccountsActivity accountsActivity = (AccountsActivity) getActivity();
|
||||
accountsActivity.userChanged();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -163,9 +161,13 @@ public abstract class UtilFragment extends RxFragment {
|
||||
}
|
||||
}
|
||||
|
||||
private static class UserProvidedCredentialsTask extends CredentialsDialogBuilder.CheckCredentialsTask {
|
||||
@SuppressLint("StaticFieldLeak")
|
||||
private class UserProvidedCredentialsTask extends CredentialsDialogBuilder.CheckCredentialsTask {
|
||||
|
||||
private String previousEmail;
|
||||
private String UNKNOWN = "Unknown user.";
|
||||
private String PICASAWEB = "picasaweb";
|
||||
private String Email, Name, Url;
|
||||
|
||||
@Override
|
||||
protected CredentialsDialogBuilder getDialogBuilder() {
|
||||
@@ -205,10 +207,46 @@ public abstract class UtilFragment extends RxFragment {
|
||||
@Override
|
||||
protected void onPostExecute(Void result) {
|
||||
super.onPostExecute(result);
|
||||
PreferenceManager.getDefaultSharedPreferences(context).edit().putBoolean("LOGGED_IN", true).apply();
|
||||
PreferenceManager.getDefaultSharedPreferences(context).edit().putBoolean("GOOGLE_ACC", true).apply();
|
||||
PreferenceManager.getDefaultSharedPreferences(context).edit().putBoolean("DUMMY_ACC", false).apply();
|
||||
if (success()) {
|
||||
PreferenceManager.getDefaultSharedPreferences(context).edit().putBoolean("LOGGED_IN", true).apply();
|
||||
PreferenceManager.getDefaultSharedPreferences(context).edit().putBoolean("GOOGLE_ACC", true).apply();
|
||||
PreferenceManager.getDefaultSharedPreferences(context).edit().putBoolean("DUMMY_ACC", false).apply();
|
||||
setUser();
|
||||
}
|
||||
}
|
||||
|
||||
@SuppressLint("StaticFieldLeak")
|
||||
private void setUser() {
|
||||
Email = PreferenceFragment.getString(context, PlayStoreApiAuthenticator.PREFERENCE_EMAIL);
|
||||
new GoogleAccountInfo(Email) {
|
||||
@Override
|
||||
public void onPostExecute(String result) {
|
||||
parseRAW(result);
|
||||
}
|
||||
}.execute();
|
||||
}
|
||||
|
||||
private void parseRAW(String rawData) {
|
||||
if (rawData.contains(PICASAWEB) && !rawData.contains(UNKNOWN)) {
|
||||
Name = rawData.substring(rawData.indexOf("<name>") + 6, rawData.indexOf("</name>"));
|
||||
Url = rawData.substring(rawData.indexOf("<gphoto:thumbnail>") + 18, rawData.lastIndexOf("</gphoto:thumbnail>"));
|
||||
} else {
|
||||
Name = Email;
|
||||
Url = "I dont fucking care";
|
||||
}
|
||||
|
||||
PreferenceManager.getDefaultSharedPreferences(context).edit().putString("GOOGLE_NAME", Name).apply();
|
||||
PreferenceManager.getDefaultSharedPreferences(context).edit().putString("GOOGLE_URL", Url).apply();
|
||||
|
||||
AccountsActivity accountsActivity = (AccountsActivity) getActivity();
|
||||
accountsActivity.userChanged();
|
||||
}
|
||||
}
|
||||
|
||||
protected void checkOut() {
|
||||
PreferenceManager.getDefaultSharedPreferences(getActivity()).edit().putBoolean("LOGGED_IN", false).apply();
|
||||
PreferenceManager.getDefaultSharedPreferences(getActivity()).edit().putString("GOOGLE_NAME", "").apply();
|
||||
PreferenceManager.getDefaultSharedPreferences(getActivity()).edit().putString("GOOGLE_URL", "").apply();
|
||||
}
|
||||
|
||||
protected boolean isLoggedIn() {
|
||||
@@ -222,4 +260,8 @@ public abstract class UtilFragment extends RxFragment {
|
||||
protected boolean isGoogle() {
|
||||
return PreferenceFragment.getBoolean(getActivity(), "GOOGLE_ACC");
|
||||
}
|
||||
|
||||
protected boolean isConnected() {
|
||||
return PhoneUtils.isNetworkAvailable(this.getActivity());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -9,6 +9,7 @@ import android.widget.TextView;
|
||||
import com.github.yeriomin.playstoreapi.AuthException;
|
||||
import com.github.yeriomin.playstoreapi.BulkDetailsEntry;
|
||||
import com.github.yeriomin.playstoreapi.GooglePlayAPI;
|
||||
import com.percolate.caffeine.ToastUtils;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.net.ConnectException;
|
||||
@@ -184,8 +185,9 @@ public abstract class ForegroundUpdatableAppsTaskHelper extends AppListFragment
|
||||
Log.i(getClass().getSimpleName(), "Token is stale");
|
||||
refreshMyToken();
|
||||
} else {
|
||||
ContextUtil.toast(this.getActivity(), R.string.error_incorrect_password);
|
||||
new PlayStoreApiAuthenticator(this.getActivity()).logout();
|
||||
ToastUtils.quickToast(getActivity(),e.getMessage());
|
||||
//ContextUtil.toast(this.getActivity(), R.string.error_incorrect_password);
|
||||
//new PlayStoreApiAuthenticator(this.getActivity()).logout();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -4,10 +4,10 @@
|
||||
android:insetRight="4dp"
|
||||
android:insetTop="8dp"
|
||||
android:insetBottom="8dp">
|
||||
<ripple android:color="@color/colorAccent">
|
||||
<ripple android:color="@color/colorPrimary">
|
||||
<item>
|
||||
<shape android:shape="rectangle"
|
||||
android:tint="@color/button_bg">
|
||||
android:tint="@color/colorAccent">
|
||||
<corners android:radius="3dp" />
|
||||
<solid android:color="@color/white" />
|
||||
</shape>
|
||||
|
||||
@@ -9,7 +9,7 @@
|
||||
<shape
|
||||
android:shape="rectangle">
|
||||
<corners android:radius="3dp" />
|
||||
<stroke android:width="3px" android:color="@color/button_bg"/>
|
||||
<stroke android:width="3px" android:color="@color/colorAccent"/>
|
||||
</shape>
|
||||
</item>
|
||||
</ripple>
|
||||
|
||||
@@ -154,7 +154,7 @@
|
||||
android:id="@+id/account_logout"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:background="@color/colorAccent"
|
||||
android:background="@drawable/button_bg"
|
||||
android:text="@string/action_logout"
|
||||
android:textColor="@color/white" />
|
||||
</LinearLayout>
|
||||
@@ -298,12 +298,12 @@
|
||||
android:padding="5dp"
|
||||
android:weightSum="9">
|
||||
|
||||
<android.support.v7.widget.AppCompatButton
|
||||
<Button
|
||||
android:id="@+id/google_logout"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_weight="3"
|
||||
android:background="@color/colorAccent"
|
||||
android:background="@drawable/button_bg"
|
||||
android:text="@string/action_logout"
|
||||
android:textColor="@color/white" />
|
||||
</LinearLayout>
|
||||
|
||||
Reference in New Issue
Block a user