Skip to content

Commit

Permalink
Fixes found after using the branch for a while
Browse files Browse the repository at this point in the history
Corrects soon_release flag calculation in MovieModel, and also adds it
to SeriesModel. Therefore removes it from update_series in
LocalProvider. Then we improve the badge logic in poster_button.py. And
finally corrects a typo in main_view.py that is triggered rarely.
  • Loading branch information
gnesterif committed Nov 22, 2023
1 parent 8358dc1 commit 22973de
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 25 deletions.
2 changes: 1 addition & 1 deletion src/models/movie_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ def __init__(self, d=None, t=None):
self.release_date = d['release_date']
self.revenue = d['revenue']
self.runtime = d['runtime']
self.soon_release = datetime.strptime(self.release_date, '%Y-%m-%d') < datetime.strptime(self.add_date, '%Y-%m-%d') + timedelta(days=14)
self.soon_release = datetime.strptime(self.release_date, '%Y-%m-%d') < datetime.strptime(self.add_date, '%Y-%m-%d') + timedelta(days=14) and datetime.strptime(self.release_date, '%Y-%m-%d') > datetime.strptime(self.add_date, '%Y-%m-%d')
self.status = d['status']
self.tagline = d['tagline']
self.title = d['title']
Expand Down
11 changes: 7 additions & 4 deletions src/models/series_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

import glob
import re
from datetime import datetime
from datetime import datetime, timedelta
from typing import List
from pathlib import Path

Expand Down Expand Up @@ -89,8 +89,7 @@ class SeriesModel(GObject.GObject):
def __init__(self, d=None, t=None):
super().__init__()

if d is not None:
self.activate_notification = False
if d is not None:
self.add_date = datetime.now()
self.backdrop_path = self._download_background(d['backdrop_path'])
self.created_by = self._parse_creators(api_dict=d['created_by'])
Expand All @@ -116,11 +115,15 @@ def __init__(self, d=None, t=None):
self.release_date = d['first_air_date']
self.seasons_number = d['number_of_seasons']
self.seasons = self._parse_seasons(d['seasons'])
self.soon_release = False
self.status = d['status']
self.tagline = d['tagline']
self.title = d['name']
self.watched = False
self.activate_notification = self.in_production
if self.next_air_date != '':
self.soon_release = datetime.strptime(self.next_air_date, '%Y-%m-%d') < datetime.now() + timedelta(days=6)
else:
self.soon_release = False
else:
self.activate_notification = t["activate_notification"]
self.add_date = t["add_date"] # type: ignore
Expand Down
3 changes: 1 addition & 2 deletions src/providers/local_provider.py
Original file line number Diff line number Diff line change
Expand Up @@ -1202,12 +1202,11 @@ def update_series(old: SeriesModel, new: SeriesModel) -> int | None:
connection.cursor().close()
logging.debug(f'[db] TV series {id}, deleted: {result.lastrowid}')

#Copy all flags that get reset but are still needed from the old to the new
#Copy all flags that get reset but are still needed from the old to the new soon_release is automatically set in SeriesModel
new.activate_notification = old.activate_notification
new.add_date = old.add_date
new.new_release = old.new_release
new.recent_change = old.recent_change
new.soon_release = old.soon_release
new.watched = old.watched

# Restore episodes statuses if they match before addition
Expand Down
2 changes: 1 addition & 1 deletion src/views/main_view.py
Original file line number Diff line number Diff line change
Expand Up @@ -265,7 +265,7 @@ def _update_notification_list(self, activity: BackgroundActivity) -> None:
# Check if the series went from in production to not in production
if serie.in_production == 1 and new_serie.in_production == 0:
local.set_recent_change_status(serie.id, True)
out_of_production.append(new_serie)
out_of_production_series.append(new_serie)
local.set_notification_list_status(serie.id, False)

serie = local.get_series_by_id(serie.id) #refetch serie to get all the correct flags that we set from the database
Expand Down
39 changes: 22 additions & 17 deletions src/widgets/poster_button.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ class PosterButton(Gtk.Box):

def __init__(self, content: MovieModel | SeriesModel):
super().__init__()
self.activate_notification = content.activate_notification
self.title = content.title
self.badge_color_light = content.color
self.year = content.release_date[0:4]
Expand Down Expand Up @@ -84,29 +85,33 @@ def _on_map(self, user_data: object | None) -> None:
self._picture.set_file(Gio.File.new_for_uri(self.poster_path))
self._spinner.set_visible(False)

if self.recent_change:
self._poster_box.add_css_class("pulse")
self._picture.add_css_class("shadow")

if self.new_release:
self._new_release_badge.set_visible(True)
if self.badge_color_light:
self._new_release_badge.add_css_class("light")
else:
self._new_release_badge.add_css_class("dark")
elif self.soon_release:
self._soon_release_badge.set_visible(True)
if self.badge_color_light:
self._soon_release_badge.add_css_class("light")
else:
self._soon_release_badge.add_css_class("dark")
badge_visible = False
if self.activate_notification:
if self.recent_change:
self._poster_box.add_css_class("pulse")
self._picture.add_css_class("shadow")

if self.new_release:
self._new_release_badge.set_visible(True)
badge_visible = True
if self.badge_color_light:
self._new_release_badge.add_css_class("light")
else:
self._new_release_badge.add_css_class("dark")
elif self.soon_release:
self._soon_release_badge.set_visible(True)
badge_visible = True
if self.badge_color_light:
self._soon_release_badge.add_css_class("light")
else:
self._soon_release_badge.add_css_class("dark")


if not self.year:
self._year_lbl.set_visible(False)
if self.status == '':
self._status_lbl.set_visible(False)
if self.watched:
if self.watched and not badge_visible:
self._watched_badge.set_visible(True)
if self.badge_color_light:
self._watched_badge.add_css_class("light")
Expand Down

0 comments on commit 22973de

Please sign in to comment.