add 'Skip duplicates' option
This commit is contained in:
+33
-15
@@ -33,22 +33,24 @@ type SearchDialog struct {
|
||||
list *widget.List
|
||||
selectedIndex int
|
||||
|
||||
placeholderTitle string
|
||||
content *fyne.Container
|
||||
|
||||
OnDismiss func()
|
||||
OnNavigateTo func(mediaprovider.ContentType, string, string)
|
||||
OnSearched func(string) []*mediaprovider.SearchResult
|
||||
OnUpdateSearchResults func(*searchResult, *mediaprovider.SearchResult)
|
||||
OnInit func() []*mediaprovider.SearchResult
|
||||
OnInit func() ([]*mediaprovider.SearchResult, *widget.Check)
|
||||
}
|
||||
|
||||
func NewSearchDialog(im util.ImageFetcher, placeholderTitle string, onSearched func(string) []*mediaprovider.SearchResult, onUpdateSearchResult func(*searchResult, *mediaprovider.SearchResult), onInit func() []*mediaprovider.SearchResult) *SearchDialog {
|
||||
func NewSearchDialog(im util.ImageFetcher, placeholderTitle string, onSearched func(string) []*mediaprovider.SearchResult, onUpdateSearchResult func(*searchResult, *mediaprovider.SearchResult), onInit func() ([]*mediaprovider.SearchResult, *widget.Check)) *SearchDialog {
|
||||
sd := &SearchDialog{
|
||||
imgSource: im,
|
||||
loadingDots: widgets.NewLoadingDots(),
|
||||
OnSearched: onSearched,
|
||||
OnUpdateSearchResults: onUpdateSearchResult,
|
||||
OnInit: onInit,
|
||||
placeholderTitle: placeholderTitle,
|
||||
}
|
||||
sd.ExtendBaseWidget(sd)
|
||||
|
||||
@@ -80,17 +82,6 @@ func NewSearchDialog(im util.ImageFetcher, placeholderTitle string, onSearched f
|
||||
sd.update(sr, result)
|
||||
},
|
||||
)
|
||||
|
||||
dismissBtn := widget.NewButton("Close", sd.onDismiss)
|
||||
title := widget.NewRichText(&widget.TextSegment{Text: placeholderTitle, Style: util.BoldRichTextStyle})
|
||||
title.Segments[0].(*widget.TextSegment).Style.Alignment = fyne.TextAlignCenter
|
||||
sd.content = container.NewStack(
|
||||
container.NewBorder(
|
||||
container.NewVBox(title, se),
|
||||
container.NewVBox(widget.NewSeparator(), container.NewHBox(layout.NewSpacer(), dismissBtn)),
|
||||
nil, nil, sd.list),
|
||||
container.NewCenter(sd.loadingDots),
|
||||
)
|
||||
return sd
|
||||
}
|
||||
|
||||
@@ -149,20 +140,47 @@ func (sd *SearchDialog) setResults(results []*mediaprovider.SearchResult) {
|
||||
sd.list.Select(0)
|
||||
}
|
||||
|
||||
func (sd *SearchDialog) SetContent(checkBox *widget.Check) {
|
||||
dismissBtn := widget.NewButton("Close", sd.onDismiss)
|
||||
title := widget.NewRichText(&widget.TextSegment{Text:sd.placeholderTitle, Style: util.BoldRichTextStyle})
|
||||
title.Segments[0].(*widget.TextSegment).Style.Alignment = fyne.TextAlignCenter
|
||||
se := sd.SearchEntry.(fyne.CanvasObject)
|
||||
if checkBox != nil {
|
||||
sd.content = container.NewStack(
|
||||
container.NewBorder(
|
||||
container.NewVBox(title, se),
|
||||
container.NewVBox(widget.NewSeparator(), container.NewHBox(checkBox, layout.NewSpacer(), dismissBtn)),
|
||||
nil, nil, sd.list),
|
||||
container.NewCenter(sd.loadingDots),
|
||||
)
|
||||
} else {
|
||||
sd.content = container.NewStack(
|
||||
container.NewBorder(
|
||||
container.NewVBox(title, se),
|
||||
container.NewVBox(widget.NewSeparator(), container.NewHBox(layout.NewSpacer(), dismissBtn)),
|
||||
nil, nil, sd.list),
|
||||
container.NewCenter(sd.loadingDots),
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
func (sd *SearchDialog) onInit() {
|
||||
if sd.OnInit == nil {
|
||||
sd.SetContent(nil)
|
||||
return
|
||||
}
|
||||
sd.loadingDots.Start()
|
||||
var results []*mediaprovider.SearchResult
|
||||
res := sd.OnInit()
|
||||
res, checkBox := sd.OnInit()
|
||||
if len(res) == 0 {
|
||||
log.Println("No results")
|
||||
} else {
|
||||
results = res
|
||||
}
|
||||
sd.SetContent(checkBox)
|
||||
sd.loadingDots.Stop()
|
||||
sd.setResults(results)
|
||||
sd.setResults(results)
|
||||
}
|
||||
|
||||
func (sd *SearchDialog) onSearched(query string) {
|
||||
|
||||
@@ -20,6 +20,7 @@ type SelectPlaylist struct {
|
||||
mp mediaprovider.MediaProvider
|
||||
loggedInUser string
|
||||
allPlaylists []*mediaprovider.Playlist
|
||||
SkipDuplicates bool
|
||||
}
|
||||
|
||||
func NewSelectPlaylistDialog(mp mediaprovider.MediaProvider, im util.ImageFetcher, loggedInUser string) *SelectPlaylist {
|
||||
@@ -27,6 +28,7 @@ func NewSelectPlaylistDialog(mp mediaprovider.MediaProvider, im util.ImageFetche
|
||||
sp := &SelectPlaylist{
|
||||
mp: mp,
|
||||
loggedInUser: loggedInUser,
|
||||
SkipDuplicates: false,
|
||||
}
|
||||
sd := NewSearchDialog(
|
||||
im,
|
||||
@@ -39,13 +41,13 @@ func NewSelectPlaylistDialog(mp mediaprovider.MediaProvider, im util.ImageFetche
|
||||
return sp
|
||||
}
|
||||
|
||||
func (sp *SelectPlaylist) onInit() []*mediaprovider.SearchResult {
|
||||
func (sp *SelectPlaylist) onInit() ([]*mediaprovider.SearchResult, *widget.Check) {
|
||||
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
|
||||
return results, nil
|
||||
}
|
||||
sp.allPlaylists = sharedutil.FilterSlice(playlists, func(playlist *mediaprovider.Playlist) bool {
|
||||
return playlist.Owner == sp.loggedInUser
|
||||
@@ -60,7 +62,10 @@ func (sp *SelectPlaylist) onInit() []*mediaprovider.SearchResult {
|
||||
ArtistName: playlist.Name,
|
||||
})
|
||||
}
|
||||
return results
|
||||
skipDuplicatesCheck := widget.NewCheck("Skip duplicates", func(checked bool) {
|
||||
sp.SkipDuplicates = checked
|
||||
})
|
||||
return results, skipDuplicatesCheck
|
||||
}
|
||||
|
||||
func (sp *SelectPlaylist) onSearched(query string) []*mediaprovider.SearchResult {
|
||||
|
||||
Reference in New Issue
Block a user