Skip to content

Commit

Permalink
<Merge> app-widgets -> dev
Browse files Browse the repository at this point in the history
  • Loading branch information
chr56 committed Oct 31, 2024
2 parents 4891809 + 882d0c7 commit b8fea09
Show file tree
Hide file tree
Showing 7 changed files with 309 additions and 173 deletions.
10 changes: 7 additions & 3 deletions app/src/main/java/player/phonograph/appwidgets/AppWidgetBig.kt
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package player.phonograph.appwidgets

import coil.target.Target
import player.phonograph.R
import player.phonograph.appwidgets.base.BaseAppWidget
import player.phonograph.model.Song
import player.phonograph.util.ui.getScreenSize
import androidx.core.graphics.drawable.toBitmapOrNull
Expand Down Expand Up @@ -37,10 +36,10 @@ class AppWidgetBig : BaseAppWidget() {

override fun startUpdateCover(
context: Context,
appWidgetIds: IntArray?,
view: RemoteViews,
song: Song,
isPlaying: Boolean,
appWidgetIds: IntArray?,
) {
// Load the album cover async and push the update on completion
val p = context.getScreenSize()
Expand All @@ -65,10 +64,11 @@ class AppWidgetBig : BaseAppWidget() {
}

private fun onUpdate(bitmap: Bitmap?) {
cachedCover = bitmap
if (bitmap == null) {
view.setImageViewResource(R.id.image, R.drawable.default_album_art)
} else {
view.setImageViewBitmap(R.id.image, bitmap)
updateImage(context, view, bitmap)
}
pushUpdate(context.applicationContext, appWidgetIds, view)
}
Expand All @@ -77,6 +77,10 @@ class AppWidgetBig : BaseAppWidget() {

}

override fun updateImage(context: Context, view: RemoteViews, bitmap: Bitmap?) {
view.setImageViewBitmap(R.id.image, bitmap)
}

override val clickableAreas: IntArray = intArrayOf(R.id.clickable_area)

companion object {
Expand Down
37 changes: 22 additions & 15 deletions app/src/main/java/player/phonograph/appwidgets/AppWidgetCard.kt
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package player.phonograph.appwidgets

import player.phonograph.R
import player.phonograph.appwidgets.Util.createRoundedBitmap
import player.phonograph.appwidgets.base.BaseAppWidget
import player.phonograph.coil.target.PaletteTargetBuilder
import player.phonograph.model.Song
import util.theme.color.secondaryTextColor
Expand Down Expand Up @@ -35,10 +34,10 @@ class AppWidgetCard : BaseAppWidget() {

override fun startUpdateCover(
context: Context,
appWidgetIds: IntArray?,
view: RemoteViews,
song: Song,
isPlaying: Boolean,
appWidgetIds: IntArray?,
) {
if (imageSize == 0) imageSize = context.resources.getDimensionPixelSize(
R.dimen.app_widget_card_image_size
Expand All @@ -59,7 +58,9 @@ class AppWidgetCard : BaseAppWidget() {
view.setImageViewResource(R.id.image, R.drawable.default_album_art)
}
.onResourceReady { result, paletteColor ->
updateWidget(view, context, isPlaying, result.toBitmapOrNull(), paletteColor)
val bitmap = result.toBitmapOrNull()
cachedCover = bitmap
updateWidget(view, context, isPlaying, bitmap, paletteColor)
pushUpdate(context, appWidgetIds, view)
}
.onFail {
Expand All @@ -82,20 +83,26 @@ class AppWidgetCard : BaseAppWidget() {
appWidgetView.bindDrawable(context, R.id.button_next, R.drawable.ic_skip_next_white_24dp, color)
appWidgetView.bindDrawable(context, R.id.button_prev, R.drawable.ic_skip_previous_white_24dp, color)

appWidgetView.setImageViewBitmap(
R.id.image,
createRoundedBitmap(
getAlbumArtDrawable(context.resources, bitmap),
imageSize,
imageSize,
cardRadius,
0f,
cardRadius,
0f
)
)
updateImage(context, appWidgetView, bitmap)
}

override fun updateImage(
context: Context,
view: RemoteViews,
bitmap: Bitmap?,
) = view.setImageViewBitmap(
R.id.image,
createRoundedBitmap(
getAlbumArtDrawable(context.resources, bitmap),
imageSize,
imageSize,
cardRadius,
0f,
cardRadius,
0f
)
)

override val clickableAreas: IntArray = intArrayOf(R.id.image, R.id.media_titles)

companion object {
Expand Down
38 changes: 23 additions & 15 deletions app/src/main/java/player/phonograph/appwidgets/AppWidgetClassic.kt
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package player.phonograph.appwidgets

import player.phonograph.R
import player.phonograph.appwidgets.Util.createRoundedBitmap
import player.phonograph.appwidgets.base.BaseAppWidget
import player.phonograph.coil.target.PaletteTargetBuilder
import player.phonograph.model.Song
import util.theme.color.secondaryTextColor
Expand Down Expand Up @@ -35,10 +34,10 @@ class AppWidgetClassic : BaseAppWidget() {

override fun startUpdateCover(
context: Context,
appWidgetIds: IntArray?,
view: RemoteViews,
song: Song,
isPlaying: Boolean,
appWidgetIds: IntArray?,
) {
if (imageSize == 0) imageSize = context.resources.getDimensionPixelSize(
R.dimen.app_widget_classic_image_size
Expand All @@ -59,7 +58,9 @@ class AppWidgetClassic : BaseAppWidget() {
view.setImageViewResource(R.id.image, R.drawable.default_album_art)
}
.onResourceReady { result, paletteColor ->
updateWidget(view, context, isPlaying, result.toBitmapOrNull(), paletteColor)
val bitmap = result.toBitmapOrNull()
cachedCover = bitmap
updateWidget(view, context, isPlaying, bitmap, paletteColor)
pushUpdate(context, appWidgetIds, view)
}
.onFail {
Expand All @@ -81,20 +82,27 @@ class AppWidgetClassic : BaseAppWidget() {
appWidgetView.bindDrawable(context, R.id.button_next, R.drawable.ic_skip_next_white_24dp, color)
appWidgetView.bindDrawable(context, R.id.button_prev, R.drawable.ic_skip_previous_white_24dp, color)

appWidgetView.setImageViewBitmap(
R.id.image,
createRoundedBitmap(
getAlbumArtDrawable(context.resources, bitmap),
imageSize,
imageSize,
cardRadius,
0f,
cardRadius,
0f
)
)
updateImage(context, appWidgetView, bitmap)
}

override fun updateImage(
context: Context,
view: RemoteViews,
bitmap: Bitmap?,
) = view.setImageViewBitmap(
R.id.image,
createRoundedBitmap(
getAlbumArtDrawable(context.resources, bitmap),
imageSize,
imageSize,
cardRadius,
0f,
cardRadius,
0f
)
)


override val clickableAreas: IntArray = intArrayOf(R.id.image, R.id.media_titles)

companion object {
Expand Down
37 changes: 22 additions & 15 deletions app/src/main/java/player/phonograph/appwidgets/AppWidgetSmall.kt
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package player.phonograph.appwidgets

import player.phonograph.R
import player.phonograph.appwidgets.Util.createRoundedBitmap
import player.phonograph.appwidgets.base.BaseAppWidget
import player.phonograph.coil.target.PaletteTargetBuilder
import player.phonograph.model.Song
import util.theme.color.secondaryTextColor
Expand Down Expand Up @@ -38,10 +37,10 @@ class AppWidgetSmall : BaseAppWidget() {

override fun startUpdateCover(
context: Context,
appWidgetIds: IntArray?,
view: RemoteViews,
song: Song,
isPlaying: Boolean,
appWidgetIds: IntArray?,
) {
if (imageSize == 0) imageSize = context.resources.getDimensionPixelSize(
R.dimen.app_widget_small_image_size
Expand All @@ -63,7 +62,9 @@ class AppWidgetSmall : BaseAppWidget() {
view.setImageViewResource(R.id.image, R.drawable.default_album_art)
}
.onResourceReady { result, paletteColor ->
updateWidget(view, context, isPlaying, result.toBitmapOrNull(), paletteColor)
val bitmap = result.toBitmapOrNull()
cachedCover = bitmap
updateWidget(view, context, isPlaying, bitmap, paletteColor)
pushUpdate(context, appWidgetIds, view)
}
.onFail {
Expand All @@ -86,20 +87,26 @@ class AppWidgetSmall : BaseAppWidget() {
appWidgetView.bindDrawable(context, R.id.button_next, R.drawable.ic_skip_next_white_24dp, color)
appWidgetView.bindDrawable(context, R.id.button_prev, R.drawable.ic_skip_previous_white_24dp, color)

appWidgetView.setImageViewBitmap(
R.id.image,
createRoundedBitmap(
getAlbumArtDrawable(context.resources, bitmap),
imageSize,
imageSize,
cardRadius,
0f,
cardRadius,
0f
)
)
updateImage(context, appWidgetView, bitmap)
}

override fun updateImage(
context: Context,
view: RemoteViews,
bitmap: Bitmap?,
) = view.setImageViewBitmap(
R.id.image,
createRoundedBitmap(
getAlbumArtDrawable(context.resources, bitmap),
imageSize,
imageSize,
cardRadius,
0f,
cardRadius,
0f
)
)

override val clickableAreas: IntArray = intArrayOf(R.id.image, R.id.media_titles)

companion object {
Expand Down
Loading

0 comments on commit b8fea09

Please sign in to comment.