Skip to content

Commit

Permalink
fix: most played page not refreshing when changing time range
Browse files Browse the repository at this point in the history
  • Loading branch information
MSOB7YY committed Oct 14, 2024
1 parent 4ec2636 commit 424a36f
Show file tree
Hide file tree
Showing 5 changed files with 161 additions and 162 deletions.
41 changes: 17 additions & 24 deletions lib/ui/pages/subpages/most_played_subpage.dart
Original file line number Diff line number Diff line change
Expand Up @@ -15,22 +15,20 @@ import 'package:namida/ui/widgets/custom_widgets.dart';

class MostPlayedItemsPage<T extends ItemWithDate, E> extends StatelessWidget {
final HistoryManager<T, E> historyController;
final Rx<MostPlayedTimeRange> activeTimeRangeChip;
final void Function({required MostPlayedTimeRange? mptr, DateRange? dateCustom, bool? isStartOfDay}) onSavingTimeRange;
final double? itemExtent;
final double itemExtent;
final Widget Function(Widget timeRangeChips, double bottomPadding) header;
final Widget Function(BuildContext context, int i, Map<E, List<int>> listensMap) itemBuilder;
final Rx<DateRange> customDateRange;
final Widget Function(BuildContext context, int i) itemBuilder;
final int itemsCount;

const MostPlayedItemsPage({
super.key,
required this.historyController,
required this.activeTimeRangeChip,
required this.onSavingTimeRange,
required this.itemExtent,
required this.header,
required this.itemBuilder,
required this.customDateRange,
required this.itemsCount,
});

void _onSelectingTimeRange({
Expand All @@ -39,7 +37,6 @@ class MostPlayedItemsPage<T extends ItemWithDate, E> extends StatelessWidget {
bool? isStartOfDay,
}) {
onSavingTimeRange(mptr: mptr, dateCustom: dateCustom, isStartOfDay: isStartOfDay);

historyController.updateTempMostPlayedPlaylist(
mptr: mptr,
customDateRange: dateCustom,
Expand All @@ -61,7 +58,7 @@ class MostPlayedItemsPage<T extends ItemWithDate, E> extends StatelessWidget {
return Padding(
padding: const EdgeInsets.symmetric(horizontal: 2.0),
child: ObxO(
rx: activeTimeRangeChip,
rx: historyController.currentMostPlayedTimeRange,
builder: (context, activeChip) {
final isActive = activeChip == mptr;
final textColor = isActive ? const Color.fromARGB(200, 255, 255, 255) : null;
Expand Down Expand Up @@ -109,7 +106,7 @@ class MostPlayedItemsPage<T extends ItemWithDate, E> extends StatelessWidget {
children: [
const SizedBox(width: 8.0),
ObxO(
rx: activeTimeRangeChip,
rx: historyController.currentMostPlayedTimeRange,
builder: (context, activeChip) => NamidaInkWell(
animationDurationMS: 200,
borderRadius: 6.0,
Expand Down Expand Up @@ -149,9 +146,9 @@ class MostPlayedItemsPage<T extends ItemWithDate, E> extends StatelessWidget {
scrollDirection: Axis.horizontal,
child: Row(
children: [
Obx(
(context) {
final dateRange = customDateRange.valueR;
ObxO(
rx: historyController.mostPlayedCustomDateRange,
builder: (context, dateRange) {
return _getChipChild(
context: context,
mptr: MostPlayedTimeRange.custom,
Expand All @@ -162,7 +159,7 @@ class MostPlayedItemsPage<T extends ItemWithDate, E> extends StatelessWidget {
iconSize: 14.0,
iconColor: textColor,
onPressed: () => _onSelectingTimeRange(
mptr: activeTimeRangeChip.value == MostPlayedTimeRange.custom ? MostPlayedTimeRange.allTime : null,
mptr: historyController.currentMostPlayedTimeRange.value == MostPlayedTimeRange.custom ? MostPlayedTimeRange.allTime : null,
dateCustom: DateRange.dummy(),
),
),
Expand Down Expand Up @@ -192,18 +189,14 @@ class MostPlayedItemsPage<T extends ItemWithDate, E> extends StatelessWidget {
Widget build(BuildContext context) {
final bottomWidget = getChipsRow(context);
const bottomPadding = 0.0;
final headerWidget = header(bottomWidget, bottomPadding);
return BackgroundWrapper(
child: Obx(
(context) {
final finalListenMap = historyController.currentTopTracksMapListensR;
return NamidaListView(
itemExtent: itemExtent,
header: header(bottomWidget, bottomPadding),
padding: kBottomPaddingInsets,
itemCount: finalListenMap.length,
itemBuilder: (context, i) => itemBuilder(context, i, finalListenMap),
);
},
child: NamidaListView(
itemExtent: itemExtent,
header: headerWidget,
padding: kBottomPaddingInsets,
itemCount: itemsCount,
itemBuilder: (context, i) => itemBuilder(context, i),
),
);
}
Expand Down
127 changes: 64 additions & 63 deletions lib/ui/pages/subpages/playlist_tracks_subpage.dart
Original file line number Diff line number Diff line change
Expand Up @@ -186,73 +186,74 @@ class MostPlayedTracksPage extends StatelessWidget with NamidaRouteWidget {

@override
Widget build(BuildContext context) {
return AnimationLimiter(
child: TrackTilePropertiesProvider(
configs: const TrackTilePropertiesConfigs(
queueSource: QueueSource.mostPlayed,
playlistName: k_PLAYLIST_NAME_MOST_PLAYED,
draggableThumbnail: false,
),
builder: (properties) {
final tracks = QueueSource.mostPlayed.toTracks();
return MostPlayedItemsPage(
itemExtent: Dimensions.inst.trackTileItemExtent,
historyController: HistoryController.inst,
customDateRange: settings.mostPlayedCustomDateRange,
activeTimeRangeChip: settings.mostPlayedTimeRange,
onSavingTimeRange: ({dateCustom, isStartOfDay, mptr}) {
settings.save(
mostPlayedTimeRange: mptr,
mostPlayedCustomDateRange: dateCustom,
mostPlayedCustomisStartOfDay: isStartOfDay,
);
},
header: (timeRangeChips, bottomPadding) {
return SubpagesTopContainer(
source: QueueSource.mostPlayed,
title: k_PLAYLIST_NAME_MOST_PLAYED.translatePlaylistName(),
subtitle: tracks.displayTrackKeyword,
heroTag: 'playlist_$k_PLAYLIST_NAME_MOST_PLAYED',
imageWidget: MultiArtworkContainer(
heroTag: 'playlist_$k_PLAYLIST_NAME_MOST_PLAYED',
size: context.width * 0.35,
tracks: tracks.toImageTracks(),
),
tracksFn: () => HistoryController.inst.currentMostPlayedTracks,
bottomPadding: bottomPadding,
bottomWidget: timeRangeChips,
);
},
itemBuilder: (context, i, listensMap) {
final track = tracks[i];
final listens = listensMap[track] ?? [];

return AnimatingTile(
key: Key("${track}_$i"),
position: i,
child: TrackTile(
properties: properties,
key: Key("${track}_$i"),
index: i,
trackOrTwd: tracks[i],
onRightAreaTap: () => showTrackListensDialog(track.track, datesOfListen: listens),
trailingWidget: Container(
padding: const EdgeInsets.all(6.0),
decoration: BoxDecoration(
color: context.theme.scaffoldBackgroundColor,
shape: BoxShape.circle,
return TrackTilePropertiesProvider(
configs: const TrackTilePropertiesConfigs(
queueSource: QueueSource.mostPlayed,
playlistName: k_PLAYLIST_NAME_MOST_PLAYED,
draggableThumbnail: false,
),
builder: (properties) {
return ObxO(
rx: HistoryController.inst.currentMostPlayedTimeRange,
builder: (context, currentMostPlayedTimeRange) => ObxO(
rx: HistoryController.inst.currentTopTracksMapListensReactive(currentMostPlayedTimeRange),
builder: (context, listensMap) {
final tracks = listensMap.keys.toList();
return MostPlayedItemsPage(
itemExtent: Dimensions.inst.trackTileItemExtent,
historyController: HistoryController.inst,
onSavingTimeRange: ({dateCustom, isStartOfDay, mptr}) {
settings.save(
mostPlayedTimeRange: mptr,
mostPlayedCustomDateRange: dateCustom,
mostPlayedCustomisStartOfDay: isStartOfDay,
);
},
header: (timeRangeChips, bottomPadding) {
return SubpagesTopContainer(
source: QueueSource.mostPlayed,
title: k_PLAYLIST_NAME_MOST_PLAYED.translatePlaylistName(),
subtitle: tracks.displayTrackKeyword,
heroTag: 'playlist_$k_PLAYLIST_NAME_MOST_PLAYED',
imageWidget: MultiArtworkContainer(
heroTag: 'playlist_$k_PLAYLIST_NAME_MOST_PLAYED',
size: context.width * 0.35,
tracks: tracks.toImageTracks(),
),
child: Text(
listens.length.formatDecimal(),
style: context.textTheme.displaySmall,
tracksFn: () => HistoryController.inst.currentMostPlayedTracks,
bottomPadding: bottomPadding,
bottomWidget: timeRangeChips,
);
},
itemsCount: listensMap.length,
itemBuilder: (context, i) {
final track = tracks[i];
final listens = listensMap[track] ?? [];

return TrackTile(
key: Key("${track}_$i"),
properties: properties,
index: i,
trackOrTwd: track,
onRightAreaTap: () => showTrackListensDialog(track, datesOfListen: listens),
trailingWidget: Container(
padding: const EdgeInsets.all(6.0),
decoration: BoxDecoration(
color: context.theme.scaffoldBackgroundColor,
shape: BoxShape.circle,
),
child: Text(
listens.length.formatDecimal(),
style: context.textTheme.displaySmall,
),
),
),
),
);
},
);
},
);
},
),
),
);
},
);
}
}
Expand Down
104 changes: 53 additions & 51 deletions lib/youtube/pages/yt_playlist_subpage.dart
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,6 @@ class YTMostPlayedVideosPage extends StatelessWidget with NamidaRouteWidget {
final config = MostPlayedItemsPage(
itemExtent: Dimensions.youtubeCardItemExtent,
historyController: YoutubeHistoryController.inst,
customDateRange: settings.ytMostPlayedCustomDateRange,
activeTimeRangeChip: settings.ytMostPlayedTimeRange,
onSavingTimeRange: ({dateCustom, isStartOfDay, mptr}) {
settings.save(
ytMostPlayedTimeRange: mptr,
Expand All @@ -61,62 +59,66 @@ class YTMostPlayedVideosPage extends StatelessWidget with NamidaRouteWidget {
);
},
header: (timeRangeChips, bottomPadding) => const SizedBox(),
itemBuilder: (context, i, listensMap) => const SizedBox(),
itemsCount: 0,
itemBuilder: (context, i) => const SizedBox(),
);
return config.getChipsRow(context);
}

@override
Widget build(BuildContext context) {
return Obx(
(context) {
final videos = <String>[];
final ytIds = <YoutubeID>[];
for (final e in YoutubeHistoryController.inst.currentTopTracksMapListensR.keys) {
videos.add(e);
ytIds.add(
YoutubeID(
id: e,
playlistID: const PlaylistID(id: k_PLAYLIST_NAME_MOST_PLAYED),
),
);
}

return MostPlayedItemsPage(
itemExtent: Dimensions.youtubeCardItemExtent,
historyController: YoutubeHistoryController.inst,
customDateRange: settings.ytMostPlayedCustomDateRange,
activeTimeRangeChip: settings.ytMostPlayedTimeRange,
onSavingTimeRange: ({dateCustom, isStartOfDay, mptr}) {
settings.save(
ytMostPlayedTimeRange: mptr,
ytMostPlayedCustomDateRange: dateCustom,
ytMostPlayedCustomisStartOfDay: isStartOfDay,
);
},
header: (timeRangeChips, bottomPadding) {
return Padding(
padding: const EdgeInsets.only(top: 4.0),
child: timeRangeChips,
);
},
itemBuilder: (context, i, listensMap) {
final videoID = videos[i];
final listens = listensMap[videoID] ?? [];

return YTHistoryVideoCard(
key: Key("${videoID}_$i"),
videos: ytIds,
index: i,
day: null,
overrideListens: listens,
playlistID: const PlaylistID(id: k_PLAYLIST_NAME_MOST_PLAYED),
playlistName: '',
canHaveDuplicates: false,
return ObxO(
rx: YoutubeHistoryController.inst.currentMostPlayedTimeRange,
builder: (context, currentMostPlayedTimeRange) => ObxO(
rx: YoutubeHistoryController.inst.currentTopTracksMapListensReactive(currentMostPlayedTimeRange),
builder: (context, listensMap) {
final videos = <String>[];
final ytIds = <YoutubeID>[];
for (final e in listensMap.keys) {
videos.add(e);
ytIds.add(
YoutubeID(
id: e,
playlistID: const PlaylistID(id: k_PLAYLIST_NAME_MOST_PLAYED),
),
);
},
);
},
}

return MostPlayedItemsPage(
itemExtent: Dimensions.youtubeCardItemExtent,
historyController: YoutubeHistoryController.inst,
onSavingTimeRange: ({dateCustom, isStartOfDay, mptr}) {
settings.save(
ytMostPlayedTimeRange: mptr,
ytMostPlayedCustomDateRange: dateCustom,
ytMostPlayedCustomisStartOfDay: isStartOfDay,
);
},
header: (timeRangeChips, bottomPadding) {
return Padding(
padding: const EdgeInsets.only(top: 4.0),
child: timeRangeChips,
);
},
itemsCount: listensMap.length,
itemBuilder: (context, i) {
final videoID = videos[i];
final listens = listensMap[videoID] ?? [];

return YTHistoryVideoCard(
key: Key("${videoID}_$i"),
videos: ytIds,
index: i,
day: null,
overrideListens: listens,
playlistID: const PlaylistID(id: k_PLAYLIST_NAME_MOST_PLAYED),
playlistName: '',
canHaveDuplicates: false,
);
},
);
},
),
);
}
}
Expand Down
Loading

0 comments on commit 424a36f

Please sign in to comment.