From 8ecb977629189f0bad5c223a7815ec4f323470d2 Mon Sep 17 00:00:00 2001 From: Bryson Steck Date: Wed, 9 Jun 2021 22:43:55 -0600 Subject: added new update checker, need to implement into ui --- .../me/brysonsteck/wiimmfiwatcher/Updater.java | 69 ++++++++++++++++++++++ 1 file changed, 69 insertions(+) create mode 100644 app/src/main/java/me/brysonsteck/wiimmfiwatcher/Updater.java (limited to 'app/src/main/java/me/brysonsteck/wiimmfiwatcher/Updater.java') diff --git a/app/src/main/java/me/brysonsteck/wiimmfiwatcher/Updater.java b/app/src/main/java/me/brysonsteck/wiimmfiwatcher/Updater.java new file mode 100644 index 0000000..eaa4d0c --- /dev/null +++ b/app/src/main/java/me/brysonsteck/wiimmfiwatcher/Updater.java @@ -0,0 +1,69 @@ +package me.brysonsteck.wiimmfiwatcher; + +import com.google.gson.JsonElement; +import com.google.gson.JsonObject; +import com.google.gson.JsonParser; + +import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStreamReader; +import java.net.URL; +import java.net.URLConnection; + +public class Updater { + + public boolean outdated = false; + public String newestRelease; + public String githubRelease; + public String playStore = "https://play.google.com/store/apps/details?id=me.brysonsteck.wiimmfiwatcher"; + + public Updater() { + try { + String json = urlReader(); + JsonElement root = new JsonParser().parse(json); + JsonObject rootObj = root.getAsJsonObject(); + newestRelease = rootObj.get("current-release").getAsString(); + githubRelease = rootObj.get("github-release").getAsString(); + } catch (IOException e) { + System.out.println("An error has occurred while attempting to check for updates."); + e.printStackTrace(); + } + } + + public String urlReader() throws IOException { + URL website = new URL("https://brysonsteck.net/watcher.json"); + URLConnection connection = website.openConnection(); + BufferedReader in = new BufferedReader( + new InputStreamReader( + connection.getInputStream())); + + StringBuilder response = new StringBuilder(); + String inputLine; + + while ((inputLine = in.readLine()) != null) + response.append(inputLine); + + in.close(); + + return response.toString(); + + } + + public void compareRelease(String deviceRelease) { + if (!deviceRelease.equals(newestRelease)) { + outdated = true; + } + } + + public boolean isOutdated() { + return outdated; + } + + public String getNewestRelease() { + return newestRelease; + } + + public String getGithubRelease() { + return githubRelease; + } +} -- cgit v1.2.3 From 71975e98f4b2de35af051577d5d11d935b108374 Mon Sep 17 00:00:00 2001 From: Bryson Steck Date: Mon, 28 Jun 2021 22:31:33 -0600 Subject: added update dialog --- app/src/main/java/me/brysonsteck/wiimmfiwatcher/Updater.java | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) (limited to 'app/src/main/java/me/brysonsteck/wiimmfiwatcher/Updater.java') diff --git a/app/src/main/java/me/brysonsteck/wiimmfiwatcher/Updater.java b/app/src/main/java/me/brysonsteck/wiimmfiwatcher/Updater.java index eaa4d0c..eb3e813 100644 --- a/app/src/main/java/me/brysonsteck/wiimmfiwatcher/Updater.java +++ b/app/src/main/java/me/brysonsteck/wiimmfiwatcher/Updater.java @@ -22,8 +22,12 @@ public class Updater { String json = urlReader(); JsonElement root = new JsonParser().parse(json); JsonObject rootObj = root.getAsJsonObject(); - newestRelease = rootObj.get("current-release").getAsString(); - githubRelease = rootObj.get("github-release").getAsString(); + JsonElement softwareElement = rootObj.getAsJsonObject("wiimmfi-watcher"); + JsonObject softwareObj = softwareElement.getAsJsonObject(); + newestRelease = softwareObj.get("current-release").getAsString(); + newestRelease = newestRelease.replace("\"", ""); + githubRelease = softwareObj.get("github-release").getAsString(); + githubRelease = githubRelease.replace("\"", ""); } catch (IOException e) { System.out.println("An error has occurred while attempting to check for updates."); e.printStackTrace(); @@ -31,7 +35,7 @@ public class Updater { } public String urlReader() throws IOException { - URL website = new URL("https://brysonsteck.net/watcher.json"); + URL website = new URL("https://brysonsteck.net/updates.json"); URLConnection connection = website.openConnection(); BufferedReader in = new BufferedReader( new InputStreamReader( -- cgit v1.2.3