|
|
@ -19,6 +19,7 @@ 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
|
|
|
|
import androidx.core.view.isVisible
|
|
|
|
import androidx.core.view.isVisible
|
|
|
|
|
|
|
|
import androidx.core.view.updatePadding
|
|
|
|
import androidx.fragment.app.Fragment
|
|
|
|
import androidx.fragment.app.Fragment
|
|
|
|
import androidx.fragment.app.activityViewModels
|
|
|
|
import androidx.fragment.app.activityViewModels
|
|
|
|
import androidx.navigation.findNavController
|
|
|
|
import androidx.navigation.findNavController
|
|
|
@ -32,10 +33,13 @@ import org.yuzu.yuzu_emu.adapters.SetupAdapter
|
|
|
|
import org.yuzu.yuzu_emu.databinding.FragmentSetupBinding
|
|
|
|
import org.yuzu.yuzu_emu.databinding.FragmentSetupBinding
|
|
|
|
import org.yuzu.yuzu_emu.features.settings.model.Settings
|
|
|
|
import org.yuzu.yuzu_emu.features.settings.model.Settings
|
|
|
|
import org.yuzu.yuzu_emu.model.HomeViewModel
|
|
|
|
import org.yuzu.yuzu_emu.model.HomeViewModel
|
|
|
|
|
|
|
|
import org.yuzu.yuzu_emu.model.SetupCallback
|
|
|
|
import org.yuzu.yuzu_emu.model.SetupPage
|
|
|
|
import org.yuzu.yuzu_emu.model.SetupPage
|
|
|
|
|
|
|
|
import org.yuzu.yuzu_emu.model.StepState
|
|
|
|
import org.yuzu.yuzu_emu.ui.main.MainActivity
|
|
|
|
import org.yuzu.yuzu_emu.ui.main.MainActivity
|
|
|
|
import org.yuzu.yuzu_emu.utils.DirectoryInitialization
|
|
|
|
import org.yuzu.yuzu_emu.utils.DirectoryInitialization
|
|
|
|
import org.yuzu.yuzu_emu.utils.GameHelper
|
|
|
|
import org.yuzu.yuzu_emu.utils.GameHelper
|
|
|
|
|
|
|
|
import org.yuzu.yuzu_emu.utils.ViewUtils
|
|
|
|
|
|
|
|
|
|
|
|
class SetupFragment : Fragment() {
|
|
|
|
class SetupFragment : Fragment() {
|
|
|
|
private var _binding: FragmentSetupBinding? = null
|
|
|
|
private var _binding: FragmentSetupBinding? = null
|
|
|
@ -112,14 +116,22 @@ class SetupFragment : Fragment() {
|
|
|
|
0,
|
|
|
|
0,
|
|
|
|
false,
|
|
|
|
false,
|
|
|
|
R.string.give_permission,
|
|
|
|
R.string.give_permission,
|
|
|
|
{ permissionLauncher.launch(Manifest.permission.POST_NOTIFICATIONS) },
|
|
|
|
{
|
|
|
|
|
|
|
|
notificationCallback = it
|
|
|
|
|
|
|
|
permissionLauncher.launch(Manifest.permission.POST_NOTIFICATIONS)
|
|
|
|
|
|
|
|
},
|
|
|
|
true,
|
|
|
|
true,
|
|
|
|
R.string.notification_warning,
|
|
|
|
R.string.notification_warning,
|
|
|
|
R.string.notification_warning_description,
|
|
|
|
R.string.notification_warning_description,
|
|
|
|
0,
|
|
|
|
0,
|
|
|
|
{
|
|
|
|
{
|
|
|
|
NotificationManagerCompat.from(requireContext())
|
|
|
|
if (NotificationManagerCompat.from(requireContext())
|
|
|
|
.areNotificationsEnabled()
|
|
|
|
.areNotificationsEnabled()
|
|
|
|
|
|
|
|
) {
|
|
|
|
|
|
|
|
StepState.COMPLETE
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
StepState.INCOMPLETE
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
)
|
|
|
|
)
|
|
|
|
)
|
|
|
|
)
|
|
|
@ -133,12 +145,22 @@ class SetupFragment : Fragment() {
|
|
|
|
R.drawable.ic_add,
|
|
|
|
R.drawable.ic_add,
|
|
|
|
true,
|
|
|
|
true,
|
|
|
|
R.string.select_keys,
|
|
|
|
R.string.select_keys,
|
|
|
|
{ mainActivity.getProdKey.launch(arrayOf("*/*")) },
|
|
|
|
{
|
|
|
|
|
|
|
|
keyCallback = it
|
|
|
|
|
|
|
|
getProdKey.launch(arrayOf("*/*"))
|
|
|
|
|
|
|
|
},
|
|
|
|
true,
|
|
|
|
true,
|
|
|
|
R.string.install_prod_keys_warning,
|
|
|
|
R.string.install_prod_keys_warning,
|
|
|
|
R.string.install_prod_keys_warning_description,
|
|
|
|
R.string.install_prod_keys_warning_description,
|
|
|
|
R.string.install_prod_keys_warning_help,
|
|
|
|
R.string.install_prod_keys_warning_help,
|
|
|
|
{ File(DirectoryInitialization.userDirectory + "/keys/prod.keys").exists() }
|
|
|
|
{
|
|
|
|
|
|
|
|
val file = File(DirectoryInitialization.userDirectory + "/keys/prod.keys")
|
|
|
|
|
|
|
|
if (file.exists()) {
|
|
|
|
|
|
|
|
StepState.COMPLETE
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
StepState.INCOMPLETE
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
)
|
|
|
|
)
|
|
|
|
)
|
|
|
|
)
|
|
|
|
add(
|
|
|
|
add(
|
|
|
@ -150,9 +172,8 @@ class SetupFragment : Fragment() {
|
|
|
|
true,
|
|
|
|
true,
|
|
|
|
R.string.add_games,
|
|
|
|
R.string.add_games,
|
|
|
|
{
|
|
|
|
{
|
|
|
|
mainActivity.getGamesDirectory.launch(
|
|
|
|
gamesDirCallback = it
|
|
|
|
Intent(Intent.ACTION_OPEN_DOCUMENT_TREE).data
|
|
|
|
getGamesDirectory.launch(Intent(Intent.ACTION_OPEN_DOCUMENT_TREE).data)
|
|
|
|
)
|
|
|
|
|
|
|
|
},
|
|
|
|
},
|
|
|
|
true,
|
|
|
|
true,
|
|
|
|
R.string.add_games_warning,
|
|
|
|
R.string.add_games_warning,
|
|
|
@ -163,7 +184,11 @@ class SetupFragment : Fragment() {
|
|
|
|
PreferenceManager.getDefaultSharedPreferences(
|
|
|
|
PreferenceManager.getDefaultSharedPreferences(
|
|
|
|
YuzuApplication.appContext
|
|
|
|
YuzuApplication.appContext
|
|
|
|
)
|
|
|
|
)
|
|
|
|
preferences.getString(GameHelper.KEY_GAME_PATH, "")!!.isNotEmpty()
|
|
|
|
if (preferences.getString(GameHelper.KEY_GAME_PATH, "")!!.isNotEmpty()) {
|
|
|
|
|
|
|
|
StepState.COMPLETE
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
StepState.INCOMPLETE
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
)
|
|
|
|
)
|
|
|
|
)
|
|
|
|
)
|
|
|
@ -181,6 +206,13 @@ class SetupFragment : Fragment() {
|
|
|
|
)
|
|
|
|
)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
homeViewModel.shouldPageForward.observe(viewLifecycleOwner) {
|
|
|
|
|
|
|
|
if (it) {
|
|
|
|
|
|
|
|
pageForward()
|
|
|
|
|
|
|
|
homeViewModel.setShouldPageForward(false)
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
binding.viewPager2.apply {
|
|
|
|
binding.viewPager2.apply {
|
|
|
|
adapter = SetupAdapter(requireActivity() as AppCompatActivity, pages)
|
|
|
|
adapter = SetupAdapter(requireActivity() as AppCompatActivity, pages)
|
|
|
|
offscreenPageLimit = 2
|
|
|
|
offscreenPageLimit = 2
|
|
|
@ -194,15 +226,15 @@ class SetupFragment : Fragment() {
|
|
|
|
super.onPageSelected(position)
|
|
|
|
super.onPageSelected(position)
|
|
|
|
|
|
|
|
|
|
|
|
if (position == 1 && previousPosition == 0) {
|
|
|
|
if (position == 1 && previousPosition == 0) {
|
|
|
|
showView(binding.buttonNext)
|
|
|
|
ViewUtils.showView(binding.buttonNext)
|
|
|
|
showView(binding.buttonBack)
|
|
|
|
ViewUtils.showView(binding.buttonBack)
|
|
|
|
} else if (position == 0 && previousPosition == 1) {
|
|
|
|
} else if (position == 0 && previousPosition == 1) {
|
|
|
|
hideView(binding.buttonBack)
|
|
|
|
ViewUtils.hideView(binding.buttonBack)
|
|
|
|
hideView(binding.buttonNext)
|
|
|
|
ViewUtils.hideView(binding.buttonNext)
|
|
|
|
} else if (position == pages.size - 1 && previousPosition == pages.size - 2) {
|
|
|
|
} else if (position == pages.size - 1 && previousPosition == pages.size - 2) {
|
|
|
|
hideView(binding.buttonNext)
|
|
|
|
ViewUtils.hideView(binding.buttonNext)
|
|
|
|
} else if (position == pages.size - 2 && previousPosition == pages.size - 1) {
|
|
|
|
} else if (position == pages.size - 2 && previousPosition == pages.size - 1) {
|
|
|
|
showView(binding.buttonNext)
|
|
|
|
ViewUtils.showView(binding.buttonNext)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
previousPosition = position
|
|
|
|
previousPosition = position
|
|
|
@ -215,7 +247,8 @@ class SetupFragment : Fragment() {
|
|
|
|
|
|
|
|
|
|
|
|
// Checks if the user has completed the task on the current page
|
|
|
|
// Checks if the user has completed the task on the current page
|
|
|
|
if (currentPage.hasWarning) {
|
|
|
|
if (currentPage.hasWarning) {
|
|
|
|
if (currentPage.taskCompleted.invoke()) {
|
|
|
|
val stepState = currentPage.stepCompleted.invoke()
|
|
|
|
|
|
|
|
if (stepState != StepState.INCOMPLETE) {
|
|
|
|
pageForward()
|
|
|
|
pageForward()
|
|
|
|
return@setOnClickListener
|
|
|
|
return@setOnClickListener
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -264,9 +297,15 @@ class SetupFragment : Fragment() {
|
|
|
|
_binding = null
|
|
|
|
_binding = null
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private lateinit var notificationCallback: SetupCallback
|
|
|
|
|
|
|
|
|
|
|
|
@RequiresApi(Build.VERSION_CODES.TIRAMISU)
|
|
|
|
@RequiresApi(Build.VERSION_CODES.TIRAMISU)
|
|
|
|
private val permissionLauncher =
|
|
|
|
private val permissionLauncher =
|
|
|
|
registerForActivityResult(ActivityResultContracts.RequestPermission()) {
|
|
|
|
registerForActivityResult(ActivityResultContracts.RequestPermission()) {
|
|
|
|
|
|
|
|
if (it) {
|
|
|
|
|
|
|
|
notificationCallback.onStepCompleted()
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (!it &&
|
|
|
|
if (!it &&
|
|
|
|
!shouldShowRequestPermissionRationale(Manifest.permission.POST_NOTIFICATIONS)
|
|
|
|
!shouldShowRequestPermissionRationale(Manifest.permission.POST_NOTIFICATIONS)
|
|
|
|
) {
|
|
|
|
) {
|
|
|
@ -277,6 +316,27 @@ class SetupFragment : Fragment() {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private lateinit var keyCallback: SetupCallback
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
val getProdKey =
|
|
|
|
|
|
|
|
registerForActivityResult(ActivityResultContracts.OpenDocument()) { result ->
|
|
|
|
|
|
|
|
if (result != null) {
|
|
|
|
|
|
|
|
if (mainActivity.processKey(result)) {
|
|
|
|
|
|
|
|
keyCallback.onStepCompleted()
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private lateinit var gamesDirCallback: SetupCallback
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
val getGamesDirectory =
|
|
|
|
|
|
|
|
registerForActivityResult(ActivityResultContracts.OpenDocumentTree()) { result ->
|
|
|
|
|
|
|
|
if (result != null) {
|
|
|
|
|
|
|
|
mainActivity.processGamesDir(result)
|
|
|
|
|
|
|
|
gamesDirCallback.onStepCompleted()
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private fun finishSetup() {
|
|
|
|
private fun finishSetup() {
|
|
|
|
PreferenceManager.getDefaultSharedPreferences(YuzuApplication.appContext).edit()
|
|
|
|
PreferenceManager.getDefaultSharedPreferences(YuzuApplication.appContext).edit()
|
|
|
|
.putBoolean(Settings.PREF_FIRST_APP_LAUNCH, false)
|
|
|
|
.putBoolean(Settings.PREF_FIRST_APP_LAUNCH, false)
|
|
|
@ -284,33 +344,6 @@ class SetupFragment : Fragment() {
|
|
|
|
mainActivity.finishSetup(binding.root.findNavController())
|
|
|
|
mainActivity.finishSetup(binding.root.findNavController())
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private fun showView(view: View) {
|
|
|
|
|
|
|
|
view.apply {
|
|
|
|
|
|
|
|
alpha = 0f
|
|
|
|
|
|
|
|
visibility = View.VISIBLE
|
|
|
|
|
|
|
|
isClickable = true
|
|
|
|
|
|
|
|
}.animate().apply {
|
|
|
|
|
|
|
|
duration = 300
|
|
|
|
|
|
|
|
alpha(1f)
|
|
|
|
|
|
|
|
}.start()
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private fun hideView(view: View) {
|
|
|
|
|
|
|
|
if (view.visibility == View.INVISIBLE) {
|
|
|
|
|
|
|
|
return
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
view.apply {
|
|
|
|
|
|
|
|
alpha = 1f
|
|
|
|
|
|
|
|
isClickable = false
|
|
|
|
|
|
|
|
}.animate().apply {
|
|
|
|
|
|
|
|
duration = 300
|
|
|
|
|
|
|
|
alpha(0f)
|
|
|
|
|
|
|
|
}.withEndAction {
|
|
|
|
|
|
|
|
view.visibility = View.INVISIBLE
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
fun pageForward() {
|
|
|
|
fun pageForward() {
|
|
|
|
binding.viewPager2.currentItem = binding.viewPager2.currentItem + 1
|
|
|
|
binding.viewPager2.currentItem = binding.viewPager2.currentItem + 1
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -326,15 +359,29 @@ class SetupFragment : Fragment() {
|
|
|
|
private fun setInsets() =
|
|
|
|
private fun setInsets() =
|
|
|
|
ViewCompat.setOnApplyWindowInsetsListener(
|
|
|
|
ViewCompat.setOnApplyWindowInsetsListener(
|
|
|
|
binding.root
|
|
|
|
binding.root
|
|
|
|
) { view: View, windowInsets: WindowInsetsCompat ->
|
|
|
|
) { _: View, windowInsets: WindowInsetsCompat ->
|
|
|
|
val barInsets = windowInsets.getInsets(WindowInsetsCompat.Type.systemBars())
|
|
|
|
val barInsets = windowInsets.getInsets(WindowInsetsCompat.Type.systemBars())
|
|
|
|
val cutoutInsets = windowInsets.getInsets(WindowInsetsCompat.Type.displayCutout())
|
|
|
|
val cutoutInsets = windowInsets.getInsets(WindowInsetsCompat.Type.displayCutout())
|
|
|
|
view.setPadding(
|
|
|
|
|
|
|
|
barInsets.left + cutoutInsets.left,
|
|
|
|
val leftPadding = barInsets.left + cutoutInsets.left
|
|
|
|
barInsets.top + cutoutInsets.top,
|
|
|
|
val topPadding = barInsets.top + cutoutInsets.top
|
|
|
|
barInsets.right + cutoutInsets.right,
|
|
|
|
val rightPadding = barInsets.right + cutoutInsets.right
|
|
|
|
barInsets.bottom + cutoutInsets.bottom
|
|
|
|
val bottomPadding = barInsets.bottom + cutoutInsets.bottom
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
if (resources.getBoolean(R.bool.small_layout)) {
|
|
|
|
|
|
|
|
binding.viewPager2
|
|
|
|
|
|
|
|
.updatePadding(left = leftPadding, top = topPadding, right = rightPadding)
|
|
|
|
|
|
|
|
binding.constraintButtons
|
|
|
|
|
|
|
|
.updatePadding(left = leftPadding, right = rightPadding, bottom = bottomPadding)
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
binding.viewPager2.updatePadding(top = topPadding, bottom = bottomPadding)
|
|
|
|
|
|
|
|
binding.constraintButtons
|
|
|
|
|
|
|
|
.updatePadding(
|
|
|
|
|
|
|
|
left = leftPadding,
|
|
|
|
|
|
|
|
right = rightPadding,
|
|
|
|
|
|
|
|
bottom = bottomPadding
|
|
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
}
|
|
|
|
windowInsets
|
|
|
|
windowInsets
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|