From 8a7df954e5ff5cc83bbc96db926dd872b846f8f4 Mon Sep 17 00:00:00 2001 From: topjohnwu Date: Fri, 23 Sep 2016 17:12:29 +0800 Subject: [PATCH] Update check module update --- app/build.gradle | 6 +- .../com/topjohnwu/magisk/ReposFragment.java | 30 +- .../com/topjohnwu/magisk/module/Module.java | 10 + .../com/topjohnwu/magisk/module/Repo.java | 264 +----------------- .../topjohnwu/magisk/module/RepoHelper.java | 7 + .../com/topjohnwu/magisk/utils/Async.java | 1 + 6 files changed, 44 insertions(+), 274 deletions(-) diff --git a/app/build.gradle b/app/build.gradle index 442597aa7..eebc46c62 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -32,9 +32,9 @@ repositories { dependencies { compile fileTree(include: ['*.jar'], dir: 'libs') - compile 'com.android.support:recyclerview-v7:24.2.0' - compile 'com.android.support:cardview-v7:24.2.0' - compile 'com.android.support:design:24.2.0' + compile 'com.android.support:recyclerview-v7:24.2.1' + compile 'com.android.support:cardview-v7:24.2.1' + compile 'com.android.support:design:24.2.1' compile 'com.github.d8ahazard:BroadcastTileSupportUpdate:master' compile 'com.jakewharton:butterknife:8.4.0' compile 'com.github.michalis-vitos:aFileChooser:master' diff --git a/app/src/main/java/com/topjohnwu/magisk/ReposFragment.java b/app/src/main/java/com/topjohnwu/magisk/ReposFragment.java index ee9ede7d6..31692631a 100644 --- a/app/src/main/java/com/topjohnwu/magisk/ReposFragment.java +++ b/app/src/main/java/com/topjohnwu/magisk/ReposFragment.java @@ -43,7 +43,7 @@ public class ReposFragment extends Fragment { private boolean alertUpdate; private boolean ignoreAlertUpdate; private String alertPackage; - private SharedPreferences prefs; +// private SharedPreferences prefs; @Nullable @@ -52,16 +52,16 @@ public class ReposFragment extends Fragment { View view = inflater.inflate(R.layout.repos_fragment, container, false); mView = view; ButterKnife.bind(this, view); - prefs = PreferenceManager.getDefaultSharedPreferences(getActivity()); - if (prefs.contains("ignoreUpdateAlerts")) { - ignoreAlertUpdate = prefs.getBoolean("ignoreUpdateAlerts", false); - } - swipeRefreshLayout.setOnRefreshListener(() -> { - this.LoadRepo(true); - ignoreAlertUpdate = false; - prefs.edit().putBoolean("ignoreUpdateAlerts",false).apply(); - - }); +// prefs = PreferenceManager.getDefaultSharedPreferences(getActivity()); +// if (prefs.contains("ignoreUpdateAlerts")) { +// ignoreAlertUpdate = prefs.getBoolean("ignoreUpdateAlerts", false); +// } +// swipeRefreshLayout.setOnRefreshListener(() -> { +// this.LoadRepo(true); +// ignoreAlertUpdate = false; +// prefs.edit().putBoolean("ignoreUpdateAlerts",false).apply(); +// +// }); LoadRepo(false); setHasOptionsMenu(false); alertUpdate = false; @@ -136,10 +136,10 @@ public class ReposFragment extends Fragment { break; case DialogInterface.BUTTON_NEGATIVE: - ignoreAlertUpdate = true; - SharedPreferences.Editor editor = prefs.edit(); - editor.putBoolean("ignoreUpdateAlerts", ignoreAlertUpdate); - editor.apply(); +// ignoreAlertUpdate = true; +// SharedPreferences.Editor editor = prefs.edit(); +// editor.putBoolean("ignoreUpdateAlerts", ignoreAlertUpdate); +// editor.apply(); break; } }; diff --git a/app/src/main/java/com/topjohnwu/magisk/module/Module.java b/app/src/main/java/com/topjohnwu/magisk/module/Module.java index 2724738fa..006d652e3 100644 --- a/app/src/main/java/com/topjohnwu/magisk/module/Module.java +++ b/app/src/main/java/com/topjohnwu/magisk/module/Module.java @@ -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 void createDisableFile() { diff --git a/app/src/main/java/com/topjohnwu/magisk/module/Repo.java b/app/src/main/java/com/topjohnwu/magisk/module/Repo.java index c30641ceb..83118e43a 100644 --- a/app/src/main/java/com/topjohnwu/magisk/module/Repo.java +++ b/app/src/main/java/com/topjohnwu/magisk/module/Repo.java @@ -42,6 +42,14 @@ public class Repo extends BaseModule { } } + public void setUpdate() { + mCanUpdate = true; + } + + public void setInstalled() { + mIsInstalled = true; + } + public String getZipUrl() { return mZipUrl; } @@ -62,259 +70,3 @@ public class Repo extends BaseModule { public boolean canUpdate() { return mCanUpdate; } 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; } -//} - diff --git a/app/src/main/java/com/topjohnwu/magisk/module/RepoHelper.java b/app/src/main/java/com/topjohnwu/magisk/module/RepoHelper.java index e4f5faa0a..abfd241d6 100644 --- a/app/src/main/java/com/topjohnwu/magisk/module/RepoHelper.java +++ b/app/src/main/java/com/topjohnwu/magisk/module/RepoHelper.java @@ -5,6 +5,7 @@ import android.content.SharedPreferences; import com.google.gson.Gson; import com.google.gson.reflect.TypeToken; +import com.topjohnwu.magisk.ModulesFragment; import com.topjohnwu.magisk.R; import com.topjohnwu.magisk.utils.Utils; 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 getSortedList() { ArrayList list = new ArrayList<>(repoMap.values()); Collections.sort(list, new Utils.ModuleComparator()); diff --git a/app/src/main/java/com/topjohnwu/magisk/utils/Async.java b/app/src/main/java/com/topjohnwu/magisk/utils/Async.java index 266e9c347..9e0485970 100644 --- a/app/src/main/java/com/topjohnwu/magisk/utils/Async.java +++ b/app/src/main/java/com/topjohnwu/magisk/utils/Async.java @@ -227,6 +227,7 @@ public class Async { protected Void doInBackground(Void... voids) { ReposFragment.mListRepos.clear(); RepoHelper.createRepoMap(mContext); + RepoHelper.checkUpdate(); ReposFragment.mListRepos = RepoHelper.getSortedList(); return null; }