mirror of
https://github.com/advplyr/audiobookshelf-app.git
synced 2025-08-03 17:44:51 +02:00
redo widget layout, hide buttons on force close
This commit is contained in:
parent
bc6ef96465
commit
a5ba6c64c9
6 changed files with 72 additions and 52 deletions
|
@ -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
|
||||
|
@ -184,6 +189,13 @@ class PlayerNotificationService : MediaBrowserServiceCompat() {
|
|||
override fun onTaskRemoved(rootIntent: Intent?) {
|
||||
super.onTaskRemoved(rootIntent)
|
||||
Log.d(tag, "onTaskRemoved")
|
||||
// Updates widget to hide buttons when app is force closed
|
||||
val appWidgetManager = AppWidgetManager.getInstance(this)
|
||||
val remoteViews = RemoteViews(this.packageName, R.layout.media_player_widget)
|
||||
val thisWidget = ComponentName(this, MediaPlayerWidget::class.java)
|
||||
remoteViews.setViewVisibility(R.id.widgetButtonContainer, View.GONE)
|
||||
appWidgetManager.updateAppWidget(thisWidget, remoteViews)
|
||||
|
||||
stopSelf()
|
||||
}
|
||||
|
||||
|
@ -334,6 +346,13 @@ class PlayerNotificationService : MediaBrowserServiceCompat() {
|
|||
|
||||
initializeMPlayer()
|
||||
currentPlayer = mPlayer
|
||||
|
||||
// Updates widget to show buttons when app is opened
|
||||
val appWidgetManager = AppWidgetManager.getInstance(this)
|
||||
val remoteViews = RemoteViews(this.packageName, R.layout.media_player_widget)
|
||||
val thisWidget = ComponentName(this, MediaPlayerWidget::class.java)
|
||||
remoteViews.setViewVisibility(R.id.widgetButtonContainer, View.VISIBLE)
|
||||
appWidgetManager.updateAppWidget(thisWidget, remoteViews)
|
||||
}
|
||||
|
||||
private fun initializeMPlayer() {
|
||||
|
|
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,38 +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"
|
||||
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>
|
||||
|
|
|
@ -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>
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue