Skip to content
This repository was archived by the owner on Feb 27, 2022. It is now read-only.

Commit 10aa10e

Browse files
author
Elad Gil
committed
updated lib to require RN 0.57 minimum
updated testApp to latest RN updated Fetch to version 3.0.3
1 parent 3adae88 commit 10aa10e

File tree

21 files changed

+2084
-3149
lines changed

21 files changed

+2084
-3149
lines changed

.babelrc

Lines changed: 0 additions & 3 deletions
This file was deleted.

android/build.gradle

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
apply plugin: 'com.android.library'
22

33
android {
4-
compileSdkVersion 26
5-
buildToolsVersion "26.0.1"
4+
compileSdkVersion rootProject.ext.compileSdkVersion
5+
buildToolsVersion rootProject.ext.buildToolsVersion
66

77
defaultConfig {
8-
minSdkVersion 16
9-
targetSdkVersion 26
8+
minSdkVersion rootProject.ext.minSdkVersion
9+
targetSdkVersion rootProject.ext.targetSdkVersion
1010
versionCode 1
1111
versionName "1.0"
1212
ndk {
@@ -18,5 +18,5 @@ android {
1818
dependencies {
1919
//noinspection GradleDynamicVersion
2020
implementation 'com.facebook.react:react-native:+'
21-
compile "com.tonyodev.fetch2:fetch2:2.0.0-RC12"
21+
implementation "com.tonyodev.fetch2:fetch2:3.0.3"
2222
}

android/src/main/java/com/eko/RNBackgroundDownloaderModule.java

Lines changed: 49 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
package com.eko;
22

33
import android.annotation.SuppressLint;
4-
import android.content.Context;
5-
import android.content.SharedPreferences;
64
import android.util.Log;
75

86
import com.facebook.react.bridge.Arguments;
@@ -18,12 +16,16 @@
1816
import com.tonyodev.fetch2.Download;
1917
import com.tonyodev.fetch2.Error;
2018
import com.tonyodev.fetch2.Fetch;
19+
import com.tonyodev.fetch2.FetchConfiguration;
2120
import com.tonyodev.fetch2.FetchListener;
22-
import com.tonyodev.fetch2.Func;
2321
import com.tonyodev.fetch2.NetworkType;
2422
import com.tonyodev.fetch2.Priority;
2523
import com.tonyodev.fetch2.Request;
2624
import com.tonyodev.fetch2.Status;
25+
import com.tonyodev.fetch2core.DownloadBlock;
26+
import com.tonyodev.fetch2core.Func;
27+
28+
import org.jetbrains.annotations.NotNull;
2729

2830
import java.io.File;
2931
import java.io.FileInputStream;
@@ -69,9 +71,10 @@ public RNBackgroundDownloaderModule(ReactApplicationContext reactContext) {
6971
super(reactContext);
7072

7173
loadConfigMap();
72-
fetch = new Fetch.Builder(this.getReactApplicationContext(), "RNBackgroundDownloader")
74+
FetchConfiguration fetchConfiguration = new FetchConfiguration.Builder(this.getReactApplicationContext())
7375
.setDownloadConcurrentLimit(4)
7476
.build();
77+
fetch = Fetch.Impl.getInstance(fetchConfiguration);
7578
fetch.addListener(this);
7679
}
7780

@@ -201,9 +204,9 @@ public void stopTask(String identifier) {
201204

202205
@ReactMethod
203206
public void checkForExistingDownloads(final Promise promise) {
204-
fetch.getDownloads(new Func<List<? extends Download>>() {
207+
fetch.getDownloads(new Func<List<Download>>() {
205208
@Override
206-
public void call(List<? extends Download> downloads) {
209+
public void call(@NotNull List<Download> downloads) {
207210
WritableArray foundIds = Arguments.createArray();
208211

209212
for (Download download : downloads) {
@@ -231,11 +234,6 @@ public void call(List<? extends Download> downloads) {
231234
}
232235

233236
// Fetch API
234-
@Override
235-
public void onQueued(Download download) {
236-
237-
}
238-
239237
@Override
240238
public void onCompleted(Download download) {
241239
WritableMap params = Arguments.createMap();
@@ -246,24 +244,6 @@ public void onCompleted(Download download) {
246244
fetch.remove(download.getId());
247245
}
248246

249-
@Override
250-
public void onError(Download download) {
251-
Error error = download.getError();
252-
Throwable throwable = error.getThrowable();
253-
254-
WritableMap params = Arguments.createMap();
255-
params.putString("id", requestIdToConfig.get(download.getId()).id);
256-
if (error == Error.UNKNOWN && throwable != null) {
257-
params.putString("error", throwable.getLocalizedMessage());
258-
} else {
259-
params.putString("error", error.toString());
260-
}
261-
ee.emit("downloadFailed", params);
262-
263-
removeFromMaps(download.getId());
264-
fetch.remove(download.getId());
265-
}
266-
267247
@Override
268248
public void onProgress(Download download, long l, long l1) {
269249
RNBGDTaskConfig config = requestIdToConfig.get(download.getId());
@@ -318,4 +298,44 @@ public void onRemoved(Download download) {
318298
public void onDeleted(Download download) {
319299

320300
}
301+
302+
@Override
303+
public void onAdded(Download download) {
304+
305+
}
306+
307+
@Override
308+
public void onQueued(Download download, boolean b) {
309+
310+
}
311+
312+
@Override
313+
public void onWaitingNetwork(Download download) {
314+
315+
}
316+
317+
@Override
318+
public void onError(Download download, Error error, Throwable throwable) {
319+
WritableMap params = Arguments.createMap();
320+
params.putString("id", requestIdToConfig.get(download.getId()).id);
321+
if (error == Error.UNKNOWN && throwable != null) {
322+
params.putString("error", throwable.getLocalizedMessage());
323+
} else {
324+
params.putString("error", error.toString());
325+
}
326+
ee.emit("downloadFailed", params);
327+
328+
removeFromMaps(download.getId());
329+
fetch.remove(download.getId());
330+
}
331+
332+
@Override
333+
public void onDownloadBlockUpdated(Download download, DownloadBlock downloadBlock, int i) {
334+
335+
}
336+
337+
@Override
338+
public void onStarted(Download download, List<? extends DownloadBlock> list, int i) {
339+
340+
}
321341
}

babel.config.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
module.exports = {
2+
presets: ["module:metro-react-native-babel-preset"]
3+
}

metro.config.js

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
/**
2+
* Metro configuration for React Native
3+
* https://github.com/facebook/react-native
4+
*
5+
* @format
6+
*/
7+
8+
module.exports = {
9+
transformer: {
10+
getTransformOptions: async () => ({
11+
transform: {
12+
experimentalImportSupport: false,
13+
inlineRequires: false,
14+
},
15+
}),
16+
},
17+
};

package.json

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -40,14 +40,19 @@
4040
],
4141
"license": "Apache-2.0",
4242
"peerDependencies": {
43-
"react-native": ">=0.41.2"
43+
"react-native": ">=0.57.0"
4444
},
4545
"devDependencies": {
46-
"babel-eslint": "^8.2.5",
47-
"eslint": "^4.19.1",
48-
"jest": "^23.1.0",
49-
"react": "16.3.1",
50-
"react-native": "^0.55.4"
46+
"@babel/core": "^7.4.0",
47+
"@babel/runtime": "^7.4.2",
48+
"@react-native-community/eslint-config": "^0.0.3",
49+
"babel-jest": "^24.5.0",
50+
"eslint": "^5.16.0",
51+
"jest": "^24.5.0",
52+
"metro-react-native-babel-preset": "^0.53.1",
53+
"react-test-renderer": "16.8.3",
54+
"react": "16.8.3",
55+
"react-native": "0.59.2"
5156
},
5257
"jest": {
5358
"preset": "react-native",

testApp/android/app/BUCK

Lines changed: 6 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -8,23 +8,13 @@
88
# - `buck install -r android/app` - compile, install and run application
99
#
1010

11+
load(":build_defs.bzl", "create_aar_targets", "create_jar_targets")
12+
1113
lib_deps = []
1214

13-
for jarfile in glob(['libs/*.jar']):
14-
name = 'jars__' + jarfile[jarfile.rindex('/') + 1: jarfile.rindex('.jar')]
15-
lib_deps.append(':' + name)
16-
prebuilt_jar(
17-
name = name,
18-
binary_jar = jarfile,
19-
)
15+
create_aar_targets(glob(["libs/*.aar"]))
2016

21-
for aarfile in glob(['libs/*.aar']):
22-
name = 'aars__' + aarfile[aarfile.rindex('/') + 1: aarfile.rindex('.aar')]
23-
lib_deps.append(':' + name)
24-
android_prebuilt_aar(
25-
name = name,
26-
aar = aarfile,
27-
)
17+
create_jar_targets(glob(["libs/*.jar"]))
2818

2919
android_library(
3020
name = "all-libs",
@@ -45,12 +35,12 @@ android_library(
4535

4636
android_build_config(
4737
name = "build_config",
48-
package = "com.testapp",
38+
package = "com.testapp2",
4939
)
5040

5141
android_resource(
5242
name = "res",
53-
package = "com.testapp",
43+
package = "com.testapp2",
5444
res = "src/main/res",
5545
)
5646

testApp/android/app/build.gradle

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -95,24 +95,25 @@ def enableProguardInReleaseBuilds = false
9595

9696
android {
9797
compileSdkVersion rootProject.ext.compileSdkVersion
98-
buildToolsVersion rootProject.ext.buildToolsVersion
98+
99+
compileOptions {
100+
sourceCompatibility JavaVersion.VERSION_1_8
101+
targetCompatibility JavaVersion.VERSION_1_8
102+
}
99103

100104
defaultConfig {
101105
applicationId "com.testapp"
102106
minSdkVersion rootProject.ext.minSdkVersion
103107
targetSdkVersion rootProject.ext.targetSdkVersion
104108
versionCode 1
105109
versionName "1.0"
106-
ndk {
107-
abiFilters "armeabi-v7a", "x86"
108-
}
109110
}
110111
splits {
111112
abi {
112113
reset()
113114
enable enableSeparateBuildPerCPUArchitecture
114115
universalApk false // If true, also generate a universal APK
115-
include "armeabi-v7a", "x86"
116+
include "armeabi-v7a", "x86", "arm64-v8a", "x86_64"
116117
}
117118
}
118119
buildTypes {
@@ -126,7 +127,7 @@ android {
126127
variant.outputs.each { output ->
127128
// For each separate APK per architecture, set a unique version code as described here:
128129
// http://tools.android.com/tech-docs/new-build-system/user-guide/apk-splits
129-
def versionCodes = ["armeabi-v7a":1, "x86":2]
130+
def versionCodes = ["armeabi-v7a":1, "x86":2, "arm64-v8a": 3, "x86_64": 4]
130131
def abi = output.getFilter(OutputFile.ABI)
131132
if (abi != null) { // null for the universal-debug, universal-release variants
132133
output.versionCodeOverride =
@@ -137,7 +138,7 @@ android {
137138
}
138139

139140
dependencies {
140-
compile project(':react-native-background-downloader')
141+
implementation project(':react-native-background-downloader')
141142
implementation fileTree(dir: "libs", include: ["*.jar"])
142143
implementation "com.android.support:appcompat-v7:${rootProject.ext.supportLibVersion}"
143144
implementation "com.facebook.react:react-native:+" // From node_modules

testApp/android/app/src/main/AndroidManifest.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
2-
package="com.testapp">
2+
package="com.testapp">
33

44
<uses-permission android:name="android.permission.INTERNET" />
5-
<uses-permission android:name="android.permission.SYSTEM_ALERT_WINDOW"/>
65

76
<application
87
android:name=".MainApplication"
98
android:label="@string/app_name"
109
android:icon="@mipmap/ic_launcher"
10+
android:roundIcon="@mipmap/ic_launcher_round"
1111
android:allowBackup="false"
1212
android:theme="@style/AppTheme">
1313
<activity

testApp/android/build.gradle

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,18 +2,18 @@
22

33
buildscript {
44
ext {
5-
buildToolsVersion = "27.0.3"
5+
buildToolsVersion = "28.0.3"
66
minSdkVersion = 16
7-
compileSdkVersion = 27
8-
targetSdkVersion = 26
9-
supportLibVersion = "27.1.1"
7+
compileSdkVersion = 28
8+
targetSdkVersion = 28
9+
supportLibVersion = "28.0.0"
1010
}
1111
repositories {
1212
google()
1313
jcenter()
1414
}
1515
dependencies {
16-
classpath 'com.android.tools.build:gradle:3.1.4'
16+
classpath 'com.android.tools.build:gradle:3.3.1'
1717

1818
// NOTE: Do not place your application dependencies here; they belong
1919
// in the individual module build.gradle files
@@ -31,9 +31,3 @@ allprojects {
3131
}
3232
}
3333
}
34-
35-
36-
task wrapper(type: Wrapper) {
37-
gradleVersion = '4.4'
38-
distributionUrl = distributionUrl.replace("bin", "all")
39-
}

0 commit comments

Comments
 (0)