diff --git a/app/src/main/java/com/topjohnwu/magisk/FlashActivity.java b/app/src/main/java/com/topjohnwu/magisk/FlashActivity.java index 6cf3ffbe2..9fbcc00e9 100644 --- a/app/src/main/java/com/topjohnwu/magisk/FlashActivity.java +++ b/app/src/main/java/com/topjohnwu/magisk/FlashActivity.java @@ -14,7 +14,6 @@ import android.widget.TextView; import com.topjohnwu.magisk.asyncs.FlashZip; import com.topjohnwu.magisk.components.Activity; import com.topjohnwu.magisk.utils.AdaptiveList; -import com.topjohnwu.magisk.utils.Shell; import butterknife.BindView; import butterknife.ButterKnife; diff --git a/app/src/main/java/com/topjohnwu/magisk/MagiskFragment.java b/app/src/main/java/com/topjohnwu/magisk/MagiskFragment.java index 160335a5f..a9d5d35c9 100644 --- a/app/src/main/java/com/topjohnwu/magisk/MagiskFragment.java +++ b/app/src/main/java/com/topjohnwu/magisk/MagiskFragment.java @@ -1,7 +1,5 @@ package com.topjohnwu.magisk; -import android.animation.Animator; -import android.animation.ValueAnimator; import android.app.NotificationManager; import android.app.ProgressDialog; import android.content.Context; @@ -16,7 +14,6 @@ import android.support.v7.widget.CardView; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; -import android.view.ViewTreeObserver; import android.widget.ArrayAdapter; import android.widget.Button; import android.widget.CheckBox; @@ -28,6 +25,7 @@ import android.widget.TextView; import com.topjohnwu.magisk.asyncs.CheckUpdates; import com.topjohnwu.magisk.components.AlertDialogBuilder; +import com.topjohnwu.magisk.components.ExpandableView; import com.topjohnwu.magisk.components.Fragment; import com.topjohnwu.magisk.components.SnackbarMaker; import com.topjohnwu.magisk.receivers.DownloadReceiver; @@ -49,15 +47,14 @@ import butterknife.OnClick; import butterknife.Unbinder; public class MagiskFragment extends Fragment - implements Topic.Subscriber, SwipeRefreshLayout.OnRefreshListener { + implements Topic.Subscriber, SwipeRefreshLayout.OnRefreshListener, ExpandableView { public static final String SHOW_DIALOG = "dialog"; private static final String UNINSTALLER = "magisk_uninstaller.sh"; private static final String UTIL_FUNCTIONS= "util_functions.sh"; - private static int expandHeight = 0; - private static boolean mExpanded = false; + private Container expandableContainer = new Container(); private MagiskManager magiskManager; private Unbinder unbinder; @@ -231,23 +228,8 @@ public class MagiskFragment extends Fragment unbinder = ButterKnife.bind(this, v); magiskManager = getApplication(); - expandLayout.getViewTreeObserver().addOnPreDrawListener( - new ViewTreeObserver.OnPreDrawListener() { - @Override - public boolean onPreDraw() { - if (expandHeight == 0) { - final int widthSpec = View.MeasureSpec.makeMeasureSpec(0, View.MeasureSpec.UNSPECIFIED); - final int heightSpec = View.MeasureSpec.makeMeasureSpec(0, View.MeasureSpec.UNSPECIFIED); - expandLayout.measure(widthSpec, heightSpec); - expandHeight = expandLayout.getMeasuredHeight(); - } - - expandLayout.getViewTreeObserver().removeOnPreDrawListener(this); - setExpanded(); - return true; - } - - }); + expandableContainer.expandLayout = expandLayout; + setupExpandable(); mSwipeRefreshLayout.setOnRefreshListener(this); @@ -306,6 +288,11 @@ public class MagiskFragment extends Fragment unbinder.unbind(); } + @Override + public Container getContainer() { + return expandableContainer; + } + private void updateUI() { ((MainActivity) getActivity()).checkHideSection(); @@ -440,56 +427,5 @@ public class MagiskFragment extends Fragment expand(); } } - - private void setExpanded() { - ViewGroup.LayoutParams layoutParams = expandLayout.getLayoutParams(); - layoutParams.height = mExpanded ? expandHeight : 0; - expandLayout.setLayoutParams(layoutParams); - expandLayout.setVisibility(mExpanded ? View.VISIBLE : View.GONE); - } - - private void expand() { - if (mExpanded) return; - expandLayout.setVisibility(View.VISIBLE); - ValueAnimator mAnimator = slideAnimator(0, expandHeight); - mAnimator.start(); - mExpanded = true; - } - - private void collapse() { - if (!mExpanded) return; - int finalHeight = expandLayout.getHeight(); - ValueAnimator mAnimator = slideAnimator(finalHeight, 0); - mAnimator.addListener(new Animator.AnimatorListener() { - @Override - public void onAnimationEnd(Animator animator) { - expandLayout.setVisibility(View.GONE); - } - - @Override - public void onAnimationStart(Animator animator) {} - - @Override - public void onAnimationCancel(Animator animator) {} - - @Override - public void onAnimationRepeat(Animator animator) {} - }); - mAnimator.start(); - mExpanded = false; - } - - private ValueAnimator slideAnimator(int start, int end) { - - ValueAnimator animator = ValueAnimator.ofInt(start, end); - - animator.addUpdateListener(valueAnimator -> { - int value = (Integer) valueAnimator.getAnimatedValue(); - ViewGroup.LayoutParams layoutParams = expandLayout.getLayoutParams(); - layoutParams.height = value; - expandLayout.setLayoutParams(layoutParams); - }); - return animator; - } } diff --git a/app/src/main/java/com/topjohnwu/magisk/adapters/PolicyAdapter.java b/app/src/main/java/com/topjohnwu/magisk/adapters/PolicyAdapter.java index 40c25eff6..bdf092fd7 100644 --- a/app/src/main/java/com/topjohnwu/magisk/adapters/PolicyAdapter.java +++ b/app/src/main/java/com/topjohnwu/magisk/adapters/PolicyAdapter.java @@ -12,7 +12,7 @@ import android.widget.TextView; import com.topjohnwu.magisk.R; import com.topjohnwu.magisk.components.AlertDialogBuilder; -import com.topjohnwu.magisk.components.ExpandableViewHolder; +import com.topjohnwu.magisk.components.ExpandableView; import com.topjohnwu.magisk.components.SnackbarMaker; import com.topjohnwu.magisk.database.SuDatabaseHelper; import com.topjohnwu.magisk.superuser.Policy; @@ -50,7 +50,7 @@ public class PolicyAdapter extends RecyclerView.Adapter { - if (holder.mExpanded) { + if (holder.isExpanded()) { holder.collapse(); expandList.remove(policy); } else { @@ -119,7 +119,7 @@ public class PolicyAdapter extends RecyclerView.Adapter { - if (holder.mExpanded) { + if (holder.isExpanded()) { holder.collapse(); itemExpanded.remove(sqlPosition); } else { @@ -128,7 +128,7 @@ public class SuLogAdapter extends SectionedAdapter { + int value = (Integer) valueAnimator.getAnimatedValue(); + ViewGroup.LayoutParams layoutParams = container.expandLayout.getLayoutParams(); + layoutParams.height = value; + container.expandLayout.setLayoutParams(layoutParams); + }); + return animator; + } +} diff --git a/app/src/main/java/com/topjohnwu/magisk/components/ExpandableViewHolder.java b/app/src/main/java/com/topjohnwu/magisk/components/ExpandableViewHolder.java deleted file mode 100644 index 5d5ef9cd9..000000000 --- a/app/src/main/java/com/topjohnwu/magisk/components/ExpandableViewHolder.java +++ /dev/null @@ -1,77 +0,0 @@ -package com.topjohnwu.magisk.components; - -import android.animation.ValueAnimator; -import android.support.v7.widget.RecyclerView; -import android.view.View; -import android.view.ViewGroup; -import android.view.ViewTreeObserver; - -public abstract class ExpandableViewHolder extends RecyclerView.ViewHolder { - - protected ViewGroup expandLayout; - private ValueAnimator expandAnimator, collapseAnimator; - private static int expandHeight = 0; - - public boolean mExpanded = false; - - public ExpandableViewHolder(View itemView) { - super(itemView); - setExpandLayout(itemView); - expandLayout.getViewTreeObserver().addOnPreDrawListener( - new ViewTreeObserver.OnPreDrawListener() { - - @Override - public boolean onPreDraw() { - if (expandHeight == 0) { - final int widthSpec = View.MeasureSpec.makeMeasureSpec(0, View.MeasureSpec.UNSPECIFIED); - final int heightSpec = View.MeasureSpec.makeMeasureSpec(0, View.MeasureSpec.UNSPECIFIED); - expandLayout.measure(widthSpec, heightSpec); - expandHeight = expandLayout.getMeasuredHeight(); - } - - expandLayout.getViewTreeObserver().removeOnPreDrawListener(this); - expandLayout.setVisibility(View.GONE); - expandAnimator = slideAnimator(0, expandHeight); - collapseAnimator = slideAnimator(expandHeight, 0); - return true; - } - - }); - } - - public void setExpanded(boolean expanded) { - mExpanded = expanded; - ViewGroup.LayoutParams layoutParams = expandLayout.getLayoutParams(); - layoutParams.height = expanded ? expandHeight : 0; - expandLayout.setLayoutParams(layoutParams); - expandLayout.setVisibility(expanded ? View.VISIBLE : View.GONE); - } - - public void expand() { - if (mExpanded) return; - expandLayout.setVisibility(View.VISIBLE); - expandAnimator.start(); - mExpanded = true; - } - - public void collapse() { - if (!mExpanded) return; - collapseAnimator.start(); - mExpanded = false; - } - - public abstract void setExpandLayout(View itemView); - - private ValueAnimator slideAnimator(int start, int end) { - - ValueAnimator animator = ValueAnimator.ofInt(start, end); - - animator.addUpdateListener(valueAnimator -> { - int value = (Integer) valueAnimator.getAnimatedValue(); - ViewGroup.LayoutParams layoutParams = expandLayout.getLayoutParams(); - layoutParams.height = value; - expandLayout.setLayoutParams(layoutParams); - }); - return animator; - } -} diff --git a/app/src/main/java/com/topjohnwu/magisk/utils/Topic.java b/app/src/main/java/com/topjohnwu/magisk/utils/Topic.java index 515dcd9b7..4864a63b8 100644 --- a/app/src/main/java/com/topjohnwu/magisk/utils/Topic.java +++ b/app/src/main/java/com/topjohnwu/magisk/utils/Topic.java @@ -34,8 +34,8 @@ public class Topic { publish(true); } - public void publish(boolean b) { - hasPublished = b; + public void publish(boolean record) { + hasPublished = record; if (subscribers != null) { for (WeakReference subscriber : subscribers) { if (subscriber.get() != null) diff --git a/app/src/main/java/com/topjohnwu/magisk/utils/Utils.java b/app/src/main/java/com/topjohnwu/magisk/utils/Utils.java index 9d2da3974..d0f131846 100644 --- a/app/src/main/java/com/topjohnwu/magisk/utils/Utils.java +++ b/app/src/main/java/com/topjohnwu/magisk/utils/Utils.java @@ -142,7 +142,7 @@ public class Utils { @Override public void handleResults(Result result) { getMagiskManager(mActivity).SNCheckResult = result; - getMagiskManager(mActivity).safetyNetDone.publish(); + getMagiskManager(mActivity).safetyNetDone.publish(false); } }.requestTest(); }