Added 0-5 keyboard shortcuts for rating tracks in the overlay.

This commit is contained in:
casey langen 2020-01-08 12:27:10 -08:00
parent 46a4c97656
commit c1320847c5
2 changed files with 27 additions and 11 deletions

View File

@ -101,16 +101,32 @@ void TrackOverlays::ShowRateTrackOverlay(
}
auto dialog = std::make_shared<ListOverlay>();
auto updateRatingInLibrary = [track, library, callback, dialog](int index) {
auto query = std::make_shared<SetTrackRatingQuery>(track->GetId(), (int) index);
library->Enqueue(query, ILibrary::QuerySynchronous);
dialog->Dismiss();
callback(true);
};
dialog->SetAdapter(adapter)
.SetTitle(_TSTR("track_list_rate_track_overlay_title"))
.SetWidth(_DIMEN("track_list_rate_track_width", kDefaultRatingOverlayWidth))
.SetSelectedIndex((int) currentRating)
.SetKeyInterceptorCallback(
[updateRatingInLibrary](ListOverlay* overlay, std::string key) -> bool {
if (key == "0") { updateRatingInLibrary(0); return true; }
if (key == "1") { updateRatingInLibrary(1); return true; }
if (key == "2") { updateRatingInLibrary(2); return true; }
if (key == "3") { updateRatingInLibrary(3); return true; }
if (key == "4") { updateRatingInLibrary(4); return true; }
if (key == "5") { updateRatingInLibrary(5); return true; }
return false;
})
.SetItemSelectedCallback(
[track, library, callback]
[updateRatingInLibrary]
(ListOverlay* overlay, IScrollAdapterPtr adapter, size_t index) {
auto query = std::make_shared<SetTrackRatingQuery>(track->GetId(), (int) index);
library->Enqueue(query, ILibrary::QuerySynchronous);
callback(true);
updateRatingInLibrary((int) index);
});
cursespp::App::Overlays().Push(dialog);

View File

@ -83,6 +83,13 @@ namespace cursespp {
return focus;
}
void Dismiss() {
if (this->stack) {
stack->Remove(this);
this->OnDismissed();
}
}
protected:
static void style(TextLabel& label) {
label.SetContentColor(Color::OverlayContent);
@ -119,13 +126,6 @@ namespace cursespp {
return this->stack;
}
void Dismiss() {
if (this->stack) {
stack->Remove(this);
this->OnDismissed();
}
}
virtual void OnDismissed() {
/* for subclass use */
}