Skip to content

Commit

Permalink
Implement the jump back in section, then I NEED to clean up the code!
Browse files Browse the repository at this point in the history
  • Loading branch information
Samuel Oldham committed Sep 14, 2024
1 parent 933b2b0 commit 01712ee
Show file tree
Hide file tree
Showing 5 changed files with 119 additions and 32 deletions.
2 changes: 1 addition & 1 deletion psst-gui/src/data/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -537,7 +537,7 @@ pub struct MixedView {
pub title: Arc<str>,
pub playlists: Vector<Playlist>,
pub artists: Vector<Artist>,
pub albums: Vector<Album>,
pub albums: Vector<Arc<Album>>,
pub shows: Vector<Arc<Show>>,
}

Expand Down
58 changes: 57 additions & 1 deletion psst-gui/src/ui/album.rs
Original file line number Diff line number Diff line change
Expand Up @@ -99,9 +99,65 @@ fn rounded_cover_widget(size: f64) -> impl Widget<Arc<Album>> {
cover_widget(size).clip(Size::new(size, size).to_rounded_rect(4.0))
}

pub fn horizontal_album_widget() -> impl Widget<WithCtx<Arc<Album>>> {
let album_cover = rounded_cover_widget(theme::grid(16.0));

let album_name = Flex::column()
.with_child(
Label::raw()
.with_font(theme::UI_FONT_MEDIUM)
.with_line_break_mode(LineBreaking::Clip)
.lens(Album::name.in_arc()),
)
.with_spacer(theme::grid(0.5))
.with_child(ViewSwitcher::new(
|album: &Arc<Album>, _| album.has_explicit(),
|selector: &bool, _, _| match selector {
true => icons::EXPLICIT.scale(theme::ICON_SIZE_TINY).boxed(),
false => Box::new(Flex::column()),
},
))
.center();

let album_artists = List::new(|| {
Label::raw()
.with_text_size(theme::TEXT_SIZE_SMALL)
.with_line_break_mode(LineBreaking::Clip)
.lens(ArtistLink::name)
})
.horizontal()
.with_spacing(theme::grid(1.0))
.lens(Album::artists.in_arc());

let album_date = Label::<Arc<Album>>::dynamic(|album, _| album.release_year())
.with_text_size(theme::TEXT_SIZE_SMALL)
.with_text_color(theme::PLACEHOLDER_COLOR);

let album_info = Flex::column()
.cross_axis_alignment(CrossAxisAlignment::Start)
.with_child(album_name)
.with_spacer(1.0)
.with_child(album_artists);

let album = Flex::column()
.with_child(album_cover)
.with_default_spacer()
.with_child(album_info)
.padding(theme::grid(1.0))
.lens(Ctx::data());

album
.link()
.rounded(theme::BUTTON_BORDER_RADIUS)
.on_left_click(|ctx, _, album, _| {
ctx.submit_command(cmd::NAVIGATE.with(Nav::AlbumDetail(album.data.link())));
})
.context_menu(album_ctx_menu)
}

pub fn album_widget() -> impl Widget<WithCtx<Arc<Album>>> {
let album_cover = rounded_cover_widget(theme::grid(6.0));

let album_name = Flex::row()
.with_child(
Label::raw()
Expand Down
2 changes: 1 addition & 1 deletion psst-gui/src/ui/artist.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use druid::{
im::Vector, kurbo::Circle, widget::{CrossAxisAlignment, Flex, Label, LabelText, LineBreaking, List, Scroll}, Data, Insets, LensExt, LocalizedString, Menu, MenuItem, Selector, Size, Widget, WidgetExt
im::Vector, kurbo::Circle, widget::{CrossAxisAlignment, Flex, Label, LabelText, LineBreaking, List}, Data, Insets, LensExt, LocalizedString, Menu, MenuItem, Selector, Widget, WidgetExt
};

use crate::{
Expand Down
47 changes: 27 additions & 20 deletions psst-gui/src/ui/home.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,15 @@ use druid::im::Vector;
use druid::widget::{Either, Flex, Label, Scroll};
use druid::{widget::List, LensExt, Selector, Widget, WidgetExt};

use crate::data::{Album, Artist, Ctx, HomeDetail, MixedView, Show, Track, WithCtx};
use crate::data::{Artist, Ctx, HomeDetail, MixedView, Show, Track, WithCtx};
use crate::widget::Empty;
use crate::{
data::AppState,
webapi::WebApi,
widget::{Async, MyWidgetExt},
};

use super::{artist, playable, show, theme, track};
use super::{album, artist, playable, show, theme, track};
use super::{
playlist,
utils::{error_widget, spinner_widget},
Expand Down Expand Up @@ -57,7 +57,7 @@ pub fn home_widget() -> impl Widget<AppState> {
}

pub fn made_for_you() -> impl Widget<AppState> {
Async::new(spinner_widget, loaded_results_widget.clone(), error_widget)
Async::new(spinner_widget, loaded_results_widget, error_widget)
.lens(
Ctx::make(
AppState::common_ctx,
Expand All @@ -74,7 +74,7 @@ pub fn made_for_you() -> impl Widget<AppState> {
}

pub fn recommended_stations() -> impl Widget<AppState> {
Async::new(spinner_widget, loaded_results_widget.clone(), error_widget)
Async::new(spinner_widget, loaded_results_widget, error_widget)
.lens(
Ctx::make(
AppState::common_ctx,
Expand All @@ -91,7 +91,7 @@ pub fn recommended_stations() -> impl Widget<AppState> {
}

pub fn uniquely_yours() -> impl Widget<AppState> {
Async::new(spinner_widget, loaded_results_widget.clone(), error_widget)
Async::new(spinner_widget, loaded_results_widget, error_widget)
.lens(
Ctx::make(
AppState::common_ctx,
Expand All @@ -108,7 +108,7 @@ pub fn uniquely_yours() -> impl Widget<AppState> {
}

pub fn user_top_mixes() -> impl Widget<AppState> {
Async::new(spinner_widget, loaded_results_widget.clone(), error_widget)
Async::new(spinner_widget, loaded_results_widget, error_widget)
.lens(
Ctx::make(
AppState::common_ctx,
Expand All @@ -125,7 +125,7 @@ pub fn user_top_mixes() -> impl Widget<AppState> {
}

pub fn your_shows() -> impl Widget<AppState> {
Async::new(spinner_widget, loaded_results_widget.clone(), error_widget)
Async::new(spinner_widget, loaded_results_widget, error_widget)
.lens(
Ctx::make(
AppState::common_ctx,
Expand All @@ -142,7 +142,7 @@ pub fn your_shows() -> impl Widget<AppState> {
}

pub fn jump_back_in() -> impl Widget<AppState> {
Async::new(spinner_widget, loaded_results_widget.clone(), error_widget)
Async::new(spinner_widget, loaded_results_widget, error_widget)
.lens(
Ctx::make(
AppState::common_ctx,
Expand All @@ -159,7 +159,7 @@ pub fn jump_back_in() -> impl Widget<AppState> {
}

pub fn shows_that_you_might_like() -> impl Widget<AppState> {
Async::new(spinner_widget, loaded_results_widget.clone(), error_widget)
Async::new(spinner_widget, loaded_results_widget, error_widget)
.lens(
Ctx::make(
AppState::common_ctx,
Expand Down Expand Up @@ -189,11 +189,14 @@ fn loaded_results_widget() -> impl Widget<WithCtx<MixedView>> {
.padding(theme::grid(6.0))
.center(),
Flex::column()
.with_child(title_label())
.with_child(artist_results_widget())
.with_child(album_results_widget())
.with_child(playlist_results_widget())
.with_child(show_results_widget()),
.with_child(title_label())
.with_child(Scroll::new(Flex::row()
.with_child(artist_results_widget())
.with_child(album_results_widget())
.with_child(playlist_results_widget())
.with_child(show_results_widget()))
.align_left(),
)
)
}

Expand Down Expand Up @@ -227,12 +230,16 @@ fn artist_results_widget() -> impl Widget<WithCtx<MixedView>> {

fn album_results_widget() -> impl Widget<WithCtx<MixedView>> {
Either::new(
|albums: &Vector<Album>, _| albums.is_empty(),
|playlists: &WithCtx<MixedView>, _| playlists.data.albums.is_empty(),
Empty,
Flex::column().with_child(Label::new("not implemented"))
.align_left(),
)
.lens(Ctx::data().then(MixedView::albums))
Flex::column().with_child(
Scroll::new(
List::new(album::horizontal_album_widget).horizontal(),
)
.horizontal()
.align_left()
.lens(Ctx::map(MixedView::albums)),
))
}

fn playlist_results_widget() -> impl Widget<WithCtx<MixedView>> {
Expand All @@ -256,7 +263,7 @@ fn show_results_widget() -> impl Widget<WithCtx<MixedView>> {
Empty,
Flex::column().with_child(
Scroll::new(
List::new(|| show::horizontal_show_widget()).horizontal(),
List::new(show::horizontal_show_widget).horizontal(),
)
.align_left()
),
Expand Down
42 changes: 33 additions & 9 deletions psst-gui/src/webapi/client.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use std::{
fmt::Display, io::{self, Read}, path::PathBuf, string, sync::Arc, thread, time::Duration
fmt::Display, io::{self, Read}, path::PathBuf, sync::Arc, thread, time::Duration
};

use druid::{
Expand All @@ -20,9 +20,9 @@ use psst_core::{

use crate::{
data::{
self, library_derived_lenses::playlists, Album, AlbumType, Artist, ArtistAlbums, AudioAnalysis, Cached, Episode, EpisodeId, EpisodeLink, MixedView, Nav, Page, Playlist, PublicUser, Range, Recommendations, RecommendationsRequest, SearchResults, SearchTopic, Show, SpotifyUrl, Track, UserProfile
self, Album, AlbumType, Artist, ArtistAlbums, ArtistLink, AudioAnalysis, Cached, Episode, EpisodeId, EpisodeLink, MixedView, Nav, Page, Playlist, PublicUser, Range, Recommendations, RecommendationsRequest, SearchResults, SearchTopic, Show, SpotifyUrl, Track, UserProfile
},
error::Error, ui::album,
error::Error,
};

use super::{cache::WebApiCache, local::LocalTrackManager};
Expand Down Expand Up @@ -500,7 +500,7 @@ impl WebApi {

let mut title: Arc<str> = Arc::from("");
let mut playlist: Vector<Playlist> = Vector::new();
let mut album: Vector<Album> = Vector::new();
let mut album: Vector<Arc<Album>> = Vector::new();
let mut artist: Vector<Artist> = Vector::new();
let mut show: Vector<Arc<Show>> = Vector::new();

Expand Down Expand Up @@ -557,8 +557,32 @@ impl WebApi {
height: None,
}).collect()
),
})},

})
},
DataTypename::Album => {
album.push_back(Arc::new(Album {
id: id.into(),
name: Arc::from(item.content.data.name.clone().unwrap()),
album_type: AlbumType::Album,
images: item.content.data.cover_art.as_ref().map_or_else(Vector::new, |images|
images.sources.iter().map(|src| data::utils::Image {
url: Arc::from(src.url.clone()),
width: None,
height: None,
}).collect()
),
artists: item.content.data.artists.as_ref().map_or_else(Vector::new, |artists|
artists.items.iter().map(|artist| ArtistLink {
id: Arc::from(artist.uri.split(':').last().unwrap_or("").to_string()),
name: Arc::from(artist.profile.name.clone()),
}).collect()),
copyrights: Vector::new(),
label: "".into(),
tracks: Vector::new(),
release_date: None,
release_date_precision: None,
}))
},
DataTypename::Podcast => {
show.push_back(Arc::new(Show {
id: id.into(),
Expand All @@ -582,8 +606,8 @@ impl WebApi {
Ok(MixedView {
title,
playlists: playlist,
artists: Vector::new(),
albums: Vector::new(),
artists: artist,
albums: album,
shows: show,
})
}
Expand Down Expand Up @@ -1018,7 +1042,7 @@ impl WebApi {
Ok(result)
}

/* EPISODES
/* EPISODES, IMPLEMENT THIS TO REDO THE PODCAST SECTION
// Episodes for you, this needs a different thing, mixedview could include this
pub fn new_episodes(&self) -> Result<MixedView, Error> {
// 0JQ5DAnM3wGh0gz1MXnu3K -> New episodes
Expand Down

0 comments on commit 01712ee

Please sign in to comment.