mirror of
https://github.com/topjohnwu/Magisk.git
synced 2025-02-19 20:18:29 +00:00
Make Expandable more extensible
This commit is contained in:
parent
3e35de9b39
commit
18ac6b270f
@ -19,7 +19,8 @@ import com.topjohnwu.magisk.container.Policy;
|
||||
import com.topjohnwu.magisk.database.MagiskDB;
|
||||
import com.topjohnwu.magisk.dialogs.CustomAlertDialog;
|
||||
import com.topjohnwu.magisk.dialogs.FingerprintAuthDialog;
|
||||
import com.topjohnwu.magisk.uicomponents.ArrowExpandedViewHolder;
|
||||
import com.topjohnwu.magisk.uicomponents.ArrowExpandable;
|
||||
import com.topjohnwu.magisk.uicomponents.Expandable;
|
||||
import com.topjohnwu.magisk.uicomponents.ExpandableViewHolder;
|
||||
import com.topjohnwu.magisk.uicomponents.SnackbarMaker;
|
||||
import com.topjohnwu.magisk.utils.FingerprintHelper;
|
||||
@ -160,12 +161,12 @@ public class PolicyAdapter extends RecyclerView.Adapter<PolicyAdapter.ViewHolder
|
||||
@BindView(R.id.delete) ImageView delete;
|
||||
@BindView(R.id.more_info) ImageView moreInfo;
|
||||
|
||||
ExpandableViewHolder settings;
|
||||
Expandable settings;
|
||||
|
||||
public ViewHolder(View itemView) {
|
||||
super(itemView);
|
||||
new PolicyAdapter$ViewHolder_ViewBinding(this, itemView);
|
||||
settings = new ArrowExpandedViewHolder(expandLayout, arrow);
|
||||
settings = new ArrowExpandable(new ExpandableViewHolder(expandLayout), arrow);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -31,7 +31,8 @@ import com.topjohnwu.magisk.dialogs.MagiskInstallDialog;
|
||||
import com.topjohnwu.magisk.dialogs.ManagerInstallDialog;
|
||||
import com.topjohnwu.magisk.dialogs.UninstallDialog;
|
||||
import com.topjohnwu.magisk.tasks.CheckUpdates;
|
||||
import com.topjohnwu.magisk.uicomponents.ArrowExpandedViewHolder;
|
||||
import com.topjohnwu.magisk.uicomponents.ArrowExpandable;
|
||||
import com.topjohnwu.magisk.uicomponents.Expandable;
|
||||
import com.topjohnwu.magisk.uicomponents.ExpandableViewHolder;
|
||||
import com.topjohnwu.magisk.uicomponents.MarkDownWindow;
|
||||
import com.topjohnwu.magisk.uicomponents.SafetyNet;
|
||||
@ -73,7 +74,7 @@ public class MagiskFragment extends BaseFragment
|
||||
private UpdateCardHolder manager;
|
||||
private SafetyNet safetyNet;
|
||||
private Transition transition;
|
||||
private ExpandableViewHolder optionExpand;
|
||||
private Expandable optionExpand;
|
||||
|
||||
private void magiskInstall(View v) {
|
||||
// Show Manager update first
|
||||
@ -137,7 +138,7 @@ public class MagiskFragment extends BaseFragment
|
||||
unbinder = new MagiskFragment_ViewBinding(this, v);
|
||||
requireActivity().setTitle(R.string.magisk);
|
||||
|
||||
optionExpand = new ArrowExpandedViewHolder(optionExpandLayout, arrow);
|
||||
optionExpand = new ArrowExpandable(new ExpandableViewHolder(optionExpandLayout), arrow);
|
||||
safetyNet = new SafetyNet(v);
|
||||
magisk = new UpdateCardHolder(inflater, root);
|
||||
manager = new UpdateCardHolder(inflater, root);
|
||||
|
@ -1,40 +1,39 @@
|
||||
package com.topjohnwu.magisk.uicomponents;
|
||||
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.view.animation.Animation;
|
||||
import android.view.animation.RotateAnimation;
|
||||
|
||||
public class ArrowExpandedViewHolder extends ExpandableViewHolder {
|
||||
|
||||
public class ArrowExpandable extends Expandable {
|
||||
protected Expandable mBase;
|
||||
private View arrow;
|
||||
|
||||
public ArrowExpandedViewHolder(ViewGroup viewGroup, View arrow) {
|
||||
super(viewGroup);
|
||||
public ArrowExpandable(Expandable base, View arrow) {
|
||||
mBase = base;
|
||||
this.arrow = arrow;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setExpanded(boolean expanded) {
|
||||
super.setExpanded(expanded);
|
||||
if (arrow != null)
|
||||
arrow.setRotation(expanded ? 180 : 0);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void expand() {
|
||||
super.expand();
|
||||
public void onExpand() {
|
||||
mBase.onExpand();
|
||||
setRotate(new RotateAnimation(0, 180,
|
||||
Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF, 0.5f));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void collapse() {
|
||||
super.collapse();
|
||||
public void onCollapse() {
|
||||
mBase.onCollapse();
|
||||
setRotate(new RotateAnimation(180, 0,
|
||||
Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF, 0.5f));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onSetExpanded(boolean expanded) {
|
||||
mBase.onSetExpanded(expanded);
|
||||
if (arrow != null)
|
||||
arrow.setRotation(expanded ? 180 : 0);
|
||||
}
|
||||
|
||||
private void setRotate(RotateAnimation rotate) {
|
||||
rotate.setDuration(300);
|
||||
rotate.setFillAfter(true);
|
@ -0,0 +1,40 @@
|
||||
package com.topjohnwu.magisk.uicomponents;
|
||||
|
||||
public abstract class Expandable {
|
||||
|
||||
private boolean mExpanded = false;
|
||||
|
||||
public final boolean isExpanded() {
|
||||
return mExpanded;
|
||||
}
|
||||
|
||||
public final void setExpanded(boolean expanded) {
|
||||
mExpanded = expanded;
|
||||
onSetExpanded(expanded);
|
||||
}
|
||||
|
||||
public final void expand() {
|
||||
if (mExpanded)
|
||||
return;
|
||||
onExpand();
|
||||
mExpanded = true;
|
||||
}
|
||||
|
||||
public final void collapse() {
|
||||
if (!mExpanded)
|
||||
return;
|
||||
onCollapse();
|
||||
mExpanded = false;
|
||||
}
|
||||
|
||||
protected abstract void onExpand();
|
||||
|
||||
protected abstract void onCollapse();
|
||||
|
||||
protected void onSetExpanded(boolean expanded) {
|
||||
if (expanded)
|
||||
onExpand();
|
||||
else
|
||||
onCollapse();
|
||||
}
|
||||
}
|
@ -5,11 +5,10 @@ import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.view.ViewTreeObserver;
|
||||
|
||||
public class ExpandableViewHolder {
|
||||
public class ExpandableViewHolder extends Expandable {
|
||||
|
||||
private ViewGroup expandLayout;
|
||||
private ValueAnimator expandAnimator, collapseAnimator;
|
||||
private boolean mExpanded = false;
|
||||
private int expandHeight = 0;
|
||||
|
||||
public ExpandableViewHolder(ViewGroup viewGroup) {
|
||||
@ -34,30 +33,24 @@ public class ExpandableViewHolder {
|
||||
});
|
||||
}
|
||||
|
||||
public boolean isExpanded() {
|
||||
return mExpanded;
|
||||
@Override
|
||||
protected void onExpand() {
|
||||
expandLayout.setVisibility(View.VISIBLE);
|
||||
expandAnimator.start();
|
||||
}
|
||||
|
||||
public void setExpanded(boolean expanded) {
|
||||
mExpanded = expanded;
|
||||
@Override
|
||||
protected void onCollapse() {
|
||||
collapseAnimator.start();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onSetExpanded(boolean expanded) {
|
||||
ViewGroup.LayoutParams layoutParams = expandLayout.getLayoutParams();
|
||||
layoutParams.height = expanded ? expandHeight : 0;
|
||||
expandLayout.setLayoutParams(layoutParams);
|
||||
}
|
||||
|
||||
public void expand() {
|
||||
if (mExpanded) return;
|
||||
expandLayout.setVisibility(View.VISIBLE);
|
||||
expandAnimator.start();
|
||||
mExpanded = true;
|
||||
}
|
||||
|
||||
public void collapse() {
|
||||
if (!mExpanded) return;
|
||||
collapseAnimator.start();
|
||||
mExpanded = false;
|
||||
}
|
||||
|
||||
private ValueAnimator slideAnimator(int start, int end) {
|
||||
ValueAnimator animator = ValueAnimator.ofInt(start, end);
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user