all: reformat

This commit is contained in:
Alexander Capehart
2026-04-12 21:25:15 -06:00
parent 05502950d6
commit 29b2cd1b4b
6 changed files with 80 additions and 85 deletions
@@ -27,7 +27,6 @@ import androidx.activity.result.contract.ActivityResultContracts
import androidx.core.view.MenuCompat
import androidx.core.view.isInvisible
import androidx.core.view.isVisible
import androidx.core.view.updatePadding
import androidx.fragment.app.Fragment
import androidx.fragment.app.FragmentManager
import androidx.fragment.app.activityViewModels
@@ -41,7 +40,6 @@ import com.google.android.material.tabs.TabLayoutMediator
import com.google.android.material.transition.MaterialSharedAxis
import dagger.hilt.android.AndroidEntryPoint
import java.lang.reflect.Field
import kotlin.math.abs
import org.oxycblt.auxio.R
import org.oxycblt.auxio.databinding.FragmentHomeBinding
import org.oxycblt.auxio.detail.DetailViewModel
@@ -82,8 +80,7 @@ import timber.log.Timber as L
* @author Alexander Capehart (OxygenCobalt)
*/
@AndroidEntryPoint
class HomeFragment :
SelectionFragment<FragmentHomeBinding>() {
class HomeFragment : SelectionFragment<FragmentHomeBinding>() {
override val listModel: ListViewModel by activityViewModels()
override val musicModel: MusicViewModel by activityViewModels()
override val playbackModel: PlaybackViewModel by activityViewModels()
@@ -130,10 +127,7 @@ class HomeFragment :
// --- UI SETUP ---
binding.homeAppbar.addOnOffsetChangedListener(
FadingToolbarOffsetListener(
binding.homeToolbar,
binding.homeContent
)
FadingToolbarOffsetListener(binding.homeToolbar, binding.homeContent)
)
binding.homeNormalToolbar.apply {
setOnMenuItemClickListener(this@HomeFragment)
@@ -47,10 +47,14 @@ import coil3.request.ImageRequest
import coil3.request.target
import coil3.request.transformations
import coil3.util.CoilUtils
import com.google.android.material.R as MR
import com.google.android.material.shape.MaterialShapeDrawable
import com.google.android.material.shape.RelativeCornerSize
import com.google.android.material.shape.ShapeAppearanceModel
import dagger.hilt.android.AndroidEntryPoint
import javax.inject.Inject
import kotlin.math.min
import kotlin.random.Random
import org.oxycblt.auxio.R
import org.oxycblt.auxio.image.coil.GalleryCoverCollection
import org.oxycblt.auxio.image.coil.RoundedRectTransformation
@@ -70,10 +74,6 @@ import org.oxycblt.musikr.Genre
import org.oxycblt.musikr.Playlist
import org.oxycblt.musikr.Song
import org.oxycblt.musikr.covers.CoverCollection
import javax.inject.Inject
import kotlin.math.min
import kotlin.random.Random
import com.google.android.material.R as MR
/**
* Auxio's extension of [ImageView] that enables cover art loading and playing indicator and
@@ -121,18 +121,14 @@ constructor(context: Context, attrs: AttributeSet? = null, @AttrRes defStyleAttr
@SuppressLint("CustomViewStyleable")
val styledAttrs = context.obtainStyledAttributes(attrs, R.styleable.CoverView)
val shapeAppearanceRes = styledAttrs.getResourceId(
R.styleable.CoverView_shapeAppearance,
MR.style.ShapeAppearance_Material3_Corner_Medium
)
val shapeAppearanceRes =
styledAttrs.getResourceId(
R.styleable.CoverView_shapeAppearance,
MR.style.ShapeAppearance_Material3_Corner_Medium,
)
squareishShapeAppearance =
if (uiSettings.roundMode) {
ShapeAppearanceModel.builder(
context,
shapeAppearanceRes,
-1,
)
.build()
ShapeAppearanceModel.builder(context, shapeAppearanceRes, -1).build()
} else {
ShapeAppearanceModel.builder().build()
}
@@ -311,7 +307,6 @@ constructor(context: Context, attrs: AttributeSet? = null, @AttrRes defStyleAttr
}
}
private fun invalidateRootAlpha() {
alpha = if (isEnabled || isSelected) 1f else 0.5f
}
@@ -355,7 +350,7 @@ constructor(context: Context, attrs: AttributeSet? = null, @AttrRes defStyleAttr
{ song.cover },
context.getString(R.string.desc_album_cover, song.album.name),
R.drawable.ic_album_24,
squareishShapeAppearance
squareishShapeAppearance,
)
/**
@@ -378,7 +373,7 @@ constructor(context: Context, attrs: AttributeSet? = null, @AttrRes defStyleAttr
},
context.getString(R.string.desc_album_cover, album.name),
R.drawable.ic_album_24,
squareishShapeAppearance
squareishShapeAppearance,
)
}
@@ -405,7 +400,7 @@ constructor(context: Context, attrs: AttributeSet? = null, @AttrRes defStyleAttr
},
context.getString(R.string.desc_artist_image, artist.name),
R.drawable.ic_artist_24,
circularShapeAppearance
circularShapeAppearance,
)
}
@@ -428,7 +423,7 @@ constructor(context: Context, attrs: AttributeSet? = null, @AttrRes defStyleAttr
},
context.getString(R.string.desc_genre_image, genre.name),
R.drawable.ic_genre_24,
squareishShapeAppearance
squareishShapeAppearance,
)
/**
@@ -450,7 +445,7 @@ constructor(context: Context, attrs: AttributeSet? = null, @AttrRes defStyleAttr
},
context.getString(R.string.desc_playlist_image, playlist.name),
R.drawable.ic_playlist_24,
squareishShapeAppearance
squareishShapeAppearance,
)
/**
@@ -478,14 +473,14 @@ constructor(context: Context, attrs: AttributeSet? = null, @AttrRes defStyleAttr
},
desc,
errorRes,
squareishShapeAppearance
squareishShapeAppearance,
)
private fun bindImpl(
img: (RectF) -> Any?,
desc: String,
@DrawableRes errorRes: Int,
shapeAppearanceModel: ShapeAppearanceModel
shapeAppearanceModel: ShapeAppearanceModel,
) {
// prep proper shape to use if necessary. be safe and do it now
// idk if doing it at layout time will cause issues
@@ -497,7 +492,7 @@ constructor(context: Context, attrs: AttributeSet? = null, @AttrRes defStyleAttr
img: (RectF) -> Any?,
desc: String,
@DrawableRes errorRes: Int,
shapeAppearanceModel: ShapeAppearanceModel
shapeAppearanceModel: ShapeAppearanceModel,
) {
// for some reason randomly corner radii started breaking on menus
// fix this by waiting until we are laid out instead
@@ -505,9 +500,7 @@ constructor(context: Context, attrs: AttributeSet? = null, @AttrRes defStyleAttr
if (cornerBounds != null) {
bindWithCorners(img, desc, errorRes, cornerBounds, shapeAppearanceModel)
} else {
doOnLayout {
bindImpl(img, desc, errorRes, shapeAppearanceModel)
}
doOnLayout { bindImpl(img, desc, errorRes, shapeAppearanceModel) }
}
}
@@ -516,14 +509,13 @@ constructor(context: Context, attrs: AttributeSet? = null, @AttrRes defStyleAttr
desc: String,
@DrawableRes errorRes: Int,
cornerBounds: RectF,
shapeAppearanceModel: ShapeAppearanceModel
shapeAppearanceModel: ShapeAppearanceModel,
) {
val request =
ImageRequest.Builder(context)
.data(img(cornerBounds))
.error(
StyledDrawable(context, context.getDrawableCompat(errorRes), iconSize)
.asImage()
StyledDrawable(context, context.getDrawableCompat(errorRes), iconSize).asImage()
)
.target(image)
@@ -574,8 +566,7 @@ constructor(context: Context, attrs: AttributeSet? = null, @AttrRes defStyleAttr
return random.nextFloat() * 20f - 10f // -10 to +10 degrees
}
private fun backgroundColor(): Int =
context.getColorCompat(R.color.sel_cover_bg).defaultColor
private fun backgroundColor(): Int = context.getColorCompat(R.color.sel_cover_bg).defaultColor
private fun resolveCurrentBoundsForCorners(): RectF? {
val widthPx = firstNonZeroOrNull(width, measuredWidth, layoutParams?.width)
@@ -20,7 +20,6 @@ package org.oxycblt.auxio.search
import android.os.Bundle
import android.view.LayoutInflater
import android.view.MenuItem
import android.view.View
import android.view.inputmethod.InputMethodManager
import androidx.activity.result.ActivityResultLauncher
@@ -120,10 +119,7 @@ class SearchFragment : ListFragment<Music, FragmentSearchBinding>() {
// --- UI SETUP ---
binding.searchAppbar.addOnOffsetChangedListener(
FadingToolbarOffsetListener(
binding.searchToolbar,
binding.searchContent
)
FadingToolbarOffsetListener(binding.searchToolbar, binding.searchContent)
)
binding.searchNormalToolbar.apply {
@@ -159,16 +155,17 @@ class SearchFragment : ListFragment<Music, FragmentSearchBinding>() {
binding.searchFilterPlaylists.isChecked = MusicType.PLAYLISTS in filters
binding.searchFilters.apply {
setOnCheckedStateChangeListener { group, ids ->
val types = ids.mapNotNullTo(mutableSetOf()) {
when (it) {
R.id.search_filter_songs -> MusicType.SONGS
R.id.search_filter_albums -> MusicType.ALBUMS
R.id.search_filter_artists -> MusicType.ARTISTS
R.id.search_filter_genres -> MusicType.GENRES
R.id.search_filter_playlists -> MusicType.PLAYLISTS
else -> null
val types =
ids.mapNotNullTo(mutableSetOf()) {
when (it) {
R.id.search_filter_songs -> MusicType.SONGS
R.id.search_filter_albums -> MusicType.ALBUMS
R.id.search_filter_artists -> MusicType.ARTISTS
R.id.search_filter_genres -> MusicType.GENRES
R.id.search_filter_playlists -> MusicType.PLAYLISTS
else -> null
}
}
}
searchModel.filters = types
}
}
@@ -40,17 +40,15 @@ class SearchSettingsImpl @Inject constructor(@ApplicationContext context: Contex
Settings.Impl<Nothing>(context), SearchSettings {
override var filters: Set<MusicType>
get() =
sharedPreferences.getStringSet(
getString(R.string.set_key_search_filters),
null
)?.mapNotNull {
it.toIntOrNull()?.let(MusicType::fromIntCode)
}?.toSet() ?: setOf()
sharedPreferences
.getStringSet(getString(R.string.set_key_search_filters), null)
?.mapNotNull { it.toIntOrNull()?.let(MusicType::fromIntCode) }
?.toSet() ?: setOf()
set(value) {
sharedPreferences.edit {
putStringSet(
getString(R.string.set_key_search_filters),
value.map { it.intCode.toString() }.toSet()
value.map { it.intCode.toString() }.toSet(),
)
}
}
@@ -18,10 +18,10 @@
package org.oxycblt.auxio.search
import androidx.annotation.IdRes
import androidx.lifecycle.ViewModel
import androidx.lifecycle.viewModelScope
import dagger.hilt.android.lifecycle.HiltViewModel
import javax.inject.Inject
import kotlinx.coroutines.Job
import kotlinx.coroutines.flow.MutableStateFlow
import kotlinx.coroutines.flow.StateFlow
@@ -33,13 +33,11 @@ import org.oxycblt.auxio.list.Item
import org.oxycblt.auxio.list.PlainDivider
import org.oxycblt.auxio.list.sort.Sort
import org.oxycblt.auxio.music.MusicRepository
import org.oxycblt.auxio.music.MusicSettings
import org.oxycblt.auxio.music.MusicType
import org.oxycblt.auxio.playback.PlaySong
import org.oxycblt.auxio.playback.PlaybackSettings
import org.oxycblt.musikr.Library
import org.oxycblt.musikr.Song
import javax.inject.Inject
import timber.log.Timber as L
/**
@@ -113,23 +111,24 @@ constructor(
private suspend fun searchImpl(library: Library, query: String): List<Item> {
val filters = searchSettings.filters
val items = if (!filters.isEmpty()) {
SearchEngine.Items(
songs = if (MusicType.SONGS in filters) library.songs else null,
albums = if (MusicType.ALBUMS in filters) library.albums else null,
artists = if (MusicType.ARTISTS in filters) library.artists else null,
genres = if (MusicType.GENRES in filters) library.genres else null,
playlists = if (MusicType.PLAYLISTS in filters) library.playlists else null,
)
} else {
SearchEngine.Items(
songs = library.songs,
albums = library.albums,
artists = library.artists,
genres = library.genres,
playlists = library.playlists
)
}
val items =
if (!filters.isEmpty()) {
SearchEngine.Items(
songs = if (MusicType.SONGS in filters) library.songs else null,
albums = if (MusicType.ALBUMS in filters) library.albums else null,
artists = if (MusicType.ARTISTS in filters) library.artists else null,
genres = if (MusicType.GENRES in filters) library.genres else null,
playlists = if (MusicType.PLAYLISTS in filters) library.playlists else null,
)
} else {
SearchEngine.Items(
songs = library.songs,
albums = library.albums,
artists = library.artists,
genres = library.genres,
playlists = library.playlists,
)
}
val results = searchEngine.search(items, query)
@@ -1,3 +1,21 @@
/*
* Copyright (c) 2026 Auxio Project
* FadingToolbarOffsetListener.kt is part of Auxio.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package org.oxycblt.auxio.ui
import android.view.View
@@ -5,10 +23,8 @@ import androidx.core.view.updatePadding
import com.google.android.material.appbar.AppBarLayout
import kotlin.math.abs
class FadingToolbarOffsetListener(
private val toolbar: View,
private val content: View
) : AppBarLayout.OnOffsetChangedListener {
class FadingToolbarOffsetListener(private val toolbar: View, private val content: View) :
AppBarLayout.OnOffsetChangedListener {
override fun onOffsetChanged(appBarLayout: AppBarLayout, verticalOffset: Int) {
val range = appBarLayout.totalScrollRange
// Fade out the toolbar as the AppBarLayout collapses. To prevent status bar overlap,
@@ -17,4 +33,4 @@ class FadingToolbarOffsetListener(
toolbar.alpha = 1f - (abs(verticalOffset.toFloat()) / (range.toFloat() / 2))
content.updatePadding(bottom = range + verticalOffset)
}
}
}