all: reformat

This commit is contained in:
Alexander Capehart
2026-08-29 15:29:20 -06:00
parent d19cd9dc34
commit bf6c70192b
18 changed files with 220 additions and 216 deletions
@@ -239,31 +239,30 @@ constructor(context: Context, attrs: AttributeSet? = null, @AttrRes defStyleAttr
val playbackIndicator = (playbackIndicator ?: return).view
val iconSize = iconSize ?: (measuredWidth / 2)
playbackIndicator.apply {
imageMatrix =
indicatorMatrix.apply {
reset()
drawable?.let { drawable ->
// First scale the icon up to the desired size.
indicatorMatrixSrc.set(
0f,
0f,
drawable.intrinsicWidth.toFloat(),
drawable.intrinsicHeight.toFloat(),
)
indicatorMatrixDst.set(0f, 0f, iconSize.toFloat(), iconSize.toFloat())
indicatorMatrix.setRectToRect(
indicatorMatrixSrc,
indicatorMatrixDst,
Matrix.ScaleToFit.CENTER,
)
imageMatrix = indicatorMatrix.apply {
reset()
drawable?.let { drawable ->
// First scale the icon up to the desired size.
indicatorMatrixSrc.set(
0f,
0f,
drawable.intrinsicWidth.toFloat(),
drawable.intrinsicHeight.toFloat(),
)
indicatorMatrixDst.set(0f, 0f, iconSize.toFloat(), iconSize.toFloat())
indicatorMatrix.setRectToRect(
indicatorMatrixSrc,
indicatorMatrixDst,
Matrix.ScaleToFit.CENTER,
)
// Then actually center it into the icon.
indicatorMatrix.postTranslate(
(measuredWidth - iconSize) / 2f,
(measuredHeight - iconSize) / 2f,
)
}
// Then actually center it into the icon.
indicatorMatrix.postTranslate(
(measuredWidth - iconSize) / 2f,
(measuredHeight - iconSize) / 2f,
)
}
}
}
}
@@ -88,50 +88,49 @@ private constructor(context: Context, private val data: GalleryCoverCollection,
val positions = listOf(p0, p1, p2, p3)
// first we actually have to aggregate the geometry here so that
// our overlaps will actually work
val tiles =
positions.mapIndexed { index, baseRect ->
// generate path-tiles for each cover
val isTop = index < 2
val isLeft = index % 2 == 0
val isBottom = !isTop
val isRight = !isLeft
val tiles = positions.mapIndexed { index, baseRect ->
// generate path-tiles for each cover
val isTop = index < 2
val isLeft = index % 2 == 0
val isBottom = !isTop
val isRight = !isLeft
// inset base cover rect to prevent rounded corners from stacking in a way
// that leads weird "holes" and is instead more dynamic
// todo: refine this so we can do dynamic overlap?
val innerRect = RectF(baseRect)
innerRect.left += if (isLeft) 0f else gapWidthPx
innerRect.top += if (isTop) 0f else gapWidthPx
innerRect.right -= if (isRight) 0f else gapWidthPx
innerRect.bottom -= if (isBottom) 0f else gapWidthPx
// inset base cover rect to prevent rounded corners from stacking in a way
// that leads weird "holes" and is instead more dynamic
// todo: refine this so we can do dynamic overlap?
val innerRect = RectF(baseRect)
innerRect.left += if (isLeft) 0f else gapWidthPx
innerRect.top += if (isTop) 0f else gapWidthPx
innerRect.right -= if (isRight) 0f else gapWidthPx
innerRect.bottom -= if (isBottom) 0f else gapWidthPx
// set up the actual gap path
val gapRect = RectF(innerRect)
gapRect.inset(-gapWidthPx, -gapWidthPx)
// set up the actual gap path
val gapRect = RectF(innerRect)
gapRect.inset(-gapWidthPx, -gapWidthPx)
val gapPath =
rounded(
gapRect,
topLeft = if (!isTop && !isLeft) cornerRadiusPx else 0f,
topRight = if (!isTop && !isRight) cornerRadiusPx else 0f,
bottomRight = if (!isBottom && !isRight) cornerRadiusPx else 0f,
bottomLeft = if (!isBottom && !isLeft) cornerRadiusPx else 0f,
)
val gapPath =
rounded(
gapRect,
topLeft = if (!isTop && !isLeft) cornerRadiusPx else 0f,
topRight = if (!isTop && !isRight) cornerRadiusPx else 0f,
bottomRight = if (!isBottom && !isRight) cornerRadiusPx else 0f,
bottomLeft = if (!isBottom && !isLeft) cornerRadiusPx else 0f,
)
// then the inner mask
// adjust corner radii to make up for gap
val innerRadius = (cornerRadiusPx - gapWidthPx).coerceAtLeast(0f)
val maskPath =
rounded(
innerRect,
topLeft = if (!isTop && !isLeft) innerRadius else 0f,
topRight = if (!isTop && !isRight) innerRadius else 0f,
bottomRight = if (!isBottom && !isRight) innerRadius else 0f,
bottomLeft = if (!isBottom && !isLeft) innerRadius else 0f,
)
// then the inner mask
// adjust corner radii to make up for gap
val innerRadius = (cornerRadiusPx - gapWidthPx).coerceAtLeast(0f)
val maskPath =
rounded(
innerRect,
topLeft = if (!isTop && !isLeft) innerRadius else 0f,
topRight = if (!isTop && !isRight) innerRadius else 0f,
bottomRight = if (!isBottom && !isRight) innerRadius else 0f,
bottomLeft = if (!isBottom && !isLeft) innerRadius else 0f,
)
TileGeometry(innerRect, gapPath, maskPath)
}
TileGeometry(innerRect, gapPath, maskPath)
}
for ((orderIndex, imageIndex) in zOrder.withIndex()) {
val bitmap = bitmaps[imageIndex]
@@ -135,8 +135,9 @@ private constructor(
// Cancel the previous music loading job.
currentIndexJob?.cancel()
// Start a new music loading job on a co-routine.
currentIndexJob =
indexScope.launch { musicRepository.index(this@IndexingHolder, withCache) }
currentIndexJob = indexScope.launch {
musicRepository.index(this@IndexingHolder, withCache)
}
}
override fun onIndexingStateChanged() {
@@ -102,14 +102,18 @@ constructor(
fun getRoot() = BrowserRoot(MediaSessionUID.Tab(TabNode.Root).toString(), Bundle())
fun getItem(mediaId: String, result: Result<MediaItem>) =
result.dispatch { musicBrowser.getItem(mediaId) }
fun getItem(mediaId: String, result: Result<MediaItem>) = result.dispatch {
musicBrowser.getItem(mediaId)
}
fun getChildren(mediaId: String, maxTabs: Int, result: Result<MutableList<MediaItem>>) =
result.dispatch { musicBrowser.getChildren(mediaId, maxTabs)?.toMutableList() }
result.dispatch {
musicBrowser.getChildren(mediaId, maxTabs)?.toMutableList()
}
fun search(query: String, result: Result<MutableList<MediaItem>>) =
result.dispatchAsync { musicBrowser.search(query) }
fun search(query: String, result: Result<MutableList<MediaItem>>) = result.dispatchAsync {
musicBrowser.search(query)
}
private fun <T> Result<T>.dispatch(body: () -> T?) {
try {
@@ -194,14 +194,13 @@ constructor(
// Replace the previous position co-routine with a new one that uses the new
// state information.
lastPositionJob?.cancel()
lastPositionJob =
viewModelScope.launch {
while (true) {
_positionDs.value = progression.calculateElapsedPositionMs().msToDs()
// Wait a deci-second for the next position tick.
delay(100)
}
lastPositionJob = viewModelScope.launch {
while (true) {
_positionDs.value = progression.calculateElapsedPositionMs().msToDs()
// Wait a deci-second for the next position tick.
delay(100)
}
}
}
override fun onRepeatModeChanged(repeatMode: RepeatMode) {
@@ -310,17 +310,16 @@ private constructor(
* @param queue The current queue to upload.
*/
private fun updateQueue(queue: List<Song>) {
val queueItems =
queue.mapIndexed { i, song ->
val description =
song.toMediaDescription(
context,
{ putInt(MediaSessionInterface.KEY_QUEUE_POS, i) },
)
// Store the item index so we can then use the analogous index in the
// playback state.
MediaSessionCompat.QueueItem(description, i.toLong())
}
val queueItems = queue.mapIndexed { i, song ->
val description =
song.toMediaDescription(
context,
{ putInt(MediaSessionInterface.KEY_QUEUE_POS, i) },
)
// Store the item index so we can then use the analogous index in the
// playback state.
MediaSessionCompat.QueueItem(description, i.toLong())
}
L.d("Uploading ${queueItems.size} songs to MediaSession queue")
mediaSession.setQueue(queueItems)
}
@@ -89,14 +89,11 @@ private constructor(
private fun scheduleAutoStop() {
autoStopJob?.cancel()
autoStopJob =
scope.launch {
delay(AUTO_STOP_DELAY_MS)
L.d(
"Auto-stop timer expired after ${AUTO_STOP_DELAY_MS / 60000} minutes of inactivity"
)
playbackManager.endSession()
}
autoStopJob = scope.launch {
delay(AUTO_STOP_DELAY_MS)
L.d("Auto-stop timer expired after ${AUTO_STOP_DELAY_MS / 60000} minutes of inactivity")
playbackManager.endSession()
}
}
private fun cancelAutoStop() {
@@ -123,12 +123,11 @@ class SecondsView(context: Context, attrs: AttributeSet?) : LinearLayout(context
val one = alphaSpring.alpha(binding.icon1, cyclicAlpha[row])
val two = alphaSpring.alpha(binding.icon2, cyclicAlpha[row + 1])
val three = alphaSpring.alpha(binding.icon3, cyclicAlpha[row + 2])
val endListener =
DynamicAnimation.OnAnimationEndListener { _, cancelled, _, _ ->
if (!cancelled) {
cycle((at + 1) % 5)
}
val endListener = DynamicAnimation.OnAnimationEndListener { _, cancelled, _, _ ->
if (!cancelled) {
cycle((at + 1) % 5)
}
}
when {
cyclicAlpha[row] != binding.icon1.alpha -> {
one.addEndListener(endListener)
@@ -102,10 +102,9 @@ constructor(
// Searching is time-consuming, so do it in the background.
L.d("Searching music library for $query")
currentSearchJob =
viewModelScope.launch {
_searchResults.value = searchImpl(library, query).also { yield() }
}
currentSearchJob = viewModelScope.launch {
_searchResults.value = searchImpl(library, query).also { yield() }
}
}
private suspend fun searchImpl(library: Library, query: String): List<Item> {
@@ -51,30 +51,27 @@ class MusicPreferenceFragment : BasePreferenceFragment(R.xml.preferences_music)
override fun onSetupPreference(preference: Preference) {
if (preference.key == getString(R.string.set_key_cover_mode)) {
L.d("Configuring cover mode setting")
preference.onPreferenceChangeListener =
Preference.OnPreferenceChangeListener { _, _ ->
L.d("Cover mode changed, reloading music")
musicModel.refresh()
true
}
preference.onPreferenceChangeListener = Preference.OnPreferenceChangeListener { _, _ ->
L.d("Cover mode changed, reloading music")
musicModel.refresh()
true
}
}
if (preference.key == getString(R.string.set_key_square_covers)) {
L.d("Configuring square cover setting")
preference.onPreferenceChangeListener =
Preference.OnPreferenceChangeListener { _, _ ->
L.d("Cover mode changed, resetting image memory cache")
imageLoader.memoryCache?.clear()
true
}
preference.onPreferenceChangeListener = Preference.OnPreferenceChangeListener { _, _ ->
L.d("Cover mode changed, resetting image memory cache")
imageLoader.memoryCache?.clear()
true
}
}
if (preference.key == getString(R.string.set_key_with_hidden)) {
L.d("Configuring ignore hidden files setting")
preference.onPreferenceChangeListener =
Preference.OnPreferenceChangeListener { _, _ ->
L.d("Ignore hidden files setting changed, reloading music")
musicModel.refresh()
true
}
preference.onPreferenceChangeListener = Preference.OnPreferenceChangeListener { _, _ ->
L.d("Ignore hidden files setting changed, reloading music")
musicModel.refresh()
true
}
}
}
}
@@ -51,26 +51,25 @@ constructor(context: Context, attrs: AttributeSet? = null, @AttrRes defStyleAttr
private var scrollingChild: View? = null
private val tConsumed = IntArray(2)
private val onPreDraw =
ViewTreeObserver.OnPreDrawListener {
val child = findScrollingChild()
private val onPreDraw = ViewTreeObserver.OnPreDrawListener {
val child = findScrollingChild()
if (child != null) {
val coordinator = parent as CoordinatorLayout
coordinatorLayoutBehavior?.onNestedPreScroll(
coordinator,
this,
coordinator,
0,
0,
tConsumed,
0,
)
}
true
if (child != null) {
val coordinator = parent as CoordinatorLayout
coordinatorLayoutBehavior?.onNestedPreScroll(
coordinator,
this,
coordinator,
0,
0,
tConsumed,
0,
)
}
true
}
init {
fitsSystemWindows = true
viewTreeObserver.addOnPreDrawListener(onPreDraw)
@@ -309,7 +309,10 @@ class WidgetProvider : AppWidgetProvider() {
setImageViewBitmap(R.id.widget_cover, state.cover)
setContentDescription(
R.id.widget_cover,
context.getString(R.string.desc_album_cover, state.song.album.name.resolve(context)),
context.getString(
R.string.desc_album_cover,
state.song.album.name.resolve(context),
),
)
} else {
discardCover(context)