Extract matches
This commit is contained in:
parent
38ad041cec
commit
2c8754ce46
@ -3,6 +3,8 @@ use musichoard::collection::{
|
||||
track::{TrackFormat, TrackQuality},
|
||||
};
|
||||
|
||||
use crate::tui::lib::interface::musicbrainz::Match;
|
||||
|
||||
pub struct 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 {
|
||||
match matching {
|
||||
Some(matching) => format!(
|
||||
@ -99,11 +108,17 @@ 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_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,
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
|
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 display;
|
||||
mod info;
|
||||
mod matches;
|
||||
mod minibuffer;
|
||||
mod overlay;
|
||||
mod reload;
|
||||
@ -8,13 +9,14 @@ mod reload;
|
||||
use browse::{AlbumArea, AlbumState, ArtistArea, ArtistState, FrameArea, TrackArea, TrackState};
|
||||
use display::UiDisplay;
|
||||
use info::{AlbumOverlay, ArtistOverlay};
|
||||
use matches::AlbumMatchesState;
|
||||
use minibuffer::Minibuffer;
|
||||
use musichoard::collection::{album::Album, track::Track, Collection};
|
||||
use overlay::{OverlayBuilder, OverlaySize};
|
||||
use ratatui::{
|
||||
layout::{Alignment, Rect},
|
||||
style::{Color, Style},
|
||||
widgets::{Block, BorderType, Borders, Clear, List, ListItem, Paragraph, Wrap},
|
||||
widgets::{Block, BorderType, Borders, Clear, List, Paragraph, Wrap},
|
||||
Frame,
|
||||
};
|
||||
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(
|
||||
matching: Option<&Album>,
|
||||
matches: Option<&[Match<Album>]>,
|
||||
@ -314,8 +293,8 @@ impl Ui {
|
||||
) {
|
||||
let area = OverlayBuilder::default().build(frame.size());
|
||||
let matching_string = UiDisplay::display_matching_info(matching);
|
||||
let list = matches.map(|m| Ui::build_match_list(m)).unwrap_or_default();
|
||||
Self::render_overlay_list_widget(&matching_string, list, state, true, area, frame)
|
||||
let st = matches.map(AlbumMatchesState::new).unwrap_or_default();
|
||||
Self::render_overlay_list_widget(&matching_string, st.list, state, true, area, frame)
|
||||
}
|
||||
|
||||
fn render_reload_overlay(frame: &mut Frame) {
|
||||
|
Loading…
Reference in New Issue
Block a user