-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fixed bug of get_application_document_directory which always changes …
…whenever app restarts in ios -> added feature for checking paths in ios
- Loading branch information
Showing
9 changed files
with
55 additions
and
25 deletions.
There are no files selected for viewing
47 changes: 41 additions & 6 deletions
47
...loads/data/sources/get_downloaded_files_source/impl/get_downloaded_files_source_impl.dart
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,29 +1,64 @@ | ||
import 'dart:io'; | ||
|
||
import 'package:flutter/foundation.dart'; | ||
import 'package:path_provider/path_provider.dart'; | ||
import 'package:youtube/core/db/base_downloaded_file_model/base_downloaded_file_model.dart'; | ||
import 'package:youtube/core/db/db_floor.dart'; | ||
import 'package:youtube/features/library_downloads/data/sources/get_downloaded_files_source/get_downloaded_files_source.dart'; | ||
import 'package:youtube/utils/mixins/storage_helper.dart'; | ||
import 'package:youtube/utils/regex_helper/regex_helper.dart'; | ||
import 'package:youtube/x_injection_containers/injection_container.dart'; | ||
import 'package:collection/collection.dart'; | ||
|
||
class GetDownloadedFilesSourceImpl | ||
with StorageHelper, RegexHelper | ||
implements GetDownloadedFilesSource { | ||
|
||
class GetDownloadedFilesSourceImpl with StorageHelper implements GetDownloadedFilesSource { | ||
// Override the loadDownloadFiles method from the GetDownloadedFilesSource interface | ||
@override | ||
Future<List<BaseDownloadedFileModel>> loadDownloadFiles() async { | ||
|
||
// Get the directory for external storage (could be null if not available) | ||
final Directory? externalStorage = await getStorage(); | ||
|
||
// List all files in the external storage directory and convert them to a list | ||
var dataFromStorage = await externalStorage?.list().toList(); | ||
|
||
// Retrieve the list of downloaded files from the database using the locator pattern | ||
var dataFromDb = await locator<DbFloor>().downloadedFiles.getDownloadedFiles(); | ||
|
||
// Loop through each downloaded file in the database | ||
for (int i = 0; i < dataFromDb.length; i++) { | ||
if (!(dataFromStorage ?? []).any((el) => el.path == dataFromDb[i].downloadedPath)) { | ||
dataFromDb.removeAt(i); | ||
i--; | ||
|
||
// Check if the current platform is iOS | ||
if (defaultTargetPlatform == TargetPlatform.iOS) { | ||
|
||
// Find the corresponding file in external storage by matching the videoId in the path | ||
final findPath = (dataFromStorage ?? <FileSystemEntity>[]).firstWhereOrNull( | ||
(e) => e.path.contains( | ||
"videoId_${videoIdFromStorageSavedData(dataFromDb[i].downloadedPath ?? '')}"), | ||
); | ||
|
||
// If a matching file is found, update the path in the database model | ||
if (findPath != null) { | ||
dataFromDb[i].downloadedPath = findPath.path; | ||
} | ||
} else { | ||
|
||
// If not on iOS, check if the file exists in the external storage | ||
if (!(dataFromStorage ?? []).any((el) => el.path == dataFromDb[i].downloadedPath)) { | ||
|
||
// If the file doesn't exist, remove it from the database list | ||
dataFromDb.removeAt(i); | ||
|
||
// Decrement the index to adjust for the removed item | ||
i--; | ||
} | ||
} | ||
} | ||
|
||
// Reverse the order of the list (newest files first) | ||
dataFromDb = dataFromDb.reversed.toList(); | ||
|
||
// Return the list of downloaded files | ||
return dataFromDb; | ||
} | ||
} |
1 change: 0 additions & 1 deletion
1
lib/features/library_screen/presentation/bloc/history_bloc/history_bloc.dart
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
9 changes: 5 additions & 4 deletions
9
...deo_player_screen/cubit/domain/usecases/download_audio/download_audio_in_app_storage.dart
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
6 changes: 0 additions & 6 deletions
6
lib/features/youtube_video_player_screen/presentation/video_screen_player.dart
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
1 change: 0 additions & 1 deletion
1
lib/features/youtube_video_player_screen/services/music_background_service.dart
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,3 @@ | ||
import 'dart:io'; | ||
|
||
import 'package:flutter/cupertino.dart'; | ||
import 'package:just_audio/just_audio.dart'; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters