Skip to content

Commit

Permalink
*: show playlist play_count (#835)
Browse files Browse the repository at this point in the history
  • Loading branch information
cosven committed May 26, 2024
1 parent f918ef2 commit 97058b0
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 2 deletions.
18 changes: 16 additions & 2 deletions feeluown/gui/widgets/img_card_list.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,9 @@
)

from feeluown.utils import aio
from feeluown.library import AlbumModel, AlbumType
from feeluown.library import AlbumModel, AlbumType, PlaylistModel
from feeluown.utils.reader import wrap
from feeluown.utils.utils import int_to_human_readable
from feeluown.library import reverse
from feeluown.gui.helpers import (
ItemViewNoScrollMixin, resize_font, ReaderFetchMoreMixin, painter_save,
Expand Down Expand Up @@ -401,7 +402,20 @@ def on_activated(self, index):


class PlaylistCardListModel(ImgCardListModel):
pass
def data(self, index, role):
offset = index.row()
if not index.isValid() or offset >= len(self._items):
return None

playlist = self._items[offset]
if (
role == Qt.WhatsThisRole
and isinstance(playlist, PlaylistModel)
and playlist.play_count > 0
):
count = int_to_human_readable(playlist.play_count)
return f'► {count}'
return super().data(index, role)


class PlaylistCardListDelegate(ImgCardListDelegate):
Expand Down
6 changes: 6 additions & 0 deletions feeluown/library/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -401,6 +401,12 @@ class PlaylistModel(BriefPlaylistModel, BaseNormalModel):
name: str
cover: str
description: str
play_count: int = -1 # -1 means unknown

def model_post_init(self, _):
super().model_post_init(_)
if self.creator is not None:
self.creator_name = self.creator.name


class SimpleSearchResult(_BaseModel):
Expand Down
8 changes: 8 additions & 0 deletions feeluown/utils/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -261,3 +261,11 @@ def remove(self, item):
def clear(self):
self._map.clear()
super().clear()


def int_to_human_readable(i):
if i >= 100000000:
return f'{i / 100000000:.1f}亿'
elif i >= 10000:
return f'{i / 10000:.1f}万'
return i

0 comments on commit 97058b0

Please sign in to comment.