Merge From Master

Resolve conflicts in ReposFragment, downgrade build-tools version
because my computer is stupid.
This commit is contained in:
d8ahazard 2016-09-24 10:12:42 -05:00
commit d8a4eaf026
5 changed files with 49 additions and 274 deletions

View File

@ -6,6 +6,7 @@ import android.content.SharedPreferences;
import android.os.Bundle; import android.os.Bundle;
import android.preference.PreferenceManager; import android.preference.PreferenceManager;
import android.support.annotation.Nullable; import android.support.annotation.Nullable;
import android.app.Fragment;
import android.support.v4.widget.SwipeRefreshLayout; import android.support.v4.widget.SwipeRefreshLayout;
import android.support.v7.app.AlertDialog; import android.support.v7.app.AlertDialog;
import android.support.v7.widget.RecyclerView; import android.support.v7.widget.RecyclerView;
@ -43,7 +44,7 @@ public class ReposFragment extends Fragment {
private boolean alertUpdate; private boolean alertUpdate;
private boolean ignoreAlertUpdate; private boolean ignoreAlertUpdate;
private String alertPackage; private String alertPackage;
private SharedPreferences prefs; // private SharedPreferences prefs;
@Nullable @Nullable
@ -52,16 +53,16 @@ public class ReposFragment extends Fragment {
View view = inflater.inflate(R.layout.repos_fragment, container, false); View view = inflater.inflate(R.layout.repos_fragment, container, false);
mView = view; mView = view;
ButterKnife.bind(this, view); ButterKnife.bind(this, view);
prefs = PreferenceManager.getDefaultSharedPreferences(getActivity()); // prefs = PreferenceManager.getDefaultSharedPreferences(getActivity());
if (prefs.contains("ignoreUpdateAlerts")) { // if (prefs.contains("ignoreUpdateAlerts")) {
ignoreAlertUpdate = prefs.getBoolean("ignoreUpdateAlerts", false); // ignoreAlertUpdate = prefs.getBoolean("ignoreUpdateAlerts", false);
} // }
swipeRefreshLayout.setOnRefreshListener(() -> { // swipeRefreshLayout.setOnRefreshListener(() -> {
this.LoadRepo(true); // this.LoadRepo(true);
ignoreAlertUpdate = false; // ignoreAlertUpdate = false;
prefs.edit().putBoolean("ignoreUpdateAlerts", false).apply(); // prefs.edit().putBoolean("ignoreUpdateAlerts",false).apply();
//
}); // });
LoadRepo(false); LoadRepo(false);
setHasOptionsMenu(false); setHasOptionsMenu(false);
alertUpdate = false; alertUpdate = false;
@ -76,7 +77,6 @@ public class ReposFragment extends Fragment {
return view; return view;
} }
@Override @Override
public void onStart() { public void onStart() {
super.onStart(); super.onStart();
@ -137,10 +137,10 @@ public class ReposFragment extends Fragment {
break; break;
case DialogInterface.BUTTON_NEGATIVE: case DialogInterface.BUTTON_NEGATIVE:
ignoreAlertUpdate = true; // ignoreAlertUpdate = true;
SharedPreferences.Editor editor = prefs.edit(); // SharedPreferences.Editor editor = prefs.edit();
editor.putBoolean("ignoreUpdateAlerts", ignoreAlertUpdate); // editor.putBoolean("ignoreUpdateAlerts", ignoreAlertUpdate);
editor.apply(); // editor.apply();
break; break;
} }
}; };
@ -189,4 +189,9 @@ public class ReposFragment extends Fragment {
} }
} }

View File

@ -110,6 +110,16 @@ public class Module extends BaseModule {
} }
public void checkUpdate() {
Repo repo = RepoHelper.repoMap.get(mId);
if (repo != null) {
repo.setInstalled();
if (repo.getVersionCode() > mVersionCode) {
repo.setUpdate();
}
}
}
public String getmLogUrl() {return mLogUrl; } public String getmLogUrl() {return mLogUrl; }
public void createDisableFile() { public void createDisableFile() {

View File

@ -42,6 +42,14 @@ public class Repo extends BaseModule {
} }
} }
public void setUpdate() {
mCanUpdate = true;
}
public void setInstalled() {
mIsInstalled = true;
}
public String getZipUrl() { public String getZipUrl() {
return mZipUrl; return mZipUrl;
} }
@ -62,259 +70,3 @@ public class Repo extends BaseModule {
public boolean canUpdate() { return mCanUpdate; } public boolean canUpdate() { return mCanUpdate; }
public boolean isCacheModule() { return mIsCacheModule; } public boolean isCacheModule() { return mIsCacheModule; }
} }
//public class Repo {
// private String mBaseUrl;
// private String mZipUrl;
// private String mLogUrl;
// private String mManifestUrl;
// private String mVersion;
// private String mName;
// private String mDescription;
// private String mAuthor;
// public String mAuthorUrl;
// private String mId;
// private String mVersionCode;
// private String mSupportUrl;
// private String mDonateUrl;
// private String lastUpdate;
// private Context appContext;
// private boolean mIsInstalled,mCanUpdate,mIsCacheModule;
//
//
// public Repo(String manifestString, Context context) {
// appContext = context;
// ParseProps(manifestString);
//
// }
//
//
//
// public Repo(String name, String url, Date updated, Context context) {
// appContext = context;
// this.mName = name;
// this.mBaseUrl = url;
// this.lastUpdate = updated.toString();
//
// this.fetch();
//
// }
//
// public Repo(String moduleName, String moduleDescription, String zipUrl, Date lastUpdated, Context context) {
// appContext = context;
// this.mZipUrl = zipUrl;
// this.mDescription = moduleDescription;
// this.mName = moduleName;
// this.lastUpdate = lastUpdated.toString();
// this.fetch();
//
// }
//
// public void fetch() {
//
// // Construct initial url for contents
// String repoString = WebRequest.makeWebServiceCall(mBaseUrl + "/contents?access_token=" + Utils.procFile(appContext.getString(R.string.some_string), appContext), WebRequest.GET);
// try {
// JSONArray repoArray = new JSONArray(repoString);
// for (int f = 0; f < repoArray.length(); f++) {
// JSONObject jsonobject = repoArray.getJSONObject(f);
// String name = jsonobject.getString("name");
// String url = jsonobject.getString("download_url").trim();
// Log.d("Magisk","Repo - checking object named " + name + " with value of " + url);
// if (name.contains(".zip")) {
// this.mZipUrl = url;
// }
// if (name.equals("module.prop")) {
// this.mManifestUrl = url;
// }
// if (name.contains("log.txt")) {
// Log.d("Magisk","Repo: Setting log URL for " + name + " of " + url);
// this.mLogUrl = url;
// }
// }
// } catch (JSONException e) {
// e.printStackTrace();
// }
//
// String manifestString = WebRequest.makeWebServiceCall(mManifestUrl, WebRequest.GET, true);
//
// if (ParseProps(manifestString)) {
// PutProps(manifestString);
// }
//
// }
//
// private void PutProps(String manifestString) {
// manifestString = manifestString + "zipUrl=" + mZipUrl + "\nbaseUrl=" + mBaseUrl + "\nlogUrl=" + mLogUrl + "\nmanifestUrl=" + mManifestUrl;
// SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(appContext);
// SharedPreferences.Editor editor = prefs.edit();
// editor.putString("repo_" + mId, manifestString);
// editor.putBoolean("hasCachedRepos", true);
// editor.putString("updated_" + mId, this.lastUpdate);
// editor.apply();
// }
// private boolean ParseProps(String string) {
//
// if ((string.length() <= 1) | (!string.contains("id"))) {
// return false;
// } else {
// String lines[] = string.split("\\n");
// for (String line : lines) {
// if (line != "") {
// String props[] = line.split("=");
// switch (props[0]) {
// case "versionCode":
// this.mVersionCode = props[1];
// break;
// case "name":
// this.mName = props[1];
// break;
// case "author":
// this.mAuthor = props[1];
// break;
// case "id":
// this.mId = props[1];
// break;
// case "version":
// this.mVersion = props[1];
// break;
// case "description":
// this.mDescription = props[1];
// break;
// case "donate":
// this.mDonateUrl = props[1];
// break;
// case "cacheModule":
// this.mIsCacheModule = Boolean.valueOf(props[1]);
// break;
// case "support":
// this.mSupportUrl = props[1];
// break;
// case "logUrl":
// this.mLogUrl = props[1];
// break;
// case "donateUrl":
// this.mDonateUrl = props[1];
// break;
// case "zipUrl":
// this.mZipUrl = props[1];
// break;
// case "baseUrl":
// this.mBaseUrl = props[1];
// break;
// case "manifestUrl":
// this.mManifestUrl = props[1];
// break;
// default:
// Log.d("Magisk", "Manifest string not recognized: " + props[0]);
// break;
// }
// }
//
// }
// SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(appContext);
// if (prefs.contains("repo-isInstalled_" + this.mId)) {
// mIsInstalled = prefs.getBoolean("repo-isInstalled_" + this.mId,false);
// }
// if (prefs.contains("repo-canUpdate_" + this.mId)) {
// mCanUpdate = prefs.getBoolean("repo-canUpdate_" + this.mId,false);
// }
// if (prefs.contains("updated_" + this.mId)) {
// lastUpdate = prefs.getString("updated_" + this.mId,"");
// }
//
//
//
// return this.mId != null;
//
// }
// }
//
//
//
//
//
//
//
//
// public String getStringProperty(String mValue) {
// switch (mValue) {
// case "author":
// return mAuthor;
// case "id":
// return mId;
// case "version":
// return mVersion;
// case "description":
// return mDescription;
// case "supportUrl":
// return mSupportUrl;
// case "donateUrl":
// return mDonateUrl;
// case "baseeUrl":
// return mBaseUrl;
// case "zipUrl":
// return mZipUrl;
// default:
// return null;
// }
// }
//
// public String getName() {
// return mName;
// }
//
// public String getmVersion() {
// return mVersion;
// }
//
// public int getmVersionCode() {
// return Integer.valueOf(mVersionCode);
// }
//
// public String getDescription() {
// return mDescription;
// }
//
// public String getId() {
// return mId;
// }
//
// public String getZipUrl() {
// return mZipUrl;
// }
//
// public String getmBaseUrl() {
// return mBaseUrl;
// }
//
// public String getLogUrl() {
// return mLogUrl;
// }
//
//
// public String getAuthor() {
// return mAuthor;
// }
//
// public String getDonateUrl() {
// return mDonateUrl;
// }
//
// public String getmManifestUrl() {
// return mManifestUrl;
// }
//
// public String getSupportUrl() {
// return mSupportUrl;
// }
//
// public String getLastUpdate() {
// return lastUpdate;
// }
//
// public boolean isInstalled() { return mIsInstalled; }
// public boolean canUpdate() { return mCanUpdate; }
// public boolean isCacheModule() { return mIsCacheModule; }
//}

View File

@ -5,6 +5,7 @@ import android.content.SharedPreferences;
import com.google.gson.Gson; import com.google.gson.Gson;
import com.google.gson.reflect.TypeToken; import com.google.gson.reflect.TypeToken;
import com.topjohnwu.magisk.ModulesFragment;
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;
@ -78,6 +79,12 @@ public class RepoHelper {
} }
} }
public static void checkUpdate() {
for (Module module : ModulesFragment.listModules) {
module.checkUpdate();
}
}
public static List<Repo> getSortedList() { public static List<Repo> getSortedList() {
ArrayList<Repo> list = new ArrayList<>(repoMap.values()); ArrayList<Repo> list = new ArrayList<>(repoMap.values());
Collections.sort(list, new Utils.ModuleComparator()); Collections.sort(list, new Utils.ModuleComparator());

View File

@ -227,6 +227,7 @@ public class Async {
protected Void doInBackground(Void... voids) { protected Void doInBackground(Void... voids) {
ReposFragment.mListRepos.clear(); ReposFragment.mListRepos.clear();
RepoHelper.createRepoMap(mContext); RepoHelper.createRepoMap(mContext);
RepoHelper.checkUpdate();
ReposFragment.mListRepos = RepoHelper.getSortedList(); ReposFragment.mListRepos = RepoHelper.getSortedList();
return null; return null;
} }