From f69bc78dc56eaf2a6e33f0bcee1ba1dd812fd9b4 Mon Sep 17 00:00:00 2001 From: Charles Lombardo Date: Mon, 8 May 2023 04:49:32 -0400 Subject: android: Add early access upgrade fragment We now have a second build flavor that will determine whether the "Get Early Access" button appears. --- src/android/app/build.gradle.kts | 6 + .../yuzu/yuzu_emu/adapters/HomeSettingAdapter.kt | 16 +- .../yuzu/yuzu_emu/fragments/EarlyAccessFragment.kt | 83 +++++++ .../yuzu_emu/fragments/HomeSettingsFragment.kt | 18 +- .../app/src/main/res/drawable/ic_check_circle.xml | 9 + .../app/src/main/res/drawable/ic_diamond.xml | 9 + .../src/main/res/drawable/premium_background.xml | 9 + .../app/src/main/res/layout/card_home_option.xml | 1 + .../src/main/res/layout/fragment_early_access.xml | 242 +++++++++++++++++++++ .../src/main/res/navigation/home_navigation.xml | 8 + .../app/src/main/res/values-night/yuzu_colors.xml | 3 + src/android/app/src/main/res/values/strings.xml | 14 ++ .../app/src/main/res/values/yuzu_colors.xml | 3 + 13 files changed, 419 insertions(+), 2 deletions(-) create mode 100644 src/android/app/src/main/java/org/yuzu/yuzu_emu/fragments/EarlyAccessFragment.kt create mode 100644 src/android/app/src/main/res/drawable/ic_check_circle.xml create mode 100644 src/android/app/src/main/res/drawable/ic_diamond.xml create mode 100644 src/android/app/src/main/res/drawable/premium_background.xml create mode 100644 src/android/app/src/main/res/layout/fragment_early_access.xml (limited to 'src/android') diff --git a/src/android/app/build.gradle.kts b/src/android/app/build.gradle.kts index a9790b200..8c970609f 100644 --- a/src/android/app/build.gradle.kts +++ b/src/android/app/build.gradle.kts @@ -112,6 +112,12 @@ android { productFlavors { create("mainline") { dimension = "version" + buildConfigField("Boolean", "PREMIUM", "false") + } + + create("ea") { + dimension = "version" + buildConfigField("Boolean", "PREMIUM", "true") } } diff --git a/src/android/app/src/main/java/org/yuzu/yuzu_emu/adapters/HomeSettingAdapter.kt b/src/android/app/src/main/java/org/yuzu/yuzu_emu/adapters/HomeSettingAdapter.kt index 2b3956e6d..b719dd539 100644 --- a/src/android/app/src/main/java/org/yuzu/yuzu_emu/adapters/HomeSettingAdapter.kt +++ b/src/android/app/src/main/java/org/yuzu/yuzu_emu/adapters/HomeSettingAdapter.kt @@ -1,11 +1,16 @@ +// SPDX-FileCopyrightText: 2023 yuzu Emulator Project +// SPDX-License-Identifier: GPL-2.0-or-later + package org.yuzu.yuzu_emu.adapters import android.view.LayoutInflater import android.view.View import android.view.ViewGroup import androidx.appcompat.app.AppCompatActivity +import androidx.core.content.ContextCompat import androidx.core.content.res.ResourcesCompat import androidx.recyclerview.widget.RecyclerView +import org.yuzu.yuzu_emu.R import org.yuzu.yuzu_emu.databinding.CardHomeOptionBinding import org.yuzu.yuzu_emu.model.HomeSetting @@ -13,7 +18,8 @@ class HomeSettingAdapter(private val activity: AppCompatActivity, var options: L RecyclerView.Adapter(), View.OnClickListener { override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): HomeOptionViewHolder { - val binding = CardHomeOptionBinding.inflate(LayoutInflater.from(parent.context), parent, false) + val binding = + CardHomeOptionBinding.inflate(LayoutInflater.from(parent.context), parent, false) binding.root.setOnClickListener(this) return HomeOptionViewHolder(binding) } @@ -50,6 +56,14 @@ class HomeSettingAdapter(private val activity: AppCompatActivity, var options: L activity.theme ) ) + + when (option.titleId) { + R.string.get_early_access -> binding.optionLayout.background = + ContextCompat.getDrawable( + binding.optionCard.context, + R.drawable.premium_background + ) + } } } } diff --git a/src/android/app/src/main/java/org/yuzu/yuzu_emu/fragments/EarlyAccessFragment.kt b/src/android/app/src/main/java/org/yuzu/yuzu_emu/fragments/EarlyAccessFragment.kt new file mode 100644 index 000000000..d8bbc1ce4 --- /dev/null +++ b/src/android/app/src/main/java/org/yuzu/yuzu_emu/fragments/EarlyAccessFragment.kt @@ -0,0 +1,83 @@ +// SPDX-FileCopyrightText: 2023 yuzu Emulator Project +// SPDX-License-Identifier: GPL-2.0-or-later + +package org.yuzu.yuzu_emu.fragments + +import android.content.Intent +import android.net.Uri +import android.os.Bundle +import android.view.LayoutInflater +import android.view.View +import android.view.ViewGroup +import androidx.core.view.ViewCompat +import androidx.core.view.WindowInsetsCompat +import androidx.core.view.updatePadding +import androidx.fragment.app.Fragment +import androidx.fragment.app.activityViewModels +import androidx.navigation.fragment.findNavController +import com.google.android.material.transition.MaterialSharedAxis +import org.yuzu.yuzu_emu.R +import org.yuzu.yuzu_emu.databinding.FragmentEarlyAccessBinding +import org.yuzu.yuzu_emu.model.HomeViewModel + +class EarlyAccessFragment : Fragment() { + private var _binding: FragmentEarlyAccessBinding? = null + private val binding get() = _binding!! + + private val homeViewModel: HomeViewModel by activityViewModels() + + override fun onCreate(savedInstanceState: Bundle?) { + super.onCreate(savedInstanceState) + enterTransition = MaterialSharedAxis(MaterialSharedAxis.X, true) + returnTransition = MaterialSharedAxis(MaterialSharedAxis.X, false) + } + + override fun onCreateView( + inflater: LayoutInflater, + container: ViewGroup?, + savedInstanceState: Bundle? + ): View { + _binding = FragmentEarlyAccessBinding.inflate(layoutInflater) + return binding.root + } + + override fun onViewCreated(view: View, savedInstanceState: Bundle?) { + homeViewModel.setNavigationVisibility(visible = false, animated = true) + homeViewModel.setStatusBarShadeVisibility(visible = false) + + binding.toolbarAbout.setNavigationOnClickListener { + parentFragmentManager.primaryNavigationFragment?.findNavController()?.popBackStack() + } + + binding.getEarlyAccessButton.setOnClickListener { openLink(getString(R.string.play_store_link)) } + + setInsets() + } + + private fun openLink(link: String) { + val intent = Intent(Intent.ACTION_VIEW, Uri.parse(link)) + startActivity(intent) + } + + private fun setInsets() = + ViewCompat.setOnApplyWindowInsetsListener(binding.root) { _: View, windowInsets: WindowInsetsCompat -> + val barInsets = windowInsets.getInsets(WindowInsetsCompat.Type.systemBars()) + val cutoutInsets = windowInsets.getInsets(WindowInsetsCompat.Type.displayCutout()) + + val leftInsets = barInsets.left + cutoutInsets.left + val rightInsets = barInsets.right + cutoutInsets.right + + val mlpAppBar = binding.appbarEa.layoutParams as ViewGroup.MarginLayoutParams + mlpAppBar.leftMargin = leftInsets + mlpAppBar.rightMargin = rightInsets + binding.appbarEa.layoutParams = mlpAppBar + + binding.scrollEa.updatePadding( + left = leftInsets, + right = rightInsets, + bottom = barInsets.bottom + ) + + windowInsets + } +} diff --git a/src/android/app/src/main/java/org/yuzu/yuzu_emu/fragments/HomeSettingsFragment.kt b/src/android/app/src/main/java/org/yuzu/yuzu_emu/fragments/HomeSettingsFragment.kt index ae920d692..3044ebf66 100644 --- a/src/android/app/src/main/java/org/yuzu/yuzu_emu/fragments/HomeSettingsFragment.kt +++ b/src/android/app/src/main/java/org/yuzu/yuzu_emu/fragments/HomeSettingsFragment.kt @@ -28,6 +28,7 @@ import androidx.navigation.fragment.findNavController import androidx.recyclerview.widget.LinearLayoutManager import com.google.android.material.dialog.MaterialAlertDialogBuilder import com.google.android.material.transition.MaterialSharedAxis +import org.yuzu.yuzu_emu.BuildConfig import org.yuzu.yuzu_emu.R import org.yuzu.yuzu_emu.adapters.HomeSettingAdapter import org.yuzu.yuzu_emu.databinding.FragmentHomeSettingsBinding @@ -64,7 +65,7 @@ class HomeSettingsFragment : Fragment() { override fun onViewCreated(view: View, savedInstanceState: Bundle?) { mainActivity = requireActivity() as MainActivity - val optionsList: List = listOf( + val optionsList: MutableList = mutableListOf( HomeSetting( R.string.advanced_settings, R.string.settings_description, @@ -106,6 +107,21 @@ class HomeSettingsFragment : Fragment() { } ) + if (!BuildConfig.PREMIUM) { + optionsList.add( + 0, + HomeSetting( + R.string.get_early_access, + R.string.get_early_access_description, + R.drawable.ic_diamond + ) { + exitTransition = MaterialSharedAxis(MaterialSharedAxis.X, true) + parentFragmentManager.primaryNavigationFragment?.findNavController() + ?.navigate(R.id.action_homeSettingsFragment_to_earlyAccessFragment) + } + ) + } + binding.homeSettingsList.apply { layoutManager = LinearLayoutManager(requireContext()) adapter = HomeSettingAdapter(requireActivity() as AppCompatActivity, optionsList) diff --git a/src/android/app/src/main/res/drawable/ic_check_circle.xml b/src/android/app/src/main/res/drawable/ic_check_circle.xml new file mode 100644 index 000000000..49e6ecd71 --- /dev/null +++ b/src/android/app/src/main/res/drawable/ic_check_circle.xml @@ -0,0 +1,9 @@ + + + diff --git a/src/android/app/src/main/res/drawable/ic_diamond.xml b/src/android/app/src/main/res/drawable/ic_diamond.xml new file mode 100644 index 000000000..3896e12e4 --- /dev/null +++ b/src/android/app/src/main/res/drawable/ic_diamond.xml @@ -0,0 +1,9 @@ + + + diff --git a/src/android/app/src/main/res/drawable/premium_background.xml b/src/android/app/src/main/res/drawable/premium_background.xml new file mode 100644 index 000000000..c9c41ddbe --- /dev/null +++ b/src/android/app/src/main/res/drawable/premium_background.xml @@ -0,0 +1,9 @@ + + + + + diff --git a/src/android/app/src/main/res/layout/card_home_option.xml b/src/android/app/src/main/res/layout/card_home_option.xml index aa535943f..dc289db17 100644 --- a/src/android/app/src/main/res/layout/card_home_option.xml +++ b/src/android/app/src/main/res/layout/card_home_option.xml @@ -14,6 +14,7 @@ android:focusable="true"> diff --git a/src/android/app/src/main/res/layout/fragment_early_access.xml b/src/android/app/src/main/res/layout/fragment_early_access.xml new file mode 100644 index 000000000..644b4dd45 --- /dev/null +++ b/src/android/app/src/main/res/layout/fragment_early_access.xml @@ -0,0 +1,242 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/android/app/src/main/res/navigation/home_navigation.xml b/src/android/app/src/main/res/navigation/home_navigation.xml index f44eb3fed..2275ddc32 100644 --- a/src/android/app/src/main/res/navigation/home_navigation.xml +++ b/src/android/app/src/main/res/navigation/home_navigation.xml @@ -16,6 +16,9 @@ + + + diff --git a/src/android/app/src/main/res/values-night/yuzu_colors.xml b/src/android/app/src/main/res/values-night/yuzu_colors.xml index 1e563a6f2..49d823324 100644 --- a/src/android/app/src/main/res/values-night/yuzu_colors.xml +++ b/src/android/app/src/main/res/values-night/yuzu_colors.xml @@ -31,4 +31,7 @@ #9DCAFF #42474E + #840099 + #005AE1 + diff --git a/src/android/app/src/main/res/values/strings.xml b/src/android/app/src/main/res/values/strings.xml index 629b21e08..8ee067ffd 100644 --- a/src/android/app/src/main/res/values/strings.xml +++ b/src/android/app/src/main/res/values/strings.xml @@ -85,6 +85,20 @@ https://yuzu-emu.org/ https://github.com/yuzu-emu + + Early Access + Get Early Access + https://play.google.com/store/apps/details?id=org.yuzu.yuzu_emu.ea + Cutting-edge features, early access to updates, and more + Early Access Benefits + Cutting-edge features + Early access to updates + No manual installation + Prioritized support + Helping game preservation + Our eternal gratitude + Are you interested? + Enable limit speed When enabled, emulation speed will be limited to a specified percentage of normal speed. diff --git a/src/android/app/src/main/res/values/yuzu_colors.xml b/src/android/app/src/main/res/values/yuzu_colors.xml index 921149d88..5b7d189dc 100644 --- a/src/android/app/src/main/res/values/yuzu_colors.xml +++ b/src/android/app/src/main/res/values/yuzu_colors.xml @@ -31,4 +31,7 @@ #B52612 #D8C2BE + #99FFE1 + #76C5FF + -- cgit v1.2.3