Display years in production under media tiles (fixes #26)

This commit is contained in:
Avery
2024-02-17 19:23:54 -05:00
parent a1120925db
commit 36321927ff
5 changed files with 32 additions and 21 deletions

View File

@@ -13,7 +13,7 @@ use crate::{
app::{AppInput, APP_BROKER},
jellyfin_api::api_client::ApiClient,
tr,
utils::{item_name::ItemName, playable::get_next_playable_media},
utils::{display_years::DisplayYears, item_name::ItemName, playable::get_next_playable_media},
};
#[derive(Clone, Copy)]
@@ -47,22 +47,6 @@ impl MediaTileDisplay {
}
}
fn get_item_label(item: &BaseItemDto) -> String {
match (
&item.series_name.as_ref().map(|s| markup_escape_text(s)),
item.episode_name_with_number()
.as_ref()
.map(|s| markup_escape_text(s)),
) {
(Some(series_name), Some(name)) => format!(
r#"{series_name}
<span size="small">{name}</span>"#
),
(_, Some(name)) => name.to_string(),
_ => tr!("library-media-tile-unnamed-item").to_string(),
}
}
pub struct MediaTile {
media: BaseItemDto,
api_client: Arc<ApiClient>,
@@ -177,7 +161,7 @@ impl AsyncComponent for MediaTile {
set_max_width_chars: 1,
set_width_request: tile_display.width(),
#[watch]
set_markup: &get_item_label(&model.media),
set_markup: &model.get_item_label(),
add_controller = gtk::GestureClick {
connect_released[sender] => move |_, _, _, _| {
@@ -269,6 +253,33 @@ impl AsyncComponent for MediaTile {
}
}
impl MediaTile {
fn get_item_label(&self) -> String {
match (
self.media
.series_name
.as_ref()
.map(|s| markup_escape_text(s)),
self.media
.episode_name_with_number()
.as_ref()
.map(|s| markup_escape_text(s)),
self.media.display_years(),
) {
(Some(series_name), Some(name), _) => format!(
r#"{series_name}
<span size="small">{name}</span>"#
),
(_, Some(name), Some(display_years)) => format!(
r#"{name}
<span size="small">{display_years}</span>"#
),
(_, Some(name), _) => name.to_string(),
_ => tr!("library-media-tile-unnamed-item").to_string(),
}
}
}
async fn get_thumbnail(
api_client: Arc<ApiClient>,
media: &BaseItemDto,

View File

@@ -13,10 +13,10 @@ use uuid::Uuid;
use crate::{
jellyfin_api::api_client::ApiClient,
media_details::{media_details_header::MediaDetailsHeaderInit, seasons::SeasonsInit},
utils::display_years::DisplayYears,
};
use super::{
display_years::DisplayYears,
media_details_header::{MediaDetailsHeader, MediaDetailsHeaderInput, MediaDetailsHeaderOutput},
run_time::RunTime,
seasons::{Seasons, SeasonsOutput},

View File

@@ -20,7 +20,6 @@ use crate::{
use self::media_details_contents::MediaDetailsContentsInput;
mod display_years;
pub mod episode;
mod episodes;
mod media_details_contents;

View File

@@ -3,7 +3,7 @@ use jellyfin_api::types::{BaseItemDto, BaseItemKind};
use crate::tr;
pub(crate) trait DisplayYears {
pub trait DisplayYears {
fn display_years(&self) -> Option<String>;
}

View File

@@ -2,6 +2,7 @@ pub mod bif;
pub mod constants;
pub mod debounce;
pub mod device_profile;
pub mod display_years;
pub mod empty_component;
pub mod inhibit;
pub mod item_name;