From d796fca26bb7673fd16d374a7de6f86ad2b0b6ad Mon Sep 17 00:00:00 2001 From: Antoine POPINEAU Date: Fri, 4 Sep 2020 16:56:31 +0200 Subject: [PATCH] #15: Enabled "Add to playlist" in the search screen. Localized strings and improved UI. --- .../github/apognu/otter/activities/MainActivity.kt | 5 ++++- .../github/apognu/otter/activities/SearchActivity.kt | 12 ++++++++++++ .../github/apognu/otter/adapters/SearchAdapter.kt | 1 + .../apognu/otter/fragments/AddToPlaylistDialog.kt | 2 +- app/src/main/res/layout/dialog_add_to_playlist.xml | 8 ++++---- app/src/main/res/menu/row_track.xml | 2 +- app/src/main/res/values-fr/strings.xml | 3 +++ app/src/main/res/values/strings.xml | 3 +++ 8 files changed, 29 insertions(+), 7 deletions(-) diff --git a/app/src/main/java/com/github/apognu/otter/activities/MainActivity.kt b/app/src/main/java/com/github/apognu/otter/activities/MainActivity.kt index 0d30b86..2920388 100644 --- a/app/src/main/java/com/github/apognu/otter/activities/MainActivity.kt +++ b/app/src/main/java/com/github/apognu/otter/activities/MainActivity.kt @@ -19,6 +19,7 @@ import androidx.core.graphics.drawable.toDrawable import androidx.fragment.app.DialogFragment import androidx.fragment.app.Fragment import androidx.fragment.app.FragmentManager +import androidx.lifecycle.Lifecycle import androidx.lifecycle.lifecycleScope import com.github.apognu.otter.Otter import com.github.apognu.otter.R @@ -380,7 +381,9 @@ class MainActivity : AppCompatActivity() { is Command.RefreshTrack -> refreshCurrentTrack(command.track) - is Command.AddToPlaylist -> AddToPlaylistDialog.show(this@MainActivity, lifecycleScope, command.track) + is Command.AddToPlaylist -> if (lifecycle.currentState.isAtLeast(Lifecycle.State.RESUMED)) { + AddToPlaylistDialog.show(this@MainActivity, lifecycleScope, command.track) + } } } } diff --git a/app/src/main/java/com/github/apognu/otter/activities/SearchActivity.kt b/app/src/main/java/com/github/apognu/otter/activities/SearchActivity.kt index bd08f2a..d2aa09b 100644 --- a/app/src/main/java/com/github/apognu/otter/activities/SearchActivity.kt +++ b/app/src/main/java/com/github/apognu/otter/activities/SearchActivity.kt @@ -3,10 +3,12 @@ package com.github.apognu.otter.activities import android.os.Bundle import android.view.View import androidx.appcompat.app.AppCompatActivity +import androidx.lifecycle.Lifecycle import androidx.lifecycle.lifecycleScope import androidx.recyclerview.widget.LinearLayoutManager import com.github.apognu.otter.R import com.github.apognu.otter.adapters.SearchAdapter +import com.github.apognu.otter.fragments.AddToPlaylistDialog import com.github.apognu.otter.fragments.AlbumsFragment import com.github.apognu.otter.fragments.ArtistsFragment import com.github.apognu.otter.repositories.* @@ -47,6 +49,16 @@ class SearchActivity : AppCompatActivity() { override fun onResume() { super.onResume() + lifecycleScope.launch(Dispatchers.Main) { + CommandBus.get().collect { command -> + when (command) { + is Command.AddToPlaylist -> if (lifecycle.currentState.isAtLeast(Lifecycle.State.RESUMED)) { + AddToPlaylistDialog.show(this@SearchActivity, lifecycleScope, command.track) + } + } + } + } + lifecycleScope.launch(Dispatchers.IO) { EventBus.get().collect { message -> when (message) { diff --git a/app/src/main/java/com/github/apognu/otter/adapters/SearchAdapter.kt b/app/src/main/java/com/github/apognu/otter/adapters/SearchAdapter.kt index f146750..d81c5fe 100644 --- a/app/src/main/java/com/github/apognu/otter/adapters/SearchAdapter.kt +++ b/app/src/main/java/com/github/apognu/otter/adapters/SearchAdapter.kt @@ -215,6 +215,7 @@ class SearchAdapter(private val context: Context?, private val listener: OnSearc R.id.track_add_to_queue -> CommandBus.send(Command.AddToQueue(listOf(track))) R.id.track_play_next -> CommandBus.send(Command.PlayNext(track)) R.id.track_pin -> CommandBus.send(Command.PinTrack(track)) + R.id.track_add_to_playlist -> CommandBus.send(Command.AddToPlaylist(track)) R.id.queue_remove -> CommandBus.send(Command.RemoveFromQueue(track)) } diff --git a/app/src/main/java/com/github/apognu/otter/fragments/AddToPlaylistDialog.kt b/app/src/main/java/com/github/apognu/otter/fragments/AddToPlaylistDialog.kt index f22a500..f4fd71d 100644 --- a/app/src/main/java/com/github/apognu/otter/fragments/AddToPlaylistDialog.kt +++ b/app/src/main/java/com/github/apognu/otter/fragments/AddToPlaylistDialog.kt @@ -18,7 +18,7 @@ import kotlinx.coroutines.launch object AddToPlaylistDialog { fun show(activity: Activity, lifecycleScope: CoroutineScope, track: Track) { val dialog = AlertDialog.Builder(activity).run { - setTitle("Add track to playlist") + setTitle(activity.getString(R.string.playlist_add_to)) setView(activity.layoutInflater.inflate(R.layout.dialog_add_to_playlist, null)) create() diff --git a/app/src/main/res/layout/dialog_add_to_playlist.xml b/app/src/main/res/layout/dialog_add_to_playlist.xml index 7ce7296..43e28af 100644 --- a/app/src/main/res/layout/dialog_add_to_playlist.xml +++ b/app/src/main/res/layout/dialog_add_to_playlist.xml @@ -11,9 +11,9 @@ style="@style/Widget.MaterialComponents.TextInputLayout.OutlinedBox" android:layout_width="match_parent" android:layout_height="wrap_content" - android:layout_marginHorizontal="8dp" + android:layout_marginHorizontal="16dp" android:layout_marginTop="16dp" - android:hint="New playlist..." + android:hint="@string/playlist_add_to_new" app:boxStrokeColor="@color/controlForeground" app:hintTextColor="@color/controlForeground" app:placeholderTextColor="@color/controlForeground"> @@ -30,9 +30,9 @@ android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_gravity="end" - android:layout_marginHorizontal="8dp" + android:layout_marginHorizontal="16dp" android:enabled="false" - android:text="Create playlist" + android:text="@string/playlist_add_to_create" android:textColor="@color/controlForeground" app:rippleColor="@color/ripple" /> diff --git a/app/src/main/res/menu/row_track.xml b/app/src/main/res/menu/row_track.xml index 86f9895..7866c59 100644 --- a/app/src/main/res/menu/row_track.xml +++ b/app/src/main/res/menu/row_track.xml @@ -11,7 +11,7 @@ + android:title="@string/playlist_add_to" /> %1$d piste • %2$s %1$d pistes • %2$s + Ajouter à une playlist + Nouvelle playlist... + Créer playlist Filtres Toute la musique Ma musique diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 52c4ded..93d8c6a 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -114,6 +114,9 @@ %1$d track • %2$s" %1$d tracks • %2$s" + Add to playlist + New playlist… + Create playlist Filters All music My music