Skip to content

Commit

Permalink
Merge branch 'master' into feature/ios_support_file_store_in_any_dire…
Browse files Browse the repository at this point in the history
…ctory

# Conflicts:
#	lib/src/callback_dispatcher.dart
#	lib/src/downloader.dart

feat: The callback wasn't registered. Ignore.
  • Loading branch information
jackleemeta committed Aug 17, 2023
2 parents 71a9dad + 447702e commit 48de114
Show file tree
Hide file tree
Showing 19 changed files with 194 additions and 158 deletions.
37 changes: 9 additions & 28 deletions .github/workflows/prepare.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,59 +2,40 @@ 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
- channel: beta
flutter-version: ['3.10.x']

steps:
- name: Clone repository
uses: actions/checkout@v3

- name: Install Flutter
uses: subosito/flutter-action@v1
with:
channel: ${{ matrix.channel }}
flutter-version: ${{ matrix.version }}

- name: Flutter version
run: flutter --version

- name: Cache pub dependencies
uses: actions/cache@v3
- name: Set up Flutter
uses: subosito/flutter-action@v2
with:
path: ${{ env.FLUTTER_HOME }}/.pub-cache
key: ${{ runner.os }}-pub-${{ hashFiles('**/pubspec.lock') }}
restore-keys: ${{ runner.os }}-pub-
flutter-version: ${{ matrix.flutter-version }}

- 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

- 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
Expand All @@ -65,7 +46,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
Expand Down
52 changes: 17 additions & 35 deletions .github/workflows/publish.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,50 +2,32 @@ name: publish

on:
push:
tags: ["v*"]
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

- name: Setup Dart
# This step adds the auth token for pub.dev
- name: Set up Dart
uses: dart-lang/setup-dart@v1
with:
sdk: 2.17.0
sdk: stable

- name: Install mobile-tools
uses: actions/checkout@v3
- name: Set up Flutter
uses: subosito/flutter-action@v2
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
channel: stable

- 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 -f

- 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
34 changes: 34 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,37 @@
## 1.11.1

- Don't crash when `FlutterDownloader.registerCallback()` wasn't called (#879)

## 1.11.0

- Convert `DownloadTaskStatus` into an `enum` (#835)

## 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)
- 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
(#869)

## 1.10.4

- 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

- Fix Android build failing when using Android Gradle Plugin v8 (#857)

## 1.10.2

- Correctly read the error/success codes (#766)
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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((){ });
});
Expand All @@ -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]);
}
Expand Down
28 changes: 19 additions & 9 deletions android/build.gradle
Original file line number Diff line number Diff line change
@@ -1,21 +1,21 @@
buildscript {
ext.kotlin_version = "1.7.22"
ext.kotlin_version = "1.9.0"
repositories {
google()
mavenCentral()
gradlePluginPortal()
}

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.5.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"
Expand All @@ -28,15 +28,25 @@ rootProject.allprojects {
}

android {
compileSdk 32
namespace "vn.hunghd.flutterdownloader"
compileSdk 33

compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}

kotlinOptions {
jvmTarget = "1.8"
}

sourceSets {
main.java.srcDirs += "src/main/kotlin"
}

defaultConfig {
minSdk 19
targetSdk 32
targetSdk 33
}
}

Expand Down
3 changes: 0 additions & 3 deletions android/gradle.properties

This file was deleted.

5 changes: 0 additions & 5 deletions android/gradle/wrapper/gradle-wrapper.properties

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -91,7 +92,7 @@ class FlutterDownloaderPlugin : MethodChannel.MethodCallHandler, FlutterPlugin {
requiresStorageNotLow: Boolean,
saveInPublicStorage: Boolean,
timeout: Int,
allowCellular: Boolean,
allowCellular: Boolean
): WorkRequest {
return OneTimeWorkRequest.Builder(DownloadWorker::class.java)
.setConstraints(
Expand Down Expand Up @@ -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()
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
2 changes: 1 addition & 1 deletion example/android/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ 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"
}
}
Expand Down
2 changes: 1 addition & 1 deletion example/android/gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
Expand Up @@ -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
6 changes: 3 additions & 3 deletions example/lib/download_list_item.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
6 changes: 3 additions & 3 deletions example/lib/home_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ class _MyHomePageState extends State<MyHomePage> {
}
_port.listen((dynamic data) {
final taskId = (data as List<dynamic>)[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(
Expand All @@ -90,7 +90,7 @@ class _MyHomePageState extends State<MyHomePage> {
@pragma('vm:entry-point')
static void downloadCallback(
String id,
DownloadTaskStatus status,
int status,
int progress,
) {
print(
Expand All @@ -99,7 +99,7 @@ class _MyHomePageState extends State<MyHomePage> {
);

IsolateNameServer.lookupPortByName('downloader_send_port')
?.send([id, status.value, progress]);
?.send([id, status, progress]);
}

Widget _buildDownloadList() {
Expand Down
Loading

0 comments on commit 48de114

Please sign in to comment.