From 33048d0d4cc7532d1d5d72947f413d3dcdd07e31 Mon Sep 17 00:00:00 2001 From: Charles Lombardo Date: Tue, 13 Sep 2022 20:59:58 -0400 Subject: [PATCH] Android: Use material dividers --- .../features/cheats/ui/CheatListFragment.java | 9 +- .../settings/ui/SettingsFragment.java | 9 +- .../dolphinemu/ui/DividerItemDecoration.java | 162 ------------------ .../res/layout-land/activity_user_data.xml | 9 +- .../layout-w680dp-land/activity_convert.xml | 3 +- .../src/main/res/layout/activity_convert.xml | 5 +- .../res/layout/activity_riivolution_boot.xml | 5 +- .../main/res/layout/dialog_game_details.xml | 10 +- .../main/res/layout/fragment_ingame_menu.xml | 9 +- .../app/src/main/res/values/styles.xml | 4 + .../app/src/main/res/values/themes.xml | 1 + 11 files changed, 36 insertions(+), 190 deletions(-) delete mode 100644 Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/ui/DividerItemDecoration.java diff --git a/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/features/cheats/ui/CheatListFragment.java b/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/features/cheats/ui/CheatListFragment.java index efc446d50e..a2cf37dba8 100644 --- a/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/features/cheats/ui/CheatListFragment.java +++ b/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/features/cheats/ui/CheatListFragment.java @@ -14,9 +14,10 @@ import androidx.lifecycle.ViewModelProvider; import androidx.recyclerview.widget.LinearLayoutManager; import androidx.recyclerview.widget.RecyclerView; +import com.google.android.material.divider.MaterialDividerItemDecoration; + import org.dolphinemu.dolphinemu.R; import org.dolphinemu.dolphinemu.features.cheats.model.CheatsViewModel; -import org.dolphinemu.dolphinemu.ui.DividerItemDecoration; public class CheatListFragment extends Fragment { @@ -38,6 +39,10 @@ public class CheatListFragment extends Fragment recyclerView.setAdapter(new CheatsAdapter(activity, viewModel)); recyclerView.setLayoutManager(new LinearLayoutManager(activity)); - recyclerView.addItemDecoration(new DividerItemDecoration(activity, null)); + + MaterialDividerItemDecoration divider = + new MaterialDividerItemDecoration(requireActivity(), LinearLayoutManager.VERTICAL); + divider.setLastItemDecorated(false); + recyclerView.addItemDecoration(divider); } } diff --git a/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/features/settings/ui/SettingsFragment.java b/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/features/settings/ui/SettingsFragment.java index 86a5650de5..89587ea535 100644 --- a/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/features/settings/ui/SettingsFragment.java +++ b/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/features/settings/ui/SettingsFragment.java @@ -14,10 +14,11 @@ import androidx.fragment.app.Fragment; import androidx.recyclerview.widget.LinearLayoutManager; import androidx.recyclerview.widget.RecyclerView; +import com.google.android.material.divider.MaterialDividerItemDecoration; + import org.dolphinemu.dolphinemu.R; import org.dolphinemu.dolphinemu.features.settings.model.Settings; import org.dolphinemu.dolphinemu.features.settings.model.view.SettingsItem; -import org.dolphinemu.dolphinemu.ui.DividerItemDecoration; import java.util.ArrayList; import java.util.HashMap; @@ -136,7 +137,11 @@ public final class SettingsFragment extends Fragment implements SettingsFragment recyclerView.setAdapter(mAdapter); recyclerView.setLayoutManager(manager); - recyclerView.addItemDecoration(new DividerItemDecoration(requireActivity(), null)); + + MaterialDividerItemDecoration divider = + new MaterialDividerItemDecoration(requireActivity(), LinearLayoutManager.VERTICAL); + divider.setLastItemDecorated(false); + recyclerView.addItemDecoration(divider); SettingsActivityView activity = (SettingsActivityView) getActivity(); mPresenter.onViewCreated(menuTag, activity.getSettings()); diff --git a/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/ui/DividerItemDecoration.java b/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/ui/DividerItemDecoration.java deleted file mode 100644 index f7a1689af5..0000000000 --- a/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/ui/DividerItemDecoration.java +++ /dev/null @@ -1,162 +0,0 @@ -// SPDX-License-Identifier: GPL-2.0-or-later - -package org.dolphinemu.dolphinemu.ui; - -import android.content.Context; -import android.content.res.TypedArray; -import android.graphics.Canvas; -import android.graphics.Rect; -import android.graphics.drawable.Drawable; -import android.util.AttributeSet; -import android.view.View; - -import androidx.annotation.NonNull; -import androidx.recyclerview.widget.LinearLayoutManager; -import androidx.recyclerview.widget.RecyclerView; - -/** - * Implementation from: - * https://gist.github.com/lapastillaroja/858caf1a82791b6c1a36 - */ -public final class DividerItemDecoration extends RecyclerView.ItemDecoration -{ - - private Drawable mDivider; - private boolean mShowFirstDivider = false; - private boolean mShowLastDivider = false; - - public DividerItemDecoration(Context context, AttributeSet attrs) - { - final TypedArray a = context - .obtainStyledAttributes(attrs, new int[]{android.R.attr.listDivider}); - mDivider = a.getDrawable(0); - a.recycle(); - } - - public DividerItemDecoration(Context context, AttributeSet attrs, boolean showFirstDivider, - boolean showLastDivider) - { - this(context, attrs); - mShowFirstDivider = showFirstDivider; - mShowLastDivider = showLastDivider; - } - - public DividerItemDecoration(Drawable divider) - { - mDivider = divider; - } - - public DividerItemDecoration(Drawable divider, boolean showFirstDivider, - boolean showLastDivider) - { - this(divider); - mShowFirstDivider = showFirstDivider; - mShowLastDivider = showLastDivider; - } - - @Override - public void getItemOffsets(@NonNull Rect outRect, @NonNull View view, - @NonNull RecyclerView parent, - @NonNull RecyclerView.State state) - { - super.getItemOffsets(outRect, view, parent, state); - if (mDivider == null) - { - return; - } - if (parent.getChildAdapterPosition(view) < 1) - { - return; - } - - if (getOrientation(parent) == LinearLayoutManager.VERTICAL) - { - outRect.top = mDivider.getIntrinsicHeight(); - } - else - { - outRect.left = mDivider.getIntrinsicWidth(); - } - } - - @Override - public void onDrawOver(@NonNull Canvas c, @NonNull RecyclerView parent, - @NonNull RecyclerView.State state) - { - if (mDivider == null) - { - super.onDrawOver(c, parent, state); - return; - } - - // Initialization needed to avoid compiler warning - int left = 0, right = 0, top = 0, bottom = 0, size; - int orientation = getOrientation(parent); - int childCount = parent.getChildCount(); - - if (orientation == LinearLayoutManager.VERTICAL) - { - size = mDivider.getIntrinsicHeight(); - left = parent.getPaddingLeft(); - right = parent.getWidth() - parent.getPaddingRight(); - } - else - { //horizontal - size = mDivider.getIntrinsicWidth(); - top = parent.getPaddingTop(); - bottom = parent.getHeight() - parent.getPaddingBottom(); - } - - for (int i = mShowFirstDivider ? 0 : 1; i < childCount; i++) - { - View child = parent.getChildAt(i); - RecyclerView.LayoutParams params = (RecyclerView.LayoutParams) child.getLayoutParams(); - - if (orientation == LinearLayoutManager.VERTICAL) - { - top = child.getTop() - params.topMargin; - bottom = top + size; - } - else - { //horizontal - left = child.getLeft() - params.leftMargin; - right = left + size; - } - mDivider.setBounds(left, top, right, bottom); - mDivider.draw(c); - } - - // show last divider - if (mShowLastDivider && childCount > 0) - { - View child = parent.getChildAt(childCount - 1); - RecyclerView.LayoutParams params = (RecyclerView.LayoutParams) child.getLayoutParams(); - if (orientation == LinearLayoutManager.VERTICAL) - { - top = child.getBottom() + params.bottomMargin; - bottom = top + size; - } - else - { // horizontal - left = child.getRight() + params.rightMargin; - right = left + size; - } - mDivider.setBounds(left, top, right, bottom); - mDivider.draw(c); - } - } - - private int getOrientation(RecyclerView parent) - { - if (parent.getLayoutManager() instanceof LinearLayoutManager) - { - LinearLayoutManager layoutManager = (LinearLayoutManager) parent.getLayoutManager(); - return layoutManager.getOrientation(); - } - else - { - throw new IllegalStateException( - "DividerItemDecoration can only be used with a LinearLayoutManager."); - } - } -} diff --git a/Source/Android/app/src/main/res/layout-land/activity_user_data.xml b/Source/Android/app/src/main/res/layout-land/activity_user_data.xml index 597e598266..24863dcd5f 100644 --- a/Source/Android/app/src/main/res/layout-land/activity_user_data.xml +++ b/Source/Android/app/src/main/res/layout-land/activity_user_data.xml @@ -50,7 +50,7 @@ app:layout_constraintWidth_max="400dp" app:layout_constraintEnd_toStartOf="@id/divider" app:layout_constraintStart_toStartOf="parent" - app:layout_constraintTop_toTopOf="@id/divider" + app:layout_constraintTop_toTopOf="parent" tools:text="@string/user_data_new_location" /> - diff --git a/Source/Android/app/src/main/res/layout-w680dp-land/activity_convert.xml b/Source/Android/app/src/main/res/layout-w680dp-land/activity_convert.xml index 8091203873..1c00d679a6 100644 --- a/Source/Android/app/src/main/res/layout-w680dp-land/activity_convert.xml +++ b/Source/Android/app/src/main/res/layout-w680dp-land/activity_convert.xml @@ -53,11 +53,10 @@ app:layout_constraintStart_toStartOf="parent" app:layout_constraintEnd_toStartOf="@id/divider" /> - - - - - - + android:layout_marginBottom="16dp" />