From e320fec8f63bd11bd8bf280e7d7915a1aa9e6417 Mon Sep 17 00:00:00 2001 From: Bartek Pacia Date: Sun, 12 Mar 2023 14:28:07 +0100 Subject: [PATCH 01/16] fix CI misbehaving (#833) --- .github/workflows/prepare.yaml | 3 +-- .github/workflows/publish.yaml | 17 ++++++++++++----- 2 files changed, 13 insertions(+), 7 deletions(-) diff --git a/.github/workflows/prepare.yaml b/.github/workflows/prepare.yaml index 0a39796b..88a8621e 100644 --- a/.github/workflows/prepare.yaml +++ b/.github/workflows/prepare.yaml @@ -5,7 +5,7 @@ on: push: branches: [master] # don't run this workflow on version tags - tags-ignore: ["v*"] + tags-ignore: ['v*'] pull_request_target: branches: [master] @@ -20,7 +20,6 @@ jobs: include: - version: 3.0.0 - channel: stable - - channel: beta steps: - name: Clone repository diff --git a/.github/workflows/publish.yaml b/.github/workflows/publish.yaml index 536a5267..80e6fbe9 100644 --- a/.github/workflows/publish.yaml +++ b/.github/workflows/publish.yaml @@ -2,7 +2,7 @@ name: publish on: push: - tags: ["v*"] + tags: ['v*'] jobs: main: @@ -12,10 +12,17 @@ jobs: - name: Checkout uses: actions/checkout@v3 - - name: Setup Dart + # This action adds a token needed for pub.dev + - name: Set up Dart uses: dart-lang/setup-dart@v1 with: - sdk: 2.17.0 + sdk: stable + + - name: Set up Flutter + uses: subosito/flutter-action@v2 + with: + channel: stable + cache: true - name: Install mobile-tools uses: actions/checkout@v3 @@ -41,11 +48,11 @@ jobs: echo "IS_PRERELEASE=$(is_prerelease flutter_downloader $tag)" >> $GITHUB_ENV - name: Publish - run: dart pub publish -f + run: dart pub publish --force - name: Create release uses: softprops/action-gh-release@v1 with: name: ${{ github.ref_name }} - body: "[See changelog on pub.dev](${{ env.RELEASE_NOTES }})" + body: '[See changelog on pub.dev](${{ env.RELEASE_NOTES }})' prerelease: ${{ env.IS_PRERELEASE }} From a630b1c88e634e11f2048e1bf4a4c6fcedbe6283 Mon Sep 17 00:00:00 2001 From: jackleemeta Date: Sun, 12 Mar 2023 21:31:34 +0800 Subject: [PATCH 02/16] Feature/send message by int on port (#824) * feat: send message by `int` on port * docs: Update README.md --- README.md | 4 ++-- example/lib/home_page.dart | 4 ++-- lib/src/callback_dispatcher.dart | 4 +--- lib/src/downloader.dart | 7 +++---- 4 files changed, 8 insertions(+), 11 deletions(-) diff --git a/README.md b/README.md index b82cffcf..c1362e1f 100644 --- a/README.md +++ b/README.md @@ -320,7 +320,7 @@ void initState() { IsolateNameServer.registerPortWithName(_port.sendPort, 'downloader_send_port'); _port.listen((dynamic data) { String id = data[0]; - DownloadTaskStatus status = data[1]; + DownloadTaskStatus status = DownloadTaskStatus(data[1]); int progress = data[2]; setState((){ }); }); @@ -335,7 +335,7 @@ void dispose() { } @pragma('vm:entry-point') -static void downloadCallback(String id, DownloadTaskStatus status, int progress) { +static void downloadCallback(String id, int status, int progress) { final SendPort send = IsolateNameServer.lookupPortByName('downloader_send_port'); send.send([id, status, progress]); } diff --git a/example/lib/home_page.dart b/example/lib/home_page.dart index 558cac35..f5043cd6 100644 --- a/example/lib/home_page.dart +++ b/example/lib/home_page.dart @@ -90,7 +90,7 @@ class _MyHomePageState extends State { @pragma('vm:entry-point') static void downloadCallback( String id, - DownloadTaskStatus status, + int status, int progress, ) { print( @@ -99,7 +99,7 @@ class _MyHomePageState extends State { ); IsolateNameServer.lookupPortByName('downloader_send_port') - ?.send([id, status.value, progress]); + ?.send([id, status, progress]); } Widget _buildDownloadList() { diff --git a/lib/src/callback_dispatcher.dart b/lib/src/callback_dispatcher.dart index a10a15b9..674b4b60 100644 --- a/lib/src/callback_dispatcher.dart +++ b/lib/src/callback_dispatcher.dart @@ -4,8 +4,6 @@ import 'dart:ui'; import 'package:flutter/services.dart'; import 'package:flutter/widgets.dart'; -import 'models.dart'; - /// Pragma annotation is needed to avoid tree shaking in release mode. See /// https://github.com/dart-lang/sdk/blob/master/runtime/docs/compiler/aot/entry_point_pragma.md @pragma('vm:entry-point') @@ -30,7 +28,7 @@ void callbackDispatcher() { final status = args[2] as int; final progress = args[3] as int; - callback(id, DownloadTaskStatus(status), progress); + callback(id, status, progress); }) ..invokeMethod('didInitializeDispatcher'); } diff --git a/lib/src/downloader.dart b/lib/src/downloader.dart index b3c06fa0..1649dba4 100644 --- a/lib/src/downloader.dart +++ b/lib/src/downloader.dart @@ -4,7 +4,6 @@ import 'dart:io'; import 'dart:ui'; import 'package:flutter/services.dart'; -import 'package:flutter/widgets.dart'; import 'package:flutter_downloader/src/exceptions.dart'; import 'callback_dispatcher.dart'; @@ -14,7 +13,7 @@ import 'models.dart'; /// with [id] changes. typedef DownloadCallback = void Function( String id, - DownloadTaskStatus status, + int status, int progress, ); @@ -396,7 +395,7 @@ class FlutterDownloader { /// IsolateNameServer.registerPortWithName(_port.sendPort, 'downloader_send_port'); /// _port.listen((dynamic data) { /// String id = data[0]; - /// DownloadTaskStatus status = data[1]; + /// DownloadTaskStatus status = DownloadTaskStatus(data[1]); /// int progress = data[2]; /// setState((){ }); /// }); @@ -406,7 +405,7 @@ class FlutterDownloader { /// ///static void downloadCallback( /// String id, - /// DownloadTaskStatus status, + /// int status, /// int progress, /// ) { /// final SendPort send = IsolateNameServer.lookupPortByName( From f0e3357c0ff97970c0972bf69fd6b41f23f7b0de Mon Sep 17 00:00:00 2001 From: James Harvey <44349936+jmshrv@users.noreply.github.com> Date: Fri, 14 Apr 2023 14:05:08 +0100 Subject: [PATCH 03/16] Check protocol when opening connection without ignoreSsl (#848) --- .../kotlin/vn/hunghd/flutterdownloader/DownloadWorker.kt | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/android/src/main/kotlin/vn/hunghd/flutterdownloader/DownloadWorker.kt b/android/src/main/kotlin/vn/hunghd/flutterdownloader/DownloadWorker.kt index 1b869589..94bd5c47 100644 --- a/android/src/main/kotlin/vn/hunghd/flutterdownloader/DownloadWorker.kt +++ b/android/src/main/kotlin/vn/hunghd/flutterdownloader/DownloadWorker.kt @@ -300,7 +300,11 @@ class DownloadWorker(context: Context, params: WorkerParameters) : resourceUrl.openConnection() as HttpURLConnection } } else { - resourceUrl.openConnection() as HttpsURLConnection + if (resourceUrl.protocol.lowercase(Locale.US) == "https") { + resourceUrl.openConnection() as HttpsURLConnection + } else { + resourceUrl.openConnection() as HttpURLConnection + } } log("Open connection to $url") httpConn.connectTimeout = timeout From 1e0994b10087a22727b3d9cd9f90920e3e89fb9c Mon Sep 17 00:00:00 2001 From: Bartek Pacia Date: Mon, 15 May 2023 01:44:07 +0200 Subject: [PATCH 04/16] Add namespace to `android/build.gradle` (#857) * add namespace to android/build.gradle * bump version to 1.10.3 --- CHANGELOG.md | 4 ++++ android/build.gradle | 2 ++ pubspec.yaml | 2 +- 3 files changed, 7 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index e4492218..ea9fa7f8 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,7 @@ +## 1.10.3 + +- Fix Android build failing when using Android Gradle Plugin v8 (#857) + ## 1.10.2 - Correctly read the error/success codes (#766) diff --git a/android/build.gradle b/android/build.gradle index 8a8d17d2..0449d605 100644 --- a/android/build.gradle +++ b/android/build.gradle @@ -30,6 +30,8 @@ rootProject.allprojects { android { compileSdk 32 + namespace "vn.hunghd.flutterdownloader" + sourceSets { main.java.srcDirs += "src/main/kotlin" } diff --git a/pubspec.yaml b/pubspec.yaml index acdb35f0..29d32687 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -1,6 +1,6 @@ name: flutter_downloader description: Powerful plugin making it easy to download files. -version: 1.10.2 +version: 1.10.3 repository: https://github.com/fluttercommunity/flutter_downloader issue_tracker: https://github.com/fluttercommunity/flutter_downloader/issues maintainer: Bartek Pacia (@bartekpacia) From c69b0cd56e79d30d03b18cd543dd83ed13a9dabe Mon Sep 17 00:00:00 2001 From: Bartek Pacia Date: Thu, 18 May 2023 23:40:30 +0200 Subject: [PATCH 05/16] Set Kotlin JVM target to 1.8 (#862) * set Kotlin JVM target to 1.8 * bump version to 1.10.4 --- CHANGELOG.md | 5 +++++ android/build.gradle | 10 +++++++++- pubspec.yaml | 2 +- 3 files changed, 15 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index ea9fa7f8..d4ef57d4 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,8 @@ +## 1.10.4 + +- Fix Android build failing because of JVM and Kotlin target source + compatibility (#862) + ## 1.10.3 - Fix Android build failing when using Android Gradle Plugin v8 (#857) diff --git a/android/build.gradle b/android/build.gradle index 0449d605..4ef5e240 100644 --- a/android/build.gradle +++ b/android/build.gradle @@ -28,9 +28,17 @@ rootProject.allprojects { } android { + namespace "vn.hunghd.flutterdownloader" compileSdk 32 - namespace "vn.hunghd.flutterdownloader" + compileOptions { + sourceCompatibility JavaVersion.VERSION_1_8 + targetCompatibility JavaVersion.VERSION_1_8 + } + + kotlinOptions { + jvmTarget = "1.8" + } sourceSets { main.java.srcDirs += "src/main/kotlin" diff --git a/pubspec.yaml b/pubspec.yaml index 29d32687..3cb00e14 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -1,6 +1,6 @@ name: flutter_downloader description: Powerful plugin making it easy to download files. -version: 1.10.3 +version: 1.10.4 repository: https://github.com/fluttercommunity/flutter_downloader issue_tracker: https://github.com/fluttercommunity/flutter_downloader/issues maintainer: Bartek Pacia (@bartekpacia) From 8fe2fffd07bc3f40f030ce01fc51d0dbc53ca0ea Mon Sep 17 00:00:00 2001 From: Bartek Pacia Date: Thu, 18 May 2023 23:45:50 +0200 Subject: [PATCH 06/16] set upper dart version constraints to 4.0.0 (#863) * set upper dart version constraints to 4.0.0 * update changelog --- CHANGELOG.md | 1 + example/pubspec.yaml | 4 ++-- pubspec.yaml | 2 +- 3 files changed, 4 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index d4ef57d4..e1f2d599 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,7 @@ - Fix Android build failing because of JVM and Kotlin target source compatibility (#862) +- Set upper Dart version constraint to `<4.0.0` (#863) ## 1.10.3 diff --git a/example/pubspec.yaml b/example/pubspec.yaml index 32a4bfa4..4df84939 100644 --- a/example/pubspec.yaml +++ b/example/pubspec.yaml @@ -4,8 +4,8 @@ version: 1.0.0+1 publish_to: none environment: - sdk: ">=2.17.0 <3.0.0" - flutter: ">=3.0.0 <4.0.0" + sdk: '>=2.17.0 <4.0.0' + flutter: '>=3.0.0' dependencies: android_path_provider: ^0.3.0 diff --git a/pubspec.yaml b/pubspec.yaml index 3cb00e14..f494386c 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -15,7 +15,7 @@ flutter: pluginClass: FlutterDownloaderPlugin environment: - sdk: '>=2.17.0 <3.0.0' + sdk: '>=2.17.0 <4.0.0' flutter: '>=3.0.0' dependencies: From b3a06410960d06c43a54b8c302ecc1d819ac68c6 Mon Sep 17 00:00:00 2001 From: Bartek Pacia Date: Wed, 12 Jul 2023 00:59:11 +0200 Subject: [PATCH 07/16] make the project compile even with the app not having dependency on Kotlin (#869) --- android/build.gradle | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/android/build.gradle b/android/build.gradle index 4ef5e240..dbcbc14b 100644 --- a/android/build.gradle +++ b/android/build.gradle @@ -3,19 +3,19 @@ buildscript { repositories { google() mavenCentral() + gradlePluginPortal() } dependencies { classpath "com.android.tools.build:gradle:7.2.2" classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version" + classpath "org.jlleitschuh.gradle:ktlint-gradle:11.0.0" } } -plugins { - id "com.android.library" - id "kotlin-android" - id "org.jlleitschuh.gradle.ktlint" version "11.0.0" -} +apply plugin: "com.android.library" +apply plugin: "kotlin-android" +apply plugin: "org.jlleitschuh.gradle.ktlint" group "vn.hunghd.flutterdownloader" version "1.0-SNAPSHOT" From 82d007849a00a8aaccaff87aee3035b9232a04d0 Mon Sep 17 00:00:00 2001 From: Bartek Pacia Date: Wed, 12 Jul 2023 01:00:08 +0200 Subject: [PATCH 08/16] bump version to 1.10.5 (#870) --- CHANGELOG.md | 5 +++++ pubspec.yaml | 2 +- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index e1f2d599..f064cf98 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,8 @@ +## 1.10.5 + +- Make the project compile when the app not doesn't have dependency on Kotlin + (#869) + ## 1.10.4 - Fix Android build failing because of JVM and Kotlin target source diff --git a/pubspec.yaml b/pubspec.yaml index f494386c..d79ee4f0 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -1,6 +1,6 @@ name: flutter_downloader description: Powerful plugin making it easy to download files. -version: 1.10.4 +version: 1.10.5 repository: https://github.com/fluttercommunity/flutter_downloader issue_tracker: https://github.com/fluttercommunity/flutter_downloader/issues maintainer: Bartek Pacia (@bartekpacia) From 40950b37e859c7f15c3e59de2ee4d04f2dc778b1 Mon Sep 17 00:00:00 2001 From: Bartek Pacia Date: Sun, 30 Jul 2023 19:55:09 +0200 Subject: [PATCH 09/16] Update GH actions (#872) * update gh actions * change from pull_request to pull_request_target --- .github/workflows/prepare.yaml | 35 +++++++++------------------------- 1 file changed, 9 insertions(+), 26 deletions(-) diff --git a/.github/workflows/prepare.yaml b/.github/workflows/prepare.yaml index 88a8621e..efff0d46 100644 --- a/.github/workflows/prepare.yaml +++ b/.github/workflows/prepare.yaml @@ -2,50 +2,34 @@ name: prepare on: workflow_dispatch: - push: - branches: [master] - # don't run this workflow on version tags - tags-ignore: ['v*'] - pull_request_target: + pull_request: branches: [master] jobs: main: - name: Flutter ${{ matrix.channel }}${{ matrix.version }} + name: Flutter ${{ matrix.flutter-version }} runs-on: ubuntu-latest strategy: fail-fast: false matrix: - include: - - version: 3.0.0 - - channel: stable + flutter-version: ['3.0.x', '3.3.x', '3.7.x', '3.10.x'] steps: - name: Clone repository uses: actions/checkout@v3 - - name: Install Flutter - uses: subosito/flutter-action@v1 + - name: Set up Flutter + uses: subosito/flutter-action@v2 with: - channel: ${{ matrix.channel }} - flutter-version: ${{ matrix.version }} - - - name: Flutter version - run: flutter --version - - - name: Cache pub dependencies - uses: actions/cache@v3 - with: - path: ${{ env.FLUTTER_HOME }}/.pub-cache - key: ${{ runner.os }}-pub-${{ hashFiles('**/pubspec.lock') }} - restore-keys: ${{ runner.os }}-pub- + flutter-version: ${{ matrix.flutter-version }} + cache: true - name: flutter pub get run: flutter pub get - - name: flutter format - run: flutter format --set-exit-if-changed . + - name: dart format + run: dart format --set-exit-if-changed . - name: flutter analyze run: flutter analyze --no-fatal-infos @@ -53,7 +37,6 @@ jobs: - name: flutter test run: flutter test - # disabled because always fails for strange reasons - name: ktlint check working-directory: example/android run: ./gradlew flutter_downloader:ktlintCheck From 15bfecd67f828dd0b362e2951b8e3475ee0083ce Mon Sep 17 00:00:00 2001 From: Bartek Pacia Date: Sun, 30 Jul 2023 20:38:39 +0200 Subject: [PATCH 10/16] Bump native Android deps (#873) * bump Gradle to 8.2.1, bump Kotlin to 1.9.0 * bump deps, set min Flutter to 3.10 * fix analyzer being angry * remove unnecessasry gradle files * fix ktlint warnings * flutter format -> dart format --- .github/workflows/prepare.yaml | 4 ++-- android/build.gradle | 10 +++++----- android/gradle.properties | 3 --- android/gradle/wrapper/gradle-wrapper.properties | 5 ----- .../vn/hunghd/flutterdownloader/DownloadWorker.kt | 2 +- .../flutterdownloader/FlutterDownloaderPlugin.kt | 2 +- .../main/kotlin/vn/hunghd/flutterdownloader/TaskDao.kt | 2 +- example/android/build.gradle | 4 ++-- .../android/gradle/wrapper/gradle-wrapper.properties | 2 +- example/lib/download_list_item.dart | 6 +++--- example/pubspec.yaml | 6 +++--- lib/src/callback_dispatcher.dart | 3 ++- lib/src/downloader.dart | 6 ++---- pubspec.yaml | 6 +++--- 14 files changed, 26 insertions(+), 35 deletions(-) delete mode 100644 android/gradle.properties delete mode 100644 android/gradle/wrapper/gradle-wrapper.properties diff --git a/.github/workflows/prepare.yaml b/.github/workflows/prepare.yaml index efff0d46..77cf8d82 100644 --- a/.github/workflows/prepare.yaml +++ b/.github/workflows/prepare.yaml @@ -13,7 +13,7 @@ jobs: strategy: fail-fast: false matrix: - flutter-version: ['3.0.x', '3.3.x', '3.7.x', '3.10.x'] + flutter-version: ['3.10.x'] steps: - name: Clone repository @@ -47,7 +47,7 @@ jobs: - name: flutter format (example app) working-directory: ./example - run: flutter format --set-exit-if-changed . + run: dart format --set-exit-if-changed . - name: flutter analyze (example app) working-directory: ./example diff --git a/android/build.gradle b/android/build.gradle index dbcbc14b..cd9b2be1 100644 --- a/android/build.gradle +++ b/android/build.gradle @@ -1,5 +1,5 @@ buildscript { - ext.kotlin_version = "1.7.22" + ext.kotlin_version = "1.9.0" repositories { google() mavenCentral() @@ -7,9 +7,9 @@ buildscript { } dependencies { - classpath "com.android.tools.build:gradle:7.2.2" + classpath "com.android.tools.build:gradle:7.4.2" classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version" - classpath "org.jlleitschuh.gradle:ktlint-gradle:11.0.0" + classpath "org.jlleitschuh.gradle:ktlint-gradle:11.5.0" } } @@ -29,7 +29,7 @@ rootProject.allprojects { android { namespace "vn.hunghd.flutterdownloader" - compileSdk 32 + compileSdk 33 compileOptions { sourceCompatibility JavaVersion.VERSION_1_8 @@ -46,7 +46,7 @@ android { defaultConfig { minSdk 19 - targetSdk 32 + targetSdk 33 } } diff --git a/android/gradle.properties b/android/gradle.properties deleted file mode 100644 index 08f2b5f9..00000000 --- a/android/gradle.properties +++ /dev/null @@ -1,3 +0,0 @@ -org.gradle.jvmargs=-Xmx1536M -android.enableJetifier=true -android.useAndroidX=true diff --git a/android/gradle/wrapper/gradle-wrapper.properties b/android/gradle/wrapper/gradle-wrapper.properties deleted file mode 100644 index dcf0f19c..00000000 --- a/android/gradle/wrapper/gradle-wrapper.properties +++ /dev/null @@ -1,5 +0,0 @@ -distributionBase=GRADLE_USER_HOME -distributionPath=wrapper/dists -zipStoreBase=GRADLE_USER_HOME -zipStorePath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-7.6-all.zip diff --git a/android/src/main/kotlin/vn/hunghd/flutterdownloader/DownloadWorker.kt b/android/src/main/kotlin/vn/hunghd/flutterdownloader/DownloadWorker.kt index 94bd5c47..2d9bf628 100644 --- a/android/src/main/kotlin/vn/hunghd/flutterdownloader/DownloadWorker.kt +++ b/android/src/main/kotlin/vn/hunghd/flutterdownloader/DownloadWorker.kt @@ -257,7 +257,7 @@ class DownloadWorker(context: Context, params: WorkerParameters) : filename: String?, headers: String, isResume: Boolean, - timeout: Int, + timeout: Int ) { var actualFilename = filename var url = fileURL diff --git a/android/src/main/kotlin/vn/hunghd/flutterdownloader/FlutterDownloaderPlugin.kt b/android/src/main/kotlin/vn/hunghd/flutterdownloader/FlutterDownloaderPlugin.kt index b6f527b2..2a7b928e 100644 --- a/android/src/main/kotlin/vn/hunghd/flutterdownloader/FlutterDownloaderPlugin.kt +++ b/android/src/main/kotlin/vn/hunghd/flutterdownloader/FlutterDownloaderPlugin.kt @@ -91,7 +91,7 @@ class FlutterDownloaderPlugin : MethodChannel.MethodCallHandler, FlutterPlugin { requiresStorageNotLow: Boolean, saveInPublicStorage: Boolean, timeout: Int, - allowCellular: Boolean, + allowCellular: Boolean ): WorkRequest { return OneTimeWorkRequest.Builder(DownloadWorker::class.java) .setConstraints( diff --git a/android/src/main/kotlin/vn/hunghd/flutterdownloader/TaskDao.kt b/android/src/main/kotlin/vn/hunghd/flutterdownloader/TaskDao.kt index 6bb7a8a9..1fffd964 100644 --- a/android/src/main/kotlin/vn/hunghd/flutterdownloader/TaskDao.kt +++ b/android/src/main/kotlin/vn/hunghd/flutterdownloader/TaskDao.kt @@ -21,7 +21,7 @@ class TaskDao(private val dbHelper: TaskDbHelper) { TaskEntry.COLUMN_NAME_SHOW_NOTIFICATION, TaskEntry.COLUMN_NAME_TIME_CREATED, TaskEntry.COLUMN_SAVE_IN_PUBLIC_STORAGE, - TaskEntry.COLUMN_ALLOW_CELLULAR, + TaskEntry.COLUMN_ALLOW_CELLULAR ) fun insertOrUpdateNewTask( diff --git a/example/android/build.gradle b/example/android/build.gradle index 8b3b6ce4..5cc84de1 100644 --- a/example/android/build.gradle +++ b/example/android/build.gradle @@ -1,12 +1,12 @@ buildscript { - ext.kotlin_version = "1.7.22" + ext.kotlin_version = "1.9.0" repositories { google() mavenCentral() } dependencies { - classpath "com.android.tools.build:gradle:7.2.2" + classpath "com.android.tools.build:gradle:7.4.2" classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version" } } diff --git a/example/android/gradle/wrapper/gradle-wrapper.properties b/example/android/gradle/wrapper/gradle-wrapper.properties index dcf0f19c..ec915a81 100644 --- a/example/android/gradle/wrapper/gradle-wrapper.properties +++ b/example/android/gradle/wrapper/gradle-wrapper.properties @@ -2,4 +2,4 @@ distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-7.6-all.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-8.2.1-all.zip diff --git a/example/lib/download_list_item.dart b/example/lib/download_list_item.dart index a7ac1093..9c7d9c48 100644 --- a/example/lib/download_list_item.dart +++ b/example/lib/download_list_item.dart @@ -12,9 +12,9 @@ class DownloadListItem extends StatelessWidget { }); final ItemHolder? data; - final Function(TaskInfo?)? onTap; - final Function(TaskInfo)? onActionTap; - final Function(TaskInfo)? onCancel; + final void Function(TaskInfo?)? onTap; + final void Function(TaskInfo)? onActionTap; + final void Function(TaskInfo)? onCancel; Widget? _buildTrailing(TaskInfo task) { if (task.status == DownloadTaskStatus.undefined) { diff --git a/example/pubspec.yaml b/example/pubspec.yaml index 4df84939..1d011495 100644 --- a/example/pubspec.yaml +++ b/example/pubspec.yaml @@ -4,8 +4,8 @@ version: 1.0.0+1 publish_to: none environment: - sdk: '>=2.17.0 <4.0.0' - flutter: '>=3.0.0' + sdk: '>=3.0.0 <4.0.0' + flutter: '>=3.10.0' dependencies: android_path_provider: ^0.3.0 @@ -20,7 +20,7 @@ dependencies: dev_dependencies: flutter_test: sdk: flutter - leancode_lint: ^2.0.0+1 + leancode_lint: ^4.0.0+2 flutter: uses-material-design: true diff --git a/lib/src/callback_dispatcher.dart b/lib/src/callback_dispatcher.dart index 674b4b60..5e657e84 100644 --- a/lib/src/callback_dispatcher.dart +++ b/lib/src/callback_dispatcher.dart @@ -16,7 +16,8 @@ void callbackDispatcher() { ..setMethodCallHandler((call) async { final args = call.arguments as List; final handle = CallbackHandle.fromRawHandle(args[0] as int); - final callback = PluginUtilities.getCallbackFromHandle(handle); + final callback = PluginUtilities.getCallbackFromHandle(handle) as void + Function(String id, int status, int progress)?; if (callback == null) { // ignore: avoid_print diff --git a/lib/src/downloader.dart b/lib/src/downloader.dart index 1649dba4..15ec6ce7 100644 --- a/lib/src/downloader.dart +++ b/lib/src/downloader.dart @@ -1,3 +1,5 @@ +// ignore_for_file: avoid_dynamic_calls + import 'dart:async'; import 'dart:convert'; import 'dart:io'; @@ -149,8 +151,6 @@ class FlutterDownloader { return result.map( (dynamic item) { - // item as Map; // throws - return DownloadTask( taskId: item['task_id'] as String, status: DownloadTaskStatus(item['status'] as int), @@ -209,8 +209,6 @@ class FlutterDownloader { return result.map( (dynamic item) { - // item as Map; // throws - return DownloadTask( taskId: item['task_id'] as String, status: DownloadTaskStatus(item['status'] as int), diff --git a/pubspec.yaml b/pubspec.yaml index d79ee4f0..ff92a8e7 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -15,8 +15,8 @@ flutter: pluginClass: FlutterDownloaderPlugin environment: - sdk: '>=2.17.0 <4.0.0' - flutter: '>=3.0.0' + sdk: '>=3.0.0 <4.0.0' + flutter: '>=3.10.0' dependencies: flutter: @@ -25,4 +25,4 @@ dependencies: dev_dependencies: flutter_test: sdk: flutter - leancode_lint: ^2.0.0+1 + leancode_lint: ^4.0.0+2 From 387588f3f74e63ffa6aee4b390257506cc3a4626 Mon Sep 17 00:00:00 2001 From: Bartek Pacia Date: Sun, 30 Jul 2023 20:57:55 +0200 Subject: [PATCH 11/16] fix delete() not falling back to normal File#delete() (#871) When delete() was called, the plugin first tried to remove the file using MediaStore, and then was (trying to) fall back to normal File#delete(). Unfortunately, the calls to MediaStore were throwing a SecurityException, so the fall-back code was never executed. --- .../flutterdownloader/FlutterDownloaderPlugin.kt | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/android/src/main/kotlin/vn/hunghd/flutterdownloader/FlutterDownloaderPlugin.kt b/android/src/main/kotlin/vn/hunghd/flutterdownloader/FlutterDownloaderPlugin.kt index 2a7b928e..6867bf65 100644 --- a/android/src/main/kotlin/vn/hunghd/flutterdownloader/FlutterDownloaderPlugin.kt +++ b/android/src/main/kotlin/vn/hunghd/flutterdownloader/FlutterDownloaderPlugin.kt @@ -6,6 +6,7 @@ import android.content.Context import android.content.Intent import android.net.Uri import android.provider.MediaStore +import android.util.Log import androidx.core.app.NotificationManagerCompat import androidx.work.BackoffPolicy import androidx.work.Constraints @@ -390,7 +391,14 @@ class FlutterDownloaderPlugin : MethodChannel.MethodCallHandler, FlutterPlugin { val saveFilePath = task.savedDir + File.separator + filename val tempFile = File(saveFilePath) if (tempFile.exists()) { - deleteFileInMediaStore(tempFile) + try { + deleteFileInMediaStore(tempFile) + } catch (e: SecurityException) { + Log.d( + "FlutterDownloader", + "Failed to delete file in media store, will fall back to normal delete()" + ) + } tempFile.delete() } } From b4f330397566ce168b52b030b3db9e45922ac28f Mon Sep 17 00:00:00 2001 From: Bartek Pacia Date: Sun, 30 Jul 2023 23:00:33 +0200 Subject: [PATCH 12/16] Bump version to 1.10.6 (#874) * bump version to 1.10.6 * downgrade Kotlin version in example app * update `publish` gh action --- .github/workflows/publish.yaml | 46 ++++++++-------------------------- CHANGELOG.md | 7 ++++++ example/android/build.gradle | 2 +- pubspec.yaml | 2 +- 4 files changed, 20 insertions(+), 37 deletions(-) diff --git a/.github/workflows/publish.yaml b/.github/workflows/publish.yaml index 80e6fbe9..c8186ac6 100644 --- a/.github/workflows/publish.yaml +++ b/.github/workflows/publish.yaml @@ -5,14 +5,19 @@ on: tags: ['v*'] jobs: - main: + publish: + name: Publish on pub.dev runs-on: ubuntu-latest + permissions: + id-token: write + contents: write + steps: - - name: Checkout + - name: Clone repository uses: actions/checkout@v3 - # This action adds a token needed for pub.dev + # This step adds the auth token for pub.dev - name: Set up Dart uses: dart-lang/setup-dart@v1 with: @@ -24,35 +29,6 @@ jobs: channel: stable cache: true - - name: Install mobile-tools - uses: actions/checkout@v3 - with: - repository: leancodepl/mobile-tools - path: mobile-tools - - - name: Add mobile-tools to PATH - run: | - echo $GITHUB_WORKSPACE/mobile-tools/bin >> $GITHUB_PATH - - - name: Download pub.dev credentials - env: - CREDENTIALS: ${{ secrets.PUB_DEV_CREDENTIALS }} - run: | - mkdir -p ~/.pub-cache - echo $CREDENTIALS > ~/.pub-cache/credentials.json - - - name: Set version data - run: | - tag=${{ github.ref_name }} - echo "RELEASE_NOTES=$(link_changelog flutter_downloader $tag)" >> $GITHUB_ENV - echo "IS_PRERELEASE=$(is_prerelease flutter_downloader $tag)" >> $GITHUB_ENV - - - name: Publish - run: dart pub publish --force - - - name: Create release - uses: softprops/action-gh-release@v1 - with: - name: ${{ github.ref_name }} - body: '[See changelog on pub.dev](${{ env.RELEASE_NOTES }})' - prerelease: ${{ env.IS_PRERELEASE }} + - name: Publish to pub.dev + id: pub_release + uses: leancodepl/mobile-tools/.github/actions/pub-release@pub-release-v1 diff --git a/CHANGELOG.md b/CHANGELOG.md index f064cf98..a5dddf23 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,10 @@ +## 1.10.6 + +- Fix `delete()` not working when file isn't saved to public storage (#871) +- Update CI workflows on GitHub Actions (#872) +- Bump native Android dependencies and Gradle (#873) +- Bump minimum Flutter version to 3.10 (#873) + ## 1.10.5 - Make the project compile when the app not doesn't have dependency on Kotlin diff --git a/example/android/build.gradle b/example/android/build.gradle index 5cc84de1..80bb3e10 100644 --- a/example/android/build.gradle +++ b/example/android/build.gradle @@ -1,5 +1,5 @@ buildscript { - ext.kotlin_version = "1.9.0" + ext.kotlin_version = "1.7.22" repositories { google() mavenCentral() diff --git a/pubspec.yaml b/pubspec.yaml index ff92a8e7..0226485d 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -1,6 +1,6 @@ name: flutter_downloader description: Powerful plugin making it easy to download files. -version: 1.10.5 +version: 1.10.6 repository: https://github.com/fluttercommunity/flutter_downloader issue_tracker: https://github.com/fluttercommunity/flutter_downloader/issues maintainer: Bartek Pacia (@bartekpacia) From d59e16da4cdaebb3a9c63ccf39590b70e24183a9 Mon Sep 17 00:00:00 2001 From: Bartek Pacia Date: Sun, 30 Jul 2023 23:36:54 +0200 Subject: [PATCH 13/16] override `operator ==` and `hashCode` for `DownloadTask` (#875) * override `operator ==` and `hashCode` for `DownloadTask` * bump version to 1.10.7 * remove caching from github actions --- .github/workflows/prepare.yaml | 1 - .github/workflows/publish.yaml | 1 - CHANGELOG.md | 4 ++++ lib/src/models.dart | 31 +++++++++++++++++++++++++++++++ pubspec.yaml | 2 +- 5 files changed, 36 insertions(+), 3 deletions(-) diff --git a/.github/workflows/prepare.yaml b/.github/workflows/prepare.yaml index 77cf8d82..3c02310d 100644 --- a/.github/workflows/prepare.yaml +++ b/.github/workflows/prepare.yaml @@ -23,7 +23,6 @@ jobs: uses: subosito/flutter-action@v2 with: flutter-version: ${{ matrix.flutter-version }} - cache: true - name: flutter pub get run: flutter pub get diff --git a/.github/workflows/publish.yaml b/.github/workflows/publish.yaml index c8186ac6..3a390bd0 100644 --- a/.github/workflows/publish.yaml +++ b/.github/workflows/publish.yaml @@ -27,7 +27,6 @@ jobs: uses: subosito/flutter-action@v2 with: channel: stable - cache: true - name: Publish to pub.dev id: pub_release diff --git a/CHANGELOG.md b/CHANGELOG.md index a5dddf23..cf07fdc1 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,7 @@ +## 1.10.7 + +- Override `operator ==` and `hashCode` for `DownloadTask` (#875) + ## 1.10.6 - Fix `delete()` not working when file isn't saved to public storage (#871) diff --git a/lib/src/models.dart b/lib/src/models.dart index 5801e31b..45a76874 100644 --- a/lib/src/models.dart +++ b/lib/src/models.dart @@ -89,4 +89,35 @@ class DownloadTask { @override String toString() => 'DownloadTask(taskId: $taskId, status: $status, progress: $progress, url: $url, filename: $filename, savedDir: $savedDir, timeCreated: $timeCreated, allowCellular: $allowCellular)'; + + @override + bool operator ==(Object other) { + if (identical(this, other)) { + return true; + } + + return other is DownloadTask && + other.taskId == taskId && + other.status == status && + other.progress == progress && + other.url == url && + other.filename == filename && + other.savedDir == savedDir && + other.timeCreated == timeCreated && + other.allowCellular == allowCellular; + } + + @override + int get hashCode { + return Object.hash( + taskId, + status, + progress, + url, + filename, + savedDir, + timeCreated, + allowCellular, + ); + } } diff --git a/pubspec.yaml b/pubspec.yaml index 0226485d..86d08264 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -1,6 +1,6 @@ name: flutter_downloader description: Powerful plugin making it easy to download files. -version: 1.10.6 +version: 1.10.7 repository: https://github.com/fluttercommunity/flutter_downloader issue_tracker: https://github.com/fluttercommunity/flutter_downloader/issues maintainer: Bartek Pacia (@bartekpacia) From 4554a16ecb41a92132ae5e8d94460d04e45fc44d Mon Sep 17 00:00:00 2001 From: Bartek Pacia Date: Mon, 31 Jul 2023 00:05:23 +0200 Subject: [PATCH 14/16] Convert `DownloadTaskStatus` into enum (#835) * convert `DownloadTaskStatus` into enum * remove redundant toString() * bump version to 1.11.0 --- CHANGELOG.md | 4 +++ example/lib/home_page.dart | 2 +- lib/src/downloader.dart | 4 +-- lib/src/models.dart | 61 +++++++++++++++++++------------------- pubspec.yaml | 2 +- 5 files changed, 38 insertions(+), 35 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index cf07fdc1..d263d8ae 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,7 @@ +## 1.11.0 + +- Convert `DownloadTaskStatus` into an `enum` (#835) + ## 1.10.7 - Override `operator ==` and `hashCode` for `DownloadTask` (#875) diff --git a/example/lib/home_page.dart b/example/lib/home_page.dart index f5043cd6..412998fc 100644 --- a/example/lib/home_page.dart +++ b/example/lib/home_page.dart @@ -64,7 +64,7 @@ class _MyHomePageState extends State { } _port.listen((dynamic data) { final taskId = (data as List)[0] as String; - final status = DownloadTaskStatus(data[1] as int); + final status = DownloadTaskStatus.fromInt(data[1] as int); final progress = data[2] as int; print( diff --git a/lib/src/downloader.dart b/lib/src/downloader.dart index 15ec6ce7..adbe4504 100644 --- a/lib/src/downloader.dart +++ b/lib/src/downloader.dart @@ -153,7 +153,7 @@ class FlutterDownloader { (dynamic item) { return DownloadTask( taskId: item['task_id'] as String, - status: DownloadTaskStatus(item['status'] as int), + status: DownloadTaskStatus.fromInt(item['status'] as int), progress: item['progress'] as int, url: item['url'] as String, filename: item['file_name'] as String?, @@ -211,7 +211,7 @@ class FlutterDownloader { (dynamic item) { return DownloadTask( taskId: item['task_id'] as String, - status: DownloadTaskStatus(item['status'] as int), + status: DownloadTaskStatus.fromInt(item['status'] as int), progress: item['progress'] as int, url: item['url'] as String, filename: item['file_name'] as String?, diff --git a/lib/src/models.dart b/lib/src/models.dart index 45a76874..95f985a3 100644 --- a/lib/src/models.dart +++ b/lib/src/models.dart @@ -1,49 +1,48 @@ /// Defines a set of possible states which a [DownloadTask] can be in. @pragma('vm:entry-point') -class DownloadTaskStatus { - /// Creates a new [DownloadTaskStatus]. - const DownloadTaskStatus(int value) : _value = value; - - final int _value; - - /// The underlying index of this status. - int get value => _value; - +enum DownloadTaskStatus { /// Status of the task is either unknown or corrupted. - static const undefined = DownloadTaskStatus(0); + undefined, /// The task is scheduled, but is not running yet. - static const enqueued = DownloadTaskStatus(1); + enqueued, /// The task is in progress. - static const running = DownloadTaskStatus(2); + running, /// The task has completed successfully. - static const complete = DownloadTaskStatus(3); + complete, /// The task has failed. - static const failed = DownloadTaskStatus(4); + failed, /// The task was canceled and cannot be resumed. - static const canceled = DownloadTaskStatus(5); - - /// The task was paused and can be resumed. - static const paused = DownloadTaskStatus(6); - - @override - bool operator ==(Object other) { - if (identical(this, other)) { - return true; + canceled, + + /// The task was paused and can be resumed + paused; + + /// Creates a new [DownloadTaskStatus] from an [int]. + factory DownloadTaskStatus.fromInt(int value) { + switch (value) { + case 0: + return DownloadTaskStatus.undefined; + case 1: + return DownloadTaskStatus.enqueued; + case 2: + return DownloadTaskStatus.running; + case 3: + return DownloadTaskStatus.complete; + case 4: + return DownloadTaskStatus.failed; + case 5: + return DownloadTaskStatus.canceled; + case 6: + return DownloadTaskStatus.paused; + default: + throw ArgumentError('Invalid value: $value'); } - - return other is DownloadTaskStatus && other._value == _value; } - - @override - int get hashCode => _value.hashCode; - - @override - String toString() => 'DownloadTaskStatus($_value)'; } /// Encapsulates all information of a single download task. diff --git a/pubspec.yaml b/pubspec.yaml index 86d08264..d40df0b5 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -1,6 +1,6 @@ name: flutter_downloader description: Powerful plugin making it easy to download files. -version: 1.10.7 +version: 1.11.0 repository: https://github.com/fluttercommunity/flutter_downloader issue_tracker: https://github.com/fluttercommunity/flutter_downloader/issues maintainer: Bartek Pacia (@bartekpacia) From a03314abe31750447d7b7d90b0f8c671a636ed2b Mon Sep 17 00:00:00 2001 From: Bartek Pacia Date: Fri, 4 Aug 2023 13:28:07 +0200 Subject: [PATCH 15/16] don't crash when `FlutterDownloader.registerCallback()` wasn't called (#879) --- lib/src/callback_dispatcher.dart | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/lib/src/callback_dispatcher.dart b/lib/src/callback_dispatcher.dart index 5e657e84..deb9b81a 100644 --- a/lib/src/callback_dispatcher.dart +++ b/lib/src/callback_dispatcher.dart @@ -1,4 +1,3 @@ -import 'dart:io'; import 'dart:ui'; import 'package:flutter/services.dart'; @@ -16,19 +15,18 @@ void callbackDispatcher() { ..setMethodCallHandler((call) async { final args = call.arguments as List; final handle = CallbackHandle.fromRawHandle(args[0] as int); + final id = args[1] as String; + final status = args[2] as int; + final progress = args[3] as int; + final callback = PluginUtilities.getCallbackFromHandle(handle) as void Function(String id, int status, int progress)?; if (callback == null) { - // ignore: avoid_print - print('fatal error: could not find callback'); - exit(1); + // The callback wasn't registered. Ignore. + return; } - final id = args[1] as String; - final status = args[2] as int; - final progress = args[3] as int; - callback(id, status, progress); }) ..invokeMethod('didInitializeDispatcher'); From 447702e336345157a4cd8302d68c81a03bb80ac1 Mon Sep 17 00:00:00 2001 From: Bartek Pacia Date: Fri, 4 Aug 2023 13:49:25 +0200 Subject: [PATCH 16/16] bump version to 1.11.1 (#880) --- CHANGELOG.md | 4 ++++ pubspec.yaml | 2 +- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index d263d8ae..d1bb044d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,7 @@ +## 1.11.1 + +- Don't crash when `FlutterDownloader.registerCallback()` wasn't called (#879) + ## 1.11.0 - Convert `DownloadTaskStatus` into an `enum` (#835) diff --git a/pubspec.yaml b/pubspec.yaml index d40df0b5..21c76427 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -1,6 +1,6 @@ name: flutter_downloader description: Powerful plugin making it easy to download files. -version: 1.11.0 +version: 1.11.1 repository: https://github.com/fluttercommunity/flutter_downloader issue_tracker: https://github.com/fluttercommunity/flutter_downloader/issues maintainer: Bartek Pacia (@bartekpacia)