Skip to content

Commit

Permalink
improve my_shows and series page on upcoming release
Browse files Browse the repository at this point in the history
this improves the time format displayed in these pages.
  • Loading branch information
MaarifaMaarifa committed Aug 17, 2023
1 parent f565db8 commit 5abe06c
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 42 deletions.
35 changes: 0 additions & 35 deletions src/core/caching/episode_list.rs
Original file line number Diff line number Diff line change
Expand Up @@ -215,31 +215,6 @@ impl EpisodeReleaseTime {
self.release_time - local_time
}

/// Returns the remaining time for an episode to be released
pub fn get_remaining_release_time(&self) -> Option<String> {
let local_time = Utc::now().with_timezone(&Local);

if self.release_time > local_time {
let time_diff = self.release_time - local_time;

if time_diff.num_weeks() != 0 {
return Some(plurize_time(time_diff.num_weeks(), "week"));
}
if time_diff.num_days() != 0 {
return Some(plurize_time(time_diff.num_days(), "day"));
}
if time_diff.num_hours() != 0 {
return Some(plurize_time(time_diff.num_hours(), "hour"));
}
if time_diff.num_minutes() != 0 {
return Some(plurize_time(time_diff.num_minutes(), "minute"));
}
Some(String::from("Now"))
} else {
None
}
}

/// Returns the remaining full date and time for an episode to be released
pub fn get_full_release_date_and_time(&self) -> String {
/// appends zero the minute digit if it's below 10 for better display
Expand All @@ -266,13 +241,3 @@ impl EpisodeReleaseTime {
)
}
}

/// Takes the time and it's name i.e week, day, hour and concatenates the
/// two terms handling the condition when the time is above 1 (plural)
fn plurize_time(time_numeral: i64, word: &str) -> String {
if time_numeral > 1 {
format!("{} {}s", time_numeral, word)
} else {
format!("{} {}", time_numeral, word)
}
}
11 changes: 9 additions & 2 deletions src/gui/series_page/mini_widgets.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use crate::core::api::series_information::SeriesMainInformation;
use crate::core::caching::episode_list::EpisodeReleaseTime;
use crate::gui::assets::get_static_cow_from_asset;
use crate::gui::assets::icons::{CLOCK_FILL, STAR, STAR_FILL, STAR_HALF};
use crate::gui::helpers::season_episode_str_gen;
use crate::gui::helpers::{self, season_episode_str_gen};
use crate::gui::styles;

use iced::widget::{container, horizontal_space, row, svg, text, Space};
Expand Down Expand Up @@ -229,7 +229,14 @@ pub fn next_episode_release_time_widget(
let text = text(format!(
"{} in {}",
next_episode,
release_time.get_remaining_release_time().unwrap()
helpers::time::SaneTime::new(
release_time.get_remaining_release_duration().num_minutes() as u32
)
.get_time()
.into_iter()
.rev()
.map(|(time_text, time_value)| format!("{} {} ", time_value, time_text))
.collect::<String>()
))
.size(14);

Expand Down
17 changes: 12 additions & 5 deletions src/gui/troxide_widget.rs
Original file line number Diff line number Diff line change
Expand Up @@ -238,13 +238,20 @@ pub mod series_poster {
content = content.push(horizontal_space(Length::Fill));
let release_time_widget = container(
container(
text(
&episode_and_release_time
helpers::time::SaneTime::new(
episode_and_release_time
.1
.get_remaining_release_time()
.unwrap(),
.get_remaining_release_duration()
.num_minutes() as u32,
)
.horizontal_alignment(iced::alignment::Horizontal::Center),
.get_time()
.into_iter()
.last()
.map(|(time_text, time_value)| {
column![text(time_value), text(time_text),]
.align_items(iced::Alignment::Center)
})
.unwrap(),
)
.width(70)
.height(70)
Expand Down

0 comments on commit 5abe06c

Please sign in to comment.