From 6ecfd0daa0205b4f2cd5c0209a0085286f3db36d Mon Sep 17 00:00:00 2001 From: OxygenCobalt Date: Sun, 10 Jan 2021 17:29:02 -0700 Subject: [PATCH] Minor changes Update some things here and there. --- .gitignore | 3 +- .../oxycblt/auxio/coil/QualityCoverFetcher.kt | 6 +-- .../playback/state/PlaybackStateManager.kt | 6 +-- .../oxycblt/auxio/settings/ui/AboutDialog.kt | 13 ------ .../java/org/oxycblt/auxio/ui/EdgeUtils.kt | 4 +- .../auxio/ui/FragmentBinderDelegate.kt | 45 ++++++++++--------- .../org/oxycblt/auxio/ui/InterfaceUtils.kt | 2 +- app/src/main/res/layout/fragment_about.xml | 2 + 8 files changed, 37 insertions(+), 44 deletions(-) diff --git a/.gitignore b/.gitignore index 0e09184a7..3ccce7e90 100644 --- a/.gitignore +++ b/.gitignore @@ -12,4 +12,5 @@ captures/ # Other .externalNativeBuild *.iml -.cxx \ No newline at end of file +.cxx +changelog diff --git a/app/src/main/java/org/oxycblt/auxio/coil/QualityCoverFetcher.kt b/app/src/main/java/org/oxycblt/auxio/coil/QualityCoverFetcher.kt index 800bca6a7..112504a10 100644 --- a/app/src/main/java/org/oxycblt/auxio/coil/QualityCoverFetcher.kt +++ b/app/src/main/java/org/oxycblt/auxio/coil/QualityCoverFetcher.kt @@ -51,7 +51,7 @@ class QualityCoverFetcher(private val context: Context) : Fetcher { stream?.use { return SourceResult( - source = stream.source().buffer(), + source = it.source().buffer(), mimeType = context.contentResolver.getType(uri), dataSource = DataSource.DISK ) @@ -60,9 +60,9 @@ class QualityCoverFetcher(private val context: Context) : Fetcher { // If we are here, the extractor likely failed so instead attempt to return the compressed // cover instead. - context.contentResolver.openInputStream(data.album.coverUri)?.use { str -> + context.contentResolver.openInputStream(data.album.coverUri)?.use { return SourceResult( - source = str.source().buffer(), + source = it.source().buffer(), mimeType = context.contentResolver.getType(uri), dataSource = DataSource.DISK ) diff --git a/app/src/main/java/org/oxycblt/auxio/playback/state/PlaybackStateManager.kt b/app/src/main/java/org/oxycblt/auxio/playback/state/PlaybackStateManager.kt index ed9a1f04b..c8df60e71 100644 --- a/app/src/main/java/org/oxycblt/auxio/playback/state/PlaybackStateManager.kt +++ b/app/src/main/java/org/oxycblt/auxio/playback/state/PlaybackStateManager.kt @@ -176,9 +176,8 @@ class PlaybackStateManager private constructor() { orderSongsInGenre(song.genre!!) } } else { - // I really don't know what to do if the song doesn't have a genre, so just - // ignore it. - logE("Song doesn't have a genre. Not playing.") + // If there is no song, then just play the song from ALL_SONGS + playSong(song, PlaybackMode.ALL_SONGS) return } } @@ -199,6 +198,7 @@ class PlaybackStateManager private constructor() { } else { orderSongsInAlbum(song.album) } + mMode = mode } } diff --git a/app/src/main/java/org/oxycblt/auxio/settings/ui/AboutDialog.kt b/app/src/main/java/org/oxycblt/auxio/settings/ui/AboutDialog.kt index 4aeacfaa8..1e6a3d09b 100644 --- a/app/src/main/java/org/oxycblt/auxio/settings/ui/AboutDialog.kt +++ b/app/src/main/java/org/oxycblt/auxio/settings/ui/AboutDialog.kt @@ -6,10 +6,7 @@ import android.view.LayoutInflater import android.view.View import android.view.ViewGroup import androidx.browser.customtabs.CustomTabsIntent -import androidx.coordinatorlayout.widget.CoordinatorLayout import androidx.core.net.toUri -import com.google.android.material.bottomsheet.BottomSheetBehavior -import com.google.android.material.bottomsheet.BottomSheetDialog import com.google.android.material.bottomsheet.BottomSheetDialogFragment import org.oxycblt.auxio.BuildConfig import org.oxycblt.auxio.R @@ -18,7 +15,6 @@ import org.oxycblt.auxio.logD import org.oxycblt.auxio.logE import org.oxycblt.auxio.music.MusicStore import org.oxycblt.auxio.ui.createToast -import org.oxycblt.auxio.ui.isLandscape /** * A [BottomSheetDialogFragment] that shows Auxio's about screen. @@ -48,15 +44,6 @@ class AboutDialog : BottomSheetDialogFragment() { R.string.format_author, getString(R.string.label_author_oxycblt) ) - if (isLandscape(resources)) { - val dialog = requireDialog() as BottomSheetDialog - dialog.findViewById( - com.google.android.material.R.id.design_bottom_sheet - )?.let { - BottomSheetBehavior.from(it).state = BottomSheetBehavior.STATE_EXPANDED - } - } - logD("Dialog created.") return binding.root diff --git a/app/src/main/java/org/oxycblt/auxio/ui/EdgeUtils.kt b/app/src/main/java/org/oxycblt/auxio/ui/EdgeUtils.kt index ce36a5f9b..395499050 100644 --- a/app/src/main/java/org/oxycblt/auxio/ui/EdgeUtils.kt +++ b/app/src/main/java/org/oxycblt/auxio/ui/EdgeUtils.kt @@ -25,9 +25,7 @@ fun Activity.isIrregularLandscape(): Boolean { * Check if edge is on. Really a glorified version check. * @return Whether edge is on. */ -fun isEdgeOn(): Boolean { - return Build.VERSION.SDK_INT >= Build.VERSION_CODES.O_MR1 -} +fun isEdgeOn(): Boolean = Build.VERSION.SDK_INT >= Build.VERSION_CODES.O_MR1 /** * Check if the system bars are on the bottom. diff --git a/app/src/main/java/org/oxycblt/auxio/ui/FragmentBinderDelegate.kt b/app/src/main/java/org/oxycblt/auxio/ui/FragmentBinderDelegate.kt index 5c5df8aac..41f9ebca5 100644 --- a/app/src/main/java/org/oxycblt/auxio/ui/FragmentBinderDelegate.kt +++ b/app/src/main/java/org/oxycblt/auxio/ui/FragmentBinderDelegate.kt @@ -40,6 +40,30 @@ class FragmentBinderDelegate( } } + override fun getValue(thisRef: Fragment, property: KProperty<*>): T { + check(Looper.myLooper() == Looper.getMainLooper()) { + "View can only be accessed on the main thread." + } + + val binding = fragmentBinding + + // If the fragment is already initialized, then just return that. + if (binding != null) { + return binding + } + + val lifecycle = fragment.viewLifecycleOwner.lifecycle + + check(lifecycle.currentState.isAtLeast(Lifecycle.State.INITIALIZED)) { + "Fragment views are destroyed." + } + + // Otherwise create the binding and return that. + return inflate(LayoutInflater.from(thisRef.requireContext())).also { + fragmentBinding = it + } + } + private inline fun Fragment.observeOwnerThroughCreation( crossinline viewOwner: LifecycleOwner.() -> Unit ) { @@ -54,28 +78,9 @@ class FragmentBinderDelegate( }) } - override fun getValue(thisRef: Fragment, property: KProperty<*>): T { - if (Looper.myLooper() != Looper.getMainLooper()) { - throw IllegalThreadStateException("View can only be accessed on the main thread.") - } - - val binding = fragmentBinding - if (binding != null) { - return binding - } - - val lifecycle = fragment.viewLifecycleOwner.lifecycle - - if (!lifecycle.currentState.isAtLeast(Lifecycle.State.INITIALIZED)) { - throw IllegalStateException("Fragment views are destroyed.") - } - - return inflate(LayoutInflater.from(thisRef.requireContext())).also { fragmentBinding = it } - } - @Suppress("UNUSED") @OnLifecycleEvent(Lifecycle.Event.ON_DESTROY) - fun dispose() { + fun destroy() { fragmentBinding?.onDestroy() fragmentBinding = null } diff --git a/app/src/main/java/org/oxycblt/auxio/ui/InterfaceUtils.kt b/app/src/main/java/org/oxycblt/auxio/ui/InterfaceUtils.kt index 359225458..734277ecb 100644 --- a/app/src/main/java/org/oxycblt/auxio/ui/InterfaceUtils.kt +++ b/app/src/main/java/org/oxycblt/auxio/ui/InterfaceUtils.kt @@ -88,7 +88,7 @@ fun TextView.setTextColorResource(@ColorRes color: Int) { /** * Apply accents to a [MaterialButton] * @param highlighted Whether the MaterialButton has an "Unimportant" style or not. - * Required because you cant determine a style of a view before 29 + * Required because you cant determine a style of a view before API 29 */ fun MaterialButton.applyAccents(highlighted: Boolean) { val accent = accent.first.toColor(context) diff --git a/app/src/main/res/layout/fragment_about.xml b/app/src/main/res/layout/fragment_about.xml index de61ba897..44fa44f09 100644 --- a/app/src/main/res/layout/fragment_about.xml +++ b/app/src/main/res/layout/fragment_about.xml @@ -46,6 +46,8 @@ android:id="@+id/about_desc" android:layout_width="wrap_content" android:layout_height="wrap_content" + android:paddingStart="@dimen/padding_small" + android:paddingEnd="@dimen/padding_small" android:layout_marginTop="@dimen/margin_small" android:text="@string/app_desc" android:textAlignment="center"