Skip to content
Permalink
Browse files

demo 例子优化

  • Loading branch information
AriaLyy committed Jan 19, 2020
1 parent 7f81995 commit 96efa35c4e2034ae414bc9bed0b4ccd7400d9213
Showing with 918 additions and 1,372 deletions.
  1. +1 −1 Aria/src/main/java/com/arialyy/aria/core/download/CheckDEntityUtil.java
  2. +1 −1 Aria/src/main/java/com/arialyy/aria/core/download/CheckDGEntityUtil.java
  3. +1 −1 Aria/src/main/java/com/arialyy/aria/core/download/CheckFtpDirEntityUtil.java
  4. +1 −1 Aria/src/main/java/com/arialyy/aria/core/upload/CheckUEntityUtil.java
  5. +0 −4 HttpComponent/src/main/java/com/arialyy/aria/http/download/HttpDThreadTaskAdapter.java
  6. +85 −108 app/src/main/java/com/arialyy/simple/core/download/FtpDownloadActivity.java
  7. +90 −88 app/src/main/java/com/arialyy/simple/core/download/SFtpDownloadActivity.java
  8. +34 −82 app/src/main/java/com/arialyy/simple/core/download/SingleTaskActivity.java
  9. +56 −55 app/src/main/java/com/arialyy/simple/core/download/m3u8/M3U8LiveDLoadActivity.java
  10. +45 −62 app/src/main/java/com/arialyy/simple/core/download/m3u8/M3U8VodDLoadActivity.java
  11. +89 −121 app/src/main/java/com/arialyy/simple/core/upload/FtpUploadActivity.java
  12. +31 −33 app/src/main/java/com/arialyy/simple/core/upload/HttpUploadActivity.java
  13. +85 −141 app/src/main/java/com/arialyy/simple/core/upload/SFtpUploadActivity.java
  14. +267 −0 app/src/main/java/com/arialyy/simple/widget/ProgressLayout.java
  15. +9 −0 app/src/main/res/drawable/ic_close.xml
  16. +0 −86 app/src/main/res/layout/activity_ftp_download.xml
  17. +0 −83 app/src/main/res/layout/activity_ftp_upload.xml
  18. +6 −106 app/src/main/res/layout/activity_m3u8_live.xml
  19. +4 −59 app/src/main/res/layout/activity_m3u8_vod.xml
  20. +0 −86 app/src/main/res/layout/activity_sftp_download.xml
  21. +0 −83 app/src/main/res/layout/activity_sftp_upload.xml
  22. +6 −68 app/src/main/res/layout/activity_single.xml
  23. +0 −103 app/src/main/res/layout/activity_upload.xml
  24. +101 −0 app/src/main/res/layout/layout_progress_content.xml
  25. +2 −0 app/src/main/res/values/colors.xml
  26. +4 −0 app/src/main/res/values/strings.xml
@@ -50,7 +50,7 @@ private CheckDEntityUtil(DTaskWrapper wrapper, int action) {
@Override
public boolean checkEntity() {
if (mWrapper.getErrorEvent() != null) {
ALog.e(TAG, String.format("下载失败,%s", mWrapper.getErrorEvent().errorMsg));
ALog.e(TAG, String.format("任务操作失败,%s", mWrapper.getErrorEvent().errorMsg));
return false;
}

@@ -116,7 +116,7 @@ private void reChangeDirPath(String newDirPath) {
@Override
public boolean checkEntity() {
if (mWrapper.getErrorEvent() != null) {
ALog.e(TAG, String.format("操作失败,%s", mWrapper.getErrorEvent().errorMsg));
ALog.e(TAG, String.format("任务操作失败,%s", mWrapper.getErrorEvent().errorMsg));
return false;
}

@@ -78,7 +78,7 @@ private boolean checkDirPath() {
@Override
public boolean checkEntity() {
if (mWrapper.getErrorEvent() != null) {
ALog.e(TAG, String.format("下载失败,%s", mWrapper.getErrorEvent().errorMsg));
ALog.e(TAG, String.format("任务操作失败,%s", mWrapper.getErrorEvent().errorMsg));
return false;
}

@@ -40,7 +40,7 @@ private CheckUEntityUtil(UTaskWrapper wrapper, int action) {
@Override
public boolean checkEntity() {
if (mWrapper.getErrorEvent() != null) {
ALog.e(TAG, String.format("上传失败,%s", mWrapper.getErrorEvent().errorMsg));
ALog.e(TAG, String.format("任务操作失败,%s", mWrapper.getErrorEvent().errorMsg));
return false;
}

@@ -60,10 +60,6 @@
HttpURLConnection conn = null;
BufferedInputStream is = null;
BufferedRandomAccessFile file = null;
if (getThreadRecord().threadId == 1){
fail(null, false);
return;
}
try {
URL url = ConnectionHelp.handleUrl(getThreadConfig().url, mTaskOption);
conn = ConnectionHelp.handleConnection(url, mTaskOption);
@@ -18,34 +18,29 @@
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.Toast;
import androidx.annotation.Nullable;
import androidx.lifecycle.Observer;
import androidx.lifecycle.ViewModelProviders;
import com.arialyy.annotations.Download;
import com.arialyy.aria.core.Aria;
import com.arialyy.aria.core.common.FtpConnectionMode;
import com.arialyy.aria.core.common.AbsEntity;
import com.arialyy.aria.core.common.FtpOption;
import com.arialyy.aria.core.download.DownloadEntity;
import com.arialyy.aria.core.inf.IEntity;
import com.arialyy.aria.core.task.DownloadTask;
import com.arialyy.aria.util.ALog;
import com.arialyy.aria.util.CommonUtil;
import com.arialyy.frame.util.show.L;
import com.arialyy.frame.util.show.T;
import com.arialyy.simple.R;
import com.arialyy.simple.base.BaseActivity;
import com.arialyy.simple.common.DirChooseDialog;
import com.arialyy.simple.common.ModifyUrlDialog;
import com.arialyy.simple.databinding.ActivityFtpDownloadBinding;
import com.arialyy.simple.util.AppUtil;
import com.arialyy.simple.databinding.ActivitySingleBinding;
import com.arialyy.simple.widget.ProgressLayout;
import java.io.File;
import java.io.IOException;

/**
* Created by lyy on 2017/7/25.
* Ftp下载
*/
public class FtpDownloadActivity extends BaseActivity<ActivityFtpDownloadBinding> {
public class FtpDownloadActivity extends BaseActivity<ActivitySingleBinding> {
private String mUrl, mFilePath;
private FtpDownloadModule mModule;
private long mTaskId;
@@ -64,62 +59,36 @@
return;
}
mTaskId = entity.getId();
if (entity.getState() == IEntity.STATE_STOP) {
getBinding().setStateStr(getString(R.string.resume));
} else if (entity.getState() == IEntity.STATE_RUNNING) {
getBinding().setStateStr(getString(R.string.stop));
}

if (entity.getFileSize() != 0) {
getBinding().setFileSize(CommonUtil.formatFileSize(entity.getFileSize()));
getBinding().setProgress(entity.isComplete() ? 100
: (int) (entity.getCurrentProgress() * 100 / entity.getFileSize()));
}
getBinding().setUrl(entity.getUrl());
getBinding().setFilePath(entity.getFilePath());
mUrl = entity.getUrl();
mFilePath = entity.getFilePath();
getBinding().pl.setInfo(entity);
}
});
getBinding().setViewModel(this);
//try {
// getBinding().codeView.setSource(AppUtil.getHelpCode(this, "FtpDownload.java"));
//} catch (IOException e) {
// e.printStackTrace();
//}
}

public void onClick(View view) {
getBinding().pl.setBtListener(new ProgressLayout.OnProgressLayoutBtListener() {
@Override public void create(View v, AbsEntity entity) {
mTaskId = Aria.download(this).loadFtp(mUrl)
.setFilePath(mFilePath)
.ignoreFilePathOccupy()
.option(getFtpOption())
.create();
}

switch (view.getId()) {
case R.id.start:
@Override public void stop(View v, AbsEntity entity) {
Aria.download(this).loadFtp(mTaskId).stop();
}

if (mTaskId == -1) {
mTaskId = Aria.download(this).loadFtp(mUrl)
.setFilePath(mFilePath, true)
.option(getFtpOption())
.create();
getBinding().setStateStr(getString(R.string.stop));
break;
}
if (Aria.download(this).load(mTaskId).isRunning()) {
getBinding().setStateStr(getString(R.string.resume));
Aria.download(this).loadFtp(mTaskId).stop();
} else {
Aria.download(this)
.loadFtp(mTaskId)
.option(getFtpOption())
.resume();
getBinding().setStateStr(getString(R.string.stop));
}
break;
@Override public void resume(View v, AbsEntity entity) {
Aria.download(this)
.loadFtp(mTaskId)
.option(getFtpOption())
.resume();
}

case R.id.cancel:
@Override public void cancel(View v, AbsEntity entity) {
Aria.download(this).loadFtp(mTaskId).cancel();
getBinding().setStateStr(getString(R.string.start));
mTaskId = -1;
break;
}
}
});
}

private FtpOption getFtpOption() {
@@ -130,75 +99,83 @@ private FtpOption getFtpOption() {
return option;
}

public void chooseUrl() {
ModifyUrlDialog dialog =
new ModifyUrlDialog(this, getString(R.string.modify_url_dialog_title), mUrl);
dialog.show(getSupportFragmentManager(), "ModifyUrlDialog");
}

public void chooseFilePath() {
DirChooseDialog dirChooseDialog = new DirChooseDialog(this);
dirChooseDialog.show(getSupportFragmentManager(), "DirChooseDialog");
}

@Download.onPre() protected void onPre(DownloadTask task) {
L.d(TAG, "ftp pre");
@Download.onWait
void onWait(DownloadTask task) {
if (task.getKey().equals(mUrl)) {
Log.d(TAG, "wait ==> " + task.getDownloadEntity().getFileName());
getBinding().pl.setInfo(task.getEntity());
}
}

@Download.onTaskPre() protected void onTaskPre(DownloadTask task) {
L.d(TAG, "ftp task pre, fileSize = " + task.getConvertFileSize());
getBinding().setFileSize(task.getConvertFileSize());
@Download.onPre
protected void onPre(DownloadTask task) {
if (task.getKey().equals(mUrl)) {
getBinding().pl.setInfo(task.getEntity());
}
}

@Download.onTaskStart() void taskStart(DownloadTask task) {
L.d(TAG, "ftp task create");
@Download.onTaskStart
void taskStart(DownloadTask task) {
if (task.getKey().equals(mUrl)) {
getBinding().pl.setInfo(task.getEntity());
ALog.d(TAG, "isComplete = " + task.isComplete() + ", state = " + task.getState());
}
}

@Download.onTaskRunning() protected void running(DownloadTask task) {
ALog.d(TAG, "running, p = " + task.getPercent() + ", speed = " + task.getConvertSpeed());
getBinding().setProgress(task.getPercent());
getBinding().setSpeed(task.getConvertSpeed());
@Download.onTaskRunning
protected void running(DownloadTask task) {
if (task.getKey().equals(mUrl)) {
ALog.d(TAG, "isRunning" + "; state = " + task.getEntity().getState());
getBinding().pl.setInfo(task.getEntity());
}
}

@Download.onTaskResume() void taskResume(DownloadTask task) {
L.d(TAG, "ftp task resume");
@Download.onTaskResume
void taskResume(DownloadTask task) {
if (task.getKey().equals(mUrl)) {
ALog.d(TAG, "resume");
getBinding().pl.setInfo(task.getEntity());
}
}

@Download.onTaskStop() void taskStop(DownloadTask task) {
L.d(TAG, "ftp task stop");
getBinding().setSpeed("");
getBinding().setStateStr(getString(R.string.resume));
@Download.onTaskStop
void taskStop(DownloadTask task) {
if (task.getKey().equals(mUrl)) {
ALog.d(TAG, "stop");
getBinding().pl.setInfo(task.getEntity());
}
}

@Download.onTaskCancel() void taskCancel(DownloadTask task) {
getBinding().setSpeed("");
getBinding().setProgress(0);
@Download.onTaskCancel
void taskCancel(DownloadTask task) {
if (task.getKey().equals(mUrl)) {
mTaskId = -1;
Log.d(TAG, "cancel");
getBinding().pl.setInfo(task.getEntity());
}
}

@Download.onTaskFail() void taskFail(DownloadTask task) {
L.d(TAG, "ftp task fail");
getBinding().setSpeed("");
getBinding().setStateStr(getString(R.string.resume));
@Download.onTaskFail
void taskFail(DownloadTask task, Exception e) {
ALog.d(TAG, "下载失败");
Toast.makeText(this, getString(R.string.download_fail), Toast.LENGTH_SHORT)
.show();
if (task != null && task.getKey().equals(mUrl)) {
getBinding().pl.setInfo(task.getEntity());
}
}

@Download.onTaskComplete() void taskComplete(DownloadTask task) {
getBinding().setSpeed("");
getBinding().setProgress(100);
getBinding().setStateStr(getString(R.string.re_start));
Log.d(TAG, "md5 ==> " + CommonUtil.getFileMD5(new File(task.getFilePath())));
T.showShort(this, "文件:" + task.getEntity().getFileName() + ",下载完成");
@Download.onTaskComplete
void taskComplete(DownloadTask task) {
if (task.getKey().equals(mUrl)) {
Toast.makeText(this, getString(R.string.download_success),
Toast.LENGTH_SHORT).show();
ALog.d(TAG, "md5: " + CommonUtil.getFileMD5(new File(task.getFilePath())));
getBinding().pl.setInfo(task.getEntity());
}
}

@Override protected int setLayoutId() {
return R.layout.activity_ftp_download;
}

@Override protected void dataCallback(int result, Object data) {
super.dataCallback(result, data);
if (result == ModifyUrlDialog.MODIFY_URL_DIALOG_RESULT) {
mModule.uploadUrl(this, String.valueOf(data));
} else if (result == DirChooseDialog.DIR_CHOOSE_DIALOG_RESULT) {
mModule.updateFilePath(this, String.valueOf(data));
}
return R.layout.activity_single;
}
}

0 comments on commit 96efa35

Please sign in to comment.
You can’t perform that action at this time.