add translations for playlist add toast
This commit is contained in:
@@ -11,6 +11,7 @@ import (
|
||||
"net/url"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"strconv"
|
||||
"sync"
|
||||
"time"
|
||||
|
||||
@@ -304,14 +305,18 @@ func (m *Controller) DoAddTracksToPlaylistWorkflow(trackIDs []string) {
|
||||
m.doModalClosed()
|
||||
})
|
||||
sp.SetOnNavigateTo(func(contentType mediaprovider.ContentType, id string) {
|
||||
notifySuccess := func(n int) {
|
||||
msg := lang.LocalizePluralKey("playlist.addedtracks",
|
||||
"Added tracks to playlist", n, map[string]string{"trackCount": strconv.Itoa(n)})
|
||||
m.ToastProvider.ShowSuccessToast(msg)
|
||||
}
|
||||
pop.Hide()
|
||||
m.App.Config.Application.AddToPlaylistSkipDuplicates = sp.SkipDuplicates
|
||||
if id == "" /* creating new playlist */ {
|
||||
go func() {
|
||||
err := m.App.ServerManager.Server.CreatePlaylist(sp.SearchDialog.SearchQuery(), trackIDs)
|
||||
if err == nil {
|
||||
// TODO: translate, adjust by plurality
|
||||
m.ToastProvider.ShowSuccessToast(fmt.Sprintf("Added %d tracks to playlist", len(trackIDs)))
|
||||
notifySuccess(len(trackIDs))
|
||||
}
|
||||
}()
|
||||
} else {
|
||||
@@ -331,8 +336,7 @@ func (m *Controller) DoAddTracksToPlaylistWorkflow(trackIDs []string) {
|
||||
})
|
||||
err := m.App.ServerManager.Server.AddPlaylistTracks(id, filterTrackIDs)
|
||||
if err == nil {
|
||||
// TODO: translate, adjust by plurality
|
||||
m.ToastProvider.ShowSuccessToast(fmt.Sprintf("Added %d tracks to playlist", len(filterTrackIDs)))
|
||||
notifySuccess(len(filterTrackIDs))
|
||||
}
|
||||
}
|
||||
}()
|
||||
@@ -340,8 +344,7 @@ func (m *Controller) DoAddTracksToPlaylistWorkflow(trackIDs []string) {
|
||||
go func() {
|
||||
err := m.App.ServerManager.Server.AddPlaylistTracks(id, trackIDs)
|
||||
if err == nil {
|
||||
// TODO: translate, adjust by plurality
|
||||
m.ToastProvider.ShowSuccessToast(fmt.Sprintf("Added %d tracks to playlist", len(trackIDs)))
|
||||
notifySuccess(len(trackIDs))
|
||||
}
|
||||
}()
|
||||
}
|
||||
|
||||
+8
-3
@@ -16,6 +16,11 @@ import (
|
||||
"github.com/dweymouth/supersonic/ui/widgets"
|
||||
)
|
||||
|
||||
const (
|
||||
toastAutoDismissalTime = 3 * time.Second
|
||||
toastAnimationDuration = 100 * time.Millisecond
|
||||
)
|
||||
|
||||
type ToastOverlay struct {
|
||||
widget.BaseWidget
|
||||
|
||||
@@ -46,7 +51,7 @@ func (t *ToastOverlay) ShowSuccessToast(message string) {
|
||||
endPos := fyne.NewPos(s.Width-min.Width-pad, s.Height-min.Height-pad)
|
||||
startPos := fyne.NewPos(s.Width, endPos.Y)
|
||||
f := t.makeToastAnimFunc(endPos, false)
|
||||
t.currentToastAnim = canvas.NewPositionAnimation(startPos, endPos, 100*time.Millisecond, f)
|
||||
t.currentToastAnim = canvas.NewPositionAnimation(startPos, endPos, toastAnimationDuration, f)
|
||||
t.currentToastAnim.Curve = fyne.AnimationEaseOut
|
||||
t.currentToastAnim.Start()
|
||||
t.Refresh()
|
||||
@@ -54,7 +59,7 @@ func (t *ToastOverlay) ShowSuccessToast(message string) {
|
||||
ctx, cancel := context.WithCancel(context.Background())
|
||||
t.dismissCancel = cancel // always canceled by dismissToast
|
||||
go func() {
|
||||
time.Sleep(2 * time.Second)
|
||||
time.Sleep(toastAutoDismissalTime)
|
||||
select {
|
||||
case <-ctx.Done():
|
||||
return
|
||||
@@ -120,7 +125,7 @@ func (t *ToastOverlay) dismissToast() {
|
||||
startPos := fyne.NewPos(s.Width-min.Width-pad, s.Height-min.Height-pad)
|
||||
endPos := fyne.NewPos(s.Width, startPos.Y)
|
||||
f := t.makeToastAnimFunc(endPos, true)
|
||||
t.currentToastAnim = canvas.NewPositionAnimation(startPos, endPos, 100*time.Millisecond, f)
|
||||
t.currentToastAnim = canvas.NewPositionAnimation(startPos, endPos, toastAnimationDuration, f)
|
||||
t.currentToastAnim.Curve = fyne.AnimationEaseIn
|
||||
t.currentToastAnim.Start()
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user