diff --git a/app/src/main/java/com/fox2code/mmm/manager/LocalModuleInfo.java b/app/src/main/java/com/fox2code/mmm/manager/LocalModuleInfo.java index 0fe70f5..8c8afc2 100644 --- a/app/src/main/java/com/fox2code/mmm/manager/LocalModuleInfo.java +++ b/app/src/main/java/com/fox2code/mmm/manager/LocalModuleInfo.java @@ -4,6 +4,7 @@ import android.util.Log; import com.fox2code.mmm.utils.FastException; import com.fox2code.mmm.utils.Http; +import com.fox2code.mmm.utils.PropUtils; import org.json.JSONObject; @@ -29,9 +30,8 @@ public class LocalModuleInfo extends ModuleInfo { this.updateZipUrl = jsonUpdate.getString("zipUrl"); this.updateChangeLog = jsonUpdate.optString("changelog"); if (this.updateZipUrl.isEmpty()) throw FastException.INSTANCE; - if (this.updateVersion == null || this.updateVersion.trim().isEmpty()) { - this.updateVersion = "v" + this.updateVersionCode; - } + this.updateVersion = PropUtils.shortenVersionName( + this.updateVersion.trim(), this.updateVersionCode); } catch (Exception e) { this.updateVersion = null; this.updateVersionCode = Long.MIN_VALUE; diff --git a/app/src/main/java/com/fox2code/mmm/utils/PropUtils.java b/app/src/main/java/com/fox2code/mmm/utils/PropUtils.java index 1a56104..39e0c6f 100644 --- a/app/src/main/java/com/fox2code/mmm/utils/PropUtils.java +++ b/app/src/main/java/com/fox2code/mmm/utils/PropUtils.java @@ -230,9 +230,11 @@ public class PropUtils { if (!readName || isInvalidValue(moduleInfo.name)) { moduleInfo.name = makeNameFromId(moduleInfo.id); } - // We can't accept too long version names for usability reason. - if (!readVersion || moduleInfo.version.length() > 16) { + if (!readVersion) { moduleInfo.version = "v" + moduleInfo.versionCode; + } else { + moduleInfo.version = shortenVersionName( + moduleInfo.version, moduleInfo.versionCode); } if (!readDescription || isInvalidValue(moduleInfo.description)) { moduleInfo.description = ""; @@ -292,4 +294,15 @@ public class PropUtils { return moduleId.substring(0, 1).toUpperCase(Locale.ROOT) + moduleId.substring(1).replace('_', ' '); } + + // Make versionName no longer than 16 charters to avoid UI overflow. + public static String shortenVersionName(String versionName, long versionCode) { + if (versionName == null) return "v" + versionCode; + if (versionName.length() <= 16) return versionName; + int i = versionName.lastIndexOf('.'); + if (i != -1 && i <= 16 && versionName.indexOf('.') != i + && versionName.indexOf(' ') == -1) + return versionName.substring(0, i); + return "v" + versionCode; + } }