Add toast when added to playlist.

This commit is contained in:
Antoine POPINEAU 2020-09-06 15:15:33 +02:00
parent ab654a08c4
commit b0747658ae
No known key found for this signature in database
GPG Key ID: A78AC64694F84063
3 changed files with 14 additions and 1 deletions

View File

@ -3,6 +3,7 @@ package com.github.apognu.otter.fragments
import android.app.Activity
import android.app.AlertDialog
import android.view.View
import android.widget.Toast
import androidx.core.widget.addTextChangedListener
import androidx.recyclerview.widget.LinearLayoutManager
import com.github.apognu.otter.R
@ -13,7 +14,9 @@ import com.google.gson.Gson
import kotlinx.android.synthetic.main.dialog_add_to_playlist.*
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Dispatchers.IO
import kotlinx.coroutines.Dispatchers.Main
import kotlinx.coroutines.launch
import kotlinx.coroutines.withContext
object AddToPlaylistDialog {
fun show(activity: Activity, lifecycleScope: CoroutineScope, track: Track) {
@ -40,6 +43,11 @@ object AddToPlaylistDialog {
lifecycleScope.launch(IO) {
repository.new(name)?.let { id ->
repository.add(id, track)
withContext(Main) {
Toast.makeText(activity, activity.getString(R.string.playlist_added_to, name), Toast.LENGTH_SHORT).show()
}
dialog.dismiss()
}
}
@ -48,6 +56,9 @@ object AddToPlaylistDialog {
val adapter = PlaylistsAdapter(activity, object : PlaylistsAdapter.OnPlaylistClickListener {
override fun onClick(holder: View?, playlist: Playlist) {
repository.add(playlist.id, track)
Toast.makeText(activity, activity.getString(R.string.playlist_added_to, playlist.name), Toast.LENGTH_SHORT).show()
dialog.dismiss()
}
})

View File

@ -114,8 +114,9 @@
<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_new">Nouvelle playlist</string>
<string name="playlist_add_to_create">Créer playlist</string>
<string name="playlist_added_to">Ajouté à la playlist %s</string>
<string name="filters">Filtres</string>
<string name="fiters_all">Toute la musique</string>
<string name="filters_my_music">Ma musique</string>

View File

@ -117,6 +117,7 @@
<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="playlist_added_to">Added to playlist %s</string>
<string name="filters">Filters</string>
<string name="fiters_all">All music</string>
<string name="filters_my_music">My music</string>