Looking good...

This commit is contained in:
d8ahazard
2016-09-09 16:49:25 -05:00
parent 214649ec20
commit 1a1d37a2d0
10 changed files with 464 additions and 152 deletions
@@ -29,7 +29,7 @@ public class RepoHelper {
private static final String TAG_ID = "id";
private static final String TAG_NAME = "name";
private static String TAG = "Magisk";
private String mName,mId,mUrl;
private String mName, mId, mUrl;
private Context activityContext;
private Date updatedDate, currentDate;
private SharedPreferences prefs;
@@ -44,35 +44,7 @@ public class RepoHelper {
List<String> out = null;
} else {
Log.d(TAG, "RepoHelper: Building from cache");
repos.clear();
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) {
String[] splitStrings = string.split("=");
switch(splitStrings[0]) {
case ("id"):
mId = splitStrings[1];
break;
case ("baseUrl"):
mUrl = splitStrings[1];
break;
default:
break;
}
}
Log.d("Magisk","RepoHelper: adding repo with id of " + mId);
repos.add(new Repo(repoString,activityContext));
}
}
BuildFromCache();
}
@@ -81,6 +53,37 @@ public class RepoHelper {
return repos;
}
private void BuildFromCache() {
repos.clear();
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) {
String[] splitStrings = string.split("=");
switch (splitStrings[0]) {
case ("id"):
mId = splitStrings[1];
break;
case ("baseUrl"):
mUrl = splitStrings[1];
break;
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> {
@@ -105,9 +108,9 @@ 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);
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()) {
if (jsonStr != null && !jsonStr.isEmpty()) {
try {
repos.clear();
@@ -185,7 +188,9 @@ public class RepoHelper {
protected void onPostExecute(Void v) {
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 {
BuildFromCache();
}
} // protected void onPostExecute(Void v)