#15: Enabled "Add to playlist" in the search screen. Localized strings and improved UI.

This commit is contained in:
Antoine POPINEAU 2020-09-04 16:56:31 +02:00
parent 54d4dc2235
commit d796fca26b
No known key found for this signature in database
GPG Key ID: A78AC64694F84063
8 changed files with 29 additions and 7 deletions

View File

@ -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)
}
}
}
}

View File

@ -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) {

View File

@ -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))
}

View File

@ -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()

View File

@ -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" />

View File

@ -11,7 +11,7 @@
<item
android:id="@+id/track_add_to_playlist"
android:title="Add to playlist" />
android:title="@string/playlist_add_to" />
<item
android:id="@+id/track_pin"

View File

@ -113,6 +113,9 @@
<item quantity="one">%1$d piste • %2$s</item>
<item quantity="other">%1$d pistes • %2$s</item>
</plurals>
<string name="playlist_add_to">Ajouter à une playlist</string>
<string name="playlist_add_to_new">Nouvelle playlist...</string>
<string name="playlist_add_to_create">Créer playlist</string>
<string name="filters">Filtres</string>
<string name="fiters_all">Toute la musique</string>
<string name="filters_my_music">Ma musique</string>

View File

@ -114,6 +114,9 @@
<item quantity="one">%1$d track • %2$s"</item>
<item quantity="other">%1$d tracks • %2$s"</item>
</plurals>
<string name="playlist_add_to">Add to playlist</string>
<string name="playlist_add_to_new">New playlist…</string>
<string name="playlist_add_to_create">Create playlist</string>
<string name="filters">Filters</string>
<string name="fiters_all">All music</string>
<string name="filters_my_music">My music</string>