More MagiskHide list UI improvements

This commit is contained in:
topjohnwu 2019-03-13 07:49:01 -04:00
parent 18ac6b270f
commit 15ddd0e284
2 changed files with 60 additions and 22 deletions

View File

@ -23,6 +23,8 @@ import com.buildware.widget.indeterm.IndeterminateCheckBox;
import com.topjohnwu.magisk.App;
import com.topjohnwu.magisk.Config;
import com.topjohnwu.magisk.R;
import com.topjohnwu.magisk.uicomponents.ArrowExpandable;
import com.topjohnwu.magisk.uicomponents.Expandable;
import com.topjohnwu.magisk.utils.Topic;
import com.topjohnwu.magisk.utils.Utils;
import com.topjohnwu.superuser.Shell;
@ -110,30 +112,30 @@ public class ApplicationAdapter extends SectionedAdapter
holder.app_icon.setImageDrawable(app.info.loadIcon(pm));
holder.package_name.setText(app.info.packageName);
holder.checkBox.setOnStateChangedListener(null);
holder.checkBox.setOnStateChangedListener(app.listener);
holder.checkBox.setState(app.getState());
if (app.expanded) {
holder.checkBox.setVisibility(View.GONE);
getMargins(holder).bottomMargin = 0;
} else {
holder.checkBox.setVisibility(View.VISIBLE);
getMargins(holder).bottomMargin = BOTTOM_MARGIN;
}
holder.itemView.setOnClickListener((v) -> {
int index = getItemPosition(section, 0);
holder.ex.setExpanded(app.expanded);
int index = getItemPosition(section, 0);
holder.checkBox.setOnStateChangedListener((IndeterminateCheckBox box, @Nullable Boolean status) -> {
if (status != null) {
for (HideProcessInfo p : app.processList) {
String cmd = Utils.fmt("magiskhide --%s %s %s",
status ? "add" : "rm", app.info.packageName, p.name);
Shell.su(cmd).submit();
p.hidden = status;
}
notifyItemRangeChanged(index, app.processList.size());
}
});
holder.trigger.setOnClickListener((v) -> {
if (app.expanded) {
app.expanded = false;
notifyItemRangeRemoved(index, app.processList.size());
getMargins(holder).bottomMargin = BOTTOM_MARGIN;
holder.checkBox.setOnStateChangedListener(null);
holder.checkBox.setVisibility(View.VISIBLE);
holder.checkBox.setState(app.getState());
holder.checkBox.setOnStateChangedListener(app.listener);
holder.ex.collapse();
} else {
holder.checkBox.setVisibility(View.GONE);
getMargins(holder).bottomMargin = 0;
app.expanded = true;
notifyItemRangeInserted(index, app.processList.size());
holder.ex.expand();
}
});
}
@ -149,6 +151,7 @@ public class ApplicationAdapter extends SectionedAdapter
Shell.su(Utils.fmt("magiskhide --%s %s %s", checked ? "add" : "rm",
hideApp.info.packageName, target.name)).submit();
target.hidden = checked;
notifyItemChanged(getSectionPosition(section));
});
getMargins(holder).bottomMargin =
position == hideApp.processList.size() - 1 ? BOTTOM_MARGIN : 0;
@ -350,10 +353,25 @@ public class ApplicationAdapter extends SectionedAdapter
@BindView(R.id.app_name) TextView app_name;
@BindView(R.id.package_name) TextView package_name;
@BindView(R.id.checkbox) IndeterminateCheckBox checkBox;
@BindView(R.id.trigger) View trigger;
@BindView(R.id.arrow) ImageView arrow;
Expandable ex;
AppViewHolder(@NonNull View itemView) {
super(itemView);
new ApplicationAdapter$AppViewHolder_ViewBinding(this, itemView);
ex = new ArrowExpandable(new Expandable() {
@Override
protected void onExpand() {
getMargins(AppViewHolder.this).bottomMargin = 0;
}
@Override
protected void onCollapse() {
getMargins(AppViewHolder.this).bottomMargin = BOTTOM_MARGIN;
}
}, arrow);
}
}

View File

@ -1,7 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<androidx.cardview.widget.CardView
xmlns:android="http://schemas.android.com/apk/res/android"
<androidx.cardview.widget.CardView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
style="?attr/cardStyle"
android:layout_width="fill_parent"
@ -57,10 +56,32 @@
android:textColor="@android:color/tertiary_text_dark"
android:textIsSelectable="false"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="@+id/app_name"
app:layout_constraintEnd_toStartOf="@id/arrow"
app:layout_constraintStart_toStartOf="@+id/app_name"
app:layout_constraintTop_toBottomOf="@+id/app_name" />
<ImageView
android:id="@+id/arrow"
android:layout_width="20dp"
android:layout_height="20dp"
android:layout_marginStart="5dp"
android:layout_marginEnd="5dp"
android:tint="?attr/imageColorTint"
app:layout_constraintBottom_toBottomOf="@+id/package_name"
app:layout_constraintEnd_toEndOf="@+id/app_name"
app:layout_constraintStart_toEndOf="@+id/package_name"
app:layout_constraintTop_toTopOf="@+id/package_name"
app:srcCompat="@drawable/ic_arrow" />
<View
android:id="@+id/trigger"
android:layout_width="35dp"
android:layout_height="0dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="@+id/arrow"
app:layout_constraintStart_toStartOf="@+id/arrow"
app:layout_constraintTop_toTopOf="parent" />
<com.buildware.widget.indeterm.IndeterminateCheckBox
android:id="@+id/checkbox"
android:layout_width="wrap_content"
@ -70,8 +91,7 @@
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toEndOf="@+id/app_name"
app:layout_constraintTop_toTopOf="parent"
/>
app:layout_constraintTop_toTopOf="parent" />
</androidx.constraintlayout.widget.ConstraintLayout>