diff --git a/app/src/main/ic_launcher-playstore.png b/app/src/main/ic_launcher-playstore.png new file mode 100644 index 000000000..6c912e2ac Binary files /dev/null and b/app/src/main/ic_launcher-playstore.png differ diff --git a/app/src/main/java/org/oxycblt/auxio/MainActivity.kt b/app/src/main/java/org/oxycblt/auxio/MainActivity.kt index 5d0ec4d90..58e4b9c98 100644 --- a/app/src/main/java/org/oxycblt/auxio/MainActivity.kt +++ b/app/src/main/java/org/oxycblt/auxio/MainActivity.kt @@ -1,7 +1,10 @@ package org.oxycblt.auxio +import android.content.ComponentName import android.content.Context import android.content.Intent +import android.content.ServiceConnection +import android.os.IBinder import android.util.AttributeSet import android.view.View import androidx.appcompat.app.AppCompatActivity diff --git a/app/src/main/java/org/oxycblt/auxio/loading/LoadingFragment.kt b/app/src/main/java/org/oxycblt/auxio/loading/LoadingFragment.kt index 81690da31..fb489cc60 100644 --- a/app/src/main/java/org/oxycblt/auxio/loading/LoadingFragment.kt +++ b/app/src/main/java/org/oxycblt/auxio/loading/LoadingFragment.kt @@ -33,6 +33,8 @@ class LoadingFragment : Fragment(R.layout.fragment_loading) { findNavController().navigate( LoadingFragmentDirections.actionToMain() ) + + return null } val binding = FragmentLoadingBinding.inflate(inflater) diff --git a/app/src/main/java/org/oxycblt/auxio/playback/NotificationUtils.kt b/app/src/main/java/org/oxycblt/auxio/playback/NotificationUtils.kt index 03ccb1ece..274a04e28 100644 --- a/app/src/main/java/org/oxycblt/auxio/playback/NotificationUtils.kt +++ b/app/src/main/java/org/oxycblt/auxio/playback/NotificationUtils.kt @@ -8,6 +8,7 @@ import android.content.Context import android.content.Intent import android.os.Build import android.support.v4.media.session.MediaSessionCompat +import android.util.Log import androidx.core.app.NotificationCompat import androidx.media.app.NotificationCompat.MediaStyle import org.oxycblt.auxio.MainActivity @@ -26,7 +27,7 @@ object NotificationUtils { const val ACTION_SKIP_PREV = "ACTION_AUXIO_SKIP_PREV" const val ACTION_PLAY_PAUSE = "ACTION_AUXIO_PLAY_PAUSE" const val ACTION_SKIP_NEXT = "ACTION_AUXIO_SKIP_NEXT" - const val ACTION_SHUFFLE = "ACTION_AUXIO_SHUFFLE" + const val ACTION_EXIT = "ACTION_AUXIO_EXIT" } fun NotificationManager.createMediaNotification( @@ -51,7 +52,9 @@ fun NotificationManager.createMediaNotification( PendingIntent.FLAG_UPDATE_CURRENT ) - // TODO: It would be cool if the notification intent took you to the now playing screen. + // TODO: Things that probably aren't possible but would be nice + // - Swipe to close instead of a button to press + // - Playing intent takes you to now playing screen instead of elsewhere return NotificationCompat.Builder(context, NotificationUtils.CHANNEL_ID) .setSmallIcon(R.drawable.ic_song) .setStyle( @@ -67,7 +70,7 @@ fun NotificationManager.createMediaNotification( .addAction(newAction(NotificationUtils.ACTION_SKIP_PREV, context)) .addAction(newAction(NotificationUtils.ACTION_PLAY_PAUSE, context)) .addAction(newAction(NotificationUtils.ACTION_SKIP_NEXT, context)) - .addAction(newAction(NotificationUtils.ACTION_SHUFFLE, context)) + .addAction(newAction(NotificationUtils.ACTION_EXIT, context)) .setSubText(context.getString(R.string.title_playback)) .setContentIntent(mainIntent) .setVisibility(NotificationCompat.VISIBILITY_PUBLIC) @@ -86,19 +89,16 @@ fun NotificationCompat.Builder.setMetadata(song: Song, context: Context, onDone: } } -@SuppressLint("RestrictedApi") -fun NotificationCompat.Builder.updateLoop(context: Context) { - mActions[0] = newAction(NotificationUtils.ACTION_LOOP, context) -} - @SuppressLint("RestrictedApi") fun NotificationCompat.Builder.updatePlaying(context: Context) { mActions[2] = newAction(NotificationUtils.ACTION_PLAY_PAUSE, context) + + setOngoing(PlaybackStateManager.getInstance().isPlaying) } @SuppressLint("RestrictedApi") -fun NotificationCompat.Builder.updateShuffle(context: Context) { - mActions[4] = newAction(NotificationUtils.ACTION_SHUFFLE, context) +fun NotificationCompat.Builder.updateLoop(context: Context) { + mActions[0] = newAction(NotificationUtils.ACTION_LOOP, context) } private fun newAction(action: String, context: Context): NotificationCompat.Action { @@ -113,9 +113,7 @@ private fun newAction(action: String, context: Context): NotificationCompat.Acti } } - NotificationUtils.ACTION_SKIP_PREV -> { - R.drawable.ic_skip_prev - } + NotificationUtils.ACTION_SKIP_PREV -> R.drawable.ic_skip_prev NotificationUtils.ACTION_PLAY_PAUSE -> { if (playbackManager.isPlaying) { @@ -125,18 +123,9 @@ private fun newAction(action: String, context: Context): NotificationCompat.Acti } } - NotificationUtils.ACTION_SKIP_NEXT -> { - R.drawable.ic_skip_next - } - - NotificationUtils.ACTION_SHUFFLE -> { - if (playbackManager.isShuffling) { - R.drawable.ic_shuffle - } else { - R.drawable.ic_shuffle_disabled - } - } + NotificationUtils.ACTION_SKIP_NEXT -> R.drawable.ic_skip_next + NotificationUtils.ACTION_EXIT -> R.drawable.ic_exit else -> R.drawable.ic_play } diff --git a/app/src/main/java/org/oxycblt/auxio/playback/PlaybackService.kt b/app/src/main/java/org/oxycblt/auxio/playback/PlaybackService.kt index 7ad5bd241..5a0054e21 100644 --- a/app/src/main/java/org/oxycblt/auxio/playback/PlaybackService.kt +++ b/app/src/main/java/org/oxycblt/auxio/playback/PlaybackService.kt @@ -9,6 +9,7 @@ import android.content.Intent import android.content.IntentFilter import android.content.pm.ServiceInfo import android.media.AudioManager +import android.os.Binder import android.os.Build import android.os.IBinder import android.os.Parcelable @@ -56,6 +57,7 @@ class PlaybackService : Service(), Player.EventListener, PlaybackStateCallback { private var changeIsFromAudioFocus = true private var isForeground = false + private var isDetachedFromUI = false private val serviceJob = Job() private val serviceScope = CoroutineScope( @@ -70,7 +72,7 @@ class PlaybackService : Service(), Player.EventListener, PlaybackStateCallback { return START_NOT_STICKY } - override fun onBind(intent: Intent): IBinder? = null + override fun onBind(intent: Intent): IBinder? = LocalBinder() override fun onCreate() { super.onCreate() @@ -113,7 +115,7 @@ class PlaybackService : Service(), Player.EventListener, PlaybackStateCallback { addAction(NotificationUtils.ACTION_SKIP_PREV) addAction(NotificationUtils.ACTION_PLAY_PAUSE) addAction(NotificationUtils.ACTION_SKIP_NEXT) - addAction(NotificationUtils.ACTION_SHUFFLE) + addAction(NotificationUtils.ACTION_EXIT) addAction(BluetoothDevice.ACTION_ACL_CONNECTED) addAction(BluetoothDevice.ACTION_ACL_DISCONNECTED) @@ -229,19 +231,11 @@ class PlaybackService : Service(), Player.EventListener, PlaybackStateCallback { startPollingPosition() } else { player.pause() - notification.updatePlaying(this) startForegroundOrNotify() } } - override fun onShuffleUpdate(isShuffling: Boolean) { - changeIsFromAudioFocus = false - - notification.updateShuffle(this) - startForegroundOrNotify() - } - override fun onLoopUpdate(mode: LoopMode) { changeIsFromAudioFocus = false @@ -390,8 +384,7 @@ class PlaybackService : Service(), Player.EventListener, PlaybackStateCallback { NotificationUtils.ACTION_PLAY_PAUSE -> playbackManager.setPlayingStatus(!playbackManager.isPlaying) NotificationUtils.ACTION_SKIP_NEXT -> playbackManager.next() - NotificationUtils.ACTION_SHUFFLE -> - playbackManager.setShuffleStatus(!playbackManager.isShuffling) + NotificationUtils.ACTION_EXIT -> stop() BluetoothDevice.ACTION_ACL_CONNECTED -> resume() BluetoothDevice.ACTION_ACL_DISCONNECTED -> pause() @@ -430,6 +423,15 @@ class PlaybackService : Service(), Player.EventListener, PlaybackStateCallback { playbackManager.setPlayingStatus(false) } } + + private fun stop() { + playbackManager.setPlayingStatus(false) + stopForegroundAndNotification() + } + } + + inner class LocalBinder : Binder() { + fun getService() = this@PlaybackService } companion object { diff --git a/app/src/main/res/drawable-v24/ic_launcher_foreground.xml b/app/src/main/res/drawable-v24/ic_launcher_foreground.xml index cc988a0ab..14c8a9d96 100644 --- a/app/src/main/res/drawable-v24/ic_launcher_foreground.xml +++ b/app/src/main/res/drawable-v24/ic_launcher_foreground.xml @@ -4,24 +4,29 @@ android:height="108dp" android:viewportWidth="108" android:viewportHeight="108"> - - - - - - - - - + + + + + + + + + + + \ No newline at end of file diff --git a/app/src/main/res/drawable/ic_exit.xml b/app/src/main/res/drawable/ic_exit.xml new file mode 100644 index 000000000..575ae7453 --- /dev/null +++ b/app/src/main/res/drawable/ic_exit.xml @@ -0,0 +1,10 @@ + + + + \ No newline at end of file diff --git a/app/src/main/res/mipmap-anydpi-v26/ic_launcher.xml b/app/src/main/res/mipmap-anydpi-v26/ic_launcher.xml index eca70cfe5..bbd3e0212 100644 --- a/app/src/main/res/mipmap-anydpi-v26/ic_launcher.xml +++ b/app/src/main/res/mipmap-anydpi-v26/ic_launcher.xml @@ -1,5 +1,5 @@ - - + + \ No newline at end of file diff --git a/app/src/main/res/mipmap-anydpi-v26/ic_launcher_round.xml b/app/src/main/res/mipmap-anydpi-v26/ic_launcher_round.xml index eca70cfe5..bbd3e0212 100644 --- a/app/src/main/res/mipmap-anydpi-v26/ic_launcher_round.xml +++ b/app/src/main/res/mipmap-anydpi-v26/ic_launcher_round.xml @@ -1,5 +1,5 @@ - - + + \ No newline at end of file diff --git a/app/src/main/res/mipmap-hdpi/ic_launcher.png b/app/src/main/res/mipmap-hdpi/ic_launcher.png index a571e6009..d07640d08 100644 Binary files a/app/src/main/res/mipmap-hdpi/ic_launcher.png and b/app/src/main/res/mipmap-hdpi/ic_launcher.png differ diff --git a/app/src/main/res/mipmap-hdpi/ic_launcher_round.png b/app/src/main/res/mipmap-hdpi/ic_launcher_round.png index 61da551c5..7ecf0eabb 100644 Binary files a/app/src/main/res/mipmap-hdpi/ic_launcher_round.png and b/app/src/main/res/mipmap-hdpi/ic_launcher_round.png differ diff --git a/app/src/main/res/mipmap-mdpi/ic_launcher.png b/app/src/main/res/mipmap-mdpi/ic_launcher.png index c41dd2853..fb5703a76 100644 Binary files a/app/src/main/res/mipmap-mdpi/ic_launcher.png and b/app/src/main/res/mipmap-mdpi/ic_launcher.png differ diff --git a/app/src/main/res/mipmap-mdpi/ic_launcher_round.png b/app/src/main/res/mipmap-mdpi/ic_launcher_round.png index db5080a75..9c942a06c 100644 Binary files a/app/src/main/res/mipmap-mdpi/ic_launcher_round.png and b/app/src/main/res/mipmap-mdpi/ic_launcher_round.png differ diff --git a/app/src/main/res/mipmap-xhdpi/ic_launcher.png b/app/src/main/res/mipmap-xhdpi/ic_launcher.png index 6dba46dab..4d8a5b545 100644 Binary files a/app/src/main/res/mipmap-xhdpi/ic_launcher.png and b/app/src/main/res/mipmap-xhdpi/ic_launcher.png differ diff --git a/app/src/main/res/mipmap-xhdpi/ic_launcher_round.png b/app/src/main/res/mipmap-xhdpi/ic_launcher_round.png index da31a871c..6c18cc6a7 100644 Binary files a/app/src/main/res/mipmap-xhdpi/ic_launcher_round.png and b/app/src/main/res/mipmap-xhdpi/ic_launcher_round.png differ diff --git a/app/src/main/res/mipmap-xxhdpi/ic_launcher.png b/app/src/main/res/mipmap-xxhdpi/ic_launcher.png index 15ac68172..cafee3b15 100644 Binary files a/app/src/main/res/mipmap-xxhdpi/ic_launcher.png and b/app/src/main/res/mipmap-xxhdpi/ic_launcher.png differ diff --git a/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png b/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png index b216f2d31..9a282aa0e 100644 Binary files a/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png and b/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png differ diff --git a/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png b/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png index f25a41974..ee0348a4e 100644 Binary files a/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png and b/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png differ diff --git a/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png b/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png index e96783ccc..657c8b3be 100644 Binary files a/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png and b/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png differ