From ce43e48097e220a3838524a438016666c22000d2 Mon Sep 17 00:00:00 2001 From: laoyuyu <511455842@qq.com> Date: Sat, 25 May 2019 08:38:57 +0800 Subject: [PATCH] =?UTF-8?q?=E6=96=B0=E5=A2=9Eftp=E4=B8=8A=E4=BC=A0?= =?UTF-8?q?=E6=8B=A6=E6=88=AA=E5=99=A8=20https://github.com/AriaLyy/Aria/i?= =?UTF-8?q?ssues/402?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../core/common/ftp/AbsFtpInfoThread.java | 19 ++-- .../core/common/ftp/AbsFtpThreadTask.java | 4 - .../core/common/ftp/FtpInterceptHandler.java | 12 +- .../aria/core/common/ftp/FtpTaskDelegate.java | 13 +++ .../download/downloader/FtpThreadTask.java | 13 ++- .../upload/uploader/FtpFileInfoThread.java | 21 ++-- .../core/upload/uploader/FtpThreadTask.java | 30 +++-- .../com/arialyy/aria/util/CommonUtil.java | 13 +++ DEV_LOG.md | 1 + app/src/main/AndroidManifest.xml | 14 ++- .../simple/common/ModifyUrlDialog.java | 64 +++++++++++ .../core/download/FtpDownloadActivity.java | 2 +- .../simple/core/upload/FtpUploadActivity.java | 94 ++++++++++++--- .../arialyy/simple/widget/SvgTextView.java | 84 ++++++++++++++ app/src/main/res/drawable/ic_choose_file.xml | 6 + app/src/main/res/drawable/ic_modify.xml | 9 ++ .../main/res/layout/activity_ftp_upload.xml | 41 ++++++- app/src/main/res/layout/dialog_modify_url.xml | 77 +++++++++++++ .../main/res/layout/layout_content_single.xml | 107 ++++++++++++++++++ app/src/main/res/layout/layout_svg_text.xml | 29 +++++ app/src/main/res/values/attr.xml | 21 ++-- app/src/main/res/values/strings.xml | 14 ++- .../main/res/xml/aria_fileprovider_paths.xml | 25 ++++ 23 files changed, 632 insertions(+), 81 deletions(-) create mode 100644 app/src/main/java/com/arialyy/simple/common/ModifyUrlDialog.java create mode 100644 app/src/main/java/com/arialyy/simple/widget/SvgTextView.java create mode 100644 app/src/main/res/drawable/ic_choose_file.xml create mode 100644 app/src/main/res/drawable/ic_modify.xml create mode 100644 app/src/main/res/layout/dialog_modify_url.xml create mode 100644 app/src/main/res/layout/layout_content_single.xml create mode 100644 app/src/main/res/layout/layout_svg_text.xml create mode 100644 app/src/main/res/xml/aria_fileprovider_paths.xml diff --git a/Aria/src/main/java/com/arialyy/aria/core/common/ftp/AbsFtpInfoThread.java b/Aria/src/main/java/com/arialyy/aria/core/common/ftp/AbsFtpInfoThread.java index 672d7104..279c19c3 100644 --- a/Aria/src/main/java/com/arialyy/aria/core/common/ftp/AbsFtpInfoThread.java +++ b/Aria/src/main/java/com/arialyy/aria/core/common/ftp/AbsFtpInfoThread.java @@ -37,6 +37,7 @@ import com.arialyy.aria.exception.BaseException; import com.arialyy.aria.exception.FileNotFoundException; import com.arialyy.aria.exception.TaskException; import com.arialyy.aria.util.ALog; +import com.arialyy.aria.util.CommonUtil; import com.arialyy.aria.util.Regular; import com.arialyy.aria.util.SSLContextUtil; @@ -96,8 +97,7 @@ public abstract class AbsFtpInfoThread info) { diff --git a/Aria/src/main/java/com/arialyy/aria/core/common/ftp/FtpInterceptHandler.java b/Aria/src/main/java/com/arialyy/aria/core/common/ftp/FtpInterceptHandler.java index 28646c7e..53114368 100644 --- a/Aria/src/main/java/com/arialyy/aria/core/common/ftp/FtpInterceptHandler.java +++ b/Aria/src/main/java/com/arialyy/aria/core/common/ftp/FtpInterceptHandler.java @@ -18,7 +18,7 @@ package com.arialyy.aria.core.common.ftp; import android.text.TextUtils; /** - * Ftp上传拦截器处理 + * Ftp上传拦截器处理,只针对新任务有效 * * 如果使用者同时实现{@link Builder#resetFileName(String)}和{@link Builder#coverServerFile}, * 将默认使用{@link Builder#coverServerFile} @@ -29,8 +29,6 @@ public class FtpInterceptHandler { private String newFileName; - private boolean stopUpload; - private FtpInterceptHandler() { } @@ -42,10 +40,6 @@ public class FtpInterceptHandler { return newFileName; } - public boolean isStopUpload() { - return stopUpload; - } - public static final class Builder { private boolean coverServerFile = false; @@ -87,9 +81,7 @@ public class FtpInterceptHandler { */ public FtpInterceptHandler build() { FtpInterceptHandler handler = new FtpInterceptHandler(); - if (stopUpload) { - handler.stopUpload = true; - } else if (coverServerFile) { + if (coverServerFile) { handler.coverServerFile = true; } else if (!TextUtils.isEmpty(newFileName)) { handler.newFileName = newFileName; diff --git a/Aria/src/main/java/com/arialyy/aria/core/common/ftp/FtpTaskDelegate.java b/Aria/src/main/java/com/arialyy/aria/core/common/ftp/FtpTaskDelegate.java index f40cb1d0..a6917b5b 100644 --- a/Aria/src/main/java/com/arialyy/aria/core/common/ftp/FtpTaskDelegate.java +++ b/Aria/src/main/java/com/arialyy/aria/core/common/ftp/FtpTaskDelegate.java @@ -41,6 +41,19 @@ public class FtpTaskDelegate implements ITargetHeadDelegate { */ private IFtpUploadInterceptor uploadInterceptor; + /** + * 上传到服务器文件的新文件名{@link FtpInterceptHandler#getNewFileName()} + */ + private String newFileName; + + public String getNewFileName() { + return newFileName; + } + + public void setNewFileName(String newFileName) { + this.newFileName = newFileName; + } + public IFtpUploadInterceptor getUploadInterceptor() { return uploadInterceptor; } diff --git a/Aria/src/main/java/com/arialyy/aria/core/download/downloader/FtpThreadTask.java b/Aria/src/main/java/com/arialyy/aria/core/download/downloader/FtpThreadTask.java index d58abf6f..8514465a 100644 --- a/Aria/src/main/java/com/arialyy/aria/core/download/downloader/FtpThreadTask.java +++ b/Aria/src/main/java/com/arialyy/aria/core/download/downloader/FtpThreadTask.java @@ -29,6 +29,7 @@ import com.arialyy.aria.exception.AriaIOException; import com.arialyy.aria.exception.TaskException; import com.arialyy.aria.util.ALog; import com.arialyy.aria.util.BufferedRandomAccessFile; +import com.arialyy.aria.util.CommonUtil; import java.io.FileOutputStream; import java.io.IOException; import java.io.InputStream; @@ -84,8 +85,7 @@ class FtpThreadTask extends AbsFtpThreadTask { return this; } String remotePath = - new String(getTaskWrapper().asFtp().getUrlEntity().remotePath.getBytes(charSet), - SERVER_CHARSET); + CommonUtil.convertFtpChar(charSet, getTaskWrapper().asFtp().getUrlEntity().remotePath); ALog.i(TAG, String.format("remotePath【%s】", remotePath)); is = client.retrieveFileStream(remotePath); reply = client.getReplyCode(); @@ -135,7 +135,8 @@ class FtpThreadTask extends AbsFtpThreadTask { return; } ALog.i(TAG, - String.format("任务【%s】线程__%s__下载完毕", getConfig().TEMP_FILE.getName(), getConfig().THREAD_ID)); + String.format("任务【%s】线程__%s__下载完毕", getConfig().TEMP_FILE.getName(), + getConfig().THREAD_ID)); writeConfig(true, getConfig().END_LOCATION); getState().COMPLETE_THREAD_NUM++; if (getState().isComplete()) { @@ -143,7 +144,8 @@ class FtpThreadTask extends AbsFtpThreadTask { boolean success = mergeFile(); if (!success) { mListener.onFail(false, - new TaskException(TAG, String.format("任务【%s】分块文件合并失败", getConfig().TEMP_FILE.getName()))); + new TaskException(TAG, + String.format("任务【%s】分块文件合并失败", getConfig().TEMP_FILE.getName()))); return; } } @@ -216,7 +218,8 @@ class FtpThreadTask extends AbsFtpThreadTask { private void readNormal(InputStream is) { BufferedRandomAccessFile file = null; try { - file = new BufferedRandomAccessFile(getConfig().TEMP_FILE, "rwd", getTaskConfig().getBuffSize()); + file = + new BufferedRandomAccessFile(getConfig().TEMP_FILE, "rwd", getTaskConfig().getBuffSize()); file.seek(getConfig().START_LOCATION); byte[] buffer = new byte[getTaskConfig().getBuffSize()]; int len; diff --git a/Aria/src/main/java/com/arialyy/aria/core/upload/uploader/FtpFileInfoThread.java b/Aria/src/main/java/com/arialyy/aria/core/upload/uploader/FtpFileInfoThread.java index 818a21cb..ac4bd597 100644 --- a/Aria/src/main/java/com/arialyy/aria/core/upload/uploader/FtpFileInfoThread.java +++ b/Aria/src/main/java/com/arialyy/aria/core/upload/uploader/FtpFileInfoThread.java @@ -23,13 +23,12 @@ import com.arialyy.aria.core.common.CompleteInfo; import com.arialyy.aria.core.common.OnFileInfoCallback; import com.arialyy.aria.core.common.TaskRecord; import com.arialyy.aria.core.common.ThreadRecord; -import com.arialyy.aria.core.common.ftp.AbsFtpThreadTask; import com.arialyy.aria.core.common.ftp.FtpInterceptHandler; import com.arialyy.aria.core.common.ftp.IFtpUploadInterceptor; -import com.arialyy.aria.core.queue.UploadTaskQueue; import com.arialyy.aria.core.upload.UTaskWrapper; import com.arialyy.aria.core.upload.UploadEntity; import com.arialyy.aria.util.ALog; +import com.arialyy.aria.util.CommonUtil; import com.arialyy.aria.util.DbDataHelper; import java.io.IOException; import java.util.ArrayList; @@ -59,6 +58,10 @@ class FtpFileInfoThread extends AbsFtpInfoThread { } @Override protected boolean onInterceptor(FTPClient client, FTPFile[] ftpFiles) { + // 旧任务将不做处理,否则断点续传上传将失效 + if (!mTaskWrapper.isNewTask()) { + return true; + } try { IFtpUploadInterceptor interceptor = mTaskWrapper.asFtp().getUploadInterceptor(); if (interceptor != null) { @@ -73,30 +76,26 @@ class FtpFileInfoThread extends AbsFtpInfoThread { FtpInterceptHandler interceptHandler = interceptor.onIntercept(mEntity, files); - if (interceptHandler.isStopUpload()) { - // TODO: 2019-05-22 操作任务停止 - return true; - } - /* 处理远端有同名文件的情况 */ if (files.contains(mEntity.getFileName())) { if (interceptHandler.isCoverServerFile()) { ALog.i(TAG, String.format("远端已拥有同名文件,将覆盖该文件,文件名:%s", mEntity.getFileName())); - boolean b = client.deleteFile( - new String(getRemotePath().getBytes(charSet), AbsFtpThreadTask.SERVER_CHARSET)); + boolean b = client.deleteFile(CommonUtil.convertFtpChar(charSet, getRemotePath())); ALog.d(TAG, String.format("删除文件%s,code: %s, msg: %s", b ? "成功" : "失败", client.getReplyCode(), client.getReplyString())); } else if (!TextUtils.isEmpty(interceptHandler.getNewFileName())) { - ALog.i(TAG, String.format("远端已拥有同名文件,将修改remotePath,文件名:%s,remotePath:%s", + ALog.i(TAG, String.format("远端已拥有同名文件,将修改remotePath,原文件名:%s,新文件名:%s", mEntity.getFileName(), interceptHandler.getNewFileName())); remotePath = mTaskWrapper.asFtp().getUrlEntity().remotePath + "/" + interceptHandler.getNewFileName(); - client.disconnect(); + mTaskWrapper.asFtp().setNewFileName(interceptHandler.getNewFileName()); + closeClient(client); run(); + return false; } } } diff --git a/Aria/src/main/java/com/arialyy/aria/core/upload/uploader/FtpThreadTask.java b/Aria/src/main/java/com/arialyy/aria/core/upload/uploader/FtpThreadTask.java index 62a16fdb..cda1fe28 100644 --- a/Aria/src/main/java/com/arialyy/aria/core/upload/uploader/FtpThreadTask.java +++ b/Aria/src/main/java/com/arialyy/aria/core/upload/uploader/FtpThreadTask.java @@ -15,12 +15,14 @@ */ package com.arialyy.aria.core.upload.uploader; +import android.text.TextUtils; import aria.apache.commons.net.ftp.FTPClient; import aria.apache.commons.net.ftp.FTPReply; import aria.apache.commons.net.ftp.OnFtpInputStreamListener; import com.arialyy.aria.core.common.StateConstance; import com.arialyy.aria.core.common.SubThreadConfig; import com.arialyy.aria.core.common.ftp.AbsFtpThreadTask; +import com.arialyy.aria.core.common.ftp.FtpTaskDelegate; import com.arialyy.aria.core.config.BaseTaskConfig; import com.arialyy.aria.core.config.DownloadConfig; import com.arialyy.aria.core.config.UploadConfig; @@ -31,6 +33,7 @@ import com.arialyy.aria.exception.AriaIOException; import com.arialyy.aria.exception.TaskException; import com.arialyy.aria.util.ALog; import com.arialyy.aria.util.BufferedRandomAccessFile; +import com.arialyy.aria.util.CommonUtil; import java.io.IOException; import java.io.UnsupportedEncodingException; @@ -82,7 +85,8 @@ class FtpThreadTask extends AbsFtpThreadTask { return this; } - file = new BufferedRandomAccessFile(getConfig().TEMP_FILE, "rwd", getTaskConfig().getBuffSize()); + file = + new BufferedRandomAccessFile(getConfig().TEMP_FILE, "rwd", getTaskConfig().getBuffSize()); if (getConfig().START_LOCATION != 0) { //file.skipBytes((int) getConfig().START_LOCATION); file.seek(getConfig().START_LOCATION); @@ -92,7 +96,8 @@ class FtpThreadTask extends AbsFtpThreadTask { return this; } ALog.i(TAG, - String.format("任务【%s】线程__%s__上传完毕", getConfig().TEMP_FILE.getName(), getConfig().THREAD_ID)); + String.format("任务【%s】线程__%s__上传完毕", getConfig().TEMP_FILE.getName(), + getConfig().THREAD_ID)); writeConfig(true, getConfig().END_LOCATION); getState().COMPLETE_THREAD_NUM++; if (getState().isComplete()) { @@ -100,11 +105,13 @@ class FtpThreadTask extends AbsFtpThreadTask { } if (getState().isFail()) { mListener.onFail(false, new TaskException(TAG, - String.format("上传失败,filePath: %s, uploadUrl: %s", getEntity().getFilePath(), getConfig().URL))); + String.format("上传失败,filePath: %s, uploadUrl: %s", getEntity().getFilePath(), + getConfig().URL))); } } catch (IOException e) { fail(mChildCurrentLocation, new AriaIOException(TAG, - String.format("上传失败,filePath: %s, uploadUrl: %s", getEntity().getFilePath(), getConfig().URL))); + String.format("上传失败,filePath: %s, uploadUrl: %s", getEntity().getFilePath(), + getConfig().URL))); } catch (Exception e) { fail(mChildCurrentLocation, new AriaIOException(TAG, null, e)); } finally { @@ -123,10 +130,17 @@ class FtpThreadTask extends AbsFtpThreadTask { } private void initPath() throws UnsupportedEncodingException { - dir = new String(getTaskWrapper().asFtp().getUrlEntity().remotePath.getBytes(charSet), - SERVER_CHARSET); - remotePath = new String(String.format("%s/%s", getTaskWrapper().asFtp().getUrlEntity().remotePath, - getEntity().getFileName()).getBytes(charSet), SERVER_CHARSET); + FtpTaskDelegate delegate = getTaskWrapper().asFtp(); + dir = CommonUtil.convertFtpChar(charSet, delegate.getUrlEntity().remotePath); + + String fileName = + TextUtils.isEmpty(delegate.getNewFileName()) ? CommonUtil.convertFtpChar(charSet, + getEntity().getFileName()) + : CommonUtil.convertFtpChar(charSet, delegate.getNewFileName()); + + remotePath = + CommonUtil.convertFtpChar(charSet, + String.format("%s/%s", delegate.getUrlEntity().remotePath, fileName)); } /** diff --git a/Aria/src/main/java/com/arialyy/aria/util/CommonUtil.java b/Aria/src/main/java/com/arialyy/aria/util/CommonUtil.java index fb7bca62..5b767adf 100644 --- a/Aria/src/main/java/com/arialyy/aria/util/CommonUtil.java +++ b/Aria/src/main/java/com/arialyy/aria/util/CommonUtil.java @@ -78,6 +78,19 @@ import java.util.regex.Pattern; */ public class CommonUtil { private static final String TAG = "CommonUtil"; + public static final String SERVER_CHARSET = "ISO-8859-1"; + + /** + * 将字符串转换为Ftp服务器默认的ISO-8859-1编码 + * + * @param charSet 原字符串编码s + * @param str 需要转换的字符串 + * @return 转换后的字符串 + */ + public static String convertFtpChar(String charSet, String str) + throws UnsupportedEncodingException { + return new String(str.getBytes(charSet), SERVER_CHARSET); + } /** * 检查分块任务是否存在 diff --git a/DEV_LOG.md b/DEV_LOG.md index 51b8385f..e427b920 100644 --- a/DEV_LOG.md +++ b/DEV_LOG.md @@ -1,6 +1,7 @@ ## 开发日志 + v_3.6.5 - fix bug https://github.com/AriaLyy/Aria/issues/403 + - 新增ftp上传拦截器 https://github.com/AriaLyy/Aria/issues/402 + v_3.6.4 (2019/5/16) - 优化任务接收器的代码结构 - 修复`DbEntity.saveAll()`失败的问题 diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index 0cf6ddf8..269769f7 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -18,9 +18,9 @@ - + @@ -44,6 +44,16 @@ + + + + diff --git a/app/src/main/java/com/arialyy/simple/common/ModifyUrlDialog.java b/app/src/main/java/com/arialyy/simple/common/ModifyUrlDialog.java new file mode 100644 index 00000000..ccb14259 --- /dev/null +++ b/app/src/main/java/com/arialyy/simple/common/ModifyUrlDialog.java @@ -0,0 +1,64 @@ +/* + * Copyright (C) 2016 AriaLyy(https://github.com/AriaLyy/Aria) + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.arialyy.simple.common; + +import android.annotation.SuppressLint; +import android.os.Bundle; +import android.view.View; +import com.arialyy.simple.R; +import com.arialyy.simple.base.BaseDialog; +import com.arialyy.simple.databinding.DialogModifyUrlBinding; + +/** + * Created by AriaL on 2017/6/3. + */ +@SuppressLint("ValidFragment") public class ModifyUrlDialog + extends BaseDialog { + public static final int MODIFY_URL_DIALOG_RESULT = 0xA1; + + private String mTitle, mText; + + public ModifyUrlDialog(Object obj, String title, String defaultText) { + super(obj); + mTitle = title; + mText = defaultText; + } + + @Override protected void init(Bundle savedInstanceState) { + super.init(savedInstanceState); + getBinding().setTitle(mTitle); + getBinding().setText(mText); + getBinding().cancel.setOnClickListener(new View.OnClickListener() { + @Override public void onClick(View v) { + dismiss(); + } + }); + getBinding().enter.setOnClickListener(new View.OnClickListener() { + @Override public void onClick(View v) { + getSimplerModule().onDialog(MODIFY_URL_DIALOG_RESULT, mText); + } + }); + getBinding().edit.post(new Runnable() { + @Override public void run() { + getBinding().edit.setSelection(mText.length()); + } + }); + } + + @Override protected int setLayoutId() { + return R.layout.dialog_modify_url; + } +} diff --git a/app/src/main/java/com/arialyy/simple/core/download/FtpDownloadActivity.java b/app/src/main/java/com/arialyy/simple/core/download/FtpDownloadActivity.java index 6c1a3804..6701ef19 100644 --- a/app/src/main/java/com/arialyy/simple/core/download/FtpDownloadActivity.java +++ b/app/src/main/java/com/arialyy/simple/core/download/FtpDownloadActivity.java @@ -35,7 +35,7 @@ import java.io.File; * Ftp下载测试 */ public class FtpDownloadActivity extends BaseActivity { - private final String URL = "sftp://9.9.9.205:2222/Cyberduck-6.9.4.30164.zip"; + private final String URL = "ftp://9.9.9.205:2121/Cyberduck-6.9.4.30164.zip"; //private final String URL = "ftp://182.92.180.213:21/video/572fed5c2ad48_1024.jpg"; //private final String URL = "ftp://182.92.180.213:21/DATA/20180205/rar/1111.rar"; //private final String URL = "ftp://d:d@dygodj8.com:12311/咖啡风暴HD大陆公映意语中字[飘花www.piaohua.com].mp4"; diff --git a/app/src/main/java/com/arialyy/simple/core/upload/FtpUploadActivity.java b/app/src/main/java/com/arialyy/simple/core/upload/FtpUploadActivity.java index 8f58cfa3..c46c6868 100644 --- a/app/src/main/java/com/arialyy/simple/core/upload/FtpUploadActivity.java +++ b/app/src/main/java/com/arialyy/simple/core/upload/FtpUploadActivity.java @@ -15,7 +15,11 @@ */ package com.arialyy.simple.core.upload; +import android.content.Intent; +import android.net.Uri; +import android.os.Build; import android.os.Bundle; +import android.support.v4.content.FileProvider; import android.util.Log; import android.view.View; import com.arialyy.annotations.Upload; @@ -27,8 +31,10 @@ import com.arialyy.aria.core.upload.UploadTask; import com.arialyy.aria.util.CommonUtil; import com.arialyy.frame.util.FileUtil; import com.arialyy.frame.util.show.T; +import com.arialyy.simple.BuildConfig; import com.arialyy.simple.R; import com.arialyy.simple.base.BaseActivity; +import com.arialyy.simple.common.ModifyUrlDialog; import com.arialyy.simple.databinding.ActivityFtpUploadBinding; import java.io.File; import java.util.List; @@ -37,45 +43,81 @@ import java.util.List; * Created by lyy on 2017/7/28. Ftp 文件上传demo */ public class FtpUploadActivity extends BaseActivity { - private final String FILE_PATH = "/mnt/sdcard/AriaPrj.rar"; - private final String URL = "ftp://9.9.9.205:2121/aa/你好"; + private final int OPEN_FILE_MANAGER_CODE = 0xB1; + private String mFilePath = "/mnt/sdcard/AriaPrj.rar"; + private String mUrl = "ftp://9.9.9.205:2121/aa/你好"; @Override protected void init(Bundle savedInstanceState) { setTile("D_FTP 文件上传"); super.init(savedInstanceState); Aria.upload(this).register(); - UploadEntity entity = Aria.upload(this).getUploadEntity(FILE_PATH); + UploadEntity entity = Aria.upload(this).getUploadEntity(mFilePath); if (entity != null) { getBinding().setFileSize(CommonUtil.formatFileSize(entity.getFileSize())); getBinding().setProgress(entity.isComplete() ? 100 : (int) (entity.getCurrentProgress() * 100 / entity.getFileSize())); } + getBinding().setUrl(mUrl); + getBinding().setFilePath(mFilePath); + getBinding().setViewModel(this); } @Override protected int setLayoutId() { return R.layout.activity_ftp_upload; } + public void chooseUrl() { + ModifyUrlDialog dialog = + new ModifyUrlDialog(this, getString(R.string.modify_url_dialog_title), mUrl); + dialog.show(getSupportFragmentManager(), "ModifyUrlDialog"); + } + + public void chooseFilePath() { + + File parentFile = new File(mFilePath); + Intent intent = new Intent(Intent.ACTION_GET_CONTENT); + Uri uri; + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) { + uri = FileProvider.getUriForFile(this, + BuildConfig.APPLICATION_ID + ".provider", + parentFile.getParentFile()); + } else { + uri = Uri.fromFile(parentFile.getParentFile()); + } + + intent.setDataAndType(uri, "*/*"); + intent.addCategory(Intent.CATEGORY_OPENABLE); + intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION); + + startActivityForResult(intent, OPEN_FILE_MANAGER_CODE); + } + public void onClick(View view) { switch (view.getId()) { case R.id.start: - Aria.upload(this).loadFtp(FILE_PATH).setUploadUrl(URL).setUploadInterceptor( - new IFtpUploadInterceptor() { - - @Override - public FtpInterceptHandler onIntercept(UploadEntity entity, List fileList) { - FtpInterceptHandler.Builder builder = new FtpInterceptHandler.Builder(); - builder.coverServerFile(); - //builder.resetFileName("test"); - return builder.build(); - } - }).login("lao", "123456").start(); - break; - case R.id.stop: - Aria.upload(this).loadFtp(FILE_PATH).stop(); + if (Aria.upload(this).load(mFilePath).isRunning()) { + Aria.upload(this).loadFtp(mFilePath).stop(); + getBinding().setStateStr(getString(R.string.resume)); + } else { + getBinding().setStateStr(getString(R.string.stop)); + Aria.upload(this).loadFtp(mFilePath).setUploadUrl(mUrl).setUploadInterceptor( + new IFtpUploadInterceptor() { + + @Override + public FtpInterceptHandler onIntercept(UploadEntity entity, List fileList) { + FtpInterceptHandler.Builder builder = new FtpInterceptHandler.Builder(); + //builder.coverServerFile(); + builder.resetFileName("test.zip"); + return builder.build(); + } + }) + //.login("lao", "123456") + .login("N0rI", "0qcK") + .start(); + } break; case R.id.cancel: - Aria.upload(this).loadFtp(FILE_PATH).cancel(); + Aria.upload(this).loadFtp(mFilePath).cancel(); break; } } @@ -123,4 +165,20 @@ public class FtpUploadActivity extends BaseActivity { getBinding().setSpeed(""); T.showShort(this, "文件:" + task.getEntity().getFileName() + ",上传完成"); } + + @Override protected void dataCallback(int result, Object data) { + super.dataCallback(result, data); + if (result == ModifyUrlDialog.MODIFY_URL_DIALOG_RESULT) { + mUrl = String.valueOf(data); + getBinding().setUrl(mUrl); + } + } + + @Override protected void onActivityResult(int requestCode, int resultCode, Intent data) { + super.onActivityResult(requestCode, resultCode, data); + if (requestCode == OPEN_FILE_MANAGER_CODE && resultCode == RESULT_OK) { + Uri uri = data.getData(); + //Toast.makeText(this, "文件路径:" + uri.getPath(), Toast.LENGTH_SHORT).show(); + } + } } diff --git a/app/src/main/java/com/arialyy/simple/widget/SvgTextView.java b/app/src/main/java/com/arialyy/simple/widget/SvgTextView.java new file mode 100644 index 00000000..cdd72166 --- /dev/null +++ b/app/src/main/java/com/arialyy/simple/widget/SvgTextView.java @@ -0,0 +1,84 @@ +/* + * Copyright (C) 2016 AriaLyy(https://github.com/AriaLyy/Aria) + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.arialyy.simple.widget; + +import android.content.Context; +import android.content.res.TypedArray; +import android.databinding.BindingAdapter; +import android.graphics.drawable.Drawable; +import android.support.annotation.DrawableRes; +import android.support.v7.widget.AppCompatImageView; +import android.text.TextUtils; +import android.util.AttributeSet; +import android.view.LayoutInflater; +import android.view.View; +import android.widget.RelativeLayout; +import android.widget.TextView; +import com.arialyy.simple.R; + +public class SvgTextView extends RelativeLayout { + + private TextView textView; + private AppCompatImageView icon; + + public SvgTextView(Context context) { + this(context, null); + } + + public SvgTextView(Context context, AttributeSet attrs) { + super(context, attrs); + init(attrs); + } + + private void init(AttributeSet attrs) { + LayoutInflater.from(getContext()).inflate(R.layout.layout_svg_text, this, true); + textView = findViewById(R.id.text); + icon = findViewById(R.id.image); + + // init values from custom attributes + final TypedArray attributes = + getContext().obtainStyledAttributes(attrs, R.styleable.SvgTextView); + Drawable drawable = attributes.getDrawable(R.styleable.SvgTextView_svg_text_view_icon); + if (drawable != null) { + icon.setImageDrawable(drawable); + } + String str = attributes.getString(R.styleable.SvgTextView_text); + if (!TextUtils.isEmpty(str)) { + textView.setText(str); + } + + attributes.recycle(); + } + + public void setIconClickListener(View.OnClickListener listener){ + icon.setOnClickListener(listener); + } + + + @BindingAdapter(value = {"svg_text_view_icon"}) + public static void bindAttr(SvgTextView svgTextView, @DrawableRes int drawable) { + svgTextView.icon.setImageResource(drawable); + } + + + public void setIcon(@DrawableRes int drawable) { + icon.setImageResource(drawable); + } + + public void setText(CharSequence text) { + textView.setText(text); + } +} diff --git a/app/src/main/res/drawable/ic_choose_file.xml b/app/src/main/res/drawable/ic_choose_file.xml new file mode 100644 index 00000000..2a4617a0 --- /dev/null +++ b/app/src/main/res/drawable/ic_choose_file.xml @@ -0,0 +1,6 @@ + + + + + diff --git a/app/src/main/res/drawable/ic_modify.xml b/app/src/main/res/drawable/ic_modify.xml new file mode 100644 index 00000000..ee86c638 --- /dev/null +++ b/app/src/main/res/drawable/ic_modify.xml @@ -0,0 +1,9 @@ + + + diff --git a/app/src/main/res/layout/activity_ftp_upload.xml b/app/src/main/res/layout/activity_ftp_upload.xml index 46ac3b31..adab8e88 100644 --- a/app/src/main/res/layout/activity_ftp_upload.xml +++ b/app/src/main/res/layout/activity_ftp_upload.xml @@ -15,6 +15,22 @@ name="progress" type="int" /> + + + + + + + + diff --git a/app/src/main/res/layout/dialog_modify_url.xml b/app/src/main/res/layout/dialog_modify_url.xml new file mode 100644 index 00000000..266ce871 --- /dev/null +++ b/app/src/main/res/layout/dialog_modify_url.xml @@ -0,0 +1,77 @@ + + + + + + + + + + + + + +