diff options
Diffstat (limited to 'src')
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 aadc445f9..9f859b442 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 @@ | |||
| 3 | 3 | ||
| 4 | package org.yuzu.yuzu_emu.adapters | 4 | package org.yuzu.yuzu_emu.adapters |
| 5 | 5 | ||
| 6 | import android.text.TextUtils | ||
| 6 | import android.view.LayoutInflater | 7 | import android.view.LayoutInflater |
| 7 | import android.view.View | 8 | import android.view.View |
| 8 | import android.view.ViewGroup | 9 | import android.view.ViewGroup |
| 9 | import androidx.appcompat.app.AppCompatActivity | 10 | import androidx.appcompat.app.AppCompatActivity |
| 10 | import androidx.core.content.ContextCompat | 11 | import androidx.core.content.ContextCompat |
| 11 | import androidx.core.content.res.ResourcesCompat | 12 | import androidx.core.content.res.ResourcesCompat |
| 13 | import androidx.lifecycle.LifecycleOwner | ||
| 12 | import androidx.recyclerview.widget.RecyclerView | 14 | import androidx.recyclerview.widget.RecyclerView |
| 13 | import org.yuzu.yuzu_emu.R | 15 | import org.yuzu.yuzu_emu.R |
| 14 | import org.yuzu.yuzu_emu.databinding.CardHomeOptionBinding | 16 | import org.yuzu.yuzu_emu.databinding.CardHomeOptionBinding |
| 15 | import org.yuzu.yuzu_emu.fragments.MessageDialogFragment | 17 | import org.yuzu.yuzu_emu.fragments.MessageDialogFragment |
| 16 | import org.yuzu.yuzu_emu.model.HomeSetting | 18 | import org.yuzu.yuzu_emu.model.HomeSetting |
| 17 | 19 | ||
| 18 | class HomeSettingAdapter(private val activity: AppCompatActivity, var options: List<HomeSetting>) : | 20 | class HomeSettingAdapter( |
| 21 | private val activity: AppCompatActivity, | ||
| 22 | private val viewLifecycle: LifecycleOwner, | ||
| 23 | var options: List<HomeSetting> | ||
| 24 | ) : | ||
| 19 | RecyclerView.Adapter<HomeSettingAdapter.HomeOptionViewHolder>(), | 25 | RecyclerView.Adapter<HomeSettingAdapter.HomeOptionViewHolder>(), |
| 20 | View.OnClickListener { | 26 | View.OnClickListener { |
| 21 | override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): HomeOptionViewHolder { | 27 | override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): HomeOptionViewHolder { |
| @@ -79,6 +85,22 @@ class HomeSettingAdapter(private val activity: AppCompatActivity, var options: L | |||
| 79 | binding.optionDescription.alpha = 0.5f | 85 | binding.optionDescription.alpha = 0.5f |
| 80 | binding.optionIcon.alpha = 0.5f | 86 | binding.optionIcon.alpha = 0.5f |
| 81 | } | 87 | } |
| 88 | |||
| 89 | option.details.observe(viewLifecycle) { updateOptionDetails(it) } | ||
| 90 | binding.optionDetail.postDelayed( | ||
| 91 | { | ||
| 92 | binding.optionDetail.ellipsize = TextUtils.TruncateAt.MARQUEE | ||
| 93 | binding.optionDetail.isSelected = true | ||
| 94 | }, | ||
| 95 | 3000 | ||
| 96 | ) | ||
| 97 | } | ||
| 98 | |||
| 99 | private fun updateOptionDetails(detailString: String) { | ||
| 100 | if (detailString.isNotEmpty()) { | ||
| 101 | binding.optionDetail.text = detailString | ||
| 102 | binding.optionDetail.visibility = View.VISIBLE | ||
| 103 | } | ||
| 82 | } | 104 | } |
| 83 | } | 105 | } |
| 84 | } | 106 | } |
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 c001af892..d5e793491 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() { | |||
| 129 | mainActivity.getGamesDirectory.launch( | 129 | mainActivity.getGamesDirectory.launch( |
| 130 | Intent(Intent.ACTION_OPEN_DOCUMENT_TREE).data | 130 | Intent(Intent.ACTION_OPEN_DOCUMENT_TREE).data |
| 131 | ) | 131 | ) |
| 132 | } | 132 | }, |
| 133 | { true }, | ||
| 134 | 0, | ||
| 135 | 0, | ||
| 136 | homeViewModel.gamesDir | ||
| 133 | ) | 137 | ) |
| 134 | ) | 138 | ) |
| 135 | add( | 139 | add( |
| @@ -201,7 +205,11 @@ class HomeSettingsFragment : Fragment() { | |||
| 201 | 205 | ||
| 202 | binding.homeSettingsList.apply { | 206 | binding.homeSettingsList.apply { |
| 203 | layoutManager = LinearLayoutManager(requireContext()) | 207 | layoutManager = LinearLayoutManager(requireContext()) |
| 204 | adapter = HomeSettingAdapter(requireActivity() as AppCompatActivity, optionsList) | 208 | adapter = HomeSettingAdapter( |
| 209 | requireActivity() as AppCompatActivity, | ||
| 210 | viewLifecycleOwner, | ||
| 211 | optionsList | ||
| 212 | ) | ||
| 205 | } | 213 | } |
| 206 | 214 | ||
| 207 | setInsets() | 215 | 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 522d07c37..498c222fa 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 @@ | |||
| 3 | 3 | ||
| 4 | package org.yuzu.yuzu_emu.model | 4 | package org.yuzu.yuzu_emu.model |
| 5 | 5 | ||
| 6 | import androidx.lifecycle.LiveData | ||
| 7 | import androidx.lifecycle.MutableLiveData | ||
| 8 | |||
| 6 | data class HomeSetting( | 9 | data class HomeSetting( |
| 7 | val titleId: Int, | 10 | val titleId: Int, |
| 8 | val descriptionId: Int, | 11 | val descriptionId: Int, |
| @@ -10,5 +13,6 @@ data class HomeSetting( | |||
| 10 | val onClick: () -> Unit, | 13 | val onClick: () -> Unit, |
| 11 | val isEnabled: () -> Boolean = { true }, | 14 | val isEnabled: () -> Boolean = { true }, |
| 12 | val disabledTitleId: Int = 0, | 15 | val disabledTitleId: Int = 0, |
| 13 | val disabledMessageId: Int = 0 | 16 | val disabledMessageId: Int = 0, |
| 17 | val details: LiveData<String> = MutableLiveData("") | ||
| 14 | ) | 18 | ) |
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 e13d84c9c..a48ef7a88 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 @@ | |||
| 3 | 3 | ||
| 4 | package org.yuzu.yuzu_emu.model | 4 | package org.yuzu.yuzu_emu.model |
| 5 | 5 | ||
| 6 | import android.net.Uri | ||
| 7 | import androidx.fragment.app.FragmentActivity | ||
| 6 | import androidx.lifecycle.LiveData | 8 | import androidx.lifecycle.LiveData |
| 7 | import androidx.lifecycle.MutableLiveData | 9 | import androidx.lifecycle.MutableLiveData |
| 8 | import androidx.lifecycle.ViewModel | 10 | import androidx.lifecycle.ViewModel |
| 11 | import androidx.lifecycle.ViewModelProvider | ||
| 12 | import androidx.preference.PreferenceManager | ||
| 13 | import org.yuzu.yuzu_emu.YuzuApplication | ||
| 14 | import org.yuzu.yuzu_emu.utils.GameHelper | ||
| 9 | 15 | ||
| 10 | class HomeViewModel : ViewModel() { | 16 | class HomeViewModel : ViewModel() { |
| 11 | private val _navigationVisible = MutableLiveData<Pair<Boolean, Boolean>>() | 17 | private val _navigationVisible = MutableLiveData<Pair<Boolean, Boolean>>() |
| @@ -17,6 +23,14 @@ class HomeViewModel : ViewModel() { | |||
| 17 | private val _shouldPageForward = MutableLiveData(false) | 23 | private val _shouldPageForward = MutableLiveData(false) |
| 18 | val shouldPageForward: LiveData<Boolean> get() = _shouldPageForward | 24 | val shouldPageForward: LiveData<Boolean> get() = _shouldPageForward |
| 19 | 25 | ||
| 26 | private val _gamesDir = MutableLiveData( | ||
| 27 | Uri.parse( | ||
| 28 | PreferenceManager.getDefaultSharedPreferences(YuzuApplication.appContext) | ||
| 29 | .getString(GameHelper.KEY_GAME_PATH, "") | ||
| 30 | ).path ?: "" | ||
| 31 | ) | ||
| 32 | val gamesDir: LiveData<String> get() = _gamesDir | ||
| 33 | |||
| 20 | var navigatedToSetup = false | 34 | var navigatedToSetup = false |
| 21 | 35 | ||
| 22 | init { | 36 | init { |
| @@ -40,4 +54,9 @@ class HomeViewModel : ViewModel() { | |||
| 40 | fun setShouldPageForward(pageForward: Boolean) { | 54 | fun setShouldPageForward(pageForward: Boolean) { |
| 41 | _shouldPageForward.value = pageForward | 55 | _shouldPageForward.value = pageForward |
| 42 | } | 56 | } |
| 57 | |||
| 58 | fun setGamesDir(activity: FragmentActivity, dir: String) { | ||
| 59 | ViewModelProvider(activity)[GamesViewModel::class.java].reloadGames(true) | ||
| 60 | _gamesDir.value = dir | ||
| 61 | } | ||
| 43 | } | 62 | } |
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 f77d06262..aaf3a0ec1 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 { | |||
| 290 | ).show() | 290 | ).show() |
| 291 | 291 | ||
| 292 | gamesViewModel.reloadGames(true) | 292 | gamesViewModel.reloadGames(true) |
| 293 | homeViewModel.setGamesDir(this, result.path!!) | ||
| 293 | } | 294 | } |
| 294 | 295 | ||
| 295 | val getProdKey = | 296 | 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 dc289db17..f9f1d89fb 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 @@ | |||
| 53 | android:layout_marginTop="5dp" | 53 | android:layout_marginTop="5dp" |
| 54 | tools:text="@string/install_prod_keys_description" /> | 54 | tools:text="@string/install_prod_keys_description" /> |
| 55 | 55 | ||
| 56 | <com.google.android.material.textview.MaterialTextView | ||
| 57 | style="@style/TextAppearance.Material3.LabelMedium" | ||
| 58 | android:id="@+id/option_detail" | ||
| 59 | android:layout_width="match_parent" | ||
| 60 | android:layout_height="wrap_content" | ||
| 61 | android:textAlignment="viewStart" | ||
| 62 | android:textSize="14sp" | ||
| 63 | android:textStyle="bold" | ||
| 64 | android:singleLine="true" | ||
| 65 | android:marqueeRepeatLimit="marquee_forever" | ||
| 66 | android:ellipsize="none" | ||
| 67 | android:requiresFadingEdge="horizontal" | ||
| 68 | android:layout_marginTop="5dp" | ||
| 69 | android:visibility="gone" | ||
| 70 | tools:visibility="visible" | ||
| 71 | tools:text="/tree/primary:Games" /> | ||
| 72 | |||
| 56 | </LinearLayout> | 73 | </LinearLayout> |
| 57 | 74 | ||
| 58 | </LinearLayout> | 75 | </LinearLayout> |