From 478a408222d7f1f29f58a0e6a5213225a775485c Mon Sep 17 00:00:00 2001 From: M66B Date: Mon, 6 Apr 2020 21:00:14 +0200 Subject: [PATCH] Toast for no accounts --- .../java/eu/faircode/email/FragmentGmail.java | 34 ++++++++++++++----- .../java/eu/faircode/email/FragmentSetup.java | 2 +- 2 files changed, 26 insertions(+), 10 deletions(-) diff --git a/app/src/main/java/eu/faircode/email/FragmentGmail.java b/app/src/main/java/eu/faircode/email/FragmentGmail.java index 994bbb08c7..87c54646bb 100644 --- a/app/src/main/java/eu/faircode/email/FragmentGmail.java +++ b/app/src/main/java/eu/faircode/email/FragmentGmail.java @@ -42,6 +42,7 @@ import android.widget.Button; import android.widget.EditText; import android.widget.ScrollView; import android.widget.TextView; +import android.widget.Toast; import androidx.annotation.NonNull; import androidx.annotation.Nullable; @@ -68,6 +69,8 @@ public class FragmentGmail extends FragmentBase { private Group grpError; + private static String TYPE_GOOGLE = "com.google"; + @Override @Nullable public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) { @@ -112,7 +115,7 @@ public class FragmentGmail extends FragmentBase { Intent intent = newChooseAccountIntent( null, null, - new String[]{"com.google"}, + new String[]{TYPE_GOOGLE}, false, null, null, @@ -189,14 +192,20 @@ public class FragmentGmail extends FragmentBase { public void onActivityResult(int requestCode, int resultCode, Intent data) { super.onActivityResult(requestCode, resultCode, data); - switch (requestCode) { - case ActivitySetup.REQUEST_CHOOSE_ACCOUNT: - if (resultCode == RESULT_OK && data != null) - onAccountSelected(data); - break; - case ActivitySetup.REQUEST_DONE: - finish(); - break; + try { + switch (requestCode) { + case ActivitySetup.REQUEST_CHOOSE_ACCOUNT: + if (resultCode == RESULT_OK && data != null) + onAccountSelected(data); + else + onNoAccountSelected(); + break; + case ActivitySetup.REQUEST_DONE: + finish(); + break; + } + } catch (Throwable ex) { + Log.e(ex); } } @@ -228,6 +237,13 @@ public class FragmentGmail extends FragmentBase { }); } + private void onNoAccountSelected() { + AccountManager am = AccountManager.get(getContext()); + Account[] accounts = am.getAccountsByType(TYPE_GOOGLE); + if (accounts.length == 0) + ToastEx.makeText(getContext(), R.string.title_no_account, Toast.LENGTH_LONG).show(); + } + private void onAccountSelected(Intent data) { String name = data.getStringExtra(AccountManager.KEY_ACCOUNT_NAME); String type = data.getStringExtra(AccountManager.KEY_ACCOUNT_TYPE); diff --git a/app/src/main/java/eu/faircode/email/FragmentSetup.java b/app/src/main/java/eu/faircode/email/FragmentSetup.java index c9a8e5c2bd..ede89fb1a9 100644 --- a/app/src/main/java/eu/faircode/email/FragmentSetup.java +++ b/app/src/main/java/eu/faircode/email/FragmentSetup.java @@ -192,7 +192,7 @@ public class FragmentSetup extends FragmentBase { LocalBroadcastManager lbm = LocalBroadcastManager.getInstance(getContext()); switch (item.getItemId()) { case R.string.title_setup_gmail: - if (Helper.hasValidFingerprint(getContext())) + if (Helper.hasValidFingerprint(getContext()) || BuildConfig.DEBUG) lbm.sendBroadcast(new Intent(ActivitySetup.ACTION_QUICK_GMAIL)); else ToastEx.makeText(getContext(), R.string.title_setup_gmail_support, Toast.LENGTH_LONG).show();