Animate arrows
This commit is contained in:
parent
71638191ee
commit
841dee94c6
@ -5,6 +5,8 @@ import android.content.pm.PackageManager;
|
|||||||
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.view.animation.Animation;
|
||||||
|
import android.view.animation.RotateAnimation;
|
||||||
import android.widget.ImageView;
|
import android.widget.ImageView;
|
||||||
import android.widget.TextView;
|
import android.widget.TextView;
|
||||||
|
|
||||||
@ -17,9 +19,7 @@ import com.topjohnwu.magisk.components.ExpandableView;
|
|||||||
import com.topjohnwu.magisk.components.SnackbarMaker;
|
import com.topjohnwu.magisk.components.SnackbarMaker;
|
||||||
import com.topjohnwu.magisk.utils.FingerprintHelper;
|
import com.topjohnwu.magisk.utils.FingerprintHelper;
|
||||||
|
|
||||||
import java.util.HashSet;
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Set;
|
|
||||||
|
|
||||||
import androidx.annotation.NonNull;
|
import androidx.annotation.NonNull;
|
||||||
import androidx.appcompat.widget.SwitchCompat;
|
import androidx.appcompat.widget.SwitchCompat;
|
||||||
@ -31,10 +31,11 @@ public class PolicyAdapter extends RecyclerView.Adapter<PolicyAdapter.ViewHolder
|
|||||||
private List<Policy> policyList;
|
private List<Policy> policyList;
|
||||||
private MagiskDB dbHelper;
|
private MagiskDB dbHelper;
|
||||||
private PackageManager pm;
|
private PackageManager pm;
|
||||||
private Set<Policy> expandList = new HashSet<>();
|
private boolean[] expandList;
|
||||||
|
|
||||||
public PolicyAdapter(List<Policy> list, MagiskDB db, PackageManager pm) {
|
public PolicyAdapter(List<Policy> list, MagiskDB db, PackageManager pm) {
|
||||||
policyList = list;
|
policyList = list;
|
||||||
|
expandList = new boolean[policyList.size()];
|
||||||
dbHelper = db;
|
dbHelper = db;
|
||||||
this.pm = pm;
|
this.pm = pm;
|
||||||
}
|
}
|
||||||
@ -50,15 +51,14 @@ public class PolicyAdapter extends RecyclerView.Adapter<PolicyAdapter.ViewHolder
|
|||||||
public void onBindViewHolder(ViewHolder holder, int position) {
|
public void onBindViewHolder(ViewHolder holder, int position) {
|
||||||
Policy policy = policyList.get(position);
|
Policy policy = policyList.get(position);
|
||||||
|
|
||||||
holder.setExpanded(expandList.contains(policy));
|
holder.setExpanded(expandList[position]);
|
||||||
|
holder.trigger.setOnClickListener(view -> {
|
||||||
holder.itemView.setOnClickListener(view -> {
|
|
||||||
if (holder.isExpanded()) {
|
if (holder.isExpanded()) {
|
||||||
holder.collapse();
|
holder.collapse();
|
||||||
expandList.remove(policy);
|
expandList[position] = false;
|
||||||
} else {
|
} else {
|
||||||
holder.expand();
|
holder.expand();
|
||||||
expandList.add(policy);
|
expandList[position] = true;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -145,7 +145,8 @@ public class PolicyAdapter extends RecyclerView.Adapter<PolicyAdapter.ViewHolder
|
|||||||
@BindView(R.id.notification_switch) SwitchCompat notificationSwitch;
|
@BindView(R.id.notification_switch) SwitchCompat notificationSwitch;
|
||||||
@BindView(R.id.logging_switch) SwitchCompat loggingSwitch;
|
@BindView(R.id.logging_switch) SwitchCompat loggingSwitch;
|
||||||
@BindView(R.id.expand_layout) ViewGroup expandLayout;
|
@BindView(R.id.expand_layout) ViewGroup expandLayout;
|
||||||
|
@BindView(R.id.arrow) ImageView arrow;
|
||||||
|
@BindView(R.id.trigger) View trigger;
|
||||||
@BindView(R.id.delete) ImageView delete;
|
@BindView(R.id.delete) ImageView delete;
|
||||||
@BindView(R.id.more_info) ImageView moreInfo;
|
@BindView(R.id.more_info) ImageView moreInfo;
|
||||||
|
|
||||||
@ -162,5 +163,31 @@ public class PolicyAdapter extends RecyclerView.Adapter<PolicyAdapter.ViewHolder
|
|||||||
public Container getContainer() {
|
public Container getContainer() {
|
||||||
return container;
|
return container;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void setExpanded(boolean expanded) {
|
||||||
|
ExpandableView.super.setExpanded(expanded);
|
||||||
|
arrow.setRotation(expanded ? 180 : 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void setRotate(RotateAnimation rotate) {
|
||||||
|
rotate.setDuration(300);
|
||||||
|
rotate.setFillAfter(true);
|
||||||
|
arrow.startAnimation(rotate);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void expand() {
|
||||||
|
ExpandableView.super.expand();
|
||||||
|
setRotate(new RotateAnimation(0, 180,
|
||||||
|
Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF, 0.5f));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void collapse() {
|
||||||
|
ExpandableView.super.collapse();
|
||||||
|
setRotate(new RotateAnimation(180, 0,
|
||||||
|
Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF, 0.5f));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -72,13 +72,22 @@
|
|||||||
android:layout_width="20dp"
|
android:layout_width="20dp"
|
||||||
android:layout_height="20dp"
|
android:layout_height="20dp"
|
||||||
android:layout_marginStart="5dp"
|
android:layout_marginStart="5dp"
|
||||||
|
android:tint="@color/icon_grey"
|
||||||
app:layout_constraintBottom_toBottomOf="@+id/package_name"
|
app:layout_constraintBottom_toBottomOf="@+id/package_name"
|
||||||
app:layout_constraintEnd_toEndOf="@+id/app_name"
|
app:layout_constraintEnd_toEndOf="@+id/app_name"
|
||||||
app:layout_constraintStart_toEndOf="@+id/package_name"
|
app:layout_constraintStart_toEndOf="@+id/package_name"
|
||||||
app:layout_constraintTop_toTopOf="@+id/package_name"
|
app:layout_constraintTop_toTopOf="@+id/package_name"
|
||||||
android:tint="@color/icon_grey"
|
|
||||||
app:srcCompat="@drawable/ic_arrow" />
|
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" />
|
||||||
|
|
||||||
<androidx.appcompat.widget.SwitchCompat
|
<androidx.appcompat.widget.SwitchCompat
|
||||||
android:id="@+id/master_switch"
|
android:id="@+id/master_switch"
|
||||||
android:layout_width="wrap_content"
|
android:layout_width="wrap_content"
|
||||||
|
Loading…
Reference in New Issue
Block a user