From 0614596f54c0ae09427923df1e34788a65985e99 Mon Sep 17 00:00:00 2001 From: damontecres <154766448+damontecres@users.noreply.github.com> Date: Wed, 21 Feb 2024 19:48:11 -0500 Subject: [PATCH] Customize card sizes (#130) Add a preference to set the size of cards. This replaces the number of columns preference. --- .../stashapp/FilterListActivity.kt | 11 ++++++++ .../damontecres/stashapp/MainFragment.kt | 4 ++- .../damontecres/stashapp/PerformerActivity.kt | 10 ++++++- .../damontecres/stashapp/SettingsFragment.kt | 1 - .../damontecres/stashapp/StashGridFragment.kt | 15 ++++++----- .../stashapp/presenters/StashImageCardView.kt | 10 +++++-- .../damontecres/stashapp/util/Constants.kt | 15 +++++++++++ app/src/main/res/values/arrays.xml | 26 +++++++++++++++++++ app/src/main/res/xml/root_preferences.xml | 14 +++++----- 9 files changed, 88 insertions(+), 18 deletions(-) diff --git a/app/src/main/java/com/github/damontecres/stashapp/FilterListActivity.kt b/app/src/main/java/com/github/damontecres/stashapp/FilterListActivity.kt index 787d4437..2f83d0ff 100644 --- a/app/src/main/java/com/github/damontecres/stashapp/FilterListActivity.kt +++ b/app/src/main/java/com/github/damontecres/stashapp/FilterListActivity.kt @@ -15,6 +15,7 @@ import androidx.appcompat.widget.ListPopupWindow import androidx.fragment.app.FragmentActivity import androidx.leanback.widget.ClassPresenterSelector import androidx.lifecycle.lifecycleScope +import androidx.preference.PreferenceManager import com.apollographql.apollo3.api.Query import com.github.damontecres.stashapp.api.fragment.MarkerData import com.github.damontecres.stashapp.api.fragment.SavedFilterData @@ -22,6 +23,8 @@ import com.github.damontecres.stashapp.api.type.FindFilterType import com.github.damontecres.stashapp.api.type.SortDirectionEnum import com.github.damontecres.stashapp.data.DataType import com.github.damontecres.stashapp.presenters.MarkerPresenter +import com.github.damontecres.stashapp.presenters.PerformerPresenter +import com.github.damontecres.stashapp.presenters.ScenePresenter import com.github.damontecres.stashapp.presenters.StashPresenter import com.github.damontecres.stashapp.suppliers.MarkerDataSupplier import com.github.damontecres.stashapp.suppliers.MovieDataSupplier @@ -38,6 +41,7 @@ import com.github.damontecres.stashapp.util.SceneComparator import com.github.damontecres.stashapp.util.StudioComparator import com.github.damontecres.stashapp.util.TagComparator import com.github.damontecres.stashapp.util.convertFilter +import com.github.damontecres.stashapp.util.getInt import com.github.damontecres.stashapp.util.toPx import kotlinx.coroutines.CoroutineExceptionHandler import kotlinx.coroutines.launch @@ -231,6 +235,12 @@ class FilterListActivity : FragmentActivity() { findFilter: FindFilterType?, objectFilter: Any?, ): StashGridFragment { + val cardSize = + PreferenceManager.getDefaultSharedPreferences(this) + .getInt("cardSize", getString(R.string.card_size_default)) + val performerCardSize = + (cardSize * (ScenePresenter.CARD_WIDTH.toDouble() / PerformerPresenter.CARD_WIDTH)).toInt() + // TODO other sizes return when (dataType) { DataType.SCENE -> { val sceneFilter = @@ -250,6 +260,7 @@ class FilterListActivity : FragmentActivity() { StashGridFragment( PerformerComparator, PerformerDataSupplier(findFilter, performerFilter), + performerCardSize, ) } diff --git a/app/src/main/java/com/github/damontecres/stashapp/MainFragment.kt b/app/src/main/java/com/github/damontecres/stashapp/MainFragment.kt index 16274aff..527be93c 100644 --- a/app/src/main/java/com/github/damontecres/stashapp/MainFragment.kt +++ b/app/src/main/java/com/github/damontecres/stashapp/MainFragment.kt @@ -37,6 +37,7 @@ import com.github.damontecres.stashapp.util.StashCoroutineExceptionHandler import com.github.damontecres.stashapp.util.Version import com.github.damontecres.stashapp.util.convertFilter import com.github.damontecres.stashapp.util.getCaseInsensitive +import com.github.damontecres.stashapp.util.getInt import com.github.damontecres.stashapp.util.supportedFilterModes import com.github.damontecres.stashapp.util.testStashConnection import kotlinx.coroutines.CoroutineExceptionHandler @@ -62,7 +63,8 @@ class MainFragment : BrowseSupportFragment() { val apiKey = manager.getString("stashApiKey", null) val maxSearchResults = manager.getInt("maxSearchResults", 0) val playVideoPreviews = manager.getBoolean("playVideoPreviews", true) - return Objects.hash(url, apiKey, maxSearchResults, playVideoPreviews) + val columns = manager.getInt("cardSize", getString(R.string.card_size_default)) + return Objects.hash(url, apiKey, maxSearchResults, playVideoPreviews, columns) } override fun onCreate(savedInstanceState: Bundle?) { diff --git a/app/src/main/java/com/github/damontecres/stashapp/PerformerActivity.kt b/app/src/main/java/com/github/damontecres/stashapp/PerformerActivity.kt index 9dd56698..561d0bb8 100644 --- a/app/src/main/java/com/github/damontecres/stashapp/PerformerActivity.kt +++ b/app/src/main/java/com/github/damontecres/stashapp/PerformerActivity.kt @@ -3,6 +3,7 @@ package com.github.damontecres.stashapp import android.os.Bundle import androidx.fragment.app.FragmentActivity import androidx.leanback.widget.ObjectAdapter +import androidx.preference.PreferenceManager import com.apollographql.apollo3.api.Optional import com.github.damontecres.stashapp.api.FindScenesQuery import com.github.damontecres.stashapp.api.fragment.SlimSceneData @@ -14,6 +15,7 @@ import com.github.damontecres.stashapp.api.type.SortDirectionEnum import com.github.damontecres.stashapp.data.Performer import com.github.damontecres.stashapp.suppliers.SceneDataSupplier import com.github.damontecres.stashapp.util.SceneComparator +import com.github.damontecres.stashapp.util.getInt class PerformerActivity : FragmentActivity() { private lateinit var sceneFragment: StashGridFragment @@ -24,6 +26,12 @@ class PerformerActivity : FragmentActivity() { if (savedInstanceState == null) { val performer = this.intent.getParcelableExtra("performer") + val cardSize = + PreferenceManager.getDefaultSharedPreferences(this) + .getInt("cardSize", getString(R.string.card_size_default)) + // At medium size, 3 scenes fit in the space vs 5 normally + val columns = cardSize * 3 / 5 + sceneFragment = StashGridFragment( SceneComparator, @@ -42,7 +50,7 @@ class PerformerActivity : FragmentActivity() { ), ), ), - 3, + columns, ) supportFragmentManager.beginTransaction() diff --git a/app/src/main/java/com/github/damontecres/stashapp/SettingsFragment.kt b/app/src/main/java/com/github/damontecres/stashapp/SettingsFragment.kt index 7f33f887..bcdccace 100644 --- a/app/src/main/java/com/github/damontecres/stashapp/SettingsFragment.kt +++ b/app/src/main/java/com/github/damontecres/stashapp/SettingsFragment.kt @@ -305,7 +305,6 @@ class SettingsFragment : LeanbackSettingsFragmentCompat() { findPreference("maxSearchResults")?.min = 5 findPreference("skip_back_time")?.min = 5 findPreference("skip_forward_time")?.min = 5 - findPreference("numberOfColumns")?.min = 1 findPreference("searchDelay")?.min = 50 } diff --git a/app/src/main/java/com/github/damontecres/stashapp/StashGridFragment.kt b/app/src/main/java/com/github/damontecres/stashapp/StashGridFragment.kt index f0a398f9..e0d7c3e4 100644 --- a/app/src/main/java/com/github/damontecres/stashapp/StashGridFragment.kt +++ b/app/src/main/java/com/github/damontecres/stashapp/StashGridFragment.kt @@ -20,6 +20,7 @@ import com.apollographql.apollo3.api.Query import com.github.damontecres.stashapp.api.fragment.SavedFilterData import com.github.damontecres.stashapp.presenters.StashPresenter import com.github.damontecres.stashapp.suppliers.StashPagingSource +import com.github.damontecres.stashapp.util.getInt import kotlinx.coroutines.flow.collectLatest import kotlinx.coroutines.launch @@ -28,13 +29,13 @@ class StashGridFragment( comparator: DiffUtil.ItemCallback, private val dataSupplier: StashPagingSource.DataSupplier, val filter: SavedFilterData?, - private val numberOfColumns: Int? = null, + private val cardSize: Int? = null, ) : VerticalGridSupportFragment() { constructor( comparator: DiffUtil.ItemCallback, dataSupplier: StashPagingSource.DataSupplier, - numberOfColumns: Int? = null, - ) : this(StashPresenter.SELECTOR, comparator, dataSupplier, null, numberOfColumns) + cardSize: Int? = null, + ) : this(StashPresenter.SELECTOR, comparator, dataSupplier, null, cardSize) val mAdapter = PagingDataAdapter(presenter, comparator) @@ -42,9 +43,11 @@ class StashGridFragment( super.onCreate(savedInstanceState) val gridPresenter = StashGridPresenter() - gridPresenter.numberOfColumns = - numberOfColumns ?: PreferenceManager.getDefaultSharedPreferences(requireContext()) - .getInt("numberOfColumns", 5) + val columns = + cardSize ?: PreferenceManager.getDefaultSharedPreferences(requireContext()) + .getInt("cardSize", requireContext().getString(R.string.card_size_default)) + + gridPresenter.numberOfColumns = columns setGridPresenter(gridPresenter) adapter = mAdapter diff --git a/app/src/main/java/com/github/damontecres/stashapp/presenters/StashImageCardView.kt b/app/src/main/java/com/github/damontecres/stashapp/presenters/StashImageCardView.kt index b708d28b..547c74b6 100644 --- a/app/src/main/java/com/github/damontecres/stashapp/presenters/StashImageCardView.kt +++ b/app/src/main/java/com/github/damontecres/stashapp/presenters/StashImageCardView.kt @@ -17,6 +17,7 @@ import androidx.preference.PreferenceManager import com.github.damontecres.stashapp.R import com.github.damontecres.stashapp.StashExoPlayer import com.github.damontecres.stashapp.data.DataType +import com.github.damontecres.stashapp.util.getInt import com.github.damontecres.stashapp.util.isNotNullOrBlank import java.util.EnumMap @@ -110,9 +111,14 @@ class StashImageCardView(context: Context) : ImageCardView(context) { width: Int, height: Int, ) { + val cardSize = + PreferenceManager.getDefaultSharedPreferences(context) + .getInt("cardSize", context.getString(R.string.card_size_default)) + val scaledWidth = (width * 5.0 / cardSize).toInt() + val scaledHeight = (height * 5.0 / cardSize).toInt() val lp = mainView.layoutParams - lp.width = width - lp.height = height + lp.width = scaledWidth + lp.height = scaledHeight mainView.layoutParams = lp } diff --git a/app/src/main/java/com/github/damontecres/stashapp/util/Constants.kt b/app/src/main/java/com/github/damontecres/stashapp/util/Constants.kt index ab040cf6..aae368a3 100644 --- a/app/src/main/java/com/github/damontecres/stashapp/util/Constants.kt +++ b/app/src/main/java/com/github/damontecres/stashapp/util/Constants.kt @@ -2,6 +2,7 @@ package com.github.damontecres.stashapp.util import android.annotation.SuppressLint import android.content.Context +import android.content.SharedPreferences import android.net.Uri import android.os.Build import android.text.TextUtils @@ -418,3 +419,17 @@ fun NestedScrollView.onlyScrollIfNeeded() { isFocusable = isScrollable } } + +fun SharedPreferences.getStringNotNull( + key: String, + defValue: String, +): String { + return getString(key, defValue)!! +} + +fun SharedPreferences.getInt( + key: String, + defValue: String, +): Int { + return getStringNotNull(key, defValue).toInt() +} diff --git a/app/src/main/res/values/arrays.xml b/app/src/main/res/values/arrays.xml index aba5987a..b4e77eca 100644 --- a/app/src/main/res/values/arrays.xml +++ b/app/src/main/res/values/arrays.xml @@ -15,4 +15,30 @@ @string/playback_finished_return + Extra small + Small + Medium + Large + Extra Large + + @string/card_size_extra_small + @string/card_size_small + @string/card_size_medium + @string/card_size_large + @string/card_size_extra_large + + + 5 + + 7 + 6 + 5 + 4 + 3 + + + 100% + 110% + 120% + diff --git a/app/src/main/res/xml/root_preferences.xml b/app/src/main/res/xml/root_preferences.xml index 740f2845..21a2e71f 100644 --- a/app/src/main/res/xml/root_preferences.xml +++ b/app/src/main/res/xml/root_preferences.xml @@ -69,13 +69,13 @@ app:summary="Submit PIN automatically when typed" app:defaultValue="false" /> - +