From 5977cfeb9bfe5efcc3457d3fdf2d10f24e5ac395 Mon Sep 17 00:00:00 2001 From: Bryson Steck Date: Wed, 11 Aug 2021 21:09:02 -0600 Subject: preparing settings fragment, added new "null" catch for updater" --- .../main/java/me/brysonsteck/wiimmfiwatcher/MainActivity.java | 10 ++++++++++ app/src/main/java/me/brysonsteck/wiimmfiwatcher/Updater.java | 8 +++++++- .../brysonsteck/wiimmfiwatcher/preferences/ParseSettings.java | 4 ++++ .../wiimmfiwatcher/preferences/SettingsFragment.java | 4 ++++ 4 files changed, 25 insertions(+), 1 deletion(-) create mode 100644 app/src/main/java/me/brysonsteck/wiimmfiwatcher/preferences/ParseSettings.java create mode 100644 app/src/main/java/me/brysonsteck/wiimmfiwatcher/preferences/SettingsFragment.java diff --git a/app/src/main/java/me/brysonsteck/wiimmfiwatcher/MainActivity.java b/app/src/main/java/me/brysonsteck/wiimmfiwatcher/MainActivity.java index e98856b..878de62 100644 --- a/app/src/main/java/me/brysonsteck/wiimmfiwatcher/MainActivity.java +++ b/app/src/main/java/me/brysonsteck/wiimmfiwatcher/MainActivity.java @@ -6,6 +6,7 @@ import android.net.Uri; import android.os.Bundle; import android.view.View; import android.view.WindowManager; +import android.widget.Toast; import androidx.appcompat.app.AppCompatActivity; import androidx.room.Room; @@ -59,6 +60,7 @@ public class MainActivity extends AppCompatActivity { super.onStart(); final String[] newestRelease = {""}; final boolean[] outdated = {false}; + final boolean[] failed = {false}; Thread thread = new Thread() { public void run() { Updater updater = new Updater(); @@ -68,6 +70,10 @@ public class MainActivity extends AppCompatActivity { System.out.println("\tA newer version of Wiimmfi Watcher is available! (" + updater.getNewestRelease() + ")"); System.out.println("\tView the release notes and the source code here: " + updater.getGithubRelease()); System.out.println("\t---------------------------------------------------------------"); + } else if (updater.hasFailed()) { + System.out.println("---------------------------------------------------------------"); + System.out.println("\t\t An error has occurred while getting information from the update server."); + System.out.println("\t\t---------------------------------------------------------------"); } else { System.out.println("---------------------------------------------------------------"); System.out.println("\t\t" + updater.getNewestRelease() + " is the latest release of Wiimmfi Watcher."); @@ -75,6 +81,7 @@ public class MainActivity extends AppCompatActivity { } newestRelease[0] = updater.getNewestRelease(); outdated[0] = updater.isOutdated(); + failed[0] = updater.hasFailed(); } }; thread.start(); @@ -105,6 +112,9 @@ public class MainActivity extends AppCompatActivity { } }) .show(); + } else if (failed[0] && !shownUpdate) { + shownUpdate = true; + Toast.makeText(this, "An error occurred while checking for updates for Wiimmfi Watcher.", Toast.LENGTH_LONG).show(); } } diff --git a/app/src/main/java/me/brysonsteck/wiimmfiwatcher/Updater.java b/app/src/main/java/me/brysonsteck/wiimmfiwatcher/Updater.java index eb3e813..78e97c1 100644 --- a/app/src/main/java/me/brysonsteck/wiimmfiwatcher/Updater.java +++ b/app/src/main/java/me/brysonsteck/wiimmfiwatcher/Updater.java @@ -13,6 +13,7 @@ import java.net.URLConnection; public class Updater { public boolean outdated = false; + public boolean failed = false; public String newestRelease; public String githubRelease; public String playStore = "https://play.google.com/store/apps/details?id=me.brysonsteck.wiimmfiwatcher"; @@ -54,7 +55,10 @@ public class Updater { } public void compareRelease(String deviceRelease) { - if (!deviceRelease.equals(newestRelease)) { + if (newestRelease == null) { + failed = true; + } + else if (!deviceRelease.equals(newestRelease)) { outdated = true; } } @@ -63,6 +67,8 @@ public class Updater { return outdated; } + public boolean hasFailed() { return failed; } + public String getNewestRelease() { return newestRelease; } diff --git a/app/src/main/java/me/brysonsteck/wiimmfiwatcher/preferences/ParseSettings.java b/app/src/main/java/me/brysonsteck/wiimmfiwatcher/preferences/ParseSettings.java new file mode 100644 index 0000000..78ecced --- /dev/null +++ b/app/src/main/java/me/brysonsteck/wiimmfiwatcher/preferences/ParseSettings.java @@ -0,0 +1,4 @@ +package me.brysonsteck.wiimmfiwatcher.preferences; + +public class ParseSettings { +} diff --git a/app/src/main/java/me/brysonsteck/wiimmfiwatcher/preferences/SettingsFragment.java b/app/src/main/java/me/brysonsteck/wiimmfiwatcher/preferences/SettingsFragment.java new file mode 100644 index 0000000..e24236b --- /dev/null +++ b/app/src/main/java/me/brysonsteck/wiimmfiwatcher/preferences/SettingsFragment.java @@ -0,0 +1,4 @@ +package me.brysonsteck.wiimmfiwatcher.preferences; + +public class SettingsFragment { +} -- cgit v1.2.3