Ask to select scope apps when enabling modules
This commit is contained in:
parent
6e765a7a08
commit
125ef3589f
|
|
@ -48,7 +48,7 @@ public class AppAdapter extends RecyclerView.Adapter<AppAdapter.ViewHolder> impl
|
|||
private final ApplicationInfo.DisplayNameComparator displayNameComparator;
|
||||
protected List<PackageInfo> fullList, showList;
|
||||
private final DateFormat dateformat = new SimpleDateFormat("yyyy-MM-dd", Locale.getDefault());
|
||||
private List<String> checkedList;
|
||||
public List<String> checkedList;
|
||||
private final PackageManager pm;
|
||||
private final ApplicationFilter filter;
|
||||
private Comparator<PackageInfo> cmp;
|
||||
|
|
|
|||
|
|
@ -145,7 +145,7 @@ public class AppHelper {
|
|||
return s;
|
||||
}
|
||||
|
||||
static List<String> getScopeList(String modulePackageName) {
|
||||
public static List<String> getScopeList(String modulePackageName) {
|
||||
if (scopeList.containsKey(modulePackageName)) {
|
||||
return scopeList.get(modulePackageName);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,6 +1,7 @@
|
|||
package io.github.lsposed.manager.adapters;
|
||||
|
||||
import android.content.pm.PackageInfo;
|
||||
import android.util.Log;
|
||||
import android.widget.CompoundButton;
|
||||
|
||||
import com.google.android.material.snackbar.Snackbar;
|
||||
|
|
@ -11,6 +12,7 @@ import java.util.List;
|
|||
import io.github.lsposed.manager.R;
|
||||
import io.github.lsposed.manager.ui.activity.AppListActivity;
|
||||
import io.github.lsposed.manager.ui.widget.MasterSwitch;
|
||||
import io.github.lsposed.manager.util.ModuleUtil;
|
||||
|
||||
public class ScopeAdapter extends AppAdapter {
|
||||
|
||||
|
|
@ -26,8 +28,9 @@ public class ScopeAdapter extends AppAdapter {
|
|||
masterSwitch.setOnCheckedChangedListener(new MasterSwitch.OnCheckedChangeListener() {
|
||||
@Override
|
||||
public void onCheckedChanged(boolean checked) {
|
||||
Log.e("Test", checked + "");
|
||||
enabled = checked;
|
||||
AppHelper.saveScopeList(modulePackageName, enabled ? checkedList : new ArrayList<>());
|
||||
ModuleUtil.getInstance().setModuleEnabled(modulePackageName, enabled);
|
||||
notifyDataSetChanged();
|
||||
}
|
||||
});
|
||||
|
|
@ -43,7 +46,7 @@ public class ScopeAdapter extends AppAdapter {
|
|||
}
|
||||
scopeList.retainAll(list);
|
||||
checkedList = scopeList;
|
||||
enabled = checkedList.size() != 0;
|
||||
enabled = ModuleUtil.getInstance().isModuleEnabled(modulePackageName);
|
||||
activity.runOnUiThread(() -> masterSwitch.setChecked(enabled));
|
||||
return checkedList;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -16,6 +16,7 @@ import androidx.appcompat.app.ActionBar;
|
|||
import androidx.appcompat.widget.SearchView;
|
||||
import androidx.recyclerview.widget.DividerItemDecoration;
|
||||
|
||||
import com.google.android.material.dialog.MaterialAlertDialogBuilder;
|
||||
import com.google.android.material.snackbar.Snackbar;
|
||||
|
||||
import io.github.lsposed.manager.R;
|
||||
|
|
@ -24,6 +25,7 @@ import io.github.lsposed.manager.adapters.ScopeAdapter;
|
|||
import io.github.lsposed.manager.adapters.WhiteListAdapter;
|
||||
import io.github.lsposed.manager.databinding.ActivityScopeListBinding;
|
||||
import io.github.lsposed.manager.util.LinearLayoutManagerFix;
|
||||
import io.github.lsposed.manager.util.ModuleUtil;
|
||||
import me.zhanghai.android.fastscroll.FastScrollerBuilder;
|
||||
|
||||
public class AppListActivity extends BaseActivity {
|
||||
|
|
@ -39,16 +41,17 @@ public class AppListActivity extends BaseActivity {
|
|||
}
|
||||
};
|
||||
private final Handler handler = new Handler(Looper.getMainLooper());
|
||||
private String modulePackageName;
|
||||
|
||||
@Override
|
||||
public void onCreate(@Nullable Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
String modulePackageName = getIntent().getStringExtra("modulePackageName");
|
||||
modulePackageName = getIntent().getStringExtra("modulePackageName");
|
||||
String moduleName = getIntent().getStringExtra("moduleName");
|
||||
binding = ActivityScopeListBinding.inflate(getLayoutInflater());
|
||||
setContentView(binding.getRoot());
|
||||
setSupportActionBar(binding.toolbar);
|
||||
binding.toolbar.setNavigationOnClickListener(view -> finish());
|
||||
binding.toolbar.setNavigationOnClickListener(view -> onBackPressed());
|
||||
ActionBar bar = getSupportActionBar();
|
||||
assert bar != null;
|
||||
bar.setDisplayHomeAsUpEnabled(true);
|
||||
|
|
@ -117,7 +120,18 @@ public class AppListActivity extends BaseActivity {
|
|||
@Override
|
||||
public void onBackPressed() {
|
||||
if (searchView.isIconified()) {
|
||||
super.onBackPressed();
|
||||
if (binding.masterSwitch.isChecked() && appAdapter.checkedList.isEmpty()) {
|
||||
new MaterialAlertDialogBuilder(this)
|
||||
.setMessage(R.string.no_scope_selected)
|
||||
.setPositiveButton(android.R.string.cancel, null)
|
||||
.setNegativeButton(android.R.string.ok, (dialog, which) -> {
|
||||
ModuleUtil.getInstance().setModuleEnabled(modulePackageName, false);
|
||||
super.onBackPressed();
|
||||
})
|
||||
.show();
|
||||
} else {
|
||||
super.onBackPressed();
|
||||
}
|
||||
} else {
|
||||
searchView.setIconified(true);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -48,6 +48,7 @@ import io.github.lsposed.manager.BuildConfig;
|
|||
import io.github.lsposed.manager.Constants;
|
||||
import io.github.lsposed.manager.R;
|
||||
import io.github.lsposed.manager.adapters.AppAdapter;
|
||||
import io.github.lsposed.manager.adapters.AppHelper;
|
||||
import io.github.lsposed.manager.databinding.ActivityModulesBinding;
|
||||
import io.github.lsposed.manager.util.GlideApp;
|
||||
import io.github.lsposed.manager.util.LinearLayoutManagerFix;
|
||||
|
|
@ -205,7 +206,6 @@ public class ModulesActivity extends BaseActivity implements ModuleUtil.ModuleLi
|
|||
}
|
||||
fastScrollerBuilder.build();
|
||||
binding.swipeRefreshLayout.setOnRefreshListener(reloadModules::run);
|
||||
reloadModules.run();
|
||||
mSearchListener = new SearchView.OnQueryTextListener() {
|
||||
@Override
|
||||
public boolean onQueryTextSubmit(String query) {
|
||||
|
|
@ -222,6 +222,12 @@ public class ModulesActivity extends BaseActivity implements ModuleUtil.ModuleLi
|
|||
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onResume() {
|
||||
super.onResume();
|
||||
reloadModules.run();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onCreateOptionsMenu(Menu menu) {
|
||||
getMenuInflater().inflate(R.menu.menu_modules, menu);
|
||||
|
|
@ -521,6 +527,14 @@ public class ModulesActivity extends BaseActivity implements ModuleUtil.ModuleLi
|
|||
String packageName = item.packageName;
|
||||
boolean changed = moduleUtil.isModuleEnabled(packageName) ^ isChecked;
|
||||
if (changed) {
|
||||
if (isChecked && AppHelper.getScopeList(packageName).isEmpty()) {
|
||||
moduleUtil.setModuleEnabled(packageName, true);
|
||||
Intent intent = new Intent(ModulesActivity.this, AppListActivity.class);
|
||||
intent.putExtra("modulePackageName", packageName);
|
||||
intent.putExtra("moduleName", item.getAppName());
|
||||
startActivity(intent);
|
||||
return;
|
||||
}
|
||||
moduleUtil.setModuleEnabled(packageName, isChecked);
|
||||
moduleUtil.updateModulesList(true, binding.snackbar);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -55,7 +55,7 @@ public class MasterSwitch extends FrameLayout implements View.OnClickListener, C
|
|||
setBackground(drawable);
|
||||
|
||||
TextView masterTitle = findViewById(android.R.id.title);
|
||||
masterTitle.setText(R.string.enable_scope);
|
||||
masterTitle.setText(R.string.enable_module);
|
||||
switchCompat = findViewById(R.id.switchWidget);
|
||||
|
||||
setOnClickListener(this);
|
||||
|
|
|
|||
|
|
@ -144,7 +144,9 @@ public final class ModuleUtil {
|
|||
|
||||
public void setModuleEnabled(String packageName, boolean enabled) {
|
||||
if (enabled) {
|
||||
enabledModules.add(packageName);
|
||||
if (!enabledModules.contains(packageName)) {
|
||||
enabledModules.add(packageName);
|
||||
}
|
||||
} else {
|
||||
enabledModules.remove(packageName);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -169,4 +169,6 @@
|
|||
<string name="menu_sort">排序…</string>
|
||||
<string name="blacklist_summary">%d 个应用位于黑名单中</string>
|
||||
<string name="whitelist_summary">%d 个应用位于白名单中</string>
|
||||
<string name="enable_module">启用模块</string>
|
||||
<string name="no_scope_selected">未选择任何应用。继续?</string>
|
||||
</resources>
|
||||
|
|
|
|||
|
|
@ -177,4 +177,6 @@
|
|||
<string name="menu_sort">Sorting…</string>
|
||||
<string name="blacklist_summary">%d apps blacklisted</string>
|
||||
<string name="whitelist_summary">%d apps whitelisted</string>
|
||||
<string name="enable_module">Enable module</string>
|
||||
<string name="no_scope_selected">You did not select any app. Continue?</string>
|
||||
</resources>
|
||||
|
|
|
|||
Loading…
Reference in New Issue