mirror of
https://github.com/topjohnwu/Magisk.git
synced 2026-01-15 06:14:04 -08:00
More refinements...
This commit is contained in:
@@ -3,13 +3,16 @@ package com.topjohnwu.magisk;
|
||||
import android.animation.Animator;
|
||||
import android.animation.ValueAnimator;
|
||||
import android.content.Context;
|
||||
import android.content.DialogInterface;
|
||||
import android.content.SharedPreferences;
|
||||
import android.graphics.Color;
|
||||
import android.os.Bundle;
|
||||
import android.preference.PreferenceManager;
|
||||
import android.support.annotation.Nullable;
|
||||
import android.support.design.widget.Snackbar;
|
||||
import android.support.v4.app.Fragment;
|
||||
import android.support.v4.widget.SwipeRefreshLayout;
|
||||
import android.support.v7.app.AlertDialog;
|
||||
import android.support.v7.widget.RecyclerView;
|
||||
import android.util.DisplayMetrics;
|
||||
import android.util.Log;
|
||||
@@ -29,17 +32,22 @@ import com.topjohnwu.magisk.utils.Shell;
|
||||
import com.topjohnwu.magisk.utils.Utils;
|
||||
import com.topjohnwu.magisk.utils.WebWindow;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
|
||||
import butterknife.BindView;
|
||||
import butterknife.ButterKnife;
|
||||
|
||||
public abstract class BaseModuleFragment extends Fragment {
|
||||
@BindView(R.id.swipeRefreshLayout) SwipeRefreshLayout mSwipeRefreshLayout;
|
||||
@BindView(R.id.recyclerView) RecyclerView recyclerView;
|
||||
@BindView(R.id.empty_rv) TextView emptyTv;
|
||||
|
||||
@BindView(R.id.swipeRefreshLayout)
|
||||
SwipeRefreshLayout mSwipeRefreshLayout;
|
||||
@BindView(R.id.recyclerView)
|
||||
RecyclerView recyclerView;
|
||||
@BindView(R.id.empty_rv)
|
||||
TextView emptyTv;
|
||||
|
||||
private RepoHelper.TaskDelegate mDelegate;
|
||||
private SharedPreferences prefs;
|
||||
|
||||
@@ -55,13 +63,16 @@ public abstract class BaseModuleFragment extends Fragment {
|
||||
|
||||
|
||||
ButterKnife.bind(this, viewMain);
|
||||
mSwipeRefreshLayout.setOnRefreshListener(() -> {
|
||||
Log.d("Magisk","ModulesFragment: SWIPE");
|
||||
mDelegate.taskCompletionResult("OK");
|
||||
});
|
||||
|
||||
|
||||
prefs = PreferenceManager.getDefaultSharedPreferences(getActivity());
|
||||
mSwipeRefreshLayout.setOnRefreshListener(() -> {
|
||||
|
||||
mDelegate.taskCompletionResult("OK");
|
||||
prefs.edit().putBoolean("ignoreUpdateAlerts", false).apply();
|
||||
|
||||
|
||||
});
|
||||
prefs.registerOnSharedPreferenceChangeListener((sharedPreferences, s) -> {
|
||||
if (s.contains("updated")) {
|
||||
viewMain.invalidate();
|
||||
@@ -98,6 +109,8 @@ public abstract class BaseModuleFragment extends Fragment {
|
||||
listModules().get(position).deleteRemoveFile();
|
||||
Snackbar.make(undeleteBtn, R.string.remove_file_deleted, Snackbar.LENGTH_SHORT).show();
|
||||
}));
|
||||
|
||||
|
||||
return viewMain;
|
||||
}
|
||||
|
||||
@@ -107,20 +120,27 @@ public abstract class BaseModuleFragment extends Fragment {
|
||||
public class ModulesAdapter extends RecyclerView.Adapter<ModulesAdapter.ViewHolder> {
|
||||
|
||||
private final List<Module> mList;
|
||||
private final List<Module> mListToUpdate = new ArrayList<>();
|
||||
List<Boolean> mExpandedList;
|
||||
@BindView(R.id.expand_layout)
|
||||
@BindView(R.id.expand_layout)
|
||||
LinearLayout expandedLayout;
|
||||
private View viewMain;
|
||||
private Context context;
|
||||
private Context context;
|
||||
private final Utils.ItemClickListener chboxListener;
|
||||
private final Utils.ItemClickListener deleteBtnListener;
|
||||
private final Utils.ItemClickListener unDeleteBtnListener;
|
||||
private boolean alertUpdate, ignoreAlertUpdate;
|
||||
|
||||
public ModulesAdapter(List<Module> list, Utils.ItemClickListener chboxListener, Utils.ItemClickListener deleteBtnListener, Utils.ItemClickListener undeleteBtnListener) {
|
||||
alertUpdate = false;
|
||||
this.mList = list;
|
||||
mExpandedList = new ArrayList<>(mList.size());
|
||||
mExpandedList = new ArrayList<>(mList.size());
|
||||
for (int i = 0; i < mList.size(); i++) {
|
||||
mExpandedList.add(false);
|
||||
if (listModules().get(i).isUpdateAvailable()) {
|
||||
alertUpdate = true;
|
||||
mListToUpdate.add(listModules().get(i));
|
||||
}
|
||||
}
|
||||
this.chboxListener = chboxListener;
|
||||
this.deleteBtnListener = deleteBtnListener;
|
||||
@@ -130,43 +150,84 @@ public abstract class BaseModuleFragment extends Fragment {
|
||||
@Override
|
||||
public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
|
||||
viewMain = LayoutInflater.from(parent.getContext()).inflate(R.layout.list_item_module, parent, false);
|
||||
context = parent.getContext();
|
||||
ButterKnife.bind(this, viewMain);
|
||||
context = parent.getContext();
|
||||
ButterKnife.bind(this, viewMain);
|
||||
return new ViewHolder(viewMain);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onBindViewHolder(final ViewHolder holder, int position) {
|
||||
final Module module = mList.get(position);
|
||||
Log.d("Magisk","ModulesAdapter: Trying set up bindview from list pos " + position + " and " + module.getName() );
|
||||
|
||||
Log.d("Magisk", "ModulesAdapter: Trying set up bindview from list pos " + position + " and " + module.getName());
|
||||
Log.d("Magisk", "BaseModuleFragment: Log ID is " + module.getmLogUrl());
|
||||
holder.title.setText(module.getName());
|
||||
holder.versionName.setText(module.getVersion());
|
||||
holder.description.setText(module.getDescription());
|
||||
holder.author.setText(module.getAuthor());
|
||||
|
||||
String logUrl = module.getmLogUrl();
|
||||
String supportUrl = module.getmSupportUrl();
|
||||
String donateUrl = module.getmDonateUrl();
|
||||
if (supportUrl != null && !supportUrl.isEmpty()) holder.supportLink.setBackgroundColor(Color.GRAY);
|
||||
if (logUrl != null && !logUrl.isEmpty()) holder.changeLog.setBackgroundColor(Color.GRAY);
|
||||
if (donateUrl != null && !donateUrl.isEmpty()) holder.authorLink.setBackgroundColor(Color.GRAY);
|
||||
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
|
||||
if (prefs.contains("ignoreUpdateAlerts")) {
|
||||
ignoreAlertUpdate = prefs.getBoolean("ignoreUpdateAlerts", false);
|
||||
}
|
||||
if (prefs.contains("repo-canUpdate_" + module.getId())) {
|
||||
if (prefs.getBoolean("repo-canUpdate_" + module.getId(),false)) {
|
||||
if (prefs.getBoolean("repo-canUpdate_" + module.getId(), false)) {
|
||||
holder.updateStatus.setText(R.string.module_update_available);
|
||||
holder.updateStatus.setVisibility(View.VISIBLE);
|
||||
} else {
|
||||
holder.updateStatus.setVisibility(View.GONE);
|
||||
}
|
||||
|
||||
if (alertUpdate && !ignoreAlertUpdate) {
|
||||
Iterator<Module> iterRepo = mListToUpdate.iterator();
|
||||
while (iterRepo.hasNext()) {
|
||||
Module mModule = iterRepo.next();
|
||||
DialogInterface.OnClickListener dialogClickListener = (dialog, which) -> {
|
||||
switch (which) {
|
||||
case DialogInterface.BUTTON_POSITIVE:
|
||||
Utils.DownloadReceiver receiver = new Utils.DownloadReceiver() {
|
||||
@Override
|
||||
public void task(File file) {
|
||||
Log.d("Magisk", "Task firing");
|
||||
new Utils.FlashZIP(context, mModule.getId(), file.toString()).execute();
|
||||
}
|
||||
};
|
||||
String filename = mModule.getId().replace(" ", "") + ".zip";
|
||||
Utils.downloadAndReceive(context, receiver, mModule.getmZipUrl(), filename);
|
||||
|
||||
break;
|
||||
|
||||
case DialogInterface.BUTTON_NEGATIVE:
|
||||
ignoreAlertUpdate = true;
|
||||
SharedPreferences.Editor editor = prefs.edit();
|
||||
editor.putBoolean("ignoreUpdateAlerts", ignoreAlertUpdate);
|
||||
editor.apply();
|
||||
break;
|
||||
}
|
||||
};
|
||||
|
||||
AlertDialog.Builder builder = new AlertDialog.Builder(context);
|
||||
builder.setMessage("An update is available for " + mModule.getName() + ". Would you like to install it?").setPositiveButton("Yes", dialogClickListener)
|
||||
.setNegativeButton("No", dialogClickListener).show();
|
||||
mListToUpdate.remove(mModule);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
View.OnClickListener oCl = new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View view) {
|
||||
if (view.getId() == holder.changeLog.getId()) {
|
||||
new WebWindow("Changelog",module.getChangeLog(),context);
|
||||
}
|
||||
if (view.getId() == holder.authorLink.getId()) {
|
||||
new WebWindow("Donate",module.getmDonateUrl(),context);
|
||||
}
|
||||
if (view.getId() == holder.supportLink.getId()) {
|
||||
new WebWindow("Support",module.getmSupportUrl(),context);
|
||||
}
|
||||
View.OnClickListener oCl = view -> {
|
||||
if (view.getId() == holder.changeLog.getId()) {
|
||||
|
||||
new WebWindow("Changelog", module.getmLogUrl(), context);
|
||||
}
|
||||
if (view.getId() == holder.authorLink.getId()) {
|
||||
new WebWindow("Donate", module.getmDonateUrl(), context);
|
||||
}
|
||||
if (view.getId() == holder.supportLink.getId()) {
|
||||
new WebWindow("Support", module.getmSupportUrl(), context);
|
||||
}
|
||||
};
|
||||
|
||||
@@ -206,19 +267,31 @@ public abstract class BaseModuleFragment extends Fragment {
|
||||
|
||||
class ViewHolder extends RecyclerView.ViewHolder {
|
||||
|
||||
@BindView(R.id.title) TextView title;
|
||||
@BindView(R.id.title)
|
||||
TextView title;
|
||||
|
||||
@BindView(R.id.version_name) TextView versionName;
|
||||
@BindView(R.id.description) TextView description;
|
||||
@BindView(R.id.warning) TextView warning;
|
||||
@BindView(R.id.checkbox) CheckBox checkBox;
|
||||
@BindView(R.id.author) TextView author;
|
||||
@BindView(R.id.updateStatus) TextView updateStatus;
|
||||
@BindView(R.id.delete) ImageView delete;
|
||||
@BindView(R.id.changeLog) ImageView changeLog;
|
||||
@BindView(R.id.authorLink) ImageView authorLink;
|
||||
@BindView(R.id.supportLink) ImageView supportLink;
|
||||
@BindView(R.id.expand_layout) LinearLayout expandLayout;
|
||||
@BindView(R.id.version_name)
|
||||
TextView versionName;
|
||||
@BindView(R.id.description)
|
||||
TextView description;
|
||||
@BindView(R.id.warning)
|
||||
TextView warning;
|
||||
@BindView(R.id.checkbox)
|
||||
CheckBox checkBox;
|
||||
@BindView(R.id.author)
|
||||
TextView author;
|
||||
@BindView(R.id.updateStatus)
|
||||
TextView updateStatus;
|
||||
@BindView(R.id.delete)
|
||||
ImageView delete;
|
||||
@BindView(R.id.changeLog)
|
||||
ImageView changeLog;
|
||||
@BindView(R.id.authorLink)
|
||||
ImageView authorLink;
|
||||
@BindView(R.id.supportLink)
|
||||
ImageView supportLink;
|
||||
@BindView(R.id.expand_layout)
|
||||
LinearLayout expandLayout;
|
||||
private ValueAnimator mAnimator;
|
||||
private int mMeasuredHeight;
|
||||
|
||||
@@ -226,19 +299,19 @@ public abstract class BaseModuleFragment extends Fragment {
|
||||
super(itemView);
|
||||
WindowManager windowmanager = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE);
|
||||
ButterKnife.bind(this, itemView);
|
||||
DisplayMetrics dimension = new DisplayMetrics();
|
||||
DisplayMetrics dimension = new DisplayMetrics();
|
||||
windowmanager.getDefaultDisplay().getMetrics(dimension);
|
||||
final int mHeight = dimension.heightPixels;
|
||||
|
||||
expandLayout.getViewTreeObserver().addOnPreDrawListener(
|
||||
new ViewTreeObserver.OnPreDrawListener() {
|
||||
|
||||
|
||||
@Override
|
||||
public boolean onPreDraw() {
|
||||
expandLayout.getViewTreeObserver().removeOnPreDrawListener(this);
|
||||
expandLayout.setVisibility(View.GONE);
|
||||
final int widthSpec = View.MeasureSpec.makeMeasureSpec(0, View.MeasureSpec.UNSPECIFIED);
|
||||
final int heightSpec = View.MeasureSpec.makeMeasureSpec(0,View.MeasureSpec.UNSPECIFIED);
|
||||
final int heightSpec = View.MeasureSpec.makeMeasureSpec(0, View.MeasureSpec.UNSPECIFIED);
|
||||
expandLayout.measure(widthSpec, heightSpec);
|
||||
mAnimator = slideAnimator(0, expandLayout.getMeasuredHeight());
|
||||
return true;
|
||||
@@ -262,58 +335,59 @@ public abstract class BaseModuleFragment extends Fragment {
|
||||
delete.setEnabled(false);
|
||||
}
|
||||
}
|
||||
private void expand(View view) {
|
||||
|
||||
// set Visible
|
||||
private void expand(View view) {
|
||||
|
||||
// set Visible
|
||||
|
||||
|
||||
Log.d("Magisk", "ReposFragment: Expand anim called " + mMeasuredHeight + " and " + view.getId());
|
||||
view.setVisibility(View.VISIBLE);
|
||||
mAnimator.start();
|
||||
}
|
||||
Log.d("Magisk", "ReposFragment: Expand anim called " + mMeasuredHeight + " and " + view.getId());
|
||||
view.setVisibility(View.VISIBLE);
|
||||
mAnimator.start();
|
||||
}
|
||||
|
||||
private void collapse(View view) {
|
||||
int finalHeight = view.getHeight();
|
||||
ValueAnimator mAnimator = slideAnimator(finalHeight, 0);
|
||||
Log.d("Magisk", "ReposFragment: Collapse anim called " + finalHeight + " and " + view.getId());
|
||||
private void collapse(View view) {
|
||||
int finalHeight = view.getHeight();
|
||||
ValueAnimator mAnimator = slideAnimator(finalHeight, 0);
|
||||
Log.d("Magisk", "ReposFragment: Collapse anim called " + finalHeight + " and " + view.getId());
|
||||
|
||||
mAnimator.addListener(new Animator.AnimatorListener() {
|
||||
@Override
|
||||
public void onAnimationEnd(Animator animator) {
|
||||
// Height=0, but it set visibility to GONE
|
||||
view.setVisibility(View.GONE);
|
||||
}
|
||||
mAnimator.addListener(new Animator.AnimatorListener() {
|
||||
@Override
|
||||
public void onAnimationEnd(Animator animator) {
|
||||
// Height=0, but it set visibility to GONE
|
||||
view.setVisibility(View.GONE);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onAnimationStart(Animator animator) {
|
||||
}
|
||||
@Override
|
||||
public void onAnimationStart(Animator animator) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onAnimationCancel(Animator animator) {
|
||||
}
|
||||
@Override
|
||||
public void onAnimationCancel(Animator animator) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onAnimationRepeat(Animator animator) {
|
||||
}
|
||||
});
|
||||
mAnimator.start();
|
||||
}
|
||||
@Override
|
||||
public void onAnimationRepeat(Animator animator) {
|
||||
}
|
||||
});
|
||||
mAnimator.start();
|
||||
}
|
||||
|
||||
private ValueAnimator slideAnimator(int start, int end) {
|
||||
private ValueAnimator slideAnimator(int start, int end) {
|
||||
|
||||
ValueAnimator animator = ValueAnimator.ofInt(start, end);
|
||||
ValueAnimator animator = ValueAnimator.ofInt(start, end);
|
||||
|
||||
animator.addUpdateListener(valueAnimator -> {
|
||||
// Update Height
|
||||
int value = (Integer) valueAnimator.getAnimatedValue();
|
||||
animator.addUpdateListener(valueAnimator -> {
|
||||
// Update Height
|
||||
int value = (Integer) valueAnimator.getAnimatedValue();
|
||||
|
||||
ViewGroup.LayoutParams layoutParams = expandLayout
|
||||
.getLayoutParams();
|
||||
layoutParams.height = value;
|
||||
expandLayout.setLayoutParams(layoutParams);
|
||||
});
|
||||
return animator;
|
||||
}
|
||||
ViewGroup.LayoutParams layoutParams = expandLayout
|
||||
.getLayoutParams();
|
||||
layoutParams.height = value;
|
||||
expandLayout.setLayoutParams(layoutParams);
|
||||
});
|
||||
return animator;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user