Skip to content

Commit

Permalink
feat(yt) subscription groups
Browse files Browse the repository at this point in the history
(saved locally)
  • Loading branch information
MSOB7YY committed Jul 16, 2024
1 parent adea6db commit 6bd6013
Show file tree
Hide file tree
Showing 9 changed files with 296 additions and 127 deletions.
1 change: 1 addition & 0 deletions lib/controller/backup_controller.dart
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ class BackupController {
AppPaths.LATEST_QUEUE,
AppPaths.YT_LIKES_PLAYLIST,
AppPaths.YT_SUBSCRIPTIONS,
AppPaths.YT_SUBSCRIPTIONS_GROUPS_ALL,
AppDirs.PLAYLISTS,
AppDirs.HISTORY_PLAYLIST,
AppDirs.QUEUES,
Expand Down
1 change: 1 addition & 0 deletions lib/core/constants.dart
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,7 @@ class AppPaths {
// ================= Youtube =================
static final YT_LIKES_PLAYLIST = '${AppDirs.YOUTUBE_MAIN_DIRECTORY}/yt_likes.json';
static final YT_SUBSCRIPTIONS = '${AppDirs.YOUTUBE_MAIN_DIRECTORY}/yt_subs.json';
static final YT_SUBSCRIPTIONS_GROUPS_ALL = '${AppDirs.YOUTUBE_MAIN_DIRECTORY}/yt_sub_groups.json';
}

/// Directories used by Namida
Expand Down
3 changes: 3 additions & 0 deletions lib/core/translations/keys.dart
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ abstract class LanguageKeys {
String get ADD_MORE_FROM_THIS_ARTIST => _getKey('ADD_MORE_FROM_THIS_ARTIST');
String get ADD_MORE_FROM_THIS_FOLDER => _getKey('ADD_MORE_FROM_THIS_FOLDER');
String get ADD_MORE_FROM_TO_QUEUE => _getKey('ADD_MORE_FROM_TO_QUEUE');
String get ADD_TO_FAVOURITES => _getKey('ADD_TO_FAVOURITES');
String get ADD_TO_PLAYLIST => _getKey('ADD_TO_PLAYLIST');
String get ADD => _getKey('ADD');
String get ADDED => _getKey('ADDED');
Expand Down Expand Up @@ -275,6 +276,7 @@ abstract class LanguageKeys {
String get GO_TO_CHANNEL => _getKey('GO_TO_CHANNEL');
String get GO_TO_FOLDER => _getKey('GO_TO_FOLDER');
String get GRANT_STORAGE_PERMISSION => _getKey('GRANT_STORAGE_PERMISSION');
String get GROUP => _getKey('GROUP');
String get GROUP_ARTWORKS_BY_ALBUM => _getKey('GROUP_ARTWORKS_BY_ALBUM');
String get GUIDE => _getKey('GUIDE');
String get HEIGHT_OF_ALBUM_TILE => _getKey('HEIGHT_OF_ALBUM_TILE');
Expand Down Expand Up @@ -518,6 +520,7 @@ abstract class LanguageKeys {
String get REMOVE_WHITESPACES => _getKey('REMOVE_WHITESPACES');
String get REMOVE => _getKey('REMOVE');
String get REMOVED => _getKey('REMOVED');
String get REMOVE_FROM_FAVOURITES => _getKey('REMOVE_FROM_FAVOURITES');
String get RENAME => _getKey('RENAME');
String get RENAME_PLAYLIST => _getKey('RENAME_PLAYLIST');
String get REORDERABLE => _getKey('REORDERABLE');
Expand Down
62 changes: 36 additions & 26 deletions lib/ui/widgets/custom_widgets.dart
Original file line number Diff line number Diff line change
Expand Up @@ -768,6 +768,7 @@ class ListTileWithCheckMark extends StatelessWidget {
final Widget? leading;
final double? iconSize;
final bool dense;
final bool expanded;

const ListTileWithCheckMark({
super.key,
Expand All @@ -776,18 +777,38 @@ class ListTileWithCheckMark extends StatelessWidget {
this.onTap,
this.title,
this.subtitle = '',
this.icon,
this.icon = Broken.arrange_circle,
this.tileColor,
this.titleWidget,
this.leading,
this.iconSize,
this.dense = false,
this.expanded = true,
});

@override
Widget build(BuildContext context) {
final tileAlpha = context.isDarkMode ? 5 : 20;
final br = BorderRadius.circular(14.0.multipliedRadius);
final titleWidgetFinal = Padding(
padding: EdgeInsets.symmetric(horizontal: dense ? 10.0 : 14.0),
child: Column(
mainAxisSize: MainAxisSize.min,
crossAxisAlignment: CrossAxisAlignment.start,
children: [
titleWidget ??
Text(
title ?? lang.REVERSE_ORDER,
style: context.textTheme.displayMedium,
),
if (subtitle != '')
Text(
subtitle,
style: context.textTheme.displaySmall,
)
],
),
);
return Material(
borderRadius: br,
color: tileColor ?? Color.alphaBlend(context.theme.colorScheme.onSurface.withAlpha(tileAlpha), context.theme.cardTheme.color!),
Expand All @@ -797,33 +818,22 @@ class ListTileWithCheckMark extends StatelessWidget {
child: Padding(
padding: const EdgeInsets.symmetric(horizontal: 12.0, vertical: 8.0),
child: Row(
mainAxisSize: expanded ? MainAxisSize.max : MainAxisSize.min,
children: [
leading ??
Icon(
icon ?? Broken.arrange_circle,
size: iconSize,
),
Expanded(
child: Padding(
padding: EdgeInsets.symmetric(horizontal: dense ? 10.0 : 14.0),
child: Column(
mainAxisSize: MainAxisSize.min,
crossAxisAlignment: CrossAxisAlignment.start,
children: [
titleWidget ??
Text(
title ?? lang.REVERSE_ORDER,
style: context.textTheme.displayMedium,
),
if (subtitle != '')
Text(
subtitle,
style: context.textTheme.displaySmall,
)
],
),
if (leading != null)
leading!
else if (icon != null)
Icon(
icon,
size: iconSize,
),
),
expanded
? Expanded(
child: titleWidgetFinal,
)
: Flexible(
child: titleWidgetFinal,
),
activeRx != null
? ObxO(
rx: activeRx!,
Expand Down
1 change: 1 addition & 0 deletions lib/ui/widgets/settings/backup_restore_settings.dart
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,7 @@ class BackupAndRestore extends SettingSubpageProvider {
AppPaths.FAVOURITES_PLAYLIST,
AppPaths.YT_LIKES_PLAYLIST,
AppPaths.YT_SUBSCRIPTIONS,
AppPaths.YT_SUBSCRIPTIONS_GROUPS_ALL,
];

final totalDirs = [
Expand Down
4 changes: 4 additions & 0 deletions lib/youtube/class/youtube_subscription.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,14 @@ class YoutubeSubscription {
final String title;
final String channelID;
final bool? subscribed;
final List<String> groups;
DateTime? lastFetched;

YoutubeSubscription({
String? title,
required this.channelID,
required this.subscribed,
this.groups = const [],
this.lastFetched,
}) : title = title ?? '';

Expand All @@ -16,6 +18,7 @@ class YoutubeSubscription {
title: json['title'] ?? '',
channelID: json['channelID'] ?? '',
subscribed: json['subscribed'],
groups: (json['groups'] as List?)?.cast<String>() ?? [],
lastFetched: DateTime.fromMillisecondsSinceEpoch(json['lastFetched'] ?? 0),
);
}
Expand All @@ -25,6 +28,7 @@ class YoutubeSubscription {
"title": title,
"channelID": channelID,
"subscribed": subscribed,
"groups": groups,
"lastFetched": lastFetched?.millisecondsSinceEpoch,
};
}
Expand Down
5 changes: 5 additions & 0 deletions lib/youtube/controller/youtube_subscriptions_controller.dart
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,11 @@ class YoutubeSubscriptionsController {
return newSubscribed;
}

List<String> getGroupsForChannel(String channelId) {
final sub = availableChannels.value[channelId] ??= YoutubeSubscription(channelID: channelId, subscribed: false);
return sub.groups;
}

Future<void> sortByLastFetched() async {
_availableChannels.sortBy((e) => e.value.lastFetched ?? DateTime(0));
await saveFile();
Expand Down
Loading

0 comments on commit 6bd6013

Please sign in to comment.