From ad991c122dfdd5ecbe16bdbd65ca89722d6e6c0c Mon Sep 17 00:00:00 2001 From: Connor McLaughlin Date: Sun, 21 Mar 2021 12:33:36 +1000 Subject: [PATCH] Android: Add an update notification about controller bindings --- .../stenzek/duckstation/MainActivity.java | 1 + .../stenzek/duckstation/UpdateNotes.java | 54 +++++++++++++++++++ android/app/src/main/res/values/strings.xml | 2 + 3 files changed, 57 insertions(+) create mode 100644 android/app/src/main/java/com/github/stenzek/duckstation/UpdateNotes.java diff --git a/android/app/src/main/java/com/github/stenzek/duckstation/MainActivity.java b/android/app/src/main/java/com/github/stenzek/duckstation/MainActivity.java index 26798a762..8ba90943c 100644 --- a/android/app/src/main/java/com/github/stenzek/duckstation/MainActivity.java +++ b/android/app/src/main/java/com/github/stenzek/duckstation/MainActivity.java @@ -179,6 +179,7 @@ public class MainActivity extends AppCompatActivity { AndroidHostInterface.getInstance().setContext(this); mGameList.refresh(false, false, this); + UpdateNotes.displayUpdateNotes(this); } private void startAddGameDirectory() { diff --git a/android/app/src/main/java/com/github/stenzek/duckstation/UpdateNotes.java b/android/app/src/main/java/com/github/stenzek/duckstation/UpdateNotes.java new file mode 100644 index 000000000..6ef63878f --- /dev/null +++ b/android/app/src/main/java/com/github/stenzek/duckstation/UpdateNotes.java @@ -0,0 +1,54 @@ +package com.github.stenzek.duckstation; + +import android.app.AlertDialog; +import android.content.Intent; +import android.content.SharedPreferences; + +import androidx.preference.PreferenceManager; + +public class UpdateNotes { + private static final int VERSION_CONTROLLER_UPDATE = 1; + private static final int CURRENT_VERSION = VERSION_CONTROLLER_UPDATE; + + private static final String CONFIG_KEY = "Main/UpdateNotesVersion"; + + private static int getVersion(MainActivity parent) { + try { + final SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(parent); + return sp.getInt(CONFIG_KEY, 0); + } catch (Exception e) { + e.printStackTrace(); + return CURRENT_VERSION; + } + } + + public static void setVersion(MainActivity parent, int version) { + final SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(parent); + sp.edit().putInt(CONFIG_KEY, version).commit(); + } + + public static boolean displayUpdateNotes(MainActivity parent) { + final int version = getVersion(parent); + + if (version < VERSION_CONTROLLER_UPDATE ) { + displayControllerUpdateNotes(parent); + setVersion(parent, VERSION_CONTROLLER_UPDATE); + return true; + } + + return false; + } + + public static void displayControllerUpdateNotes(MainActivity parent) { + final AlertDialog.Builder builder = new AlertDialog.Builder(parent); + builder.setTitle(R.string.update_notes_title); + builder.setMessage(R.string.update_notes_message_version_controller_update); + builder.setPositiveButton(R.string.main_activity_yes, (dialog, which) -> { + dialog.dismiss(); + Intent intent = new Intent(parent, ControllerSettingsActivity.class); + parent.startActivity(intent); + }); + builder.setNegativeButton(R.string.main_activity_no, (dialog, which) -> dialog.dismiss()); + builder.create().show(); + } +} diff --git a/android/app/src/main/res/values/strings.xml b/android/app/src/main/res/values/strings.xml index 67bcebc1d..ccb54697e 100644 --- a/android/app/src/main/res/values/strings.xml +++ b/android/app/src/main/res/values/strings.xml @@ -312,4 +312,6 @@ Failed to import card \'%s\'. It may not be a supported format. Imported card \'%s\'. Choose Cover Image + Update Notes + This DuckStation update includes support for multiple controllers, and binding devices such as keyboards/volume buttons.\n\nYou must re-bind your controllers, otherwise they will no longer function. Do you want to do this now?