From 3a5f62383c3f979cdc369c42f36f8acc2aa860fd Mon Sep 17 00:00:00 2001 From: Neeraj Gupta <254676+ua741@users.noreply.github.com> Date: Wed, 17 May 2023 11:02:00 +0530 Subject: [PATCH] Minor refactor --- lib/utils/delete_file_util.dart | 15 +++++---------- lib/utils/device_info.dart | 9 +++++++++ 2 files changed, 14 insertions(+), 10 deletions(-) diff --git a/lib/utils/delete_file_util.dart b/lib/utils/delete_file_util.dart index 6bdff87d1..a877275e7 100644 --- a/lib/utils/delete_file_util.dart +++ b/lib/utils/delete_file_util.dart @@ -3,7 +3,6 @@ import 'dart:io' as io; import 'dart:io'; import 'dart:math'; -import 'package:device_info/device_info.dart'; import 'package:flutter/material.dart'; import 'package:logging/logging.dart'; import 'package:photo_manager/photo_manager.dart'; @@ -25,6 +24,7 @@ import 'package:photos/ui/common/linear_progress_dialog.dart'; import 'package:photos/ui/components/action_sheet_widget.dart'; import 'package:photos/ui/components/buttons/button_widget.dart'; import 'package:photos/ui/components/models/button_type.dart'; +import "package:photos/utils/device_info.dart"; import 'package:photos/utils/dialog_util.dart'; import 'package:photos/utils/file_util.dart'; import 'package:photos/utils/toast_util.dart'; @@ -330,15 +330,10 @@ Future deleteLocalFiles( } deletedIDs.addAll(await _tryDeleteSharedMediaFiles(localSharedMediaIDs)); - if (Platform.isAndroid) { - final androidInfo = await DeviceInfoPlugin().androidInfo; - if (androidInfo.version.sdkInt < android11SDKINT) { - deletedIDs - .addAll(await deleteLocalFilesInBatches(context, localAssetIDs)); - } else { - deletedIDs - .addAll(await _deleteLocalFilesInOneShot(context, localAssetIDs)); - } + final bool shouldDeleteInBatches = + await isAndroidSDKVersionLowerThan(android11SDKINT); + if (shouldDeleteInBatches) { + deletedIDs.addAll(await deleteLocalFilesInBatches(context, localAssetIDs)); } else { deletedIDs.addAll(await _deleteLocalFilesInOneShot(context, localAssetIDs)); } diff --git a/lib/utils/device_info.dart b/lib/utils/device_info.dart index c14de5929..1bb2a5ac4 100644 --- a/lib/utils/device_info.dart +++ b/lib/utils/device_info.dart @@ -42,3 +42,12 @@ Future isLowSpecDevice() async { } return false; } + +Future isAndroidSDKVersionLowerThan(int inputSDK) async { + if (Platform.isAndroid) { + final AndroidDeviceInfo androidInfo = await deviceInfoPlugin.androidInfo; + return androidInfo.version.sdkInt < inputSDK; + } else { + return false; + } +}