Reordered provider selection

pull/212/head
M66B 2 years ago
parent 9ad511fc7c
commit a39b3d4569

@ -642,8 +642,11 @@ public class ActivitySetup extends ActivityBase implements FragmentManager.OnBac
}
private void onQuickSetup(Intent intent) {
Bundle args = new Bundle();
args.putInt("title", intent.getIntExtra("title", R.string.title_setup_other));
FragmentQuickSetup fragment = new FragmentQuickSetup();
fragment.setArguments(new Bundle());
fragment.setArguments(args);
FragmentTransaction fragmentTransaction = getSupportFragmentManager().beginTransaction();
fragmentTransaction.replace(R.id.content_frame, fragment).addToBackStack("quick");
fragmentTransaction.commit();

@ -101,6 +101,7 @@ public class FragmentQuickSetup extends FragmentBase {
private Group grpCertificate;
private Group grpError;
private int title;
private boolean update;
private EmailProvider bestProvider = null;
private Bundle bestArgs = null;
@ -119,6 +120,7 @@ public class FragmentQuickSetup extends FragmentBase {
super.onCreate(savedInstanceState);
Bundle args = getArguments();
title = args.getInt("title", R.string.title_setup_other);
update = args.getBoolean("update", true);
lockOrientation();
@ -127,7 +129,7 @@ public class FragmentQuickSetup extends FragmentBase {
@Override
@Nullable
public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
setSubtitle(R.string.title_setup_other);
setSubtitle(title);
setHasOptionsMenu(true);
view = (ViewGroup) inflater.inflate(R.layout.fragment_quick_setup, container, false);

@ -291,14 +291,21 @@ public class FragmentSetup extends FragmentBase implements SharedPreferences.OnS
PopupMenuLifecycle popupMenu = new PopupMenuLifecycle(context, getViewLifecycleOwner(), btnQuick);
Menu menu = popupMenu.getMenu();
Resources res = context.getResources();
String pkg = context.getPackageName();
List<EmailProvider> providers = EmailProvider.getProviders(context, debug);
int order = 1;
// OAuth
order = getMenuItems(menu, context, providers, order, false);
menu.add(Menu.NONE, R.string.title_setup_other, order++, R.string.title_setup_other)
.setIcon(R.drawable.twotone_auto_fix_high_24);
// Gmail / account manager
{
Resources res = context.getResources();
String pkg = context.getPackageName();
String gmail = getString(R.string.title_setup_android, getString(R.string.title_setup_gmail));
SpannableString ss = new SpannableString(gmail);
ss.setSpan(new RelativeSizeSpan(HtmlHelper.FONT_SMALL), 0, ss.length(), 0);
@ -308,47 +315,11 @@ public class FragmentSetup extends FragmentBase implements SharedPreferences.OnS
item.setIcon(resid);
}
// OAuth
for (EmailProvider provider : providers)
if (provider.oauth != null &&
provider.oauth.enabled &&
!TextUtils.isEmpty(provider.oauth.clientId)) {
String title = getString(R.string.title_setup_oauth, provider.description);
SpannableString ss = new SpannableString(title);
if (provider.alt)
ss.setSpan(new RelativeSizeSpan(HtmlHelper.FONT_SMALL), 0, ss.length(), 0);
MenuItem item = menu
.add(Menu.FIRST, -1, order++, ss)
.setIntent(new Intent(ActivitySetup.ACTION_QUICK_OAUTH)
.putExtra("id", provider.id)
.putExtra("name", provider.description)
.putExtra("privacy", provider.oauth.privacy)
.putExtra("askAccount", provider.oauth.askAccount)
.putExtra("askTenant", provider.oauth.askTenant())
.putExtra("pop", provider.pop != null));
// https://developers.google.com/identity/branding-guidelines
int resid = res.getIdentifier("provider_" + provider.id, "drawable", pkg);
if (resid != 0)
item.setIcon(resid);
if ("outlook".equals(provider.id))
menu.add(Menu.FIRST, R.string.title_setup_outlook, order++, R.string.title_setup_outlook);
}
menu.add(Menu.NONE, R.string.title_setup_other, order++, R.string.title_setup_other)
.setIcon(R.drawable.twotone_auto_fix_high_24);
menu.add(Menu.NONE, R.string.title_setup_classic, order++, R.string.title_setup_classic)
.setIcon(R.drawable.twotone_settings_24)
.setVisible(false);
order = getMenuItems(menu, context, providers, order, true);
SpannableString ss = new SpannableString(getString(R.string.title_setup_pop3));
ss.setSpan(new RelativeSizeSpan(HtmlHelper.FONT_SMALL), 0, ss.length(), 0);
menu.add(Menu.NONE, R.string.title_setup_pop3, order++, ss);
menu.add(Menu.NONE, R.string.menu_faq, order++, R.string.menu_faq)
.setIcon(R.drawable.twotone_support_24)
.setVisible(false);
menu.add(Menu.FIRST, R.string.title_setup_pop3, order++, ss);
popupMenu.insertIcons(context);
@ -379,7 +350,8 @@ public class FragmentSetup extends FragmentBase implements SharedPreferences.OnS
return true;
} else if (itemId == R.string.title_setup_other ||
itemId == R.string.title_setup_outlook) {
lbm.sendBroadcast(new Intent(ActivitySetup.ACTION_QUICK_SETUP));
lbm.sendBroadcast(new Intent(ActivitySetup.ACTION_QUICK_SETUP)
.putExtra("title", itemId));
return true;
} else if (itemId == R.string.title_setup_classic) {
ibManual.setPressed(true);
@ -430,6 +402,40 @@ public class FragmentSetup extends FragmentBase implements SharedPreferences.OnS
popupMenu.show();
}
private int getMenuItems(Menu menu, Context context, List<EmailProvider> providers, int order, boolean alt) {
Resources res = context.getResources();
String pkg = context.getPackageName();
for (EmailProvider provider : providers)
if (provider.oauth != null &&
provider.oauth.enabled &&
!TextUtils.isEmpty(provider.oauth.clientId) &&
provider.alt == alt) {
String title = getString(R.string.title_setup_oauth, provider.description);
SpannableString ss = new SpannableString(title);
if (provider.alt)
ss.setSpan(new RelativeSizeSpan(HtmlHelper.FONT_SMALL), 0, ss.length(), 0);
MenuItem item = menu
.add(alt ? Menu.FIRST : Menu.NONE, -1, order++, ss)
.setIntent(new Intent(ActivitySetup.ACTION_QUICK_OAUTH)
.putExtra("id", provider.id)
.putExtra("name", provider.description)
.putExtra("privacy", provider.oauth.privacy)
.putExtra("askAccount", provider.oauth.askAccount)
.putExtra("askTenant", provider.oauth.askTenant())
.putExtra("pop", provider.pop != null));
// https://developers.google.com/identity/branding-guidelines
int resid = res.getIdentifier("provider_" + provider.id, "drawable", pkg);
if (resid != 0)
item.setIcon(resid);
if ("office365pcke".equals(provider.id))
menu.add(alt ? Menu.FIRST : Menu.NONE, R.string.title_setup_outlook, order++, R.string.title_setup_outlook);
}
return order;
}
});
tvTutorials.setPaintFlags(tvTutorials.getPaintFlags() | Paint.UNDERLINE_TEXT_FLAG);

Loading…
Cancel
Save