Improve tablet layouts
Make the tablet layouts look much better
This commit is contained in:
@@ -13,6 +13,7 @@ import androidx.navigation.NavController
|
||||
import androidx.navigation.NavOptions
|
||||
import androidx.navigation.fragment.NavHostFragment
|
||||
import androidx.navigation.fragment.findNavController
|
||||
import com.google.android.material.bottomnavigation.LabelVisibilityMode
|
||||
import org.oxycblt.auxio.databinding.FragmentMainBinding
|
||||
import org.oxycblt.auxio.detail.DetailViewModel
|
||||
import org.oxycblt.auxio.music.MusicStore
|
||||
@@ -20,6 +21,7 @@ import org.oxycblt.auxio.music.Song
|
||||
import org.oxycblt.auxio.playback.PlaybackViewModel
|
||||
import org.oxycblt.auxio.ui.Accent
|
||||
import org.oxycblt.auxio.ui.isLandscape
|
||||
import org.oxycblt.auxio.ui.isTablet
|
||||
import org.oxycblt.auxio.ui.toColor
|
||||
|
||||
/**
|
||||
@@ -66,6 +68,15 @@ class MainFragment : Fragment() {
|
||||
|
||||
binding.lifecycleOwner = this
|
||||
|
||||
binding.navBar.apply {
|
||||
itemIconTintList = navTints
|
||||
itemTextColor = navTints
|
||||
|
||||
if (isTablet(resources)) {
|
||||
labelVisibilityMode = LabelVisibilityMode.LABEL_VISIBILITY_LABELED
|
||||
}
|
||||
}
|
||||
|
||||
binding.navBar.itemIconTintList = navTints
|
||||
binding.navBar.itemTextColor = navTints
|
||||
|
||||
|
||||
@@ -19,8 +19,7 @@ import org.oxycblt.auxio.music.BaseModel
|
||||
import org.oxycblt.auxio.music.Genre
|
||||
import org.oxycblt.auxio.music.Song
|
||||
import org.oxycblt.auxio.ui.ActionMenu
|
||||
import org.oxycblt.auxio.ui.getLandscapeSpans
|
||||
import org.oxycblt.auxio.ui.isLandscape
|
||||
import org.oxycblt.auxio.ui.getSpans
|
||||
import org.oxycblt.auxio.ui.requireCompatActivity
|
||||
|
||||
/**
|
||||
@@ -64,9 +63,10 @@ class LibraryFragment : Fragment() {
|
||||
binding.libraryRecycler.apply {
|
||||
adapter = libraryAdapter
|
||||
setHasFixedSize(true)
|
||||
val spans = context.getSpans()
|
||||
|
||||
if (isLandscape(resources)) {
|
||||
layoutManager = GridLayoutManager(requireContext(), getLandscapeSpans(resources))
|
||||
if (spans != 1) {
|
||||
layoutManager = GridLayoutManager(requireContext(), spans)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -110,8 +110,8 @@ class LoadingFragment : Fragment(R.layout.fragment_loading) {
|
||||
return binding.root
|
||||
}
|
||||
|
||||
override fun onStart() {
|
||||
super.onStart()
|
||||
override fun onResume() {
|
||||
super.onResume()
|
||||
|
||||
// If the music was already loaded, then don't do it again.
|
||||
if (MusicStore.getInstance().loaded) {
|
||||
|
||||
@@ -25,8 +25,7 @@ import org.oxycblt.auxio.playback.PlaybackViewModel
|
||||
import org.oxycblt.auxio.ui.Accent
|
||||
import org.oxycblt.auxio.ui.ActionMenu
|
||||
import org.oxycblt.auxio.ui.fixAnimationInfoMemoryLeak
|
||||
import org.oxycblt.auxio.ui.getLandscapeSpans
|
||||
import org.oxycblt.auxio.ui.isLandscape
|
||||
import org.oxycblt.auxio.ui.getSpans
|
||||
import org.oxycblt.auxio.ui.requireCompatActivity
|
||||
import org.oxycblt.auxio.ui.toColor
|
||||
|
||||
@@ -85,10 +84,9 @@ class SearchFragment : Fragment() {
|
||||
|
||||
binding.searchRecycler.apply {
|
||||
adapter = searchAdapter
|
||||
val spans = context.getSpans()
|
||||
|
||||
if (isLandscape(resources)) {
|
||||
val spans = getLandscapeSpans(resources)
|
||||
|
||||
if (spans != -1) {
|
||||
layoutManager = GridLayoutManager(requireContext(), spans).apply {
|
||||
spanSizeLookup = object : GridLayoutManager.SpanSizeLookup() {
|
||||
override fun getSpanSize(position: Int): Int =
|
||||
|
||||
@@ -19,8 +19,7 @@ import org.oxycblt.auxio.music.MusicStore
|
||||
import org.oxycblt.auxio.playback.PlaybackViewModel
|
||||
import org.oxycblt.auxio.ui.Accent
|
||||
import org.oxycblt.auxio.ui.ActionMenu
|
||||
import org.oxycblt.auxio.ui.getLandscapeSpans
|
||||
import org.oxycblt.auxio.ui.isLandscape
|
||||
import org.oxycblt.auxio.ui.getSpans
|
||||
import org.oxycblt.auxio.ui.requireCompatActivity
|
||||
import kotlin.math.ceil
|
||||
|
||||
@@ -70,8 +69,10 @@ class SongsFragment : Fragment() {
|
||||
adapter = songAdapter
|
||||
setHasFixedSize(true)
|
||||
|
||||
if (isLandscape(resources)) {
|
||||
layoutManager = GridLayoutManager(requireContext(), getLandscapeSpans(resources))
|
||||
val spans = context.getSpans()
|
||||
|
||||
if (spans != 1) {
|
||||
layoutManager = GridLayoutManager(requireContext(), spans)
|
||||
}
|
||||
|
||||
post {
|
||||
|
||||
@@ -139,11 +139,24 @@ fun isLandscape(resources: Resources): Boolean {
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the span count for most RecyclerViews when in landscape mode.
|
||||
* @return 3 if landscape mode is tablet, 2 if landscape mode is phone
|
||||
* Determine if we are in tablet mode or not
|
||||
*/
|
||||
fun getLandscapeSpans(resources: Resources): Int {
|
||||
return if (resources.configuration.screenLayout == Configuration.SCREENLAYOUT_SIZE_LARGE) 3 else 2
|
||||
fun isTablet(resources: Resources): Boolean {
|
||||
val layout = resources.configuration.screenLayout and Configuration.SCREENLAYOUT_SIZE_MASK
|
||||
|
||||
return layout == Configuration.SCREENLAYOUT_SIZE_XLARGE ||
|
||||
layout == Configuration.SCREENLAYOUT_SIZE_LARGE
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the span count for most RecyclerViews
|
||||
*/
|
||||
fun Context.getSpans(): Int {
|
||||
return if (isLandscape(resources)) {
|
||||
if (isTablet(resources)) 3 else 2
|
||||
} else {
|
||||
if (isTablet(resources)) 2 else 1
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user