Toast for no accounts

pull/178/head
M66B 5 years ago
parent 94e155e652
commit 478a408222

@ -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);

@ -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();

Loading…
Cancel
Save