feat: implemented load trailer when needed and also one media popup for all

This commit is contained in:
Benex254
2024-08-05 09:46:56 +03:00
parent 9ecce3bf78
commit 5bdebcae2c
2 changed files with 44 additions and 36 deletions

View File

@@ -23,7 +23,7 @@ class MediaPopup(
caller = ObjectProperty()
player = ObjectProperty()
def __init__(self, caller, *args, **kwarg):
def __init__(self, caller=None, *args, **kwarg):
self.caller = caller
super(MediaPopup, self).__init__(*args, **kwarg)
self.player.bind(fullscreen=self.handle_clean_fullscreen_transition)
@@ -37,51 +37,59 @@ class MediaPopup(
view.open(animation=False)
"""
from kivy.core.window import Window
if self.caller:
from kivy.core.window import Window
if self._is_open:
return
self._window = Window
self._is_open = True
self.dispatch("on_pre_open")
Window.add_widget(self)
Window.bind(on_resize=self._align_center, on_keyboard=self._handle_keyboard)
self.center = self.caller.to_window(*self.caller.center)
self.fbind("center", self._align_center)
self.fbind("size", self._align_center)
if kwargs.get("animation", True):
ani = Animation(_anim_alpha=1.0, d=self._anim_duration)
ani.bind(on_complete=lambda *_args: self.dispatch("on_open"))
ani.start(self)
if self._is_open:
return
self._window = Window
self._is_open = True
self.dispatch("on_pre_open")
Window.add_widget(self)
Window.bind(on_resize=self._align_center, on_keyboard=self._handle_keyboard)
self.center = self.caller.to_window(*self.caller.center)
self.fbind("center", self._align_center)
self.fbind("size", self._align_center)
if kwargs.get("animation", True):
ani = Animation(_anim_alpha=1.0, d=self._anim_duration)
ani.bind(on_complete=lambda *_args: self.dispatch("on_open"))
ani.start(self)
else:
self._anim_alpha = 1.0
self.dispatch("on_open")
else:
self._anim_alpha = 1.0
self.dispatch("on_open")
super().open(*_args, **kwargs)
def _align_center(self, *_args):
if self._is_open:
self.center = self.caller.to_window(*self.caller.center)
if self.caller:
if self._is_open:
self.center = self.caller.to_window(*self.caller.center)
else:
super()._align_center(*_args)
def on_leave(self, *args):
def _leave(dt):
self.player.state = "stop"
if self.player._video:
self.player._video.unload()
# if self.player._video:
# self.player._video.unload()
if not self.hovering:
self.dismiss()
Clock.schedule_once(_leave, 2)
def handle_clean_fullscreen_transition(self,instance,fullscreen):
def handle_clean_fullscreen_transition(self, instance, fullscreen):
if not fullscreen:
if not self._is_open:
instance.state = "stop"
if vid:=instance._video:
vid.unload()
# if vid := instance._video:
# vid.unload()
else:
instance.state = "stop"
if vid:=instance._video:
vid.unload()
# if vid := instance._video:
# vid.unload()
self.dismiss()
media_card_popup = MediaPopup()

View File

@@ -11,7 +11,7 @@ from kivy.uix.behaviors import ButtonBehavior
from kivymd.uix.boxlayout import MDBoxLayout
from kivymd.uix.behaviors import HoverBehavior
from .components import MediaPopup
from .components.media_popup import media_card_popup, MediaPopup
class MediaCard(ButtonBehavior, HoverBehavior, MDBoxLayout):
@@ -36,7 +36,7 @@ class MediaCard(ButtonBehavior, HoverBehavior, MDBoxLayout):
stars = ListProperty([0, 0, 0, 0, 0, 0])
cover_image_url = StringProperty()
preview_image = StringProperty()
has_trailer_color = ListProperty([.5, .5, .5, .5])
has_trailer_color = ListProperty([0.5, 0.5, 0.5, 0.5])
def __init__(self, trailer_url=None, **kwargs):
super().__init__(**kwargs)
@@ -63,8 +63,8 @@ class MediaCard(ButtonBehavior, HoverBehavior, MDBoxLayout):
def on_dismiss(self, popup: MediaPopup):
popup.player.state = "stop"
if popup.player._video:
popup.player._video.unload()
# if popup.player._video:
# popup.player._video.unload()
def set_preview_image(self, image):
self.preview_image = image
@@ -74,10 +74,10 @@ class MediaCard(ButtonBehavior, HoverBehavior, MDBoxLayout):
self.has_trailer_color = self.theme_cls.primaryColor
def open(self, *_):
popup = MediaPopup(self)
popup.title = self.title
popup.bind(on_dismiss=self.on_dismiss, on_open=self.on_popup_open)
popup.open(self)
media_card_popup.caller = self
media_card_popup.title = self.title
media_card_popup.bind(on_dismiss=self.on_dismiss, on_open=self.on_popup_open)
media_card_popup.open(self)
# ---------------respond to user actions and call appropriate model-------------------------
def on_is_in_my_list(self, instance, in_user_anime_list):