diff --git a/CHANGELOG.md b/CHANGELOG.md index add5edd0e..c5913ee19 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -22,6 +22,7 @@ at the cost of longer loading times #### What's Improved - Migrated to better-looking motion transitions - App now exposes an (immutable) queue to the MediaSession +- Improved widget sizing/cover management #### What's Fixed - Fixed default material theme being used before app shows up diff --git a/app/src/main/java/org/oxycblt/auxio/MainFragment.kt b/app/src/main/java/org/oxycblt/auxio/MainFragment.kt index 119ac2538..4fceadba2 100644 --- a/app/src/main/java/org/oxycblt/auxio/MainFragment.kt +++ b/app/src/main/java/org/oxycblt/auxio/MainFragment.kt @@ -67,7 +67,7 @@ class MainFragment : .onBackPressedDispatcher.addCallback( viewLifecycleOwner, DynamicBackPressedCallback().also { callback = it }) - binding.root.setOnApplyWindowInsetsListener { v, insets -> + binding.root.setOnApplyWindowInsetsListener { _, insets -> lastInsets = insets insets } @@ -202,7 +202,7 @@ class MainFragment : } } - private fun tryExpandAll(): Boolean { + private fun tryExpandAll() { val binding = requireBinding() val playbackSheetBehavior = binding.playbackSheet.coordinatorLayoutBehavior as PlaybackSheetBehavior @@ -210,13 +210,10 @@ class MainFragment : if (playbackSheetBehavior.state != BottomSheetBehavior.STATE_HIDDEN && playbackSheetBehavior.state != BottomSheetBehavior.STATE_EXPANDED) { playbackSheetBehavior.state = BottomSheetBehavior.STATE_EXPANDED - return true } - - return false } - private fun tryCollapseAll(): Boolean { + private fun tryCollapseAll() { val binding = requireBinding() val playbackSheetBehavior = binding.playbackSheet.coordinatorLayoutBehavior as PlaybackSheetBehavior @@ -228,14 +225,10 @@ class MainFragment : playbackSheetBehavior.state = BottomSheetBehavior.STATE_COLLAPSED queueSheetBehavior.state = BottomSheetBehavior.STATE_COLLAPSED - - return true } - - return false } - private fun tryUnhideAll(): Boolean { + private fun tryUnhideAll() { val binding = requireBinding() val playbackSheetBehavior = binding.playbackSheet.coordinatorLayoutBehavior as PlaybackSheetBehavior @@ -248,14 +241,10 @@ class MainFragment : playbackSheetBehavior.state = BottomSheetBehavior.STATE_COLLAPSED queueSheetBehavior.isDraggable = true - - return true } - - return false } - private fun tryHideAll(): Boolean { + private fun tryHideAll() { val binding = requireBinding() val playbackSheetBehavior = binding.playbackSheet.coordinatorLayoutBehavior as PlaybackSheetBehavior @@ -269,11 +258,7 @@ class MainFragment : playbackSheetBehavior.state = BottomSheetBehavior.STATE_HIDDEN queueSheetBehavior.state = BottomSheetBehavior.STATE_COLLAPSED - - return true } - - return false } /** diff --git a/app/src/main/java/org/oxycblt/auxio/home/HomeFragment.kt b/app/src/main/java/org/oxycblt/auxio/home/HomeFragment.kt index 63156e338..437566b13 100644 --- a/app/src/main/java/org/oxycblt/auxio/home/HomeFragment.kt +++ b/app/src/main/java/org/oxycblt/auxio/home/HomeFragment.kt @@ -34,6 +34,7 @@ import androidx.navigation.fragment.findNavController import androidx.recyclerview.widget.RecyclerView import androidx.viewpager2.adapter.FragmentStateAdapter import androidx.viewpager2.widget.ViewPager2 +import com.google.android.material.appbar.AppBarLayout import com.google.android.material.tabs.TabLayoutMediator import com.google.android.material.transition.MaterialFadeThrough import com.google.android.material.transition.MaterialSharedAxis @@ -243,8 +244,19 @@ class HomeFragment : ViewBindingFragment(), Toolbar.OnMenuI } private fun updateTabConfiguration() { + val binding = requireBinding() + val toolbarParams = binding.homeToolbar.layoutParams as AppBarLayout.LayoutParams if (homeModel.tabs.size == 1) { - requireBinding().homeTabs.isVisible = false + // A single tag makes the tab layout redundant, hide it and disable the collapsing + // behavior. + binding.homeTabs.isVisible = false + binding.homeAppbar.setExpanded(true, false) + toolbarParams.scrollFlags = 0 + } else { + binding.homeTabs.isVisible = true + toolbarParams.scrollFlags = + AppBarLayout.LayoutParams.SCROLL_FLAG_SCROLL or + AppBarLayout.LayoutParams.SCROLL_FLAG_ENTER_ALWAYS } } diff --git a/app/src/main/java/org/oxycblt/auxio/playback/queue/QueueFragment.kt b/app/src/main/java/org/oxycblt/auxio/playback/queue/QueueFragment.kt index 1e9dce104..8af0e9bbf 100644 --- a/app/src/main/java/org/oxycblt/auxio/playback/queue/QueueFragment.kt +++ b/app/src/main/java/org/oxycblt/auxio/playback/queue/QueueFragment.kt @@ -34,8 +34,6 @@ import org.oxycblt.auxio.util.logD /** * A [Fragment] that shows the queue and enables editing as well. * - * TODO: Test older versions - * * @author OxygenCobalt */ class QueueFragment : ViewBindingFragment(), QueueItemListener { diff --git a/app/src/main/java/org/oxycblt/auxio/search/SearchFragment.kt b/app/src/main/java/org/oxycblt/auxio/search/SearchFragment.kt index 65c1a401f..c1856b1b3 100644 --- a/app/src/main/java/org/oxycblt/auxio/search/SearchFragment.kt +++ b/app/src/main/java/org/oxycblt/auxio/search/SearchFragment.kt @@ -57,6 +57,7 @@ import org.oxycblt.auxio.util.logW */ class SearchFragment : MenuFragment(), MenuItemListener, Toolbar.OnMenuItemClickListener { + // SearchViewModel is only scoped to this Fragment private val searchModel: SearchViewModel by androidViewModels() diff --git a/app/src/main/java/org/oxycblt/auxio/util/FrameworkUtil.kt b/app/src/main/java/org/oxycblt/auxio/util/FrameworkUtil.kt index e34943b23..175b4f313 100644 --- a/app/src/main/java/org/oxycblt/auxio/util/FrameworkUtil.kt +++ b/app/src/main/java/org/oxycblt/auxio/util/FrameworkUtil.kt @@ -253,9 +253,7 @@ val WindowInsets.systemBarInsetsCompat: Insets Build.VERSION.SDK_INT >= Build.VERSION_CODES.R -> { getInsets(WindowInsets.Type.systemBars()) } - else -> { - @Suppress("DEPRECATION") systemWindowInsets - } + else -> systemWindowInsetsCompat } /** @@ -277,11 +275,20 @@ val WindowInsets.systemGestureInsetsCompat: Insets getInsets(WindowInsets.Type.systemBars())) } Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q -> { - @Suppress("DEPRECATION") Insets.max(systemGestureInsets, systemWindowInsets) + @Suppress("DEPRECATION") Insets.max(systemGestureInsets, systemBarInsetsCompat) } - else -> Insets.of(0, 0, 0, 0) + else -> systemWindowInsetsCompat } +@Suppress("DEPRECATION") +val WindowInsets.systemWindowInsetsCompat: Insets + get() = + Insets.of( + systemWindowInsetLeft, + systemWindowInsetTop, + systemWindowInsetRight, + systemWindowInsetBottom) + /** * Replaces the system bar insets in a version-aware manner. This can be used to modify the insets * for child views in a way that follows all of the frustrating changes that were made between 8-11. diff --git a/app/src/main/java/org/oxycblt/auxio/widgets/WidgetComponent.kt b/app/src/main/java/org/oxycblt/auxio/widgets/WidgetComponent.kt index c86e5ad36..87f686c03 100644 --- a/app/src/main/java/org/oxycblt/auxio/widgets/WidgetComponent.kt +++ b/app/src/main/java/org/oxycblt/auxio/widgets/WidgetComponent.kt @@ -94,27 +94,28 @@ class WidgetComponent(private val context: Context) : 0 } - // Resize the image in a such a way that we don't hit the RemoteView size - // limit, which is the size of an RGB_8888 bitmap 1.5x the screen size. Note - // that we actually set the limit to be half the memory limit so that it's - // less likely for us to hit it. it to really ensure we don't hit the limit. - // This also creates the consistent sizes required for round bitmaps. + // We resize the image in a such a way that we don't hit the RemoteView size + // limit, which is the size of an RGB_8888 bitmap 1.5x the screen size. When + // enabling rounded corners, we further reduce it by a factor of 8 to get 16-dp + // rounded corners, whereas we only downsize it by 2 when there is rounded + // corners just to ensure that we do not hit the memory limit. val metrics = context.resources.displayMetrics val sw = metrics.widthPixels val sh = metrics.heightPixels - builder.size((sqrt((6f * sw * sh) / 8f)).toInt()) return if (cornerRadius > 0) { this@WidgetComponent.logD("Loading round covers: $cornerRadius") - // Use RoundedCornersTransformation. This is because our hack to get a 1:1 - // aspect ratio on widget ImageViews doesn't actually result in a square - // ImageView, so clipToOutline won't work. - builder.transformations( - SquareFrameTransform.INSTANCE, - RoundedCornersTransformation(cornerRadius.toFloat())) - } else { builder + .size(sqrt((6f / 4f / 8f) * sw * sh).toInt()) + .transformations( + SquareFrameTransform.INSTANCE, + // RoundedCornersTransformation is used instead of clipToOutline + // since our hack to get a 1:1 cover on the widget actually does + // not result in a square view, making clipToOutline not work. + RoundedCornersTransformation(cornerRadius.toFloat())) + } else { + builder.size(sqrt((6f / 4f / 2f) * sw * sh).toInt()) } } diff --git a/app/src/main/res/values/dimens.xml b/app/src/main/res/values/dimens.xml index eb772265f..dbde9c0a1 100644 --- a/app/src/main/res/values/dimens.xml +++ b/app/src/main/res/values/dimens.xml @@ -53,6 +53,6 @@ 88dp 128dp - 176dp + 180dp 100dp \ No newline at end of file