ui: make list spans use exact sizing
Make list spans use exact sizing.
This commit is contained in:
parent
4475d4a5cc
commit
c350576f21
10 changed files with 28 additions and 44 deletions
|
|
@ -27,7 +27,6 @@ import androidx.core.view.forEach
|
||||||
import androidx.fragment.app.Fragment
|
import androidx.fragment.app.Fragment
|
||||||
import androidx.fragment.app.activityViewModels
|
import androidx.fragment.app.activityViewModels
|
||||||
import androidx.navigation.fragment.findNavController
|
import androidx.navigation.fragment.findNavController
|
||||||
import androidx.recyclerview.widget.GridLayoutManager
|
|
||||||
import androidx.recyclerview.widget.RecyclerView
|
import androidx.recyclerview.widget.RecyclerView
|
||||||
import org.oxycblt.auxio.R
|
import org.oxycblt.auxio.R
|
||||||
import org.oxycblt.auxio.databinding.FragmentDetailBinding
|
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.playback.PlaybackViewModel
|
||||||
import org.oxycblt.auxio.ui.SortMode
|
import org.oxycblt.auxio.ui.SortMode
|
||||||
import org.oxycblt.auxio.ui.memberBinding
|
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.
|
* A Base [Fragment] implementing the base features shared across all detail fragments.
|
||||||
|
|
@ -110,16 +109,7 @@ abstract class DetailFragment : Fragment() {
|
||||||
adapter = detailAdapter
|
adapter = detailAdapter
|
||||||
setHasFixedSize(true)
|
setHasFixedSize(true)
|
||||||
|
|
||||||
// Set up a grid if the mode is landscape
|
applySpans(gridLookup)
|
||||||
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
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -106,12 +106,3 @@ fun Context.getPlural(@PluralsRes pluralsRes: Int, value: Int): String {
|
||||||
fun Context.isLandscape(): Boolean {
|
fun Context.isLandscape(): Boolean {
|
||||||
return resources.configuration.orientation == Configuration.ORIENTATION_LANDSCAPE
|
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
|
|
||||||
}
|
|
||||||
|
|
|
||||||
|
|
@ -35,6 +35,7 @@ import androidx.core.content.ContextCompat
|
||||||
import androidx.recyclerview.widget.GridLayoutManager
|
import androidx.recyclerview.widget.GridLayoutManager
|
||||||
import androidx.recyclerview.widget.RecyclerView
|
import androidx.recyclerview.widget.RecyclerView
|
||||||
import com.google.android.material.shape.MaterialShapeDrawable
|
import com.google.android.material.shape.MaterialShapeDrawable
|
||||||
|
import org.oxycblt.auxio.R
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Apply a [MaterialShapeDrawable] to this view, automatically initializing the elevation overlay
|
* Apply a [MaterialShapeDrawable] to this view, automatically initializing the elevation overlay
|
||||||
|
|
@ -57,11 +58,7 @@ fun View.applyMaterialDrawable() {
|
||||||
* regardless of spans
|
* regardless of spans
|
||||||
*/
|
*/
|
||||||
fun RecyclerView.applySpans(shouldBeFullWidth: ((Int) -> Boolean)? = null) {
|
fun RecyclerView.applySpans(shouldBeFullWidth: ((Int) -> Boolean)? = null) {
|
||||||
val spans = if (context.isLandscape()) {
|
val spans = resources.getInteger(R.integer.recycler_spans)
|
||||||
if (context.isXLTablet()) 3 else 2
|
|
||||||
} else {
|
|
||||||
if (context.isXLTablet()) 2 else 1
|
|
||||||
}
|
|
||||||
|
|
||||||
if (spans > 1) {
|
if (spans > 1) {
|
||||||
val mgr = GridLayoutManager(context, spans)
|
val mgr = GridLayoutManager(context, spans)
|
||||||
|
|
|
||||||
4
app/src/main/res/values-sw840dp-land/config.xml
Normal file
4
app/src/main/res/values-sw840dp-land/config.xml
Normal file
|
|
@ -0,0 +1,4 @@
|
||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<resources>
|
||||||
|
<integer name="recycler_spans">3</integer>
|
||||||
|
</resources>
|
||||||
4
app/src/main/res/values-w600dp/config.xml
Normal file
4
app/src/main/res/values-w600dp/config.xml
Normal file
|
|
@ -0,0 +1,4 @@
|
||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<resources>
|
||||||
|
<integer name="recycler_spans">2</integer>
|
||||||
|
</resources>
|
||||||
|
|
@ -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>
|
|
||||||
|
|
@ -1,4 +1,5 @@
|
||||||
<?xml version="1.0" encoding="utf-8"?>
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
<resources>
|
<resources>
|
||||||
<bool name="enable_theme_settings">true</bool>
|
<bool name="enable_theme_settings">true</bool>
|
||||||
|
<integer name="recycler_spans">1</integer>
|
||||||
</resources>
|
</resources>
|
||||||
|
|
@ -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>
|
|
||||||
|
|
@ -1,5 +1,11 @@
|
||||||
<?xml version="1.0" encoding="utf-8"?>
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
<resources>
|
<resources>
|
||||||
|
<!-- Preference values -->
|
||||||
|
<declare-styleable name="IntListPreference">
|
||||||
|
<attr name="entries" format="reference" />
|
||||||
|
<attr name="entryValues" format="reference" />
|
||||||
|
</declare-styleable>
|
||||||
|
|
||||||
<string-array name="entires_theme">
|
<string-array name="entires_theme">
|
||||||
<item>@string/set_theme_auto</item>
|
<item>@string/set_theme_auto</item>
|
||||||
<item>@string/set_theme_day</item>
|
<item>@string/set_theme_day</item>
|
||||||
|
|
@ -25,4 +31,13 @@
|
||||||
<item>@integer/play_mode_album</item>
|
<item>@integer/play_mode_album</item>
|
||||||
<item>@integer/play_mode_genre</item>
|
<item>@integer/play_mode_genre</item>
|
||||||
</string-array>
|
</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>
|
</resources>
|
||||||
Loading…
Reference in a new issue