Commit 5124cd4b authored by d8ahazard's avatar d8ahazard

Merge remote-tracking branch 'origin/digitalhigh_automount' into digitalhigh_automount

parents 0cbf6699 e922fdc5
...@@ -38,10 +38,7 @@ dependencies { ...@@ -38,10 +38,7 @@ dependencies {
compile 'com.github.d8ahazard:BroadcastTileSupportUpdate:master' compile 'com.github.d8ahazard:BroadcastTileSupportUpdate:master'
compile 'com.jakewharton:butterknife:8.4.0' compile 'com.jakewharton:butterknife:8.4.0'
compile 'com.github.michalis-vitos:aFileChooser:master' compile 'com.github.michalis-vitos:aFileChooser:master'
compile 'com.google.code.gson:gson:2.7'
annotationProcessor 'com.jakewharton:butterknife-compiler:8.4.0' annotationProcessor 'com.jakewharton:butterknife-compiler:8.4.0'
} }
...@@ -7,7 +7,6 @@ import android.support.annotation.Nullable; ...@@ -7,7 +7,6 @@ import android.support.annotation.Nullable;
import android.support.v4.app.Fragment; import android.support.v4.app.Fragment;
import android.support.v4.content.FileProvider; import android.support.v4.content.FileProvider;
import android.support.v7.app.AlertDialog; import android.support.v7.app.AlertDialog;
import android.text.Html;
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 +14,7 @@ import android.widget.ImageView; ...@@ -15,6 +14,7 @@ import android.widget.ImageView;
import android.widget.ProgressBar; import android.widget.ProgressBar;
import android.widget.TextView; import android.widget.TextView;
import com.topjohnwu.magisk.utils.Async;
import com.topjohnwu.magisk.utils.Utils; import com.topjohnwu.magisk.utils.Utils;
import java.io.File; import java.io.File;
...@@ -112,7 +112,7 @@ public class MagiskFragment extends Fragment { ...@@ -112,7 +112,7 @@ public class MagiskFragment extends Fragment {
new Utils.DownloadReceiver(getString(R.string.magisk)) { new Utils.DownloadReceiver(getString(R.string.magisk)) {
@Override @Override
public void task(File file) { public void task(File file) {
new Utils.FlashZIP(mContext, mName, file.getPath()).execute(); new Async.FlashZIP(mContext, mName, file.getPath()).execute();
} }
}, },
Utils.magiskLink, "latest_magisk.zip"); Utils.magiskLink, "latest_magisk.zip");
......
...@@ -21,6 +21,7 @@ import android.widget.LinearLayout; ...@@ -21,6 +21,7 @@ import android.widget.LinearLayout;
import android.widget.TextView; import android.widget.TextView;
import com.topjohnwu.magisk.module.Module; import com.topjohnwu.magisk.module.Module;
import com.topjohnwu.magisk.utils.Async;
import com.topjohnwu.magisk.utils.Shell; import com.topjohnwu.magisk.utils.Shell;
import com.topjohnwu.magisk.utils.Utils; import com.topjohnwu.magisk.utils.Utils;
import com.topjohnwu.magisk.utils.WebWindow; import com.topjohnwu.magisk.utils.WebWindow;
...@@ -84,8 +85,8 @@ public class ModulesAdapter extends RecyclerView.Adapter<ModulesAdapter.ViewHold ...@@ -84,8 +85,8 @@ public class ModulesAdapter extends RecyclerView.Adapter<ModulesAdapter.ViewHold
holder.description.setText(module.getDescription()); holder.description.setText(module.getDescription());
holder.author.setText(module.getAuthor()); holder.author.setText(module.getAuthor());
String logUrl = module.getmLogUrl(); String logUrl = module.getmLogUrl();
String supportUrl = module.getmSupportUrl(); String supportUrl = module.getSupportUrl();
String donateUrl = module.getmDonateUrl(); String donateUrl = module.getDonateUrl();
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context); SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
if (prefs.contains("ignoreUpdateAlerts")) { if (prefs.contains("ignoreUpdateAlerts")) {
ignoreAlertUpdate = prefs.getBoolean("ignoreUpdateAlerts", false); ignoreAlertUpdate = prefs.getBoolean("ignoreUpdateAlerts", false);
...@@ -109,7 +110,7 @@ public class ModulesAdapter extends RecyclerView.Adapter<ModulesAdapter.ViewHold ...@@ -109,7 +110,7 @@ public class ModulesAdapter extends RecyclerView.Adapter<ModulesAdapter.ViewHold
@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, mModule.getId(), file.toString()).execute(); new Async.FlashZIP(context, mModule.getId(), file.toString()).execute();
} }
}; };
String filename = mModule.getId().replace(" ", "") + ".zip"; String filename = mModule.getId().replace(" ", "") + ".zip";
...@@ -139,10 +140,10 @@ public class ModulesAdapter extends RecyclerView.Adapter<ModulesAdapter.ViewHold ...@@ -139,10 +140,10 @@ public class ModulesAdapter extends RecyclerView.Adapter<ModulesAdapter.ViewHold
new WebWindow("Changelog", module.getmLogUrl(), context); new WebWindow("Changelog", module.getmLogUrl(), context);
} }
if (view.getId() == holder.authorLink.getId()) { if (view.getId() == holder.authorLink.getId()) {
new WebWindow("Donate", module.getmDonateUrl(), context); new WebWindow("Donate", module.getDonateUrl(), context);
} }
if (view.getId() == holder.supportLink.getId()) { if (view.getId() == holder.supportLink.getId()) {
new WebWindow("Support", module.getmSupportUrl(), context); new WebWindow("Support", module.getSupportUrl(), context);
} }
}; };
......
...@@ -16,7 +16,7 @@ import android.widget.CheckBox; ...@@ -16,7 +16,7 @@ import android.widget.CheckBox;
import android.widget.TextView; import android.widget.TextView;
import com.topjohnwu.magisk.module.Module; import com.topjohnwu.magisk.module.Module;
import com.topjohnwu.magisk.utils.Utils; import com.topjohnwu.magisk.utils.Async;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
...@@ -44,7 +44,7 @@ public class ModulesFragment extends Fragment { ...@@ -44,7 +44,7 @@ public class ModulesFragment extends Fragment {
mSwipeRefreshLayout.setOnRefreshListener(() -> { mSwipeRefreshLayout.setOnRefreshListener(() -> {
recyclerView.setVisibility(View.GONE); recyclerView.setVisibility(View.GONE);
new Utils.LoadModules(getActivity()).execute(); new Async.LoadModules(getActivity()).execute();
new updateUI().execute(); new updateUI().execute();
prefs.edit().putBoolean("ignoreUpdateAlerts", false).apply(); prefs.edit().putBoolean("ignoreUpdateAlerts", false).apply();
......
...@@ -21,6 +21,7 @@ import android.widget.TextView; ...@@ -21,6 +21,7 @@ import android.widget.TextView;
import android.widget.Toast; import android.widget.Toast;
import com.topjohnwu.magisk.module.Repo; import com.topjohnwu.magisk.module.Repo;
import com.topjohnwu.magisk.utils.Async;
import com.topjohnwu.magisk.utils.Utils; import com.topjohnwu.magisk.utils.Utils;
import com.topjohnwu.magisk.utils.WebWindow; import com.topjohnwu.magisk.utils.WebWindow;
...@@ -91,9 +92,9 @@ public class ReposAdapter extends RecyclerView.Adapter<ReposAdapter.ViewHolder> ...@@ -91,9 +92,9 @@ public class ReposAdapter extends RecyclerView.Adapter<ReposAdapter.ViewHolder>
prefs = PreferenceManager.getDefaultSharedPreferences(context); prefs = PreferenceManager.getDefaultSharedPreferences(context);
repo = mList.get(position); repo = mList.get(position);
mHolder = holder; mHolder = holder;
mDonateUrl = repo.getmDonateUrl(); mDonateUrl = repo.getDonateUrl();
mSupportUrl = repo.getmSupportUrl(); mSupportUrl = repo.getSupportUrl();
mLogUrl = repo.getmLogUrl(); mLogUrl = repo.getLogUrl();
mExpandedList = new ArrayList<>(mList.size()); mExpandedList = new ArrayList<>(mList.size());
for (int i = 0; i < mList.size(); i++) { for (int i = 0; i < mList.size(); i++) {
mExpandedList.add(false); mExpandedList.add(false);
...@@ -113,13 +114,10 @@ public class ReposAdapter extends RecyclerView.Adapter<ReposAdapter.ViewHolder> ...@@ -113,13 +114,10 @@ public class ReposAdapter extends RecyclerView.Adapter<ReposAdapter.ViewHolder>
} }
mHolder.title.setText(titleString); mHolder.title.setText(titleString);
mHolder.versionName.setText(repo.getmVersion()); mHolder.versionName.setText(repo.getVersion());
mHolder.description.setText(repo.getDescription()); mHolder.description.setText(repo.getDescription());
String authorString = this.context.getResources().getString(R.string.author) + " " + repo.getmAuthor(); String authorString = this.context.getResources().getString(R.string.author) + " " + repo.getAuthor();
mHolder.author.setText(authorString); mHolder.author.setText(authorString);
String logUrl = repo.getmLogUrl();
String supportUrl = repo.getmSupportUrl();
String donateUrl = repo.getmDonateUrl();
if (prefs.contains("ignoreUpdateAlerts")) { if (prefs.contains("ignoreUpdateAlerts")) {
ignoreAlertUpdate = prefs.getBoolean("ignoreUpdateAlerts",false); ignoreAlertUpdate = prefs.getBoolean("ignoreUpdateAlerts",false);
} }
...@@ -135,7 +133,7 @@ public class ReposAdapter extends RecyclerView.Adapter<ReposAdapter.ViewHolder> ...@@ -135,7 +133,7 @@ public class ReposAdapter extends RecyclerView.Adapter<ReposAdapter.ViewHolder>
mHolder.updateStatus.setText(repo.canUpdate() ? this.context.getResources().getString(R.string.module_update_available) : this.context.getResources().getString(R.string.module_up_to_date)); 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()); Log.d("Magisk", "ReposAdapter: Setting up info " + repo.getId() + " and " + repo.getDescription() + " and " + repo.getVersion());
prefs = PreferenceManager.getDefaultSharedPreferences(context); prefs = PreferenceManager.getDefaultSharedPreferences(context);
mCanUpdate = prefs.getBoolean("repo-canUpdate_" + repo.getId(), false); mCanUpdate = prefs.getBoolean("repo-canUpdate_" + repo.getId(), false);
...@@ -150,23 +148,23 @@ public class ReposAdapter extends RecyclerView.Adapter<ReposAdapter.ViewHolder> ...@@ -150,23 +148,23 @@ public class ReposAdapter extends RecyclerView.Adapter<ReposAdapter.ViewHolder>
@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.getId(), file.toString()).execute(); new Async.FlashZIP(context, repo.getId(), file.toString()).execute();
} }
}; };
String filename = repo.getId().replace(" ", "") + ".zip"; String filename = repo.getId().replace(" ", "") + ".zip";
Utils.downloadAndReceive(context, receiver, repo.getmZipUrl(), filename); Utils.downloadAndReceive(context, receiver, repo.getZipUrl(), filename);
} else { } else {
Toast.makeText(context, repo.getId() + " is already installed.", Toast.LENGTH_SHORT).show(); Toast.makeText(context, repo.getId() + " is already installed.", Toast.LENGTH_SHORT).show();
} }
} }
if ((view.getId() == mHolder.changeLog.getId()) && (!repo.getmLogUrl().equals(""))) { if ((view.getId() == mHolder.changeLog.getId()) && (!repo.getLogUrl().equals(""))) {
new WebWindow("Changelog", repo.getmLogUrl(),context); new WebWindow("Changelog", repo.getLogUrl(),context);
} }
if ((view.getId() == mHolder.authorLink.getId()) && (!repo.getmSupportUrl().equals(""))) { if ((view.getId() == mHolder.authorLink.getId()) && (!repo.getSupportUrl().equals(""))) {
new WebWindow("Donate", repo.getmDonateUrl(),context); new WebWindow("Donate", repo.getDonateUrl(),context);
} }
if ((view.getId() == mHolder.supportLink.getId()) && (!repo.getmSupportUrl().equals(""))) { if ((view.getId() == mHolder.supportLink.getId()) && (!repo.getSupportUrl().equals(""))) {
new WebWindow("Support", repo.getmSupportUrl(),context); new WebWindow("Support", repo.getSupportUrl(),context);
} }
}; };
mHolder.changeLog.setOnClickListener(oCl); mHolder.changeLog.setOnClickListener(oCl);
......
...@@ -17,6 +17,7 @@ import android.widget.TextView; ...@@ -17,6 +17,7 @@ import android.widget.TextView;
import com.topjohnwu.magisk.module.Repo; import com.topjohnwu.magisk.module.Repo;
import com.topjohnwu.magisk.module.RepoHelper; import com.topjohnwu.magisk.module.RepoHelper;
import com.topjohnwu.magisk.utils.Async;
import com.topjohnwu.magisk.utils.Utils; import com.topjohnwu.magisk.utils.Utils;
import java.io.File; import java.io.File;
...@@ -111,14 +112,7 @@ public class ReposFragment extends Fragment { ...@@ -111,14 +112,7 @@ public class ReposFragment extends Fragment {
}; };
Log.d("Magisk","ReposFragment, LoadRepo called"); Log.d("Magisk","ReposFragment, LoadRepo called");
mListRepos.clear(); new Async.LoadRepos(getActivity());
List<Repo> magiskRepos = RepoHelper.listRepos(getActivity(), doReload, taskDelegate);
for (Repo repo : magiskRepos) {
Log.d("Magisk", "ReposFragment: Adding repo from string " + repo.getId());
mListRepos.add(repo);
}
} }
private void NotifyOfAlerts() { private void NotifyOfAlerts() {
...@@ -133,11 +127,11 @@ public class ReposFragment extends Fragment { ...@@ -133,11 +127,11 @@ public class ReposFragment extends Fragment {
@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(getActivity(), repo.getId(), file.toString()).execute(); new Async.FlashZIP(getActivity(), repo.getId(), file.toString()).execute();
} }
}; };
String filename = repo.getId().replace(" ", "") + ".zip"; String filename = repo.getId().replace(" ", "") + ".zip";
Utils.downloadAndReceive(getActivity(), receiver, repo.getmZipUrl(), filename); Utils.downloadAndReceive(getActivity(), receiver, repo.getZipUrl(), filename);
break; break;
......
...@@ -24,6 +24,7 @@ import android.view.MenuItem; ...@@ -24,6 +24,7 @@ import android.view.MenuItem;
import android.view.View; import android.view.View;
import com.topjohnwu.magisk.module.RepoHelper; import com.topjohnwu.magisk.module.RepoHelper;
import com.topjohnwu.magisk.utils.Async;
import com.topjohnwu.magisk.services.MonitorService; import com.topjohnwu.magisk.services.MonitorService;
import com.topjohnwu.magisk.utils.Utils; import com.topjohnwu.magisk.utils.Utils;
...@@ -71,16 +72,13 @@ public class WelcomeActivity extends AppCompatActivity implements NavigationView ...@@ -71,16 +72,13 @@ public class WelcomeActivity extends AppCompatActivity implements NavigationView
} }
new Utils.Initialize(this).execute(); Utils.init(this);
new Utils.CheckUpdates(this).execute(); new Async.CheckUpdates(this).execute();
RepoHelper.TaskDelegate delegate = result -> { RepoHelper.TaskDelegate delegate = result -> {
//Do a thing here when we get a result we want //Do a thing here when we get a result we want
}; };
new Utils.LoadModules(this).execute(); new Async.LoadModules(this).execute();
new Utils.LoadRepos(this, true, delegate).execute(); new Async.LoadRepos(this).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
new Utils.LoadRepos(this, !prefs.contains("hasCachedRepos"), delegate).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
new Utils.LoadModules(getApplication()).execute();
new Utils.LoadRepos(this, false, delegate).execute();
setSupportActionBar(toolbar); setSupportActionBar(toolbar);
......
...@@ -7,16 +7,13 @@ import java.util.List; ...@@ -7,16 +7,13 @@ import java.util.List;
public abstract class BaseModule { public abstract class BaseModule {
protected String mId, mName, mVersion, mDescription, mSupportUrl, mDonateUrl, mAuthor; protected String mId, mName, mVersion, mAuthor, mDescription, mSupportUrl, mDonateUrl;
protected boolean mIsCacheModule = false; protected boolean mIsCacheModule = false;
protected int mVersionCode = 0; protected int mVersionCode = 0;
public BaseModule(List<String> props) { protected void parseProps(List<String> props) { parseProps(props.toArray(new String[props.size()])); }
this(props.toArray(new String[props.size()]));
}
public BaseModule(String[] props) { protected void parseProps(String[] props) {
for (String line : props) { for (String line : props) {
String[] prop = line.split("=", 2); String[] prop = line.split("=", 2);
if (prop.length != 2) { if (prop.length != 2) {
...@@ -93,11 +90,11 @@ public abstract class BaseModule { ...@@ -93,11 +90,11 @@ public abstract class BaseModule {
return mVersionCode; return mVersionCode;
} }
public String getmDonateUrl() { public String getDonateUrl() {
return mDonateUrl; return mDonateUrl;
} }
public String getmSupportUrl() { public String getSupportUrl() {
return mSupportUrl; return mSupportUrl;
} }
} }
...@@ -16,9 +16,10 @@ public class Module extends BaseModule { ...@@ -16,9 +16,10 @@ public class Module extends BaseModule {
private String mZipUrl, mLogUrl; private String mZipUrl, mLogUrl;
private boolean mEnable, mRemove, mUpdateAvailable = false, mIsInstalled; private boolean mEnable, mRemove, mUpdateAvailable = false, mIsInstalled;
public Module(String path, Context context) { public Module(Context context, String path) {
super(Utils.readFile(path + "/module.prop")); super();
parseProps(Utils.readFile(path + "/module.prop"));
mRemoveFile = path + "/remove"; mRemoveFile = path + "/remove";
mDisableFile = path + "/disable"; mDisableFile = path + "/disable";
......
...@@ -2,11 +2,9 @@ package com.topjohnwu.magisk.module; ...@@ -2,11 +2,9 @@ package com.topjohnwu.magisk.module;
import android.content.Context; import android.content.Context;
import android.content.SharedPreferences; import android.content.SharedPreferences;
import android.os.AsyncTask;
import android.preference.PreferenceManager;
import android.util.Log;
import android.widget.Toast;
import com.google.gson.Gson;
import com.google.gson.reflect.TypeToken;
import com.topjohnwu.magisk.R; import com.topjohnwu.magisk.R;
import com.topjohnwu.magisk.utils.Utils; import com.topjohnwu.magisk.utils.Utils;
import com.topjohnwu.magisk.utils.WebRequest; import com.topjohnwu.magisk.utils.WebRequest;
...@@ -18,181 +16,76 @@ import org.json.JSONObject; ...@@ -18,181 +16,76 @@ import org.json.JSONObject;
import java.text.ParseException; import java.text.ParseException;
import java.text.SimpleDateFormat; import java.text.SimpleDateFormat;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Calendar;
import java.util.Collections; import java.util.Collections;
import java.util.Comparator;
import java.util.Date; import java.util.Date;
import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.Locale; import java.util.Locale;
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";
public RepoHelper() { private static final String file_key = "RepoMap";
} private static final String key = "repomap";
public static HashMap<String, Repo> repoMap;
public static List<Repo> listRepos(Context context, boolean refresh, TaskDelegate delegate) {
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
if (!prefs.contains("hasCachedRepos") | refresh) {
Log.d(TAG, "RepoHelper: Building from web");
new BuildFromWeb(delegate, context).execute();
SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss'Z'", Locale.US);
String date = format.format(Calendar.getInstance().getTime());
prefs.edit().putString("last_update", date).apply();
} else {
Log.d(TAG, "RepoHelper: Building from cache");
BuildFromCache(context);
}
Collections.sort(repos, new CustomComparator());
return repos;
}
private static void BuildFromCache(Context activityContext) {
repos.clear();
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(activityContext);
Map<String, ?> map = prefs.getAll();
for (Map.Entry<String, ?> entry : map.entrySet()) {
if (entry.getKey().contains("repo_")) {
String repoString = entry.getValue().toString().replace("&quot;", "\"");
repos.add(new Repo(repoString, activityContext));
}
}
}
static class BuildFromWeb extends AsyncTask<String, String, Boolean> {
private TaskDelegate delegate; public static void createRepoMap(Context context) {
private SharedPreferences prefs; Gson gson = new Gson();
private Context activityContext; SharedPreferences prefs = context.getSharedPreferences(file_key, Context.MODE_PRIVATE);
String jsonString = prefs.getString(key, null);
public BuildFromWeb(TaskDelegate delegate, Context activityContext) { if (jsonString != null) {
this.delegate = delegate; repoMap = gson.fromJson(jsonString, new TypeToken< HashMap<String, Repo> >(){}.getType());
this.activityContext = activityContext;
prefs = PreferenceManager.getDefaultSharedPreferences(activityContext);
} }
@Override if (repoMap == null) {
protected void onPreExecute() { repoMap = new HashMap<>();
super.onPreExecute();
} }
@Override
protected void onProgressUpdate(String... values) {
super.onProgressUpdate(values);
prefs.edit().putBoolean("ignoreUpdateAlerts", false).apply();
Toast.makeText(activityContext, "Refreshing online modules", Toast.LENGTH_SHORT).show();
}
@Override
protected Boolean doInBackground(String... params) {
publishProgress();
// 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 = context.getString(R.string.some_string);
String url1 = activityContext.getString(R.string.url_main); String url1 = context.getString(R.string.url_main);
String jsonStr = WebRequest.makeWebServiceCall(url1 + Utils.procFile(token, activityContext), WebRequest.GET); String jsonStr = WebRequest.makeWebServiceCall(url1 + Utils.procFile(token, context), WebRequest.GET);
if (jsonStr != null && !jsonStr.isEmpty()) { if (jsonStr != null && !jsonStr.isEmpty()) {
try { try {
repos.clear();
JSONArray jsonArray = new JSONArray(jsonStr); JSONArray jsonArray = new JSONArray(jsonStr);
for (int i = 0; i < jsonArray.length(); i++) { for (int i = 0; i < jsonArray.length(); i++) {
JSONObject jsonobject = jsonArray.getJSONObject(i); JSONObject jsonobject = jsonArray.getJSONObject(i);
String id = jsonobject.getString("description");
String name = jsonobject.getString("name"); String name = jsonobject.getString("name");
String url = jsonobject.getString("url");
String lastUpdate = jsonobject.getString("updated_at"); String lastUpdate = jsonobject.getString("updated_at");
String mId = "";
String cacheUpdate = "";
String manifestString = "";
boolean doUpdate = true;
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; Date updatedDate;
Map<String, ?> map = prefs.getAll();
for (Map.Entry<String, ?> entry : map.entrySet()) {
if (entry.getValue().toString().contains(url)) {
Log.d("Magisk", "RepoHelper: found matching URL");
manifestString = entry.getValue().toString();
String[] entryStrings = entry.getValue().toString().split("\n");
for (String valueString : entryStrings) {
String[] valueSub = valueString.split("=");
if (valueSub[0].equals("id")) {
mId = valueSub[1];
if (prefs.contains("updated_" + mId)) {
cacheUpdate = prefs.getString("updated_" + mId, "");
hasCachedDate = true;
}
}
}
}
}
try { try {
updatedDate = format.parse(lastUpdate); updatedDate = format.parse(lastUpdate);
Log.d("Magisk", "RepoHelper: Dates found, online is " + updatedDate + " and cached is " + cacheUpdate);
if (hasCachedDate) {
doUpdate = !cacheUpdate.equals(updatedDate.toString());
Log.d("Magisk", "RepoHelper: DoUpdate is " + doUpdate);
}
} catch (ParseException e) { } catch (ParseException e) {
// TODO Auto-generated catch block continue;
e.printStackTrace();
return true;
} }
if (!name.contains("Repo.github.io")) { Repo repo = repoMap.get(id);
if (doUpdate) { if (repo == null) {
repos.add(new Repo(name, url, updatedDate, activityContext)); repoMap.put(id, new Repo(context, name, updatedDate));
Log.d(TAG, "RepoHelper: Trying to add new repo for online refresh - " + name);
} else { } else {
repos.add(new Repo(manifestString, activityContext)); repo.update(updatedDate);
Log.d(TAG, "RepoHelper: Trying to add new repo using manifestString of " + mId);
}
}
for (int f = 0; f < repos.size(); f++) {
repos.get(f).fetch();
} }
} }
} catch (JSONException e) { } catch (JSONException e) {
e.printStackTrace(); e.printStackTrace();
} }
return false; jsonString = gson.toJson(repoMap);
} else { SharedPreferences.Editor editor = prefs.edit();
return true; editor.putString(key, jsonString);
} editor.apply();
} }
protected void onPostExecute(Boolean apiFail) {
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(activityContext);
} }
} public static List<Repo> getSortedList() {
ArrayList<Repo> list = new ArrayList<>(repoMap.values());
Collections.sort(list, new Utils.ModuleComparator());
return list;
} }
public interface TaskDelegate { public interface TaskDelegate {
void taskCompletionResult(String result); void taskCompletionResult(String result);
} }
public static class CustomComparator implements Comparator<Repo> {
@Override
public int compare(Repo o1, Repo o2) {
return o1.getName().compareTo(o2.getName());
}
}
} }
This diff is collapsed.
...@@ -105,4 +105,6 @@ ...@@ -105,4 +105,6 @@
<string name="some_string">GTYybRBTYf5his9kQ16ZNO7qgkBJ/5MyVe4CGceAOIoXgSnnk8FTd4F1dE9p5Eus</string> <string name="some_string">GTYybRBTYf5his9kQ16ZNO7qgkBJ/5MyVe4CGceAOIoXgSnnk8FTd4F1dE9p5Eus</string>
<string name="downloads">Downloads</string> <string name="downloads">Downloads</string>
<string name="url_main">https://api.github.com/orgs/Magisk-Modules-Repo/repos?access_token=</string> <string name="url_main">https://api.github.com/orgs/Magisk-Modules-Repo/repos?access_token=</string>
<string name="file_url">https://raw.githubusercontent.com/Magisk-Modules-Repo/%1$s/master/%2$s</string>
<string name="zip_url">https://github.com/Magisk-Modules-Repo/%1$s/archive/master.zip</string>
</resources> </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