|
@@ -3,6 +3,7 @@
|
|
|
|
|
|
|
|
package org.yuzu.yuzu_emu.fragments
|
|
package org.yuzu.yuzu_emu.fragments
|
|
|
|
|
|
|
|
|
|
+import android.Manifest
|
|
|
import android.content.Intent
|
|
import android.content.Intent
|
|
|
import android.os.Build
|
|
import android.os.Build
|
|
|
import android.os.Bundle
|
|
import android.os.Bundle
|
|
@@ -11,7 +12,9 @@ import android.view.View
|
|
|
import android.view.ViewGroup
|
|
import android.view.ViewGroup
|
|
|
import androidx.activity.OnBackPressedCallback
|
|
import androidx.activity.OnBackPressedCallback
|
|
|
import androidx.activity.result.contract.ActivityResultContracts
|
|
import androidx.activity.result.contract.ActivityResultContracts
|
|
|
|
|
+import androidx.annotation.RequiresApi
|
|
|
import androidx.appcompat.app.AppCompatActivity
|
|
import androidx.appcompat.app.AppCompatActivity
|
|
|
|
|
+import androidx.core.app.NotificationManagerCompat
|
|
|
import androidx.core.content.ContextCompat
|
|
import androidx.core.content.ContextCompat
|
|
|
import androidx.core.view.ViewCompat
|
|
import androidx.core.view.ViewCompat
|
|
|
import androidx.core.view.WindowInsetsCompat
|
|
import androidx.core.view.WindowInsetsCompat
|
|
@@ -65,10 +68,6 @@ class SetupFragment : Fragment() {
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
|
|
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
|
|
|
- if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) {
|
|
|
|
|
- pushNotificationPermissionLauncher.launch(android.Manifest.permission.POST_NOTIFICATIONS)
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
mainActivity = requireActivity() as MainActivity
|
|
mainActivity = requireActivity() as MainActivity
|
|
|
|
|
|
|
|
homeViewModel.setNavigationVisibility(visible = false, animated = false)
|
|
homeViewModel.setNavigationVisibility(visible = false, animated = false)
|
|
@@ -88,60 +87,93 @@ class SetupFragment : Fragment() {
|
|
|
requireActivity().window.navigationBarColor =
|
|
requireActivity().window.navigationBarColor =
|
|
|
ContextCompat.getColor(requireContext(), android.R.color.transparent)
|
|
ContextCompat.getColor(requireContext(), android.R.color.transparent)
|
|
|
|
|
|
|
|
- val pages = listOf(
|
|
|
|
|
- SetupPage(
|
|
|
|
|
- R.drawable.ic_yuzu_title,
|
|
|
|
|
- R.string.welcome,
|
|
|
|
|
- R.string.welcome_description,
|
|
|
|
|
- 0,
|
|
|
|
|
- true,
|
|
|
|
|
- R.string.get_started,
|
|
|
|
|
- { pageForward() },
|
|
|
|
|
- false
|
|
|
|
|
- ),
|
|
|
|
|
- SetupPage(
|
|
|
|
|
- R.drawable.ic_key,
|
|
|
|
|
- R.string.keys,
|
|
|
|
|
- R.string.keys_description,
|
|
|
|
|
- R.drawable.ic_add,
|
|
|
|
|
- true,
|
|
|
|
|
- R.string.select_keys,
|
|
|
|
|
- { mainActivity.getProdKey.launch(arrayOf("*/*")) },
|
|
|
|
|
- true,
|
|
|
|
|
- R.string.install_prod_keys_warning,
|
|
|
|
|
- R.string.install_prod_keys_warning_description,
|
|
|
|
|
- R.string.install_prod_keys_warning_help,
|
|
|
|
|
- { File(DirectoryInitialization.userDirectory + "/keys/prod.keys").exists() }
|
|
|
|
|
- ),
|
|
|
|
|
- SetupPage(
|
|
|
|
|
- R.drawable.ic_controller,
|
|
|
|
|
- R.string.games,
|
|
|
|
|
- R.string.games_description,
|
|
|
|
|
- R.drawable.ic_add,
|
|
|
|
|
- true,
|
|
|
|
|
- R.string.add_games,
|
|
|
|
|
- { mainActivity.getGamesDirectory.launch(Intent(Intent.ACTION_OPEN_DOCUMENT_TREE).data) },
|
|
|
|
|
- true,
|
|
|
|
|
- R.string.add_games_warning,
|
|
|
|
|
- R.string.add_games_warning_description,
|
|
|
|
|
- R.string.add_games_warning_help,
|
|
|
|
|
- {
|
|
|
|
|
- val preferences =
|
|
|
|
|
- PreferenceManager.getDefaultSharedPreferences(YuzuApplication.appContext)
|
|
|
|
|
- preferences.getString(GameHelper.KEY_GAME_PATH, "")!!.isNotEmpty()
|
|
|
|
|
- }
|
|
|
|
|
- ),
|
|
|
|
|
- SetupPage(
|
|
|
|
|
- R.drawable.ic_check,
|
|
|
|
|
- R.string.done,
|
|
|
|
|
- R.string.done_description,
|
|
|
|
|
- R.drawable.ic_arrow_forward,
|
|
|
|
|
- false,
|
|
|
|
|
- R.string.text_continue,
|
|
|
|
|
- { finishSetup() },
|
|
|
|
|
- false
|
|
|
|
|
|
|
+ val pages = mutableListOf<SetupPage>()
|
|
|
|
|
+ pages.apply {
|
|
|
|
|
+ add(
|
|
|
|
|
+ SetupPage(
|
|
|
|
|
+ R.drawable.ic_yuzu_title,
|
|
|
|
|
+ R.string.welcome,
|
|
|
|
|
+ R.string.welcome_description,
|
|
|
|
|
+ 0,
|
|
|
|
|
+ true,
|
|
|
|
|
+ R.string.get_started,
|
|
|
|
|
+ { pageForward() },
|
|
|
|
|
+ false
|
|
|
|
|
+ )
|
|
|
|
|
+ )
|
|
|
|
|
+
|
|
|
|
|
+ if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) {
|
|
|
|
|
+ add(
|
|
|
|
|
+ SetupPage(
|
|
|
|
|
+ R.drawable.ic_notification,
|
|
|
|
|
+ R.string.notifications,
|
|
|
|
|
+ R.string.notifications_description,
|
|
|
|
|
+ 0,
|
|
|
|
|
+ false,
|
|
|
|
|
+ R.string.give_permission,
|
|
|
|
|
+ { permissionLauncher.launch(Manifest.permission.POST_NOTIFICATIONS) },
|
|
|
|
|
+ true,
|
|
|
|
|
+ R.string.notification_warning,
|
|
|
|
|
+ R.string.notification_warning_description,
|
|
|
|
|
+ 0,
|
|
|
|
|
+ {
|
|
|
|
|
+ NotificationManagerCompat.from(requireContext())
|
|
|
|
|
+ .areNotificationsEnabled()
|
|
|
|
|
+ }
|
|
|
|
|
+ )
|
|
|
|
|
+ )
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ add(
|
|
|
|
|
+ SetupPage(
|
|
|
|
|
+ R.drawable.ic_key,
|
|
|
|
|
+ R.string.keys,
|
|
|
|
|
+ R.string.keys_description,
|
|
|
|
|
+ R.drawable.ic_add,
|
|
|
|
|
+ true,
|
|
|
|
|
+ R.string.select_keys,
|
|
|
|
|
+ { mainActivity.getProdKey.launch(arrayOf("*/*")) },
|
|
|
|
|
+ true,
|
|
|
|
|
+ R.string.install_prod_keys_warning,
|
|
|
|
|
+ R.string.install_prod_keys_warning_description,
|
|
|
|
|
+ R.string.install_prod_keys_warning_help,
|
|
|
|
|
+ { File(DirectoryInitialization.userDirectory + "/keys/prod.keys").exists() }
|
|
|
|
|
+ )
|
|
|
)
|
|
)
|
|
|
- )
|
|
|
|
|
|
|
+ add(
|
|
|
|
|
+ SetupPage(
|
|
|
|
|
+ R.drawable.ic_controller,
|
|
|
|
|
+ R.string.games,
|
|
|
|
|
+ R.string.games_description,
|
|
|
|
|
+ R.drawable.ic_add,
|
|
|
|
|
+ true,
|
|
|
|
|
+ R.string.add_games,
|
|
|
|
|
+ { mainActivity.getGamesDirectory.launch(Intent(Intent.ACTION_OPEN_DOCUMENT_TREE).data) },
|
|
|
|
|
+ true,
|
|
|
|
|
+ R.string.add_games_warning,
|
|
|
|
|
+ R.string.add_games_warning_description,
|
|
|
|
|
+ R.string.add_games_warning_help,
|
|
|
|
|
+ {
|
|
|
|
|
+ val preferences =
|
|
|
|
|
+ PreferenceManager.getDefaultSharedPreferences(YuzuApplication.appContext)
|
|
|
|
|
+ preferences.getString(GameHelper.KEY_GAME_PATH, "")!!.isNotEmpty()
|
|
|
|
|
+ }
|
|
|
|
|
+ )
|
|
|
|
|
+ )
|
|
|
|
|
+ add(
|
|
|
|
|
+ SetupPage(
|
|
|
|
|
+ R.drawable.ic_check,
|
|
|
|
|
+ R.string.done,
|
|
|
|
|
+ R.string.done_description,
|
|
|
|
|
+ R.drawable.ic_arrow_forward,
|
|
|
|
|
+ false,
|
|
|
|
|
+ R.string.text_continue,
|
|
|
|
|
+ { finishSetup() },
|
|
|
|
|
+ false
|
|
|
|
|
+ )
|
|
|
|
|
+ )
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
binding.viewPager2.apply {
|
|
binding.viewPager2.apply {
|
|
|
adapter = SetupAdapter(requireActivity() as AppCompatActivity, pages)
|
|
adapter = SetupAdapter(requireActivity() as AppCompatActivity, pages)
|
|
|
offscreenPageLimit = 2
|
|
offscreenPageLimit = 2
|
|
@@ -225,9 +257,15 @@ class SetupFragment : Fragment() {
|
|
|
_binding = null
|
|
_binding = null
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- private val pushNotificationPermissionLauncher =
|
|
|
|
|
|
|
+ @RequiresApi(Build.VERSION_CODES.TIRAMISU)
|
|
|
|
|
+ private val permissionLauncher =
|
|
|
registerForActivityResult(ActivityResultContracts.RequestPermission()) {
|
|
registerForActivityResult(ActivityResultContracts.RequestPermission()) {
|
|
|
- // TODO: Show proper notification request reason and confirmation
|
|
|
|
|
|
|
+ if (!it && !shouldShowRequestPermissionRationale(Manifest.permission.POST_NOTIFICATIONS)) {
|
|
|
|
|
+ PermissionDeniedDialogFragment().show(
|
|
|
|
|
+ childFragmentManager,
|
|
|
|
|
+ PermissionDeniedDialogFragment.TAG
|
|
|
|
|
+ )
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
private fun finishSetup() {
|
|
private fun finishSetup() {
|