diff options
author | Bryson Steck <steck.bryson@gmail.com> | 2021-06-28 23:11:38 -0600 |
---|---|---|
committer | Bryson Steck <steck.bryson@gmail.com> | 2021-06-28 23:11:38 -0600 |
commit | 1643931494c2b9411a05fdefe8c03416fe072142 (patch) | |
tree | aa630be5609065b17b3bcaea0069c11972a49fbc /app/src/main/java/me/brysonsteck/wiimmfiwatcher/MainActivity.java | |
parent | 3c2a356b1a57cdc3c9264a0bab6d4e6c6bb265e1 (diff) | |
parent | 3c10ea67a3dab3d221e609d8dc6bc0df145f1220 (diff) | |
download | wiimmfi-watcher-1.1.4.tar wiimmfi-watcher-1.1.4.tar.gz wiimmfi-watcher-1.1.4.tar.bz2 |
released 1.1.41.1.4
Diffstat (limited to 'app/src/main/java/me/brysonsteck/wiimmfiwatcher/MainActivity.java')
-rw-r--r-- | app/src/main/java/me/brysonsteck/wiimmfiwatcher/MainActivity.java | 68 |
1 files changed, 65 insertions, 3 deletions
diff --git a/app/src/main/java/me/brysonsteck/wiimmfiwatcher/MainActivity.java b/app/src/main/java/me/brysonsteck/wiimmfiwatcher/MainActivity.java index 8084714..e98856b 100644 --- a/app/src/main/java/me/brysonsteck/wiimmfiwatcher/MainActivity.java +++ b/app/src/main/java/me/brysonsteck/wiimmfiwatcher/MainActivity.java @@ -1,20 +1,26 @@ package me.brysonsteck.wiimmfiwatcher; -import android.os.Build; +import android.content.DialogInterface; +import android.content.Intent; +import android.net.Uri; import android.os.Bundle; import android.view.View; import android.view.WindowManager; -import androidx.annotation.RequiresApi; import androidx.appcompat.app.AppCompatActivity; import androidx.room.Room; +import com.google.android.material.dialog.MaterialAlertDialogBuilder; + import me.brysonsteck.wiimmfiwatcher.database.AppDatabase; +import me.brysonsteck.wiimmfiwatcher.fragments.AboutFragment; +import me.brysonsteck.wiimmfiwatcher.fragments.WatchCodeFragment; public class MainActivity extends AppCompatActivity { AppDatabase database; + final MaterialAlertDialogBuilder[] dialog = new MaterialAlertDialogBuilder[1]; + boolean shownUpdate = false; - @RequiresApi(api = Build.VERSION_CODES.LOLLIPOP) @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); @@ -47,6 +53,62 @@ public class MainActivity extends AppCompatActivity { }); } + + @Override + protected void onStart() { + super.onStart(); + final String[] newestRelease = {""}; + final boolean[] outdated = {false}; + Thread thread = new Thread() { + public void run() { + 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---------------------------------------------------------------"); + } + newestRelease[0] = updater.getNewestRelease(); + outdated[0] = updater.isOutdated(); + } + }; + thread.start(); + try { + thread.join(); + } catch (InterruptedException e) { + e.printStackTrace(); + } + if (outdated[0] && !shownUpdate) { + shownUpdate = true; + final String appPackageName = getPackageName(); // getPackageName() from Context or Activity object + new MaterialAlertDialogBuilder(this) + .setTitle(R.string.update_title) + .setMessage(getResources().getString(R.string.update_message, newestRelease[0])) + .setNegativeButton(getResources().getString(R.string.update_negative), new DialogInterface.OnClickListener() { + @Override + public void onClick(DialogInterface dialog, int which) { + } + }) + .setPositiveButton(getResources().getString(R.string.update_positive), new DialogInterface.OnClickListener() { + @Override + public void onClick(DialogInterface dialog, int which) { + try { + startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("market://details?id=" + appPackageName))); + } catch (android.content.ActivityNotFoundException anfe) { + startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("https://play.google.com/store/apps/details?id=" + appPackageName))); + } + } + }) + .show(); + } + + } + @Override protected void onStop() { super.onStop(); |