ui: rework rounded covers into round mode

Rework the rounded covers option into a new "Round Mode" option.

This commit extends the rounded corners configuration to now the
widget, thus making the setting apply now to covers, the bar, and
the widget configuration. This makes a naming change useful.
This commit is contained in:
OxygenCobalt
2022-07-01 20:06:54 -06:00
parent e41645ee28
commit 217ced8ade
31 changed files with 151 additions and 91 deletions
@@ -61,7 +61,7 @@ constructor(context: Context, attrs: AttributeSet? = null, @AttrRes defStyleAttr
set(value) {
field = value
(background as? MaterialShapeDrawable)?.let { bg ->
if (settings.roundCovers) {
if (settings.roundMode) {
bg.setCornerSize(value)
} else {
bg.setCornerSize(0f)
@@ -160,7 +160,7 @@ private class IndexerNotification(private val context: Context) :
notificationManager.createNotificationChannel(channel)
}
setSmallIcon(R.drawable.ic_indexer_32)
setSmallIcon(R.drawable.ic_indexer_24)
setCategory(NotificationCompat.CATEGORY_PROGRESS)
setShowWhen(false)
setSilent(true)
@@ -27,6 +27,7 @@ import android.support.v4.media.session.MediaSessionCompat
import androidx.annotation.DrawableRes
import androidx.core.app.NotificationCompat
import androidx.media.app.NotificationCompat.MediaStyle
import okhttp3.internal.notify
import org.oxycblt.auxio.BuildConfig
import org.oxycblt.auxio.IntegerTable
import org.oxycblt.auxio.R
@@ -35,6 +36,7 @@ import org.oxycblt.auxio.music.MusicParent
import org.oxycblt.auxio.music.Song
import org.oxycblt.auxio.playback.state.RepeatMode
import org.oxycblt.auxio.util.getSystemServiceSafe
import org.oxycblt.auxio.util.logD
import org.oxycblt.auxio.util.newBroadcastPendingIntent
import org.oxycblt.auxio.util.newMainPendingIntent
@@ -94,24 +96,26 @@ class NotificationComponent(
/** Set the metadata of the notification using [song]. */
fun updateMetadata(song: Song, parent: MusicParent?) {
setContentTitle(song.resolveName(context))
setContentText(song.resolveIndividualArtistName(context))
// Starting in API 24, the subtext field changed semantics from being below the content
// text to being above the title.
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
setSubText(parent?.resolveName(context) ?: context.getString(R.string.lbl_all_songs))
} else {
setSubText(song.album.resolveName(context))
}
provider.load(
song,
object : BitmapProvider.Target {
override fun onCompleted(bitmap: Bitmap?) {
logD("writing ${song.rawName} to notif")
setLargeIcon(bitmap)
build()
callback.onNotificationChanged(this@NotificationComponent)
setContentTitle(song.resolveName(context))
setContentText(song.resolveIndividualArtistName(context))
// Starting in API 24, the subtext field changed semantics from being below the
// content text to being above the title.
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
setSubText(
parent?.resolveName(context)
?: context.getString(R.string.lbl_all_songs))
} else {
setSubText(song.album.resolveName(context))
}
callback.onNotificationChanged(song, this@NotificationComponent)
}
})
}
@@ -120,7 +124,7 @@ class NotificationComponent(
fun updatePlaying(isPlaying: Boolean) {
mActions[2] = buildPlayPauseAction(context, isPlaying)
if (!provider.isBusy) {
callback.onNotificationChanged(this)
callback.onNotificationChanged(null, this)
}
}
@@ -128,7 +132,7 @@ class NotificationComponent(
fun updateRepeatMode(repeatMode: RepeatMode) {
mActions[0] = buildRepeatAction(context, repeatMode)
if (!provider.isBusy) {
callback.onNotificationChanged(this)
callback.onNotificationChanged(null, this)
}
}
@@ -136,7 +140,7 @@ class NotificationComponent(
fun updateShuffled(isShuffled: Boolean) {
mActions[0] = buildShuffleAction(context, isShuffled)
if (!provider.isBusy) {
callback.onNotificationChanged(this)
callback.onNotificationChanged(null, this)
}
}
@@ -188,7 +192,7 @@ class NotificationComponent(
}
interface Callback {
fun onNotificationChanged(component: NotificationComponent)
fun onNotificationChanged(song: Song?, component: NotificationComponent)
}
companion object {
@@ -24,6 +24,7 @@ import android.content.Intent
import android.content.IntentFilter
import android.media.AudioManager
import android.os.IBinder
import androidx.core.app.NotificationCompat
import androidx.core.app.ServiceCompat
import com.google.android.exoplayer2.C
import com.google.android.exoplayer2.ExoPlayer
@@ -310,9 +311,10 @@ class PlaybackService :
// --- NOTIFICATION CALLBACKS ---
override fun onNotificationChanged(component: NotificationComponent) {
override fun onNotificationChanged(song: Song?, component: NotificationComponent) {
if (hasPlayed && playbackManager.song != null) {
logD("Starting foreground/notifying")
logD("Starting foreground/notifying: ${song?.rawName}")
logD(NotificationCompat.getContentTitle(component.build()))
if (!isForeground) {
startForeground(IntegerTable.PLAYBACK_NOTIFICATION_CODE, component.build())
@@ -123,9 +123,9 @@ class Settings(private val context: Context, private val callback: Callback? = n
val useQualityCovers: Boolean
get() = inner.getBoolean(context.getString(R.string.set_key_quality_covers), false)
/** Whether to round album covers */
val roundCovers: Boolean
get() = inner.getBoolean(context.getString(R.string.set_key_round_covers), false)
/** Whether to round additional UI elements (including album covers) */
val roundMode: Boolean
get() = inner.getBoolean(context.getString(R.string.set_key_round_mode), false)
/** Whether to resume playback when a headset is connected (may not work well in all cases) */
val headsetAutoplay: Boolean
@@ -102,7 +102,7 @@ constructor(context: Context, attrs: AttributeSet? = null, defStyle: Int = 0) :
private val elevationNormal = context.getDimenSafe(R.dimen.elevation_normal)
private val cornersLarge =
if (Settings(context).roundCovers) {
if (Settings(context).roundMode) {
// Since album covers are rounded, we can also round the bar too.
context.getDimenSizeSafe(R.dimen.size_corners_large)
} else {
@@ -18,12 +18,14 @@
package org.oxycblt.auxio.widgets
import android.content.Context
import android.os.Build
import android.view.View
import android.widget.RemoteViews
import androidx.annotation.LayoutRes
import org.oxycblt.auxio.R
import org.oxycblt.auxio.playback.state.RepeatMode
import org.oxycblt.auxio.playback.system.PlaybackService
import org.oxycblt.auxio.settings.Settings
import org.oxycblt.auxio.util.newBroadcastPendingIntent
import org.oxycblt.auxio.util.newMainPendingIntent
@@ -39,6 +41,7 @@ fun createDefaultWidget(context: Context) = createViews(context, R.layout.widget
*/
fun createThinWidget(context: Context, state: WidgetComponent.WidgetState) =
createViews(context, R.layout.widget_thin)
.applyRoundingToBackground(context)
.applyMeta(context, state)
.applyBasicControls(context, state)
/**
@@ -48,6 +51,7 @@ fun createThinWidget(context: Context, state: WidgetComponent.WidgetState) =
*/
fun createSmallWidget(context: Context, state: WidgetComponent.WidgetState) =
createViews(context, R.layout.widget_small)
.applyRoundingToBar(context)
.applyCover(context, state)
.applyBasicControls(context, state)
@@ -57,18 +61,21 @@ fun createSmallWidget(context: Context, state: WidgetComponent.WidgetState) =
*/
fun createMediumWidget(context: Context, state: WidgetComponent.WidgetState) =
createViews(context, R.layout.widget_medium)
.applyRoundingToBackground(context)
.applyMeta(context, state)
.applyBasicControls(context, state)
/** The wide widget is for Nx2 widgets and is like the small widget but with more controls. */
fun createWideWidget(context: Context, state: WidgetComponent.WidgetState) =
createViews(context, R.layout.widget_wide)
.applyRoundingToBar(context)
.applyCover(context, state)
.applyFullControls(context, state)
/** The large widget is for 3x4 widgets and shows all metadata and controls. */
fun createLargeWidget(context: Context, state: WidgetComponent.WidgetState): RemoteViews =
createViews(context, R.layout.widget_large)
.applyRoundingToBackground(context)
.applyMeta(context, state)
.applyFullControls(context, state)
@@ -78,6 +85,26 @@ private fun createViews(context: Context, @LayoutRes layout: Int): RemoteViews {
return views
}
private fun RemoteViews.applyRoundingToBackground(context: Context): RemoteViews {
if (Settings(context).roundMode && Build.VERSION.SDK_INT < Build.VERSION_CODES.S) {
setInt(android.R.id.background, "setBackgroundResource", R.drawable.ui_widget_bg_round)
} else {
setInt(android.R.id.background, "setBackgroundResource", R.drawable.ui_widget_bg)
}
return this
}
private fun RemoteViews.applyRoundingToBar(context: Context): RemoteViews {
if (Settings(context).roundMode && Build.VERSION.SDK_INT < Build.VERSION_CODES.S) {
setInt(R.id.widget_controls, "setBackgroundResource", R.drawable.ui_widget_bg_round)
} else {
setInt(R.id.widget_controls, "setBackgroundResource", R.drawable.ui_widget_bar)
}
return this
}
private fun RemoteViews.applyMeta(
context: Context,
state: WidgetComponent.WidgetState
@@ -84,14 +84,23 @@ class WidgetComponent(private val context: Context) :
song,
object : BitmapProvider.Target {
override fun onConfigRequest(builder: ImageRequest.Builder): ImageRequest.Builder {
val cornerRadius =
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.S) {
context.getDimenSizeSafe(android.R.dimen.system_app_widget_inner_radius)
} else if (settings.roundMode) {
context.getDimenSizeSafe(R.dimen.size_corners_large)
} else {
0
}
// The widget has two distinct styles that we must transform the album art to
// accommodate:
// - Before Android 12, the widget has hard edges, so we don't need to round
// out the album art.
// - After Android 12, the widget has round edges, so we need to round out
// the album art. I dislike this, but it's mainly for stylistic cohesion.
return if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.S) {
this@WidgetComponent.logD("Doing API 31 cover load")
return if (cornerRadius > 0) {
this@WidgetComponent.logD("Loading round covers: $cornerRadius")
val metrics = context.resources.displayMetrics
@@ -101,11 +110,7 @@ class WidgetComponent(private val context: Context) :
builder
.transformations(
SquareFrameTransform.INSTANCE,
RoundedCornersTransformation(
context
.getDimenSizeSafe(
android.R.dimen.system_app_widget_inner_radius)
.toFloat()))
RoundedCornersTransformation(cornerRadius.toFloat()))
// The output of RoundedCornersTransformation is dimension-dependent,
// so scale up the image to the screen size to ensure consistent radii.
// Make sure we stop at 1024, so we don't accidentally make a massive
@@ -145,7 +150,8 @@ class WidgetComponent(private val context: Context) :
override fun onRepeatChanged(repeatMode: RepeatMode) = update()
override fun onSettingChanged(key: String) {
if (key == context.getString(R.string.set_key_show_covers) ||
key == context.getString(R.string.set_key_quality_covers)) {
key == context.getString(R.string.set_key_quality_covers) ||
key == context.getString(R.string.set_key_round_mode)) {
update()
}
}