diff --git a/src/app/components/playlist_details/playlist_details.rs b/src/app/components/playlist_details/playlist_details.rs index a767fffe..6ca976a5 100644 --- a/src/app/components/playlist_details/playlist_details.rs +++ b/src/app/components/playlist_details/playlist_details.rs @@ -90,10 +90,23 @@ impl PlaylistDetailsWidget { self.imp().scrolling_header.connect_bottom_edge(f); } + fn set_header_visible(&self, visible: bool) { + let widget = self.imp(); + widget.headerbar.set_title_visible(true); + if visible { + widget.headerbar.add_classes(&["flat"]); + } else { + widget.headerbar.remove_classes(&["flat"]); + } + } + fn connect_header(&self) { - self.imp() - .scrolling_header - .connect_header_visibility(|_| {}); + self.set_header_visible(false); + self.imp().scrolling_header.connect_header_visibility( + clone!(@weak self as _self => move |visible| { + _self.set_header_visible(visible); + }), + ); } fn set_loaded(&self) { @@ -111,13 +124,9 @@ impl PlaylistDetailsWidget { self.imp().headerbar.set_editable(editing); } - fn set_album_and_artist(&self, album: &str, artist: &str) { - self.imp() - .header_widget - .set_album_and_artist_and_year(album, artist, None); - self.imp() - .header_mobile - .set_album_and_artist_and_year(album, artist, None); + fn set_info(&self, playlist: &str, owner: &str) { + self.imp().header_widget.set_info(playlist, owner); + self.imp().header_mobile.set_info(playlist, owner); } fn set_artwork(&self, art: &gdk_pixbuf::Pixbuf) { @@ -125,12 +134,12 @@ impl PlaylistDetailsWidget { self.imp().header_mobile.set_artwork(art); } - fn connect_artist_clicked(&self, f: F) + fn connect_owner_clicked(&self, f: F) where F: Fn() + Clone + 'static, { - self.imp().header_widget.connect_artist_clicked(f.clone()); - self.imp().header_mobile.connect_artist_clicked(f); + self.imp().header_widget.connect_owner_clicked(f.clone()); + self.imp().header_mobile.connect_owner_clicked(f); } pub fn connect_edit(&self, f: F) @@ -144,7 +153,13 @@ impl PlaylistDetailsWidget { where F: Fn() + 'static, { - self.imp().headerbar.connect_cancel(f); + self.imp() + .headerbar + .connect_cancel(clone!(@weak self as _self => move || { + _self.imp().header_widget.reset_playlist_name(); + _self.imp().header_mobile.reset_playlist_name(); + f(); + })); } pub fn connect_done(&self, f: F) @@ -195,7 +210,7 @@ impl PlaylistDetails { model.load_more_tracks(); })); - widget.connect_artist_clicked(clone!(@weak model => move || model.view_owner())); + widget.connect_owner_clicked(clone!(@weak model => move || model.view_owner())); widget.connect_edit(clone!(@weak model => move || { model.enable_selection(); @@ -223,7 +238,7 @@ impl PlaylistDetails { let owner = &info.owner.display_name[..]; let art_url = info.art.as_ref(); - self.widget.set_album_and_artist(title, owner); + self.widget.set_info(title, owner); if let Some(art_url) = art_url.cloned() { let widget = self.widget.downgrade(); diff --git a/src/app/components/playlist_details/playlist_details.ui b/src/app/components/playlist_details/playlist_details.ui index 5eb62d4d..99d7e83f 100644 --- a/src/app/components/playlist_details/playlist_details.ui +++ b/src/app/components/playlist_details/playlist_details.ui @@ -36,7 +36,7 @@ diff --git a/src/app/components/playlist_details/playlist_header.css b/src/app/components/playlist_details/playlist_header.css index 28828e48..2df9145f 100644 --- a/src/app/components/playlist_details/playlist_header.css +++ b/src/app/components/playlist_details/playlist_header.css @@ -21,4 +21,26 @@ margin-top: 18px; margin-left: 6px; margin-bottom: 6px; +} + +clamp.playlist_details__clamp { + background-color: @view_bg_color; + box-shadow: inset 0px -1px 0px @borders; +} + +headerbar.playlist_details__headerbar { + transition: background-color .3s ease; +} + +headerbar.flat.playlist_details__headerbar windowtitle { + opacity: 0; +} + +headerbar.playlist_details__headerbar windowtitle { + transition: opacity .3s ease; + opacity: 1; +} + +.playlist_details__headerbar.flat { + background-color: @view_bg_color; } \ No newline at end of file diff --git a/src/app/components/playlist_details/playlist_header.rs b/src/app/components/playlist_details/playlist_header.rs index f7ccb656..4df3cdea 100644 --- a/src/app/components/playlist_details/playlist_header.rs +++ b/src/app/components/playlist_details/playlist_header.rs @@ -7,10 +7,16 @@ const CSS_RO_ENTRY: &str = "playlist__title-entry--ro"; mod imp { + use std::cell::RefCell; + use std::convert::TryFrom; + + use glib::{ParamSpec, Properties}; + use super::*; - #[derive(Debug, Default, CompositeTemplate)] + #[derive(Debug, Default, CompositeTemplate, Properties)] #[template(resource = "/dev/alextren/Spot/components/playlist_header.ui")] + #[properties(wrapper_type = super::PlaylistHeaderWidget)] pub struct PlaylistHeaderWidget { #[template_child] pub playlist_label_entry: TemplateChild, @@ -27,8 +33,8 @@ mod imp { #[template_child] pub author_button_label: TemplateChild, - #[template_child] - pub year_label: TemplateChild, + #[property(get, set, name = "original-entry-text")] + pub original_entry_text: RefCell, } #[glib::object_subclass] @@ -47,7 +53,30 @@ mod imp { } } - impl ObjectImpl for PlaylistHeaderWidget {} + impl ObjectImpl for PlaylistHeaderWidget { + fn properties() -> &'static [ParamSpec] { + Self::derived_properties() + } + + fn set_property(&self, id: usize, value: &glib::Value, pspec: &glib::ParamSpec) { + self.derived_set_property(id, value, pspec); + } + + fn property(&self, id: usize, pspec: &glib::ParamSpec) -> glib::Value { + self.derived_property(id, pspec) + } + + fn constructed(&self) { + self.parent_constructed(); + let entry: >k::Entry = &self.playlist_label_entry; + entry + .bind_property("text", entry, "width-chars") + .transform_to(|_, text: &str| Some(text.len() as i32)) + .flags(glib::BindingFlags::DEFAULT | glib::BindingFlags::SYNC_CREATE) + .build(); + } + } + impl WidgetImpl for PlaylistHeaderWidget {} impl BoxImpl for PlaylistHeaderWidget {} } @@ -61,7 +90,7 @@ impl PlaylistHeaderWidget { glib::Object::new() } - pub fn connect_artist_clicked(&self, f: F) + pub fn connect_owner_clicked(&self, f: F) where F: Fn() + 'static, { @@ -71,6 +100,12 @@ impl PlaylistHeaderWidget { }); } + pub fn reset_playlist_name(&self) { + self.imp() + .playlist_label_entry + .set_text(&self.original_entry_text()); + } + pub fn get_edited_playlist_name(&self) -> String { self.imp().playlist_label_entry.text().to_string() } @@ -79,17 +114,14 @@ impl PlaylistHeaderWidget { self.imp().playlist_art.set_from_pixbuf(Some(art)); } - pub fn set_album_and_artist_and_year(&self, album: &str, artist: &str, year: Option) { + pub fn set_info(&self, playlist: &str, owner: &str) { let widget = self.imp(); - widget.playlist_label_entry.set_text(album); + self.set_original_entry_text(playlist); + widget.playlist_label_entry.set_text(playlist); widget .playlist_label_entry - .set_placeholder_text(Some(album)); - widget.author_button_label.set_label(artist); - match year { - Some(year) => widget.year_label.set_label(&year.to_string()), - None => widget.year_label.hide(), - } + .set_placeholder_text(Some(playlist)); + widget.author_button_label.set_label(owner); } pub fn set_centered(&self) { diff --git a/src/app/components/playlist_details/playlist_header.ui b/src/app/components/playlist_details/playlist_header.ui index cbb4c76f..08a35183 100644 --- a/src/app/components/playlist_details/playlist_header.ui +++ b/src/app/components/playlist_details/playlist_header.ui @@ -32,7 +32,7 @@ 6 - 0 + 1 start 0 0 @@ -63,20 +63,6 @@ - - - 0 - start - Year - end - 50 - 1 - 0 - - - diff --git a/src/meson.build b/src/meson.build index 9d654ec3..e1bf1338 100644 --- a/src/meson.build +++ b/src/meson.build @@ -141,6 +141,8 @@ sources = files( './app/components/playlist_details/playlist_details_model.rs', './app/components/playlist_details/mod.rs', './app/components/playlist_details/playlist_details.rs', +'./app/components/playlist_details/playlist_headerbar.rs', +'./app/components/playlist_details/playlist_header.rs', './app/components/headerbar/widget.rs', './app/components/headerbar/component.rs', './app/components/headerbar/mod.rs',