Skip to content
This repository was archived by the owner on May 4, 2023. It is now read-only.

Commit d094e29

Browse files
committed
Improve name shortening to be smarter (Close #31)
1 parent 584d8b1 commit d094e29

File tree

2 files changed

+18
-5
lines changed

2 files changed

+18
-5
lines changed

app/src/main/java/com/fox2code/mmm/manager/LocalModuleInfo.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
import com.fox2code.mmm.utils.FastException;
66
import com.fox2code.mmm.utils.Http;
7+
import com.fox2code.mmm.utils.PropUtils;
78

89
import org.json.JSONObject;
910

@@ -29,9 +30,8 @@ public void checkModuleUpdate() {
2930
this.updateZipUrl = jsonUpdate.getString("zipUrl");
3031
this.updateChangeLog = jsonUpdate.optString("changelog");
3132
if (this.updateZipUrl.isEmpty()) throw FastException.INSTANCE;
32-
if (this.updateVersion == null || this.updateVersion.trim().isEmpty()) {
33-
this.updateVersion = "v" + this.updateVersionCode;
34-
}
33+
this.updateVersion = PropUtils.shortenVersionName(
34+
this.updateVersion.trim(), this.updateVersionCode);
3535
} catch (Exception e) {
3636
this.updateVersion = null;
3737
this.updateVersionCode = Long.MIN_VALUE;

app/src/main/java/com/fox2code/mmm/utils/PropUtils.java

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -230,9 +230,11 @@ public static void readProperties(ModuleInfo moduleInfo, InputStream inputStream
230230
if (!readName || isInvalidValue(moduleInfo.name)) {
231231
moduleInfo.name = makeNameFromId(moduleInfo.id);
232232
}
233-
// We can't accept too long version names for usability reason.
234-
if (!readVersion || moduleInfo.version.length() > 16) {
233+
if (!readVersion) {
235234
moduleInfo.version = "v" + moduleInfo.versionCode;
235+
} else {
236+
moduleInfo.version = shortenVersionName(
237+
moduleInfo.version, moduleInfo.versionCode);
236238
}
237239
if (!readDescription || isInvalidValue(moduleInfo.description)) {
238240
moduleInfo.description = "";
@@ -292,4 +294,15 @@ private static String makeNameFromId(String moduleId) {
292294
return moduleId.substring(0, 1).toUpperCase(Locale.ROOT) +
293295
moduleId.substring(1).replace('_', ' ');
294296
}
297+
298+
// Make versionName no longer than 16 charters to avoid UI overflow.
299+
public static String shortenVersionName(String versionName, long versionCode) {
300+
if (versionName == null) return "v" + versionCode;
301+
if (versionName.length() <= 16) return versionName;
302+
int i = versionName.lastIndexOf('.');
303+
if (i != -1 && i <= 16 && versionName.indexOf('.') != i
304+
&& versionName.indexOf(' ') == -1)
305+
return versionName.substring(0, i);
306+
return "v" + versionCode;
307+
}
295308
}

0 commit comments

Comments
 (0)