feat:added download task card to download screen which marks the end of it

This commit is contained in:
Benedict Xavier Wanyonyi
2024-05-28 14:02:18 +03:00
parent 129766111d
commit 1e9e9d71a1
7 changed files with 76 additions and 14 deletions

View File

@@ -0,0 +1,28 @@
#:import color_text Utility.kivy_markup_helper.color_text
<TaskText@MDLabel>:
adaptive_height:True
max_lines:0
shorten:False
markup:True
font_style: "Label"
role: "large"
bold:True
<TaskCard>:
adaptive_height:True
radius:8
padding:"20dp"
md_bg_color:self.theme_cls.surfaceContainerHighColor
TaskText:
size_hint_x:.8
text:color_text(root.anime_task_name,root.theme_cls.primaryColor)
TaskText:
size_hint_x:.2
# color:self.theme_cls.surfaceDimColor
theme_text_color:"Secondary"
text:color_text(root.episodes_to_download,root.theme_cls.secondaryColor)
MDIcon:
icon:"check-bold"

View File

@@ -0,0 +1,12 @@
from kivy.properties import StringProperty
from kivymd.uix.boxlayout import MDBoxLayout
# TODO: add a progress bar to show the individual progress of each task
class TaskCard(MDBoxLayout):
anime_task_name = StringProperty()
episodes_to_download = StringProperty()
def __init__(self, anime_title:str, episodes:str, *args, **kwargs):
super().__init__(*args, **kwargs)
self.anime_task_name = f"{anime_title}"
self.episodes_to_download = f"Episodes: {episodes}"

View File

@@ -24,12 +24,20 @@
SearchBar:
MDScrollView:
size_hint:.95,1
MDGridLayout:
padding: "75dp","50dp","10dp","100dp"
spacing:"40dp"
MDBoxLayout:
id:main_container
cols:5
orientation:"vertical"
padding:"40dp"
pos_hint:{"center_x":.5}
spacing:"10dp"
adaptive_height:True
HeaderLabel:
text:"Download Tasks"
halign:"left"
MDIcon:
padding:"10dp"
pos_hint:{"center_y":.5}
icon:"clock"
MDBoxLayout:
size_hint_y:None
height:"40dp"
@@ -39,7 +47,7 @@
DownloadsScreenLabel:
id:download_progress_label
size_hint_x: .6
text:"current episode"
text:"Try Downloading sth :)"
pos_hint: {'center_y': .5}
MDLinearProgressIndicator:
id: progress_bar

View File

@@ -1,18 +1,29 @@
from kivy.clock import Clock
from kivy.properties import ObjectProperty
from kivy.logger import Logger
from kivy.utils import format_bytes_to_human
from View.base_screen import BaseScreenView
from .components.task_card import TaskCard
class DownloadsScreenView(BaseScreenView):
main_container = ObjectProperty()
progress_bar = ObjectProperty()
download_progress_label = ObjectProperty()
def on_new_download_task(self,anime_title:str,episodes:str|None):
if not episodes:
episodes = "All"
self.main_container.add_widget(TaskCard(anime_title,episodes))
def on_episode_download_progress(self,current_bytes_downloaded,total_bytes,episode_info):
percentage_completion = (current_bytes_downloaded/total_bytes)*100
self.progress_bar.value= max(min(percentage_completion,100),0)
self.download_progress_label.text = f"Downloading: {episode_info['anime_title']} - {episode_info['episode']} ({format_bytes_to_human(current_bytes_downloaded)}/{format_bytes_to_human(total_bytes)})"
percentage_completion = round((current_bytes_downloaded/total_bytes)*100)
progress_text = f"Downloading: {episode_info['anime_title']} - {episode_info['episode']} ({format_bytes_to_human(current_bytes_downloaded)}/{format_bytes_to_human(total_bytes)})"
if (percentage_completion%5)==0:
self.progress_bar.value= max(min(percentage_completion,100),0)
self.download_progress_label.text = progress_text
Logger.info(f"Downloader: {progress_text}")
# def on_enter(self):
# Clock.schedule_once(lambda _:self.controller.requested_update_my_list_screen())

View File

@@ -1,3 +1,3 @@
<MDLabel>:
allow_copy:True
allow_selection:True
# <MDLabel>:
# allow_copy:True
# allow_selection:True

View File

@@ -139,6 +139,7 @@ class AniXStreamApp(MDApp):
self.theme_cls.theme_style = value
def on_stop(self):
del self.downloads_worker_thread
if self.animdl_streaming_subprocess:
self.animdl_streaming_subprocess.terminate()
Logger.info("Animdl:Successfully terminated existing animdl subprocess")
@@ -185,7 +186,6 @@ class AniXStreamApp(MDApp):
"New Download Task Queued",
f"{default_cmds.get('title')} has been queued for downloading",
)
self.add_anime_to_user_downloads_list(anime_id)
# TODO:Add custom download cmds functionality
@@ -193,6 +193,7 @@ class AniXStreamApp(MDApp):
*args
)
output_path = self.config.get("Preferences", "downloads_dir") # type: ignore
self.download_screen.on_new_download_task(default_cmds["title"],default_cmds.get("episodes_range"))
if episodes_range := default_cmds.get("episodes_range"):
download_task = lambda: AnimdlApi.download_anime_by_title(
default_cmds["title"],
@@ -213,7 +214,9 @@ class AniXStreamApp(MDApp):
output_path,
) # ,default_cmds.get("quality")
self.downloads_queue.put(download_task)
Logger.info(
f"Downloader:Successfully Queued {default_cmds['title']} for downloading"
)
def watch_on_allanime(self, title_):
"""
Opens the given anime in your default browser on allanimes site