From 14c7d81b545f42b7bec298bbc84ee624946c5547 Mon Sep 17 00:00:00 2001 From: Charles Lombardo Date: Thu, 26 Jan 2023 20:42:39 -0500 Subject: [PATCH] Android: Create analytics dialog fragment --- .../dolphinemu/dialogs/AnalyticsDialog.kt | 29 +++++++++++++++++++ .../dolphinemu/utils/Analytics.java | 21 ++++---------- 2 files changed, 34 insertions(+), 16 deletions(-) create mode 100644 Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/dialogs/AnalyticsDialog.kt diff --git a/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/dialogs/AnalyticsDialog.kt b/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/dialogs/AnalyticsDialog.kt new file mode 100644 index 0000000000..51e7b9b279 --- /dev/null +++ b/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/dialogs/AnalyticsDialog.kt @@ -0,0 +1,29 @@ +// SPDX-License-Identifier: GPL-2.0-or-later + +package org.dolphinemu.dolphinemu.dialogs + +import android.app.Dialog +import android.os.Bundle +import androidx.fragment.app.DialogFragment +import com.google.android.material.dialog.MaterialAlertDialogBuilder +import org.dolphinemu.dolphinemu.R +import org.dolphinemu.dolphinemu.utils.Analytics + +class AnalyticsDialog : DialogFragment() { + override fun onCreateDialog(savedInstanceState: Bundle?): Dialog { + val dialog = MaterialAlertDialogBuilder(requireContext()) + .setTitle(requireContext().getString(R.string.analytics)) + .setMessage(requireContext().getString(R.string.analytics_desc)) + .setPositiveButton(R.string.yes) { _, _ -> + Analytics.firstAnalyticsAdd(true) + } + .setNegativeButton(R.string.no) { _, _ -> + Analytics.firstAnalyticsAdd(false) + } + return dialog.create() + } + + companion object { + const val TAG = "AnalyticsDialog" + } +} diff --git a/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/utils/Analytics.java b/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/utils/Analytics.java index 961620213a..b1537f260e 100644 --- a/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/utils/Analytics.java +++ b/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/utils/Analytics.java @@ -2,17 +2,16 @@ package org.dolphinemu.dolphinemu.utils; -import android.content.Context; import android.os.Build; import androidx.annotation.Keep; +import androidx.fragment.app.FragmentActivity; import com.android.volley.Request; import com.android.volley.toolbox.StringRequest; -import com.google.android.material.dialog.MaterialAlertDialogBuilder; import org.dolphinemu.dolphinemu.DolphinApplication; -import org.dolphinemu.dolphinemu.R; +import org.dolphinemu.dolphinemu.dialogs.AnalyticsDialog; import org.dolphinemu.dolphinemu.features.settings.model.BooleanSetting; import org.dolphinemu.dolphinemu.features.settings.model.Settings; @@ -23,28 +22,18 @@ public class Analytics private static final String DEVICE_MODEL = "DEVICE_MODEL"; private static final String DEVICE_TYPE = "DEVICE_TYPE"; - public static void checkAnalyticsInit(Context context) + public static void checkAnalyticsInit(FragmentActivity activity) { new AfterDirectoryInitializationRunner().runWithoutLifecycle(() -> { if (!BooleanSetting.MAIN_ANALYTICS_PERMISSION_ASKED.getBooleanGlobal()) { - showMessage(context); + new AnalyticsDialog().show(activity.getSupportFragmentManager(), AnalyticsDialog.TAG); } }); } - private static void showMessage(Context context) - { - new MaterialAlertDialogBuilder(context) - .setTitle(context.getString(R.string.analytics)) - .setMessage(context.getString(R.string.analytics_desc)) - .setPositiveButton(R.string.yes, (dialogInterface, i) -> firstAnalyticsAdd(true)) - .setNegativeButton(R.string.no, (dialogInterface, i) -> firstAnalyticsAdd(false)) - .show(); - } - - private static void firstAnalyticsAdd(boolean enabled) + public static void firstAnalyticsAdd(boolean enabled) { try (Settings settings = new Settings()) {