Move URL handling to relevant structs and share selected song
This commit is contained in:
@@ -199,6 +199,12 @@ impl ListItem for Album {
|
|||||||
Some(AlbumView::new(queue, library, self).as_boxed_view_ext())
|
Some(AlbumView::new(queue, library, self).as_boxed_view_ext())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn share_url(&self) -> Option<String> {
|
||||||
|
self.id
|
||||||
|
.clone()
|
||||||
|
.map(|id| format!("https://open.spotify.com/album/{}", id))
|
||||||
|
}
|
||||||
|
|
||||||
fn artist(&self) -> Option<Artist> {
|
fn artist(&self) -> Option<Artist> {
|
||||||
Some(Artist::new(
|
Some(Artist::new(
|
||||||
self.artist_ids[0].clone(),
|
self.artist_ids[0].clone(),
|
||||||
|
|||||||
@@ -193,4 +193,10 @@ impl ListItem for Artist {
|
|||||||
fn open(&self, queue: Arc<Queue>, library: Arc<Library>) -> Option<Box<dyn ViewExt>> {
|
fn open(&self, queue: Arc<Queue>, library: Arc<Library>) -> Option<Box<dyn ViewExt>> {
|
||||||
Some(ArtistView::new(queue, library, self).as_boxed_view_ext())
|
Some(ArtistView::new(queue, library, self).as_boxed_view_ext())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn share_url(&self) -> Option<String> {
|
||||||
|
self.id
|
||||||
|
.clone()
|
||||||
|
.map(|id| format!("https://open.spotify.com/artist/{}", id))
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -10,7 +10,7 @@ use clipboard::{ClipboardContext, ClipboardProvider};
|
|||||||
use library::Library;
|
use library::Library;
|
||||||
use queue::{Queue, RepeatSetting};
|
use queue::{Queue, RepeatSetting};
|
||||||
use spotify::Spotify;
|
use spotify::Spotify;
|
||||||
use traits::ViewExt;
|
use traits::{ListItem, ViewExt};
|
||||||
use ui::layout::Layout;
|
use ui::layout::Layout;
|
||||||
|
|
||||||
type CommandCb = dyn Fn(&mut Cursive, &[String]) -> Result<Option<String>, String>;
|
type CommandCb = dyn Fn(&mut Cursive, &[String]) -> Result<Option<String>, String>;
|
||||||
@@ -202,14 +202,14 @@ impl CommandManager {
|
|||||||
let queue = queue.clone();
|
let queue = queue.clone();
|
||||||
self.register_command(
|
self.register_command(
|
||||||
"share",
|
"share",
|
||||||
Some(Box::new(move |_, _| {
|
Some(Box::new(move |_, args| {
|
||||||
if let Some(url) = queue
|
if let Some(url) = args.get(0).and_then(|source| match source.as_str() {
|
||||||
.get_current()
|
"current" => queue.get_current().and_then(|t| t.share_url()),
|
||||||
.and_then(|t| t.id)
|
_ => None,
|
||||||
.map(|id| format!("https://open.spotify.com/track/{}", id))
|
}) {
|
||||||
{
|
ClipboardProvider::new()
|
||||||
let mut ctx: ClipboardContext = ClipboardProvider::new().unwrap();
|
.and_then(|mut ctx: ClipboardContext| ctx.set_contents(url))
|
||||||
ctx.set_contents(url).unwrap();
|
.unwrap();
|
||||||
}
|
}
|
||||||
|
|
||||||
Ok(None)
|
Ok(None)
|
||||||
@@ -341,7 +341,8 @@ impl CommandManager {
|
|||||||
kb.insert(",".into(), "seek -500".into());
|
kb.insert(",".into(), "seek -500".into());
|
||||||
kb.insert("r".into(), "repeat".into());
|
kb.insert("r".into(), "repeat".into());
|
||||||
kb.insert("z".into(), "shuffle".into());
|
kb.insert("z".into(), "shuffle".into());
|
||||||
kb.insert("x".into(), "share".into());
|
kb.insert("x".into(), "share current".into());
|
||||||
|
kb.insert("Shift+x".into(), "share selected".into());
|
||||||
|
|
||||||
kb.insert("F1".into(), "focus queue".into());
|
kb.insert("F1".into(), "focus queue".into());
|
||||||
kb.insert("F2".into(), "focus search".into());
|
kb.insert("F2".into(), "focus search".into());
|
||||||
|
|||||||
@@ -166,4 +166,11 @@ impl ListItem for Playlist {
|
|||||||
fn open(&self, queue: Arc<Queue>, library: Arc<Library>) -> Option<Box<dyn ViewExt>> {
|
fn open(&self, queue: Arc<Queue>, library: Arc<Library>) -> Option<Box<dyn ViewExt>> {
|
||||||
Some(PlaylistView::new(queue, library, self).as_boxed_view_ext())
|
Some(PlaylistView::new(queue, library, self).as_boxed_view_ext())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn share_url(&self) -> Option<String> {
|
||||||
|
Some(format!(
|
||||||
|
"https://open.spotify.com/user/{}/{}",
|
||||||
|
self.owner_id, self.id
|
||||||
|
))
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -189,6 +189,12 @@ impl ListItem for Track {
|
|||||||
None
|
None
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn share_url(&self) -> Option<String> {
|
||||||
|
self.id
|
||||||
|
.clone()
|
||||||
|
.map(|id| format!("https://open.spotify.com/track/{}", id))
|
||||||
|
}
|
||||||
|
|
||||||
fn album(&self, queue: Arc<Queue>) -> Option<Album> {
|
fn album(&self, queue: Arc<Queue>) -> Option<Album> {
|
||||||
let spotify = queue.get_spotify();
|
let spotify = queue.get_spotify();
|
||||||
|
|
||||||
|
|||||||
@@ -18,6 +18,7 @@ pub trait ListItem: Sync + Send + 'static {
|
|||||||
fn queue(&mut self, queue: Arc<Queue>);
|
fn queue(&mut self, queue: Arc<Queue>);
|
||||||
fn toggle_saved(&mut self, library: Arc<Library>);
|
fn toggle_saved(&mut self, library: Arc<Library>);
|
||||||
fn open(&self, queue: Arc<Queue>, library: Arc<Library>) -> Option<Box<dyn ViewExt>>;
|
fn open(&self, queue: Arc<Queue>, library: Arc<Library>) -> Option<Box<dyn ViewExt>>;
|
||||||
|
fn share_url(&self) -> Option<String>;
|
||||||
|
|
||||||
fn album(&self, _queue: Arc<Queue>) -> Option<Album> {
|
fn album(&self, _queue: Arc<Queue>) -> Option<Album> {
|
||||||
None
|
None
|
||||||
|
|||||||
@@ -9,6 +9,7 @@ use cursive::view::ScrollBase;
|
|||||||
use cursive::{Cursive, Printer, Rect, Vec2};
|
use cursive::{Cursive, Printer, Rect, Vec2};
|
||||||
use unicode_width::UnicodeWidthStr;
|
use unicode_width::UnicodeWidthStr;
|
||||||
|
|
||||||
|
use clipboard::{ClipboardContext, ClipboardProvider};
|
||||||
use commands::CommandResult;
|
use commands::CommandResult;
|
||||||
use library::Library;
|
use library::Library;
|
||||||
use queue::Queue;
|
use queue::Queue;
|
||||||
@@ -314,6 +315,26 @@ impl<I: ListItem + Clone> ViewExt for ListView<I> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if cmd == "share" {
|
||||||
|
return args.get(0).map_or_else(
|
||||||
|
|| Err("wrong number of parameters".to_string()),
|
||||||
|
|source| match source.as_str() {
|
||||||
|
"selected" => {
|
||||||
|
if let Some(url) = self.content.read().ok().and_then(|content| {
|
||||||
|
content.get(self.selected).and_then(ListItem::share_url)
|
||||||
|
}) {
|
||||||
|
ClipboardProvider::new()
|
||||||
|
.and_then(|mut ctx: ClipboardContext| ctx.set_contents(url))
|
||||||
|
.unwrap();
|
||||||
|
}
|
||||||
|
|
||||||
|
Ok(CommandResult::Consumed(None))
|
||||||
|
}
|
||||||
|
_ => Ok(CommandResult::Ignored),
|
||||||
|
},
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
if cmd == "move" {
|
if cmd == "move" {
|
||||||
if let Some(dir) = args.get(0) {
|
if let Some(dir) = args.get(0) {
|
||||||
let amount: usize = args
|
let amount: usize = args
|
||||||
|
|||||||
Reference in New Issue
Block a user