Skip to content

Commit 4a9bd2a

Browse files
author
Tianhua Ran
committed
feat: show how to switch to OkDownload
1 parent 6237a8c commit 4a9bd2a

File tree

4 files changed

+32
-4
lines changed

4 files changed

+32
-4
lines changed

build.gradle

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
buildscript {
22
repositories {
3+
mavenLocal()
34
jcenter()
45
google()
56
}
@@ -11,6 +12,7 @@ buildscript {
1112

1213
allprojects {
1314
repositories {
15+
mavenLocal()
1416
jcenter()
1517
google()
1618
}

demo/build.gradle

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,10 @@ android {
4141
// which is harmless for us.
4242
warning 'InvalidPackage'
4343
}
44+
compileOptions {
45+
sourceCompatibility 1.8
46+
targetCompatibility 1.8
47+
}
4448
}
4549

4650
dependencies {
@@ -49,7 +53,10 @@ dependencies {
4953
implementation 'com.android.support:design:28.0.0'
5054
debugImplementation 'cn.dreamtobe.threaddebugger:threaddebugger:1.3.3'
5155
releaseImplementation 'cn.dreamtobe.threaddebugger:threaddebugger-no-op:1.3.3'
52-
implementation project(':library')
56+
// implementation "com.liulishuo.filedownloader:library:1.7.7"
5357
// for testing
5458
implementation 'com.squareup.okio:okio:1.14.0'
59+
implementation "com.liulishuo.okdownload:okdownload:1.0.7-SNAPSHOT"
60+
implementation "com.liulishuo.okdownload:filedownloader:1.0.7-SNAPSHOT"
61+
implementation "com.liulishuo.okdownload:sqlite:1.0.7-SNAPSHOT"
5562
}

demo/src/main/java/com/liulishuo/filedownloader/demo/DemoApplication.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,9 @@
66

77
import com.liulishuo.filedownloader.FileDownloader;
88
import com.liulishuo.filedownloader.connection.FileDownloadUrlConnection;
9-
import com.liulishuo.filedownloader.util.FileDownloadLog;
9+
//import com.liulishuo.filedownloader.util.FileDownloadLog;
1010
import com.liulishuo.filedownloader.util.FileDownloadUtils;
11+
import com.liulishuo.okdownload.core.Util;
1112

1213
import cn.dreamtobe.threaddebugger.IThreadDebugger;
1314
import cn.dreamtobe.threaddebugger.ThreadDebugger;
@@ -27,7 +28,8 @@ public void onCreate() {
2728
CONTEXT = this;
2829

2930
// just for open the log in this demo project.
30-
FileDownloadLog.NEED_LOG = BuildConfig.DOWNLOAD_NEED_LOG;
31+
// FileDownloadLog.NEED_LOG = BuildConfig.DOWNLOAD_NEED_LOG;
32+
Util.enableConsoleLog();
3133

3234
/**
3335
* just for cache Application's Context, and ':filedownloader' progress will NOT be launched

demo/src/main/java/com/liulishuo/filedownloader/demo/TasksManagerDemoActivity.java

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -356,7 +356,8 @@ public void onBindViewHolder(TaskItemViewHolder holder, int position) {
356356

357357

358358
if (TasksManager.getImpl().isReady()) {
359-
final int status = TasksManager.getImpl().getStatus(model.getId(), model.getPath());
359+
// final int status = TasksManager.getImpl().getStatus(model.getId(), model.getPath());
360+
final int status = TasksManager.getImpl().getStatus(model.getUrl(), model.getPath());
360361
if (status == FileDownloadStatus.pending || status == FileDownloadStatus.started ||
361362
status == FileDownloadStatus.connected) {
362363
// start task, but file not created yet
@@ -420,6 +421,8 @@ private void initDemo() {
420421
final String url = Constant.BIG_FILE_URLS[i];
421422
addTask(url);
422423
}
424+
} else {
425+
correctModelId();
423426
}
424427
}
425428

@@ -492,6 +495,15 @@ public void onCreate(final WeakReference<TasksManagerDemoActivity> activityWeakR
492495
}
493496
}
494497

498+
private void correctModelId() {
499+
for (TasksManagerModel model : modelList) {
500+
final BaseDownloadTask task = FileDownloader.getImpl().create(model.getUrl());
501+
model.id = task.getId();
502+
model.name = DemoApplication.CONTEXT
503+
.getString(R.string.tasks_manager_demo_name, model.id);
504+
}
505+
}
506+
495507
public void onDestroy() {
496508
unregisterServiceConnectionListener();
497509
releaseTask();
@@ -524,10 +536,15 @@ public boolean isDownloaded(final int status) {
524536
return status == FileDownloadStatus.completed;
525537
}
526538

539+
@Deprecated
527540
public int getStatus(final int id, String path) {
528541
return FileDownloader.getImpl().getStatus(id, path);
529542
}
530543

544+
public int getStatus(final String url, final String path) {
545+
return FileDownloader.getImpl().getStatus(url, path);
546+
}
547+
531548
public long getTotal(final int id) {
532549
return FileDownloader.getImpl().getTotal(id);
533550
}

0 commit comments

Comments
 (0)