add a list with all the playlists and then filter by the search text
This commit is contained in:
@@ -347,6 +347,7 @@ func (m *Controller) DoAddTracksToPlaylistWorkflow(trackIDs []string) {
|
||||
min := sp.MinSize()
|
||||
height := fyne.Max(min.Height, fyne.Min(min.Height*1.5, m.MainWindow.Canvas().Size().Height*0.7))
|
||||
pop.Resize(fyne.NewSize(min.Width, height))
|
||||
sp.SearchDialog.Show()
|
||||
pop.Show()
|
||||
m.MainWindow.Canvas().Focus(sp.GetSearchEntry())
|
||||
}
|
||||
|
||||
@@ -27,6 +27,7 @@ func NewQuickSearch(mp mediaprovider.MediaProvider, im util.ImageFetcher) *Quick
|
||||
"Quick Search",
|
||||
q.onSearched,
|
||||
q.onUpdateSearchResult,
|
||||
nil,
|
||||
)
|
||||
q.SearchDialog = sd
|
||||
return q
|
||||
|
||||
+38
-13
@@ -39,14 +39,16 @@ type SearchDialog struct {
|
||||
OnNavigateTo func(mediaprovider.ContentType, string, string)
|
||||
OnSearched func(string) []*mediaprovider.SearchResult
|
||||
OnUpdateSearchResults func(*searchResult, *mediaprovider.SearchResult)
|
||||
OnInit func() []*mediaprovider.SearchResult
|
||||
}
|
||||
|
||||
func NewSearchDialog(im util.ImageFetcher, placeholderTitle string, onSearched func(string) []*mediaprovider.SearchResult, onUpdateSearchResult func(*searchResult, *mediaprovider.SearchResult)) *SearchDialog {
|
||||
func NewSearchDialog(im util.ImageFetcher, placeholderTitle string, onSearched func(string) []*mediaprovider.SearchResult, onUpdateSearchResult func(*searchResult, *mediaprovider.SearchResult), onInit func() []*mediaprovider.SearchResult) *SearchDialog {
|
||||
sd := &SearchDialog{
|
||||
imgSource: im,
|
||||
loadingDots: widgets.NewLoadingDots(),
|
||||
OnSearched: onSearched,
|
||||
OnUpdateSearchResults: onUpdateSearchResult,
|
||||
OnInit: onInit,
|
||||
}
|
||||
sd.ExtendBaseWidget(sd)
|
||||
|
||||
@@ -92,6 +94,11 @@ func NewSearchDialog(im util.ImageFetcher, placeholderTitle string, onSearched f
|
||||
return sd
|
||||
}
|
||||
|
||||
func (sd *SearchDialog) Show() {
|
||||
sd.onInit()
|
||||
sd.BaseWidget.Show()
|
||||
}
|
||||
|
||||
func (sd *SearchDialog) onDismiss() {
|
||||
if sd.OnDismiss != nil {
|
||||
sd.OnDismiss()
|
||||
@@ -132,18 +139,7 @@ func (sd *SearchDialog) moveSelectionUp() {
|
||||
sd.list.Select(sd.selectedIndex)
|
||||
}
|
||||
|
||||
func (sd *SearchDialog) onSearched(query string) {
|
||||
sd.loadingDots.Start()
|
||||
var results []*mediaprovider.SearchResult
|
||||
if query != "" {
|
||||
res := sd.OnSearched(query)
|
||||
if len(res) == 0 {
|
||||
log.Println("No results matched the query.")
|
||||
} else {
|
||||
results = res
|
||||
}
|
||||
}
|
||||
sd.loadingDots.Stop()
|
||||
func (sd *SearchDialog) setResults(results []*mediaprovider.SearchResult) {
|
||||
sd.resultsMutex.Lock()
|
||||
sd.searchResults = results
|
||||
sd.resultsMutex.Unlock()
|
||||
@@ -153,6 +149,35 @@ func (sd *SearchDialog) onSearched(query string) {
|
||||
sd.list.Select(0)
|
||||
}
|
||||
|
||||
func (sd *SearchDialog) onInit() {
|
||||
if sd.OnInit == nil {
|
||||
return
|
||||
}
|
||||
sd.loadingDots.Start()
|
||||
var results []*mediaprovider.SearchResult
|
||||
res := sd.OnInit()
|
||||
if len(res) == 0 {
|
||||
log.Println("No results")
|
||||
} else {
|
||||
results = res
|
||||
}
|
||||
sd.loadingDots.Stop()
|
||||
sd.setResults(results)
|
||||
}
|
||||
|
||||
func (sd *SearchDialog) onSearched(query string) {
|
||||
sd.loadingDots.Start()
|
||||
var results []*mediaprovider.SearchResult
|
||||
res := sd.OnSearched(query)
|
||||
if len(res) == 0 {
|
||||
log.Println("No results matched the query.")
|
||||
} else {
|
||||
results = res
|
||||
}
|
||||
sd.loadingDots.Stop()
|
||||
sd.setResults(results)
|
||||
}
|
||||
|
||||
func (sd *SearchDialog) CreateRenderer() fyne.WidgetRenderer {
|
||||
return widget.NewSimpleRenderer(sd.content)
|
||||
}
|
||||
|
||||
@@ -19,6 +19,7 @@ type SelectPlaylist struct {
|
||||
SearchDialog *SearchDialog
|
||||
mp mediaprovider.MediaProvider
|
||||
loggedInUser string
|
||||
allPlaylists []*mediaprovider.Playlist
|
||||
}
|
||||
|
||||
func NewSelectPlaylistDialog(mp mediaprovider.MediaProvider, im util.ImageFetcher, loggedInUser string) *SelectPlaylist {
|
||||
@@ -27,50 +28,69 @@ func NewSelectPlaylistDialog(mp mediaprovider.MediaProvider, im util.ImageFetche
|
||||
mp: mp,
|
||||
loggedInUser: loggedInUser,
|
||||
}
|
||||
|
||||
sd := NewSearchDialog(
|
||||
im,
|
||||
"Select playlist",
|
||||
sp.onSearched,
|
||||
sp.onUpdateSearchResult,
|
||||
sp.onInit,
|
||||
)
|
||||
sp.SearchDialog = sd
|
||||
return sp
|
||||
}
|
||||
|
||||
func (sp *SelectPlaylist) onInit() []*mediaprovider.SearchResult {
|
||||
var results []*mediaprovider.SearchResult
|
||||
playlists, err := sp.mp.GetPlaylists()
|
||||
if err != nil {
|
||||
// TODO: surface this error to user
|
||||
log.Printf("error getting playlists: %s", err.Error())
|
||||
return results
|
||||
}
|
||||
sp.allPlaylists = sharedutil.FilterSlice(playlists, func(playlist *mediaprovider.Playlist) bool {
|
||||
return playlist.Owner == sp.loggedInUser
|
||||
})
|
||||
for _, playlist := range sp.allPlaylists {
|
||||
results = append(results, &mediaprovider.SearchResult{
|
||||
Name: playlist.Name,
|
||||
ID: playlist.ID,
|
||||
CoverID: playlist.CoverArtID,
|
||||
Type: mediaprovider.ContentTypePlaylist,
|
||||
Size: playlist.TrackCount,
|
||||
ArtistName: playlist.Name,
|
||||
})
|
||||
}
|
||||
return results
|
||||
}
|
||||
|
||||
func (sp *SelectPlaylist) onSearched(query string) []*mediaprovider.SearchResult {
|
||||
var results []*mediaprovider.SearchResult
|
||||
if query != "" {
|
||||
var filteredPlaylists []*mediaprovider.Playlist
|
||||
if playlists, err := sp.mp.GetPlaylists(); err != nil {
|
||||
// TODO: surface this error to user
|
||||
log.Printf("error getting playlists: %s", err.Error())
|
||||
return results
|
||||
} else {
|
||||
filteredPlaylists = sharedutil.FilterSlice(playlists, func(playlist *mediaprovider.Playlist) bool {
|
||||
return strings.Contains(
|
||||
sanitize.Accents(strings.ToLower(playlist.Name)),
|
||||
sanitize.Accents(strings.ToLower(query)),
|
||||
) && playlist.Owner == sp.loggedInUser
|
||||
})
|
||||
}
|
||||
|
||||
var filteredPlaylists []*mediaprovider.Playlist
|
||||
if query == "" {
|
||||
filteredPlaylists = sp.allPlaylists
|
||||
} else {
|
||||
filteredPlaylists = sharedutil.FilterSlice(sp.allPlaylists, func(playlist *mediaprovider.Playlist) bool {
|
||||
return strings.Contains(
|
||||
sanitize.Accents(strings.ToLower(playlist.Name)),
|
||||
sanitize.Accents(strings.ToLower(query)),
|
||||
)
|
||||
})
|
||||
results = append(results, &mediaprovider.SearchResult{
|
||||
Name: fmt.Sprintf("Create new playlist: %s", query),
|
||||
Type: mediaprovider.ContentTypePlaylist,
|
||||
Query: query,
|
||||
})
|
||||
for _, playlist := range filteredPlaylists {
|
||||
results = append(results, &mediaprovider.SearchResult{
|
||||
Name: playlist.Name,
|
||||
ID: playlist.ID,
|
||||
CoverID: playlist.CoverArtID,
|
||||
Type: mediaprovider.ContentTypePlaylist,
|
||||
Size: playlist.TrackCount,
|
||||
ArtistName: playlist.Name,
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
for _, playlist := range filteredPlaylists {
|
||||
results = append(results, &mediaprovider.SearchResult{
|
||||
Name: playlist.Name,
|
||||
ID: playlist.ID,
|
||||
CoverID: playlist.CoverArtID,
|
||||
Type: mediaprovider.ContentTypePlaylist,
|
||||
Size: playlist.TrackCount,
|
||||
ArtistName: playlist.Name,
|
||||
})
|
||||
}
|
||||
return results
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user