Extract matches
This commit is contained in:
parent
38ad041cec
commit
2c8754ce46
@ -3,6 +3,8 @@ use musichoard::collection::{
|
|||||||
track::{TrackFormat, TrackQuality},
|
track::{TrackFormat, TrackQuality},
|
||||||
};
|
};
|
||||||
|
|
||||||
|
use crate::tui::lib::interface::musicbrainz::Match;
|
||||||
|
|
||||||
pub struct UiDisplay;
|
pub struct UiDisplay;
|
||||||
|
|
||||||
impl UiDisplay {
|
impl UiDisplay {
|
||||||
@ -88,6 +90,13 @@ impl UiDisplay {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn display_track_quality(quality: &TrackQuality) -> String {
|
||||||
|
match quality.format {
|
||||||
|
TrackFormat::Flac => "FLAC".to_string(),
|
||||||
|
TrackFormat::Mp3 => format!("MP3 {}kbps", quality.bitrate),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
pub fn display_matching_info(matching: Option<&Album>) -> String {
|
pub fn display_matching_info(matching: Option<&Album>) -> String {
|
||||||
match matching {
|
match matching {
|
||||||
Some(matching) => format!(
|
Some(matching) => format!(
|
||||||
@ -99,11 +108,17 @@ impl UiDisplay {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn display_track_quality(quality: &TrackQuality) -> String {
|
pub fn display_match_string(match_album: &Match<Album>) -> String {
|
||||||
match quality.format {
|
format!(
|
||||||
TrackFormat::Flac => "FLAC".to_string(),
|
"{:010} | {} [{}] ({}%)",
|
||||||
TrackFormat::Mp3 => format!("MP3 {}kbps", quality.bitrate),
|
UiDisplay::display_album_date(&match_album.item.date),
|
||||||
}
|
&match_album.item.id.title,
|
||||||
|
UiDisplay::display_type(
|
||||||
|
&match_album.item.primary_type,
|
||||||
|
&match_album.item.secondary_types
|
||||||
|
),
|
||||||
|
match_album.score,
|
||||||
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
23
src/tui/ui/matches.rs
Normal file
23
src/tui/ui/matches.rs
Normal file
@ -0,0 +1,23 @@
|
|||||||
|
use musichoard::collection::album::Album;
|
||||||
|
use ratatui::widgets::{List, ListItem};
|
||||||
|
|
||||||
|
use crate::tui::{lib::interface::musicbrainz::Match, ui::display::UiDisplay};
|
||||||
|
|
||||||
|
#[derive(Default)]
|
||||||
|
pub struct AlbumMatchesState<'a> {
|
||||||
|
pub list: List<'a>,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl<'a> AlbumMatchesState<'a> {
|
||||||
|
pub fn new(matches: &[Match<Album>]) -> Self {
|
||||||
|
let list = List::new(
|
||||||
|
matches
|
||||||
|
.iter()
|
||||||
|
.map(UiDisplay::display_match_string)
|
||||||
|
.map(ListItem::new)
|
||||||
|
.collect::<Vec<ListItem>>(),
|
||||||
|
);
|
||||||
|
|
||||||
|
AlbumMatchesState { list }
|
||||||
|
}
|
||||||
|
}
|
@ -1,6 +1,7 @@
|
|||||||
mod browse;
|
mod browse;
|
||||||
mod display;
|
mod display;
|
||||||
mod info;
|
mod info;
|
||||||
|
mod matches;
|
||||||
mod minibuffer;
|
mod minibuffer;
|
||||||
mod overlay;
|
mod overlay;
|
||||||
mod reload;
|
mod reload;
|
||||||
@ -8,13 +9,14 @@ mod reload;
|
|||||||
use browse::{AlbumArea, AlbumState, ArtistArea, ArtistState, FrameArea, TrackArea, TrackState};
|
use browse::{AlbumArea, AlbumState, ArtistArea, ArtistState, FrameArea, TrackArea, TrackState};
|
||||||
use display::UiDisplay;
|
use display::UiDisplay;
|
||||||
use info::{AlbumOverlay, ArtistOverlay};
|
use info::{AlbumOverlay, ArtistOverlay};
|
||||||
|
use matches::AlbumMatchesState;
|
||||||
use minibuffer::Minibuffer;
|
use minibuffer::Minibuffer;
|
||||||
use musichoard::collection::{album::Album, track::Track, Collection};
|
use musichoard::collection::{album::Album, track::Track, Collection};
|
||||||
use overlay::{OverlayBuilder, OverlaySize};
|
use overlay::{OverlayBuilder, OverlaySize};
|
||||||
use ratatui::{
|
use ratatui::{
|
||||||
layout::{Alignment, Rect},
|
layout::{Alignment, Rect},
|
||||||
style::{Color, Style},
|
style::{Color, Style},
|
||||||
widgets::{Block, BorderType, Borders, Clear, List, ListItem, Paragraph, Wrap},
|
widgets::{Block, BorderType, Borders, Clear, List, Paragraph, Wrap},
|
||||||
Frame,
|
Frame,
|
||||||
};
|
};
|
||||||
use reload::ReloadMenu;
|
use reload::ReloadMenu;
|
||||||
@ -283,29 +285,6 @@ impl Ui {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn display_match_string(match_album: &Match<Album>) -> String {
|
|
||||||
format!(
|
|
||||||
"{:010} | {} [{}] ({}%)",
|
|
||||||
UiDisplay::display_album_date(&match_album.item.date),
|
|
||||||
&match_album.item.id.title,
|
|
||||||
UiDisplay::display_type(
|
|
||||||
&match_album.item.primary_type,
|
|
||||||
&match_album.item.secondary_types
|
|
||||||
),
|
|
||||||
match_album.score,
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
fn build_match_list(matches: &[Match<Album>]) -> List {
|
|
||||||
List::new(
|
|
||||||
matches
|
|
||||||
.iter()
|
|
||||||
.map(Ui::display_match_string)
|
|
||||||
.map(ListItem::new)
|
|
||||||
.collect::<Vec<ListItem>>(),
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
fn render_matches_overlay(
|
fn render_matches_overlay(
|
||||||
matching: Option<&Album>,
|
matching: Option<&Album>,
|
||||||
matches: Option<&[Match<Album>]>,
|
matches: Option<&[Match<Album>]>,
|
||||||
@ -314,8 +293,8 @@ impl Ui {
|
|||||||
) {
|
) {
|
||||||
let area = OverlayBuilder::default().build(frame.size());
|
let area = OverlayBuilder::default().build(frame.size());
|
||||||
let matching_string = UiDisplay::display_matching_info(matching);
|
let matching_string = UiDisplay::display_matching_info(matching);
|
||||||
let list = matches.map(|m| Ui::build_match_list(m)).unwrap_or_default();
|
let st = matches.map(AlbumMatchesState::new).unwrap_or_default();
|
||||||
Self::render_overlay_list_widget(&matching_string, list, state, true, area, frame)
|
Self::render_overlay_list_widget(&matching_string, st.list, state, true, area, frame)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn render_reload_overlay(frame: &mut Frame) {
|
fn render_reload_overlay(frame: &mut Frame) {
|
||||||
|
Loading…
Reference in New Issue
Block a user