I'm going to commit this now...

Still got work to do, but I don't want to lose this...
This commit is contained in:
d8ahazard 2016-09-11 13:36:58 -05:00
parent 041531e96d
commit 98aa9bd3fe
12 changed files with 506 additions and 358 deletions

View File

@ -206,7 +206,7 @@ public abstract class BaseModuleFragment extends Fragment {
viewMain.setOnClickListener(view -> {
int position = getAdapterPosition();
Log.d("Magisk", "BaseRepoFragment: CLICK. " + position + " and " + mExpandedList.get(position));
Log.d("Magisk", "ReposFragment: CLICK. " + position + " and " + mExpandedList.get(position));
if (mExpandedList.get(position)) {
collapse(expandLayout);
@ -226,7 +226,7 @@ public abstract class BaseModuleFragment extends Fragment {
// set Visible
Log.d("Magisk", "BaseRepoFragment: Expand anim called " + mMeasuredHeight + " and " + view.getId());
Log.d("Magisk", "ReposFragment: Expand anim called " + mMeasuredHeight + " and " + view.getId());
view.setVisibility(View.VISIBLE);
mAnimator.start();
}
@ -234,7 +234,7 @@ public abstract class BaseModuleFragment extends Fragment {
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());
Log.d("Magisk", "ReposFragment: Collapse anim called " + finalHeight + " and " + view.getId());
mAnimator.addListener(new Animator.AnimatorListener() {
@Override

View File

@ -1,297 +0,0 @@
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.Utils;
import com.topjohnwu.magisk.utils.WebWindow;
import java.io.File;
import java.util.ArrayList;
import java.util.List;
import butterknife.BindView;
import butterknife.ButterKnife;
public abstract class BaseRepoFragment extends Fragment {
@BindView(R.id.recyclerView)
RecyclerView recyclerView;
@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) {
emptyTv.setVisibility(View.VISIBLE);
recyclerView.setVisibility(View.GONE);
return view;
}
Log.d("Magisk", "BaseRepoFragment: ListRepos size is " + listRepos().size());
recyclerView.setAdapter(new ReposAdapter(listRepos()) {
});
return view;
}
protected abstract List<Repo> listRepos();
public class ReposAdapter extends RecyclerView.Adapter<ReposAdapter.ViewHolder> {
private final List<Repo> mList;
List<Boolean> mExpandedList;
@BindView(R.id.update)
ImageView updateImage;
@BindView(R.id.installed)
ImageView installedImage;
@BindView(R.id.expand_layout)
LinearLayout expandedLayout;
private View viewMain;
private Context context;
private boolean mIsInstalled, mCanUpdate;
private Repo repo;
private ViewHolder mHolder;
private int mPosition;
public ReposAdapter(List<Repo> list) {
this.mList = list;
mExpandedList = new ArrayList<>(mList.size());
for (int i = 0; i < mList.size(); i++) {
mExpandedList.add(false);
}
}
@Override
public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
viewMain = LayoutInflater.from(parent.getContext()).inflate(R.layout.list_item_repo, parent, false);
ButterKnife.bind(this, viewMain);
context = parent.getContext();
return new ViewHolder(viewMain);
}
@Override
public void onBindViewHolder(final ViewHolder holder, int position) {
repo = mList.get(position);
mHolder = holder;
SetupViewElements();
}
private void SetupViewElements() {
mPosition = mHolder.getAdapterPosition();
if (repo.getId() != null) {
TextView authorView = mHolder.author;
mHolder.title.setText(repo.getName());
mHolder.versionName.setText(repo.getmVersion());
mHolder.description.setText(repo.getDescription());
String authorString = getResources().getString(R.string.author) + " " + repo.getmAuthor();
mHolder.author.setText(authorString);
if ((repo.getmLogUrl() != null) && (repo.getmLogUrl().equals(""))) {
mHolder.log.setText(repo.getmLogUrl());
Linkify.addLinks(mHolder.log, Linkify.WEB_URLS);
} else {
mHolder.log.setVisibility(View.GONE);
}
mHolder.installedStatus.setText(repo.isInstalled() ? getResources().getString(R.string.module_installed) : getResources().getString(R.string.module_not_installed));
if (mExpandedList.get(mPosition)) {
mHolder.expandLayout.setVisibility(View.VISIBLE);
} else {
mHolder.expandLayout.setVisibility(View.GONE);
}
if (repo.isInstalled()) {
mHolder.installedStatus.setTextColor(Color.parseColor("#14AD00"));
mHolder.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);
updateImage.setImageResource(R.drawable.ic_system_update_alt_black);
mCanUpdate = prefs.getBoolean("repo-isInstalled_" + repo.getId(), false);
View.OnClickListener oCl = view -> {
if (view == updateImage) {
if (!mIsInstalled | mCanUpdate) {
Utils.DownloadReceiver receiver = 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, receiver, repo.getmZipUrl(), filename);
} else {
Toast.makeText(context, repo.getId() + " is already installed.", Toast.LENGTH_SHORT).show();
}
} else if (view == mHolder.log) {
new WebWindow("Changelog",repo.getmLogUrl(),getActivity());
}
};
updateImage.setOnClickListener(oCl);
mHolder.log.setOnClickListener(oCl);
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();
}
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.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;
}
}
}
}

View File

@ -41,7 +41,6 @@ public class ModulesFragment extends Fragment {
public static List<Module> listModules = new ArrayList<>();
public static List<Module> listModulesCache = new ArrayList<>();
public static List<Repo> listModulesDownload = new ArrayList<>();
private static final int FILE_SELECT_CODE = 0;
private int viewPagePosition;
private static final int RESULT_OK = 1;
@ -119,7 +118,6 @@ public class ModulesFragment extends Fragment {
viewPagePosition = tabLayout.getSelectedTabPosition();
listModules.clear();
listModulesCache.clear();
listModulesDownload.clear();
progressBar.setVisibility(View.VISIBLE);
viewPager.setAdapter(new TabsAdapter(getChildFragmentManager()));
tabLayout.setupWithViewPager(viewPager);
@ -155,14 +153,6 @@ public class ModulesFragment extends Fragment {
}
public static class DownloadModuleFragment extends BaseRepoFragment {
@Override
protected List<Repo> listRepos() {
return listModulesDownload;
}
}
private class updateUI extends AsyncTask<Void, Void, Void> {
@ -186,7 +176,7 @@ public class ModulesFragment extends Fragment {
private class TabsAdapter extends FragmentPagerAdapter {
String[] tabTitles = new String[]{
getString(R.string.modules), getString(R.string.cache_modules), "Download"
getString(R.string.modules), getString(R.string.cache_modules)
};
public TabsAdapter(FragmentManager fm) {
@ -207,10 +197,8 @@ public class ModulesFragment extends Fragment {
public Fragment getItem(int position) {
if (position == 0) {
return new NormalModuleFragment();
} else if (position == 1) {
return new CacheModuleFragment();
} else {
return new DownloadModuleFragment();
return new CacheModuleFragment();
}
}
}

View File

@ -0,0 +1,263 @@
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.preference.PreferenceManager;
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.Utils;
import com.topjohnwu.magisk.utils.WebWindow;
import java.io.File;
import java.util.ArrayList;
import java.util.List;
import butterknife.BindView;
import butterknife.ButterKnife;
public class ReposAdapter extends RecyclerView.Adapter<ReposAdapter.ViewHolder> {
private ReposFragment reposFragment;
private final List<Repo> mList;
List<Boolean> mExpandedList;
@BindView(R.id.update)
ImageView updateImage;
@BindView(R.id.installed)
ImageView installedImage;
@BindView(R.id.expand_layout)
LinearLayout expandedLayout;
private View viewMain;
private Context context;
private boolean mIsInstalled, mCanUpdate;
private Repo repo;
private ViewHolder mHolder;
public ReposAdapter(ReposFragment reposFragment, List<Repo> list) {
this.reposFragment = reposFragment;
this.mList = list;
Log.d("Magisk", "ReposAdapter: I am alive. I have a list " + list.size());
mExpandedList = new ArrayList<>(mList.size());
for (int i = 0; i < mList.size(); i++) {
mExpandedList.add(false);
}
}
@Override
public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
viewMain = LayoutInflater.from(parent.getContext()).inflate(R.layout.list_item_repo, parent, false);
ButterKnife.bind(this, viewMain);
context = parent.getContext();
return new ViewHolder(viewMain);
}
// @Override
// public boolean onOptionsItemSelected(MenuItem item) {
// switch (item.getItemId()) {
// case R.id.force_reload:
// listModulesDownload.clear();
// new Utils.LoadModules(getActivity(), true).execute();
// break;
// }
//
// return super.onOptionsItemSelected(item);
// }
@Override
public void onBindViewHolder(final ViewHolder holder, int position) {
repo = mList.get(position);
mHolder = holder;
mExpandedList = new ArrayList<>(mList.size());
for (int i = 0; i < mList.size(); i++) {
mExpandedList.add(false);
}
SetupViewElements();
}
private void SetupViewElements() {
int mPosition = mHolder.getAdapterPosition();
if (repo.getId() != null) {
mHolder.title.setText(repo.getName());
mHolder.versionName.setText(repo.getmVersion());
mHolder.description.setText(repo.getDescription());
String authorString = this.context.getResources().getString(R.string.author) + " " + repo.getmAuthor();
mHolder.author.setText(authorString);
if ((repo.getmLogUrl() != null) && (repo.getmLogUrl().equals(""))) {
mHolder.log.setText(repo.getmLogUrl());
Linkify.addLinks(mHolder.log, Linkify.WEB_URLS);
} else {
mHolder.log.setVisibility(View.GONE);
}
mHolder.installedStatus.setText(repo.isInstalled() ? this.context.getResources().getString(R.string.module_installed) : this.context.getResources().getString(R.string.module_not_installed));
if (mExpandedList.get(mPosition)) {
mHolder.expandLayout.setVisibility(View.VISIBLE);
} else {
mHolder.expandLayout.setVisibility(View.GONE);
}
if (repo.isInstalled()) {
mHolder.installedStatus.setTextColor(Color.parseColor("#14AD00"));
mHolder.updateStatus.setText(repo.canUpdate() ? this.context.getResources().getString(R.string.module_update_available) : this.context.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);
updateImage.setImageResource(R.drawable.ic_system_update_alt_black);
mCanUpdate = prefs.getBoolean("repo-isInstalled_" + repo.getId(), false);
View.OnClickListener oCl = view -> {
if (view == updateImage) {
if (!mIsInstalled | mCanUpdate) {
Utils.DownloadReceiver receiver = 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, receiver, repo.getmZipUrl(), filename);
} else {
Toast.makeText(context, repo.getId() + " is already installed.", Toast.LENGTH_SHORT).show();
}
} else if (view == mHolder.log) {
new WebWindow("Changelog", repo.getmLogUrl(), this.context);
}
};
updateImage.setOnClickListener(oCl);
mHolder.log.setOnClickListener(oCl);
if (prefs.contains("repo-isInstalled_" + repo.getId())) {
mIsInstalled = prefs.getBoolean("repo-isInstalled_" + repo.getId(), false);
}
}
}
// protected List<Repo> mListRepos() {
// return ReposFragment.listModulesDownload;
// }
@Override
public int getItemCount() {
return mList.size();
}
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.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;
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);
expandLayout.getViewTreeObserver().addOnPreDrawListener(
new ViewTreeObserver.OnPreDrawListener() {
@Override
public boolean onPreDraw() {
final int widthSpec = View.MeasureSpec.makeMeasureSpec(0, View.MeasureSpec.UNSPECIFIED);
final int heightSpec = View.MeasureSpec.makeMeasureSpec(0, View.MeasureSpec.UNSPECIFIED);
expandLayout.getViewTreeObserver().removeOnPreDrawListener(this);
expandLayout.setVisibility(View.GONE);
expandLayout.measure(widthSpec, heightSpec);
mAnimator = slideAnimator(0, expandLayout.getMeasuredHeight());
return true;
}
});
viewMain.setOnClickListener(view -> {
int position = getAdapterPosition();
if (mExpandedList.get(position)) {
collapse(expandLayout);
} else {
expand(expandLayout);
}
mExpandedList.set(position, !mExpandedList.get(position));
});
}
private void expand(View view) {
view.setVisibility(View.VISIBLE);
mAnimator.start();
}
private void collapse(View view) {
int finalHeight = view.getHeight();
ValueAnimator mAnimator = slideAnimator(finalHeight, 0);
mAnimator.addListener(new Animator.AnimatorListener() {
@Override
public void onAnimationEnd(Animator animator) {
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 -> {
int value = (Integer) valueAnimator.getAnimatedValue();
ViewGroup.LayoutParams layoutParams = expandLayout
.getLayoutParams();
layoutParams.height = value;
expandLayout.setLayoutParams(layoutParams);
});
return animator;
}
}
}

View File

@ -0,0 +1,118 @@
package com.topjohnwu.magisk;
import android.content.Context;
import android.os.AsyncTask;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.support.v4.widget.SwipeRefreshLayout;
import android.support.v7.widget.RecyclerView;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;
import com.topjohnwu.magisk.module.Repo;
import com.topjohnwu.magisk.module.RepoHelper;
import java.util.ArrayList;
import java.util.List;
import butterknife.BindView;
import butterknife.ButterKnife;
public class ReposFragment extends Fragment {
public static List<Repo> mListRepos = new ArrayList<>();
@BindView(R.id.recyclerView)
RecyclerView recyclerView;
@BindView(R.id.empty_rv)
TextView emptyTv;
@BindView(R.id.swipeRefreshLayout)
SwipeRefreshLayout swipeRefreshLayout;
private RepoHelper.TaskDelegate taskDelegate;
@Nullable
@Override
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.single_repo_fragment, container, false);
ButterKnife.bind(this, view);
swipeRefreshLayout.setOnRefreshListener(() -> {
Log.d("Magisk","ReposFragment: WTF IM CALLED");
this.LoadRepo(true);
});
LoadRepo(false);
setHasOptionsMenu(false);
if (mListRepos.size() == 0) {
emptyTv.setVisibility(View.VISIBLE);
recyclerView.setVisibility(View.GONE);
return view;
}
Log.d("Magisk", "ReposFragment: ListRepos size is " + listRepos().size());
recyclerView.setAdapter(new ReposAdapter(this, mListRepos));
return view;
}
private void LoadRepo (boolean doReload) {
taskDelegate = result -> {
if (result.equals("Complete")) {
Log.d("Magisk", "ReposFragment, got delegate");
UpdateUI();
}
};
Log.d("Magisk","ReposFragment, LoadRepo called");
mListRepos.clear();
RepoHelper mr = new RepoHelper();
List<Repo> magiskRepos = mr.listRepos(getActivity(), doReload,taskDelegate);
for (Repo repo : magiskRepos) {
Log.d("Magisk", "ReposFragment: Adding repo from string " + repo.getId());
mListRepos.add(repo);
}
}
@Override
public void onResume() {
super.onResume();
LoadRepo(false);
}
protected List<Repo> listRepos() {
return mListRepos;
}
private void UpdateUI() {
Log.d("Magisk","ReposFragment: UpdateUI Called, size is " + listRepos().size());
if (listRepos().size() == 0) {
emptyTv.setVisibility(View.VISIBLE);
recyclerView.setVisibility(View.GONE);
}
Log.d("Magisk", "ReposFragment: ListRepos size is " + listRepos().size());
recyclerView.setAdapter(new ReposAdapter(this, listRepos()));
if (swipeRefreshLayout.isRefreshing()) {
swipeRefreshLayout.setRefreshing(false);
}
}
}

View File

@ -23,6 +23,7 @@ import android.support.v7.widget.Toolbar;
import android.view.MenuItem;
import android.view.View;
import com.topjohnwu.magisk.module.RepoHelper;
import com.topjohnwu.magisk.utils.Utils;
import butterknife.BindView;
@ -60,13 +61,20 @@ public class WelcomeActivity extends AppCompatActivity implements NavigationView
new Utils.Initialize(this).execute();
new Utils.CheckUpdates(this).execute();
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this);
RepoHelper.TaskDelegate delegate = result -> {
//Do a thing here when we get a result we want
};
if (!prefs.contains("oauth_key")) {
}
if (!prefs.contains("hasCachedRepos")) {
new Utils.LoadModules(this, true).execute();
new Utils.LoadRepos(this, true,delegate).execute();
} else {
new Utils.LoadModules(getApplication(),false).execute();
new Utils.LoadRepos(this, false,delegate).execute();
}
setSupportActionBar(toolbar);
@ -146,6 +154,11 @@ public class WelcomeActivity extends AppCompatActivity implements NavigationView
tag = "modules";
navFragment = new ModulesFragment();
break;
case R.id.downloads:
setTitle(R.string.downloads);
tag = "downloads";
navFragment = new ReposFragment();
break;
case R.id.log:
setTitle(R.string.log);
tag = "log";

View File

@ -66,7 +66,6 @@ public class Repo {
WebRequest webreq = new WebRequest();
// Construct initial url for contents
Log.d("Magisk", "Repo: Fetch called, Manifest string is: " + mBaseUrl + "/contents?access_token=" + Utils.procFile(appContext.getString(R.string.some_string),appContext));
String repoString = webreq.makeWebServiceCall(mBaseUrl + "/contents?access_token=" + Utils.procFile(appContext.getString(R.string.some_string),appContext), WebRequest.GET);
try {
JSONArray repoArray = new JSONArray(repoString);
@ -85,10 +84,8 @@ public class Repo {
e.printStackTrace();
}
Log.d("Magisk", "Repo: Inner fetch: " + mManifestUrl + "?access_token=" + Utils.procFile(appContext.getString(R.string.some_string),appContext));
WebRequest propReq = new WebRequest();
String manifestString = propReq.makeWebServiceCall(mManifestUrl,WebRequest.GET,true);
Log.d("Magisk","Repo: parseprops called from fetch for string " + manifestString);
if (ParseProps(manifestString)) {
PutProps(manifestString);
@ -103,7 +100,6 @@ public class Repo {
editor.putString("repo_" + mId, manifestString);
editor.putBoolean("hasCachedRepos", true);
editor.putString("updated_" + mId, this.lastUpdate);
Log.d("Magisk", "Storing Preferences: " + manifestString);
editor.apply();
}
private boolean ParseProps(String string) {

View File

@ -18,6 +18,7 @@ import org.json.JSONObject;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Date;
import java.util.List;
import java.util.Map;
@ -35,21 +36,21 @@ public class RepoHelper {
private SharedPreferences prefs;
private boolean apiFail;
public List<Repo> listRepos(Context context, boolean refresh) {
public List<Repo> listRepos(Context context, boolean refresh, TaskDelegate delegate) {
prefs = PreferenceManager.getDefaultSharedPreferences(context);
activityContext = context;
TaskDelegate mDelegate = delegate;
if (!prefs.contains("hasCachedRepos") | refresh) {
Log.d(TAG, "RepoHelper: Building from web");
new MyAsyncTask().execute();
new MyAsyncTask(delegate).execute();
List<String> out = null;
} else {
Log.d(TAG, "RepoHelper: Building from cache");
BuildFromCache();
}
return repos;
}
@ -58,7 +59,6 @@ public class RepoHelper {
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("&quot;", "\"");
String[] repoStrings = repoString.split("\n");
for (String string : repoStrings) {
@ -73,26 +73,27 @@ public class RepoHelper {
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> {
private TaskDelegate delegate;
public MyAsyncTask(TaskDelegate delegate) {
this.delegate = delegate;
}
@Override
protected void onPreExecute() {
super.onPreExecute();
}
@Override
protected void onProgressUpdate(String... values) {
super.onProgressUpdate(values);
@ -109,7 +110,6 @@ 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);
Log.d("Magisk", "doInBackground Running, String: " + jsonStr + " Url: " + url);
if (jsonStr != null && !jsonStr.isEmpty()) {
try {
@ -136,7 +136,6 @@ public class RepoHelper {
String[] valueSub = valueString.split("=");
if (valueSub[0].equals("id")) {
mId = valueSub[1];
Log.d("Magisk", "RepoHelper: Got id for package of " + mId);
if (prefs.contains("updated_" + mId)) {
cacheUpdate = prefs.getString("updated_" + mId, "");
hasCachedDate = true;
@ -190,15 +189,22 @@ public class RepoHelper {
if (apiFail) {
Toast.makeText(activityContext, "GitHub API Limit reached, please try refreshing again in an hour.", Toast.LENGTH_LONG).show();
} else {
Log.d("Magisk","RepoHelper: postExecute fired");
delegate.taskCompletionResult("Complete");
BuildFromCache();
}
} // protected void onPostExecute(Void v)
} //class MyAsyncTask extends AsyncTask<String, String, Void>
}
}
protected void onPreExecute() {
}
public interface TaskDelegate {
public void taskCompletionResult(String result);
}
}

View File

@ -23,9 +23,10 @@ import android.widget.Toast;
import com.topjohnwu.magisk.ModulesFragment;
import com.topjohnwu.magisk.R;
import com.topjohnwu.magisk.ReposFragment;
import com.topjohnwu.magisk.module.Module;
import com.topjohnwu.magisk.module.RepoHelper;
import com.topjohnwu.magisk.module.Repo;
import com.topjohnwu.magisk.module.RepoHelper;
import org.json.JSONException;
import org.json.JSONObject;
@ -54,18 +55,17 @@ public class Utils {
public static int magiskVersion, remoteMagiskVersion = -1, remoteAppVersion = -1;
public static String magiskLink, magiskChangelog, appChangelog, appLink, phhLink, supersuLink;
private Context appContext;
private static final String TAG = "Magisk";
public static final String MAGISK_PATH = "/magisk";
public static final String MAGISK_CACHE_PATH = "/cache/magisk";
public static final String UPDATE_JSON = "https://raw.githubusercontent.com/topjohnwu/MagiskManager/updates/magisk_update.json";
public static boolean fileExist(String path) {
List<String> ret;
ret = Shell.sh("if [ -f " + path + " ]; then echo true; else echo false; fi");
if (!Boolean.parseBoolean(ret.get(0)) && Shell.rootAccess()) ret = Shell.su("if [ -f " + path + " ]; then echo true; else echo false; fi");
if (!Boolean.parseBoolean(ret.get(0)) && Shell.rootAccess())
ret = Shell.su("if [ -f " + path + " ]; then echo true; else echo false; fi");
return Boolean.parseBoolean(ret.get(0));
}
@ -102,7 +102,7 @@ public class Utils {
}
public Utils(Context context) {
appContext = context;
Context appContext = context;
}
public static void downloadAndReceive(Context context, DownloadReceiver receiver, String link, String file) {
@ -128,15 +128,19 @@ public class Utils {
long downloadID;
public String mName;
public DownloadReceiver() {}
public DownloadReceiver(String name) { mName = name; }
public DownloadReceiver() {
}
public DownloadReceiver(String name) {
mName = name;
}
@Override
public void onReceive(Context context, Intent intent) {
mContext = context;
DownloadManager downloadManager = (DownloadManager) context.getSystemService(Context.DOWNLOAD_SERVICE);
String action = intent.getAction();
if(DownloadManager.ACTION_DOWNLOAD_COMPLETE.equals(action)){
if (DownloadManager.ACTION_DOWNLOAD_COMPLETE.equals(action)) {
DownloadManager.Query query = new DownloadManager.Query();
query.setFilterById(downloadID);
Cursor c = downloadManager.query(query);
@ -157,11 +161,14 @@ public class Utils {
}
}
public void setDownloadID(long id) { downloadID = id;}
public void setDownloadID(long id) {
downloadID = id;
}
public abstract void task(File file);
}
public static class Initialize extends AsyncTask <Void, Void, Void> {
public static class Initialize extends AsyncTask<Void, Void, Void> {
private Context mContext;
@ -199,7 +206,7 @@ public class Utils {
protected void onPostExecute(Void aVoid) {
super.onPostExecute(aVoid);
if (!Shell.rootAccess()) {
Snackbar.make(((Activity)mContext).findViewById(android.R.id.content), R.string.no_root_access, Snackbar.LENGTH_LONG).show();
Snackbar.make(((Activity) mContext).findViewById(android.R.id.content), R.string.no_root_access, Snackbar.LENGTH_LONG).show();
}
}
@ -318,8 +325,7 @@ public class Utils {
new AlertDialog.Builder(mContext)
.setTitle(R.string.root_method_title)
.setItems(new String[]{mContext.getString(R.string.phh), mContext.getString(R.string.supersu)}, (dialogInterface1, root) -> {
switch(root)
{
switch (root) {
case 0:
downloadAndReceive(
mContext,
@ -430,24 +436,45 @@ public class Utils {
protected Void doInBackground(Void... voids) {
ModulesFragment.listModules.clear();
ModulesFragment.listModulesCache.clear();
ModulesFragment.listModulesDownload.clear();
List<String> magisk = getModList(MAGISK_PATH);
Log.d("Magisk", "Utils: Reload called, loading modules from" + (doReload ? " the internet " : " cache"));
List<String> magiskCache = getModList(MAGISK_CACHE_PATH);
RepoHelper mr = new RepoHelper();
List<Repo> magiskRepos = mr.listRepos(mContext, doReload);
for (String mod : magisk) {
Log.d("Magisk","Utils: Adding module from string " + mod);
ModulesFragment.listModules.add(new Module(mod,mContext));
Log.d("Magisk", "Utils: Adding module from string " + mod);
ModulesFragment.listModules.add(new Module(mod, mContext));
}
for (String mod : magiskCache) {
Log.d("Magisk","Utils: Adding cache module from string " + mod);
ModulesFragment.listModulesCache.add(new Module(mod,mContext));
Log.d("Magisk", "Utils: Adding cache module from string " + mod);
ModulesFragment.listModulesCache.add(new Module(mod, mContext));
}
return null;
}
}
public static class LoadRepos extends AsyncTask<Void, Void, Void> {
private Context mContext;
private boolean doReload;
private RepoHelper.TaskDelegate mTaskDelegate;
public LoadRepos(Context context, boolean reload, RepoHelper.TaskDelegate delegate) {
mContext = context;
doReload = reload;
mTaskDelegate = delegate;
}
@Override
protected Void doInBackground(Void... voids) {
ReposFragment.mListRepos.clear();
RepoHelper mr = new RepoHelper();
List<Repo> magiskRepos = mr.listRepos(mContext, doReload, mTaskDelegate);
for (Repo repo : magiskRepos) {
Log.d("Magisk","Utils: Adding repo from string " + repo.getId());
ModulesFragment.listModulesDownload.add(repo);
Log.d("Magisk", "Utils: Adding repo from string " + repo.getId());
ReposFragment.mListRepos.add(repo);
}
return null;
@ -486,7 +513,7 @@ public class Utils {
"BOOTMODE=true sh /data/tmp/META-INF/com/google/android/update-binary dummy 1 /data/tmp/install.zip",
"if [ $? -eq 0 ]; then echo true; else echo false; fi"
);
return Boolean.parseBoolean(ret.get(ret.size() -1));
return Boolean.parseBoolean(ret.get(ret.size() - 1));
}
}

View File

@ -0,0 +1,28 @@
<?xml version="1.0" encoding="utf-8"?>
<android.support.v4.widget.SwipeRefreshLayout android:id="@+id/swipeRefreshLayout"
android:layout_width="match_parent"
android:layout_height="fill_parent"
android:orientation="vertical"
android:layout_marginTop="?attr/actionBarSize"
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto">
<android.support.v7.widget.RecyclerView
android:id="@+id/recyclerView"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layoutManager="android.support.v7.widget.LinearLayoutManager"/>
<TextView
android:id="@+id/empty_rv"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="center"
android:fontFamily="sans-serif-light"
android:gravity="center"
android:text="@string/no_modules_found"
android:textSize="20sp"
android:textStyle="italic"
android:visibility="gone"/>
</android.support.v4.widget.SwipeRefreshLayout>

View File

@ -20,6 +20,11 @@
android:icon="@drawable/ic_extension"
android:title="@string/modules"/>
<item
android:id="@+id/downloads"
android:icon="@drawable/ic_extension"
android:title="@string/downloads"/>
<item
android:id="@+id/log"
android:icon="@drawable/ic_bug_report"

View File

@ -96,4 +96,5 @@
<string name="root_system_msg">It seems that you have incompatible root installed\nDo you want to install Magisk compatible root now?</string>
<string name="pass">MagiskRox666</string>
<string name="some_string">GTYybRBTYf5his9kQ16ZNO7qgkBJ/5MyVe4CGceAOIoXgSnnk8FTd4F1dE9p5Eus</string>
<string name="downloads">Downloads</string>
</resources>