From 21e8a8277ad8697576a2b1a4e230a68649c17812 Mon Sep 17 00:00:00 2001 From: Charles Lombardo Date: Mon, 1 May 2023 16:33:21 -0400 Subject: [PATCH] android: About fragment --- .../yuzu/yuzu_emu/fragments/AboutFragment.kt | 120 +++++++++++ .../fragments/HomeSettingsFragment.kt | 26 ++- .../app/src/main/res/drawable/ic_back.xml | 10 + .../app/src/main/res/drawable/ic_discord.xml | 10 + .../app/src/main/res/drawable/ic_github.xml | 10 + .../src/main/res/drawable/ic_info_outline.xml | 9 + .../app/src/main/res/drawable/ic_website.xml | 9 + .../src/main/res/layout/fragment_about.xml | 199 ++++++++++++++++++ .../main/res/navigation/home_navigation.xml | 11 +- .../app/src/main/res/values/strings.xml | 14 ++ 10 files changed, 415 insertions(+), 3 deletions(-) create mode 100644 src/android/app/src/main/java/org/yuzu/yuzu_emu/fragments/AboutFragment.kt create mode 100644 src/android/app/src/main/res/drawable/ic_back.xml create mode 100644 src/android/app/src/main/res/drawable/ic_discord.xml create mode 100644 src/android/app/src/main/res/drawable/ic_github.xml create mode 100644 src/android/app/src/main/res/drawable/ic_info_outline.xml create mode 100644 src/android/app/src/main/res/drawable/ic_website.xml create mode 100644 src/android/app/src/main/res/layout/fragment_about.xml diff --git a/src/android/app/src/main/java/org/yuzu/yuzu_emu/fragments/AboutFragment.kt b/src/android/app/src/main/java/org/yuzu/yuzu_emu/fragments/AboutFragment.kt new file mode 100644 index 000000000..fc7c782a6 --- /dev/null +++ b/src/android/app/src/main/java/org/yuzu/yuzu_emu/fragments/AboutFragment.kt @@ -0,0 +1,120 @@ +// SPDX-FileCopyrightText: 2023 yuzu Emulator Project +// SPDX-License-Identifier: GPL-2.0-or-later + +package org.yuzu.yuzu_emu.fragments + +import android.content.ClipData +import android.content.ClipboardManager +import android.content.Context +import android.content.Intent +import android.net.Uri +import android.os.Build +import android.os.Bundle +import android.view.LayoutInflater +import android.view.View +import android.view.ViewGroup +import android.view.ViewGroup.MarginLayoutParams +import android.widget.Toast +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.BuildConfig +import org.yuzu.yuzu_emu.R +import org.yuzu.yuzu_emu.databinding.FragmentAboutBinding +import org.yuzu.yuzu_emu.model.HomeViewModel + +class AboutFragment : Fragment() { + private var _binding: FragmentAboutBinding? = 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 = FragmentAboutBinding.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.imageLogo.setOnLongClickListener { + Toast.makeText( + requireContext(), + R.string.gaia_is_not_real, + Toast.LENGTH_SHORT + ).show() + true + } + + binding.buttonContributors.setOnClickListener { openLink(getString(R.string.contributors_link)) } + + binding.textBuildHash.text = BuildConfig.GIT_HASH + binding.buttonBuildHash.setOnClickListener { + val clipBoard = + requireContext().getSystemService(Context.CLIPBOARD_SERVICE) as ClipboardManager + val clip = ClipData.newPlainText(getString(R.string.build), BuildConfig.GIT_HASH) + clipBoard.setPrimaryClip(clip) + + if (Build.VERSION.SDK_INT < Build.VERSION_CODES.TIRAMISU) { + Toast.makeText( + requireContext(), + R.string.copied_to_clipboard, + Toast.LENGTH_SHORT + ).show() + } + } + + binding.buttonDiscord.setOnClickListener { openLink(getString(R.string.support_link)) } + binding.buttonWebsite.setOnClickListener { openLink(getString(R.string.website_link)) } + binding.buttonGithub.setOnClickListener { openLink(getString(R.string.github_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.appbarAbout.layoutParams as MarginLayoutParams + mlpAppBar.leftMargin = leftInsets + mlpAppBar.rightMargin = rightInsets + binding.appbarAbout.layoutParams = mlpAppBar + + val mlpScrollAbout = binding.scrollAbout.layoutParams as MarginLayoutParams + mlpScrollAbout.leftMargin = leftInsets + mlpScrollAbout.rightMargin = rightInsets + binding.scrollAbout.layoutParams = mlpScrollAbout + + binding.contentAbout.updatePadding(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 875dce676..c7427e151 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 @@ -23,8 +23,10 @@ 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 androidx.recyclerview.widget.LinearLayoutManager import com.google.android.material.dialog.MaterialAlertDialogBuilder +import com.google.android.material.transition.MaterialSharedAxis import org.yuzu.yuzu_emu.R import org.yuzu.yuzu_emu.adapters.HomeSettingAdapter import org.yuzu.yuzu_emu.databinding.FragmentHomeSettingsBinding @@ -44,6 +46,11 @@ class HomeSettingsFragment : Fragment() { private val homeViewModel: HomeViewModel by activityViewModels() + override fun onCreate(savedInstanceState: Bundle?) { + super.onCreate(savedInstanceState) + reenterTransition = MaterialSharedAxis(MaterialSharedAxis.X, false) + } + override fun onCreateView( inflater: LayoutInflater, container: ViewGroup?, @@ -54,7 +61,6 @@ class HomeSettingsFragment : Fragment() { } override fun onViewCreated(view: View, savedInstanceState: Bundle?) { - homeViewModel.setNavigationVisibility(visible = true, animated = false) mainActivity = requireActivity() as MainActivity val optionsList: List = listOf( @@ -87,7 +93,16 @@ class HomeSettingsFragment : Fragment() { R.string.install_prod_keys, R.string.install_prod_keys_description, R.drawable.ic_unlock - ) { mainActivity.getProdKey.launch(arrayOf("*/*")) } + ) { mainActivity.getProdKey.launch(arrayOf("*/*")) }, + HomeSetting( + R.string.about, + R.string.about_description, + R.drawable.ic_info_outline + ) { + exitTransition = MaterialSharedAxis(MaterialSharedAxis.X, true) + parentFragmentManager.primaryNavigationFragment?.findNavController() + ?.navigate(R.id.action_homeSettingsFragment_to_aboutFragment) + } ) binding.homeSettingsList.apply { @@ -98,6 +113,13 @@ class HomeSettingsFragment : Fragment() { setInsets() } + override fun onStart() { + super.onStart() + exitTransition = null + homeViewModel.setNavigationVisibility(visible = true, animated = true) + homeViewModel.setStatusBarShadeVisibility(visible = true) + } + override fun onDestroyView() { super.onDestroyView() _binding = null diff --git a/src/android/app/src/main/res/drawable/ic_back.xml b/src/android/app/src/main/res/drawable/ic_back.xml new file mode 100644 index 000000000..f99fea719 --- /dev/null +++ b/src/android/app/src/main/res/drawable/ic_back.xml @@ -0,0 +1,10 @@ + + + diff --git a/src/android/app/src/main/res/drawable/ic_discord.xml b/src/android/app/src/main/res/drawable/ic_discord.xml new file mode 100644 index 000000000..7a9c6ba79 --- /dev/null +++ b/src/android/app/src/main/res/drawable/ic_discord.xml @@ -0,0 +1,10 @@ + + + diff --git a/src/android/app/src/main/res/drawable/ic_github.xml b/src/android/app/src/main/res/drawable/ic_github.xml new file mode 100644 index 000000000..c2ee43803 --- /dev/null +++ b/src/android/app/src/main/res/drawable/ic_github.xml @@ -0,0 +1,10 @@ + + + diff --git a/src/android/app/src/main/res/drawable/ic_info_outline.xml b/src/android/app/src/main/res/drawable/ic_info_outline.xml new file mode 100644 index 000000000..92ae0eeaf --- /dev/null +++ b/src/android/app/src/main/res/drawable/ic_info_outline.xml @@ -0,0 +1,9 @@ + + + diff --git a/src/android/app/src/main/res/drawable/ic_website.xml b/src/android/app/src/main/res/drawable/ic_website.xml new file mode 100644 index 000000000..f35b84a7c --- /dev/null +++ b/src/android/app/src/main/res/drawable/ic_website.xml @@ -0,0 +1,9 @@ + + + diff --git a/src/android/app/src/main/res/layout/fragment_about.xml b/src/android/app/src/main/res/layout/fragment_about.xml new file mode 100644 index 000000000..549f00aa5 --- /dev/null +++ b/src/android/app/src/main/res/layout/fragment_about.xml @@ -0,0 +1,199 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +