From b0747658aecc566ac1d0899886966a92791f628f Mon Sep 17 00:00:00 2001 From: Antoine POPINEAU Date: Sun, 6 Sep 2020 15:15:33 +0200 Subject: [PATCH] Add toast when added to playlist. --- .../apognu/otter/fragments/AddToPlaylistDialog.kt | 11 +++++++++++ app/src/main/res/values-fr/strings.xml | 3 ++- app/src/main/res/values/strings.xml | 1 + 3 files changed, 14 insertions(+), 1 deletion(-) 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 f4fd71d..3bd43e8 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 @@ -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() } }) diff --git a/app/src/main/res/values-fr/strings.xml b/app/src/main/res/values-fr/strings.xml index 2408b7c..96db926 100644 --- a/app/src/main/res/values-fr/strings.xml +++ b/app/src/main/res/values-fr/strings.xml @@ -114,8 +114,9 @@ %1$d pistes • %2$s Ajouter à une playlist - Nouvelle playlist... + Nouvelle playlist… Créer playlist + Ajouté à la playlist %s 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 93d8c6a..ebd295e 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -117,6 +117,7 @@ Add to playlist New playlist… Create playlist + Added to playlist %s Filters All music My music