Android: Create analytics dialog fragment

This commit is contained in:
Charles Lombardo 2023-01-26 20:42:39 -05:00
parent f056cec859
commit 14c7d81b54
2 changed files with 34 additions and 16 deletions

View File

@ -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"
}
}

View File

@ -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())
{