update AtomReader, add support releaseTag on android

This commit is contained in:
Anthony Calosa
2024-10-25 18:03:46 +08:00
parent 1f05a5a295
commit 6334c9f922
10 changed files with 41 additions and 35 deletions

View File

@@ -12,12 +12,12 @@ import java.util.Date;
import java.util.List; import java.util.List;
public class RSSReader { public class RSSReader {
public static String getCommitLog(Date buildDateOriginal, Date maxDate) { public static String getCommitLog(String commitsAtom, Date buildDateOriginal, Date maxDate) {
String message = ""; String message = "";
SimpleDateFormat simpleDate = TextUtil.getSimpleDate(); SimpleDateFormat simpleDate = TextUtil.getSimpleDate();
try { try {
RssReader reader = new RssReader(); RssReader reader = new RssReader();
URL url = new URL("https://github.com/Card-Forge/forge/commits/master.atom"); URL url = new URL(commitsAtom);
InputStream inputStream = url.openStream(); InputStream inputStream = url.openStream();
List<Item> items = reader.read(inputStream).toList(); List<Item> items = reader.read(inputStream).toList();
StringBuilder logs = new StringBuilder(); StringBuilder logs = new StringBuilder();
@@ -49,11 +49,11 @@ public class RSSReader {
} }
return message; return message;
} }
public static String getLatestReleaseTag() { public static String getLatestReleaseTag(String releaseAtom) {
String tag = ""; String tag = "";
try { try {
RssReader reader = new RssReader(); RssReader reader = new RssReader();
URL url = new URL("https://github.com/Card-Forge/forge/releases.atom"); URL url = new URL(releaseAtom);
InputStream inputStream = url.openStream(); InputStream inputStream = url.openStream();
List<Item> items = reader.read(inputStream).toList(); List<Item> items = reader.read(inputStream).toList();
for (Item i : items) { for (Item i : items) {

View File

@@ -10,10 +10,10 @@ import java.util.Date;
import java.util.List; import java.util.List;
public class GitLogs { public class GitLogs {
public String getLatest(Date buildDateOriginal, Date maxDate) { public String getLatest(String commitsAtom, Date buildDateOriginal, Date maxDate) {
String message = ""; String message = "";
try { try {
URL url = new URL("https://github.com/Card-Forge/forge/commits/master.atom"); URL url = new URL(commitsAtom);
InputStream inputStream = url.openStream(); InputStream inputStream = url.openStream();
List<AtomReader.Entry> entries = new AtomReader().parse(inputStream); List<AtomReader.Entry> entries = new AtomReader().parse(inputStream);
StringBuilder logs = new StringBuilder(); StringBuilder logs = new StringBuilder();
@@ -47,10 +47,10 @@ public class GitLogs {
return message; return message;
} }
public String getLatestReleaseTag() { public String getLatestReleaseTag(String releaseAtom) {
String tag = ""; String tag = "";
try { try {
URL url = new URL("https://github.com/Card-Forge/forge/releases.atom"); URL url = new URL(releaseAtom);
InputStream inputStream = url.openStream(); InputStream inputStream = url.openStream();
List<AtomReader.Entry> entries = new AtomReader().parse(inputStream); List<AtomReader.Entry> entries = new AtomReader().parse(inputStream);
for (AtomReader.Entry entry : entries) { for (AtomReader.Entry entry : entries) {

View File

@@ -635,13 +635,13 @@ public class Main extends ForgeAndroidApplication {
} }
@Override @Override
public String getLatestChanges(Date buildDateOriginal, Date maxDate) { public String getLatestChanges(String commitsAtom, Date buildDateOriginal, Date maxDate) {
return new GitLogs().getLatest(buildDateOriginal, maxDate); return new GitLogs().getLatest(commitsAtom, buildDateOriginal, maxDate);
} }
@Override @Override
public String getReleaseTag() { public String getReleaseTag(String releaseAtom) {
return new GitLogs().getLatestReleaseTag(); return new GitLogs().getLatestReleaseTag(releaseAtom);
} }
@Override @Override

View File

@@ -19,6 +19,8 @@ import forge.util.RSSReader;
import java.util.concurrent.CompletableFuture; import java.util.concurrent.CompletableFuture;
import static forge.localinstance.properties.ForgeConstants.GITHUB_COMMITS_URL_ATOM;
/** /**
* Controls the utilities submenu in the home UI. * Controls the utilities submenu in the home UI.
* *
@@ -30,7 +32,7 @@ public enum CSubmenuDownloaders implements ICDoc {
SINGLETON_INSTANCE; SINGLETON_INSTANCE;
private final UiCommand cmdLicensing = VSubmenuDownloaders.SINGLETON_INSTANCE::showLicensing; private final UiCommand cmdLicensing = VSubmenuDownloaders.SINGLETON_INSTANCE::showLicensing;
private final UiCommand cmdCheckForUpdates = () -> new AutoUpdater(false).attemptToUpdate(CompletableFuture.supplyAsync(() -> RSSReader.getCommitLog(null, null))); private final UiCommand cmdCheckForUpdates = () -> new AutoUpdater(false).attemptToUpdate(CompletableFuture.supplyAsync(() -> RSSReader.getCommitLog(GITHUB_COMMITS_URL_ATOM, null, null)));
private final UiCommand cmdPicDownload = () -> new GuiDownloader(new GuiDownloadPicturesLQ()).show(); private final UiCommand cmdPicDownload = () -> new GuiDownloader(new GuiDownloadPicturesLQ()).show();
private final UiCommand cmdPicDownloadHQ = () -> new GuiDownloader(new GuiDownloadPicturesHQ()).show(); private final UiCommand cmdPicDownloadHQ = () -> new GuiDownloader(new GuiDownloadPicturesHQ()).show();

View File

@@ -29,6 +29,8 @@ import forge.util.BuildInfo;
import forge.util.Localizer; import forge.util.Localizer;
import forge.util.RSSReader; import forge.util.RSSReader;
import static forge.localinstance.properties.ForgeConstants.GITHUB_COMMITS_URL_ATOM;
@SuppressWarnings("serial") @SuppressWarnings("serial")
public abstract class FTitleBarBase extends SkinnedMenuBar { public abstract class FTitleBarBase extends SkinnedMenuBar {
protected static final int visibleHeight = 27; protected static final int visibleHeight = 27;
@@ -431,7 +433,7 @@ public abstract class FTitleBarBase extends SkinnedMenuBar {
@Override @Override
protected void onClick() { protected void onClick() {
try { try {
new AutoUpdater(false).attemptToUpdate(CompletableFuture.supplyAsync(() -> RSSReader.getCommitLog(null, null))); new AutoUpdater(false).attemptToUpdate(CompletableFuture.supplyAsync(() -> RSSReader.getCommitLog(GITHUB_COMMITS_URL_ATOM, null, null)));
} catch (Exception e) { } catch (Exception e) {
e.printStackTrace(); e.printStackTrace();
} }

View File

@@ -80,12 +80,12 @@ public class Main extends IOSApplication.Delegate {
} }
@Override @Override
public String getLatestChanges(Date buildDateOriginal, Date maxDate) { public String getLatestChanges(String commitsAtom, Date buildDateOriginal, Date maxDate) {
return ""; return "";
} }
@Override @Override
public String getReleaseTag() { public String getReleaseTag(String releaseAtom) {
return ""; return "";
} }

View File

@@ -52,13 +52,13 @@ public class Main {
} }
@Override @Override
public String getLatestChanges(Date buildDateOriginal, Date max) { public String getLatestChanges(String commitsAtom, Date buildDateOriginal, Date max) {
return RSSReader.getCommitLog(buildDateOriginal, max); return RSSReader.getCommitLog(commitsAtom, buildDateOriginal, max);
} }
@Override @Override
public String getReleaseTag() { public String getReleaseTag(String releaseAtom) {
return RSSReader.getLatestReleaseTag(); return RSSReader.getLatestReleaseTag(releaseAtom);
} }
@Override @Override

View File

@@ -23,6 +23,9 @@ import forge.gui.util.SOptionPane;
import forge.localinstance.properties.ForgeConstants; import forge.localinstance.properties.ForgeConstants;
import forge.util.FileUtil; import forge.util.FileUtil;
import static forge.localinstance.properties.ForgeConstants.GITHUB_COMMITS_URL_ATOM;
import static forge.localinstance.properties.ForgeConstants.GITHUB_RELEASES_URL_ATOM;
public class AssetsDownloader { public class AssetsDownloader {
private final static ImmutableList<String> downloadIgnoreExit = ImmutableList.of("Download", "Ignore", "Exit"); private final static ImmutableList<String> downloadIgnoreExit = ImmutableList.of("Download", "Ignore", "Exit");
private final static ImmutableList<String> downloadExit = ImmutableList.of("Download", "Exit"); private final static ImmutableList<String> downloadExit = ImmutableList.of("Download", "Exit");
@@ -40,7 +43,7 @@ public class AssetsDownloader {
} }
} }
//currently for desktop/mobile-dev release on github //currently for desktop/mobile-dev release on github
String releaseTag = Forge.getDeviceAdapter().getReleaseTag(); final String releaseTag = Forge.getDeviceAdapter().getReleaseTag(GITHUB_RELEASES_URL_ATOM);
final String packageSize = GuiBase.isAndroid() ? "160MB" : "270MB"; final String packageSize = GuiBase.isAndroid() ? "160MB" : "270MB";
final String apkSize = "12MB"; final String apkSize = "12MB";
@@ -100,7 +103,7 @@ public class AssetsDownloader {
message += " If so, you may want to connect to wifi first. The download is around " + (GuiBase.isAndroid() ? apkSize : packageSize) + "."; message += " If so, you may want to connect to wifi first. The download is around " + (GuiBase.isAndroid() ? apkSize : packageSize) + ".";
} }
if (!GuiBase.isAndroid()) { if (!GuiBase.isAndroid()) {
message += Forge.getDeviceAdapter().getLatestChanges(null, null); message += Forge.getDeviceAdapter().getLatestChanges(GITHUB_COMMITS_URL_ATOM, null, null);
} }
//failed to grab latest github tag //failed to grab latest github tag
if (!isSnapshots && releaseTag.isEmpty()) { if (!isSnapshots && releaseTag.isEmpty()) {
@@ -129,8 +132,7 @@ public class AssetsDownloader {
if (!GuiBase.isAndroid()) if (!GuiBase.isAndroid())
run(runnable); run(runnable);
} }
} } catch (Exception e) {
catch (Exception e) {
e.printStackTrace(); e.printStackTrace();
if (!GuiBase.isAndroid()) { if (!GuiBase.isAndroid()) {
run(runnable); run(runnable);
@@ -167,8 +169,7 @@ public class AssetsDownloader {
if (!versionFile.exists()) { if (!versionFile.exists()) {
try { try {
versionFile.file().createNewFile(); versionFile.file().createNewFile();
} } catch (IOException e) {
catch (IOException e) {
e.printStackTrace(); e.printStackTrace();
Forge.isMobileAdventureMode = Forge.advStartup; Forge.isMobileAdventureMode = Forge.advStartup;
Forge.exitAnimation(false); //can't continue if this fails Forge.exitAnimation(false); //can't continue if this fails
@@ -202,7 +203,7 @@ public class AssetsDownloader {
SimpleDateFormat simpleDate = TextUtil.getSimpleDate(); SimpleDateFormat simpleDate = TextUtil.getSimpleDate();
simpleDate.setTimeZone(TimeZone.getDefault()); simpleDate.setTimeZone(TimeZone.getDefault());
build += "Installed resources date: " + simpleDate.format(calendar.getTime()) + "\n\n"; build += "Installed resources date: " + simpleDate.format(calendar.getTime()) + "\n\n";
log = Forge.getDeviceAdapter().getLatestChanges(null, null); log = Forge.getDeviceAdapter().getLatestChanges(GITHUB_COMMITS_URL_ATOM, null, null);
} catch (Exception e) { } catch (Exception e) {
e.printStackTrace(); e.printStackTrace();
} }
@@ -218,8 +219,7 @@ public class AssetsDownloader {
message = "Updated resource files cannot be downloaded due to lack of internet connection.\n\n"; message = "Updated resource files cannot be downloaded due to lack of internet connection.\n\n";
if (canIgnoreDownload) { if (canIgnoreDownload) {
message += "You can continue without this download, but you may miss out on card fixes or experience other problems."; message += "You can continue without this download, but you may miss out on card fixes or experience other problems.";
} } else {
else {
message += "You cannot start the app since you haven't previously downloaded these files."; message += "You cannot start the app since you haven't previously downloaded these files.";
} }
switch (SOptionPane.showOptionDialog(message, "No Internet Connection", null, ImmutableList.of("Ok"))) { switch (SOptionPane.showOptionDialog(message, "No Internet Connection", null, ImmutableList.of("Ok"))) {
@@ -238,8 +238,7 @@ public class AssetsDownloader {
"This download is around " + packageSize + ", "; "This download is around " + packageSize + ", ";
if (Forge.getDeviceAdapter().isConnectedToWifi()) { if (Forge.getDeviceAdapter().isConnectedToWifi()) {
message += "which shouldn't take long if your wifi connection is good."; message += "which shouldn't take long if your wifi connection is good.";
} } else {
else {
message += "so it's highly recommended that you connect to wifi first."; message += "so it's highly recommended that you connect to wifi first.";
} }
final List<String> options; final List<String> options;
@@ -300,6 +299,7 @@ public class AssetsDownloader {
Forge.isMobileAdventureMode = Forge.advStartup; Forge.isMobileAdventureMode = Forge.advStartup;
Forge.exitAnimation(true); Forge.exitAnimation(true);
} }
private static void run(Runnable toRun) { private static void run(Runnable toRun) {
if (toRun != null) { if (toRun != null) {
if (!GuiBase.isAndroid()) { if (!GuiBase.isAndroid()) {

View File

@@ -14,8 +14,8 @@ public interface IDeviceAdapter {
boolean isTablet(); boolean isTablet();
String getDownloadsDir(); String getDownloadsDir();
String getVersionString(); String getVersionString();
String getLatestChanges(Date buildDateOriginal, Date maxDate); String getLatestChanges(String commitsAtom, Date buildDateOriginal, Date maxDate);
String getReleaseTag(); String getReleaseTag(String releaseAtom);
boolean openFile(String filename); boolean openFile(String filename);
void setLandscapeMode(boolean landscapeMode); void setLandscapeMode(boolean landscapeMode);
void preventSystemSleep(boolean preventSleep); void preventSystemSleep(boolean preventSleep);

View File

@@ -25,6 +25,8 @@ import java.util.Collections;
import java.util.Map; import java.util.Map;
public final class ForgeConstants { public final class ForgeConstants {
public static final String GITHUB_RELEASES_URL_ATOM = "https://github.com/Card-Forge/forge/releases.atom";
public static final String GITHUB_COMMITS_URL_ATOM = "https://github.com/Card-Forge/forge/commits/master.atom";
public static final String PATH_SEPARATOR = File.separator; public static final String PATH_SEPARATOR = File.separator;
public static final String ASSETS_DIR = GuiBase.getInterface().getAssetsDir(); public static final String ASSETS_DIR = GuiBase.getInterface().getAssetsDir();
public static final String PROFILE_FILE = ASSETS_DIR + "forge.profile.properties"; public static final String PROFILE_FILE = ASSETS_DIR + "forge.profile.properties";