update AtomReader, add support releaseTag on android

This commit is contained in:
Anthony Calosa
2024-10-25 17:43:35 +08:00
parent 07bb0e6fe3
commit 1f05a5a295
3 changed files with 47 additions and 4 deletions

View File

@@ -61,10 +61,12 @@ public class AtomReader {
public static class Entry { public static class Entry {
public final String title; public final String title;
public final String updated; public final String updated;
public final String link;
private Entry(String title, String updated) { private Entry(String title, String updated, String link) {
this.title = title; this.title = title;
this.updated = updated; this.updated = updated;
this.link = link;
} }
} }
@@ -72,6 +74,7 @@ public class AtomReader {
parser.require(XmlPullParser.START_TAG, ns, "entry"); parser.require(XmlPullParser.START_TAG, ns, "entry");
String title = null; String title = null;
String updated = null; String updated = null;
String link = null;
while (parser.next() != XmlPullParser.END_TAG) { while (parser.next() != XmlPullParser.END_TAG) {
if (parser.getEventType() != XmlPullParser.START_TAG) { if (parser.getEventType() != XmlPullParser.START_TAG) {
continue; continue;
@@ -81,11 +84,13 @@ public class AtomReader {
title = readTitle(parser); title = readTitle(parser);
} else if (name.equals("updated")) { } else if (name.equals("updated")) {
updated = readUpdated(parser); updated = readUpdated(parser);
} else if (name.equals("link")) {
link = readLink(parser);
} else { } else {
skip(parser); skip(parser);
} }
} }
return new Entry(title, updated); return new Entry(title, updated, link);
} }
private String readTitle(XmlPullParser parser) throws Exception { private String readTitle(XmlPullParser parser) throws Exception {
@@ -102,6 +107,21 @@ public class AtomReader {
return updated; return updated;
} }
private String readLink(XmlPullParser parser) throws Exception {
String link = "";
parser.require(XmlPullParser.START_TAG, ns, "link");
String tag = parser.getName();
String relType = parser.getAttributeValue(null, "rel");
if (tag.equals("link")) {
if (relType.equals("alternate")) {
link = parser.getAttributeValue(null, "href");
parser.nextTag();
}
}
parser.require(XmlPullParser.END_TAG, ns, "link");
return link;
}
private String readText(XmlPullParser parser) throws Exception { private String readText(XmlPullParser parser) throws Exception {
String result = ""; String result = "";
if (parser.next() == XmlPullParser.TEXT) { if (parser.next() == XmlPullParser.TEXT) {

View File

@@ -46,4 +46,28 @@ public class GitLogs {
} }
return message; return message;
} }
public String getLatestReleaseTag() {
String tag = "";
try {
URL url = new URL("https://github.com/Card-Forge/forge/releases.atom");
InputStream inputStream = url.openStream();
List<AtomReader.Entry> entries = new AtomReader().parse(inputStream);
for (AtomReader.Entry entry : entries) {
if (entry.link != null) {
try {
String val = entry.link;
tag = val.substring(val.lastIndexOf("forge"));
break;
} catch (Exception e) {
e.printStackTrace();
}
}
}
inputStream.close();
} catch (Exception e) {
e.printStackTrace();
}
return tag;
}
} }

View File

@@ -641,8 +641,7 @@ public class Main extends ForgeAndroidApplication {
@Override @Override
public String getReleaseTag() { public String getReleaseTag() {
//android doesn't have release yet on github... return new GitLogs().getLatestReleaseTag();
return "";
} }
@Override @Override