[app] Fix crash when module no longer exists (#536)
This commit is contained in:
parent
20c2f872ad
commit
11801e0145
|
|
@ -94,9 +94,9 @@ public class ScopeAdapter extends RecyclerView.Adapter<ScopeAdapter.ViewHolder>
|
||||||
private final PackageManager pm;
|
private final PackageManager pm;
|
||||||
private final SharedPreferences preferences;
|
private final SharedPreferences preferences;
|
||||||
private final Handler loadAppListHandler;
|
private final Handler loadAppListHandler;
|
||||||
|
private final ModuleUtil moduleUtil;
|
||||||
|
|
||||||
private final String modulePackageName;
|
private final ModuleUtil.InstalledModule module;
|
||||||
private final String moduleName;
|
|
||||||
|
|
||||||
private final HashSet<ApplicationWithEquals> recommendedList = new HashSet<>();
|
private final HashSet<ApplicationWithEquals> recommendedList = new HashSet<>();
|
||||||
private final HashSet<ApplicationWithEquals> checkedList = new HashSet<>();
|
private final HashSet<ApplicationWithEquals> checkedList = new HashSet<>();
|
||||||
|
|
@ -106,7 +106,7 @@ public class ScopeAdapter extends RecyclerView.Adapter<ScopeAdapter.ViewHolder>
|
||||||
private final SwitchBar.OnCheckedChangeListener switchBarOnCheckedChangeListener = new SwitchBar.OnCheckedChangeListener() {
|
private final SwitchBar.OnCheckedChangeListener switchBarOnCheckedChangeListener = new SwitchBar.OnCheckedChangeListener() {
|
||||||
@Override
|
@Override
|
||||||
public boolean onCheckedChanged(SwitchBar view, boolean isChecked) {
|
public boolean onCheckedChanged(SwitchBar view, boolean isChecked) {
|
||||||
if (!ModuleUtil.getInstance().setModuleEnabled(modulePackageName, isChecked)) {
|
if (!moduleUtil.setModuleEnabled(module.packageName, isChecked)) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
enabled = isChecked;
|
enabled = isChecked;
|
||||||
|
|
@ -131,16 +131,15 @@ public class ScopeAdapter extends RecyclerView.Adapter<ScopeAdapter.ViewHolder>
|
||||||
private boolean refreshing = false;
|
private boolean refreshing = false;
|
||||||
private boolean enabled = true;
|
private boolean enabled = true;
|
||||||
|
|
||||||
public ScopeAdapter(AppListActivity activity, String moduleName, String modulePackageName) {
|
public ScopeAdapter(AppListActivity activity, ModuleUtil.InstalledModule module) {
|
||||||
this.activity = activity;
|
this.activity = activity;
|
||||||
this.moduleName = moduleName;
|
this.module = module;
|
||||||
this.modulePackageName = modulePackageName;
|
moduleUtil = ModuleUtil.getInstance();
|
||||||
HandlerThread handlerThread = new HandlerThread("appList");
|
HandlerThread handlerThread = new HandlerThread("appList");
|
||||||
handlerThread.start();
|
handlerThread.start();
|
||||||
loadAppListHandler = new Handler(handlerThread.getLooper(), this);
|
loadAppListHandler = new Handler(handlerThread.getLooper(), this);
|
||||||
preferences = App.getPreferences();
|
preferences = App.getPreferences();
|
||||||
pm = activity.getPackageManager();
|
pm = activity.getPackageManager();
|
||||||
refresh(false);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@NonNull
|
@NonNull
|
||||||
|
|
@ -151,7 +150,7 @@ public class ScopeAdapter extends RecyclerView.Adapter<ScopeAdapter.ViewHolder>
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean shouldHideApp(PackageInfo info, ApplicationWithEquals app) {
|
private boolean shouldHideApp(PackageInfo info, ApplicationWithEquals app) {
|
||||||
if (info.packageName.equals(this.modulePackageName)) {
|
if (info.packageName.equals(this.module.packageName)) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
if (info.packageName.equals(BuildConfig.APPLICATION_ID)) {
|
if (info.packageName.equals(BuildConfig.APPLICATION_ID)) {
|
||||||
|
|
@ -221,7 +220,7 @@ public class ScopeAdapter extends RecyclerView.Adapter<ScopeAdapter.ViewHolder>
|
||||||
private void checkRecommended() {
|
private void checkRecommended() {
|
||||||
checkedList.clear();
|
checkedList.clear();
|
||||||
checkedList.addAll(recommendedList);
|
checkedList.addAll(recommendedList);
|
||||||
ConfigManager.setModuleScope(modulePackageName, checkedList);
|
ConfigManager.setModuleScope(module.packageName, checkedList);
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean onOptionsItemSelected(MenuItem item) {
|
public boolean onOptionsItemSelected(MenuItem item) {
|
||||||
|
|
@ -251,7 +250,7 @@ public class ScopeAdapter extends RecyclerView.Adapter<ScopeAdapter.ViewHolder>
|
||||||
item.setChecked(!item.isChecked());
|
item.setChecked(!item.isChecked());
|
||||||
preferences.edit().putBoolean("filter_modules", item.isChecked()).apply();
|
preferences.edit().putBoolean("filter_modules", item.isChecked()).apply();
|
||||||
} else if (itemId == R.id.menu_launch) {
|
} else if (itemId == R.id.menu_launch) {
|
||||||
Intent launchIntent = AppHelper.getSettingsIntent(modulePackageName, pm);
|
Intent launchIntent = AppHelper.getSettingsIntent(module.packageName, pm);
|
||||||
if (launchIntent != null) {
|
if (launchIntent != null) {
|
||||||
activity.startActivity(launchIntent);
|
activity.startActivity(launchIntent);
|
||||||
} else {
|
} else {
|
||||||
|
|
@ -262,7 +261,7 @@ public class ScopeAdapter extends RecyclerView.Adapter<ScopeAdapter.ViewHolder>
|
||||||
Calendar now = Calendar.getInstance();
|
Calendar now = Calendar.getInstance();
|
||||||
activity.backupLauncher.launch(String.format(Locale.US,
|
activity.backupLauncher.launch(String.format(Locale.US,
|
||||||
"%s_%04d%02d%02d_%02d%02d%02d.lsp",
|
"%s_%04d%02d%02d_%02d%02d%02d.lsp",
|
||||||
moduleName,
|
module.getAppName(),
|
||||||
now.get(Calendar.YEAR), now.get(Calendar.MONTH) + 1,
|
now.get(Calendar.YEAR), now.get(Calendar.MONTH) + 1,
|
||||||
now.get(Calendar.DAY_OF_MONTH), now.get(Calendar.HOUR_OF_DAY),
|
now.get(Calendar.DAY_OF_MONTH), now.get(Calendar.HOUR_OF_DAY),
|
||||||
now.get(Calendar.MINUTE), now.get(Calendar.SECOND)));
|
now.get(Calendar.MINUTE), now.get(Calendar.SECOND)));
|
||||||
|
|
@ -320,11 +319,11 @@ public class ScopeAdapter extends RecyclerView.Adapter<ScopeAdapter.ViewHolder>
|
||||||
|
|
||||||
public void onCreateOptionsMenu(@NonNull Menu menu, @NonNull MenuInflater inflater) {
|
public void onCreateOptionsMenu(@NonNull Menu menu, @NonNull MenuInflater inflater) {
|
||||||
inflater.inflate(R.menu.menu_app_list, menu);
|
inflater.inflate(R.menu.menu_app_list, menu);
|
||||||
Intent intent = AppHelper.getSettingsIntent(modulePackageName, pm);
|
Intent intent = AppHelper.getSettingsIntent(module.packageName, pm);
|
||||||
if (intent == null) {
|
if (intent == null) {
|
||||||
menu.removeItem(R.id.menu_launch);
|
menu.removeItem(R.id.menu_launch);
|
||||||
}
|
}
|
||||||
List<String> scopeList = ModuleUtil.getInstance().getModule(modulePackageName).getScopeList();
|
List<String> scopeList = module.getScopeList();
|
||||||
if (scopeList == null || scopeList.isEmpty()) {
|
if (scopeList == null || scopeList.isEmpty()) {
|
||||||
menu.removeItem(R.id.use_recommended);
|
menu.removeItem(R.id.use_recommended);
|
||||||
}
|
}
|
||||||
|
|
@ -470,7 +469,7 @@ public class ScopeAdapter extends RecyclerView.Adapter<ScopeAdapter.ViewHolder>
|
||||||
activity.binding.progress.setIndeterminate(true);
|
activity.binding.progress.setIndeterminate(true);
|
||||||
activity.binding.progress.setVisibility(View.VISIBLE);
|
activity.binding.progress.setVisibility(View.VISIBLE);
|
||||||
}
|
}
|
||||||
enabled = ModuleUtil.getInstance().isModuleEnabled(modulePackageName);
|
enabled = moduleUtil.isModuleEnabled(module.packageName);
|
||||||
activity.binding.masterSwitch.setOnCheckedChangeListener(null);
|
activity.binding.masterSwitch.setOnCheckedChangeListener(null);
|
||||||
activity.binding.masterSwitch.setChecked(enabled);
|
activity.binding.masterSwitch.setChecked(enabled);
|
||||||
activity.binding.masterSwitch.setOnCheckedChangeListener(switchBarOnCheckedChangeListener);
|
activity.binding.masterSwitch.setOnCheckedChangeListener(switchBarOnCheckedChangeListener);
|
||||||
|
|
@ -483,7 +482,7 @@ public class ScopeAdapter extends RecyclerView.Adapter<ScopeAdapter.ViewHolder>
|
||||||
} else {
|
} else {
|
||||||
checkedList.remove(appInfo.application);
|
checkedList.remove(appInfo.application);
|
||||||
}
|
}
|
||||||
if (!ConfigManager.setModuleScope(modulePackageName, checkedList)) {
|
if (!ConfigManager.setModuleScope(module.packageName, checkedList)) {
|
||||||
activity.makeSnackBar(R.string.failed_to_save_scope_list, Snackbar.LENGTH_SHORT);
|
activity.makeSnackBar(R.string.failed_to_save_scope_list, Snackbar.LENGTH_SHORT);
|
||||||
if (!isChecked) {
|
if (!isChecked) {
|
||||||
checkedList.add(appInfo.application);
|
checkedList.add(appInfo.application);
|
||||||
|
|
@ -509,9 +508,9 @@ public class ScopeAdapter extends RecyclerView.Adapter<ScopeAdapter.ViewHolder>
|
||||||
recommendedList.clear();
|
recommendedList.clear();
|
||||||
searchList.clear();
|
searchList.clear();
|
||||||
|
|
||||||
checkedList.addAll(ConfigManager.getModuleScope(modulePackageName));
|
checkedList.addAll(ConfigManager.getModuleScope(module.packageName));
|
||||||
HashSet<ApplicationWithEquals> installedList = new HashSet<>();
|
HashSet<ApplicationWithEquals> installedList = new HashSet<>();
|
||||||
List<String> scopeList = ModuleUtil.getInstance().getModule(modulePackageName).getScopeList();
|
List<String> scopeList = module.getScopeList();
|
||||||
boolean emptyCheckedList = checkedList.isEmpty();
|
boolean emptyCheckedList = checkedList.isEmpty();
|
||||||
for (PackageInfo info : appList) {
|
for (PackageInfo info : appList) {
|
||||||
int uid = info.applicationInfo.uid;
|
int uid = info.applicationInfo.uid;
|
||||||
|
|
@ -544,7 +543,7 @@ public class ScopeAdapter extends RecyclerView.Adapter<ScopeAdapter.ViewHolder>
|
||||||
}
|
}
|
||||||
checkedList.retainAll(installedList);
|
checkedList.retainAll(installedList);
|
||||||
if (emptyCheckedList) {
|
if (emptyCheckedList) {
|
||||||
ConfigManager.setModuleScope(modulePackageName, checkedList);
|
ConfigManager.setModuleScope(module.packageName, checkedList);
|
||||||
}
|
}
|
||||||
sortApps(searchList);
|
sortApps(searchList);
|
||||||
synchronized (dataReadyRunnable) {
|
synchronized (dataReadyRunnable) {
|
||||||
|
|
@ -628,8 +627,8 @@ public class ScopeAdapter extends RecyclerView.Adapter<ScopeAdapter.ViewHolder>
|
||||||
builder.setPositiveButton(android.R.string.cancel, null);
|
builder.setPositiveButton(android.R.string.cancel, null);
|
||||||
}
|
}
|
||||||
builder.setNegativeButton(!recommendedList.isEmpty() ? android.R.string.cancel : android.R.string.ok, (dialog, which) -> {
|
builder.setNegativeButton(!recommendedList.isEmpty() ? android.R.string.cancel : android.R.string.ok, (dialog, which) -> {
|
||||||
ModuleUtil.getInstance().setModuleEnabled(modulePackageName, false);
|
moduleUtil.setModuleEnabled(module.packageName, false);
|
||||||
Toast.makeText(activity, activity.getString(R.string.module_disabled_no_selection, moduleName), Toast.LENGTH_LONG).show();
|
Toast.makeText(activity, activity.getString(R.string.module_disabled_no_selection, module.getAppName()), Toast.LENGTH_LONG).show();
|
||||||
activity.finish();
|
activity.finish();
|
||||||
});
|
});
|
||||||
builder.show();
|
builder.show();
|
||||||
|
|
|
||||||
|
|
@ -44,6 +44,7 @@ import org.lsposed.manager.databinding.ActivityAppListBinding;
|
||||||
import org.lsposed.manager.ui.activity.base.BaseActivity;
|
import org.lsposed.manager.ui.activity.base.BaseActivity;
|
||||||
import org.lsposed.manager.util.BackupUtils;
|
import org.lsposed.manager.util.BackupUtils;
|
||||||
import org.lsposed.manager.util.LinearLayoutManagerFix;
|
import org.lsposed.manager.util.LinearLayoutManagerFix;
|
||||||
|
import org.lsposed.manager.util.ModuleUtil;
|
||||||
|
|
||||||
import rikka.recyclerview.RecyclerViewKt;
|
import rikka.recyclerview.RecyclerViewKt;
|
||||||
|
|
||||||
|
|
@ -60,18 +61,23 @@ public class AppListActivity extends BaseActivity {
|
||||||
public void onCreate(@Nullable Bundle savedInstanceState) {
|
public void onCreate(@Nullable Bundle savedInstanceState) {
|
||||||
super.onCreate(savedInstanceState);
|
super.onCreate(savedInstanceState);
|
||||||
String modulePackageName = getIntent().getStringExtra("modulePackageName");
|
String modulePackageName = getIntent().getStringExtra("modulePackageName");
|
||||||
String moduleName = getIntent().getStringExtra("moduleName");
|
|
||||||
binding = ActivityAppListBinding.inflate(getLayoutInflater());
|
binding = ActivityAppListBinding.inflate(getLayoutInflater());
|
||||||
setContentView(binding.getRoot());
|
setContentView(binding.getRoot());
|
||||||
setAppBar(binding.appBar, binding.toolbar);
|
setAppBar(binding.appBar, binding.toolbar);
|
||||||
binding.appBar.setRaised(true);
|
binding.appBar.setRaised(true);
|
||||||
binding.toolbar.setNavigationOnClickListener(view -> onBackPressed());
|
binding.toolbar.setNavigationOnClickListener(view -> onBackPressed());
|
||||||
|
ModuleUtil.InstalledModule module = ModuleUtil.getInstance().getModule(modulePackageName);
|
||||||
|
if (module == null) {
|
||||||
|
finish();
|
||||||
|
return;
|
||||||
|
}
|
||||||
ActionBar bar = getSupportActionBar();
|
ActionBar bar = getSupportActionBar();
|
||||||
assert bar != null;
|
if (bar != null) {
|
||||||
bar.setDisplayHomeAsUpEnabled(true);
|
bar.setDisplayHomeAsUpEnabled(true);
|
||||||
bar.setTitle(moduleName);
|
bar.setTitle(module.getAppName());
|
||||||
bar.setSubtitle(modulePackageName);
|
bar.setSubtitle(module.packageName);
|
||||||
scopeAdapter = new ScopeAdapter(this, moduleName, modulePackageName);
|
}
|
||||||
|
scopeAdapter = new ScopeAdapter(this, module);
|
||||||
scopeAdapter.setHasStableIds(true);
|
scopeAdapter.setHasStableIds(true);
|
||||||
binding.recyclerView.setAdapter(scopeAdapter);
|
binding.recyclerView.setAdapter(scopeAdapter);
|
||||||
binding.recyclerView.setHasFixedSize(true);
|
binding.recyclerView.setHasFixedSize(true);
|
||||||
|
|
@ -149,6 +155,12 @@ public class AppListActivity extends BaseActivity {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void onResume() {
|
||||||
|
super.onResume();
|
||||||
|
scopeAdapter.refresh(false);
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean onOptionsItemSelected(@NonNull MenuItem item) {
|
public boolean onOptionsItemSelected(@NonNull MenuItem item) {
|
||||||
if (scopeAdapter.onOptionsItemSelected(item)) {
|
if (scopeAdapter.onOptionsItemSelected(item)) {
|
||||||
|
|
|
||||||
|
|
@ -278,7 +278,6 @@ public class ModulesActivity extends ListActivity implements ModuleUtil.ModuleLi
|
||||||
holder.itemView.setOnClickListener(v -> {
|
holder.itemView.setOnClickListener(v -> {
|
||||||
Intent intent = new Intent(ModulesActivity.this, AppListActivity.class);
|
Intent intent = new Intent(ModulesActivity.this, AppListActivity.class);
|
||||||
intent.putExtra("modulePackageName", item.packageName);
|
intent.putExtra("modulePackageName", item.packageName);
|
||||||
intent.putExtra("moduleName", item.getAppName());
|
|
||||||
startActivity(intent);
|
startActivity(intent);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -53,7 +53,6 @@ public final class NotificationUtil {
|
||||||
|
|
||||||
Intent intent = new Intent(context, AppListActivity.class)
|
Intent intent = new Intent(context, AppListActivity.class)
|
||||||
.putExtra("modulePackageName", modulePackageName)
|
.putExtra("modulePackageName", modulePackageName)
|
||||||
.putExtra("moduleName", moduleName)
|
|
||||||
.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
|
.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
|
||||||
|
|
||||||
PendingIntent contentIntent = PendingIntent.getActivity(context, PENDING_INTENT_OPEN_APP_LIST, intent, PendingIntent.FLAG_UPDATE_CURRENT | PendingIntent.FLAG_IMMUTABLE);
|
PendingIntent contentIntent = PendingIntent.getActivity(context, PENDING_INTENT_OPEN_APP_LIST, intent, PendingIntent.FLAG_UPDATE_CURRENT | PendingIntent.FLAG_IMMUTABLE);
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue