ui: make list spans use exact sizing

Make list spans use exact sizing.
This commit is contained in:
OxygenCobalt 2021-11-20 10:54:24 -07:00
parent 4475d4a5cc
commit c350576f21
No known key found for this signature in database
GPG key ID: 37DBE3621FE9AD47
10 changed files with 28 additions and 44 deletions

View file

@ -27,7 +27,6 @@ import androidx.core.view.forEach
import androidx.fragment.app.Fragment
import androidx.fragment.app.activityViewModels
import androidx.navigation.fragment.findNavController
import androidx.recyclerview.widget.GridLayoutManager
import androidx.recyclerview.widget.RecyclerView
import org.oxycblt.auxio.R
import org.oxycblt.auxio.databinding.FragmentDetailBinding
@ -35,7 +34,7 @@ import org.oxycblt.auxio.music.MusicParent
import org.oxycblt.auxio.playback.PlaybackViewModel
import org.oxycblt.auxio.ui.SortMode
import org.oxycblt.auxio.ui.memberBinding
import org.oxycblt.auxio.util.isLandscape
import org.oxycblt.auxio.util.applySpans
/**
* A Base [Fragment] implementing the base features shared across all detail fragments.
@ -110,16 +109,7 @@ abstract class DetailFragment : Fragment() {
adapter = detailAdapter
setHasFixedSize(true)
// Set up a grid if the mode is landscape
if (requireContext().isLandscape()) {
layoutManager = GridLayoutManager(requireContext(), 2).also {
it.spanSizeLookup = object : GridLayoutManager.SpanSizeLookup() {
override fun getSpanSize(position: Int): Int {
return if (gridLookup(position)) 2 else 1
}
}
}
}
applySpans(gridLookup)
}
}

View file

@ -106,12 +106,3 @@ fun Context.getPlural(@PluralsRes pluralsRes: Int, value: Int): String {
fun Context.isLandscape(): Boolean {
return resources.configuration.orientation == Configuration.ORIENTATION_LANDSCAPE
}
/**
* Determine if the tablet is XLARGE, ignoring normal tablets.
*/
fun Context.isXLTablet(): Boolean {
val layout = resources.configuration.screenLayout and Configuration.SCREENLAYOUT_SIZE_MASK
return layout == Configuration.SCREENLAYOUT_SIZE_XLARGE
}

View file

@ -35,6 +35,7 @@ import androidx.core.content.ContextCompat
import androidx.recyclerview.widget.GridLayoutManager
import androidx.recyclerview.widget.RecyclerView
import com.google.android.material.shape.MaterialShapeDrawable
import org.oxycblt.auxio.R
/**
* Apply a [MaterialShapeDrawable] to this view, automatically initializing the elevation overlay
@ -57,11 +58,7 @@ fun View.applyMaterialDrawable() {
* regardless of spans
*/
fun RecyclerView.applySpans(shouldBeFullWidth: ((Int) -> Boolean)? = null) {
val spans = if (context.isLandscape()) {
if (context.isXLTablet()) 3 else 2
} else {
if (context.isXLTablet()) 2 else 1
}
val spans = resources.getInteger(R.integer.recycler_spans)
if (spans > 1) {
val mgr = GridLayoutManager(context, spans)

View file

@ -0,0 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<integer name="recycler_spans">3</integer>
</resources>

View file

@ -0,0 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<integer name="recycler_spans">2</integer>
</resources>

View file

@ -1,7 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<declare-styleable name="IntListPreference">
<attr name="entries" format="reference" />
<attr name="entryValues" format="reference" />
</declare-styleable>
</resources>

View file

@ -1,4 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<bool name="enable_theme_settings">true</bool>
<integer name="recycler_spans">1</integer>
</resources>

View file

@ -1,11 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<integer name="theme_auto">-1</integer>
<integer name="theme_light">1</integer>
<integer name="theme_dark">2</integer>
<integer name="play_mode_genre">0xA103</integer>
<integer name="play_mode_artist">0xA104</integer>
<integer name="play_mode_album">0xA105</integer>
<integer name="play_mode_songs">0xA106</integer>
</resources>

View file

@ -1,5 +1,11 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<!-- Preference values -->
<declare-styleable name="IntListPreference">
<attr name="entries" format="reference" />
<attr name="entryValues" format="reference" />
</declare-styleable>
<string-array name="entires_theme">
<item>@string/set_theme_auto</item>
<item>@string/set_theme_day</item>
@ -25,4 +31,13 @@
<item>@integer/play_mode_album</item>
<item>@integer/play_mode_genre</item>
</string-array>
<integer name="theme_auto">-1</integer>
<integer name="theme_light">1</integer>
<integer name="theme_dark">2</integer>
<integer name="play_mode_genre">0xA103</integer>
<integer name="play_mode_artist">0xA104</integer>
<integer name="play_mode_album">0xA105</integer>
<integer name="play_mode_songs">0xA106</integer>
</resources>