feat: add downloaded status indicator to table rows
This commit is contained in:
@@ -1,7 +1,7 @@
|
|||||||
"""Utils for table operations."""
|
"""Utils for table operations."""
|
||||||
|
|
||||||
import unicodedata
|
import unicodedata
|
||||||
from typing import Callable
|
from typing import TYPE_CHECKING, Callable
|
||||||
|
|
||||||
from .constants import (
|
from .constants import (
|
||||||
AUTHOR_NAME_DISPLAY_LENGTH,
|
AUTHOR_NAME_DISPLAY_LENGTH,
|
||||||
@@ -9,6 +9,9 @@ from .constants import (
|
|||||||
PROGRESS_COLUMN_INDEX,
|
PROGRESS_COLUMN_INDEX,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
if TYPE_CHECKING:
|
||||||
|
from .downloads import DownloadManager
|
||||||
|
|
||||||
|
|
||||||
def create_title_sort_key(reverse: bool = False) -> tuple[Callable, bool]:
|
def create_title_sort_key(reverse: bool = False) -> tuple[Callable, bool]:
|
||||||
"""Create a sort key function for sorting by title."""
|
"""Create a sort key function for sorting by title."""
|
||||||
@@ -43,11 +46,11 @@ def truncate_author_name(author_names: str) -> str:
|
|||||||
return author_names
|
return author_names
|
||||||
|
|
||||||
|
|
||||||
def format_item_as_row(item: dict, library_client) -> tuple[str, str, str, str]:
|
def format_item_as_row(item: dict, library_client, download_manager: "DownloadManager | None" = None) -> tuple[str, str, str, str, str]:
|
||||||
"""Format a library item into table row data.
|
"""Format a library item into table row data.
|
||||||
|
|
||||||
Returns:
|
Returns:
|
||||||
Tuple of (title, author, runtime, progress) strings
|
Tuple of (title, author, runtime, progress, downloaded) strings
|
||||||
"""
|
"""
|
||||||
title = library_client.extract_title(item)
|
title = library_client.extract_title(item)
|
||||||
|
|
||||||
@@ -67,7 +70,13 @@ def format_item_as_row(item: dict, library_client) -> tuple[str, str, str, str]:
|
|||||||
else "0%"
|
else "0%"
|
||||||
)
|
)
|
||||||
|
|
||||||
return (title, author_display, runtime_str, progress_str)
|
downloaded_str = ""
|
||||||
|
if download_manager:
|
||||||
|
asin = library_client.extract_asin(item)
|
||||||
|
if asin and download_manager.is_cached(asin):
|
||||||
|
downloaded_str = "✓"
|
||||||
|
|
||||||
|
return (title, author_display, runtime_str, progress_str, downloaded_str)
|
||||||
|
|
||||||
|
|
||||||
def filter_unfinished_items(items: list[dict], library_client) -> list[dict]:
|
def filter_unfinished_items(items: list[dict], library_client) -> list[dict]:
|
||||||
|
|||||||
Reference in New Issue
Block a user