mirror of
https://github.com/advplyr/audiobookshelf-app.git
synced 2025-08-04 10:04:39 +02:00
Update android widget sizing, hide buttons on app close, and initialize when added
This commit is contained in:
commit
f5ca30620f
8 changed files with 73 additions and 61 deletions
|
@ -37,6 +37,16 @@ class MediaPlayerWidget : AppWidgetProvider() {
|
|||
override fun onEnabled(context: Context) {
|
||||
Log.i(tag, "onEnabled check context ${context.packageName}")
|
||||
|
||||
DeviceManager.deviceData.lastPlaybackSession?.let {
|
||||
val appWidgetManager = AppWidgetManager.getInstance(context)
|
||||
val componentName = ComponentName(context, MediaPlayerWidget::class.java)
|
||||
val ids = appWidgetManager.getAppWidgetIds(componentName)
|
||||
Log.d(tag, "Setting initial widget state with last playback session ${it.displayTitle}")
|
||||
for (widgetId in ids) {
|
||||
updateAppWidget(context, appWidgetManager, widgetId, it, false, true)
|
||||
}
|
||||
}
|
||||
|
||||
// Enter relevant functionality for when the first widget is created
|
||||
DeviceManager.widgetUpdater = (object : WidgetEventEmitter {
|
||||
override fun onPlayerChanged(pns: PlayerNotificationService) {
|
||||
|
@ -73,12 +83,6 @@ internal fun updateAppWidget(context: Context, appWidgetManager: AppWidgetManage
|
|||
PendingIntent.FLAG_UPDATE_CURRENT or PendingIntent.FLAG_IMMUTABLE
|
||||
)
|
||||
|
||||
// todo: show grayed out icons?
|
||||
val viewVisibility = if (isAppClosed) View.INVISIBLE else View.VISIBLE
|
||||
views.setViewVisibility(R.id.widgetPlayPauseButton, viewVisibility)
|
||||
views.setViewVisibility(R.id.widgetFastForwardButton, viewVisibility)
|
||||
views.setViewVisibility(R.id.widgetRewindButton, viewVisibility)
|
||||
|
||||
val playPausePI = MediaButtonReceiver.buildMediaButtonPendingIntent(context, PlaybackStateCompat.ACTION_PLAY_PAUSE)
|
||||
views.setOnClickPendingIntent(R.id.widgetPlayPauseButton, playPausePI)
|
||||
|
||||
|
@ -88,6 +92,8 @@ internal fun updateAppWidget(context: Context, appWidgetManager: AppWidgetManage
|
|||
val rewindPI = MediaButtonReceiver.buildMediaButtonPendingIntent(context, PlaybackStateCompat.ACTION_REWIND)
|
||||
views.setOnClickPendingIntent(R.id.widgetRewindButton, rewindPI)
|
||||
|
||||
// Show/Hide button container
|
||||
views.setViewVisibility(R.id.widgetButtonContainer, if (isAppClosed) View.GONE else View.VISIBLE)
|
||||
|
||||
views.setOnClickPendingIntent(R.id.widgetBackground, wholeWidgetClickPI)
|
||||
|
||||
|
|
|
@ -1,6 +1,8 @@
|
|||
package com.audiobookshelf.app.player
|
||||
|
||||
import android.app.*
|
||||
import android.appwidget.AppWidgetManager
|
||||
import android.content.ComponentName
|
||||
import android.content.Context
|
||||
import android.content.Intent
|
||||
import android.graphics.Bitmap
|
||||
|
@ -21,12 +23,15 @@ import android.support.v4.media.session.MediaControllerCompat
|
|||
import android.support.v4.media.session.MediaSessionCompat
|
||||
import android.support.v4.media.session.PlaybackStateCompat
|
||||
import android.util.Log
|
||||
import android.view.View
|
||||
import android.widget.RemoteViews
|
||||
import androidx.annotation.RequiresApi
|
||||
import androidx.core.app.NotificationCompat
|
||||
import androidx.core.content.ContextCompat
|
||||
import androidx.media.MediaBrowserServiceCompat
|
||||
import androidx.media.utils.MediaConstants
|
||||
import com.audiobookshelf.app.BuildConfig
|
||||
import com.audiobookshelf.app.MediaPlayerWidget
|
||||
import com.audiobookshelf.app.R
|
||||
import com.audiobookshelf.app.data.*
|
||||
import com.audiobookshelf.app.data.DeviceInfo
|
||||
|
@ -188,6 +193,7 @@ class PlayerNotificationService : MediaBrowserServiceCompat() {
|
|||
override fun onTaskRemoved(rootIntent: Intent?) {
|
||||
super.onTaskRemoved(rootIntent)
|
||||
Log.d(tag, "onTaskRemoved")
|
||||
|
||||
stopSelf()
|
||||
}
|
||||
|
||||
|
|
Binary file not shown.
Before Width: | Height: | Size: 3.4 KiB |
Binary file not shown.
Before Width: | Height: | Size: 51 KiB After Width: | Height: | Size: 89 KiB |
|
@ -3,13 +3,13 @@
|
|||
android:id="@+id/widgetBackground"
|
||||
android:layout_width="fill_parent"
|
||||
android:layout_height="fill_parent"
|
||||
android:orientation="vertical"
|
||||
android:orientation="horizontal"
|
||||
android:theme="@style/AppTheme.AppWidgetContainer"
|
||||
style="@style/Widget.Android.AppWidget.Container">
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="0dp"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="match_parent"
|
||||
android:layout_weight="3"
|
||||
android:background="?android:attr/colorAccent"
|
||||
android:theme="@style/MediaPlayerWidgetTheme"
|
||||
|
@ -19,22 +19,25 @@
|
|||
android:id="@+id/widgetAlbumArt"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="match_parent"
|
||||
android:layout_weight="1"
|
||||
android:layout_margin="8dp"
|
||||
android:layout_weight="2"
|
||||
android:scaleType="centerCrop"
|
||||
android:src="@drawable/icon" />
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="match_parent"
|
||||
android:layout_weight="3"
|
||||
android:layout_marginVertical="8dp"
|
||||
android:orientation="vertical"
|
||||
android:gravity="center_vertical">
|
||||
|
||||
<TextView
|
||||
android:id="@+id/widgetArtistText"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginHorizontal="8dp"
|
||||
android:layout_height="0dp"
|
||||
android:layout_weight="2"
|
||||
android:layout_marginLeft="8dp"
|
||||
android:gravity="bottom"
|
||||
android:ellipsize="end"
|
||||
android:maxLines="1"
|
||||
android:text="Artist"/>
|
||||
|
@ -42,12 +45,49 @@
|
|||
<TextView
|
||||
android:id="@+id/widgetMediaTitle"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginHorizontal="8dp"
|
||||
android:layout_height="0dp"
|
||||
android:layout_weight="2"
|
||||
android:layout_marginLeft="8dp"
|
||||
android:gravity="top"
|
||||
android:ellipsize="end"
|
||||
android:maxLines="1"
|
||||
android:text="Title"/>
|
||||
|
||||
<LinearLayout
|
||||
android:id="@+id/widgetButtonContainer"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="0dp"
|
||||
android:layout_weight="3"
|
||||
android:orientation="horizontal"
|
||||
android:background="?android:attr/colorAccent"
|
||||
android:theme="@style/MediaPlayerWidgetTheme">
|
||||
|
||||
<ImageView
|
||||
android:id="@+id/widgetRewindButton"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="match_parent"
|
||||
android:layout_weight="1"
|
||||
android:layout_margin="8dp"
|
||||
android:src="@drawable/exo_icon_rewind"
|
||||
style="@style/Widget.Android.AppWidget.InnerView"/>
|
||||
|
||||
<ImageView
|
||||
android:id="@+id/widgetPlayPauseButton"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="match_parent"
|
||||
android:layout_weight="1"
|
||||
android:layout_margin="6dp"
|
||||
android:src="@drawable/ic_media_play_dark" />
|
||||
|
||||
<ImageView
|
||||
android:id="@+id/widgetFastForwardButton"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="match_parent"
|
||||
android:layout_weight="1"
|
||||
android:layout_margin="8dp"
|
||||
android:src="@drawable/exo_icon_fastforward" />
|
||||
</LinearLayout>
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
<LinearLayout
|
||||
|
@ -65,39 +105,4 @@
|
|||
</LinearLayout>
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="0dp"
|
||||
android:layout_weight="2"
|
||||
android:orientation="horizontal"
|
||||
android:background="?android:attr/colorBackground"
|
||||
android:theme="@style/MediaPlayerWidgetTheme">
|
||||
|
||||
<ImageView
|
||||
android:id="@+id/widgetRewindButton"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="match_parent"
|
||||
android:layout_weight="1"
|
||||
android:layout_margin="8dp"
|
||||
android:src="@drawable/exo_icon_rewind"
|
||||
style="@style/Widget.Android.AppWidget.InnerView"/>
|
||||
|
||||
<ImageView
|
||||
android:id="@+id/widgetPlayPauseButton"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="match_parent"
|
||||
android:layout_weight="1"
|
||||
android:layout_margin="8dp"
|
||||
android:src="@android:drawable/ic_media_play" />
|
||||
|
||||
<ImageView
|
||||
android:id="@+id/widgetFastForwardButton"
|
||||
style="@style/Widget.Android.AppWidget.InnerView"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="match_parent"
|
||||
android:layout_margin="8dp"
|
||||
android:layout_weight="1"
|
||||
android:src="@drawable/exo_icon_fastforward" />
|
||||
</LinearLayout>
|
||||
</LinearLayout>
|
||||
|
|
|
@ -37,6 +37,6 @@
|
|||
<style name="Widget.Android.AppWidget.InnerView" parent="android:Widget">
|
||||
<!-- <item name="android:background">?android:attr/colorBackground</item>-->
|
||||
<!-- <item name="android:textColor">?android:attr/textColorPrimary</item>-->
|
||||
<item name="android:padding">48dp</item>
|
||||
<item name="android:padding">0dp</item>
|
||||
</style>
|
||||
</resources>
|
||||
|
|
|
@ -2,21 +2,16 @@
|
|||
|
||||
<style name="AppTheme.AppWidgetContainerParent" parent="@android:style/Theme.DeviceDefault">
|
||||
<!-- Radius of the outer bound of widgets to make the rounded corners -->
|
||||
<item name="appWidgetRadius">16dp</item>
|
||||
<item name="appWidgetRadius">0dp</item>
|
||||
<!--
|
||||
Radius of the inner view's bound of widgets to make the rounded corners.
|
||||
It needs to be 8dp or less than the value of appWidgetRadius
|
||||
-->
|
||||
<item name="appWidgetInnerRadius">8dp</item>
|
||||
<item name="appWidgetInnerRadius">0dp</item>
|
||||
</style>
|
||||
|
||||
<style name="AppTheme.AppWidgetContainer" parent="AppTheme.AppWidgetContainerParent">
|
||||
<!-- Apply padding to avoid the content of the widget colliding with the rounded corners -->
|
||||
<item name="appWidgetPadding">16dp</item>
|
||||
</style>
|
||||
|
||||
<style name="AppTheme.AppWidgetButton" parent="AppTheme.AppWidgetContainerParent">
|
||||
<!-- Apply padding to avoid the content of the widget colliding with the rounded corners -->
|
||||
<item name="appWidgetPadding">8dp</item>
|
||||
<item name="appWidgetPadding">0dp</item>
|
||||
</style>
|
||||
</resources>
|
||||
|
|
|
@ -3,8 +3,8 @@
|
|||
android:description="@string/app_widget_description"
|
||||
android:initialKeyguardLayout="@layout/media_player_widget"
|
||||
android:initialLayout="@layout/media_player_widget"
|
||||
android:minWidth="272dp"
|
||||
android:minHeight="56dp"
|
||||
android:minWidth="275dp"
|
||||
android:minHeight="50dp"
|
||||
android:previewImage="@drawable/media_player_widget_preview"
|
||||
android:previewLayout="@layout/media_player_widget"
|
||||
android:resizeMode="horizontal"
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue