summaryrefslogtreecommitdiff
path: root/Source/Android/app/src
diff options
context:
space:
mode:
authorJosJuice <josjuice@gmail.com>2022-11-16 20:47:59 +0100
committerGitHub <noreply@github.com>2022-11-16 20:47:59 +0100
commitcecd4d15fe476b580966c805463e002f11d3bad1 (patch)
tree7d96d92f528e87e3fc417a9418162415049d1fb2 /Source/Android/app/src
parent7ce2be93861ba741b5b415afba76e27cea71ac17 (diff)
parenteb060c73567ea5ef93ca4848f003c620d4ec6a0c (diff)
Merge pull request #11254 from t895/adaptive-grid
Android: Dynamically adapt grid span to card_game size
Diffstat (limited to 'Source/Android/app/src')
-rw-r--r--Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/ui/platform/PlatformGamesFragment.java33
-rw-r--r--Source/Android/app/src/main/res/layout/fragment_grid.xml4
-rw-r--r--Source/Android/app/src/main/res/values-w1000dp/integers.xml4
-rw-r--r--Source/Android/app/src/main/res/values-w1050dp/dimens.xml6
-rw-r--r--Source/Android/app/src/main/res/values-w300dp/integers.xml4
-rw-r--r--Source/Android/app/src/main/res/values-w400dp/integers.xml4
-rw-r--r--Source/Android/app/src/main/res/values-w500dp/integers.xml4
-rw-r--r--Source/Android/app/src/main/res/values-w750dp/integers.xml4
-rw-r--r--Source/Android/app/src/main/res/values-w820dp/dimens.xml5
-rw-r--r--Source/Android/app/src/main/res/values/dimens.xml4
-rw-r--r--Source/Android/app/src/main/res/values/integers.xml1
11 files changed, 28 insertions, 45 deletions
diff --git a/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/ui/platform/PlatformGamesFragment.java b/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/ui/platform/PlatformGamesFragment.java
index 9b3cd0e87f..527b7d659d 100644
--- a/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/ui/platform/PlatformGamesFragment.java
+++ b/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/ui/platform/PlatformGamesFragment.java
@@ -6,12 +6,12 @@ import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
+import android.view.ViewTreeObserver;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.fragment.app.Fragment;
import androidx.recyclerview.widget.GridLayoutManager;
-import androidx.recyclerview.widget.RecyclerView;
import androidx.swiperefreshlayout.widget.SwipeRefreshLayout;
import com.google.android.material.color.MaterialColors;
@@ -62,11 +62,33 @@ public final class PlatformGamesFragment extends Fragment implements PlatformGam
public void onViewCreated(@NonNull View view, Bundle savedInstanceState)
{
mSwipeRefresh = mBinding.swipeRefresh;
-
- int columns = getResources().getInteger(R.integer.game_grid_columns);
- RecyclerView.LayoutManager layoutManager = new GridLayoutManager(getActivity(), columns);
mAdapter = new GameAdapter(requireActivity());
+ // Here we have to make sure the fragment is attached to an activity, wait for the layout
+ // to be drawn, and make sure it is drawn with a width > 0 before finding the correct
+ // span for our grid layout. Once drawn correctly, we can stop listening for layout changes.
+ if (isAdded())
+ {
+ view.getViewTreeObserver()
+ .addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener()
+ {
+ @Override
+ public void onGlobalLayout()
+ {
+ int columns = mBinding.getRoot().getMeasuredWidth() /
+ requireContext().getResources().getDimensionPixelSize(R.dimen.card_width);
+ if (columns == 0)
+ {
+ columns = 1;
+ }
+ view.getViewTreeObserver().removeOnGlobalLayoutListener(this);
+ GridLayoutManager layoutManager = new GridLayoutManager(getActivity(), columns);
+ mBinding.gridGames.setLayoutManager(layoutManager);
+ mBinding.gridGames.setAdapter(mAdapter);
+ }
+ });
+ }
+
// Set theme color to the refresh animation's background
mSwipeRefresh.setProgressBackgroundColorSchemeColor(
MaterialColors.getColor(mSwipeRefresh, R.attr.colorPrimary));
@@ -75,9 +97,6 @@ public final class PlatformGamesFragment extends Fragment implements PlatformGam
mSwipeRefresh.setOnRefreshListener(mOnRefreshListener);
- mBinding.gridGames.setLayoutManager(layoutManager);
- mBinding.gridGames.setAdapter(mAdapter);
-
InsetsHelper.setUpList(getContext(), mBinding.gridGames);
setRefreshing(GameFileCacheManager.isLoadingOrRescanning());
diff --git a/Source/Android/app/src/main/res/layout/fragment_grid.xml b/Source/Android/app/src/main/res/layout/fragment_grid.xml
index 62be5a20ea..16395414c6 100644
--- a/Source/Android/app/src/main/res/layout/fragment_grid.xml
+++ b/Source/Android/app/src/main/res/layout/fragment_grid.xml
@@ -7,9 +7,7 @@
<androidx.swiperefreshlayout.widget.SwipeRefreshLayout
android:id="@+id/swipe_refresh"
android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:layout_marginLeft="@dimen/activity_horizontal_margin"
- android:layout_marginRight="@dimen/activity_horizontal_margin">
+ android:layout_height="wrap_content">
<androidx.recyclerview.widget.RecyclerView
android:id="@+id/grid_games"
diff --git a/Source/Android/app/src/main/res/values-w1000dp/integers.xml b/Source/Android/app/src/main/res/values-w1000dp/integers.xml
deleted file mode 100644
index 2609297d5b..0000000000
--- a/Source/Android/app/src/main/res/values-w1000dp/integers.xml
+++ /dev/null
@@ -1,4 +0,0 @@
-<?xml version="1.0" encoding="utf-8"?>
-<resources>
- <integer name="game_grid_columns">8</integer>
-</resources> \ No newline at end of file
diff --git a/Source/Android/app/src/main/res/values-w1050dp/dimens.xml b/Source/Android/app/src/main/res/values-w1050dp/dimens.xml
deleted file mode 100644
index 92fcb2b668..0000000000
--- a/Source/Android/app/src/main/res/values-w1050dp/dimens.xml
+++ /dev/null
@@ -1,6 +0,0 @@
-<?xml version="1.0" encoding="utf-8"?>
-<resources>
- <!-- Example customization of dimensions originally defined in res/values/dimens.xml
- (such as screen margins) for screens with more than 1024dp of available width. -->
- <dimen name="activity_horizontal_margin">96dp</dimen>
-</resources>
diff --git a/Source/Android/app/src/main/res/values-w300dp/integers.xml b/Source/Android/app/src/main/res/values-w300dp/integers.xml
deleted file mode 100644
index 250e291e9d..0000000000
--- a/Source/Android/app/src/main/res/values-w300dp/integers.xml
+++ /dev/null
@@ -1,4 +0,0 @@
-<?xml version="1.0" encoding="utf-8"?>
-<resources>
- <integer name="game_grid_columns">2</integer>
-</resources>
diff --git a/Source/Android/app/src/main/res/values-w400dp/integers.xml b/Source/Android/app/src/main/res/values-w400dp/integers.xml
deleted file mode 100644
index 4148b62c39..0000000000
--- a/Source/Android/app/src/main/res/values-w400dp/integers.xml
+++ /dev/null
@@ -1,4 +0,0 @@
-<?xml version="1.0" encoding="utf-8"?>
-<resources>
- <integer name="game_grid_columns">3</integer>
-</resources>
diff --git a/Source/Android/app/src/main/res/values-w500dp/integers.xml b/Source/Android/app/src/main/res/values-w500dp/integers.xml
deleted file mode 100644
index 5cd4e24f38..0000000000
--- a/Source/Android/app/src/main/res/values-w500dp/integers.xml
+++ /dev/null
@@ -1,4 +0,0 @@
-<?xml version="1.0" encoding="utf-8"?>
-<resources>
- <integer name="game_grid_columns">4</integer>
-</resources> \ No newline at end of file
diff --git a/Source/Android/app/src/main/res/values-w750dp/integers.xml b/Source/Android/app/src/main/res/values-w750dp/integers.xml
deleted file mode 100644
index 4dbc25806e..0000000000
--- a/Source/Android/app/src/main/res/values-w750dp/integers.xml
+++ /dev/null
@@ -1,4 +0,0 @@
-<?xml version="1.0" encoding="utf-8"?>
-<resources>
- <integer name="game_grid_columns">6</integer>
-</resources> \ No newline at end of file
diff --git a/Source/Android/app/src/main/res/values-w820dp/dimens.xml b/Source/Android/app/src/main/res/values-w820dp/dimens.xml
deleted file mode 100644
index d27181e85e..0000000000
--- a/Source/Android/app/src/main/res/values-w820dp/dimens.xml
+++ /dev/null
@@ -1,5 +0,0 @@
-<resources>
- <!-- Example customization of dimensions originally defined in res/values/dimens.xml
- (such as screen margins) for screens with more than 820dp of available width. -->
- <dimen name="activity_horizontal_margin">64dp</dimen>
-</resources>
diff --git a/Source/Android/app/src/main/res/values/dimens.xml b/Source/Android/app/src/main/res/values/dimens.xml
index e0e16c895e..fa4901ee10 100644
--- a/Source/Android/app/src/main/res/values/dimens.xml
+++ b/Source/Android/app/src/main/res/values/dimens.xml
@@ -1,8 +1,6 @@
<resources>
- <!-- Default screen margins, per the Android Design guidelines. -->
- <dimen name="activity_horizontal_margin">16dp</dimen>
-
<dimen name="spacing_small">4dp</dimen>
<dimen name="spacing_medlarge">12dp</dimen>
<dimen name="spacing_large">16dp</dimen>
+ <dimen name="card_width">140dp</dimen>
</resources>
diff --git a/Source/Android/app/src/main/res/values/integers.xml b/Source/Android/app/src/main/res/values/integers.xml
index 676ebabe7b..b1c1915fa8 100644
--- a/Source/Android/app/src/main/res/values/integers.xml
+++ b/Source/Android/app/src/main/res/values/integers.xml
@@ -1,7 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<integer name="game_title_lines">2</integer>
- <integer name="game_grid_columns">1</integer>
<integer name="loadsave_state_columns">1</integer>
<integer name="loadsave_state_rows">6</integer>