[app] Compare version string directly
This commit is contained in:
parent
07c05771aa
commit
dea35b24c2
|
|
@ -36,7 +36,6 @@ import io.github.lsposed.manager.BuildConfig;
|
||||||
import io.github.lsposed.manager.Constants;
|
import io.github.lsposed.manager.Constants;
|
||||||
import io.github.lsposed.manager.R;
|
import io.github.lsposed.manager.R;
|
||||||
import io.github.lsposed.manager.util.NavUtil;
|
import io.github.lsposed.manager.util.NavUtil;
|
||||||
import io.github.lsposed.manager.util.Version;
|
|
||||||
import io.github.lsposed.manager.util.theme.ThemeUtil;
|
import io.github.lsposed.manager.util.theme.ThemeUtil;
|
||||||
import rikka.core.res.ResourcesKt;
|
import rikka.core.res.ResourcesKt;
|
||||||
import rikka.material.app.MaterialActivity;
|
import rikka.material.app.MaterialActivity;
|
||||||
|
|
@ -56,9 +55,7 @@ public class BaseActivity extends MaterialActivity {
|
||||||
// make sure the versions are consistent
|
// make sure the versions are consistent
|
||||||
String coreVersionStr = Constants.getXposedVersion();
|
String coreVersionStr = Constants.getXposedVersion();
|
||||||
if (coreVersionStr != null) {
|
if (coreVersionStr != null) {
|
||||||
Version managerVersion = new Version(BuildConfig.VERSION_NAME);
|
if (!BuildConfig.VERSION_NAME.equals(coreVersionStr)) {
|
||||||
Version coreVersion = new Version(coreVersionStr);
|
|
||||||
if (!managerVersion.equals(coreVersion)) {
|
|
||||||
new AlertDialog.Builder(this)
|
new AlertDialog.Builder(this)
|
||||||
.setMessage(R.string.outdated_manager)
|
.setMessage(R.string.outdated_manager)
|
||||||
.setPositiveButton(R.string.ok, (dialog, id) -> {
|
.setPositiveButton(R.string.ok, (dialog, id) -> {
|
||||||
|
|
|
||||||
|
|
@ -1,71 +0,0 @@
|
||||||
/*
|
|
||||||
* This file is part of LSPosed.
|
|
||||||
*
|
|
||||||
* LSPosed is free software: you can redistribute it and/or modify
|
|
||||||
* it under the terms of the GNU General Public License as published by
|
|
||||||
* the Free Software Foundation, either version 3 of the License, or
|
|
||||||
* (at your option) any later version.
|
|
||||||
*
|
|
||||||
* LSPosed is distributed in the hope that it will be useful,
|
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
* GNU General Public License for more details.
|
|
||||||
*
|
|
||||||
* You should have received a copy of the GNU General Public License
|
|
||||||
* along with LSPosed. If not, see <https://www.gnu.org/licenses/>.
|
|
||||||
*
|
|
||||||
* Copyright (C) 2020 EdXposed Contributors
|
|
||||||
* Copyright (C) 2021 LSPosed Contributors
|
|
||||||
*/
|
|
||||||
|
|
||||||
package io.github.lsposed.manager.util;
|
|
||||||
|
|
||||||
// https://stackoverflow.com/a/11024200
|
|
||||||
public class Version implements Comparable<Version> {
|
|
||||||
|
|
||||||
private final String version;
|
|
||||||
|
|
||||||
public final String get() {
|
|
||||||
return this.version;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Version(String version) {
|
|
||||||
if (version == null)
|
|
||||||
throw new IllegalArgumentException("Version can not be null");
|
|
||||||
if (!version.matches("v[0-9]+(\\.[0-9]+)*"))
|
|
||||||
throw new IllegalArgumentException("Invalid version format");
|
|
||||||
this.version = version.substring(1); // v
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public int compareTo(Version that) {
|
|
||||||
if (that == null)
|
|
||||||
return 1;
|
|
||||||
String[] thisParts = this.get().split("\\.");
|
|
||||||
String[] thatParts = that.get().split("\\.");
|
|
||||||
int length = Math.max(thisParts.length, thatParts.length);
|
|
||||||
for (int i = 0; i < length; i++) {
|
|
||||||
int thisPart = i < thisParts.length ?
|
|
||||||
Integer.parseInt(thisParts[i]) : 0;
|
|
||||||
int thatPart = i < thatParts.length ?
|
|
||||||
Integer.parseInt(thatParts[i]) : 0;
|
|
||||||
if (thisPart < thatPart)
|
|
||||||
return -1;
|
|
||||||
if (thisPart > thatPart)
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean equals(Object that) {
|
|
||||||
if (this == that)
|
|
||||||
return true;
|
|
||||||
if (that == null)
|
|
||||||
return false;
|
|
||||||
if (this.getClass() != that.getClass())
|
|
||||||
return false;
|
|
||||||
return this.compareTo((Version) that) == 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
Loading…
Reference in New Issue