Skip to content

Commit

Permalink
chore: menu for current yt video
Browse files Browse the repository at this point in the history
+ repeat for n times button
  • Loading branch information
MSOB7YY committed Feb 8, 2024
1 parent 9fd1c45 commit 4d5c41c
Show file tree
Hide file tree
Showing 3 changed files with 117 additions and 55 deletions.
65 changes: 37 additions & 28 deletions lib/ui/widgets/custom_widgets.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2841,18 +2841,22 @@ class _LazyLoadListViewState extends State<LazyLoadListView> {
class NamidaPopupItem {
final IconData icon;
final String title;
final Widget Function(TextStyle? style)? titleBuilder;
final String subtitle;
final void Function() onTap;
final bool enabled;
final bool oneLinedSub;
final Widget? trailing;

const NamidaPopupItem({
required this.icon,
required this.title,
this.titleBuilder,
this.subtitle = '',
required this.onTap,
this.enabled = true,
this.oneLinedSub = false,
this.trailing,
});
}

Expand Down Expand Up @@ -2902,35 +2906,40 @@ class NamidaPopupWrapper extends StatelessWidget {
items: [
if (childrenDefault != null)
...childrenDefault!().map(
(e) => PopupMenuItem(
height: 42.0,
onTap: e.onTap,
enabled: e.enabled,
child: Row(
children: [
Icon(e.icon, size: 20.0),
const SizedBox(width: 6.0),
Expanded(
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(
e.title,
style: context.textTheme.displayMedium?.copyWith(color: e.enabled ? null : context.textTheme.displayMedium?.color?.withOpacity(0.4)),
),
if (e.subtitle != '')
Text(
e.subtitle,
style: context.textTheme.displaySmall,
maxLines: e.oneLinedSub ? 1 : null,
overflow: TextOverflow.ellipsis,
),
],
(e) {
final titleStyle = context.textTheme.displayMedium?.copyWith(color: e.enabled ? null : context.textTheme.displayMedium?.color?.withOpacity(0.4));
return PopupMenuItem(
height: 42.0,
onTap: e.onTap,
enabled: e.enabled,
child: Row(
children: [
Icon(e.icon, size: 20.0),
const SizedBox(width: 6.0),
Expanded(
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
e.titleBuilder?.call(titleStyle) ??
Text(
e.title,
style: titleStyle,
),
if (e.subtitle != '')
Text(
e.subtitle,
style: context.textTheme.displaySmall,
maxLines: e.oneLinedSub ? 1 : null,
overflow: TextOverflow.ellipsis,
),
],
),
),
),
],
),
),
if (e.trailing != null) e.trailing!,
],
),
);
},
),
if (children != null)
...children!().map(
Expand Down
104 changes: 78 additions & 26 deletions lib/youtube/youtube_miniplayer.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import 'package:flutter/material.dart';
import 'package:flutter_html/flutter_html.dart';
import 'package:get/get.dart';
import 'package:jiffy/jiffy.dart';
import 'package:namida/core/enums.dart';
import 'package:newpipeextractor_dart/newpipeextractor_dart.dart';
import 'package:share_plus/share_plus.dart';
import 'package:url_launcher/url_launcher_string.dart';
Expand Down Expand Up @@ -41,11 +42,14 @@ import 'package:namida/youtube/widgets/yt_subscribe_buttons.dart';
import 'package:namida/youtube/widgets/yt_thumbnail.dart';
import 'package:namida/youtube/widgets/yt_video_card.dart';
import 'package:namida/youtube/yt_miniplayer_comments_subpage.dart';
import 'package:namida/youtube/yt_utils.dart';

const _space2ForThumbnail = 90.0;
const _extraPaddingForYTMiniplayer = 12.0;
const kYoutubeMiniplayerHeight = _extraPaddingForYTMiniplayer + _space2ForThumbnail * 9 / 16;

final _numberOfRepeats = 1.obs;

class YoutubeMiniPlayer extends StatelessWidget {
const YoutubeMiniPlayer({super.key});

Expand Down Expand Up @@ -199,35 +203,83 @@ class YoutubeMiniPlayer extends StatelessWidget {
collapsedIconColor: context.theme.colorScheme.onBackground,
childrenPadding: const EdgeInsets.all(18.0),
onExpansionChanged: (value) => YoutubeController.inst.isTitleExpanded.value = value,
trailing: Obx(
() {
final videoListens = YoutubeHistoryController.inst.topTracksMapListens[currentId] ?? [];
return Row(
mainAxisSize: MainAxisSize.min,
children: [
if (videoListens.isNotEmpty)
NamidaInkWell(
borderRadius: 6.0,
bgColor: CurrentColor.inst.miniplayerColor.withOpacity(0.7),
trailing: Row(
mainAxisSize: MainAxisSize.min,
children: [
Obx(
() {
final videoListens = YoutubeHistoryController.inst.topTracksMapListens[currentId] ?? [];
if (videoListens.isEmpty) return const SizedBox();
return NamidaInkWell(
borderRadius: 6.0,
bgColor: CurrentColor.inst.miniplayerColor.withOpacity(0.7),
onTap: () {
showVideoListensDialog(currentId);
},
padding: const EdgeInsets.symmetric(horizontal: 6.0, vertical: 2.0),
child: Text(
videoListens.length.formatDecimal(),
style: context.textTheme.displaySmall?.copyWith(
color: Colors.white.withOpacity(0.6),
),
),
);
},
),
const SizedBox(width: 8.0),
NamidaPopupWrapper(
onPop: () {
_numberOfRepeats.value = 1;
},
childrenDefault: () {
final videoId = currentId;
final items = YTUtils.getVideoCardMenuItems(
videoId: videoId,
url: videoInfo?.url,
channelUrl: channelIDOrURL,
playlistID: null,
idsNamesLookup: {videoId: videoInfo?.name},
);
if (Player.inst.nowPlayingVideoID != null && videoId == Player.inst.getCurrentVideoId) {
final repeatForWidget = NamidaPopupItem(
icon: Broken.cd,
title: '',
titleBuilder: (style) => Obx(
() => Text(
lang.REPEAT_FOR_N_TIMES.replaceFirst('_NUM_', _numberOfRepeats.value.toString()),
style: style,
),
),
onTap: () {
showVideoListensDialog(currentId);
settings.save(playerRepeatMode: RepeatMode.forNtimes);
Player.inst.updateNumberOfRepeats(_numberOfRepeats.value);
},
padding: const EdgeInsets.symmetric(horizontal: 6.0, vertical: 2.0),
child: Text(
videoListens.length.formatDecimal(),
style: context.textTheme.displaySmall?.copyWith(
color: Colors.white.withOpacity(0.6),
),
trailing: Row(
mainAxisSize: MainAxisSize.min,
children: [
NamidaIconButton(
icon: Broken.minus_cirlce,
onPressed: () => _numberOfRepeats.value = (_numberOfRepeats.value - 1).clamp(1, 20),
iconSize: 20.0,
),
NamidaIconButton(
icon: Broken.add_circle,
onPressed: () => _numberOfRepeats.value = (_numberOfRepeats.value + 1).clamp(1, 20),
iconSize: 20.0,
),
],
),
),
const SizedBox(width: 8.0),
const Icon(
Broken.arrow_down_2,
size: 20.0,
),
],
);
},
);
items.add(repeatForWidget);
}
return items;
},
child: const Icon(
Broken.arrow_down_2,
size: 20.0,
),
),
],
),
title: Obx(
() {
Expand Down
3 changes: 2 additions & 1 deletion lib/youtube/yt_utils.dart
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,7 @@ class YTUtils {
YoutubeID? videoYTID,
}) {
final playAfterVid = getPlayerAfterVideo();
final isCurrentlyPlaying = Player.inst.nowPlayingVideoID != null && videoId == Player.inst.getCurrentVideoId;
return [
NamidaPopupItem(
icon: Broken.music_library_2,
Expand All @@ -187,7 +188,7 @@ class YTUtils {
title: lang.SHARE,
onTap: () => Share.share(url),
),
Player.inst.nowPlayingVideoID != null && videoId == Player.inst.getCurrentVideoId
isCurrentlyPlaying
? NamidaPopupItem(
icon: Broken.pause,
title: lang.STOP_AFTER_THIS_VIDEO,
Expand Down

0 comments on commit 4d5c41c

Please sign in to comment.