Commit 98aa9bd3 authored by d8ahazard's avatar d8ahazard

I'm going to commit this now...

Still got work to do, but I don't want to lose this...
parent 041531e9
......@@ -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
......
......@@ -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();
}
}
}
......
This diff is collapsed.
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);
}
}
}
......@@ -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";
......
......@@ -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) {
......
......@@ -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);
}
}
......@@ -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));
}
}
......
<?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>
\ No newline at end of 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"
......
......@@ -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>
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment