From ead1be4728544d0207664646705da1d99af8b559 Mon Sep 17 00:00:00 2001 From: Connor McLaughlin Date: Mon, 7 Dec 2020 01:07:13 +1000 Subject: [PATCH] Android: Add version, GitHub, Discord to app --- .../app/src/cpp/android_host_interface.cpp | 5 +++ .../duckstation/AndroidHostInterface.java | 1 + .../stenzek/duckstation/MainActivity.java | 39 +++++++++++++++++++ android/app/src/main/res/menu/menu_main.xml | 9 +++++ 4 files changed, 54 insertions(+) diff --git a/android/app/src/cpp/android_host_interface.cpp b/android/app/src/cpp/android_host_interface.cpp index dd7b411db..700754e9b 100644 --- a/android/app/src/cpp/android_host_interface.cpp +++ b/android/app/src/cpp/android_host_interface.cpp @@ -793,6 +793,11 @@ DEFINE_JNI_ARGS_METHOD(jstring, AndroidHostInterface_getScmVersion, jobject unus return env->NewStringUTF(g_scm_tag_str); } +DEFINE_JNI_ARGS_METHOD(jstring, AndroidHostInterface_getFullScmVersion, jobject unused) +{ + return env->NewStringUTF(SmallString::FromFormat("DuckStation for Android %s (%s)\nBuilt %s %s", g_scm_tag_str, g_scm_branch_str, __DATE__, __TIME__)); +} + DEFINE_JNI_ARGS_METHOD(jobject, AndroidHostInterface_create, jobject unused, jobject context_object, jstring user_directory) { diff --git a/android/app/src/main/java/com/github/stenzek/duckstation/AndroidHostInterface.java b/android/app/src/main/java/com/github/stenzek/duckstation/AndroidHostInterface.java index 2a06b8d18..b0713ba47 100644 --- a/android/app/src/main/java/com/github/stenzek/duckstation/AndroidHostInterface.java +++ b/android/app/src/main/java/com/github/stenzek/duckstation/AndroidHostInterface.java @@ -19,6 +19,7 @@ public class AndroidHostInterface { private Context mContext; static public native String getScmVersion(); + static public native String getFullScmVersion(); static public native AndroidHostInterface create(Context context, String userDirectory); 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 4ed992bc7..ec5c1aa22 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 @@ -1,6 +1,8 @@ package com.github.stenzek.duckstation; import android.Manifest; +import android.content.ClipData; +import android.content.ClipboardManager; import android.content.Intent; import android.content.SharedPreferences; import android.content.pm.PackageManager; @@ -170,6 +172,15 @@ public class MainActivity extends AppCompatActivity { Intent intent = new Intent(this, SettingsActivity.class); startActivity(intent); return true; + } else if (id == R.id.action_show_version) { + showVersion(); + return true; + } else if (id == R.id.action_github_respository) { + openGithubRepository(); + return true; + } else if (id == R.id.action_discord_server) { + openDiscordServer(); + return true; } return super.onOptionsItemSelected(item); @@ -377,4 +388,32 @@ public class MainActivity extends AppCompatActivity { .create() .show(); } + + private void showVersion() { + final String message = AndroidHostInterface.getFullScmVersion(); + new AlertDialog.Builder(this) + .setTitle("Version") + .setMessage(message) + .setPositiveButton("OK", (dialog, button) -> { + }) + .setNeutralButton("Copy", (dialog, button) -> { + ClipboardManager clipboard = (ClipboardManager) getSystemService(CLIPBOARD_SERVICE); + if (clipboard != null) + clipboard.setPrimaryClip(ClipData.newPlainText("Version", message)); + }) + .create() + .show(); + } + + private void openGithubRepository() { + final String url = "https://github.com/stenzek/duckstation"; + final Intent browserIntent = new Intent(Intent.ACTION_VIEW, Uri.parse(url)); + startActivity(browserIntent); + } + + private void openDiscordServer() { + final String url = "https://discord.gg/Buktv3t"; + final Intent browserIntent = new Intent(Intent.ACTION_VIEW, Uri.parse(url)); + startActivity(browserIntent); + } } diff --git a/android/app/src/main/res/menu/menu_main.xml b/android/app/src/main/res/menu/menu_main.xml index 9dadf7843..1ff712b1d 100644 --- a/android/app/src/main/res/menu/menu_main.xml +++ b/android/app/src/main/res/menu/menu_main.xml @@ -26,6 +26,15 @@ + + +