From df00da1760dcf336015c6e18233d293fb1fd6cf4 Mon Sep 17 00:00:00 2001 From: Charles Lombardo Date: Mon, 21 Aug 2023 16:25:11 -0400 Subject: [PATCH] android: Show associated value in home settings (#11272) --- .../yuzu_emu/adapters/HomeSettingAdapter.kt | 24 ++++++++++++++++++- .../fragments/HomeSettingsFragment.kt | 12 ++++++++-- .../org/yuzu/yuzu_emu/model/HomeSetting.kt | 6 ++++- .../org/yuzu/yuzu_emu/model/HomeViewModel.kt | 19 +++++++++++++++ .../org/yuzu/yuzu_emu/ui/main/MainActivity.kt | 1 + .../src/main/res/layout/card_home_option.xml | 17 +++++++++++++ 6 files changed, 75 insertions(+), 4 deletions(-) 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 aadc445f98..9f859b4422 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 @@ -3,19 +3,25 @@ package org.yuzu.yuzu_emu.adapters +import android.text.TextUtils 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.lifecycle.LifecycleOwner import androidx.recyclerview.widget.RecyclerView import org.yuzu.yuzu_emu.R import org.yuzu.yuzu_emu.databinding.CardHomeOptionBinding import org.yuzu.yuzu_emu.fragments.MessageDialogFragment import org.yuzu.yuzu_emu.model.HomeSetting -class HomeSettingAdapter(private val activity: AppCompatActivity, var options: List) : +class HomeSettingAdapter( + private val activity: AppCompatActivity, + private val viewLifecycle: LifecycleOwner, + var options: List +) : RecyclerView.Adapter(), View.OnClickListener { override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): HomeOptionViewHolder { @@ -79,6 +85,22 @@ class HomeSettingAdapter(private val activity: AppCompatActivity, var options: L binding.optionDescription.alpha = 0.5f binding.optionIcon.alpha = 0.5f } + + option.details.observe(viewLifecycle) { updateOptionDetails(it) } + binding.optionDetail.postDelayed( + { + binding.optionDetail.ellipsize = TextUtils.TruncateAt.MARQUEE + binding.optionDetail.isSelected = true + }, + 3000 + ) + } + + private fun updateOptionDetails(detailString: String) { + if (detailString.isNotEmpty()) { + binding.optionDetail.text = detailString + binding.optionDetail.visibility = View.VISIBLE + } } } } 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 c001af892a..d5e7934915 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 @@ -129,7 +129,11 @@ class HomeSettingsFragment : Fragment() { mainActivity.getGamesDirectory.launch( Intent(Intent.ACTION_OPEN_DOCUMENT_TREE).data ) - } + }, + { true }, + 0, + 0, + homeViewModel.gamesDir ) ) add( @@ -201,7 +205,11 @@ class HomeSettingsFragment : Fragment() { binding.homeSettingsList.apply { layoutManager = LinearLayoutManager(requireContext()) - adapter = HomeSettingAdapter(requireActivity() as AppCompatActivity, optionsList) + adapter = HomeSettingAdapter( + requireActivity() as AppCompatActivity, + viewLifecycleOwner, + optionsList + ) } setInsets() diff --git a/src/android/app/src/main/java/org/yuzu/yuzu_emu/model/HomeSetting.kt b/src/android/app/src/main/java/org/yuzu/yuzu_emu/model/HomeSetting.kt index 522d07c37c..498c222fa9 100644 --- a/src/android/app/src/main/java/org/yuzu/yuzu_emu/model/HomeSetting.kt +++ b/src/android/app/src/main/java/org/yuzu/yuzu_emu/model/HomeSetting.kt @@ -3,6 +3,9 @@ package org.yuzu.yuzu_emu.model +import androidx.lifecycle.LiveData +import androidx.lifecycle.MutableLiveData + data class HomeSetting( val titleId: Int, val descriptionId: Int, @@ -10,5 +13,6 @@ data class HomeSetting( val onClick: () -> Unit, val isEnabled: () -> Boolean = { true }, val disabledTitleId: Int = 0, - val disabledMessageId: Int = 0 + val disabledMessageId: Int = 0, + val details: LiveData = MutableLiveData("") ) diff --git a/src/android/app/src/main/java/org/yuzu/yuzu_emu/model/HomeViewModel.kt b/src/android/app/src/main/java/org/yuzu/yuzu_emu/model/HomeViewModel.kt index e13d84c9ca..a48ef7a88a 100644 --- a/src/android/app/src/main/java/org/yuzu/yuzu_emu/model/HomeViewModel.kt +++ b/src/android/app/src/main/java/org/yuzu/yuzu_emu/model/HomeViewModel.kt @@ -3,9 +3,15 @@ package org.yuzu.yuzu_emu.model +import android.net.Uri +import androidx.fragment.app.FragmentActivity import androidx.lifecycle.LiveData import androidx.lifecycle.MutableLiveData import androidx.lifecycle.ViewModel +import androidx.lifecycle.ViewModelProvider +import androidx.preference.PreferenceManager +import org.yuzu.yuzu_emu.YuzuApplication +import org.yuzu.yuzu_emu.utils.GameHelper class HomeViewModel : ViewModel() { private val _navigationVisible = MutableLiveData>() @@ -17,6 +23,14 @@ class HomeViewModel : ViewModel() { private val _shouldPageForward = MutableLiveData(false) val shouldPageForward: LiveData get() = _shouldPageForward + private val _gamesDir = MutableLiveData( + Uri.parse( + PreferenceManager.getDefaultSharedPreferences(YuzuApplication.appContext) + .getString(GameHelper.KEY_GAME_PATH, "") + ).path ?: "" + ) + val gamesDir: LiveData get() = _gamesDir + var navigatedToSetup = false init { @@ -40,4 +54,9 @@ class HomeViewModel : ViewModel() { fun setShouldPageForward(pageForward: Boolean) { _shouldPageForward.value = pageForward } + + fun setGamesDir(activity: FragmentActivity, dir: String) { + ViewModelProvider(activity)[GamesViewModel::class.java].reloadGames(true) + _gamesDir.value = dir + } } diff --git a/src/android/app/src/main/java/org/yuzu/yuzu_emu/ui/main/MainActivity.kt b/src/android/app/src/main/java/org/yuzu/yuzu_emu/ui/main/MainActivity.kt index f77d062620..aaf3a0ec1e 100644 --- a/src/android/app/src/main/java/org/yuzu/yuzu_emu/ui/main/MainActivity.kt +++ b/src/android/app/src/main/java/org/yuzu/yuzu_emu/ui/main/MainActivity.kt @@ -290,6 +290,7 @@ class MainActivity : AppCompatActivity(), ThemeProvider { ).show() gamesViewModel.reloadGames(true) + homeViewModel.setGamesDir(this, result.path!!) } val getProdKey = 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 dc289db17d..f9f1d89fb5 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 @@ -53,6 +53,23 @@ android:layout_marginTop="5dp" tools:text="@string/install_prod_keys_description" /> + +