Skip to content

Commit 295e847

Browse files
impl version ignore for modules
fixes #9 TODO: ignore updates in UI as well as notif Signed-off-by: androidacy-user <opensource@androidacy.com>
1 parent ae41a47 commit 295e847

5 files changed

Lines changed: 140 additions & 7 deletions

File tree

app/src/main/java/com/fox2code/mmm/background/BackgroundUpdateChecker.java

Lines changed: 43 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,10 @@
3737
import com.fox2code.mmm.utils.io.PropUtils;
3838

3939
import java.util.HashMap;
40+
import java.util.HashSet;
4041
import java.util.Map;
4142
import java.util.Objects;
43+
import java.util.Set;
4244
import java.util.concurrent.TimeUnit;
4345

4446
import timber.log.Timber;
@@ -136,12 +138,52 @@ static void doCheck(Context context) {
136138
if ("twrp-keep".equals(localModuleInfo.id)) continue;
137139
// exclude all modules with id's stored in the pref pref_background_update_check_excludes
138140
try {
139-
if (Objects.requireNonNull(MainApplication.getSharedPreferences("mmm").getStringSet("pref_background_update_check_excludes", null)).contains(localModuleInfo.id))
141+
if (Objects.requireNonNull(MainApplication.getSharedPreferences("mmm").getStringSet("pref_background_update_check_excludes", new HashSet<>())).contains(localModuleInfo.id))
140142
continue;
141143
} catch (Exception ignored) {
142144
}
145+
// now, we just had to make it more fucking complicated, didn't we?
146+
// we now have pref_background_update_check_excludes_version, which is a id:version stringset of versions the user may want to "skip"
147+
// oh, and because i hate myself, i made ^ at the beginning match that version and newer, and $ at the end match that version and older
148+
Set<String> stringSet = MainApplication.getSharedPreferences("mmm").getStringSet("pref_background_update_check_excludes_version", new HashSet<>());
149+
String version = "";
150+
if (stringSet.contains(localModuleInfo.id)) {
151+
// get the one matching
152+
version = stringSet.stream().filter(s -> s.startsWith(localModuleInfo.id)).findFirst().orElse("");
153+
}
143154
RepoModule repoModule = repoModules.get(localModuleInfo.id);
144155
localModuleInfo.checkModuleUpdate();
156+
String remoteVersion = localModuleInfo.updateVersion;
157+
String remoteVersionCode = String.valueOf(localModuleInfo.updateVersionCode);
158+
if (repoModule != null) {
159+
remoteVersion = repoModule.moduleInfo.version;
160+
remoteVersionCode = String.valueOf(repoModule.moduleInfo.versionCode);
161+
}
162+
// now, coerce everything into an int
163+
int localVersionCode = Integer.parseInt(String.valueOf(localModuleInfo.versionCode));
164+
int remoteVersionCodeInt = Integer.parseInt(remoteVersionCode);
165+
// we also have to match the version name
166+
int localVersion = Integer.parseInt(localModuleInfo.version);
167+
int remoteVersionInt = Integer.parseInt(remoteVersion);
168+
int wantsVersion = Integer.parseInt(version.split(":")[1]);
169+
// now find out if user wants up to and including this version, or this version and newer
170+
// if it starts with ^, it's this version and newer, if it ends with $, it's this version and older
171+
if (version.startsWith("^")) {
172+
// this version and newer
173+
if (wantsVersion > localVersion || wantsVersion > remoteVersionInt || wantsVersion > remoteVersionCodeInt || wantsVersion < localVersionCode) {
174+
// if it is, we skip it
175+
continue;
176+
}
177+
} else if (version.endsWith("$")) {
178+
// this version and older
179+
if (wantsVersion < localVersion || wantsVersion < remoteVersionInt || wantsVersion < remoteVersionCodeInt || wantsVersion > localVersionCode) {
180+
// if it is, we skip it
181+
continue;
182+
}
183+
} else if (wantsVersion == localVersion || wantsVersion == remoteVersionInt || wantsVersion == remoteVersionCodeInt || wantsVersion == localVersionCode) {
184+
// if it is, we skip it
185+
continue;
186+
}
145187
if (localModuleInfo.updateVersionCode > localModuleInfo.versionCode && !PropUtils.isNullString(localModuleInfo.updateVersion)) {
146188
moduleUpdateCount++;
147189
updateableModules.put(localModuleInfo.name, localModuleInfo.version);

app/src/main/java/com/fox2code/mmm/module/ModuleViewAdapter.java

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
import android.widget.HorizontalScrollView;
1313
import android.widget.ImageButton;
1414
import android.widget.TextView;
15+
import android.widget.Toast;
1516

1617
import androidx.annotation.ColorInt;
1718
import androidx.annotation.NonNull;
@@ -212,6 +213,21 @@ public boolean update(ModuleHolder moduleHolder) {
212213
} else {
213214
this.creditText.setText(localModuleInfo.version + ((localModuleInfo.updateVersion != null && (Objects.equals(localModuleInfo.version, localModuleInfo.updateVersion) || Objects.equals(localModuleInfo.version, localModuleInfo.updateVersion + " (" + localModuleInfo.updateVersionCode + ")"))) ? "" : " (" + this.getString(R.string.module_last_update) + " " + localModuleInfo.updateVersion + ")") + " " + this.getString(R.string.module_by) + " " + localModuleInfo.author);
214215
}
216+
// add an onclick listener to the credit text to show the versionCode
217+
this.creditText.setOnClickListener(v -> {
218+
// if both local and remote moduleInfo are available, show the versionCode of both
219+
if (localModuleInfo != null) {
220+
// if moduleInfo and localModuleInfo have the same versionCode, only show one, otherwise show both
221+
if (localModuleInfo.versionCode == moduleInfo.versionCode) {
222+
Toast.makeText(this.itemView.getContext(), this.getString(R.string.module_version) + " " + localModuleInfo.version + " (" + localModuleInfo.versionCode + ")", Toast.LENGTH_LONG).show();
223+
} else {
224+
// format is Version: version (versionCode) | Remote Version: version (versionCode)
225+
Toast.makeText(this.itemView.getContext(), this.getString(R.string.module_version) + " " + localModuleInfo.version + " (" + localModuleInfo.versionCode + ") | " + this.getString(R.string.module_remote_version) + " " + moduleInfo.version + " (" + moduleInfo.versionCode + ")", Toast.LENGTH_LONG).show();
226+
}
227+
} else {
228+
Toast.makeText(this.itemView.getContext(), this.getString(R.string.module_remote_version) + " " + moduleInfo.version + " (" + moduleInfo.versionCode + ")", Toast.LENGTH_LONG).show();
229+
}
230+
});
215231
if (moduleInfo.description == null || moduleInfo.description.isEmpty()) {
216232
this.descriptionText.setText(R.string.no_desc_found);
217233
} else {

app/src/main/java/com/fox2code/mmm/settings/SettingsActivity.java

Lines changed: 74 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,12 @@
2222
import android.text.Editable;
2323
import android.text.TextWatcher;
2424
import android.view.View;
25+
import android.view.ViewGroup;
2526
import android.view.inputmethod.EditorInfo;
2627
import android.widget.Button;
2728
import android.widget.EditText;
29+
import android.widget.LinearLayout;
30+
import android.widget.ScrollView;
2831
import android.widget.Toast;
2932

3033
import androidx.annotation.StringRes;
@@ -76,6 +79,7 @@
7679
import com.google.android.material.navigation.NavigationBarView;
7780
import com.google.android.material.snackbar.BaseTransientBottomBar;
7881
import com.google.android.material.snackbar.Snackbar;
82+
import com.google.android.material.textview.MaterialTextView;
7983
import com.mikepenz.aboutlibraries.LibsBuilder;
8084
import com.topjohnwu.superuser.internal.UiThreadHandler;
8185

@@ -579,18 +583,18 @@ public void onCreatePreferences(Bundle savedInstanceState, String rootKey) {
579583
String[] moduleNames = new String[localModuleInfos.size()];
580584
checkedItems = new boolean[localModuleInfos.size()];
581585
int i = 0;
586+
// get the stringset pref_background_update_check_excludes
587+
Set<String> stringSetTemp = sharedPreferences.getStringSet("pref_background_update_check_excludes", new HashSet<>());
588+
// copy to a new set so we can modify it
589+
Set<String> stringSet = new HashSet<>(stringSetTemp);
582590
for (LocalModuleInfo localModuleInfo : localModuleInfos) {
583591
moduleNames[i] = localModuleInfo.name;
584-
// get the stringset pref_background_update_check_excludes
585-
Set<String> stringSet = sharedPreferences.getStringSet("pref_background_update_check_excludes", new HashSet<>());
586592
// Stringset uses id, we show name
587593
checkedItems[i] = stringSet.contains(localModuleInfo.id);
588594
Timber.d("name: %s, checked: %s", moduleNames[i], checkedItems[i]);
589595
i++;
590596
}
591597
new MaterialAlertDialogBuilder(this.requireContext()).setTitle(R.string.background_update_check_excludes).setMultiChoiceItems(moduleNames, checkedItems, (dialog, which, isChecked) -> {
592-
// get the stringset pref_background_update_check_excludes
593-
Set<String> stringSet = new HashSet<>(sharedPreferences.getStringSet("pref_background_update_check_excludes", new HashSet<>()));
594598
// get id from name
595599
String id;
596600
if (localModuleInfos.stream().anyMatch(localModuleInfo -> localModuleInfo.name.equals(moduleNames[which]))) {
@@ -614,6 +618,72 @@ public void onCreatePreferences(Bundle savedInstanceState, String rootKey) {
614618
}
615619
return true;
616620
});
621+
// now handle pref_background_update_check_excludes_version
622+
updateCheckVersionExcludes.setVisible(MainApplication.isBackgroundUpdateCheckEnabled() && !MainApplication.isWrapped());
623+
updateCheckVersionExcludes.setOnPreferenceClickListener(preference -> {
624+
// get the stringset pref_background_update_check_excludes_version
625+
Set<String> stringSet = sharedPreferences.getStringSet("pref_background_update_check_excludes_version", new HashSet<>());
626+
Timber.d("stringSet: %s", stringSet);
627+
// for every module, add it's name and a text field to the dialog. the text field should accept a comma separated list of versions
628+
Collection<LocalModuleInfo> localModuleInfos = ModuleManager.getINSTANCE().getModules().values();
629+
// make sure we have modules
630+
if (localModuleInfos.isEmpty()) {
631+
new MaterialAlertDialogBuilder(this.requireContext()).setTitle(R.string.background_update_check_excludes).setMessage(R.string.background_update_check_excludes_no_modules).setPositiveButton(R.string.ok, (dialog, which) -> {
632+
}).show();
633+
} else {
634+
LinearLayout layout = new LinearLayout(this.requireContext());
635+
layout.setOrientation(LinearLayout.VERTICAL);
636+
LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT);
637+
params.setMargins(48, 0, 48, 0);
638+
// add a summary
639+
MaterialTextView textView = new MaterialTextView(this.requireContext());
640+
textView.setLayoutParams(params);
641+
textView.setText(R.string.background_update_check_excludes_version_summary);
642+
for (LocalModuleInfo localModuleInfo : localModuleInfos) {
643+
// two views: materialtextview for name, edittext for version
644+
MaterialTextView materialTextView = new MaterialTextView(this.requireContext());
645+
materialTextView.setLayoutParams(params);
646+
materialTextView.setPadding(12, 8, 12, 8);
647+
materialTextView.setTextAppearance(com.google.android.material.R.style.TextAppearance_MaterialComponents_Subtitle1);
648+
materialTextView.setText(localModuleInfo.name);
649+
layout.addView(materialTextView);
650+
EditText editText = new EditText(this.requireContext());
651+
editText.setLayoutParams(params);
652+
editText.setHint(R.string.background_update_check_excludes_version_hint);
653+
// stringset uses id:version, we show version for name
654+
// so we need to get id from name, then get version from stringset
655+
String id = localModuleInfos.stream().filter(localModuleInfo1 -> localModuleInfo1.name.equals(localModuleInfo.name)).findFirst().orElse(null).id;
656+
String version = stringSet.stream().filter(s -> s.startsWith(id)).findFirst().orElse("");
657+
if (!version.isEmpty()) {
658+
editText.setText(version.split(":")[1]);
659+
}
660+
layout.addView(editText);
661+
}
662+
ScrollView scrollView = new ScrollView(this.requireContext());
663+
scrollView.addView(layout);
664+
new MaterialAlertDialogBuilder(this.requireContext()).setTitle(R.string.background_update_check_excludes_version).setView(scrollView).setPositiveButton(R.string.ok, (dialog, which) -> {
665+
Timber.d("ok clicked");
666+
// for every module, get the text field and save it to the stringset
667+
Set<String> stringSetTemp = new HashSet<>();
668+
for (int i = 0; i < layout.getChildCount(); i++) {
669+
EditText editText = (EditText) layout.getChildAt(i);
670+
String text = editText.getText().toString();
671+
if (!text.isEmpty()) {
672+
// text cannot contain a colon because we use that to split id and version
673+
text = text.replace(":", "");
674+
// we have to use module id even though we show name
675+
stringSetTemp.add(localModuleInfos.stream().filter(localModuleInfo -> localModuleInfo.name.equals(editText.getHint().toString())).findFirst().orElse(null).id + ":" + text);
676+
Timber.d("text is %s for %s", text, editText.getHint().toString());
677+
} else {
678+
Timber.d("text is empty for %s", editText.getHint().toString());
679+
}
680+
}
681+
sharedPreferences.edit().putStringSet("pref_background_update_check_excludes_version", stringSetTemp).apply();
682+
}).setNegativeButton(R.string.cancel, (dialog, which) -> {
683+
}).show();
684+
}
685+
return true;
686+
});
617687
final LibsBuilder libsBuilder = new LibsBuilder().withShowLoadingProgress(false).withLicenseShown(true).withAboutMinimalDesign(false);
618688
ClipboardManager clipboard = (ClipboardManager) requireContext().getSystemService(Context.CLIPBOARD_SERVICE);
619689
LongClickablePreference linkClickable = findPreference("pref_update");

app/src/main/res/layout/activity_crash_handler.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,8 +68,8 @@
6868

6969
<com.google.android.material.button.MaterialButton
7070
android:id="@+id/copy_button"
71-
android:layout_width="28dp"
72-
android:layout_height="28dp"
71+
android:layout_width="36dp"
72+
android:layout_height="36dp"
7373
android:layout_gravity="top|end"
7474
android:layout_margin="10dp"
7575
android:background="@drawable/baseline_copy_all_24"

app/src/main/res/values/strings.xml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -418,4 +418,9 @@
418418
<string name="setup_scroll_down_v2">To enable the finish button, scroll to the bottom and acknowledge you have read and agree to the EULA and license(s).</string>
419419
<string name="notification_update_ignore_version_desc">Ignore specific versions when checking for module updates. Disabling update checks per-module above overrides this setting!</string>
420420
<string name="notification_update_ignore_version_pref">Exclude version(s) from update checks</string>
421+
<string name="background_update_check_excludes_version">Exclude version(s) of modules from checks</string>
422+
<string name="background_update_check_excludes_version_summary">Specify versions of modules you\'d like to ignore. Version code or version name will work, but version code may be more accurate. Use ^ at the beginning to match that version and newer. Use $ at the end to match up until that version.</string>
423+
<string name="module_version">"Version: "</string>
424+
<string name="module_remote_version">Remote version</string>
425+
<string name="background_update_check_excludes_version_hint">Version(s) to ignore</string>
421426
</resources>

0 commit comments

Comments
 (0)