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.App;
import com.topjohnwu.magisk.Config; import com.topjohnwu.magisk.Config;
import com.topjohnwu.magisk.R; 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.Topic;
import com.topjohnwu.magisk.utils.Utils; import com.topjohnwu.magisk.utils.Utils;
import com.topjohnwu.superuser.Shell; import com.topjohnwu.superuser.Shell;
@ -110,30 +112,30 @@ public class ApplicationAdapter extends SectionedAdapter
holder.app_icon.setImageDrawable(app.info.loadIcon(pm)); holder.app_icon.setImageDrawable(app.info.loadIcon(pm));
holder.package_name.setText(app.info.packageName); holder.package_name.setText(app.info.packageName);
holder.checkBox.setOnStateChangedListener(null); holder.checkBox.setOnStateChangedListener(null);
holder.checkBox.setOnStateChangedListener(app.listener);
holder.checkBox.setState(app.getState()); holder.checkBox.setState(app.getState());
if (app.expanded) { holder.ex.setExpanded(app.expanded);
holder.checkBox.setVisibility(View.GONE);
getMargins(holder).bottomMargin = 0; int index = getItemPosition(section, 0);
} else { holder.checkBox.setOnStateChangedListener((IndeterminateCheckBox box, @Nullable Boolean status) -> {
holder.checkBox.setVisibility(View.VISIBLE); if (status != null) {
getMargins(holder).bottomMargin = BOTTOM_MARGIN; for (HideProcessInfo p : app.processList) {
} String cmd = Utils.fmt("magiskhide --%s %s %s",
holder.itemView.setOnClickListener((v) -> { status ? "add" : "rm", app.info.packageName, p.name);
int index = getItemPosition(section, 0); Shell.su(cmd).submit();
p.hidden = status;
}
notifyItemRangeChanged(index, app.processList.size());
}
});
holder.trigger.setOnClickListener((v) -> {
if (app.expanded) { if (app.expanded) {
app.expanded = false; app.expanded = false;
notifyItemRangeRemoved(index, app.processList.size()); notifyItemRangeRemoved(index, app.processList.size());
getMargins(holder).bottomMargin = BOTTOM_MARGIN; holder.ex.collapse();
holder.checkBox.setOnStateChangedListener(null);
holder.checkBox.setVisibility(View.VISIBLE);
holder.checkBox.setState(app.getState());
holder.checkBox.setOnStateChangedListener(app.listener);
} else { } else {
holder.checkBox.setVisibility(View.GONE);
getMargins(holder).bottomMargin = 0;
app.expanded = true; app.expanded = true;
notifyItemRangeInserted(index, app.processList.size()); 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", Shell.su(Utils.fmt("magiskhide --%s %s %s", checked ? "add" : "rm",
hideApp.info.packageName, target.name)).submit(); hideApp.info.packageName, target.name)).submit();
target.hidden = checked; target.hidden = checked;
notifyItemChanged(getSectionPosition(section));
}); });
getMargins(holder).bottomMargin = getMargins(holder).bottomMargin =
position == hideApp.processList.size() - 1 ? BOTTOM_MARGIN : 0; 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.app_name) TextView app_name;
@BindView(R.id.package_name) TextView package_name; @BindView(R.id.package_name) TextView package_name;
@BindView(R.id.checkbox) IndeterminateCheckBox checkBox; @BindView(R.id.checkbox) IndeterminateCheckBox checkBox;
@BindView(R.id.trigger) View trigger;
@BindView(R.id.arrow) ImageView arrow;
Expandable ex;
AppViewHolder(@NonNull View itemView) { AppViewHolder(@NonNull View itemView) {
super(itemView); super(itemView);
new ApplicationAdapter$AppViewHolder_ViewBinding(this, 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"?> <?xml version="1.0" encoding="utf-8"?>
<androidx.cardview.widget.CardView <androidx.cardview.widget.CardView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto" xmlns:app="http://schemas.android.com/apk/res-auto"
style="?attr/cardStyle" style="?attr/cardStyle"
android:layout_width="fill_parent" android:layout_width="fill_parent"
@ -57,10 +56,32 @@
android:textColor="@android:color/tertiary_text_dark" android:textColor="@android:color/tertiary_text_dark"
android:textIsSelectable="false" android:textIsSelectable="false"
app:layout_constraintBottom_toBottomOf="parent" 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_constraintStart_toStartOf="@+id/app_name"
app:layout_constraintTop_toBottomOf="@+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 <com.buildware.widget.indeterm.IndeterminateCheckBox
android:id="@+id/checkbox" android:id="@+id/checkbox"
android:layout_width="wrap_content" android:layout_width="wrap_content"
@ -70,8 +91,7 @@
app:layout_constraintBottom_toBottomOf="parent" app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent" app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toEndOf="@+id/app_name" app:layout_constraintStart_toEndOf="@+id/app_name"
app:layout_constraintTop_toTopOf="parent" app:layout_constraintTop_toTopOf="parent" />
/>
</androidx.constraintlayout.widget.ConstraintLayout> </androidx.constraintlayout.widget.ConstraintLayout>