added new update checker, need to implement into ui
This commit is contained in:
parent
2abb9ca557
commit
8ecb977629
3 changed files with 92 additions and 3 deletions
|
@ -11,8 +11,8 @@ android {
|
||||||
applicationId "me.brysonsteck.wiimmfiwatcher"
|
applicationId "me.brysonsteck.wiimmfiwatcher"
|
||||||
minSdkVersion 19
|
minSdkVersion 19
|
||||||
targetSdkVersion 30
|
targetSdkVersion 30
|
||||||
versionCode 5
|
versionCode 6
|
||||||
versionName "1.1.3"
|
versionName "1.1.4"
|
||||||
|
|
||||||
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
|
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
|
||||||
}
|
}
|
||||||
|
@ -33,6 +33,7 @@ android {
|
||||||
}
|
}
|
||||||
|
|
||||||
dependencies {
|
dependencies {
|
||||||
|
implementation 'com.google.code.gson:gson:2.8.6'
|
||||||
def lifecycle_version = "2.3.1"
|
def lifecycle_version = "2.3.1"
|
||||||
|
|
||||||
// ViewModel
|
// ViewModel
|
||||||
|
|
|
@ -16,7 +16,6 @@ import me.brysonsteck.wiimmfiwatcher.fragments.WatchCodeFragment;
|
||||||
public class MainActivity extends AppCompatActivity {
|
public class MainActivity extends AppCompatActivity {
|
||||||
AppDatabase database;
|
AppDatabase database;
|
||||||
|
|
||||||
@RequiresApi(api = Build.VERSION_CODES.LOLLIPOP)
|
|
||||||
@Override
|
@Override
|
||||||
protected void onCreate(Bundle savedInstanceState) {
|
protected void onCreate(Bundle savedInstanceState) {
|
||||||
super.onCreate(savedInstanceState);
|
super.onCreate(savedInstanceState);
|
||||||
|
@ -49,6 +48,26 @@ public class MainActivity extends AppCompatActivity {
|
||||||
});
|
});
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void onStart() {
|
||||||
|
super.onStart();
|
||||||
|
new Thread(() -> {
|
||||||
|
Updater updater = new Updater();
|
||||||
|
updater.compareRelease(BuildConfig.VERSION_NAME);
|
||||||
|
if (updater.isOutdated()) {
|
||||||
|
System.out.println("---------------------------------------------------------------");
|
||||||
|
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 {
|
||||||
|
System.out.println("---------------------------------------------------------------");
|
||||||
|
System.out.println("\t\t" + updater.getNewestRelease() + " is the latest release of Wiimmfi Watcher.");
|
||||||
|
System.out.println("\t\t---------------------------------------------------------------");
|
||||||
|
}
|
||||||
|
}).start();
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onStop() {
|
protected void onStop() {
|
||||||
super.onStop();
|
super.onStop();
|
||||||
|
|
69
app/src/main/java/me/brysonsteck/wiimmfiwatcher/Updater.java
Normal file
69
app/src/main/java/me/brysonsteck/wiimmfiwatcher/Updater.java
Normal file
|
@ -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;
|
||||||
|
}
|
||||||
|
}
|
Reference in a new issue