Skip to content

Commit

Permalink
download playlist metadata only after logging in
Browse files Browse the repository at this point in the history
- also reworded the download item name for it
  • Loading branch information
Chaphasilor committed Nov 3, 2024
1 parent cfc7fea commit 45d51cf
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 11 deletions.
2 changes: 1 addition & 1 deletion lib/l10n/app_en.arb
Original file line number Diff line number Diff line change
Expand Up @@ -1357,7 +1357,7 @@
},
"description": "Tooltip for downloadbutton on incidental downloads, which show a lock icon. It says one of the requiring downloads."
},
"finampCollectionNames": "{itemType, select, favorites{Favorites} allPlaylists{All Playlists} fiveLatestAlbums{5 Latest Albums} allPlaylistsMetadata{Info for All Playlists} other{{itemType}} }",
"finampCollectionNames": "{itemType, select, favorites{Favorites} allPlaylists{All Playlists} fiveLatestAlbums{5 Latest Albums} allPlaylistsMetadata{Playlist Metadata} other{{itemType}} }",
"@finampCollectionNames": {
"placeholders": {
"itemType": {
Expand Down
9 changes: 7 additions & 2 deletions lib/models/finamp_models.dart
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,7 @@ const _showStopButtonOnMediaNotificationDefault = false;
const _showSeekControlsOnMediaNotificationDefault = true;
const _keepScreenOnOption = KeepScreenOnOption.whileLyrics;
const _keepScreenOnWhilePluggedIn = true;
const _hasDownloadedPlaylistInfoDefault = false;

@HiveType(typeId: 28)
class FinampSettings {
Expand Down Expand Up @@ -157,7 +158,7 @@ class FinampSettings {
this.autoloadLastQueueOnStartup = _autoLoadLastQueueOnStartup,
this.hasCompletedBlurhashImageMigration = true,
this.hasCompletedBlurhashImageMigrationIdFix = true,
this.hasCompleteddownloadsServiceMigration = true,
this.hasCompleteddownloadsServiceMigration = false,
this.requireWifiForDownloads = false,
this.onlyShowFullyDownloaded = false,
this.showDownloadsWithUnknownLibrary = true,
Expand Down Expand Up @@ -196,7 +197,8 @@ class FinampSettings {
this.showSeekControlsOnMediaNotification =
_showSeekControlsOnMediaNotificationDefault,
this.keepScreenOnOption = _keepScreenOnOption,
this.keepScreenOnWhilePluggedIn = _keepScreenOnWhilePluggedIn});
this.keepScreenOnWhilePluggedIn = _keepScreenOnWhilePluggedIn,
this.hasDownloadedPlaylistInfo = false});

@HiveField(0, defaultValue: _isOfflineDefault)
bool isOffline;
Expand Down Expand Up @@ -433,6 +435,9 @@ class FinampSettings {
@HiveField(73, defaultValue: _keepScreenOnWhilePluggedIn)
bool keepScreenOnWhilePluggedIn;

@HiveField(74, defaultValue: _hasDownloadedPlaylistInfoDefault)
bool hasDownloadedPlaylistInfo;

static Future<FinampSettings> create() async {
final downloadLocation = await DownloadLocation.create(
name: "Internal Storage",
Expand Down
12 changes: 12 additions & 0 deletions lib/screens/music_screen.dart
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import 'package:get_it/get_it.dart';
import 'package:hive/hive.dart';
import 'package:logging/logging.dart';

import 'package:finamp/services/downloads_service.dart';
import '../components/MusicScreen/music_screen_drawer.dart';
import '../components/MusicScreen/music_screen_tab_view.dart';
import '../components/MusicScreen/sort_by_menu_button.dart';
Expand All @@ -21,6 +22,16 @@ import '../services/finamp_settings_helper.dart';
import '../services/finamp_user_helper.dart';
import '../services/jellyfin_api_helper.dart';

void postLaunchHook() async {
final downloadsService = GetIt.instance<DownloadsService>();

// make sure playlist info is downloaded for users upgrading from older versions and new installations AFTER logging in and selecting their libraries/views
if (!FinampSettingsHelper.finampSettings.hasDownloadedPlaylistInfo) {
await downloadsService.addDefaultPlaylistInfoDownload();
FinampSettingsHelper.setHasDownloadedPlaylistInfo(true);
}
}

class MusicScreen extends ConsumerStatefulWidget {
const MusicScreen({super.key});

Expand Down Expand Up @@ -92,6 +103,7 @@ class _MusicScreenState extends ConsumerState<MusicScreen>
@override
void initState() {
super.initState();
postLaunchHook();
}

@override
Expand Down
21 changes: 13 additions & 8 deletions lib/services/downloads_service.dart
Original file line number Diff line number Diff line change
Expand Up @@ -1012,7 +1012,6 @@ class DownloadsService {
/// always be re-run later by the user. Note that the existing hive metadata is
/// not deleted by this migration, we just stop using it.
Future<void> migrateFromHive() async {
final finampUserHelper = GetIt.instance<FinampUserHelper>();
if (FinampSettingsHelper.finampSettings.downloadLocationsMap.values
.where((element) =>
element.baseDirectory == DownloadLocationType.internalSupport)
Expand All @@ -1038,13 +1037,6 @@ class DownloadsService {
content: Text(AppLocalizations.of(scaffold)!.runRepairWarning),
duration: const Duration(seconds: 20)));
}));

// Automatically download playlist metadata (to enhance the playlist actions dialog and offline mode)
unawaited(addDownload(
stub: DownloadStub.fromFinampCollection(FinampCollection(type: FinampCollectionType.allPlaylistsMetadata)),
viewId: finampUserHelper.currentUser!.currentViewId!,
transcodeProfile: DownloadProfile(transcodeCodec: FinampTranscodingCodec.original),
));
}

/// Substep 1 of [migrateFromHive].
Expand Down Expand Up @@ -1232,6 +1224,19 @@ class DownloadsService {
}
}

Future<void> addDefaultPlaylistInfoDownload() async {
final finampUserHelper = GetIt.instance<FinampUserHelper>();

// Automatically download playlist metadata (to enhance the playlist actions dialog and offline mode)
await addDownload(
stub: DownloadStub.fromFinampCollection(
FinampCollection(type: FinampCollectionType.allPlaylistsMetadata)),
viewId: finampUserHelper.currentUser!.currentViewId!,
transcodeProfile:
DownloadProfile(transcodeCodec: FinampTranscodingCodec.original),
);
}

/// Get all user-downloaded items. Used to show items on downloads screen.
List<DownloadStub> getUserDownloaded() => getVisibleChildren(_anchor);

Expand Down
7 changes: 7 additions & 0 deletions lib/services/finamp_settings_helper.dart
Original file line number Diff line number Diff line change
Expand Up @@ -305,6 +305,13 @@ class FinampSettingsHelper {
.put("FinampSettings", finampSettingsTemp);
}

static void setHasDownloadedPlaylistInfo(bool hasDownloadedPlaylistInfo) {
FinampSettings finampSettingsTemp = finampSettings;
finampSettingsTemp.hasDownloadedPlaylistInfo = hasDownloadedPlaylistInfo;
Hive.box<FinampSettings>("FinampSettings")
.put("FinampSettings", finampSettingsTemp);
}

static void setTabOrder(List<TabContentType> newTabOrder) {
FinampSettings finampSettingsTemp = finampSettings;
finampSettingsTemp.tabOrder = newTabOrder;
Expand Down

0 comments on commit 45d51cf

Please sign in to comment.