Improve layout responsiveness
Make layouts better on all screen sizes.
This commit is contained in:
@@ -17,11 +17,8 @@ class AuxioApp : Application(), ImageLoaderFactory {
|
||||
}
|
||||
|
||||
override fun newImageLoader(): ImageLoader {
|
||||
// Don't cache images on-disk [The covers are already on-disk]
|
||||
// Crossfade by default
|
||||
// Use a transparent placeholder
|
||||
return ImageLoader.Builder(applicationContext)
|
||||
.diskCachePolicy(CachePolicy.DISABLED)
|
||||
.diskCachePolicy(CachePolicy.DISABLED) // Not downloading anything, so no disk-caching
|
||||
.crossfade(true)
|
||||
.placeholder(android.R.color.transparent)
|
||||
.build()
|
||||
|
||||
@@ -77,5 +77,5 @@ class AlbumArtFetcher(private val context: Context) : Fetcher<Album> {
|
||||
return loadMediaStoreCovers(data)
|
||||
}
|
||||
|
||||
override fun key(data: Album) = data.id.toString()
|
||||
override fun key(data: Album) = data.coverUri.toString()
|
||||
}
|
||||
|
||||
@@ -83,7 +83,7 @@ class MosaicFetcher(private val context: Context) : Fetcher<Parent> {
|
||||
}
|
||||
|
||||
/**
|
||||
* Create the mosaic, Code adapted from Phonograph
|
||||
* Create the mosaic image, Code adapted from Phonograph
|
||||
* https://github.com/kabouzeid/Phonograph
|
||||
*/
|
||||
private fun drawMosaic(streams: List<InputStream>): Bitmap {
|
||||
@@ -122,16 +122,13 @@ class MosaicFetcher(private val context: Context) : Fetcher<Parent> {
|
||||
}
|
||||
|
||||
/**
|
||||
* Iterate through a list of [Closeable]s, running [use] on each.
|
||||
* @param action What to do for each [Closeable]
|
||||
* Iterate through a list of [Closeable]s, running [block] on each and closing it when done.
|
||||
*/
|
||||
private fun <T : Closeable> List<T>.useForEach(action: (T) -> Unit) {
|
||||
forEach {
|
||||
it.use(action)
|
||||
}
|
||||
private fun <T : Closeable> List<T>.useForEach(block: (T) -> Unit) {
|
||||
forEach { it.use(block) }
|
||||
}
|
||||
|
||||
override fun key(data: Parent): String = data.id.toString()
|
||||
override fun key(data: Parent): String = data.hashCode().toString()
|
||||
override fun handles(data: Parent) = data !is Album // Albums are not used here
|
||||
|
||||
companion object {
|
||||
|
||||
@@ -33,7 +33,7 @@ fun Fragment.newMenu(anchor: View, data: BaseModel, flag: Int = ActionMenu.FLAG_
|
||||
* @param activity [AppCompatActivity] required as both a context and ViewModelStore owner.
|
||||
* @param anchor [View] This should be centered around
|
||||
* @param data [BaseModel] this menu corresponds to
|
||||
* @param flag Any extra flags to accompany the data. See [FLAG_NONE], [FLAG_IN_ALBUM], [FLAG_IN_ARTIST], [FLAG_IN_GENRE] for more detials.
|
||||
* @param flag Any extra flags to accompany the data. See [FLAG_NONE], [FLAG_IN_ALBUM], [FLAG_IN_ARTIST], [FLAG_IN_GENRE] for more details.
|
||||
* @throws IllegalArgumentException When there is no menu for this specific datatype/flag
|
||||
*/
|
||||
class ActionMenu(
|
||||
|
||||
@@ -162,13 +162,22 @@ fun isTablet(resources: Resources): Boolean {
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the span count for most RecyclerViews
|
||||
* Determine if the tablet is XLARGE, ignoring normal tablets.
|
||||
*/
|
||||
fun isXLTablet(resources: Resources): Boolean {
|
||||
val layout = resources.configuration.screenLayout and Configuration.SCREENLAYOUT_SIZE_MASK
|
||||
|
||||
return layout == Configuration.SCREENLAYOUT_SIZE_XLARGE
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the span count for most RecyclerViews. These probably work right on most displays. Trust me.
|
||||
*/
|
||||
fun RecyclerView.getSpans(): Int {
|
||||
return if (isLandscape(resources)) {
|
||||
if (isTablet(resources)) 3 else 2
|
||||
if (isXLTablet(resources)) 3 else 2
|
||||
} else {
|
||||
if (isTablet(resources)) 2 else 1
|
||||
if (isXLTablet(resources)) 2 else 1
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user