[WIP] Use checkbox and delete button instead of a popup menu
This commit is contained in:
parent
c68e37a8c4
commit
3ad06c406c
@ -45,12 +45,28 @@ public class Module {
|
|||||||
return mDescription;
|
return mDescription;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void createRemoveFile() {
|
public void createDisableFile() {
|
||||||
Utils.executeCommand("echo \"\" > " + mRemoveFile.getPath());
|
Utils.executeCommand("touch " + mDisableFile.getPath());
|
||||||
}
|
}
|
||||||
|
|
||||||
public void createDisableFile() {
|
public boolean removeDisableFile() {
|
||||||
Utils.executeCommand("echo \"\" > " + mDisableFile.getPath());
|
return mDisableFile.delete();
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isEnabled() {
|
||||||
|
return mDisableFile.exists();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void createRemoveFile() {
|
||||||
|
Utils.executeCommand("touch " + mRemoveFile.getPath());
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean deleteRemoveFile() {
|
||||||
|
return mRemoveFile.delete();
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean willBeRemoved() {
|
||||||
|
return mRemoveFile.exists();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void parse() throws Exception {
|
public void parse() throws Exception {
|
||||||
|
@ -4,6 +4,8 @@ import android.support.v7.widget.RecyclerView;
|
|||||||
import android.view.LayoutInflater;
|
import android.view.LayoutInflater;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
import android.view.ViewGroup;
|
import android.view.ViewGroup;
|
||||||
|
import android.widget.CheckBox;
|
||||||
|
import android.widget.CompoundButton;
|
||||||
import android.widget.ImageView;
|
import android.widget.ImageView;
|
||||||
import android.widget.TextView;
|
import android.widget.TextView;
|
||||||
|
|
||||||
@ -18,11 +20,13 @@ import butterknife.ButterKnife;
|
|||||||
public class ModulesAdapter extends RecyclerView.Adapter<ModulesAdapter.ViewHolder> {
|
public class ModulesAdapter extends RecyclerView.Adapter<ModulesAdapter.ViewHolder> {
|
||||||
|
|
||||||
private final List<Module> mList;
|
private final List<Module> mList;
|
||||||
private final ItemClickListener mListener;
|
private final ItemClickListener chboxListener;
|
||||||
|
private final ItemClickListener deleteBtnListener;
|
||||||
|
|
||||||
public ModulesAdapter(List<Module> list, ItemClickListener listener) {
|
public ModulesAdapter(List<Module> list, ItemClickListener chboxListener, ItemClickListener deleteBtnListener) {
|
||||||
this.mList = list;
|
this.mList = list;
|
||||||
this.mListener = listener;
|
this.chboxListener = chboxListener;
|
||||||
|
this.deleteBtnListener = deleteBtnListener;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -34,18 +38,38 @@ public class ModulesAdapter extends RecyclerView.Adapter<ModulesAdapter.ViewHold
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onBindViewHolder(final ViewHolder holder, int position) {
|
public void onBindViewHolder(final ViewHolder holder, int position) {
|
||||||
Module module = mList.get(position);
|
final Module module = mList.get(position);
|
||||||
|
|
||||||
holder.title.setText(module.getName());
|
holder.title.setText(module.getName());
|
||||||
holder.versionName.setText(module.getVersion());
|
holder.versionName.setText(module.getVersion());
|
||||||
holder.description.setText(module.getDescription());
|
holder.description.setText(module.getDescription());
|
||||||
|
|
||||||
holder.overflowButton.setOnClickListener(new View.OnClickListener() {
|
holder.checkBox.setChecked(module.isEnabled());
|
||||||
|
holder.checkBox.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
|
||||||
@Override
|
@Override
|
||||||
public void onClick(View view) {
|
public void onCheckedChanged(CompoundButton compoundButton, boolean b) {
|
||||||
mListener.onItemClick(holder.overflowButton, holder.getAdapterPosition());
|
chboxListener.onItemClick(compoundButton, holder.getAdapterPosition());
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
holder.delete.setOnClickListener(new View.OnClickListener() {
|
||||||
|
@Override
|
||||||
|
public void onClick(View view) {
|
||||||
|
deleteBtnListener.onItemClick(holder.delete, holder.getAdapterPosition());
|
||||||
|
holder.warning.setVisibility(module.willBeRemoved() ? View.VISIBLE : View.GONE);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
holder.delete.setOnLongClickListener(new View.OnLongClickListener() {
|
||||||
|
@Override
|
||||||
|
public boolean onLongClick(View view) {
|
||||||
|
module.deleteRemoveFile();
|
||||||
|
holder.warning.setVisibility(module.willBeRemoved() ? View.VISIBLE : View.GONE);
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
holder.warning.setVisibility(module.willBeRemoved() ? View.VISIBLE : View.GONE);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -56,9 +80,14 @@ public class ModulesAdapter extends RecyclerView.Adapter<ModulesAdapter.ViewHold
|
|||||||
static class ViewHolder extends RecyclerView.ViewHolder {
|
static class ViewHolder extends RecyclerView.ViewHolder {
|
||||||
|
|
||||||
@BindView(R.id.title) TextView title;
|
@BindView(R.id.title) TextView title;
|
||||||
|
|
||||||
@BindView(R.id.version_name) TextView versionName;
|
@BindView(R.id.version_name) TextView versionName;
|
||||||
@BindView(R.id.description) TextView description;
|
@BindView(R.id.description) TextView description;
|
||||||
@BindView(R.id.overflow) ImageView overflowButton;
|
|
||||||
|
@BindView(R.id.warning) TextView warning;
|
||||||
|
|
||||||
|
@BindView(R.id.checkbox) CheckBox checkBox;
|
||||||
|
@BindView(R.id.delete) ImageView delete;
|
||||||
|
|
||||||
public ViewHolder(View itemView) {
|
public ViewHolder(View itemView) {
|
||||||
super(itemView);
|
super(itemView);
|
||||||
|
@ -4,20 +4,17 @@ import android.os.Bundle;
|
|||||||
import android.support.annotation.Nullable;
|
import android.support.annotation.Nullable;
|
||||||
import android.support.design.widget.Snackbar;
|
import android.support.design.widget.Snackbar;
|
||||||
import android.support.v4.app.Fragment;
|
import android.support.v4.app.Fragment;
|
||||||
import android.support.v7.widget.PopupMenu;
|
|
||||||
import android.support.v7.widget.RecyclerView;
|
import android.support.v7.widget.RecyclerView;
|
||||||
import android.view.LayoutInflater;
|
import android.view.LayoutInflater;
|
||||||
import android.view.MenuItem;
|
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
import android.view.ViewGroup;
|
import android.view.ViewGroup;
|
||||||
|
import android.widget.CheckBox;
|
||||||
|
|
||||||
import com.topjohnwu.magisk.R;
|
import com.topjohnwu.magisk.R;
|
||||||
import com.topjohnwu.magisk.model.Module;
|
import com.topjohnwu.magisk.model.Module;
|
||||||
import com.topjohnwu.magisk.rv.ItemClickListener;
|
import com.topjohnwu.magisk.rv.ItemClickListener;
|
||||||
import com.topjohnwu.magisk.rv.ModulesAdapter;
|
import com.topjohnwu.magisk.rv.ModulesAdapter;
|
||||||
|
|
||||||
import java.lang.reflect.Field;
|
|
||||||
import java.lang.reflect.Method;
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import butterknife.BindView;
|
import butterknife.BindView;
|
||||||
@ -27,56 +24,32 @@ public abstract class BaseModuleFragment extends Fragment {
|
|||||||
|
|
||||||
@BindView(R.id.recyclerView) RecyclerView recyclerView;
|
@BindView(R.id.recyclerView) RecyclerView recyclerView;
|
||||||
|
|
||||||
private ItemClickListener moduleActions = new ItemClickListener() {
|
|
||||||
@Override
|
|
||||||
public void onItemClick(final View view, final int position) {
|
|
||||||
PopupMenu popup = new PopupMenu(getContext(), view);
|
|
||||||
|
|
||||||
// Force show icons
|
|
||||||
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
|
@Nullable
|
||||||
@Override
|
@Override
|
||||||
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
|
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
|
||||||
View view = inflater.inflate(R.layout.single_module_fragment, container, false);
|
View view = inflater.inflate(R.layout.single_module_fragment, container, false);
|
||||||
ButterKnife.bind(this, view);
|
ButterKnife.bind(this, view);
|
||||||
|
|
||||||
recyclerView.setAdapter(new ModulesAdapter(listModules(), moduleActions));
|
recyclerView.setAdapter(new ModulesAdapter(listModules(), new ItemClickListener() {
|
||||||
|
@Override
|
||||||
|
public void onItemClick(View view, int position) {
|
||||||
|
CheckBox chbox = (CheckBox) view;
|
||||||
|
|
||||||
|
if (!chbox.isChecked()) {
|
||||||
|
listModules().get(position).createDisableFile();
|
||||||
|
Snackbar.make(view, R.string.disable_file_created, Snackbar.LENGTH_SHORT).show();
|
||||||
|
} else {
|
||||||
|
listModules().get(position).removeDisableFile();
|
||||||
|
Snackbar.make(view, R.string.disable_file_removed, Snackbar.LENGTH_SHORT).show();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}, new ItemClickListener() {
|
||||||
|
@Override
|
||||||
|
public void onItemClick(View view, int position) {
|
||||||
|
listModules().get(position).createRemoveFile();
|
||||||
|
Snackbar.make(view, R.string.remove_file_created, Snackbar.LENGTH_SHORT).show();
|
||||||
|
}
|
||||||
|
}));
|
||||||
return view;
|
return view;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,9 +0,0 @@
|
|||||||
<vector xmlns:android="http://schemas.android.com/apk/res/android"
|
|
||||||
android:width="24dp"
|
|
||||||
android:height="24dp"
|
|
||||||
android:viewportWidth="24.0"
|
|
||||||
android:viewportHeight="24.0">
|
|
||||||
<path
|
|
||||||
android:fillColor="#757575"
|
|
||||||
android:pathData="M12,2C6.48,2 2,6.48 2,12s4.48,10 10,10 10,-4.48 10,-10S17.52,2 12,2zM4,12c0,-4.42 3.58,-8 8,-8 1.85,0 3.55,0.63 4.9,1.69L5.69,16.9C4.63,15.55 4,13.85 4,12zM12,20c-1.85,0 -3.55,-0.63 -4.9,-1.69L18.31,7.1C19.37,8.45 20,10.15 20,12c0,4.42 -3.58,8 -8,8z"/>
|
|
||||||
</vector>
|
|
@ -64,10 +64,20 @@
|
|||||||
android:textAppearance="?android:attr/textAppearanceSmall"
|
android:textAppearance="?android:attr/textAppearanceSmall"
|
||||||
android:textIsSelectable="false"/>
|
android:textIsSelectable="false"/>
|
||||||
|
|
||||||
|
<TextView
|
||||||
|
android:id="@+id/warning"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_gravity="center_vertical"
|
||||||
|
android:text="@string/remove_file_created"
|
||||||
|
android:textAppearance="?android:attr/textAppearanceSmall"
|
||||||
|
android:textColor="@color/red500"
|
||||||
|
android:visibility="gone"/>
|
||||||
|
|
||||||
</LinearLayout>
|
</LinearLayout>
|
||||||
|
|
||||||
<ImageView
|
<CheckBox
|
||||||
android:id="@+id/overflow"
|
android:id="@+id/checkbox"
|
||||||
android:layout_width="wrap_content"
|
android:layout_width="wrap_content"
|
||||||
android:layout_height="match_parent"
|
android:layout_height="match_parent"
|
||||||
android:focusable="false"
|
android:focusable="false"
|
||||||
@ -76,6 +86,16 @@
|
|||||||
android:src="@drawable/ic_menu_overflow_material"
|
android:src="@drawable/ic_menu_overflow_material"
|
||||||
tools:ignore="ContentDescription"/>
|
tools:ignore="ContentDescription"/>
|
||||||
|
|
||||||
|
<ImageView
|
||||||
|
android:id="@+id/delete"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="match_parent"
|
||||||
|
android:focusable="false"
|
||||||
|
android:gravity="center"
|
||||||
|
android:padding="3dp"
|
||||||
|
android:src="@drawable/ic_delete"
|
||||||
|
tools:ignore="ContentDescription"/>
|
||||||
|
|
||||||
</LinearLayout>
|
</LinearLayout>
|
||||||
|
|
||||||
</android.support.v7.widget.CardView>
|
</android.support.v7.widget.CardView>
|
@ -1,14 +0,0 @@
|
|||||||
<?xml version="1.0" encoding="utf-8"?>
|
|
||||||
<menu xmlns:android="http://schemas.android.com/apk/res/android">
|
|
||||||
|
|
||||||
<item
|
|
||||||
android:id="@+id/remove"
|
|
||||||
android:icon="@drawable/ic_delete"
|
|
||||||
android:title="@string/remove"/>
|
|
||||||
|
|
||||||
<item
|
|
||||||
android:id="@+id/disable"
|
|
||||||
android:icon="@drawable/ic_block"
|
|
||||||
android:title="@string/disable"/>
|
|
||||||
|
|
||||||
</menu>
|
|
@ -9,5 +9,6 @@
|
|||||||
<color name="secondary_text">#757575</color>
|
<color name="secondary_text">#757575</color>
|
||||||
<color name="icons">#FFFFFF</color>
|
<color name="icons">#FFFFFF</color>
|
||||||
<color name="divider">#BDBDBD</color>
|
<color name="divider">#BDBDBD</color>
|
||||||
|
<color name="red500">#F44336</color>
|
||||||
|
|
||||||
</resources>
|
</resources>
|
||||||
|
@ -40,5 +40,6 @@
|
|||||||
<string name="log_is_empty">Log is empty</string>
|
<string name="log_is_empty">Log is empty</string>
|
||||||
<string name="logs_save_failed">Could not write log to SD card:</string>
|
<string name="logs_save_failed">Could not write log to SD card:</string>
|
||||||
<string name="permissionNotGranted">This feature will not work without permission to write external storage.</string>
|
<string name="permissionNotGranted">This feature will not work without permission to write external storage.</string>
|
||||||
|
<string name="disable_file_removed">Module will be enabled at next reboot</string>
|
||||||
|
|
||||||
</resources>
|
</resources>
|
||||||
|
@ -1,32 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright (C) 2012 Dominik Schürmann <dominik@dominikschuermann.de>
|
|
||||||
*
|
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
||||||
* you may not use this file except in compliance with the License.
|
|
||||||
* You may obtain a copy of the License at
|
|
||||||
*
|
|
||||||
* http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
*
|
|
||||||
* Unless required by applicable law or agreed to in writing, software
|
|
||||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
* See the License for the specific language governing permissions and
|
|
||||||
* limitations under the License.
|
|
||||||
*/
|
|
||||||
|
|
||||||
package org.sufficientlysecure.rootcommands.util;
|
|
||||||
|
|
||||||
import java.io.IOException;
|
|
||||||
|
|
||||||
public class RootAccessDeniedException extends IOException {
|
|
||||||
private static final long serialVersionUID = 9088998884166225540L;
|
|
||||||
|
|
||||||
public RootAccessDeniedException() {
|
|
||||||
super();
|
|
||||||
}
|
|
||||||
|
|
||||||
public RootAccessDeniedException(String detailMessage) {
|
|
||||||
super(detailMessage);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
@ -1,30 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright (C) 2012 Dominik Schürmann <dominik@dominikschuermann.de>
|
|
||||||
*
|
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
||||||
* you may not use this file except in compliance with the License.
|
|
||||||
* You may obtain a copy of the License at
|
|
||||||
*
|
|
||||||
* http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
*
|
|
||||||
* Unless required by applicable law or agreed to in writing, software
|
|
||||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
* See the License for the specific language governing permissions and
|
|
||||||
* limitations under the License.
|
|
||||||
*/
|
|
||||||
|
|
||||||
package org.sufficientlysecure.rootcommands.util;
|
|
||||||
|
|
||||||
public class UnsupportedArchitectureException extends Exception {
|
|
||||||
private static final long serialVersionUID = 7826528799780001655L;
|
|
||||||
|
|
||||||
public UnsupportedArchitectureException() {
|
|
||||||
super();
|
|
||||||
}
|
|
||||||
|
|
||||||
public UnsupportedArchitectureException(String detailMessage) {
|
|
||||||
super(detailMessage);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
Loading…
Reference in New Issue
Block a user