Skip to content

Commit

Permalink
feat: most played page for youtube
Browse files Browse the repository at this point in the history
  • Loading branch information
MSOB7YY committed Nov 7, 2023
1 parent 47f0ee0 commit 493800c
Show file tree
Hide file tree
Showing 11 changed files with 514 additions and 338 deletions.
3 changes: 0 additions & 3 deletions android/app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -95,9 +95,6 @@
<meta-data
android:name="flutterEmbedding"
android:value="2" />
<service
android:name=".BetterPlayerService"
android:stopWithTask="false" />

<!-- ADD THIS "SERVICE" element -->
<service android:name="com.ryanheise.audioservice.AudioService"
Expand Down
35 changes: 29 additions & 6 deletions lib/controller/settings_controller.dart
Original file line number Diff line number Diff line change
Expand Up @@ -185,10 +185,14 @@ class SettingsController {

final Rx<TrackPlayMode> trackPlayMode = TrackPlayMode.searchResults.obs;

final Rx<MostPlayedTimeRange> mostPlayedTimeRange = MostPlayedTimeRange.allTime.obs;
final mostPlayedTimeRange = MostPlayedTimeRange.allTime.obs;
final mostPlayedCustomDateRange = DateRange.dummy().obs;
final mostPlayedCustomisStartOfDay = true.obs;

final ytMostPlayedTimeRange = MostPlayedTimeRange.allTime.obs;
final ytMostPlayedCustomDateRange = DateRange.dummy().obs;
final ytMostPlayedCustomisStartOfDay = true.obs;

/// Track Items
final RxBool displayThirdRow = true.obs;
final RxBool displayThirdItemInEachRow = false.obs;
Expand Down Expand Up @@ -441,6 +445,10 @@ class SettingsController {
mostPlayedCustomDateRange.value = json['mostPlayedCustomDateRange'] != null ? DateRange.fromJson(json['mostPlayedCustomDateRange']) : mostPlayedCustomDateRange.value;
mostPlayedCustomisStartOfDay.value = json['mostPlayedCustomisStartOfDay'] ?? mostPlayedCustomisStartOfDay.value;

ytMostPlayedTimeRange.value = MostPlayedTimeRange.values.getEnum(json['ytMostPlayedTimeRange']) ?? ytMostPlayedTimeRange.value;
ytMostPlayedCustomDateRange.value = json['ytMostPlayedCustomDateRange'] != null ? DateRange.fromJson(json['ytMostPlayedCustomDateRange']) : ytMostPlayedCustomDateRange.value;
ytMostPlayedCustomisStartOfDay.value = json['ytMostPlayedCustomisStartOfDay'] ?? ytMostPlayedCustomisStartOfDay.value;

/// Track Items
displayThirdRow.value = json['displayThirdRow'] ?? displayThirdRow.value;
displayThirdItemInEachRow.value = json['displayThirdItemInEachRow'] ?? displayThirdItemInEachRow.value;
Expand Down Expand Up @@ -637,13 +645,16 @@ class SettingsController {
'localVideoMatchingCheckSameDir': localVideoMatchingCheckSameDir.value,
'playerRepeatMode': playerRepeatMode.value.convertToString,
'trackPlayMode': trackPlayMode.value.convertToString,
'mostPlayedTimeRange': mostPlayedTimeRange.value.convertToString,
'onNotificationTapAction': onNotificationTapAction.value.convertToString,
'onYoutubeLinkOpen': onYoutubeLinkOpen.value.convertToString,
'performanceMode': performanceMode.value.convertToString,
'killPlayerAfterDismissingAppMode': killPlayerAfterDismissingAppMode.value.convertToString,
'mostPlayedTimeRange': mostPlayedTimeRange.value.convertToString,
'mostPlayedCustomDateRange': mostPlayedCustomDateRange.value.toJson(),
'mostPlayedCustomisStartOfDay': mostPlayedCustomisStartOfDay.value,
'ytMostPlayedTimeRange': ytMostPlayedTimeRange.value.convertToString,
'ytMostPlayedCustomDateRange': ytMostPlayedCustomDateRange.value.toJson(),
'ytMostPlayedCustomisStartOfDay': ytMostPlayedCustomisStartOfDay.value,

/// Track Items
'displayThirdRow': displayThirdRow.value,
Expand Down Expand Up @@ -813,13 +824,16 @@ class SettingsController {
bool? localVideoMatchingCheckSameDir,
RepeatMode? playerRepeatMode,
TrackPlayMode? trackPlayMode,
MostPlayedTimeRange? mostPlayedTimeRange,
NotificationTapAction? onNotificationTapAction,
OnYoutubeLinkOpenAction? onYoutubeLinkOpen,
PerformanceMode? performanceMode,
KillAppMode? killPlayerAfterDismissingAppMode,
MostPlayedTimeRange? mostPlayedTimeRange,
DateRange? mostPlayedCustomDateRange,
bool? mostPlayedCustomisStartOfDay,
MostPlayedTimeRange? ytMostPlayedTimeRange,
DateRange? ytMostPlayedCustomDateRange,
bool? ytMostPlayedCustomisStartOfDay,
bool? didSupportNamida,
}) {
if (selectedLanguage != null) {
Expand Down Expand Up @@ -1276,9 +1290,6 @@ class SettingsController {
if (trackPlayMode != null) {
this.trackPlayMode.value = trackPlayMode;
}
if (mostPlayedTimeRange != null) {
this.mostPlayedTimeRange.value = mostPlayedTimeRange;
}
if (onNotificationTapAction != null) {
this.onNotificationTapAction.value = onNotificationTapAction;
}
Expand All @@ -1291,12 +1302,24 @@ class SettingsController {
if (killPlayerAfterDismissingAppMode != null) {
this.killPlayerAfterDismissingAppMode.value = killPlayerAfterDismissingAppMode;
}
if (mostPlayedTimeRange != null) {
this.mostPlayedTimeRange.value = mostPlayedTimeRange;
}
if (mostPlayedCustomDateRange != null) {
this.mostPlayedCustomDateRange.value = mostPlayedCustomDateRange;
}
if (mostPlayedCustomisStartOfDay != null) {
this.mostPlayedCustomisStartOfDay.value = mostPlayedCustomisStartOfDay;
}
if (ytMostPlayedTimeRange != null) {
this.ytMostPlayedTimeRange.value = ytMostPlayedTimeRange;
}
if (ytMostPlayedCustomDateRange != null) {
this.ytMostPlayedCustomDateRange.value = ytMostPlayedCustomDateRange;
}
if (ytMostPlayedCustomisStartOfDay != null) {
this.ytMostPlayedCustomisStartOfDay.value = ytMostPlayedCustomisStartOfDay;
}

if (didSupportNamida != null) {
this.didSupportNamida = didSupportNamida;
Expand Down
1 change: 0 additions & 1 deletion lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import 'dart:io';

import 'package:catcher/catcher.dart';
import 'package:external_path/external_path.dart';
import 'package:flutter/gestures.dart';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:flutter_local_notifications/flutter_local_notifications.dart';
Expand Down
195 changes: 195 additions & 0 deletions lib/ui/pages/subpages/most_played_subpage.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,195 @@
import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:history_manager/history_manager.dart';

import 'package:namida/controller/current_color.dart';
import 'package:namida/controller/navigator_controller.dart';
import 'package:namida/core/dimensions.dart';
import 'package:namida/core/extensions.dart';
import 'package:namida/core/functions.dart';
import 'package:namida/core/icon_fonts/broken_icons.dart';
import 'package:namida/core/namida_converter_ext.dart';
import 'package:namida/core/translations/language.dart';
import 'package:namida/ui/widgets/custom_widgets.dart';

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

const MostPlayedItemsPage({
super.key,
required this.historyController,
required this.isTimeRangeChipEnabled,
required this.onSavingTimeRange,
required this.itemExtents,
required this.header,
required this.itemBuilder,
required this.customDateRange,
});

void _onSelectingTimeRange({
required MostPlayedTimeRange? mptr,
DateRange? dateCustom,
bool? isStartOfDay,
}) {
onSavingTimeRange(mptr: mptr, dateCustom: dateCustom, isStartOfDay: isStartOfDay);

historyController.updateTempMostPlayedPlaylist(
mptr: mptr,
customDateRange: dateCustom,
isStartOfDay: isStartOfDay,
);
NamidaNavigator.inst.closeDialog();
}

bool _isEnabled(MostPlayedTimeRange type) => isTimeRangeChipEnabled(type);

Widget _getChipChild({
required BuildContext context,
DateRange? dateCustom,
required MostPlayedTimeRange mptr,
Widget? Function(Color? textColor)? trailing,
}) {
final dateText = dateCustom == null || dateCustom == DateRange.dummy()
? null
: "${dateCustom.oldest.millisecondsSinceEpoch.dateFormattedOriginalNoYears(dateCustom.newest)} → ${dateCustom.newest.millisecondsSinceEpoch.dateFormattedOriginalNoYears(dateCustom.oldest)}";

final textColor = _isEnabled(mptr) ? const Color.fromARGB(200, 255, 255, 255) : null;
return Padding(
padding: const EdgeInsets.symmetric(horizontal: 2.0),
child: GestureDetector(
onTap: () => _onSelectingTimeRange(
dateCustom: dateCustom,
mptr: mptr,
),
child: AnimatedContainer(
duration: const Duration(milliseconds: 250),
padding: const EdgeInsets.symmetric(horizontal: 12.0, vertical: 6.0),
decoration: BoxDecoration(
color: _isEnabled(mptr) ? CurrentColor.inst.currentColorScheme.withAlpha(160) : context.theme.cardColor,
borderRadius: BorderRadius.circular(8.0.multipliedRadius),
),
child: Row(
children: [
Text(
dateText ?? mptr.toText(),
style: context.textTheme.displaySmall?.copyWith(
color: textColor,
fontSize: dateText == null ? null : 12.0.multipliedFontScale,
fontWeight: FontWeight.w600,
),
),
if (trailing != null) ...[
const SizedBox(width: 2.0),
trailing(textColor)!,
]
],
),
),
),
);
}

@override
Widget build(BuildContext context) {
return BackgroundWrapper(
child: Obx(
() {
final finalListenMap = historyController.currentTopTracksMapListens;
final mostplayedOptions = List<MostPlayedTimeRange>.from(MostPlayedTimeRange.values)..remove(MostPlayedTimeRange.custom);
final bottomWidget = Padding(
padding: const EdgeInsets.symmetric(vertical: 8.0),
child: Row(
children: [
const SizedBox(width: 8.0),
NamidaInkWell(
animationDurationMS: 200,
borderRadius: 6.0,
bgColor: context.theme.cardTheme.color,
padding: const EdgeInsets.all(8.0),
decoration: BoxDecoration(
border: _isEnabled(MostPlayedTimeRange.custom) ? Border.all(color: CurrentColor.inst.color) : null,
borderRadius: BorderRadius.circular(8.0.multipliedRadius),
),
child: Row(
children: [
const Icon(Broken.calendar, size: 18.0),
const SizedBox(width: 4.0),
Text(
lang.CUSTOM,
style: context.textTheme.displayMedium,
),
const SizedBox(width: 4.0),
const Icon(Broken.arrow_down_2, size: 14.0),
],
),
onTap: () {
showCalendarDialog(
title: lang.CHOOSE,
buttonText: lang.CONFIRM,
useHistoryDates: true,
onGenerate: (dates) => _onSelectingTimeRange(
dateCustom: DateRange(oldest: dates.first, newest: dates.last),
mptr: MostPlayedTimeRange.custom,
),
);
},
),
const SizedBox(width: 4.0),
Expanded(
child: SingleChildScrollView(
scrollDirection: Axis.horizontal,
child: Row(
children: [
Obx(
() {
final dateRange = customDateRange.value;
return _getChipChild(
context: context,
mptr: MostPlayedTimeRange.custom,
dateCustom: dateRange,
trailing: (textColor) => NamidaIconButton(
padding: EdgeInsets.zero,
icon: Broken.close_circle,
iconSize: 14.0,
iconColor: textColor,
onPressed: () => _onSelectingTimeRange(mptr: MostPlayedTimeRange.allTime, dateCustom: DateRange.dummy()),
),
).animateEntrance(
showWhen: dateRange.oldest != DateTime(0),
durationMS: 400,
reverseDurationMS: 200,
);
},
),
...mostplayedOptions.map(
(action) => _getChipChild(
context: context,
mptr: action,
),
),
],
),
),
),
],
),
);
const bottomPadding = 0.0;
return NamidaListView(
itemExtents: itemExtents,
header: header(bottomWidget, bottomPadding),
padding: const EdgeInsets.only(bottom: kBottomPadding),
itemCount: finalListenMap.length,
itemBuilder: (context, i) => itemBuilder(context, i, finalListenMap),
);
},
),
);
}
}
Loading

0 comments on commit 493800c

Please sign in to comment.