My brain hurts...
This commit is contained in:
parent
8dfe0f4373
commit
aa991b62f4
@ -1,10 +1,14 @@
|
|||||||
package com.topjohnwu.magisk;
|
package com.topjohnwu.magisk;
|
||||||
|
|
||||||
|
import android.content.SharedPreferences;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
|
import android.preference.PreferenceManager;
|
||||||
import android.support.annotation.Nullable;
|
import android.support.annotation.Nullable;
|
||||||
import android.support.design.widget.Snackbar;
|
import android.support.design.widget.Snackbar;
|
||||||
import android.support.v4.app.Fragment;
|
import android.support.v4.app.Fragment;
|
||||||
|
import android.support.v4.widget.SwipeRefreshLayout;
|
||||||
import android.support.v7.widget.RecyclerView;
|
import android.support.v7.widget.RecyclerView;
|
||||||
|
import android.util.Log;
|
||||||
import android.view.LayoutInflater;
|
import android.view.LayoutInflater;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
import android.view.ViewGroup;
|
import android.view.ViewGroup;
|
||||||
@ -15,6 +19,7 @@ import com.topjohnwu.magisk.module.Module;
|
|||||||
import com.topjohnwu.magisk.utils.Utils;
|
import com.topjohnwu.magisk.utils.Utils;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.concurrent.ExecutionException;
|
||||||
|
|
||||||
import butterknife.BindView;
|
import butterknife.BindView;
|
||||||
import butterknife.ButterKnife;
|
import butterknife.ButterKnife;
|
||||||
@ -23,13 +28,30 @@ public abstract class BaseModuleFragment extends Fragment {
|
|||||||
|
|
||||||
@BindView(R.id.recyclerView) RecyclerView recyclerView;
|
@BindView(R.id.recyclerView) RecyclerView recyclerView;
|
||||||
@BindView(R.id.empty_rv) TextView emptyTv;
|
@BindView(R.id.empty_rv) TextView emptyTv;
|
||||||
|
private SwipeRefreshLayout mSwipeRefreshLayout;
|
||||||
|
private View view;
|
||||||
|
private SharedPreferences prefs;
|
||||||
@Nullable
|
@Nullable
|
||||||
@Override
|
@Override
|
||||||
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
|
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
|
||||||
View view = inflater.inflate(R.layout.single_module_fragment, container, false);
|
view = inflater.inflate(R.layout.single_module_fragment, container, false);
|
||||||
ButterKnife.bind(this, view);
|
mSwipeRefreshLayout = (SwipeRefreshLayout) view.findViewById(R.id.swipeRefreshLayout);
|
||||||
|
mSwipeRefreshLayout.setOnRefreshListener(() -> {
|
||||||
|
refreshItems();
|
||||||
|
});
|
||||||
|
|
||||||
|
ButterKnife.bind(this, view);
|
||||||
|
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();
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
if (listModules().size() == 0) {
|
if (listModules().size() == 0) {
|
||||||
emptyTv.setVisibility(View.VISIBLE);
|
emptyTv.setVisibility(View.VISIBLE);
|
||||||
recyclerView.setVisibility(View.GONE);
|
recyclerView.setVisibility(View.GONE);
|
||||||
@ -62,5 +84,22 @@ public abstract class BaseModuleFragment extends Fragment {
|
|||||||
return view;
|
return view;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void refreshItems() {
|
||||||
|
Log.d("Magisk", "Calling refreshitems for online");
|
||||||
|
Utils.LoadModules utils = new Utils.LoadModules(getActivity(),true);
|
||||||
|
utils.execute();
|
||||||
|
onItemsLoadComplete();
|
||||||
|
view.requestLayout();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void onItemsLoadComplete() {
|
||||||
|
// Update the adapter and notify data set changed
|
||||||
|
// ...
|
||||||
|
|
||||||
|
// Stop refresh animation
|
||||||
|
mSwipeRefreshLayout.setRefreshing(false);
|
||||||
|
}
|
||||||
|
|
||||||
protected abstract List<Module> listModules();
|
protected abstract List<Module> listModules();
|
||||||
}
|
}
|
||||||
|
@ -3,7 +3,9 @@ package com.topjohnwu.magisk;
|
|||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.support.annotation.Nullable;
|
import android.support.annotation.Nullable;
|
||||||
import android.support.v4.app.Fragment;
|
import android.support.v4.app.Fragment;
|
||||||
|
import android.support.v4.widget.SwipeRefreshLayout;
|
||||||
import android.support.v7.widget.RecyclerView;
|
import android.support.v7.widget.RecyclerView;
|
||||||
|
import android.util.Log;
|
||||||
import android.view.LayoutInflater;
|
import android.view.LayoutInflater;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
import android.view.ViewGroup;
|
import android.view.ViewGroup;
|
||||||
@ -11,6 +13,7 @@ import android.widget.TextView;
|
|||||||
|
|
||||||
import com.topjohnwu.magisk.module.Module;
|
import com.topjohnwu.magisk.module.Module;
|
||||||
import com.topjohnwu.magisk.module.Repo;
|
import com.topjohnwu.magisk.module.Repo;
|
||||||
|
import com.topjohnwu.magisk.utils.Utils;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
@ -23,11 +26,16 @@ public abstract class BaseRepoFragment extends Fragment {
|
|||||||
RecyclerView recyclerView;
|
RecyclerView recyclerView;
|
||||||
@BindView(R.id.empty_rv)
|
@BindView(R.id.empty_rv)
|
||||||
TextView emptyTv;
|
TextView emptyTv;
|
||||||
|
private SwipeRefreshLayout mSwipeRefreshLayout;
|
||||||
@Nullable
|
@Nullable
|
||||||
@Override
|
@Override
|
||||||
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
|
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
|
||||||
View view = inflater.inflate(R.layout.single_module_fragment, container, false);
|
View view = inflater.inflate(R.layout.single_module_fragment, container, false);
|
||||||
|
mSwipeRefreshLayout = (SwipeRefreshLayout) view.findViewById(R.id.swipeRefreshLayout);
|
||||||
|
mSwipeRefreshLayout.setOnRefreshListener(() -> {
|
||||||
|
refreshItems();
|
||||||
|
});
|
||||||
|
|
||||||
ButterKnife.bind(this, view);
|
ButterKnife.bind(this, view);
|
||||||
|
|
||||||
if (listRepos().size() == 0) {
|
if (listRepos().size() == 0) {
|
||||||
@ -43,5 +51,18 @@ public abstract class BaseRepoFragment extends Fragment {
|
|||||||
return view;
|
return view;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void refreshItems() {
|
||||||
|
Log.d("Magisk", "Calling refreshitems for online");
|
||||||
|
new Utils.LoadModules(getActivity(),true).execute();
|
||||||
|
onItemsLoadComplete();
|
||||||
|
}
|
||||||
|
|
||||||
|
void onItemsLoadComplete() {
|
||||||
|
// Update the adapter and notify data set changed
|
||||||
|
// ...
|
||||||
|
|
||||||
|
// Stop refresh animation
|
||||||
|
mSwipeRefreshLayout.setRefreshing(false);
|
||||||
|
}
|
||||||
protected abstract List<Repo> listRepos();
|
protected abstract List<Repo> listRepos();
|
||||||
}
|
}
|
||||||
|
@ -2,9 +2,11 @@ package com.topjohnwu.magisk;
|
|||||||
|
|
||||||
import android.app.Activity;
|
import android.app.Activity;
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
|
import android.content.SharedPreferences;
|
||||||
import android.net.Uri;
|
import android.net.Uri;
|
||||||
import android.os.AsyncTask;
|
import android.os.AsyncTask;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
|
import android.preference.PreferenceManager;
|
||||||
import android.support.annotation.Nullable;
|
import android.support.annotation.Nullable;
|
||||||
import android.support.design.widget.FloatingActionButton;
|
import android.support.design.widget.FloatingActionButton;
|
||||||
import android.support.design.widget.TabLayout;
|
import android.support.design.widget.TabLayout;
|
||||||
@ -50,7 +52,12 @@ public class ModulesFragment extends Fragment {
|
|||||||
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
|
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
|
||||||
View view = inflater.inflate(R.layout.modules_fragment, container, false);
|
View view = inflater.inflate(R.layout.modules_fragment, container, false);
|
||||||
ButterKnife.bind(this, view);
|
ButterKnife.bind(this, view);
|
||||||
new Utils.LoadModules(getContext()).execute();
|
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(getActivity());
|
||||||
|
if (prefs.contains("hasCachedRepos")) {
|
||||||
|
new Utils.LoadModules(getActivity(), false).execute();
|
||||||
|
} else {
|
||||||
|
new Utils.LoadModules(getActivity(), true).execute();
|
||||||
|
}
|
||||||
new updateUI().execute();
|
new updateUI().execute();
|
||||||
setHasOptionsMenu(true);
|
setHasOptionsMenu(true);
|
||||||
return view;
|
return view;
|
||||||
@ -99,7 +106,7 @@ public class ModulesFragment extends Fragment {
|
|||||||
progressBar.setVisibility(View.VISIBLE);
|
progressBar.setVisibility(View.VISIBLE);
|
||||||
viewPager.setAdapter(new TabsAdapter(getChildFragmentManager()));
|
viewPager.setAdapter(new TabsAdapter(getChildFragmentManager()));
|
||||||
tabLayout.setupWithViewPager(viewPager);
|
tabLayout.setupWithViewPager(viewPager);
|
||||||
new Utils.LoadModules(getContext()).execute();
|
new Utils.LoadModules(getActivity(),false).execute();
|
||||||
new updateUI().execute();
|
new updateUI().execute();
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -1,6 +1,8 @@
|
|||||||
package com.topjohnwu.magisk;
|
package com.topjohnwu.magisk;
|
||||||
|
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
|
import android.content.SharedPreferences;
|
||||||
|
import android.preference.PreferenceManager;
|
||||||
import android.support.v7.widget.RecyclerView;
|
import android.support.v7.widget.RecyclerView;
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
import android.view.LayoutInflater;
|
import android.view.LayoutInflater;
|
||||||
@ -9,6 +11,7 @@ import android.view.ViewGroup;
|
|||||||
import android.widget.CheckBox;
|
import android.widget.CheckBox;
|
||||||
import android.widget.ImageView;
|
import android.widget.ImageView;
|
||||||
import android.widget.TextView;
|
import android.widget.TextView;
|
||||||
|
import android.widget.Toast;
|
||||||
|
|
||||||
import com.topjohnwu.magisk.module.Module;
|
import com.topjohnwu.magisk.module.Module;
|
||||||
import com.topjohnwu.magisk.module.Repo;
|
import com.topjohnwu.magisk.module.Repo;
|
||||||
@ -52,17 +55,21 @@ public class ReposAdapter extends RecyclerView.Adapter<ReposAdapter.ViewHolder>
|
|||||||
view.setOnClickListener(new View.OnClickListener() {
|
view.setOnClickListener(new View.OnClickListener() {
|
||||||
@Override
|
@Override
|
||||||
public void onClick(View view) {
|
public void onClick(View view) {
|
||||||
|
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
|
||||||
|
if (!prefs.contains("isInstalled_" + repo.getName())) {
|
||||||
|
|
||||||
Utils.DownloadReceiver reciever = new Utils.DownloadReceiver() {
|
Utils.DownloadReceiver reciever = new Utils.DownloadReceiver() {
|
||||||
@Override
|
@Override
|
||||||
public void task(File file) {
|
public void task(File file) {
|
||||||
Log.d("Magisk","Task firing");
|
Log.d("Magisk", "Task firing");
|
||||||
new Utils.FlashZIP(context,repo.getName(),file.toString()).execute();
|
new Utils.FlashZIP(context, repo.getName(), file.toString()).execute();
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
String filename = repo.getName().replace(" ","") + ".zip";
|
String filename = repo.getName().replace(" ", "") + ".zip";
|
||||||
Utils.downloadAndReceive(context,reciever,repo.getZipUrl(),filename);
|
Utils.downloadAndReceive(context, reciever, repo.getZipUrl(), filename);
|
||||||
|
} else {
|
||||||
|
Toast.makeText(context,repo.getName() + " is already installed.",Toast.LENGTH_SHORT).show();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -1,6 +1,8 @@
|
|||||||
package com.topjohnwu.magisk;
|
package com.topjohnwu.magisk;
|
||||||
|
|
||||||
import android.Manifest;
|
import android.Manifest;
|
||||||
|
import android.app.Activity;
|
||||||
|
import android.content.Context;
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
import android.content.pm.PackageManager;
|
import android.content.pm.PackageManager;
|
||||||
import android.os.Build;
|
import android.os.Build;
|
||||||
@ -28,6 +30,7 @@ import butterknife.ButterKnife;
|
|||||||
public class WelcomeActivity extends AppCompatActivity implements NavigationView.OnNavigationItemSelectedListener {
|
public class WelcomeActivity extends AppCompatActivity implements NavigationView.OnNavigationItemSelectedListener {
|
||||||
|
|
||||||
private static final String SELECTED_ITEM_ID = "SELECTED_ITEM_ID";
|
private static final String SELECTED_ITEM_ID = "SELECTED_ITEM_ID";
|
||||||
|
private Context mContext;
|
||||||
|
|
||||||
private final Handler mDrawerHandler = new Handler();
|
private final Handler mDrawerHandler = new Handler();
|
||||||
|
|
||||||
@ -55,7 +58,7 @@ public class WelcomeActivity extends AppCompatActivity implements NavigationView
|
|||||||
}
|
}
|
||||||
new Utils.Initialize(this).execute();
|
new Utils.Initialize(this).execute();
|
||||||
new Utils.CheckUpdates(this).execute();
|
new Utils.CheckUpdates(this).execute();
|
||||||
new Utils.LoadModules(this).execute();
|
new Utils.LoadModules(getApplication(),false).execute();
|
||||||
|
|
||||||
setSupportActionBar(toolbar);
|
setSupportActionBar(toolbar);
|
||||||
|
|
||||||
@ -88,6 +91,7 @@ public class WelcomeActivity extends AppCompatActivity implements NavigationView
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onSaveInstanceState(Bundle outState) {
|
protected void onSaveInstanceState(Bundle outState) {
|
||||||
super.onSaveInstanceState(outState);
|
super.onSaveInstanceState(outState);
|
||||||
|
@ -1,7 +1,14 @@
|
|||||||
package com.topjohnwu.magisk.module;
|
package com.topjohnwu.magisk.module;
|
||||||
|
|
||||||
|
import android.content.Context;
|
||||||
|
import android.content.SharedPreferences;
|
||||||
|
import android.preference.PreferenceManager;
|
||||||
|
import android.util.Log;
|
||||||
|
|
||||||
import com.topjohnwu.magisk.utils.Utils;
|
import com.topjohnwu.magisk.utils.Utils;
|
||||||
|
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
public class Module {
|
public class Module {
|
||||||
|
|
||||||
private String mRemoveFile;
|
private String mRemoveFile;
|
||||||
@ -18,7 +25,16 @@ public class Module {
|
|||||||
private String mId;
|
private String mId;
|
||||||
private int mVersionCode;
|
private int mVersionCode;
|
||||||
|
|
||||||
public Module(String path) {
|
public Module(String path, Context context) {
|
||||||
|
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
|
||||||
|
Map<String,?> keys = prefs.getAll();
|
||||||
|
|
||||||
|
for(Map.Entry<String,?> entry : keys.entrySet()){
|
||||||
|
|
||||||
|
if(entry.getValue().toString().contains(path)) {
|
||||||
|
Log.d("Magisk", "Hey, look a matching path, this guy's name is " + entry.getKey().replace("path_",""));
|
||||||
|
}
|
||||||
|
}
|
||||||
mRemoveFile = path + "/remove";
|
mRemoveFile = path + "/remove";
|
||||||
mDisableFile = path + "/disable";
|
mDisableFile = path + "/disable";
|
||||||
for (String line : Utils.readFile(path + "/module.prop")) {
|
for (String line : Utils.readFile(path + "/module.prop")) {
|
||||||
|
@ -11,38 +11,43 @@ import org.json.JSONArray;
|
|||||||
import org.json.JSONException;
|
import org.json.JSONException;
|
||||||
import org.json.JSONObject;
|
import org.json.JSONObject;
|
||||||
|
|
||||||
import java.util.HashSet;
|
import java.text.SimpleDateFormat;
|
||||||
import java.util.Set;
|
import java.util.Date;
|
||||||
|
|
||||||
public class Repo {
|
public class Repo {
|
||||||
public String name;
|
public String name;
|
||||||
public String baseUrl, zipUrl,manifestUrl, logUrl;
|
public String baseUrl, zipUrl, manifestUrl, logUrl, manifest, version, moduleName, moduleDescription, moduleAuthor, moduleAuthorUrl;
|
||||||
public String manifest, version, moduleName, moduleDescription, moduleAuthor, moduleAuthorUrl;
|
public Date lastUpdate;
|
||||||
public Boolean usesRoot,usesXposed;
|
public Boolean usesRoot, usesXposed;
|
||||||
private Context appContext;
|
private Context appContext;
|
||||||
private SharedPreferences prefs;
|
private SharedPreferences prefs;
|
||||||
|
|
||||||
|
|
||||||
public Repo(String name, String url, Context context) {
|
public Repo(String name, String url, Date updated, Context context) {
|
||||||
appContext = context;
|
appContext = context;
|
||||||
this.name = name;
|
this.name = name;
|
||||||
this.baseUrl = url;
|
this.baseUrl = url;
|
||||||
prefs = PreferenceManager.getDefaultSharedPreferences(appContext);
|
this.lastUpdate = updated;
|
||||||
|
this.fetch();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public Repo(String moduleName, String moduleDescription, String zipUrl) {
|
public Repo(String moduleName, String moduleDescription, String zipUrl, Date lastUpdated, Context context) {
|
||||||
|
Log.d("Magisk", "Hey, I'm a repo! My name is " + moduleName);
|
||||||
|
appContext = context;
|
||||||
this.zipUrl = zipUrl;
|
this.zipUrl = zipUrl;
|
||||||
this.moduleDescription = moduleDescription;
|
this.moduleDescription = moduleDescription;
|
||||||
this.moduleName = moduleName;
|
this.moduleName = moduleName;
|
||||||
prefs = PreferenceManager.getDefaultSharedPreferences(appContext);
|
this.lastUpdate = lastUpdated;
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void fetch() {
|
public void fetch() {
|
||||||
|
prefs = PreferenceManager.getDefaultSharedPreferences(appContext);
|
||||||
WebRequest webreq = new WebRequest();
|
WebRequest webreq = new WebRequest();
|
||||||
// Construct initial url for contents
|
// Construct initial url for contents
|
||||||
Log.d("Magisk","Manifest string is: " + baseUrl + "/contents/");
|
Log.d("Magisk", "Manifest string is: " + baseUrl + "/contents/");
|
||||||
String repoString = webreq.makeWebServiceCall(baseUrl + "/contents/", WebRequest.GET);
|
String repoString = webreq.makeWebServiceCall(baseUrl + "/contents/", WebRequest.GET);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
@ -63,13 +68,13 @@ public class Repo {
|
|||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
|
|
||||||
Log.d("Magisk","Inner fetch: " + repoString);
|
Log.d("Magisk", "Inner fetch: " + repoString);
|
||||||
try {
|
try {
|
||||||
WebRequest jsonReq = new WebRequest();
|
WebRequest jsonReq = new WebRequest();
|
||||||
// Construct initial url for contents
|
// Construct initial url for contents
|
||||||
String manifestString = webreq.makeWebServiceCall(this.manifestUrl, WebRequest.GET);
|
String manifestString = webreq.makeWebServiceCall(this.manifestUrl, WebRequest.GET);
|
||||||
JSONObject manifestObject = new JSONObject(manifestString);
|
JSONObject manifestObject = new JSONObject(manifestString);
|
||||||
Log.d("Magisk","Object: " +manifestObject.toString());
|
Log.d("Magisk", "Object: " + manifestObject.toString());
|
||||||
version = manifestObject.getString("versionCode");
|
version = manifestObject.getString("versionCode");
|
||||||
moduleName = manifestObject.getString("moduleName");
|
moduleName = manifestObject.getString("moduleName");
|
||||||
moduleDescription = manifestObject.getString("moduleDescription");
|
moduleDescription = manifestObject.getString("moduleDescription");
|
||||||
@ -84,9 +89,13 @@ public class Repo {
|
|||||||
+ "\"usesRoot\":\"" + usesRoot + "\","
|
+ "\"usesRoot\":\"" + usesRoot + "\","
|
||||||
+ "\"usesXposed\":\"" + usesXposed + "\","
|
+ "\"usesXposed\":\"" + usesXposed + "\","
|
||||||
+ "\"zipUrl\":\"" + zipUrl + "\","
|
+ "\"zipUrl\":\"" + zipUrl + "\","
|
||||||
|
+ "\"lastUpdate\":\"" + lastUpdate + "\","
|
||||||
+ "\"logUrl\":\"" + logUrl + "\"}]";
|
+ "\"logUrl\":\"" + logUrl + "\"}]";
|
||||||
editor.putString("module_" + moduleName,prefsString);
|
editor.putString("module_" + moduleName, prefsString);
|
||||||
editor.putBoolean("hasCachedRepos",true);
|
editor.putBoolean("hasCachedRepos", true);
|
||||||
|
SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMdd_HHmmss");
|
||||||
|
editor.putString("updated", sdf.toString());
|
||||||
|
Log.d("Magisk", "Storing Preferences: " + prefsString);
|
||||||
editor.apply();
|
editor.apply();
|
||||||
|
|
||||||
} catch (JSONException e) {
|
} catch (JSONException e) {
|
||||||
@ -116,6 +125,4 @@ public class Repo {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
@ -28,6 +28,7 @@ import com.topjohnwu.magisk.module.Module;
|
|||||||
import com.topjohnwu.magisk.module.RepoAdapter;
|
import com.topjohnwu.magisk.module.RepoAdapter;
|
||||||
import com.topjohnwu.magisk.module.Repo;
|
import com.topjohnwu.magisk.module.Repo;
|
||||||
|
|
||||||
|
import org.json.JSONArray;
|
||||||
import org.json.JSONException;
|
import org.json.JSONException;
|
||||||
import org.json.JSONObject;
|
import org.json.JSONObject;
|
||||||
|
|
||||||
@ -37,17 +38,21 @@ import java.io.IOException;
|
|||||||
import java.io.InputStreamReader;
|
import java.io.InputStreamReader;
|
||||||
import java.net.HttpURLConnection;
|
import java.net.HttpURLConnection;
|
||||||
import java.net.URL;
|
import java.net.URL;
|
||||||
|
import java.text.ParseException;
|
||||||
|
import java.text.SimpleDateFormat;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
public class Utils {
|
public class Utils {
|
||||||
|
|
||||||
public static int magiskVersion, remoteMagiskVersion = -1, remoteAppVersion = -1;
|
public static int magiskVersion, remoteMagiskVersion = -1, remoteAppVersion = -1;
|
||||||
public static String magiskLink, magiskChangelog, appChangelog, appLink, phhLink, supersuLink;
|
public static String magiskLink, magiskChangelog, appChangelog, appLink, phhLink, supersuLink;
|
||||||
|
private Context appContext;
|
||||||
|
|
||||||
public static final String MAGISK_PATH = "/magisk";
|
public static final String MAGISK_PATH = "/magisk";
|
||||||
public static final String MAGISK_CACHE_PATH = "/cache/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 final String UPDATE_JSON = "https://raw.githubusercontent.com/topjohnwu/MagiskManager/updates/magisk_update.json";
|
||||||
|
|
||||||
|
|
||||||
public static boolean fileExist(String path) {
|
public static boolean fileExist(String path) {
|
||||||
List<String> ret;
|
List<String> ret;
|
||||||
ret = Shell.sh("if [ -f " + path + " ]; then echo true; else echo false; fi");
|
ret = Shell.sh("if [ -f " + path + " ]; then echo true; else echo false; fi");
|
||||||
@ -87,6 +92,10 @@ public class Utils {
|
|||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public Utils(Context context) {
|
||||||
|
appContext = context;
|
||||||
|
}
|
||||||
|
|
||||||
public static void downloadAndReceive(Context context, DownloadReceiver receiver, String link, String file) {
|
public static void downloadAndReceive(Context context, DownloadReceiver receiver, String link, String file) {
|
||||||
if (ActivityCompat.checkSelfPermission(context, Manifest.permission.WRITE_EXTERNAL_STORAGE) != PackageManager.PERMISSION_GRANTED) {
|
if (ActivityCompat.checkSelfPermission(context, Manifest.permission.WRITE_EXTERNAL_STORAGE) != PackageManager.PERMISSION_GRANTED) {
|
||||||
Toast.makeText(context, R.string.permissionNotGranted, Toast.LENGTH_LONG).show();
|
Toast.makeText(context, R.string.permissionNotGranted, Toast.LENGTH_LONG).show();
|
||||||
@ -366,9 +375,14 @@ public class Utils {
|
|||||||
public static class LoadModules extends AsyncTask<Void, Void, Void> {
|
public static class LoadModules extends AsyncTask<Void, Void, Void> {
|
||||||
|
|
||||||
private Context mContext;
|
private Context mContext;
|
||||||
|
private boolean doReload;
|
||||||
|
|
||||||
public LoadModules(Context context) {
|
public LoadModules(Context context, boolean reload) {
|
||||||
|
Log.d("Magisk", "LoadModules created, online is " + reload);
|
||||||
mContext = context;
|
mContext = context;
|
||||||
|
doReload = reload;
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -377,17 +391,17 @@ public class Utils {
|
|||||||
ModulesFragment.listModulesCache.clear();
|
ModulesFragment.listModulesCache.clear();
|
||||||
ModulesFragment.listModulesDownload.clear();
|
ModulesFragment.listModulesDownload.clear();
|
||||||
List<String> magisk = getModList(MAGISK_PATH);
|
List<String> magisk = getModList(MAGISK_PATH);
|
||||||
Log.d("Magisk", String.valueOf(magisk));
|
Log.d("Magisk", "Reload called, online mode set to " + doReload);
|
||||||
List<String> magiskCache = getModList(MAGISK_CACHE_PATH);
|
List<String> magiskCache = getModList(MAGISK_CACHE_PATH);
|
||||||
RepoAdapter mr = new RepoAdapter();
|
RepoAdapter mr = new RepoAdapter();
|
||||||
|
|
||||||
List<Repo> magiskRepos = mr.listRepos(mContext);
|
|
||||||
|
List<Repo> magiskRepos = mr.listRepos(mContext, doReload);
|
||||||
for (String mod : magisk) {
|
for (String mod : magisk) {
|
||||||
Log.d("Magisk","Utils, listing modules " + mod);
|
ModulesFragment.listModules.add(new Module(mod,mContext));
|
||||||
ModulesFragment.listModules.add(new Module(mod));
|
|
||||||
}
|
}
|
||||||
for (String mod : magiskCache) {
|
for (String mod : magiskCache) {
|
||||||
ModulesFragment.listModulesCache.add(new Module(mod));
|
ModulesFragment.listModulesCache.add(new Module(mod,mContext));
|
||||||
}
|
}
|
||||||
for (Repo repo : magiskRepos) {
|
for (Repo repo : magiskRepos) {
|
||||||
ModulesFragment.listModulesDownload.add(repo);
|
ModulesFragment.listModulesDownload.add(repo);
|
||||||
@ -395,6 +409,11 @@ public class Utils {
|
|||||||
|
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void onPostExecute(Void aVoid) {
|
||||||
|
super.onPostExecute(aVoid);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static class FlashZIP extends AsyncTask<Void, Void, Boolean> {
|
public static class FlashZIP extends AsyncTask<Void, Void, Boolean> {
|
||||||
@ -402,6 +421,7 @@ public class Utils {
|
|||||||
private String mPath, mName;
|
private String mPath, mName;
|
||||||
private ProgressDialog progress;
|
private ProgressDialog progress;
|
||||||
private Context mContext;
|
private Context mContext;
|
||||||
|
private List<String> ret;
|
||||||
|
|
||||||
public FlashZIP(Context context, String name, String path) {
|
public FlashZIP(Context context, String name, String path) {
|
||||||
mContext = context;
|
mContext = context;
|
||||||
@ -420,7 +440,7 @@ public class Utils {
|
|||||||
if (!Shell.rootAccess()) {
|
if (!Shell.rootAccess()) {
|
||||||
return false;
|
return false;
|
||||||
} else {
|
} else {
|
||||||
List<String> ret = Shell.su(
|
ret = Shell.su(
|
||||||
"rm -rf /data/tmp",
|
"rm -rf /data/tmp",
|
||||||
"mkdir -p /data/tmp",
|
"mkdir -p /data/tmp",
|
||||||
"cp -af " + mPath + " /data/tmp/install.zip",
|
"cp -af " + mPath + " /data/tmp/install.zip",
|
||||||
@ -428,7 +448,6 @@ public class Utils {
|
|||||||
"BOOTMODE=true sh /data/tmp/META-INF/com/google/android/update-binary dummy 1 /data/tmp/install.zip",
|
"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"
|
"if [ $? -eq 0 ]; then echo true; else echo false; fi"
|
||||||
);
|
);
|
||||||
Log.d("Magisk","ZipResult: " + ret.toString());
|
|
||||||
return Boolean.parseBoolean(ret.get(ret.size() -1));
|
return Boolean.parseBoolean(ret.get(ret.size() -1));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -441,6 +460,35 @@ public class Utils {
|
|||||||
if (!result) {
|
if (!result) {
|
||||||
Toast.makeText(mContext, mContext.getString(R.string.manual_install, mPath), Toast.LENGTH_LONG).show();
|
Toast.makeText(mContext, mContext.getString(R.string.manual_install, mPath), Toast.LENGTH_LONG).show();
|
||||||
return;
|
return;
|
||||||
|
} else {
|
||||||
|
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(mContext);
|
||||||
|
String jsonString = prefs.getString("module_" + mName,"");
|
||||||
|
String retSplit[] = ret.toString().split("Using path:");
|
||||||
|
String ret2Split[] = retSplit[1].split(",");
|
||||||
|
String ret3Split[] = ret2Split[0].split("/");
|
||||||
|
String finalSplit = "/" + ret3Split[1] + "/" + ret3Split[2];
|
||||||
|
Log.d("Magisk","Damn, all that work for one path " + finalSplit);
|
||||||
|
if (!jsonString.equals("")) {
|
||||||
|
|
||||||
|
JSONArray repoArray = null;
|
||||||
|
try {
|
||||||
|
repoArray = new JSONArray(jsonString);
|
||||||
|
|
||||||
|
|
||||||
|
for (int f = 0; f < repoArray.length(); f++) {
|
||||||
|
JSONObject jsonobject = repoArray.getJSONObject(f);
|
||||||
|
String name = mName;
|
||||||
|
Boolean installed = true;
|
||||||
|
SharedPreferences.Editor editor = prefs.edit();
|
||||||
|
editor.putBoolean("isInstalled_" + mName,true);
|
||||||
|
editor.putString("path_" + mName,finalSplit);
|
||||||
|
editor.apply();
|
||||||
|
|
||||||
|
}
|
||||||
|
} catch (JSONException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
done();
|
done();
|
||||||
}
|
}
|
||||||
|
@ -1,9 +1,10 @@
|
|||||||
<?xml version="1.0" encoding="utf-8"?>
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
<android.support.v4.widget.SwipeRefreshLayout android:id="@+id/swipeRefreshLayout"
|
||||||
xmlns:app="http://schemas.android.com/apk/res-auto"
|
android:layout_width="match_parent"
|
||||||
android:layout_width="match_parent"
|
android:layout_height="match_parent"
|
||||||
android:layout_height="match_parent"
|
layout_height=""
|
||||||
android:orientation="vertical">
|
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
|
xmlns:app="http://schemas.android.com/apk/res-auto">
|
||||||
|
|
||||||
<android.support.v7.widget.RecyclerView
|
<android.support.v7.widget.RecyclerView
|
||||||
android:id="@+id/recyclerView"
|
android:id="@+id/recyclerView"
|
||||||
@ -23,4 +24,4 @@
|
|||||||
android:textStyle="italic"
|
android:textStyle="italic"
|
||||||
android:visibility="gone"/>
|
android:visibility="gone"/>
|
||||||
|
|
||||||
</LinearLayout>
|
</android.support.v4.widget.SwipeRefreshLayout>
|
Loading…
Reference in New Issue
Block a user