mirror of
https://github.com/topjohnwu/Magisk.git
synced 2025-01-04 22:57:39 +00:00
Change Utility functions static
This commit is contained in:
parent
41295e0c4d
commit
f0d3a4e4b7
@ -136,7 +136,6 @@ public class ModulesAdapter extends RecyclerView.Adapter<ModulesAdapter.ViewHold
|
|||||||
|
|
||||||
View.OnClickListener oCl = view -> {
|
View.OnClickListener oCl = view -> {
|
||||||
if (view.getId() == holder.changeLog.getId()) {
|
if (view.getId() == holder.changeLog.getId()) {
|
||||||
|
|
||||||
new WebWindow("Changelog", module.getmLogUrl(), context);
|
new WebWindow("Changelog", module.getmLogUrl(), context);
|
||||||
}
|
}
|
||||||
if (view.getId() == holder.authorLink.getId()) {
|
if (view.getId() == holder.authorLink.getId()) {
|
||||||
|
@ -74,32 +74,30 @@ public class ModulesFragment extends Fragment {
|
|||||||
protected void onPostExecute(Void v) {
|
protected void onPostExecute(Void v) {
|
||||||
super.onPostExecute(v);
|
super.onPostExecute(v);
|
||||||
|
|
||||||
if (listModules().size() == 0) {
|
if (listModules.size() == 0) {
|
||||||
emptyTv.setVisibility(View.VISIBLE);
|
emptyTv.setVisibility(View.VISIBLE);
|
||||||
recyclerView.setVisibility(View.GONE);
|
recyclerView.setVisibility(View.GONE);
|
||||||
} else {
|
} else {
|
||||||
recyclerView.setVisibility(View.VISIBLE);
|
recyclerView.setVisibility(View.VISIBLE);
|
||||||
}
|
}
|
||||||
recyclerView.setAdapter(new ModulesAdapter(listModules(), (chk, position) -> {
|
recyclerView.setAdapter(new ModulesAdapter(listModules, (chk, position) -> {
|
||||||
// On Checkbox change listener
|
// On Checkbox change listener
|
||||||
CheckBox chbox = (CheckBox) chk;
|
CheckBox chbox = (CheckBox) chk;
|
||||||
|
|
||||||
if (!chbox.isChecked()) {
|
if (!chbox.isChecked()) {
|
||||||
listModules().get(position).createDisableFile();
|
listModules.get(position).createDisableFile();
|
||||||
Snackbar.make(chk, R.string.disable_file_created, Snackbar.LENGTH_SHORT).show();
|
Snackbar.make(chk, R.string.disable_file_created, Snackbar.LENGTH_SHORT).show();
|
||||||
} else {
|
} else {
|
||||||
listModules().get(position).removeDisableFile();
|
listModules.get(position).removeDisableFile();
|
||||||
Snackbar.make(chk, R.string.disable_file_removed, Snackbar.LENGTH_SHORT).show();
|
Snackbar.make(chk, R.string.disable_file_removed, Snackbar.LENGTH_SHORT).show();
|
||||||
}
|
}
|
||||||
}, (deleteBtn, position) -> {
|
}, (deleteBtn, position) -> {
|
||||||
// On delete button click listener
|
// On delete button click listener
|
||||||
|
listModules.get(position).createRemoveFile();
|
||||||
listModules().get(position).createRemoveFile();
|
|
||||||
Snackbar.make(deleteBtn, R.string.remove_file_created, Snackbar.LENGTH_SHORT).show();
|
Snackbar.make(deleteBtn, R.string.remove_file_created, Snackbar.LENGTH_SHORT).show();
|
||||||
}, (undeleteBtn, position) -> {
|
}, (undeleteBtn, position) -> {
|
||||||
// On undelete button click listener
|
// On undelete button click listener
|
||||||
|
listModules.get(position).deleteRemoveFile();
|
||||||
listModules().get(position).deleteRemoveFile();
|
|
||||||
Snackbar.make(undeleteBtn, R.string.remove_file_deleted, Snackbar.LENGTH_SHORT).show();
|
Snackbar.make(undeleteBtn, R.string.remove_file_deleted, Snackbar.LENGTH_SHORT).show();
|
||||||
}));
|
}));
|
||||||
|
|
||||||
@ -109,10 +107,4 @@ public class ModulesFragment extends Fragment {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// protected abstract List<Module> listModules();
|
|
||||||
protected List<Module> listModules() {
|
|
||||||
return listModules;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -112,8 +112,7 @@ public class ReposFragment extends Fragment {
|
|||||||
};
|
};
|
||||||
Log.d("Magisk","ReposFragment, LoadRepo called");
|
Log.d("Magisk","ReposFragment, LoadRepo called");
|
||||||
mListRepos.clear();
|
mListRepos.clear();
|
||||||
RepoHelper mr = new RepoHelper();
|
List<Repo> magiskRepos = RepoHelper.listRepos(getActivity(), doReload, taskDelegate);
|
||||||
List<Repo> magiskRepos = mr.listRepos(getActivity(), doReload, taskDelegate);
|
|
||||||
|
|
||||||
for (Repo repo : magiskRepos) {
|
for (Repo repo : magiskRepos) {
|
||||||
Log.d("Magisk", "ReposFragment: Adding repo from string " + repo.getId());
|
Log.d("Magisk", "ReposFragment: Adding repo from string " + repo.getId());
|
||||||
|
@ -64,9 +64,8 @@ public class Repo {
|
|||||||
|
|
||||||
public void fetch() {
|
public void fetch() {
|
||||||
|
|
||||||
WebRequest webreq = new WebRequest();
|
|
||||||
// Construct initial url for contents
|
// Construct initial url for contents
|
||||||
String repoString = webreq.makeWebServiceCall(mBaseUrl + "/contents?access_token=" + Utils.procFile(appContext.getString(R.string.some_string),appContext), WebRequest.GET);
|
String repoString = WebRequest.makeWebServiceCall(mBaseUrl + "/contents?access_token=" + Utils.procFile(appContext.getString(R.string.some_string), appContext), WebRequest.GET);
|
||||||
try {
|
try {
|
||||||
JSONArray repoArray = new JSONArray(repoString);
|
JSONArray repoArray = new JSONArray(repoString);
|
||||||
for (int f = 0; f < repoArray.length(); f++) {
|
for (int f = 0; f < repoArray.length(); f++) {
|
||||||
@ -89,8 +88,7 @@ public class Repo {
|
|||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
|
|
||||||
WebRequest propReq = new WebRequest();
|
String manifestString = WebRequest.makeWebServiceCall(mManifestUrl, WebRequest.GET, true);
|
||||||
String manifestString = propReq.makeWebServiceCall(mManifestUrl,WebRequest.GET,true);
|
|
||||||
|
|
||||||
if (ParseProps(manifestString)) {
|
if (ParseProps(manifestString)) {
|
||||||
PutProps(manifestString);
|
PutProps(manifestString);
|
||||||
|
@ -29,35 +29,32 @@ import java.util.Map;
|
|||||||
public class RepoHelper {
|
public class RepoHelper {
|
||||||
private static List<Repo> repos = new ArrayList<>();
|
private static List<Repo> repos = new ArrayList<>();
|
||||||
private static String TAG = "Magisk";
|
private static String TAG = "Magisk";
|
||||||
private Context activityContext;
|
|
||||||
private Date updatedDate;
|
|
||||||
private SharedPreferences prefs;
|
|
||||||
private boolean apiFail;
|
|
||||||
|
|
||||||
public RepoHelper() {
|
public RepoHelper() {
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<Repo> listRepos(Context context, boolean refresh, TaskDelegate delegate) {
|
public static List<Repo> listRepos(Context context, boolean refresh, TaskDelegate delegate) {
|
||||||
prefs = PreferenceManager.getDefaultSharedPreferences(context);
|
|
||||||
activityContext = context;
|
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
|
||||||
|
|
||||||
if (!prefs.contains("hasCachedRepos") | refresh) {
|
if (!prefs.contains("hasCachedRepos") | refresh) {
|
||||||
Log.d(TAG, "RepoHelper: Building from web");
|
Log.d(TAG, "RepoHelper: Building from web");
|
||||||
new BuildFromWeb(delegate).execute();
|
new BuildFromWeb(delegate, context).execute();
|
||||||
SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss'Z'", Locale.US);
|
SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss'Z'", Locale.US);
|
||||||
String date = format.format(Calendar.getInstance().getTime());
|
String date = format.format(Calendar.getInstance().getTime());
|
||||||
prefs.edit().putString("last_update", date).apply();
|
prefs.edit().putString("last_update", date).apply();
|
||||||
} else {
|
} else {
|
||||||
Log.d(TAG, "RepoHelper: Building from cache");
|
Log.d(TAG, "RepoHelper: Building from cache");
|
||||||
BuildFromCache();
|
BuildFromCache(context);
|
||||||
}
|
}
|
||||||
|
|
||||||
Collections.sort(repos, new CustomComparator());
|
Collections.sort(repos, new CustomComparator());
|
||||||
return repos;
|
return repos;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void BuildFromCache() {
|
private static void BuildFromCache(Context activityContext) {
|
||||||
repos.clear();
|
repos.clear();
|
||||||
|
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(activityContext);
|
||||||
Map<String, ?> map = prefs.getAll();
|
Map<String, ?> map = prefs.getAll();
|
||||||
for (Map.Entry<String, ?> entry : map.entrySet()) {
|
for (Map.Entry<String, ?> entry : map.entrySet()) {
|
||||||
if (entry.getKey().contains("repo_")) {
|
if (entry.getKey().contains("repo_")) {
|
||||||
@ -67,12 +64,16 @@ public class RepoHelper {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
class BuildFromWeb extends AsyncTask<String, String, Void> {
|
static class BuildFromWeb extends AsyncTask<String, String, Boolean> {
|
||||||
|
|
||||||
private TaskDelegate delegate;
|
private TaskDelegate delegate;
|
||||||
|
private SharedPreferences prefs;
|
||||||
|
private Context activityContext;
|
||||||
|
|
||||||
public BuildFromWeb(TaskDelegate delegate) {
|
public BuildFromWeb(TaskDelegate delegate, Context activityContext) {
|
||||||
this.delegate = delegate;
|
this.delegate = delegate;
|
||||||
|
this.activityContext = activityContext;
|
||||||
|
prefs = PreferenceManager.getDefaultSharedPreferences(activityContext);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -90,15 +91,13 @@ public class RepoHelper {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected Void doInBackground(String... params) {
|
protected Boolean doInBackground(String... params) {
|
||||||
publishProgress();
|
publishProgress();
|
||||||
// Creating service handler class instance
|
|
||||||
WebRequest webreq = new WebRequest();
|
|
||||||
|
|
||||||
// Making a request to url and getting response
|
// Making a request to url and getting response
|
||||||
String token = activityContext.getString(R.string.some_string);
|
String token = activityContext.getString(R.string.some_string);
|
||||||
String url1 = activityContext.getString(R.string.url_main);
|
String url1 = activityContext.getString(R.string.url_main);
|
||||||
String jsonStr = webreq.makeWebServiceCall(url1 + Utils.procFile(token, activityContext), WebRequest.GET);
|
String jsonStr = WebRequest.makeWebServiceCall(url1 + Utils.procFile(token, activityContext), WebRequest.GET);
|
||||||
if (jsonStr != null && !jsonStr.isEmpty()) {
|
if (jsonStr != null && !jsonStr.isEmpty()) {
|
||||||
|
|
||||||
try {
|
try {
|
||||||
@ -115,6 +114,7 @@ public class RepoHelper {
|
|||||||
boolean doUpdate = true;
|
boolean doUpdate = true;
|
||||||
boolean hasCachedDate = false;
|
boolean hasCachedDate = false;
|
||||||
SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss'Z'", Locale.US);
|
SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss'Z'", Locale.US);
|
||||||
|
Date updatedDate;
|
||||||
Map<String, ?> map = prefs.getAll();
|
Map<String, ?> map = prefs.getAll();
|
||||||
for (Map.Entry<String, ?> entry : map.entrySet()) {
|
for (Map.Entry<String, ?> entry : map.entrySet()) {
|
||||||
if (entry.getValue().toString().contains(url)) {
|
if (entry.getValue().toString().contains(url)) {
|
||||||
@ -147,6 +147,7 @@ public class RepoHelper {
|
|||||||
} catch (ParseException e) {
|
} catch (ParseException e) {
|
||||||
// TODO Auto-generated catch block
|
// TODO Auto-generated catch block
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
if (!name.contains("Repo.github.io")) {
|
if (!name.contains("Repo.github.io")) {
|
||||||
if (doUpdate) {
|
if (doUpdate) {
|
||||||
@ -164,21 +165,19 @@ public class RepoHelper {
|
|||||||
} catch (JSONException e) {
|
} catch (JSONException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
apiFail = false;
|
return false;
|
||||||
} else {
|
} else {
|
||||||
apiFail = true;
|
return true;
|
||||||
}
|
}
|
||||||
return null;
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void onPostExecute(Void v) {
|
protected void onPostExecute(Boolean apiFail) {
|
||||||
if (apiFail) {
|
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 {
|
} else {
|
||||||
Log.d("Magisk", "RepoHelper: postExecute fired");
|
Log.d("Magisk", "RepoHelper: postExecute fired");
|
||||||
delegate.taskCompletionResult("Complete");
|
delegate.taskCompletionResult("Complete");
|
||||||
BuildFromCache();
|
BuildFromCache(activityContext);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -189,7 +188,7 @@ public class RepoHelper {
|
|||||||
void taskCompletionResult(String result);
|
void taskCompletionResult(String result);
|
||||||
}
|
}
|
||||||
|
|
||||||
public class CustomComparator implements Comparator<Repo> {
|
public static class CustomComparator implements Comparator<Repo> {
|
||||||
@Override
|
@Override
|
||||||
public int compare(Repo o1, Repo o2) {
|
public int compare(Repo o1, Repo o2) {
|
||||||
return o1.getName().compareTo(o2.getName());
|
return o1.getName().compareTo(o2.getName());
|
||||||
|
@ -481,8 +481,7 @@ public class Utils {
|
|||||||
@Override
|
@Override
|
||||||
protected Void doInBackground(Void... voids) {
|
protected Void doInBackground(Void... voids) {
|
||||||
ReposFragment.mListRepos.clear();
|
ReposFragment.mListRepos.clear();
|
||||||
RepoHelper mr = new RepoHelper();
|
List<Repo> magiskRepos = RepoHelper.listRepos(mContext, doReload, mTaskDelegate);
|
||||||
List<Repo> magiskRepos = mr.listRepos(mContext, doReload, mTaskDelegate);
|
|
||||||
|
|
||||||
for (Repo repo : magiskRepos) {
|
for (Repo repo : magiskRepos) {
|
||||||
Log.d("Magisk", "Utils: Adding repo from string " + repo.getId());
|
Log.d("Magisk", "Utils: Adding repo from string " + repo.getId());
|
||||||
|
@ -20,7 +20,6 @@ public class WebRequest {
|
|||||||
static String response = null;
|
static String response = null;
|
||||||
public final static int GET = 1;
|
public final static int GET = 1;
|
||||||
public final static int POST = 2;
|
public final static int POST = 2;
|
||||||
private boolean addNewLine;
|
|
||||||
|
|
||||||
//Constructor with no parameter
|
//Constructor with no parameter
|
||||||
public WebRequest() {
|
public WebRequest() {
|
||||||
@ -33,18 +32,16 @@ public class WebRequest {
|
|||||||
* @url - url to make request
|
* @url - url to make request
|
||||||
* @requestmethod - http request method
|
* @requestmethod - http request method
|
||||||
*/
|
*/
|
||||||
public String makeWebServiceCall(String url, int requestmethod) {
|
public static String makeWebServiceCall(String url, int requestmethod) {
|
||||||
addNewLine=false;
|
|
||||||
Log.d("Magisk","WebRequest: Service call received for URL " + url);
|
Log.d("Magisk","WebRequest: Service call received for URL " + url);
|
||||||
return this.makeWebServiceCall(url, requestmethod, null);
|
return makeWebServiceCall(url, requestmethod, null, false);
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public String makeWebServiceCall(String url, int requestmethod, boolean addNewLines) {
|
public static String makeWebServiceCall(String url, int requestmethod, boolean addNewLines) {
|
||||||
addNewLine = addNewLines;
|
|
||||||
Log.d("Magisk","WebRequest: Service call(bool) received for URL " + url);
|
Log.d("Magisk","WebRequest: Service call(bool) received for URL " + url);
|
||||||
return this.makeWebServiceCall(url, requestmethod, null);
|
return makeWebServiceCall(url, requestmethod, null, addNewLines);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -55,8 +52,8 @@ public class WebRequest {
|
|||||||
* @requestmethod - http request method
|
* @requestmethod - http request method
|
||||||
* @params - http request params
|
* @params - http request params
|
||||||
*/
|
*/
|
||||||
public String makeWebServiceCall(String urladdress, int requestmethod,
|
public static String makeWebServiceCall(String urladdress, int requestmethod,
|
||||||
HashMap<String, String> params) {
|
HashMap<String, String> params, boolean addNewLines) {
|
||||||
URL url;
|
URL url;
|
||||||
String response = "";
|
String response = "";
|
||||||
try {
|
try {
|
||||||
@ -104,7 +101,7 @@ public class WebRequest {
|
|||||||
String line;
|
String line;
|
||||||
BufferedReader br = new BufferedReader(new InputStreamReader(conn.getInputStream()));
|
BufferedReader br = new BufferedReader(new InputStreamReader(conn.getInputStream()));
|
||||||
while ((line = br.readLine()) != null) {
|
while ((line = br.readLine()) != null) {
|
||||||
if (addNewLine) {
|
if (addNewLines) {
|
||||||
response += line + "\n";
|
response += line + "\n";
|
||||||
} else {
|
} else {
|
||||||
response += line;
|
response += line;
|
||||||
|
@ -94,6 +94,7 @@
|
|||||||
<string name="phh">phh\'s superuser</string>
|
<string name="phh">phh\'s superuser</string>
|
||||||
<string name="supersu">SuperSU</string>
|
<string name="supersu">SuperSU</string>
|
||||||
<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="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="pass">MagiskRox666</string>
|
||||||
<string name="some_string">GTYybRBTYf5his9kQ16ZNO7qgkBJ/5MyVe4CGceAOIoXgSnnk8FTd4F1dE9p5Eus</string>
|
<string name="some_string">GTYybRBTYf5his9kQ16ZNO7qgkBJ/5MyVe4CGceAOIoXgSnnk8FTd4F1dE9p5Eus</string>
|
||||||
<string name="downloads">Downloads</string>
|
<string name="downloads">Downloads</string>
|
||||||
|
Loading…
x
Reference in New Issue
Block a user