Permalink
Show file tree
Hide file tree
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Merge pull request #11496 from t895/analytics-dialog-kotlin
Android: Convert analytics dialog to Kotlin
- Loading branch information
Showing
3 changed files
with
96 additions
and
95 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -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" | ||
| } | ||
| } |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,67 @@ | ||
| // SPDX-License-Identifier: GPL-2.0-or-later | ||
|
|
||
| package org.dolphinemu.dolphinemu.utils | ||
|
|
||
| import android.os.Build | ||
| import androidx.annotation.Keep | ||
| import androidx.fragment.app.FragmentActivity | ||
| import com.android.volley.Response | ||
| import com.android.volley.toolbox.StringRequest | ||
| import org.dolphinemu.dolphinemu.DolphinApplication | ||
| import org.dolphinemu.dolphinemu.dialogs.AnalyticsDialog | ||
| import org.dolphinemu.dolphinemu.features.settings.model.BooleanSetting | ||
| import org.dolphinemu.dolphinemu.features.settings.model.Settings | ||
|
|
||
| object Analytics { | ||
| private const val DEVICE_MANUFACTURER = "DEVICE_MANUFACTURER" | ||
| private const val DEVICE_OS = "DEVICE_OS" | ||
| private const val DEVICE_MODEL = "DEVICE_MODEL" | ||
| private const val DEVICE_TYPE = "DEVICE_TYPE" | ||
|
|
||
| @JvmStatic | ||
| fun checkAnalyticsInit(activity: FragmentActivity) { | ||
| AfterDirectoryInitializationRunner().runWithoutLifecycle { | ||
| if (!BooleanSetting.MAIN_ANALYTICS_PERMISSION_ASKED.booleanGlobal) { | ||
| AnalyticsDialog().show(activity.supportFragmentManager, AnalyticsDialog.TAG) | ||
| } | ||
| } | ||
| } | ||
|
|
||
| fun firstAnalyticsAdd(enabled: Boolean) { | ||
| Settings().use { settings -> | ||
| settings.loadSettings() | ||
| BooleanSetting.MAIN_ANALYTICS_ENABLED.setBoolean(settings, enabled) | ||
| BooleanSetting.MAIN_ANALYTICS_PERMISSION_ASKED.setBoolean(settings, true) | ||
|
|
||
| // Context is set to null to avoid toasts | ||
| settings.saveSettings(null, null) | ||
| } | ||
| } | ||
|
|
||
| @Keep | ||
| @JvmStatic | ||
| fun sendReport(endpoint: String, data: ByteArray) { | ||
| val request: StringRequest = object : StringRequest( | ||
| Method.POST, | ||
| endpoint, | ||
| null, | ||
| Response.ErrorListener { Log.debug("Failed to send report") }) { | ||
| override fun getBody(): ByteArray { | ||
| return data | ||
| } | ||
| } | ||
| VolleyUtil.getQueue().add(request) | ||
| } | ||
|
|
||
| @Keep | ||
| @JvmStatic | ||
| fun getValue(key: String?): String { | ||
| return when (key) { | ||
| DEVICE_MODEL -> Build.MODEL | ||
| DEVICE_MANUFACTURER -> Build.MANUFACTURER | ||
| DEVICE_OS -> Build.VERSION.SDK_INT.toString() | ||
| DEVICE_TYPE -> if (TvUtil.isLeanback(DolphinApplication.getAppContext())) "android-tv" else "android-mobile" | ||
| else -> "" | ||
| } | ||
| } | ||
| } |