From 6090694eab008b88c6d4bb58f7ccf7ff7733f47d Mon Sep 17 00:00:00 2001 From: Charles Lombardo Date: Sun, 27 Nov 2022 22:19:25 -0500 Subject: [PATCH] Android: Move game grid options to Main/TV Activities --- .../ui/SettingsFragmentPresenter.java | 4 - .../fragments/GridOptionDialogFragment.kt | 124 ++++++++++++++++++ .../dolphinemu/ui/main/MainActivity.java | 17 ++- .../dolphinemu/ui/main/MainPresenter.java | 4 + .../dolphinemu/ui/main/MainView.java | 4 + .../dolphinemu/ui/main/TvMainActivity.java | 18 ++- .../app/src/main/res/drawable/ic_list.xml | 9 ++ .../app/src/main/res/drawable/ic_list_tv.xml | 9 ++ .../main/res/layout/fragment_grid_options.xml | 83 ++++++++++++ .../res/layout/fragment_grid_options_tv.xml | 48 +++++++ .../app/src/main/res/menu/menu_game_grid.xml | 6 + .../src/main/res/values-night-v31/themes.xml | 1 + .../app/src/main/res/values-v31/themes.xml | 1 + .../app/src/main/res/values/strings.xml | 4 +- .../app/src/main/res/values/styles.xml | 13 ++ .../app/src/main/res/values/themes.xml | 12 +- 16 files changed, 337 insertions(+), 20 deletions(-) create mode 100644 Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/fragments/GridOptionDialogFragment.kt create mode 100644 Source/Android/app/src/main/res/drawable/ic_list.xml create mode 100644 Source/Android/app/src/main/res/drawable/ic_list_tv.xml create mode 100644 Source/Android/app/src/main/res/layout/fragment_grid_options.xml create mode 100644 Source/Android/app/src/main/res/layout/fragment_grid_options_tv.xml diff --git a/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/features/settings/ui/SettingsFragmentPresenter.java b/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/features/settings/ui/SettingsFragmentPresenter.java index 7e2d15bb22..5a83729f17 100644 --- a/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/features/settings/ui/SettingsFragmentPresenter.java +++ b/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/features/settings/ui/SettingsFragmentPresenter.java @@ -324,10 +324,6 @@ public final class SettingsFragmentPresenter R.string.panic_handlers, R.string.panic_handlers_description)); sl.add(new SwitchSetting(mContext, BooleanSetting.MAIN_OSD_MESSAGES, R.string.osd_messages, R.string.osd_messages_description)); - sl.add(new SwitchSetting(mContext, BooleanSetting.MAIN_USE_GAME_COVERS, - R.string.download_game_covers, 0)); - sl.add(new SwitchSetting(mContext, BooleanSetting.MAIN_SHOW_GAME_TITLES, - R.string.show_titles_in_game_list, R.string.show_titles_in_game_list_description)); AbstractIntSetting appTheme = new AbstractIntSetting() { diff --git a/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/fragments/GridOptionDialogFragment.kt b/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/fragments/GridOptionDialogFragment.kt new file mode 100644 index 0000000000..94dda3f579 --- /dev/null +++ b/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/fragments/GridOptionDialogFragment.kt @@ -0,0 +1,124 @@ +package org.dolphinemu.dolphinemu.fragments + +import com.google.android.material.bottomsheet.BottomSheetDialogFragment +import android.view.LayoutInflater +import android.view.ViewGroup +import android.os.Bundle +import android.view.View +import com.google.android.material.bottomsheet.BottomSheetBehavior +import org.dolphinemu.dolphinemu.features.settings.model.BooleanSetting +import android.widget.CompoundButton +import androidx.appcompat.app.AppCompatActivity +import com.google.android.material.bottomsheet.BottomSheetDialog +import org.dolphinemu.dolphinemu.databinding.FragmentGridOptionsBinding +import org.dolphinemu.dolphinemu.databinding.FragmentGridOptionsTvBinding +import org.dolphinemu.dolphinemu.features.settings.model.NativeConfig +import org.dolphinemu.dolphinemu.ui.main.MainView + +class GridOptionDialogFragment : BottomSheetDialogFragment() { + + private lateinit var mView: MainView + + private var _mBindingMobile: FragmentGridOptionsBinding? = null + private var _mBindingTv: FragmentGridOptionsTvBinding? = null + + // This property is only valid between onCreateView and + // onDestroyView. + private val mBindingMobile get() = _mBindingMobile!! + private val mBindingTv get() = _mBindingTv!! + + override fun onCreateView( + inflater: LayoutInflater, container: ViewGroup?, + savedInstanceState: Bundle? + ): View { + mView = (activity as MainView) + + if (activity is AppCompatActivity) + { + _mBindingMobile = FragmentGridOptionsBinding.inflate(inflater, container, false) + return mBindingMobile.root + } + _mBindingTv = FragmentGridOptionsTvBinding.inflate(inflater, container, false) + return mBindingTv.root + } + + override fun onViewCreated(view: View, savedInstanceState: Bundle?) { + if (activity is AppCompatActivity) { + setUpCoverButtons() + setUpTitleButtons() + + // Pins fragment to the top of the dialog ensures the dialog is expanded in landscape by default + BottomSheetBehavior.from(mBindingMobile.gridSheet).state = + BottomSheetBehavior.STATE_EXPANDED + dialog?.setOnShowListener { + val dialog = it as BottomSheetDialog + mBindingMobile.gridSheet.let { sheet -> + dialog.behavior.peekHeight = sheet.height + } + } + } else { + setUpCoverButtonsTv() + + // Pins fragment to the top of the dialog ensures the dialog is expanded in landscape by default + BottomSheetBehavior.from(mBindingTv.gridSheet).state = + BottomSheetBehavior.STATE_EXPANDED + dialog?.setOnShowListener { + val dialog = it as BottomSheetDialog + mBindingTv.gridSheet.let { sheet -> + dialog.behavior.peekHeight = sheet.height + } + } + } + } + + override fun onDestroyView() { + super.onDestroyView() + _mBindingMobile = null + _mBindingTv = null + } + + private fun setUpCoverButtons() { + mBindingMobile.switchDownloadCovers.isChecked = + BooleanSetting.MAIN_USE_GAME_COVERS.booleanGlobal + mBindingMobile.rootDownloadCovers.setOnClickListener { + mBindingMobile.switchDownloadCovers.isChecked = !mBindingMobile.switchDownloadCovers.isChecked + } + mBindingMobile.switchDownloadCovers.setOnCheckedChangeListener { _: CompoundButton, _: Boolean -> + BooleanSetting.MAIN_USE_GAME_COVERS.setBooleanGlobal( + NativeConfig.LAYER_BASE, + mBindingMobile.switchDownloadCovers.isChecked + ) + mView.reloadGrid() + } + } + + private fun setUpTitleButtons() { + mBindingMobile.switchShowTitles.isChecked = BooleanSetting.MAIN_SHOW_GAME_TITLES.booleanGlobal + mBindingMobile.rootShowTitles.setOnClickListener { + mBindingMobile.switchShowTitles.isChecked = !mBindingMobile.switchShowTitles.isChecked + } + mBindingMobile.switchShowTitles.setOnCheckedChangeListener { _: CompoundButton, _: Boolean -> + BooleanSetting.MAIN_SHOW_GAME_TITLES.setBooleanGlobal( + NativeConfig.LAYER_BASE, + mBindingMobile.switchShowTitles.isChecked + ) + mView.reloadGrid() + } + } + + // TODO: Remove this when leanback is removed + private fun setUpCoverButtonsTv() { + mBindingTv.switchDownloadCovers.isChecked = + BooleanSetting.MAIN_USE_GAME_COVERS.booleanGlobal + mBindingTv.rootDownloadCovers.setOnClickListener { + mBindingTv.switchDownloadCovers.isChecked = !mBindingTv.switchDownloadCovers.isChecked + } + mBindingTv.switchDownloadCovers.setOnCheckedChangeListener { _: CompoundButton, _: Boolean -> + BooleanSetting.MAIN_USE_GAME_COVERS.setBooleanGlobal( + NativeConfig.LAYER_BASE, + mBindingTv.switchDownloadCovers.isChecked + ) + mView.reloadGrid() + } + } +} diff --git a/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/ui/main/MainActivity.java b/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/ui/main/MainActivity.java index 35e5b1051e..464c2a2c89 100644 --- a/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/ui/main/MainActivity.java +++ b/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/ui/main/MainActivity.java @@ -24,6 +24,7 @@ import androidx.swiperefreshlayout.widget.SwipeRefreshLayout; import com.google.android.material.color.MaterialColors; import com.google.android.material.tabs.TabLayout; +import org.dolphinemu.dolphinemu.fragments.GridOptionDialogFragment; import org.dolphinemu.dolphinemu.R; import org.dolphinemu.dolphinemu.activities.EmulationActivity; import org.dolphinemu.dolphinemu.adapters.PlatformPagerAdapter; @@ -123,10 +124,6 @@ public final class MainActivity extends AppCompatActivity } mPresenter.onResume(); - - // In case the user changed a setting that affects how games are displayed, - // such as system language, cover downloading... - forEachPlatformGamesView(PlatformGamesView::refetchMetadata); } @Override @@ -333,6 +330,18 @@ public final class MainActivity extends AppCompatActivity forEachPlatformGamesView(PlatformGamesView::showGames); } + @Override + public void reloadGrid() + { + forEachPlatformGamesView(PlatformGamesView::refetchMetadata); + } + + @Override + public void showGridOptions() + { + new GridOptionDialogFragment().show(getSupportFragmentManager(), "gridOptions"); + } + private void forEachPlatformGamesView(Action1 action) { for (Platform platform : Platform.values()) diff --git a/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/ui/main/MainPresenter.java b/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/ui/main/MainPresenter.java index d43187dcca..0115dba7cc 100644 --- a/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/ui/main/MainPresenter.java +++ b/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/ui/main/MainPresenter.java @@ -94,6 +94,10 @@ public final class MainPresenter mView.launchSettingsActivity(MenuTag.SETTINGS); return true; + case R.id.menu_grid_options: + mView.showGridOptions(); + return true; + case R.id.menu_refresh: mView.setRefreshing(true); GameFileCacheManager.startRescan(); diff --git a/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/ui/main/MainView.java b/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/ui/main/MainView.java index a40b0a7d7d..604cb5d1a8 100644 --- a/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/ui/main/MainView.java +++ b/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/ui/main/MainView.java @@ -34,4 +34,8 @@ public interface MainView * To be called when the game file cache is updated. */ void showGames(); + + void reloadGrid(); + + void showGridOptions(); } diff --git a/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/ui/main/TvMainActivity.java b/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/ui/main/TvMainActivity.java index 925c755880..21a8fc2880 100644 --- a/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/ui/main/TvMainActivity.java +++ b/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/ui/main/TvMainActivity.java @@ -19,6 +19,7 @@ import androidx.leanback.widget.ListRow; import androidx.leanback.widget.ListRowPresenter; import androidx.swiperefreshlayout.widget.SwipeRefreshLayout; +import org.dolphinemu.dolphinemu.fragments.GridOptionDialogFragment; import org.dolphinemu.dolphinemu.R; import org.dolphinemu.dolphinemu.activities.EmulationActivity; import org.dolphinemu.dolphinemu.adapters.GameRowPresenter; @@ -87,10 +88,6 @@ public final class TvMainActivity extends FragmentActivity } mPresenter.onResume(); - - // In case the user changed a setting that affects how games are displayed, - // such as system language, cover downloading... - refetchMetadata(); } @Override @@ -217,7 +214,8 @@ public final class TvMainActivity extends FragmentActivity buildRowsAdapter(); } - private void refetchMetadata() + @Override + public void reloadGrid() { for (ArrayObjectAdapter row : mGameRows) { @@ -225,6 +223,12 @@ public final class TvMainActivity extends FragmentActivity } } + @Override + public void showGridOptions() + { + new GridOptionDialogFragment().show(getSupportFragmentManager(), "gridOptions"); + } + /** * Callback from AddDirectoryActivity. Applies any changes necessary to the GameGridActivity. * @@ -370,6 +374,10 @@ public final class TvMainActivity extends FragmentActivity R.drawable.ic_add_tv, R.string.add_directory_title)); + rowItems.add(new TvSettingsItem(R.id.menu_grid_options, + R.drawable.ic_list_tv, + R.string.grid_menu_grid_options)); + rowItems.add(new TvSettingsItem(R.id.menu_refresh, R.drawable.ic_refresh_tv, R.string.grid_menu_refresh)); diff --git a/Source/Android/app/src/main/res/drawable/ic_list.xml b/Source/Android/app/src/main/res/drawable/ic_list.xml new file mode 100644 index 0000000000..390068de6e --- /dev/null +++ b/Source/Android/app/src/main/res/drawable/ic_list.xml @@ -0,0 +1,9 @@ + + + diff --git a/Source/Android/app/src/main/res/drawable/ic_list_tv.xml b/Source/Android/app/src/main/res/drawable/ic_list_tv.xml new file mode 100644 index 0000000000..f4dc846c67 --- /dev/null +++ b/Source/Android/app/src/main/res/drawable/ic_list_tv.xml @@ -0,0 +1,9 @@ + + + diff --git a/Source/Android/app/src/main/res/layout/fragment_grid_options.xml b/Source/Android/app/src/main/res/layout/fragment_grid_options.xml new file mode 100644 index 0000000000..d00138b395 --- /dev/null +++ b/Source/Android/app/src/main/res/layout/fragment_grid_options.xml @@ -0,0 +1,83 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/Source/Android/app/src/main/res/layout/fragment_grid_options_tv.xml b/Source/Android/app/src/main/res/layout/fragment_grid_options_tv.xml new file mode 100644 index 0000000000..b3f4d407a0 --- /dev/null +++ b/Source/Android/app/src/main/res/layout/fragment_grid_options_tv.xml @@ -0,0 +1,48 @@ + + + + + + + + + + + + + + + + diff --git a/Source/Android/app/src/main/res/menu/menu_game_grid.xml b/Source/Android/app/src/main/res/menu/menu_game_grid.xml index b6232e830b..47c551a51a 100644 --- a/Source/Android/app/src/main/res/menu/menu_game_grid.xml +++ b/Source/Android/app/src/main/res/menu/menu_game_grid.xml @@ -8,6 +8,12 @@ android:icon="@drawable/ic_settings" app:showAsAction="ifRoom"/> + + @style/MaterialDialog @style/ThemeOverlay.Material3 + @style/Widget.Material3.ExtendedFloatingActionButton.Primary diff --git a/Source/Android/app/src/main/res/values-v31/themes.xml b/Source/Android/app/src/main/res/values-v31/themes.xml index f1ed53cc81..15f9c1ea31 100644 --- a/Source/Android/app/src/main/res/values-v31/themes.xml +++ b/Source/Android/app/src/main/res/values-v31/themes.xml @@ -26,5 +26,6 @@ @style/MaterialDialog @style/ThemeOverlay.Material3 + @style/Widget.Material3.ExtendedFloatingActionButton.Primary diff --git a/Source/Android/app/src/main/res/values/strings.xml b/Source/Android/app/src/main/res/values/strings.xml index 0fdc259ab5..e970976b8b 100644 --- a/Source/Android/app/src/main/res/values/strings.xml +++ b/Source/Android/app/src/main/res/values/strings.xml @@ -193,8 +193,7 @@ Show On-Screen Display Messages Display messages over the emulation screen area. These messages include memory card writes, video backend and CPU information, and JIT cache clearing. Download Game Covers from GameTDB.com - Show Titles in Game List - Show the title and creator below each game cover. + Show Titles Change App Theme Change Theme Mode Use Black Backgrounds @@ -442,6 +441,7 @@ Add Games Add Folder to Library Settings + Grid Options Refresh Library Open File Install WAD diff --git a/Source/Android/app/src/main/res/values/styles.xml b/Source/Android/app/src/main/res/values/styles.xml index 01a81238ba..5580b5a823 100644 --- a/Source/Android/app/src/main/res/values/styles.xml +++ b/Source/Android/app/src/main/res/values/styles.xml @@ -60,4 +60,17 @@ + + + + + + diff --git a/Source/Android/app/src/main/res/values/themes.xml b/Source/Android/app/src/main/res/values/themes.xml index 177febe54b..3a361c693c 100644 --- a/Source/Android/app/src/main/res/values/themes.xml +++ b/Source/Android/app/src/main/res/values/themes.xml @@ -16,8 +16,8 @@