From 31b552ab514fd33308bb7dbfd078e2df4f831047 Mon Sep 17 00:00:00 2001 From: dvdandroid Date: Sun, 21 Aug 2016 16:08:45 +0200 Subject: [PATCH] Module fragment with menu; remove and disable buttons --- .idea/.name | 1 - .idea/compiler.xml | 22 ------ .idea/encodings.xml | 6 -- .idea/gradle.xml | 28 -------- .idea/misc.xml | 62 ----------------- .idea/modules.xml | 11 --- .idea/runConfigurations.xml | 12 ---- .../com/topjohnwu/magisk/model/Module.java | 22 +++++- .../magisk/rv/ItemClickListener.java | 9 +++ .../topjohnwu/magisk/rv/ModulesAdapter.java | 28 ++++---- .../topjohnwu/magisk/ui/ModulesFragment.java | 69 +++++++++++++++---- app/src/main/res/drawable/ic_block.xml | 9 +++ .../ic_bug_report.xml | 0 app/src/main/res/drawable/ic_delete.xml | 9 +++ .../ic_extension.xml | 0 .../drawable/ic_menu_overflow_material.xml | 25 +++++++ app/src/main/res/layout/modules_fragment.xml | 6 ++ app/src/main/res/layout/row.xml | 2 +- app/src/main/res/menu/module_popup.xml | 14 ++++ app/src/main/res/values/strings.xml | 4 ++ 20 files changed, 163 insertions(+), 176 deletions(-) delete mode 100644 .idea/.name delete mode 100644 .idea/compiler.xml delete mode 100644 .idea/encodings.xml delete mode 100644 .idea/gradle.xml delete mode 100644 .idea/misc.xml delete mode 100644 .idea/modules.xml delete mode 100644 .idea/runConfigurations.xml create mode 100644 app/src/main/java/com/topjohnwu/magisk/rv/ItemClickListener.java create mode 100644 app/src/main/res/drawable/ic_block.xml rename app/src/main/res/{drawable-anydpi => drawable}/ic_bug_report.xml (100%) create mode 100644 app/src/main/res/drawable/ic_delete.xml rename app/src/main/res/{drawable-anydpi => drawable}/ic_extension.xml (100%) create mode 100644 app/src/main/res/drawable/ic_menu_overflow_material.xml create mode 100644 app/src/main/res/menu/module_popup.xml diff --git a/.idea/.name b/.idea/.name deleted file mode 100644 index 14992600a..000000000 --- a/.idea/.name +++ /dev/null @@ -1 +0,0 @@ -MagiskManager \ No newline at end of file diff --git a/.idea/compiler.xml b/.idea/compiler.xml deleted file mode 100644 index b42dd7204..000000000 --- a/.idea/compiler.xml +++ /dev/null @@ -1,22 +0,0 @@ - - - - - \ No newline at end of file diff --git a/.idea/encodings.xml b/.idea/encodings.xml deleted file mode 100644 index 97626ba45..000000000 --- a/.idea/encodings.xml +++ /dev/null @@ -1,6 +0,0 @@ - - - - - - \ No newline at end of file diff --git a/.idea/gradle.xml b/.idea/gradle.xml deleted file mode 100644 index 6d530c3d5..000000000 --- a/.idea/gradle.xml +++ /dev/null @@ -1,28 +0,0 @@ - - - - - - \ No newline at end of file diff --git a/.idea/misc.xml b/.idea/misc.xml deleted file mode 100644 index 471660067..000000000 --- a/.idea/misc.xml +++ /dev/null @@ -1,62 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 1.8 - - - - - - - - \ No newline at end of file diff --git a/.idea/modules.xml b/.idea/modules.xml deleted file mode 100644 index 106f29ccb..000000000 --- a/.idea/modules.xml +++ /dev/null @@ -1,11 +0,0 @@ - - - - - - - - - - - \ No newline at end of file diff --git a/.idea/runConfigurations.xml b/.idea/runConfigurations.xml deleted file mode 100644 index 7f68460d8..000000000 --- a/.idea/runConfigurations.xml +++ /dev/null @@ -1,12 +0,0 @@ - - - - - - \ No newline at end of file diff --git a/app/src/main/java/com/topjohnwu/magisk/model/Module.java b/app/src/main/java/com/topjohnwu/magisk/model/Module.java index 3958c79ca..84734b548 100644 --- a/app/src/main/java/com/topjohnwu/magisk/model/Module.java +++ b/app/src/main/java/com/topjohnwu/magisk/model/Module.java @@ -1,5 +1,7 @@ package com.topjohnwu.magisk.model; +import com.topjohnwu.magisk.ui.utils.Utils; + import java.io.BufferedReader; import java.io.File; import java.io.FileReader; @@ -8,6 +10,10 @@ public class Module { private final boolean isValid; private final boolean isCache; + + private File mRemoveFile; + private File mDisableFile; + private File mPropFile; private String mName; @@ -18,9 +24,11 @@ public class Module { this.isCache = file.getPath().contains("cache"); this.isValid = new File(file + "/module.prop").exists(); - if (isValid) { - mPropFile = new File(file + "/module.prop"); - } + if (!isValid) return; + + mPropFile = new File(file + "/module.prop"); + mRemoveFile = new File(file + "/remove"); + mDisableFile = new File(file + "/disable"); } public boolean isValid() { @@ -43,6 +51,14 @@ public class Module { return mDescription; } + public void createRemoveFile() { + Utils.executeCommand("echo \"\" > " + mRemoveFile.getPath()); + } + + public void createDisableFile() { + Utils.executeCommand("echo \"\" > " + mDisableFile.getPath()); + } + public void parse() throws Exception { BufferedReader reader = new BufferedReader(new FileReader(mPropFile)); String line; diff --git a/app/src/main/java/com/topjohnwu/magisk/rv/ItemClickListener.java b/app/src/main/java/com/topjohnwu/magisk/rv/ItemClickListener.java new file mode 100644 index 000000000..eeb0e80d1 --- /dev/null +++ b/app/src/main/java/com/topjohnwu/magisk/rv/ItemClickListener.java @@ -0,0 +1,9 @@ +package com.topjohnwu.magisk.rv; + +import android.view.View; + +public interface ItemClickListener { + + void onItemClick(View view, int position); + +} diff --git a/app/src/main/java/com/topjohnwu/magisk/rv/ModulesAdapter.java b/app/src/main/java/com/topjohnwu/magisk/rv/ModulesAdapter.java index 1ad675623..9446f146a 100644 --- a/app/src/main/java/com/topjohnwu/magisk/rv/ModulesAdapter.java +++ b/app/src/main/java/com/topjohnwu/magisk/rv/ModulesAdapter.java @@ -4,6 +4,7 @@ import android.support.v7.widget.RecyclerView; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; +import android.widget.ImageView; import android.widget.TextView; import com.topjohnwu.magisk.R; @@ -17,37 +18,34 @@ import butterknife.ButterKnife; public class ModulesAdapter extends RecyclerView.Adapter { private final List mList; + private final ItemClickListener mListener; - public ModulesAdapter(List mList) { - this.mList = mList; + public ModulesAdapter(List list, ItemClickListener listener) { + this.mList = list; + this.mListener = listener; } @Override public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) { View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.row, parent, false); -/*FIXME - final ViewHolder viewHolder = new ViewHolder(view); - view.setOnClickListener(new View.OnClickListener() { - @Override - public void onClick(View v) { - listener.onItemClick(viewHolder.getAdapterPosition()); - } - });*/ return new ViewHolder(view); } @Override - public void onBindViewHolder(ViewHolder holder, int position) { + public void onBindViewHolder(final ViewHolder holder, int position) { Module module = mList.get(position); holder.title.setText(module.getName()); holder.versionName.setText(module.getVersion()); holder.description.setText(module.getDescription()); - //FIXME - - //holder.cache.setText("" + module.isCache()); + holder.overflowButton.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View view) { + mListener.onItemClick(holder.overflowButton, holder.getAdapterPosition()); + } + }); } @Override @@ -60,7 +58,7 @@ public class ModulesAdapter extends RecyclerView.Adapter listModules = new ArrayList<>(); + private ItemClickListener moduleActions = new ItemClickListener() { + @Override + public void onItemClick(final View view, final int position) { + PopupMenu popup = new PopupMenu(getContext(), view); + try { + Field[] fields = popup.getClass().getDeclaredFields(); + for (Field field : fields) { + if ("mPopup".equals(field.getName())) { + field.setAccessible(true); + Object menuPopupHelper = field.get(popup); + Class classPopupHelper = Class.forName(menuPopupHelper.getClass().getName()); + Method setForceIcons = classPopupHelper.getMethod("setForceShowIcon", boolean.class); + setForceIcons.invoke(menuPopupHelper, true); + break; + } + } + } catch (Exception ignored) { + } + + popup.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() { + @Override + public boolean onMenuItemClick(MenuItem item) { + switch (item.getItemId()) { + case R.id.remove: + listModules.get(position).createRemoveFile(); + Snackbar.make(view, R.string.remove_file_created, Snackbar.LENGTH_SHORT).show(); + break; + case R.id.disable: + listModules.get(position).createDisableFile(); + Snackbar.make(view, R.string.disable_file_created, Snackbar.LENGTH_SHORT).show(); + break; + } + + return false; + } + }); + popup.inflate(R.menu.module_popup); + popup.show(); + } + }; + @Nullable @Override public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) { - View v = inflater.inflate(R.layout.modules_fragment, container, false); - ButterKnife.bind(this, v); + View view = inflater.inflate(R.layout.modules_fragment, container, false); + ButterKnife.bind(this, view); new CheckFolders().execute(); - return v; + return view; } private class CheckFolders extends AsyncTask { - private ProgressDialog progress; - - @Override - protected void onPreExecute() { - super.onPreExecute(); - - progress = ProgressDialog.show(getContext(), null, getString(R.string.loading), true, false); - } - @Override protected Boolean doInBackground(Void... voids) { File[] magisk = new File(MAGISK_PATH).listFiles(new FileFilter() { @@ -104,9 +143,9 @@ public class ModulesFragment extends android.support.v4.app.Fragment { protected void onPostExecute(Boolean result) { super.onPostExecute(result); - progress.dismiss(); + progressBar.setVisibility(View.GONE); - recyclerView.setAdapter(new ModulesAdapter(listModules)); + recyclerView.setAdapter(new ModulesAdapter(listModules, moduleActions)); } } diff --git a/app/src/main/res/drawable/ic_block.xml b/app/src/main/res/drawable/ic_block.xml new file mode 100644 index 000000000..ea9660ac2 --- /dev/null +++ b/app/src/main/res/drawable/ic_block.xml @@ -0,0 +1,9 @@ + + + diff --git a/app/src/main/res/drawable-anydpi/ic_bug_report.xml b/app/src/main/res/drawable/ic_bug_report.xml similarity index 100% rename from app/src/main/res/drawable-anydpi/ic_bug_report.xml rename to app/src/main/res/drawable/ic_bug_report.xml diff --git a/app/src/main/res/drawable/ic_delete.xml b/app/src/main/res/drawable/ic_delete.xml new file mode 100644 index 000000000..a8d8089bf --- /dev/null +++ b/app/src/main/res/drawable/ic_delete.xml @@ -0,0 +1,9 @@ + + + diff --git a/app/src/main/res/drawable-anydpi/ic_extension.xml b/app/src/main/res/drawable/ic_extension.xml similarity index 100% rename from app/src/main/res/drawable-anydpi/ic_extension.xml rename to app/src/main/res/drawable/ic_extension.xml diff --git a/app/src/main/res/drawable/ic_menu_overflow_material.xml b/app/src/main/res/drawable/ic_menu_overflow_material.xml new file mode 100644 index 000000000..4ab8f2f1d --- /dev/null +++ b/app/src/main/res/drawable/ic_menu_overflow_material.xml @@ -0,0 +1,25 @@ + + + + + \ No newline at end of file diff --git a/app/src/main/res/layout/modules_fragment.xml b/app/src/main/res/layout/modules_fragment.xml index 1495adf5c..d898a4d96 100644 --- a/app/src/main/res/layout/modules_fragment.xml +++ b/app/src/main/res/layout/modules_fragment.xml @@ -6,6 +6,12 @@ android:layout_marginTop="?attr/actionBarSize" android:orientation="vertical"> + + + android:src="@drawable/ic_menu_overflow_material"/> diff --git a/app/src/main/res/menu/module_popup.xml b/app/src/main/res/menu/module_popup.xml new file mode 100644 index 000000000..2cf1d7804 --- /dev/null +++ b/app/src/main/res/menu/module_popup.xml @@ -0,0 +1,14 @@ + + + + + + + + \ No newline at end of file diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 969b5bd76..e376e260d 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -28,4 +28,8 @@ Root Modules Log + Remove + Disable + Module will be removed at next reboot + Module will be disabled at next reboot