Skip to content

Commit

Permalink
Use default folder for audio/video downloads on Android 12+
Browse files Browse the repository at this point in the history
  • Loading branch information
Artx-II committed Mar 26, 2024
1 parent e2d9851 commit 9e01f2f
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 2 deletions.
5 changes: 3 additions & 2 deletions lib/providers/app_settings.dart
Original file line number Diff line number Diff line change
Expand Up @@ -74,11 +74,12 @@ class AppSettings extends ChangeNotifier {
final musicPath = sharedPreferences.getString(musicDirectoryKey);
final videoPath = sharedPreferences.getString(videoDirectoryKey);
// Check for our media directories, if they're null we have to set a default path
if (musicPath == null) {
// We will also apply this default path to android sdk equal or greather than 33
if (musicPath == null || androidSdk >= 31) {
final defaultMusicDirectory = await AndroidPathProvider.musicPath;
await sharedPreferences.setString(musicDirectoryKey, defaultMusicDirectory);
}
if (videoPath == null) {
if (videoPath == null || androidSdk >= 31) {
final defaultVideoDirectory = await AndroidPathProvider.moviesPath;
await sharedPreferences.setString(videoDirectoryKey, defaultVideoDirectory);
}
Expand Down
8 changes: 8 additions & 0 deletions lib/providers/download_provider.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@ import 'dart:io';

import 'package:audio_tagger/audio_tagger.dart';
import 'package:flutter/foundation.dart';
import 'package:permission_handler/permission_handler.dart';
import 'package:provider/provider.dart';
import 'package:songtube/internal/enums/download_type.dart';
import 'package:songtube/providers/app_settings.dart';
import 'package:songtube/internal/artwork_manager.dart';
import 'package:songtube/internal/global.dart';
Expand Down Expand Up @@ -68,6 +70,12 @@ class DownloadProvider extends ChangeNotifier {

// Handle Single Video Download
Future<void> handleDownloadItem({required DownloadInfo info}) async {
if (info.downloadType == DownloadType.audio) {
await (androidSdk >= 33 ? Permission.audio.request() : Permission.storage.request());
}
if (info.downloadType == DownloadType.video) {
await (androidSdk >= 33 ? Permission.videos.request() : Permission.storage.request());
}
queue.add(await DownloadItem.buildData(info: info)
..onDownloadCancelled = (id) {
moveToCancelled(id);
Expand Down
2 changes: 2 additions & 0 deletions lib/screens/settings/download_settings.dart
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ class _DownloadSettingsState extends State<DownloadSettings> {
},
),
// Download Audio Path
if (androidSdk < 31)
SettingTile(
title: Languages.of(context)!.labelAudioFolder,
subtitle: '${Languages.of(context)!.labelCurrent}: ${AppSettings.musicDirectory.path}',
Expand All @@ -79,6 +80,7 @@ class _DownloadSettingsState extends State<DownloadSettings> {
}
),
// Download Video Path
if (androidSdk < 31)
SettingTile(
title: Languages.of(context)!.labelVideoFolder,
subtitle: '${Languages.of(context)!.labelCurrent}: ${AppSettings.videoDirectory.path}',
Expand Down

0 comments on commit 9e01f2f

Please sign in to comment.