Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add text column db #209

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions android/.project
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>android</name>
<comment>Project android created by Buildship.</comment>
<projects>
</projects>
<buildSpec>
<buildCommand>
<name>org.eclipse.buildship.core.gradleprojectbuilder</name>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>org.eclipse.buildship.core.gradleprojectnature</nature>
</natures>
</projectDescription>
Comment on lines +1 to +17
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like an autogenerated file included by mistake - please delete it.

13 changes: 13 additions & 0 deletions android/.settings/org.eclipse.buildship.core.prefs
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
arguments=
auto.sync=false
build.scans.enabled=false
connection.gradle.distribution=GRADLE_DISTRIBUTION(VERSION(6.0-20191016123526+0000))
connection.project.dir=
eclipse.preferences.version=1
gradle.user.home=
java.home=/usr/lib/jvm/java-11-openjdk-amd64
jvm.arguments=
offline.mode=false
override.workspace.settings=true
show.console.view=true
show.executions.view=true
Comment on lines +1 to +13
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same here.

Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ public class DownloadTask {
int progress;
String url;
String filename;
String additionalinfo;
String savedDir;
String headers;
String mimeType;
Expand All @@ -15,14 +16,15 @@ public class DownloadTask {
boolean openFileFromNotification;
long timeCreated;

DownloadTask(int primaryId, String taskId, int status, int progress, String url, String filename, String savedDir,
DownloadTask(int primaryId, String taskId, int status, int progress, String url, String filename, String additionalinfo, String savedDir,
String headers, String mimeType, boolean resumable, boolean showNotification, boolean openFileFromNotification, long timeCreated) {
this.primaryId = primaryId;
this.taskId = taskId;
this.status = status;
this.progress = progress;
this.url = url;
this.filename = filename;
this.additionalinfo = additionalinfo;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd rename this field to extra.

this.savedDir = savedDir;
this.headers = headers;
this.mimeType = mimeType;
Expand All @@ -34,6 +36,6 @@ public class DownloadTask {

@Override
public String toString() {
return "DownloadTask{taskId=" + taskId + ",status=" + status + ",progress=" + progress + ",url=" + url + ",filename=" + filename + ",savedDir=" + savedDir + ",headers=" + headers + "}";
return "DownloadTask{taskId=" + taskId + ",status=" + status + ",progress=" + progress + ",url=" + url + ",filename=" + filename + ",additionalinfo=" + additionalinfo + ",savedDir=" + savedDir + ",headers=" + headers + "}";
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@
public class DownloadWorker extends Worker implements MethodChannel.MethodCallHandler {
public static final String ARG_URL = "url";
public static final String ARG_FILE_NAME = "file_name";
public static final String ARG_ADDITIONAL_INFO = "additional_info";
public static final String ARG_SAVED_DIR = "saved_file";
public static final String ARG_HEADERS = "headers";
public static final String ARG_IS_RESUME = "is_resume";
Expand Down Expand Up @@ -159,6 +160,7 @@ public Result doWork() {

String url = getInputData().getString(ARG_URL);
String filename = getInputData().getString(ARG_FILE_NAME);
String additionalinfo = getInputData().getString(ARG_ADDITIONAL_INFO);
String savedDir = getInputData().getString(ARG_SAVED_DIR);
String headers = getInputData().getString(ARG_HEADERS);
boolean isResume = getInputData().getBoolean(ARG_IS_RESUME, false);
Expand All @@ -171,7 +173,7 @@ public Result doWork() {
msgPaused = res.getString(R.string.flutter_downloader_notification_paused);
msgComplete = res.getString(R.string.flutter_downloader_notification_complete);

Log.d(TAG, "DownloadWorker{url=" + url + ",filename=" + filename + ",savedDir=" + savedDir + ",header=" + headers + ",isResume=" + isResume);
Log.d(TAG, "DownloadWorker{url=" + url + ",filename=" + filename + ",additionalinfo=" + additionalinfo + ",savedDir=" + savedDir + ",header=" + headers + ",isResume=" + isResume);

showNotification = getInputData().getBoolean(ARG_SHOW_NOTIFICATION, false);
clickToOpenDownloadedFile = getInputData().getBoolean(ARG_OPEN_FILE_FROM_NOTIFICATION, false);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ public void onDetachedFromEngine(FlutterPluginBinding binding) {
flutterChannel = null;
}

private WorkRequest buildRequest(String url, String savedDir, String filename, String headers, boolean showNotification, boolean openFileFromNotification, boolean isResume, boolean requiresStorageNotLow) {
private WorkRequest buildRequest(String url, String savedDir, String filename, String additionalinfo, String headers, boolean showNotification, boolean openFileFromNotification, boolean isResume, boolean requiresStorageNotLow) {
WorkRequest request = new OneTimeWorkRequest.Builder(DownloadWorker.class)
.setConstraints(new Constraints.Builder()
.setRequiresStorageNotLow(requiresStorageNotLow)
Expand All @@ -121,6 +121,7 @@ private WorkRequest buildRequest(String url, String savedDir, String filename, S
.putString(DownloadWorker.ARG_URL, url)
.putString(DownloadWorker.ARG_SAVED_DIR, savedDir)
.putString(DownloadWorker.ARG_FILE_NAME, filename)
.putString(DownloadWorker.ARG_ADDITIONAL_INFO, additionalinfo)
.putString(DownloadWorker.ARG_HEADERS, headers)
.putBoolean(DownloadWorker.ARG_SHOW_NOTIFICATION, showNotification)
.putBoolean(DownloadWorker.ARG_OPEN_FILE_FROM_NOTIFICATION, openFileFromNotification)
Expand Down Expand Up @@ -160,16 +161,17 @@ private void enqueue(MethodCall call, MethodChannel.Result result) {
String url = call.argument("url");
String savedDir = call.argument("saved_dir");
String filename = call.argument("file_name");
String additionalinfo = call.argument("additional_info");
String headers = call.argument("headers");
boolean showNotification = call.argument("show_notification");
boolean openFileFromNotification = call.argument("open_file_from_notification");
boolean requiresStorageNotLow = call.argument("requires_storage_not_low");
WorkRequest request = buildRequest(url, savedDir, filename, headers, showNotification, openFileFromNotification, false, requiresStorageNotLow);
WorkRequest request = buildRequest(url, savedDir, filename, additionalinfo, headers, showNotification, openFileFromNotification, false, requiresStorageNotLow);
WorkManager.getInstance(context).enqueue(request);
String taskId = request.getId().toString();
result.success(taskId);
sendUpdateProgress(taskId, DownloadStatus.ENQUEUED, 0);
taskDao.insertOrUpdateNewTask(taskId, url, DownloadStatus.ENQUEUED, 0, filename, savedDir, headers, showNotification, openFileFromNotification);
taskDao.insertOrUpdateNewTask(taskId, url, DownloadStatus.ENQUEUED, 0, filename, additionalinfo, savedDir, headers, showNotification, openFileFromNotification);
}

private void loadTasks(MethodCall call, MethodChannel.Result result) {
Expand All @@ -182,6 +184,7 @@ private void loadTasks(MethodCall call, MethodChannel.Result result) {
item.put("progress", task.progress);
item.put("url", task.url);
item.put("file_name", task.filename);
item.put("additional_info", task.additionalinfo);
item.put("saved_dir", task.savedDir);
item.put("time_created", task.timeCreated);
array.add(item);
Expand All @@ -200,6 +203,7 @@ private void loadTasksWithRawQuery(MethodCall call, MethodChannel.Result result)
item.put("progress", task.progress);
item.put("url", task.url);
item.put("file_name", task.filename);
item.put("additional_info", task.additionalinfo);
item.put("saved_dir", task.savedDir);
item.put("time_created", task.timeCreated);
array.add(item);
Expand Down Expand Up @@ -238,7 +242,7 @@ private void resume(MethodCall call, MethodChannel.Result result) {
String partialFilePath = task.savedDir + File.separator + filename;
File partialFile = new File(partialFilePath);
if (partialFile.exists()) {
WorkRequest request = buildRequest(task.url, task.savedDir, task.filename, task.headers, task.showNotification, task.openFileFromNotification, true, requiresStorageNotLow);
WorkRequest request = buildRequest(task.url, task.savedDir, task.filename, task.additionalinfo, task.headers, task.showNotification, task.openFileFromNotification, true, requiresStorageNotLow);
String newTaskId = request.getId().toString();
result.success(newTaskId);
sendUpdateProgress(newTaskId, DownloadStatus.RUNNING, task.progress);
Expand All @@ -261,7 +265,7 @@ private void retry(MethodCall call, MethodChannel.Result result) {
boolean requiresStorageNotLow = call.argument("requires_storage_not_low");
if (task != null) {
if (task.status == DownloadStatus.FAILED || task.status == DownloadStatus.CANCELED) {
WorkRequest request = buildRequest(task.url, task.savedDir, task.filename, task.headers, task.showNotification, task.openFileFromNotification, false, requiresStorageNotLow);
WorkRequest request = buildRequest(task.url, task.savedDir, task.filename, task.additionalinfo, task.headers, task.showNotification, task.openFileFromNotification, false, requiresStorageNotLow);
String newTaskId = request.getId().toString();
result.success(newTaskId);
sendUpdateProgress(newTaskId, DownloadStatus.ENQUEUED, task.progress);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ public static class TaskEntry implements BaseColumns {
public static final String COLUMN_NAME_URL = "url";
public static final String COLUMN_NAME_SAVED_DIR = "saved_dir";
public static final String COLUMN_NAME_FILE_NAME = "file_name";
public static final String COLUMN_NAME_ADDITIONAL_INFO = "additional_info";
public static final String COLUMN_NAME_MIME_TYPE = "mime_type";
public static final String COLUMN_NAME_RESUMABLE = "resumable";
public static final String COLUMN_NAME_HEADERS = "headers";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ public class TaskDao {
TaskContract.TaskEntry.COLUMN_NAME_STATUS,
TaskContract.TaskEntry.COLUMN_NAME_URL,
TaskContract.TaskEntry.COLUMN_NAME_FILE_NAME,
TaskContract.TaskEntry.COLUMN_NAME_ADDITIONAL_INFO,
TaskContract.TaskEntry.COLUMN_NAME_SAVED_DIR,
TaskContract.TaskEntry.COLUMN_NAME_HEADERS,
TaskContract.TaskEntry.COLUMN_NAME_MIME_TYPE,
Expand All @@ -31,7 +32,7 @@ public TaskDao(TaskDbHelper helper) {
dbHelper = helper;
}

public void insertOrUpdateNewTask(String taskId, String url, int status, int progress, String fileName,
public void insertOrUpdateNewTask(String taskId, String url, int status, int progress, String fileName, String additionalinfo,
String savedDir, String headers, boolean showNotification, boolean openFileFromNotification) {
SQLiteDatabase db = dbHelper.getWritableDatabase();

Expand All @@ -41,6 +42,7 @@ public void insertOrUpdateNewTask(String taskId, String url, int status, int pro
values.put(TaskContract.TaskEntry.COLUMN_NAME_STATUS, status);
values.put(TaskContract.TaskEntry.COLUMN_NAME_PROGRESS, progress);
values.put(TaskContract.TaskEntry.COLUMN_NAME_FILE_NAME, fileName);
values.put(TaskContract.TaskEntry.COLUMN_NAME_ADDITIONAL_INFO, additionalinfo);
values.put(TaskContract.TaskEntry.COLUMN_NAME_SAVED_DIR, savedDir);
values.put(TaskContract.TaskEntry.COLUMN_NAME_HEADERS, headers);
values.put(TaskContract.TaskEntry.COLUMN_NAME_MIME_TYPE, "unknown");
Expand Down Expand Up @@ -216,14 +218,15 @@ private DownloadTask parseCursor(Cursor cursor) {
int progress = cursor.getInt(cursor.getColumnIndexOrThrow(TaskContract.TaskEntry.COLUMN_NAME_PROGRESS));
String url = cursor.getString(cursor.getColumnIndexOrThrow(TaskContract.TaskEntry.COLUMN_NAME_URL));
String filename = cursor.getString(cursor.getColumnIndexOrThrow(TaskContract.TaskEntry.COLUMN_NAME_FILE_NAME));
String additionalinfo = cursor.getString(cursor.getColumnIndexOrThrow(TaskContract.TaskEntry.COLUMN_NAME_ADDITIONAL_INFO));
String savedDir = cursor.getString(cursor.getColumnIndexOrThrow(TaskContract.TaskEntry.COLUMN_NAME_SAVED_DIR));
String headers = cursor.getString(cursor.getColumnIndexOrThrow(TaskContract.TaskEntry.COLUMN_NAME_HEADERS));
String mimeType = cursor.getString(cursor.getColumnIndexOrThrow(TaskContract.TaskEntry.COLUMN_NAME_MIME_TYPE));
int resumable = cursor.getShort(cursor.getColumnIndexOrThrow(TaskContract.TaskEntry.COLUMN_NAME_RESUMABLE));
int showNotification = cursor.getShort(cursor.getColumnIndexOrThrow(TaskContract.TaskEntry.COLUMN_NAME_SHOW_NOTIFICATION));
int clickToOpenDownloadedFile = cursor.getShort(cursor.getColumnIndexOrThrow(TaskContract.TaskEntry.COLUMN_NAME_OPEN_FILE_FROM_NOTIFICATION));
long timeCreated = cursor.getLong(cursor.getColumnIndexOrThrow(TaskContract.TaskEntry.COLUMN_NAME_TIME_CREATED));
return new DownloadTask(primaryId, taskId, status, progress, url, filename, savedDir, headers,
return new DownloadTask(primaryId, taskId, status, progress, url, filename, additionalinfo, savedDir, headers,
mimeType, resumable == 1, showNotification == 1, clickToOpenDownloadedFile == 1, timeCreated);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ public class TaskDbHelper extends SQLiteOpenHelper {
TaskEntry.COLUMN_NAME_STATUS + " INTEGER DEFAULT 0, " +
TaskEntry.COLUMN_NAME_PROGRESS + " INTEGER DEFAULT 0, " +
TaskEntry.COLUMN_NAME_FILE_NAME + " TEXT, " +
TaskEntry.COLUMN_NAME_ADDITIONAL_INFO + " TEXT, " +
TaskEntry.COLUMN_NAME_SAVED_DIR + " TEXT, " +
TaskEntry.COLUMN_NAME_HEADERS + " TEXT, " +
TaskEntry.COLUMN_NAME_MIME_TYPE + " VARCHAR(128), " +
Expand Down
13 changes: 13 additions & 0 deletions example/.vscode/launch.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"name": "Flutter",
"request": "launch",
"type": "dart"
}
]
}
Comment on lines +1 to +13
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please delete this file.

17 changes: 17 additions & 0 deletions example/android/.project
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>android</name>
<comment>Project android created by Buildship.</comment>
<projects>
</projects>
<buildSpec>
<buildCommand>
<name>org.eclipse.buildship.core.gradleprojectbuilder</name>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>org.eclipse.buildship.core.gradleprojectnature</nature>
</natures>
</projectDescription>
Comment on lines +1 to +17
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please delete.

2 changes: 2 additions & 0 deletions example/android/.settings/org.eclipse.buildship.core.prefs
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
connection.project.dir=
eclipse.preferences.version=1
Comment on lines +1 to +2
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Delete.

6 changes: 6 additions & 0 deletions example/android/app/.classpath
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-11/"/>
<classpathentry kind="con" path="org.eclipse.buildship.core.gradleclasspathcontainer"/>
<classpathentry kind="output" path="bin/default"/>
</classpath>
Comment on lines +1 to +6
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same as above.

23 changes: 23 additions & 0 deletions example/android/app/.project
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>app</name>
<comment>Project app created by Buildship.</comment>
<projects>
</projects>
<buildSpec>
<buildCommand>
<name>org.eclipse.jdt.core.javabuilder</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>org.eclipse.buildship.core.gradleprojectbuilder</name>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>org.eclipse.jdt.core.javanature</nature>
<nature>org.eclipse.buildship.core.gradleprojectnature</nature>
</natures>
</projectDescription>
Comment on lines +1 to +23
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please delete.

Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
connection.project.dir=..
eclipse.preferences.version=1
Comment on lines +1 to +2
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

😕 please remove this file

1 change: 1 addition & 0 deletions example/ios/Flutter/flutter_export_environment.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#!/bin/sh
# This is a generated file; do not edit or check into version control.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Rever this change.

export "FLUTTER_ROOT=/Users/hunghd/Documents/Workspace/flutter"
export "FLUTTER_APPLICATION_PATH=/Users/hunghd/Documents/Workspace/flutter_packages/flutter_downloader/example"
export "FLUTTER_TARGET=lib/main.dart"
Expand Down
1 change: 1 addition & 0 deletions example/lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -393,6 +393,7 @@ class _MyHomePageState extends State<MyHomePage> {
void _requestDownload(_TaskInfo task) async {
task.taskId = await FlutterDownloader.enqueue(
url: task.link,
additionalInfo: 'this is additional info of ${task.link}',
headers: {"auth": "test_for_sql_encoding"},
savedDir: _localPath,
showNotification: true,
Expand Down
Loading