summaryrefslogtreecommitdiffstats
path: root/src/android/app/src/main/java/org/yuzu/yuzu_emu/utils/StartupHandler.kt
blob: 9deff68706b5e70a41c7bd968fdc6968c572d2fc (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
// SPDX-FileCopyrightText: 2023 yuzu Emulator Project
// SPDX-License-Identifier: GPL-2.0-or-later

package org.yuzu.yuzu_emu.utils

import androidx.preference.PreferenceManager
import android.text.Html
import android.text.method.LinkMovementMethod
import android.view.View
import android.widget.TextView
import com.google.android.material.dialog.MaterialAlertDialogBuilder
import org.yuzu.yuzu_emu.R
import org.yuzu.yuzu_emu.YuzuApplication
import org.yuzu.yuzu_emu.features.settings.model.Settings
import org.yuzu.yuzu_emu.ui.main.MainActivity
import org.yuzu.yuzu_emu.ui.main.MainPresenter

object StartupHandler {
    private val preferences =
        PreferenceManager.getDefaultSharedPreferences(YuzuApplication.appContext)

    private fun handleStartupPromptDismiss(parent: MainActivity) {
        parent.launchFileListActivity(MainPresenter.REQUEST_INSTALL_KEYS)
    }

    private fun markFirstBoot() {
        preferences.edit()
            .putBoolean(Settings.PREF_FIRST_APP_LAUNCH, false)
            .apply()
    }

    fun handleInit(parent: MainActivity) {
        if (preferences.getBoolean(Settings.PREF_FIRST_APP_LAUNCH, true)) {
            markFirstBoot()
            val alert = MaterialAlertDialogBuilder(parent)
                .setMessage(Html.fromHtml(parent.resources.getString(R.string.app_disclaimer)))
                .setTitle(R.string.app_name)
                .setIcon(R.mipmap.ic_launcher)
                .setPositiveButton(android.R.string.ok, null)
                .setOnDismissListener {
                    handleStartupPromptDismiss(parent)
                }
                .show()
            (alert.findViewById<View>(android.R.id.message) as TextView?)!!.movementMethod =
                LinkMovementMethod.getInstance()
        }
    }
}