Looking good...
This commit is contained in:
parent
214649ec20
commit
1a1d37a2d0
@ -1,5 +1,8 @@
|
||||
package com.topjohnwu.magisk;
|
||||
|
||||
import android.animation.Animator;
|
||||
import android.animation.ValueAnimator;
|
||||
import android.content.Context;
|
||||
import android.content.SharedPreferences;
|
||||
import android.os.Bundle;
|
||||
import android.preference.PreferenceManager;
|
||||
@ -7,18 +10,23 @@ import android.support.annotation.Nullable;
|
||||
import android.support.design.widget.Snackbar;
|
||||
import android.support.v4.app.Fragment;
|
||||
import android.support.v7.widget.RecyclerView;
|
||||
import android.util.DisplayMetrics;
|
||||
import android.util.Log;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.view.ViewTreeObserver;
|
||||
import android.view.WindowManager;
|
||||
import android.widget.CheckBox;
|
||||
import android.widget.ImageView;
|
||||
import android.widget.LinearLayout;
|
||||
import android.widget.TextView;
|
||||
|
||||
import com.topjohnwu.magisk.module.Module;
|
||||
import com.topjohnwu.magisk.utils.Shell;
|
||||
import com.topjohnwu.magisk.utils.Utils;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import butterknife.BindView;
|
||||
@ -35,17 +43,17 @@ public abstract class BaseModuleFragment extends Fragment {
|
||||
@Nullable
|
||||
@Override
|
||||
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
|
||||
View view = inflater.inflate(R.layout.single_module_fragment, container, false);
|
||||
View viewMain = inflater.inflate(R.layout.single_module_fragment, container, false);
|
||||
|
||||
|
||||
ButterKnife.bind(this, view);
|
||||
ButterKnife.bind(this, viewMain);
|
||||
prefs = PreferenceManager.getDefaultSharedPreferences(getActivity());
|
||||
prefs.registerOnSharedPreferenceChangeListener(new SharedPreferences.OnSharedPreferenceChangeListener() {
|
||||
@Override
|
||||
public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, String s) {
|
||||
if (s.contains("updated")) {
|
||||
view.invalidate();
|
||||
view.requestLayout();
|
||||
viewMain.invalidate();
|
||||
viewMain.requestLayout();
|
||||
|
||||
}
|
||||
}
|
||||
@ -54,7 +62,7 @@ public abstract class BaseModuleFragment extends Fragment {
|
||||
emptyTv.setVisibility(View.VISIBLE);
|
||||
recyclerView.setVisibility(View.GONE);
|
||||
|
||||
return view;
|
||||
return viewMain;
|
||||
}
|
||||
|
||||
recyclerView.setAdapter(new ModulesAdapter(listModules(), (chk, position) -> {
|
||||
@ -79,7 +87,7 @@ public abstract class BaseModuleFragment extends Fragment {
|
||||
listModules().get(position).deleteRemoveFile();
|
||||
Snackbar.make(undeleteBtn, R.string.remove_file_deleted, Snackbar.LENGTH_SHORT).show();
|
||||
}));
|
||||
return view;
|
||||
return viewMain;
|
||||
}
|
||||
|
||||
|
||||
@ -88,12 +96,21 @@ public abstract class BaseModuleFragment extends Fragment {
|
||||
public class ModulesAdapter extends RecyclerView.Adapter<ModulesAdapter.ViewHolder> {
|
||||
|
||||
private final List<Module> mList;
|
||||
List<Boolean> mExpandedList;
|
||||
@BindView(R.id.expand_layout)
|
||||
LinearLayout expandedLayout;
|
||||
private View viewMain;
|
||||
private Context context;
|
||||
private final Utils.ItemClickListener chboxListener;
|
||||
private final Utils.ItemClickListener deleteBtnListener;
|
||||
private final Utils.ItemClickListener unDeleteBtnListener;
|
||||
|
||||
public ModulesAdapter(List<Module> list, Utils.ItemClickListener chboxListener, Utils.ItemClickListener deleteBtnListener, Utils.ItemClickListener undeleteBtnListener) {
|
||||
this.mList = list;
|
||||
mExpandedList = new ArrayList<>(mList.size());
|
||||
for (int i = 0; i < mList.size(); i++) {
|
||||
mExpandedList.add(false);
|
||||
}
|
||||
this.chboxListener = chboxListener;
|
||||
this.deleteBtnListener = deleteBtnListener;
|
||||
this.unDeleteBtnListener = undeleteBtnListener;
|
||||
@ -101,9 +118,10 @@ public abstract class BaseModuleFragment extends Fragment {
|
||||
|
||||
@Override
|
||||
public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
|
||||
View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.list_item_module, parent, false);
|
||||
|
||||
return new ViewHolder(view);
|
||||
viewMain = LayoutInflater.from(parent.getContext()).inflate(R.layout.list_item_module, parent, false);
|
||||
context = parent.getContext();
|
||||
ButterKnife.bind(this, viewMain);
|
||||
return new ViewHolder(viewMain);
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -158,15 +176,103 @@ public abstract class BaseModuleFragment extends Fragment {
|
||||
@BindView(R.id.checkbox) CheckBox checkBox;
|
||||
@BindView(R.id.delete)
|
||||
ImageView delete;
|
||||
@BindView(R.id.expand_layout)
|
||||
LinearLayout expandLayout;
|
||||
private ValueAnimator mAnimator;
|
||||
private int mMeasuredHeight;
|
||||
|
||||
public ViewHolder(View itemView) {
|
||||
super(itemView);
|
||||
WindowManager windowmanager = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE);
|
||||
ButterKnife.bind(this, itemView);
|
||||
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);
|
||||
expandLayout.measure(widthSpec, heightSpec);
|
||||
mAnimator = slideAnimator(0, expandLayout.getMeasuredHeight());
|
||||
return true;
|
||||
}
|
||||
});
|
||||
|
||||
viewMain.setOnClickListener(view -> {
|
||||
int position = getAdapterPosition();
|
||||
Log.d("Magisk", "BaseRepoFragment: CLICK. " + position + " and " + mExpandedList.get(position));
|
||||
|
||||
if (mExpandedList.get(position)) {
|
||||
collapse(expandLayout);
|
||||
} else {
|
||||
expand(expandLayout);
|
||||
}
|
||||
mExpandedList.set(position, !mExpandedList.get(position));
|
||||
|
||||
});
|
||||
if (!Shell.rootAccess()) {
|
||||
checkBox.setEnabled(false);
|
||||
delete.setEnabled(false);
|
||||
}
|
||||
}
|
||||
private void expand(View view) {
|
||||
|
||||
// set Visible
|
||||
|
||||
|
||||
Log.d("Magisk", "BaseRepoFragment: 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", "BaseRepoFragment: 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);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onAnimationStart(Animator animator) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onAnimationCancel(Animator animator) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onAnimationRepeat(Animator animator) {
|
||||
}
|
||||
});
|
||||
mAnimator.start();
|
||||
}
|
||||
|
||||
private ValueAnimator slideAnimator(int start, int end) {
|
||||
|
||||
ValueAnimator animator = ValueAnimator.ofInt(start, end);
|
||||
|
||||
animator.addUpdateListener(valueAnimator -> {
|
||||
// Update Height
|
||||
int value = (Integer) valueAnimator.getAnimatedValue();
|
||||
|
||||
ViewGroup.LayoutParams layoutParams = expandLayout
|
||||
.getLayoutParams();
|
||||
layoutParams.height = value;
|
||||
expandLayout.setLayoutParams(layoutParams);
|
||||
});
|
||||
return animator;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,26 +1,33 @@
|
||||
package com.topjohnwu.magisk;
|
||||
|
||||
import android.animation.Animator;
|
||||
import android.animation.ValueAnimator;
|
||||
import android.content.Context;
|
||||
import android.content.SharedPreferences;
|
||||
import android.graphics.Color;
|
||||
import android.os.Bundle;
|
||||
import android.preference.PreferenceManager;
|
||||
import android.support.annotation.Nullable;
|
||||
import android.support.v4.app.Fragment;
|
||||
import android.support.v7.widget.RecyclerView;
|
||||
import android.text.util.Linkify;
|
||||
import android.util.DisplayMetrics;
|
||||
import android.util.Log;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.view.ViewTreeObserver;
|
||||
import android.view.WindowManager;
|
||||
import android.widget.ImageView;
|
||||
import android.widget.LinearLayout;
|
||||
import android.widget.TextView;
|
||||
import android.widget.Toast;
|
||||
|
||||
import com.topjohnwu.magisk.module.Repo;
|
||||
import com.topjohnwu.magisk.utils.AnimationHelper;
|
||||
import com.topjohnwu.magisk.utils.Utils;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import butterknife.BindView;
|
||||
@ -33,15 +40,11 @@ public abstract class BaseRepoFragment extends Fragment {
|
||||
@BindView(R.id.empty_rv)
|
||||
TextView emptyTv;
|
||||
|
||||
|
||||
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
|
||||
View view = inflater.inflate(R.layout.single_module_fragment, container, false);
|
||||
|
||||
|
||||
ButterKnife.bind(this, view);
|
||||
|
||||
if (listRepos().size() == 0) {
|
||||
@ -50,7 +53,7 @@ public abstract class BaseRepoFragment extends Fragment {
|
||||
|
||||
return view;
|
||||
}
|
||||
Log.d("Magisk","BaseRepoFragment: ListRepos size is " + listRepos().size());
|
||||
Log.d("Magisk", "BaseRepoFragment: ListRepos size is " + listRepos().size());
|
||||
recyclerView.setAdapter(new ReposAdapter(listRepos()) {
|
||||
|
||||
});
|
||||
@ -63,21 +66,23 @@ public abstract class BaseRepoFragment extends Fragment {
|
||||
public class ReposAdapter extends RecyclerView.Adapter<ReposAdapter.ViewHolder> {
|
||||
|
||||
private final List<Repo> mList;
|
||||
private View viewMain;
|
||||
private Context context;
|
||||
List<Boolean> mExpandedList;
|
||||
@BindView(R.id.update)
|
||||
ImageView updateImage;
|
||||
@BindView(R.id.installed)
|
||||
ImageView installedImage;
|
||||
// @BindView(R.id.popup_layout)
|
||||
// LinearLayout popupLayout;
|
||||
|
||||
|
||||
private boolean isCardExpanded;
|
||||
@BindView(R.id.expand_layout)
|
||||
LinearLayout expandedLayout;
|
||||
private View viewMain;
|
||||
private Context context;
|
||||
private boolean mIsInstalled, mCanUpdate;
|
||||
|
||||
public ReposAdapter(List<Repo> list) {
|
||||
this.mList = list;
|
||||
mExpandedList = new ArrayList<>(mList.size());
|
||||
for (int i = 0; i < mList.size(); i++) {
|
||||
mExpandedList.add(false);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -92,64 +97,69 @@ public abstract class BaseRepoFragment extends Fragment {
|
||||
@Override
|
||||
public void onBindViewHolder(final ViewHolder holder, int position) {
|
||||
final Repo repo = mList.get(position);
|
||||
Log.d("Magisk","ReposAdapter: Trying set up bindview from list pos " + position + " out of a total of " + mList.size() + " and " + repo.getId() );
|
||||
|
||||
Log.d("Magisk", "ReposAdapter: Trying set up bindview from list pos " + position + " out of a total of " + mList.size() + " and " + repo.getId());
|
||||
if (repo.getId() != null) {
|
||||
TextView authorView = holder.author;
|
||||
holder.title.setText(repo.getName());
|
||||
holder.versionName.setText(repo.getmVersion());
|
||||
holder.description.setText(repo.getDescription());
|
||||
String authorString = getResources().getString(R.string.author) + " " + repo.getmAuthor();
|
||||
holder.author.setText(authorString);
|
||||
if ((repo.getmLogUrl() != null) && (repo.getmLogUrl().equals(""))) {
|
||||
holder.log.setText(repo.getmLogUrl());
|
||||
Linkify.addLinks(holder.log, Linkify.WEB_URLS);
|
||||
} else {
|
||||
holder.log.setVisibility(View.GONE);
|
||||
}
|
||||
holder.installedStatus.setText(repo.isInstalled() ? getResources().getString(R.string.module_installed) : getResources().getString(R.string.module_not_installed));
|
||||
if (mExpandedList.get(position)) {
|
||||
holder.expandLayout.setVisibility(View.VISIBLE);
|
||||
} else {
|
||||
holder.expandLayout.setVisibility(View.GONE);
|
||||
}
|
||||
if (repo.isInstalled()) {
|
||||
holder.installedStatus.setTextColor(Color.parseColor("#14AD00"));
|
||||
holder.updateStatus.setText(repo.canUpdate() ? getResources().getString(R.string.module_update_available) : getResources().getString(R.string.module_up_to_date));
|
||||
}
|
||||
Log.d("Magisk", "ReposAdapter: Setting up info " + repo.getId() + " and " + repo.getDescription() + " and " + repo.getmVersion());
|
||||
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
|
||||
if (prefs.contains("repo-isInstalled_" + repo.getId())) {
|
||||
mIsInstalled = prefs.getBoolean("repo-isInstalled_" + repo.getId(), false);
|
||||
if (mIsInstalled) {
|
||||
installedImage.setImageResource(R.drawable.ic_done_black);
|
||||
}
|
||||
mCanUpdate = prefs.getBoolean("repo-isInstalled_" + repo.getId(), false);
|
||||
if (mCanUpdate) {
|
||||
updateImage.setImageResource(R.drawable.ic_system_update_alt_black);
|
||||
}
|
||||
}
|
||||
|
||||
isCardExpanded = false;
|
||||
// AnimationHelper.collapse(popupLayout);
|
||||
|
||||
viewMain.setOnClickListener(new View.OnClickListener() {
|
||||
updateImage.setImageResource(R.drawable.ic_system_update_alt_black);
|
||||
mCanUpdate = prefs.getBoolean("repo-isInstalled_" + repo.getId(), false);
|
||||
updateImage.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
|
||||
public void onClick(View view) {
|
||||
if (isCardExpanded) {
|
||||
// AnimationHelper.expand(popupLayout);
|
||||
isCardExpanded = false;
|
||||
if (!mIsInstalled | mCanUpdate) {
|
||||
|
||||
Utils.DownloadReceiver reciever = new Utils.DownloadReceiver() {
|
||||
@Override
|
||||
public void task(File file) {
|
||||
Log.d("Magisk", "Task firing");
|
||||
new Utils.FlashZIP(context, repo.getId(), file.toString()).execute();
|
||||
}
|
||||
};
|
||||
String filename = repo.getId().replace(" ", "") + ".zip";
|
||||
Utils.downloadAndReceive(context, reciever, repo.getmZipUrl(), filename);
|
||||
} else {
|
||||
// AnimationHelper.collapse(popupLayout);
|
||||
isCardExpanded = true;
|
||||
|
||||
Toast.makeText(context, repo.getId() + " is already installed.", Toast.LENGTH_SHORT).show();
|
||||
}
|
||||
|
||||
// if (!mIsInstalled | mCanUpdate) {
|
||||
//
|
||||
// Utils.DownloadReceiver reciever = new Utils.DownloadReceiver() {
|
||||
// @Override
|
||||
// public void task(File file) {
|
||||
// Log.d("Magisk", "Task firing");
|
||||
// new Utils.FlashZIP(context, repo.getId(), file.toString()).execute();
|
||||
// }
|
||||
// };
|
||||
// String filename = repo.getId().replace(" ", "") + ".zip";
|
||||
// Utils.downloadAndReceive(context, reciever, repo.getmZipUrl(), filename);
|
||||
// } else {
|
||||
// Toast.makeText(context,repo.getId() + " is already installed.", Toast.LENGTH_SHORT).show();
|
||||
// }
|
||||
}
|
||||
});
|
||||
if (prefs.contains("repo-isInstalled_" + repo.getId())) {
|
||||
mIsInstalled = prefs.getBoolean("repo-isInstalled_" + repo.getId(), false);
|
||||
// if (mIsInstalled) {
|
||||
// installedImage.setImageResource(R.drawable.ic_done_black);
|
||||
// }
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
@Override
|
||||
public int getItemCount() {
|
||||
return mList.size();
|
||||
@ -157,15 +167,120 @@ public abstract class BaseRepoFragment extends Fragment {
|
||||
|
||||
class ViewHolder extends RecyclerView.ViewHolder {
|
||||
|
||||
@BindView(R.id.title) TextView title;
|
||||
@BindView(R.id.version_name) TextView versionName;
|
||||
@BindView(R.id.description) TextView description;
|
||||
@BindView(R.id.title)
|
||||
TextView title;
|
||||
@BindView(R.id.version_name)
|
||||
TextView versionName;
|
||||
@BindView(R.id.description)
|
||||
TextView description;
|
||||
@BindView(R.id.author)
|
||||
TextView author;
|
||||
@BindView(R.id.log)
|
||||
TextView log;
|
||||
@BindView(R.id.installedStatus)
|
||||
TextView installedStatus;
|
||||
@BindView(R.id.updateStatus)
|
||||
TextView updateStatus;
|
||||
@BindView(R.id.expand_layout)
|
||||
LinearLayout expandLayout;
|
||||
private ValueAnimator mAnimator;
|
||||
private int mMeasuredHeight;
|
||||
|
||||
|
||||
public ViewHolder(View itemView) {
|
||||
super(itemView);
|
||||
WindowManager windowmanager = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE);
|
||||
ButterKnife.bind(this, itemView);
|
||||
|
||||
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);
|
||||
expandLayout.measure(widthSpec, heightSpec);
|
||||
mAnimator = slideAnimator(0, expandLayout.getMeasuredHeight());
|
||||
return true;
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
viewMain.setOnClickListener(view -> {
|
||||
int position = getAdapterPosition();
|
||||
Log.d("Magisk", "BaseRepoFragment: CLICK. " + position + " and " + mExpandedList.get(position));
|
||||
|
||||
if (mExpandedList.get(position)) {
|
||||
collapse(expandLayout);
|
||||
} else {
|
||||
expand(expandLayout);
|
||||
}
|
||||
mExpandedList.set(position, !mExpandedList.get(position));
|
||||
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
private void expand(View view) {
|
||||
|
||||
// set Visible
|
||||
|
||||
|
||||
Log.d("Magisk", "BaseRepoFragment: 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", "BaseRepoFragment: 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);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onAnimationStart(Animator animator) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onAnimationCancel(Animator animator) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onAnimationRepeat(Animator animator) {
|
||||
}
|
||||
});
|
||||
mAnimator.start();
|
||||
}
|
||||
|
||||
private ValueAnimator slideAnimator(int start, int end) {
|
||||
|
||||
ValueAnimator animator = ValueAnimator.ofInt(start, end);
|
||||
|
||||
animator.addUpdateListener(valueAnimator -> {
|
||||
// Update Height
|
||||
int value = (Integer) valueAnimator.getAnimatedValue();
|
||||
|
||||
ViewGroup.LayoutParams layoutParams = expandLayout
|
||||
.getLayoutParams();
|
||||
layoutParams.height = value;
|
||||
expandLayout.setLayoutParams(layoutParams);
|
||||
});
|
||||
return animator;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -41,9 +41,7 @@ public class ModulesFragment extends Fragment {
|
||||
public static List<Module> listModulesCache = new ArrayList<>();
|
||||
public static List<Repo> listModulesDownload = new ArrayList<>();
|
||||
private static final int FILE_SELECT_CODE = 0;
|
||||
private TabsAdapter ta;
|
||||
private File input;
|
||||
private SwipeRefreshLayout mSwipeRefreshLayout;
|
||||
private int viewPagePosition;
|
||||
|
||||
@BindView(R.id.progressBar) ProgressBar progressBar;
|
||||
@BindView(R.id.fab) FloatingActionButton fabio;
|
||||
@ -56,7 +54,7 @@ public class ModulesFragment extends Fragment {
|
||||
View view = inflater.inflate(R.layout.modules_fragment, container, false);
|
||||
|
||||
ButterKnife.bind(this, view);
|
||||
//new Utils.LoadModules(getActivity(),false).execute();
|
||||
new Utils.LoadModules(getActivity(),false).execute();
|
||||
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(getActivity());
|
||||
new updateUI().execute();
|
||||
setHasOptionsMenu(true);
|
||||
@ -101,12 +99,14 @@ public class ModulesFragment extends Fragment {
|
||||
public boolean onOptionsItemSelected(MenuItem item) {
|
||||
switch (item.getItemId()) {
|
||||
case R.id.force_reload:
|
||||
viewPagePosition = tabLayout.getSelectedTabPosition();
|
||||
listModules.clear();
|
||||
listModulesCache.clear();
|
||||
listModulesDownload.clear();
|
||||
progressBar.setVisibility(View.VISIBLE);
|
||||
viewPager.setAdapter(new TabsAdapter(getChildFragmentManager()));
|
||||
tabLayout.setupWithViewPager(viewPager);
|
||||
viewPager.setCurrentItem(viewPagePosition);
|
||||
new Utils.LoadModules(getActivity(),true).execute();
|
||||
new updateUI().execute();
|
||||
break;
|
||||
@ -115,6 +115,11 @@ public class ModulesFragment extends Fragment {
|
||||
return super.onOptionsItemSelected(item);
|
||||
}
|
||||
|
||||
void selectPage(int pageIndex){
|
||||
tabLayout.setScrollPosition(pageIndex,0f,true);
|
||||
viewPager.setCurrentItem(pageIndex);
|
||||
}
|
||||
|
||||
public static class NormalModuleFragment extends BaseModuleFragment {
|
||||
|
||||
@Override
|
||||
@ -154,9 +159,10 @@ public class ModulesFragment extends Fragment {
|
||||
super.onPostExecute(v);
|
||||
|
||||
progressBar.setVisibility(View.GONE);
|
||||
|
||||
viewPager.setAdapter(new TabsAdapter(getChildFragmentManager()));
|
||||
tabLayout.setupWithViewPager(viewPager);
|
||||
selectPage(viewPagePosition);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@ -186,7 +192,7 @@ public class ModulesFragment extends Fragment {
|
||||
return new NormalModuleFragment();
|
||||
} else if (position == 1) {
|
||||
return new CacheModuleFragment();
|
||||
} else {
|
||||
} else {
|
||||
return new DownloadModuleFragment();
|
||||
}
|
||||
}
|
||||
|
@ -29,7 +29,7 @@ public class RepoHelper {
|
||||
private static final String TAG_ID = "id";
|
||||
private static final String TAG_NAME = "name";
|
||||
private static String TAG = "Magisk";
|
||||
private String mName,mId,mUrl;
|
||||
private String mName, mId, mUrl;
|
||||
private Context activityContext;
|
||||
private Date updatedDate, currentDate;
|
||||
private SharedPreferences prefs;
|
||||
@ -44,35 +44,7 @@ public class RepoHelper {
|
||||
List<String> out = null;
|
||||
} else {
|
||||
Log.d(TAG, "RepoHelper: Building from cache");
|
||||
repos.clear();
|
||||
Map<String, ?> map = prefs.getAll();
|
||||
for(Map.Entry<String,?> entry : map.entrySet()){
|
||||
if (entry.getKey().contains("repo_")) {
|
||||
Log.d("Magisk","RepoHelper: found entry for repo " + entry.getKey());
|
||||
String repoString = entry.getValue().toString().replace(""", "\"");
|
||||
String[] repoStrings = repoString.split("\n");
|
||||
for(String string : repoStrings) {
|
||||
String[] splitStrings = string.split("=");
|
||||
switch(splitStrings[0]) {
|
||||
case ("id"):
|
||||
mId = splitStrings[1];
|
||||
break;
|
||||
case ("baseUrl"):
|
||||
mUrl = splitStrings[1];
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
}
|
||||
Log.d("Magisk","RepoHelper: adding repo with id of " + mId);
|
||||
repos.add(new Repo(repoString,activityContext));
|
||||
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
BuildFromCache();
|
||||
|
||||
|
||||
}
|
||||
@ -81,6 +53,37 @@ public class RepoHelper {
|
||||
return repos;
|
||||
}
|
||||
|
||||
private void BuildFromCache() {
|
||||
repos.clear();
|
||||
Map<String, ?> map = prefs.getAll();
|
||||
for (Map.Entry<String, ?> entry : map.entrySet()) {
|
||||
if (entry.getKey().contains("repo_")) {
|
||||
Log.d("Magisk", "RepoHelper: found entry for repo " + entry.getKey());
|
||||
String repoString = entry.getValue().toString().replace(""", "\"");
|
||||
String[] repoStrings = repoString.split("\n");
|
||||
for (String string : repoStrings) {
|
||||
String[] splitStrings = string.split("=");
|
||||
switch (splitStrings[0]) {
|
||||
case ("id"):
|
||||
mId = splitStrings[1];
|
||||
break;
|
||||
case ("baseUrl"):
|
||||
mUrl = splitStrings[1];
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
}
|
||||
Log.d("Magisk", "RepoHelper: adding repo with id of " + mId);
|
||||
repos.add(new Repo(repoString, activityContext));
|
||||
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
class MyAsyncTask extends AsyncTask<String, String, Void> {
|
||||
|
||||
@ -105,9 +108,9 @@ public class RepoHelper {
|
||||
|
||||
// Making a request to url and getting response
|
||||
String token = activityContext.getString(R.string.some_string);
|
||||
String jsonStr = webreq.makeWebServiceCall(url + Utils.procFile(token,activityContext), WebRequest.GET);
|
||||
String jsonStr = webreq.makeWebServiceCall(url + Utils.procFile(token, activityContext), WebRequest.GET);
|
||||
Log.d("Magisk", "doInBackground Running, String: " + jsonStr + " Url: " + url);
|
||||
if(jsonStr != null && !jsonStr.isEmpty()) {
|
||||
if (jsonStr != null && !jsonStr.isEmpty()) {
|
||||
|
||||
try {
|
||||
repos.clear();
|
||||
@ -185,7 +188,9 @@ public class RepoHelper {
|
||||
|
||||
protected void onPostExecute(Void v) {
|
||||
if (apiFail) {
|
||||
Toast.makeText(activityContext,"GitHub API Limit reached, please try refreshing again in an hour.",Toast.LENGTH_LONG).show();
|
||||
Toast.makeText(activityContext, "GitHub API Limit reached, please try refreshing again in an hour.", Toast.LENGTH_LONG).show();
|
||||
} else {
|
||||
BuildFromCache();
|
||||
}
|
||||
|
||||
} // protected void onPostExecute(Void v)
|
||||
|
@ -4,6 +4,6 @@
|
||||
android:viewportWidth="24.0"
|
||||
android:viewportHeight="24.0">
|
||||
<path
|
||||
android:fillColor="#FF000000"
|
||||
android:fillColor="#757575"
|
||||
android:pathData="M12,16.5l4,-4h-3v-9h-2v9L8,12.5l4,4zM21,3.5h-6v1.99h6v14.03L3,19.52L3,5.49h6L9,3.5L3,3.5c-1.1,0 -2,0.9 -2,2v14c0,1.1 0.9,2 2,2h18c1.1,0 2,-0.9 2,-2v-14c0,-1.1 -0.9,-2 -2,-2z"/>
|
||||
</vector>
|
||||
|
@ -13,6 +13,10 @@
|
||||
android:minHeight="?android:attr/listPreferredItemHeight"
|
||||
card_view:cardCornerRadius="2dp"
|
||||
card_view:cardElevation="2dp">
|
||||
<LinearLayout
|
||||
android:orientation="vertical"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent">
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
@ -64,9 +68,24 @@
|
||||
android:textAppearance="?android:attr/textAppearanceSmall"
|
||||
android:textColor="@color/red500"
|
||||
android:visibility="gone"/>
|
||||
<LinearLayout
|
||||
android:id="@+id/expand_layout"
|
||||
android:minHeight="100dp"
|
||||
android:layout_width="fill_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:orientation="vertical">
|
||||
|
||||
<TextView
|
||||
android:id="@+id/author"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:textAppearance="?android:attr/textAppearanceSmall"
|
||||
android:textColor="@android:color/tertiary_text_dark"
|
||||
android:textIsSelectable="false"
|
||||
android:textStyle="bold|italic" />
|
||||
</LinearLayout>
|
||||
|
||||
</LinearLayout>
|
||||
<CheckBox
|
||||
android:id="@+id/checkbox"
|
||||
android:layout_width="wrap_content"
|
||||
@ -86,6 +105,9 @@
|
||||
android:padding="3dp"
|
||||
android:src="@drawable/ic_delete"
|
||||
tools:ignore="ContentDescription"/>
|
||||
</LinearLayout>
|
||||
|
||||
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
|
@ -60,22 +60,64 @@
|
||||
android:textAppearance="?android:attr/textAppearanceSmall"
|
||||
android:textIsSelectable="false"/>
|
||||
|
||||
<LinearLayout
|
||||
android:id="@+id/expand_layout"
|
||||
android:minHeight="100dp"
|
||||
android:layout_width="fill_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:orientation="vertical">
|
||||
|
||||
<TextView
|
||||
android:id="@+id/author"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:textAppearance="?android:attr/textAppearanceSmall"
|
||||
android:textColor="@android:color/tertiary_text_dark"
|
||||
android:textIsSelectable="false"
|
||||
android:textStyle="bold|italic" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/log"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:textAppearance="?android:attr/textAppearanceSmall"
|
||||
android:textIsSelectable="false"/>
|
||||
<TextView
|
||||
android:id="@+id/installedStatus"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:textAppearance="?android:attr/textAppearanceSmall"
|
||||
android:textIsSelectable="false"/>
|
||||
<TextView
|
||||
android:id="@+id/updateStatus"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:textAppearance="?android:attr/textAppearanceSmall"
|
||||
android:textIsSelectable="false"/>
|
||||
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
</LinearLayout>
|
||||
<ImageView
|
||||
android:id="@+id/installed"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content" />
|
||||
android:layout_height="match_parent"
|
||||
android:focusable="false"
|
||||
android:gravity="center"
|
||||
android:padding="5dp"
|
||||
/>
|
||||
|
||||
<ImageView
|
||||
android:id="@+id/update"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content" />
|
||||
android:layout_height="match_parent"
|
||||
android:focusable="false"
|
||||
android:gravity="center"
|
||||
android:padding="5dp" />
|
||||
|
||||
</LinearLayout>
|
||||
<!-- <include layout="@layout/list_item_repo_expanded" />-->
|
||||
|
||||
</LinearLayout>
|
||||
</android.support.v7.widget.CardView>
|
||||
|
||||
|
@ -1,54 +1,67 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<android.support.design.widget.CoordinatorLayout
|
||||
android:id="@+id/main_content"
|
||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
<android.support.design.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||
android:id="@+id/main_content"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent">
|
||||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||
android:id="@+id/llayout"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:layout_marginTop="?attr/actionBarSize"
|
||||
android:orientation="vertical">
|
||||
|
||||
<android.support.design.widget.TabLayout
|
||||
android:id="@+id/tab_layout"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:background="?attr/colorPrimary"
|
||||
android:elevation="4dp"
|
||||
android:minHeight="?attr/actionBarSize"
|
||||
app:tabGravity="fill"
|
||||
app:tabIndicatorColor="?attr/colorAccent"
|
||||
app:tabMode="fixed"
|
||||
app:tabTextAppearance="@style/TextAppearance.Design.Tab"/>
|
||||
<RelativeLayout
|
||||
android:layout_width="fill_parent"
|
||||
android:layout_height="wrap_content">
|
||||
|
||||
<ProgressBar
|
||||
android:id="@+id/progressBar"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_gravity="center"/>
|
||||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||
android:id="@+id/llayout"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="fill_parent"
|
||||
android:layout_marginTop="?attr/actionBarSize"
|
||||
android:orientation="vertical">
|
||||
|
||||
<android.support.v4.view.ViewPager
|
||||
android:id="@+id/pager"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent" />
|
||||
<android.support.design.widget.TabLayout
|
||||
android:id="@+id/tab_layout"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:background="?attr/colorPrimary"
|
||||
android:elevation="4dp"
|
||||
android:minHeight="?attr/actionBarSize"
|
||||
app:tabGravity="fill"
|
||||
app:tabIndicatorColor="?attr/colorAccent"
|
||||
app:tabMode="fixed"
|
||||
app:tabTextAppearance="@style/TextAppearance.Design.Tab" />
|
||||
|
||||
<ProgressBar
|
||||
android:id="@+id/progressBar"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_gravity="center" />
|
||||
|
||||
<android.support.v4.view.ViewPager
|
||||
android:id="@+id/pager"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:animateLayoutChanges="true" />
|
||||
|
||||
|
||||
|
||||
|
||||
</LinearLayout>
|
||||
<android.support.design.widget.FloatingActionButton
|
||||
android:id="@+id/fab"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_gravity="right"
|
||||
android:layout_margin="16dp"
|
||||
android:clickable="true"
|
||||
app:layout_anchor="@id/llayout"
|
||||
android:src="@drawable/ic_add"
|
||||
app:layout_anchorGravity="bottom|right|end"
|
||||
/>
|
||||
</LinearLayout>
|
||||
<LinearLayout
|
||||
android:id="@+id/ly_bar_bottom"
|
||||
android:layout_width="fill_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_alignParentBottom="true"
|
||||
android:gravity="center"
|
||||
android:orientation="horizontal">
|
||||
<android.support.design.widget.FloatingActionButton
|
||||
android:id="@+id/fab"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_margin="16dp"
|
||||
android:baselineAlignBottom="false"
|
||||
android:clickable="true"
|
||||
android:src="@drawable/ic_add"
|
||||
app:layout_anchorGravity="bottom|right|end"
|
||||
/>
|
||||
</LinearLayout>
|
||||
</RelativeLayout>
|
||||
</android.support.design.widget.CoordinatorLayout>
|
@ -2,4 +2,5 @@
|
||||
<resources>
|
||||
<dimen name="floating_height">650dp</dimen>
|
||||
<dimen name="floating_width">500dp</dimen>
|
||||
<dimen name="min_rowheight">100dp</dimen>
|
||||
</resources>
|
@ -42,13 +42,15 @@
|
||||
<!--Module Fragment-->
|
||||
<string name="cache_modules">Cache modules</string>
|
||||
<string name="no_modules_found">No modules found</string>
|
||||
<string name="module_update_available">Update available</string>
|
||||
<string name="mudule_up_to_date">Module is up-to-date</string>
|
||||
<string name="module_update_available">An update is available</string>
|
||||
<string name="module_up_to_date">Module is up-to-date</string>
|
||||
<string name="module_installed">Module is installed</string>
|
||||
<string name="module_not_installed">Module is not installed</string>
|
||||
<string name="remove_file_created">Module will be removed at next reboot</string>
|
||||
<string name="remove_file_deleted">Module will not be removed at next reboot</string>
|
||||
<string name="disable_file_created">Module will be disabled at next reboot</string>
|
||||
<string name="disable_file_removed">Module will be enabled at next reboot</string>
|
||||
<string name="author">Created by </string>
|
||||
|
||||
<!--Log Fragment-->
|
||||
<string name="menuSaveToSd">Save to SD</string>
|
||||
|
Loading…
Reference in New Issue
Block a user