diff --git a/android/app/build.gradle b/android/app/build.gradle index 7b3ce58..71df5dc 100644 --- a/android/app/build.gradle +++ b/android/app/build.gradle @@ -47,8 +47,8 @@ android { applicationId "com.example.traderscircuit" // You can update the following values to match your application needs. // For more information, see: https://docs.flutter.dev/deployment/android#reviewing-the-gradle-build-configuration. - minSdkVersion 21 - targetSdkVersion flutter.targetSdkVersion + minSdkVersion 24 + targetSdkVersion 33 versionCode flutterVersionCode.toInteger() versionName flutterVersionName } diff --git a/android/app/src/main/AndroidManifest.xml b/android/app/src/main/AndroidManifest.xml index 6a60234..c21d2f1 100644 --- a/android/app/src/main/AndroidManifest.xml +++ b/android/app/src/main/AndroidManifest.xml @@ -1,10 +1,17 @@ + + + + + + networkImageToMultipartFile( @@ -61,4 +66,112 @@ class Utils { barrierDismissible: false, ); } + + static Future getStoragePermission() async { + DeviceInfoPlugin plugin = DeviceInfoPlugin(); + AndroidDeviceInfo android = await plugin.androidInfo; + if (android.version.sdkInt < 33) { + if (await Permission.storage.request().isGranted) { + // setState(() { + // permissionGranted = true; + // }); + } else if (await Permission.storage.request().isPermanentlyDenied) { + await openAppSettings(); + await showToast("Permission denied."); + } + // else if (await Permission.audio.request().isDenied) { + // // setState(() { + // // permissionGranted = false; + // // }); + // } + } else { + if (await Permission.photos.request().isGranted) { + // await utils.showToast("Permission granted."); + // setState(() { + // permissionGranted = true; + // }); + } else if (await Permission.photos.request().isPermanentlyDenied) { + await openAppSettings(); + await showToast("Permission denied."); + } else if (await Permission.photos.request().isDenied) { + await openAppSettings(); + await showToast("Permission denied."); + // setState(() { + // permissionGranted = false; + // }); + } + } + } + + static Future openFile({ + required String url, + String? fileName, + }) async { + var status; + // Permission.manageExternalStorage.request(); + final deviceInfo = await DeviceInfoPlugin().androidInfo; + if (deviceInfo.version.sdkInt > 32) { + status = await Permission.photos.request().isGranted; + + await Permission.manageExternalStorage.request(); + } else { + status = await Permission.storage.request().isGranted; + await Permission.manageExternalStorage.request(); + } + if (status) { + await downloadFile(url, fileName!); + // if (file == null) { + // log("Error 3333333333333"); + // } else { + // await OpenFile.open(file.path).then((value) { + // print("RUNNING THIS"); + // if (value.type == ResultType.noAppToOpen) { + // ScaffoldMessenger.of(context).showSnackBar(Helper.displaySnackBar( + // "type", + // "error", + // "You do not have any application to open this file")); + + // //Navigator.pop(context); + // } else { + // log(value.message); + // } + // }); + + // // if (message.toString() != "done") { + // // displaySnackBar("login", "error", message.message.toString()); + // // } + // } + } else { + openAppSettings(); + } + } + + static Future downloadFile(String url, String name) async { + final appStorage = Directory("/storage/emulated/0/Download"); + final file = File('${appStorage.path}/$name'); + + try { + showToast("Downloading..."); + final response = await Dio().get( + url, + options: Options( + // headers: requestHeaders, + responseType: ResponseType.bytes, + followRedirects: false, + // receiveTimeout: 0, + ), + ); + final raf = file.openSync(mode: FileMode.write); + raf.writeFromSync(response.data); + await raf.close(); + showToast("Download Completed !"); + + return file; + } catch (e) { + log(e.toString()); + showToast("Download Error! Please try again"); + + return null; + } + } } diff --git a/lib/controller/content_bytes_controller.dart b/lib/controller/content_bytes_controller.dart index bfb083f..a76454c 100644 --- a/lib/controller/content_bytes_controller.dart +++ b/lib/controller/content_bytes_controller.dart @@ -40,13 +40,14 @@ class ContentBytesController extends GetxController { super.dispose(); } - void init(index) async { + void init(index, type) async { audioPlayer = AudioPlayer(); isAudioInitialize = true; indexForAudios.value = index; try { - log(index.toString()); - await audioPlayer.setUrl(contentBytesModel.data!.audio![index].link!); + await audioPlayer.setUrl(type == "new" + ? contentBytesModel.data!.newReleaseAudio![index].link! + : contentBytesModel.data!.audio![index].link!); // await audioPlayer.setAsset(url); } on PlayerException catch (e) { print("Error code: ${e.code}"); @@ -75,7 +76,7 @@ class ContentBytesController extends GetxController { } else if (processingState != ProcessingState.completed) { buttonNotifier.value = ButtonState.playing; } else { - _playNextTrack(); + // _playNextTrack(type); // audioPlayer.seek(Duration.zero); // audioPlayer.pause(); @@ -110,7 +111,7 @@ class ContentBytesController extends GetxController { }); } - void _playNextTrack() { + void _playNextTrack(type) { // Determine the index of the next track (you need to implement this logic) int nextIndex = getNextTrackIndex(); @@ -120,7 +121,7 @@ class ContentBytesController extends GetxController { if (isPlaying()) { stop(); } - init(nextIndex); + init(nextIndex, type); play(nextIndex); } else { audioPlayer.seek(Duration.zero); @@ -184,41 +185,4 @@ class ContentBytesController extends GetxController { titlePlayingList![index] = true; } } - - // RxList