Prevent crash

pull/152/head
M66B 6 years ago
parent 8508a936fc
commit fb5752f708

@ -57,6 +57,7 @@ import java.io.OutputStream;
import java.security.SecureRandom;
import java.security.spec.KeySpec;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.Objects;
@ -138,6 +139,9 @@ public class ActivitySetup extends ActivityBilling implements FragmentManager.On
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
DrawerItem item = drawerArray.getItem(position);
if (item == null)
return;
switch (item.getMenuId()) {
case R.string.title_setup_export:
onMenuExport();
@ -179,6 +183,9 @@ public class ActivitySetup extends ActivityBilling implements FragmentManager.On
@Override
public boolean onItemLongClick(AdapterView<?> parent, View view, int position, long id) {
DrawerItem item = drawerArray.getItem(position);
if (item == null)
return false;
if (item.getMenuId() == R.string.menu_privacy) {
new SimpleTask<Void>() {
@Override
@ -200,36 +207,40 @@ public class ActivitySetup extends ActivityBilling implements FragmentManager.On
}
});
List<DrawerItem> items = new ArrayList<>();
PackageManager pm = getPackageManager();
if (getIntentExport().resolveActivity(pm) != null)
drawerArray.add(new DrawerItem(-1, R.string.title_setup_export, R.drawable.baseline_archive_24));
items.add(new DrawerItem(-1, R.string.title_setup_export, R.drawable.baseline_archive_24));
if (getIntentImport().resolveActivity(pm) != null)
drawerArray.add(new DrawerItem(-2, R.string.title_setup_import, R.drawable.baseline_unarchive_24));
items.add(new DrawerItem(-2, R.string.title_setup_import, R.drawable.baseline_unarchive_24));
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this);
String theme = prefs.getString("theme", "system");
if ("light".equals(theme))
drawerArray.add(new DrawerItem(-3, R.string.title_setup_dark_theme, R.drawable.baseline_palette_24));
items.add(new DrawerItem(-3, R.string.title_setup_dark_theme, R.drawable.baseline_palette_24));
else if ("dark".equals(theme))
drawerArray.add(new DrawerItem(-4, R.string.title_setup_black_theme, R.drawable.baseline_palette_24));
items.add(new DrawerItem(-4, R.string.title_setup_black_theme, R.drawable.baseline_palette_24));
else if ("black".equals(theme))
drawerArray.add(new DrawerItem(-5, R.string.title_setup_system_theme, R.drawable.baseline_palette_24));
items.add(new DrawerItem(-5, R.string.title_setup_system_theme, R.drawable.baseline_palette_24));
else
drawerArray.add(new DrawerItem(-6, R.string.title_setup_light_theme, R.drawable.baseline_palette_24));
items.add(new DrawerItem(-6, R.string.title_setup_light_theme, R.drawable.baseline_palette_24));
if (getIntentNotifications(this).resolveActivity(pm) != null)
drawerArray.add(new DrawerItem(-7, R.string.title_setup_notifications, R.drawable.baseline_notifications_24));
items.add(new DrawerItem(-7, R.string.title_setup_notifications, R.drawable.baseline_notifications_24));
drawerArray.add(new DrawerItem(-8, R.string.title_setup_advanced, R.drawable.baseline_settings_applications_24));
items.add(new DrawerItem(-8, R.string.title_setup_advanced, R.drawable.baseline_settings_applications_24));
drawerArray.add(new DrawerItem(-9));
items.add(new DrawerItem(-9));
drawerArray.add(new DrawerItem(-10, R.string.menu_legend, R.drawable.baseline_help_24));
items.add(new DrawerItem(-10, R.string.menu_legend, R.drawable.baseline_help_24));
if (Helper.getIntentFAQ().resolveActivity(getPackageManager()) != null)
drawerArray.add(new DrawerItem(-11, R.string.menu_faq, R.drawable.baseline_question_answer_24));
items.add(new DrawerItem(-11, R.string.menu_faq, R.drawable.baseline_question_answer_24));
if (Helper.getIntentPrivacy().resolveActivity(getPackageManager()) != null)
drawerArray.add(new DrawerItem(-12, R.string.menu_privacy, R.drawable.baseline_account_box_24));
drawerArray.add(new DrawerItem(-13, R.string.menu_about, R.drawable.baseline_info_24));
items.add(new DrawerItem(-12, R.string.menu_privacy, R.drawable.baseline_account_box_24));
items.add(new DrawerItem(-13, R.string.menu_about, R.drawable.baseline_info_24));
drawerArray.set(items);
getSupportFragmentManager().addOnBackStackChangedListener(this);

@ -178,6 +178,9 @@ public class ActivityView extends ActivityBilling implements FragmentManager.OnB
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
DrawerItem item = drawerArray.getItem(position);
if (item == null)
return;
switch (item.getMenuId()) {
case R.string.menu_answers:
onMenuAnswers();
@ -229,6 +232,9 @@ public class ActivityView extends ActivityBilling implements FragmentManager.OnB
@Override
public boolean onItemLongClick(AdapterView<?> parent, View view, int position, long id) {
DrawerItem item = drawerArray.getItem(position);
if (item == null)
return false;
switch (item.getMenuId()) {
case R.string.menu_operations:
onShowLog();
@ -303,33 +309,33 @@ public class ActivityView extends ActivityBilling implements FragmentManager.OnB
return;
last = accounts;
drawerArray.clear();
List<DrawerItem> items = new ArrayList<>();
for (TupleAccountEx account : accounts)
drawerArray.add(new DrawerItem(
items.add(new DrawerItem(
account.id,
"connected".equals(account.state) ? R.drawable.baseline_folder_24 : R.drawable.baseline_folder_open_24,
account.color,
account.unseen > 0 ? getString(R.string.title_unseen_count, account.name, account.unseen) : account.toString(),
account.unseen > 0));
drawerArray.add(new DrawerItem(-1));
drawerArray.add(new DrawerItem(-2, R.string.menu_answers, R.drawable.baseline_reply_24));
drawerArray.add(new DrawerItem(-3, R.string.menu_operations, R.drawable.baseline_list_24));
drawerArray.add(new DrawerItem(-4, R.string.menu_setup, R.drawable.baseline_settings_applications_24));
drawerArray.add(new DrawerItem(-5));
drawerArray.add(new DrawerItem(-6, R.string.menu_legend, R.drawable.baseline_help_24));
items.add(new DrawerItem(-1));
items.add(new DrawerItem(-2, R.string.menu_answers, R.drawable.baseline_reply_24));
items.add(new DrawerItem(-3, R.string.menu_operations, R.drawable.baseline_list_24));
items.add(new DrawerItem(-4, R.string.menu_setup, R.drawable.baseline_settings_applications_24));
items.add(new DrawerItem(-5));
items.add(new DrawerItem(-6, R.string.menu_legend, R.drawable.baseline_help_24));
if (Helper.getIntentFAQ().resolveActivity(getPackageManager()) != null)
drawerArray.add(new DrawerItem(-7, R.string.menu_faq, R.drawable.baseline_question_answer_24));
items.add(new DrawerItem(-7, R.string.menu_faq, R.drawable.baseline_question_answer_24));
if (BuildConfig.BETA_RELEASE)
drawerArray.add(new DrawerItem(-8, R.string.menu_issue, R.drawable.baseline_report_problem_24));
items.add(new DrawerItem(-8, R.string.menu_issue, R.drawable.baseline_report_problem_24));
if (Helper.getIntentPrivacy().resolveActivity(getPackageManager()) != null)
drawerArray.add(new DrawerItem(-9, R.string.menu_privacy, R.drawable.baseline_account_box_24));
items.add(new DrawerItem(-9, R.string.menu_privacy, R.drawable.baseline_account_box_24));
drawerArray.add(new DrawerItem(-10, R.string.menu_about, R.drawable.baseline_info_24));
items.add(new DrawerItem(-10, R.string.menu_about, R.drawable.baseline_info_24));
boolean pro = (getIntentPro() == null || getIntentPro().resolveActivity(getPackageManager()) != null);
boolean invite = (getIntentInvite().resolveActivity(getPackageManager()) != null);
@ -337,19 +343,21 @@ public class ActivityView extends ActivityBilling implements FragmentManager.OnB
boolean other = (getIntentOtherApps().resolveActivity(getPackageManager()) != null);
if (pro || invite || rate || other)
drawerArray.add(new DrawerItem(-11));
items.add(new DrawerItem(-11));
if (pro)
drawerArray.add(new DrawerItem(-12, R.string.menu_pro, R.drawable.baseline_monetization_on_24));
items.add(new DrawerItem(-12, R.string.menu_pro, R.drawable.baseline_monetization_on_24));
if (invite)
drawerArray.add(new DrawerItem(-13, R.string.menu_invite, R.drawable.baseline_people_24));
items.add(new DrawerItem(-13, R.string.menu_invite, R.drawable.baseline_people_24));
if (rate)
drawerArray.add(new DrawerItem(-14, R.string.menu_rate, R.drawable.baseline_star_24));
items.add(new DrawerItem(-14, R.string.menu_rate, R.drawable.baseline_star_24));
if (other)
drawerArray.add(new DrawerItem(-15, R.string.menu_other, R.drawable.baseline_get_app_24));
items.add(new DrawerItem(-15, R.string.menu_other, R.drawable.baseline_get_app_24));
drawerArray.set(items);
}
});

@ -8,9 +8,15 @@ import android.widget.ArrayAdapter;
import android.widget.ImageView;
import android.widget.TextView;
import java.util.ArrayList;
import java.util.List;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
public class DrawerAdapter extends ArrayAdapter<DrawerItem> {
private List<DrawerItem> items = new ArrayList<>();
DrawerAdapter(@NonNull Context context) {
super(context, -1);
}
@ -39,6 +45,25 @@ public class DrawerAdapter extends ArrayAdapter<DrawerItem> {
return row;
}
void set(List<DrawerItem> items) {
this.items = items;
notifyDataSetChanged();
}
@Override
public int getCount() {
return items.size();
}
@Nullable
@Override
public DrawerItem getItem(int position) {
if (position < items.size())
return items.get(position);
else
return null;
}
@Override
public boolean hasStableIds() {
return true;

Loading…
Cancel
Save