Skip to content

Commit

Permalink
fix: hide shorts in horizontal history not normal history page
Browse files Browse the repository at this point in the history
  • Loading branch information
MSOB7YY committed Jul 25, 2024
1 parent 61bc5df commit 2afb697
Show file tree
Hide file tree
Showing 2 changed files with 186 additions and 206 deletions.
364 changes: 181 additions & 183 deletions lib/youtube/pages/youtube_user_history_page.dart
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import 'package:flutter/material.dart';

import 'package:youtipie/class/chunks/history_chunk.dart';
import 'package:youtipie/class/publish_time.dart';
import 'package:youtipie/class/result_wrapper/history_result.dart';
Expand Down Expand Up @@ -43,94 +42,102 @@ class YoutubeUserHistoryPage extends StatelessWidget with NamidaRouteWidget {
shimmerEnabled: true,
);

const isShortsVisible = false;

return YoutubeMainPageFetcherAccBase<YoutiPieHistoryResult, YoutiPieHistoryChunk>(
onListUpdated: onListUpdated,
transparentShimmer: true,
title: lang.HISTORY,
cacheReader: YoutiPie.cacheBuilder.forHistoryVideos(),
networkFetcher: (details) => YoutubeInfoController.history.fetchHistory(details: details),
itemExtent: thumbnailItemExtent,
dummyCard: dummyCard,
itemBuilder: (chunk, index, list) {
final items = chunk.items;
int itemsLengthWithoutHiddens = items.length;
if (!isShortsVisible) itemsLengthWithoutHiddens -= chunk.shortsItemsCount.value;
if (itemsLengthWithoutHiddens <= 0) return const SizedBox();
return ObxO(
rx: settings.youtube.ytVisibleShorts,
builder: (visibleShorts) {
final isShortsVisible = visibleShorts[YTVisibleShortPlaces.history] ?? true;
return YoutubeMainPageFetcherAccBase<YoutiPieHistoryResult, YoutiPieHistoryChunk>(
onListUpdated: onListUpdated,
transparentShimmer: true,
title: lang.HISTORY,
cacheReader: YoutiPie.cacheBuilder.forHistoryVideos(),
networkFetcher: (details) => YoutubeInfoController.history.fetchHistory(details: details),
itemExtent: thumbnailItemExtent,
dummyCard: dummyCard,
itemBuilder: (chunk, index, list) {
final items = chunk.items;
int itemsLengthWithoutHiddens = items.length;
if (!isShortsVisible) itemsLengthWithoutHiddens -= chunk.shortsItemsCount.value;
if (itemsLengthWithoutHiddens <= 0) return const SizedBox();

final hasBeforeAndAfterPadding = chunk.title.isNotEmpty;
final hasBeforeAndAfterPadding = chunk.title.isNotEmpty;

return Column(
mainAxisSize: MainAxisSize.min,
crossAxisAlignment: CrossAxisAlignment.start,
children: [
if (hasBeforeAndAfterPadding)
SizedBox(
height: beforeSublistHeight,
child: Padding(
padding: const EdgeInsets.symmetric(horizontal: 12.0),
child: Text(
chunk.title,
style: context.textTheme.displayMedium,
return Column(
mainAxisSize: MainAxisSize.min,
crossAxisAlignment: CrossAxisAlignment.start,
children: [
if (hasBeforeAndAfterPadding)
SizedBox(
height: beforeSublistHeight,
child: Padding(
padding: const EdgeInsets.symmetric(horizontal: 12.0),
child: Text(
chunk.title,
style: context.textTheme.displayMedium,
),
),
),
SizedBox(
height: itemsLengthWithoutHiddens * thumbnailItemExtent,
child: ListView.builder(
padding: EdgeInsets.zero,
scrollDirection: Axis.vertical,
primary: false,
physics: const NeverScrollableScrollPhysics(),
itemExtent: isShortsVisible ? thumbnailItemExtent : null,
// -- we use extent builder only if shorts are hidden
itemExtentBuilder: isShortsVisible
? null
: (index, dimensions) {
final item = items[index];
if (item is StreamInfoItemShort) return 0;
return thumbnailItemExtent;
},
itemCount: items.length,
itemBuilder: (context, index) {
final item = items[index];
return switch (item.runtimeType) {
const (StreamInfoItem) => YoutubeVideoCard(
thumbnailHeight: thumbnailHeight,
thumbnailWidth: thumbnailWidth,
isImageImportantInCache: false,
video: item as StreamInfoItem,
playlistID: null,
),
const (StreamInfoItemShort) => YoutubeShortVideoCard(
thumbnailHeight: thumbnailHeight,
thumbnailWidth: thumbnailWidth,
short: item as StreamInfoItemShort,
playlistID: null,
),
_ => dummyCard,
};
},
),
),
),
SizedBox(
height: itemsLengthWithoutHiddens * thumbnailItemExtent,
child: ListView.builder(
padding: EdgeInsets.zero,
scrollDirection: Axis.vertical,
primary: false,
physics: const NeverScrollableScrollPhysics(),
itemExtentBuilder: (index, dimensions) {
final item = items[index];
if (item is StreamInfoItemShort) return 0;
return thumbnailItemExtent;
},
itemCount: items.length,
itemBuilder: (context, index) {
final item = items[index];
return switch (item.runtimeType) {
const (StreamInfoItem) => YoutubeVideoCard(
thumbnailHeight: thumbnailHeight,
thumbnailWidth: thumbnailWidth,
isImageImportantInCache: false,
video: item as StreamInfoItem,
playlistID: null,
),
const (StreamInfoItemShort) => YoutubeShortVideoCard(
thumbnailHeight: thumbnailHeight,
thumbnailWidth: thumbnailWidth,
short: item as StreamInfoItemShort,
playlistID: null,
),
_ => dummyCard,
};
},
),
),
if (hasBeforeAndAfterPadding) const SizedBox(height: afterSublistHeight),
],
if (hasBeforeAndAfterPadding) const SizedBox(height: afterSublistHeight),
],
);
},
sliverListBuilder: (listItems, itemBuilder, dummyCard) => SliverVariedExtentList.builder(
itemExtentBuilder: (index, dimensions) {
final chunk = listItems.items[index];
final hasBeforeAndAfterPadding = chunk.title.isNotEmpty;
double itemsExtent = chunk.items.length * thumbnailItemExtent;
if (hasBeforeAndAfterPadding) {
itemsExtent += beforeSublistHeight;
itemsExtent += afterSublistHeight;
}
return itemsExtent;
},
itemCount: listItems.items.length,
itemBuilder: (context, index) {
final chunk = listItems.items[index];
return itemBuilder(chunk, index, listItems);
},
),
);
},
sliverListBuilder: (listItems, itemBuilder, dummyCard) => SliverVariedExtentList.builder(
itemExtentBuilder: (index, dimensions) {
final chunk = listItems.items[index];
final hasBeforeAndAfterPadding = chunk.title.isNotEmpty;
double itemsExtent = chunk.items.length * thumbnailItemExtent;
if (hasBeforeAndAfterPadding) {
itemsExtent += beforeSublistHeight;
itemsExtent += afterSublistHeight;
}
return itemsExtent;
},
itemCount: listItems.items.length,
itemBuilder: (context, index) {
final chunk = listItems.items[index];
return itemBuilder(chunk, index, listItems);
},
),
);
}
}
Expand All @@ -155,115 +162,106 @@ class YoutubeUserHistoryPageHorizontal extends StatelessWidget {
bgColor: context.theme.cardColor,
);

return ObxO(
rx: settings.youtube.ytVisibleShorts,
builder: (visibleShorts) {
final isShortsVisible = visibleShorts[YTVisibleShortPlaces.history] ?? true;
return YoutubeMainPageFetcherAccBase<YoutiPieHistoryResult, YoutiPieHistoryChunk>(
key: pageKey,
isHorizontal: true,
horizontalHeight: horizontalHeight,
enablePullToRefresh: false,
transparentShimmer: true,
topPadding: 12.0,
bottomPadding: 32.0,
title: lang.HISTORY,
onHeaderTap: YoutubeUserHistoryPage(
onListUpdated: (result) {
if (result == null) return;
(pageKey?.currentState as dynamic)?.updateList(result);
},
).navigate,
cacheReader: YoutiPie.cacheBuilder.forHistoryVideos(),
networkFetcher: (details) => YoutubeInfoController.history.fetchHistory(details: details),
itemExtent: thumbnailItemExtent,
dummyCard: dummyCard,
itemBuilder: (chunk, chunkIndex, list) {
final items = chunk.items;
int itemsLengthWithoutHiddens = items.length;
if (!isShortsVisible) itemsLengthWithoutHiddens -= chunk.shortsItemsCount.value;
if (itemsLengthWithoutHiddens <= 0) return const SizedBox();
const isShortsVisible = false;

return SizedBox(
height: horizontalHeight,
width: itemsLengthWithoutHiddens * thumbnailItemExtent,
child: ListView.builder(
scrollDirection: Axis.horizontal,
primary: false,
itemExtent: isShortsVisible ? thumbnailItemExtent : null,
// -- we use extent builder only if shorts are hidden
itemExtentBuilder: isShortsVisible
? null
: (index, dimensions) {
final item = items[index];
if (item is StreamInfoItemShort) return 0;
return thumbnailItemExtent;
},
return YoutubeMainPageFetcherAccBase<YoutiPieHistoryResult, YoutiPieHistoryChunk>(
key: pageKey,
isHorizontal: true,
horizontalHeight: horizontalHeight,
enablePullToRefresh: false,
transparentShimmer: true,
topPadding: 12.0,
bottomPadding: 32.0,
title: lang.HISTORY,
onHeaderTap: YoutubeUserHistoryPage(
onListUpdated: (result) {
if (result == null) return;
(pageKey?.currentState as dynamic)?.updateList(result);
},
).navigate,
cacheReader: YoutiPie.cacheBuilder.forHistoryVideos(),
networkFetcher: (details) => YoutubeInfoController.history.fetchHistory(details: details),
itemExtent: thumbnailItemExtent,
dummyCard: dummyCard,
itemBuilder: (chunk, chunkIndex, list) {
final items = chunk.items;
int itemsLengthWithoutHiddens = items.length;
if (!isShortsVisible) itemsLengthWithoutHiddens -= chunk.shortsItemsCount.value;
if (itemsLengthWithoutHiddens <= 0) return const SizedBox();

itemCount: items.length,
itemBuilder: (context, index) {
return YTHistoryVideoCardBase(
mainList: items,
itemToYTVideoId: (e) {
if (e is StreamInfoItem) {
return (e.id, null);
} else if (e is StreamInfoItemShort) {
return (e.id, null);
}
throw Exception('itemToYTID unknown type');
},
day: null,
index: index,
playlistID: null,
playlistName: lang.HISTORY,
canHaveDuplicates: true,
minimalCard: true,
info: (item) {
if (item is StreamInfoItem) {
return item;
}
if (item is StreamInfoItemShort) {
return StreamInfoItem(
id: item.id,
title: item.title,
shortDescription: null,
channel: const ChannelInfoItem.anonymous(),
thumbnailGifUrl: null,
publishedFromText: '',
publishedAt: const PublishTime.unknown(),
indexInPlaylist: null,
durSeconds: null,
durText: null,
viewsText: item.viewsText,
viewsCount: item.viewsCount,
percentageWatched: null,
liveThumbs: item.liveThumbs,
isUploaderVerified: null,
badges: null,
);
}
return null;
},
thumbnailHeight: thumbnailHeight,
minimalCardWidth: thumbnailWidth,
);
},
),
);
},
sliverListBuilder: (listItems, itemBuilder, dummyCard) => SliverVariedExtentList.builder(
return SizedBox(
height: horizontalHeight,
width: itemsLengthWithoutHiddens * thumbnailItemExtent,
child: ListView.builder(
scrollDirection: Axis.horizontal,
primary: false,
itemExtentBuilder: (index, dimensions) {
final chunk = listItems.items[index];
return chunk.items.length * thumbnailItemExtent;
final item = items[index];
if (item is StreamInfoItemShort) return 0;
return thumbnailItemExtent;
},
itemCount: listItems.items.length,
itemCount: items.length,
itemBuilder: (context, index) {
final chunk = listItems.items[index];
return itemBuilder(chunk, index, listItems);
return YTHistoryVideoCardBase(
mainList: items,
itemToYTVideoId: (e) {
if (e is StreamInfoItem) {
return (e.id, null);
} else if (e is StreamInfoItemShort) {
return (e.id, null);
}
throw Exception('itemToYTID unknown type');
},
day: null,
index: index,
playlistID: null,
playlistName: lang.HISTORY,
canHaveDuplicates: true,
minimalCard: true,
info: (item) {
if (item is StreamInfoItem) {
return item;
}
if (item is StreamInfoItemShort) {
return StreamInfoItem(
id: item.id,
title: item.title,
shortDescription: null,
channel: const ChannelInfoItem.anonymous(),
thumbnailGifUrl: null,
publishedFromText: '',
publishedAt: const PublishTime.unknown(),
indexInPlaylist: null,
durSeconds: null,
durText: null,
viewsText: item.viewsText,
viewsCount: item.viewsCount,
percentageWatched: null,
liveThumbs: item.liveThumbs,
isUploaderVerified: null,
badges: null,
);
}
return null;
},
thumbnailHeight: thumbnailHeight,
minimalCardWidth: thumbnailWidth,
);
},
),
);
},
sliverListBuilder: (listItems, itemBuilder, dummyCard) => SliverVariedExtentList.builder(
itemExtentBuilder: (index, dimensions) {
final chunk = listItems.items[index];
return chunk.items.length * thumbnailItemExtent;
},
itemCount: listItems.items.length,
itemBuilder: (context, index) {
final chunk = listItems.items[index];
return itemBuilder(chunk, index, listItems);
},
),
);
}
}
Loading

0 comments on commit 2afb697

Please sign in to comment.