Skip to content

Commit

Permalink
On-Boot: Block swipe/drage profiles and scripts
Browse files Browse the repository at this point in the history
Also, cosmetic changes for consistency

Signed-off-by: sunilpaulmathew <sunil.kde@gmail.com>
  • Loading branch information
sunilpaulmathew committed May 19, 2020
1 parent a6865be commit bea1586
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 26 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@
import com.smartpack.kernelmanager.utils.ViewUtils;
import com.smartpack.kernelmanager.utils.tools.ScriptManager;
import com.smartpack.kernelmanager.views.dialog.Dialog;
import com.smartpack.kernelmanager.views.recyclerview.DescriptionView;
import com.smartpack.kernelmanager.views.recyclerview.RecyclerViewItem;
import com.smartpack.kernelmanager.views.recyclerview.SwipeableDescriptionView;

Expand Down Expand Up @@ -145,31 +144,14 @@ private void load(List<RecyclerViewItem> items) {
applyOnBootView.setDrawable(ViewUtils.getColoredIcon(R.drawable.ic_drag_handle, requireContext()));
applyOnBootView.setSummary(applyOnBootItem.mCategory.replace("_onboot", "")
+ ": " + applyOnBootItem.mCommand);


applyOnBootView.setOnItemSwipedListener((item, position) -> {
mSettings.delete(position);
mSettings.commit();
//reload();
});

applyOnBootView.setOnItemDragListener((item, fromPosition, toPosition) -> {
mSettings.swap(fromPosition, toPosition);
mSettings.commit();
//reload();
});

// Maybe comment this out
applyOnBootView.setOnItemClickListener(item -> {
mDeleteDialog = ViewUtils.dialogBuilder(getString(R.string.delete_question,
applyOnBootItem.mCommand),
(dialogInterface, i1) -> {
}, (dialogInterface, i1) -> {
mSettings.delete(applyOnBootItem.mPosition);
mSettings.commit();
reload();
}, dialogInterface -> mDeleteDialog = null, getActivity());
mDeleteDialog.show();
});

applyOnBoot.add(applyOnBootView);
Expand All @@ -182,9 +164,9 @@ private void load(List<RecyclerViewItem> items) {
List<RecyclerViewItem> profiles = new ArrayList<>();
for (final Profiles.ProfileItem profileItem : mProfiles.getAllProfiles()) {
if (profileItem.isOnBootEnabled()) {
DescriptionView profileView = new DescriptionView();
profileView.setTitle("[" + getString(R.string.profile) + "]");
profileView.setSummary(profileItem.getName());
SwipeableDescriptionView profileView = new SwipeableDescriptionView();
profileView.setDrawable(ViewUtils.getColoredIcon(R.drawable.ic_drag_handle, requireContext()));
profileView.setSummary(getString(R.string.profile) + ": " + profileItem.getName());
profileView.setOnItemClickListener(item -> {
mDeleteDialog = ViewUtils.dialogBuilder(getString(R.string.disable_question,
profileItem.getName()),
Expand All @@ -196,6 +178,14 @@ private void load(List<RecyclerViewItem> items) {
}, dialogInterface -> mDeleteDialog = null, getActivity());
mDeleteDialog.show();
});
profileView.setOnItemSwipedListener((item, position) -> {
Utils.snackbar(getRootView(), getString(R.string.swipe_message, getString(R.string.profile)));
reload();
});
profileView.setOnItemDragListener((item, fromPosition, toPosition) -> {
Utils.snackbar(getRootView(), getString(R.string.drag_message, getString(R.string.profile)));
reload();
});

profiles.add(profileView);
}
Expand All @@ -210,8 +200,8 @@ private void load(List<RecyclerViewItem> items) {
final Set<String> onBootScripts = Prefs.getStringSet("on_boot_scripts", new HashSet<>(), getActivity());
for (final String script : ScriptManager.list()) {
if (script_onboot && Utils.getExtension(script).equals("sh")) {
DescriptionView scriptItem = new DescriptionView();
scriptItem.setTitle("[Script]");
SwipeableDescriptionView scriptItem = new SwipeableDescriptionView();
scriptItem.setDrawable(ViewUtils.getColoredIcon(R.drawable.ic_drag_handle, requireContext()));
scriptItem.setSummary(getString(R.string.script_manger) + ": " + script);
scriptItem.setOnItemClickListener(item -> {
mDeleteDialog = ViewUtils.dialogBuilder(getString(R.string.remove_script_question, script),
Expand All @@ -225,12 +215,20 @@ private void load(List<RecyclerViewItem> items) {
}, dialogInterface -> mDeleteDialog = null, getActivity());
mDeleteDialog.show();
});
scriptItem.setOnItemSwipedListener((item, position) -> {
Utils.snackbar(getRootView(), getString(R.string.swipe_message, getString(R.string.script)));
reload();
});
scriptItem.setOnItemDragListener((item, fromPosition, toPosition) -> {
Utils.snackbar(getRootView(), getString(R.string.drag_message, getString(R.string.script)));
reload();
});

items.add(scriptItem);
} else if (Prefs.getStringSet("on_boot_scripts", new HashSet<>(), getActivity()).contains(script)
&& Utils.getExtension(script).equals("sh")) {
DescriptionView scriptItem = new DescriptionView();
scriptItem.setTitle("[Script]");
SwipeableDescriptionView scriptItem = new SwipeableDescriptionView();
scriptItem.setDrawable(ViewUtils.getColoredIcon(R.drawable.ic_drag_handle, requireContext()));
scriptItem.setSummary(getString(R.string.script_manger) + ": " + script);
scriptItem.setOnItemClickListener(item -> {
mDeleteDialog = ViewUtils.dialogBuilder(getString(R.string.delete_question, script),
Expand All @@ -241,6 +239,14 @@ private void load(List<RecyclerViewItem> items) {
}, dialogInterface -> mDeleteDialog = null, getActivity());
mDeleteDialog.show();
});
scriptItem.setOnItemSwipedListener((item, position) -> {
Utils.snackbar(getRootView(), getString(R.string.swipe_message, getString(R.string.script)));
reload();
});
scriptItem.setOnItemDragListener((item, fromPosition, toPosition) -> {
Utils.snackbar(getRootView(), getString(R.string.drag_message, getString(R.string.script)));
reload();
});

items.add(scriptItem);
}
Expand Down
4 changes: 3 additions & 1 deletion app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -972,9 +972,11 @@
<string name="share_script">To apply this script, simply import this file on \'SmartPack-Kernel Manager -> Script Manager -> Import\'.</string>

<!-- On Boot -->
<string name="on_boot_welcome_summary">This section shows you what things will happen when your device boots up. If it\'s blank, then nothing will happen after boot.</string>
<string name="on_boot_welcome_summary">This section shows you what things will happen when your device boots up. If it\'s blank, then nothing will happen after boot. You can swipe left or right to remove a command (not a profile or script)!</string>
<string name="delete_question">Delete %s?</string>
<string name="disable_question">Disable %s?</string>
<string name="swipe_message">Sorry! You can\'t swipe out a %s.</string>
<string name="drag_message">Sorry! You can\'t drag a %s into different position.</string>

<!-- SmartPack -->
<string name="acquiring">Acquiring update info</string>
Expand Down

0 comments on commit bea1586

Please sign in to comment.