Skip to content

Commit a7e39d7

Browse files
committed
updates
1 parent df9e3da commit a7e39d7

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

49 files changed

+2505
-0
lines changed

.idea/gradle.xml

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Downloader/.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
/build

Downloader/build.gradle

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
plugins {
2+
id 'com.android.library'
3+
}
4+
5+
android {
6+
compileSdkVersion 30
7+
buildToolsVersion "30.0.3"
8+
9+
defaultConfig {
10+
minSdkVersion 21
11+
targetSdkVersion 30
12+
versionCode 1
13+
versionName "1.0"
14+
15+
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
16+
consumerProguardFiles "consumer-rules.pro"
17+
}
18+
19+
buildTypes {
20+
release {
21+
minifyEnabled false
22+
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
23+
}
24+
}
25+
compileOptions {
26+
sourceCompatibility JavaVersion.VERSION_1_8
27+
targetCompatibility JavaVersion.VERSION_1_8
28+
}
29+
}
30+
31+
dependencies {
32+
33+
implementation 'androidx.appcompat:appcompat:1.3.0'
34+
implementation 'com.google.android.material:material:1.4.0'
35+
testImplementation 'junit:junit:4.+'
36+
androidTestImplementation 'androidx.test.ext:junit:1.1.3'
37+
androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0'
38+
}

Downloader/consumer-rules.pro

Whitespace-only changes.

Downloader/proguard-rules.pro

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
# Add project specific ProGuard rules here.
2+
# You can control the set of applied configuration files using the
3+
# proguardFiles setting in build.gradle.
4+
#
5+
# For more details, see
6+
# http://developer.android.com/guide/developing/tools/proguard.html
7+
8+
# If your project uses WebView with JS, uncomment the following
9+
# and specify the fully qualified class name to the JavaScript interface
10+
# class:
11+
#-keepclassmembers class fqcn.of.javascript.interface.for.webview {
12+
# public *;
13+
#}
14+
15+
# Uncomment this to preserve the line number information for
16+
# debugging stack traces.
17+
#-keepattributes SourceFile,LineNumberTable
18+
19+
# If you keep the line number information, uncomment this to
20+
# hide the original source file name.
21+
#-renamesourcefileattribute SourceFile
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
package com.oms.downloader;
2+
3+
import android.content.Context;
4+
5+
import androidx.test.platform.app.InstrumentationRegistry;
6+
import androidx.test.ext.junit.runners.AndroidJUnit4;
7+
8+
import org.junit.Test;
9+
import org.junit.runner.RunWith;
10+
11+
import static org.junit.Assert.*;
12+
13+
/**
14+
* Instrumented test, which will execute on an Android device.
15+
*
16+
* @see <a href="http://d.android.com/tools/testing">Testing documentation</a>
17+
*/
18+
@RunWith(AndroidJUnit4.class)
19+
public class ExampleInstrumentedTest {
20+
@Test
21+
public void useAppContext() {
22+
// Context of the app under test.
23+
Context appContext = InstrumentationRegistry.getInstrumentation().getTargetContext();
24+
assertEquals("com.oms.downloader.test", appContext.getPackageName());
25+
}
26+
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
3+
package="com.oms.downloader">
4+
5+
</manifest>
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
package com.oms.downloader;
2+
3+
4+
public final class Constants {
5+
6+
public static final int UPDATE = 0x01;
7+
public static final String RANGE = "Range";
8+
public static final String ETAG = "ETag";
9+
public static final String USER_AGENT = "User-Agent";
10+
public static final String DEFAULT_USER_AGENT = "Downloader";
11+
public static final int DEFAULT_READ_TIMEOUT_IN_MILLS = 20_000;
12+
public static final int DEFAULT_CONNECT_TIMEOUT_IN_MILLS = 20_000;
13+
public static final int HTTP_RANGE_NOT_SATISFIABLE = 416;
14+
public static final int HTTP_TEMPORARY_REDIRECT = 307;
15+
public static final int HTTP_PERMANENT_REDIRECT = 308;
16+
17+
private Constants() {
18+
// no instance
19+
}
20+
21+
}
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
package com.oms.downloader;
2+
3+
import android.content.Context;
4+
5+
import com.oms.downloader.core.Core;
6+
import com.oms.downloader.internal.ComponentHolder;
7+
import com.oms.downloader.internal.DownloadRequestQueue;
8+
import com.oms.downloader.request.DownloadRequestBuilder;
9+
import com.oms.downloader.utils.Utils;
10+
11+
public class Downloader {
12+
13+
private Downloader() {
14+
}
15+
16+
public static void initialize(Context context) {
17+
initialize(context, DownloaderConfig.newBuilder().build());
18+
}
19+
20+
public static void initialize(Context context, DownloaderConfig config) {
21+
ComponentHolder.getInstance().init(context, config);
22+
DownloadRequestQueue.initialize();
23+
}
24+
25+
public static DownloadRequestBuilder download(String url, String dirPath, String fileName) {
26+
return new DownloadRequestBuilder(url, dirPath, fileName);
27+
}
28+
29+
public static void pause(int downloadId) {
30+
DownloadRequestQueue.getInstance().pause(downloadId);
31+
}
32+
33+
public static void resume(int downloadId) {
34+
DownloadRequestQueue.getInstance().resume(downloadId);
35+
}
36+
37+
public static void cancel(int downloadId) {
38+
DownloadRequestQueue.getInstance().cancel(downloadId);
39+
}
40+
41+
public static void cancel(Object tag) {
42+
DownloadRequestQueue.getInstance().cancel(tag);
43+
}
44+
45+
public static void cancelAll() {
46+
DownloadRequestQueue.getInstance().cancelAll();
47+
}
48+
49+
public static Status getStatus(int downloadId) {
50+
return DownloadRequestQueue.getInstance().getStatus(downloadId);
51+
}
52+
53+
public static void cleanUp(int days) {
54+
Utils.deleteUnwantedModelsAndTempFiles(days);
55+
}
56+
57+
public static void shutDown() {
58+
Core.shutDown();
59+
}
60+
61+
}
Lines changed: 104 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,104 @@
1+
package com.oms.downloader;
2+
3+
import com.oms.downloader.httpclient.DefaultHttpClient;
4+
import com.oms.downloader.httpclient.HttpClient;
5+
6+
7+
public class DownloaderConfig {
8+
9+
private int readTimeout;
10+
private int connectTimeout;
11+
private String userAgent;
12+
private HttpClient httpClient;
13+
private boolean databaseEnabled;
14+
15+
private DownloaderConfig(Builder builder) {
16+
this.readTimeout = builder.readTimeout;
17+
this.connectTimeout = builder.connectTimeout;
18+
this.userAgent = builder.userAgent;
19+
this.httpClient = builder.httpClient;
20+
this.databaseEnabled = builder.databaseEnabled;
21+
}
22+
23+
public static Builder newBuilder() {
24+
return new Builder();
25+
}
26+
27+
public int getReadTimeout() {
28+
return readTimeout;
29+
}
30+
31+
public void setReadTimeout(int readTimeout) {
32+
this.readTimeout = readTimeout;
33+
}
34+
35+
public int getConnectTimeout() {
36+
return connectTimeout;
37+
}
38+
39+
public void setConnectTimeout(int connectTimeout) {
40+
this.connectTimeout = connectTimeout;
41+
}
42+
43+
public String getUserAgent() {
44+
return userAgent;
45+
}
46+
47+
public void setUserAgent(String userAgent) {
48+
this.userAgent = userAgent;
49+
}
50+
51+
public HttpClient getHttpClient() {
52+
return httpClient;
53+
}
54+
55+
public void setHttpClient(HttpClient httpClient) {
56+
this.httpClient = httpClient;
57+
}
58+
59+
public boolean isDatabaseEnabled() {
60+
return databaseEnabled;
61+
}
62+
63+
public void setDatabaseEnabled(boolean databaseEnabled) {
64+
this.databaseEnabled = databaseEnabled;
65+
}
66+
67+
public static class Builder {
68+
69+
int readTimeout = Constants.DEFAULT_READ_TIMEOUT_IN_MILLS;
70+
int connectTimeout = Constants.DEFAULT_CONNECT_TIMEOUT_IN_MILLS;
71+
String userAgent = Constants.DEFAULT_USER_AGENT;
72+
HttpClient httpClient = new DefaultHttpClient();
73+
boolean databaseEnabled = false;
74+
75+
public Builder setReadTimeout(int readTimeout) {
76+
this.readTimeout = readTimeout;
77+
return this;
78+
}
79+
80+
public Builder setConnectTimeout(int connectTimeout) {
81+
this.connectTimeout = connectTimeout;
82+
return this;
83+
}
84+
85+
public Builder setUserAgent(String userAgent) {
86+
this.userAgent = userAgent;
87+
return this;
88+
}
89+
90+
public Builder setHttpClient(HttpClient httpClient) {
91+
this.httpClient = httpClient;
92+
return this;
93+
}
94+
95+
public Builder setDatabaseEnabled(boolean databaseEnabled) {
96+
this.databaseEnabled = databaseEnabled;
97+
return this;
98+
}
99+
100+
public DownloaderConfig build() {
101+
return new DownloaderConfig(this);
102+
}
103+
}
104+
}
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
package com.oms.downloader;
2+
3+
import java.util.List;
4+
import java.util.Map;
5+
6+
7+
public class Error {
8+
9+
private boolean isServerError;
10+
private boolean isConnectionError;
11+
private String serverErrorMessage;
12+
private Map<String, List<String>> headerFields;
13+
private Throwable connectionException;
14+
private int responseCode;
15+
16+
public boolean isServerError() {
17+
return isServerError;
18+
}
19+
20+
public void setServerError(boolean serverError) {
21+
isServerError = serverError;
22+
}
23+
24+
public boolean isConnectionError() {
25+
return isConnectionError;
26+
}
27+
28+
public void setConnectionError(boolean connectionError) {
29+
isConnectionError = connectionError;
30+
}
31+
32+
public String getServerErrorMessage() {
33+
return serverErrorMessage;
34+
}
35+
36+
public void setServerErrorMessage(String serverErrorMessage) {
37+
this.serverErrorMessage = serverErrorMessage;
38+
}
39+
40+
public Map<String, List<String>> getHeaderFields() {
41+
return headerFields;
42+
}
43+
44+
public void setHeaderFields(Map<String, List<String>> headerFields) {
45+
this.headerFields = headerFields;
46+
}
47+
48+
public Throwable getConnectionException() {
49+
return connectionException;
50+
}
51+
52+
public void setConnectionException(Throwable connectionException) {
53+
this.connectionException = connectionException;
54+
}
55+
56+
public int getResponseCode() {
57+
return responseCode;
58+
}
59+
60+
public void setResponseCode(int responseCode) {
61+
this.responseCode = responseCode;
62+
}
63+
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
package com.oms.downloader;
2+
3+
4+
5+
public interface OnCancelListener {
6+
7+
void onCancel();
8+
9+
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
package com.oms.downloader;
2+
3+
4+
5+
public interface OnDownloadListener {
6+
7+
void onDownloadComplete();
8+
9+
void onError(Error error);
10+
11+
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
package com.oms.downloader;
2+
3+
4+
5+
public interface OnPauseListener {
6+
7+
void onPause();
8+
9+
}

0 commit comments

Comments
 (0)