Minor changes

Update some things here and there.
This commit is contained in:
OxygenCobalt 2021-01-10 17:29:02 -07:00
parent bf24199158
commit 6ecfd0daa0
No known key found for this signature in database
GPG key ID: 37DBE3621FE9AD47
8 changed files with 37 additions and 44 deletions

3
.gitignore vendored
View file

@ -12,4 +12,5 @@ captures/
# Other
.externalNativeBuild
*.iml
.cxx
.cxx
changelog

View file

@ -51,7 +51,7 @@ class QualityCoverFetcher(private val context: Context) : Fetcher<Song> {
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<Song> {
// 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
)

View file

@ -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
}
}

View file

@ -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<CoordinatorLayout>(
com.google.android.material.R.id.design_bottom_sheet
)?.let {
BottomSheetBehavior.from(it).state = BottomSheetBehavior.STATE_EXPANDED
}
}
logD("Dialog created.")
return binding.root

View file

@ -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.

View file

@ -40,6 +40,30 @@ class FragmentBinderDelegate<T : ViewBinding>(
}
}
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<T : ViewBinding>(
})
}
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
}

View file

@ -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)

View file

@ -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"