parent
d239ecc1e7
commit
1f527572e7
@ -0,0 +1,74 @@ |
||||
/* |
||||
* 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.aria.core.upload; |
||||
|
||||
import android.text.TextUtils; |
||||
import android.util.Log; |
||||
import com.arialyy.aria.core.inf.AbsUploadTarget; |
||||
import com.arialyy.aria.orm.DbEntity; |
||||
|
||||
/** |
||||
* Created by Aria.Lao on 2017/7/27. |
||||
* ftp单任务上传 |
||||
*/ |
||||
public class FtpUploadTarget |
||||
extends AbsUploadTarget<FtpUploadTarget, UploadEntity, UploadTaskEntity> { |
||||
private final String TAG = "FtpUploadTarget"; |
||||
|
||||
FtpUploadTarget(String filePath, String targetName) { |
||||
this.mTargetName = targetName; |
||||
mTaskEntity = DbEntity.findFirst(UploadTaskEntity.class, "key=?", filePath); |
||||
if (mTaskEntity == null) { |
||||
mTaskEntity = new UploadTaskEntity(); |
||||
mTaskEntity.entity = getUploadEntity(filePath); |
||||
} |
||||
if (mTaskEntity.entity == null) { |
||||
mTaskEntity.entity = getUploadEntity(filePath); |
||||
} |
||||
mEntity = mTaskEntity.entity; |
||||
} |
||||
|
||||
/** |
||||
* ftp 用户登录信息 |
||||
* |
||||
* @param userName ftp用户名 |
||||
* @param password ftp用户密码 |
||||
*/ |
||||
public FtpUploadTarget login(String userName, String password) { |
||||
return login(userName, password, null); |
||||
} |
||||
|
||||
/** |
||||
* ftp 用户登录信息 |
||||
* |
||||
* @param userName ftp用户名 |
||||
* @param password ftp用户密码 |
||||
* @param account ftp账号 |
||||
*/ |
||||
public FtpUploadTarget login(String userName, String password, String account) { |
||||
if (TextUtils.isEmpty(userName)) { |
||||
Log.e(TAG, "用户名不能为null"); |
||||
return this; |
||||
} else if (TextUtils.isEmpty(password)) { |
||||
Log.e(TAG, "密码不能为null"); |
||||
return this; |
||||
} |
||||
mTaskEntity.userName = userName; |
||||
mTaskEntity.userPw = password; |
||||
mTaskEntity.account = account; |
||||
return this; |
||||
} |
||||
} |
@ -0,0 +1,66 @@ |
||||
/* |
||||
* 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.aria.core.upload.uploader; |
||||
|
||||
/** |
||||
* Created by lyy on 2016/10/31. |
||||
* 抽象的下载接口 |
||||
*/ |
||||
public interface IUploadUtil { |
||||
|
||||
/** |
||||
* 获取文件大小 |
||||
*/ |
||||
long getFileSize(); |
||||
|
||||
/** |
||||
* 获取当前上传位置 |
||||
*/ |
||||
long getCurrentLocation(); |
||||
|
||||
/** |
||||
* 是否正在下载 |
||||
* |
||||
* @return true, 正在下载 |
||||
*/ |
||||
boolean isUploading(); |
||||
|
||||
/** |
||||
* 取消下载 |
||||
*/ |
||||
void cancelUpload(); |
||||
|
||||
/** |
||||
* 停止下载 |
||||
*/ |
||||
void stopUpload(); |
||||
|
||||
/** |
||||
* 开始下载 |
||||
*/ |
||||
void startUpload(); |
||||
|
||||
/** |
||||
* 从上次断点恢复下载 |
||||
*/ |
||||
void resumeUpload(); |
||||
|
||||
/** |
||||
* 设置最大下载速度 |
||||
*/ |
||||
void setMaxSpeed(double maxSpeed); |
||||
} |
@ -0,0 +1,101 @@ |
||||
/* |
||||
* 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.aria.core.upload.uploader; |
||||
|
||||
import com.arialyy.aria.core.upload.UploadEntity; |
||||
import com.arialyy.aria.core.upload.UploadTaskEntity; |
||||
import java.util.Timer; |
||||
import java.util.TimerTask; |
||||
|
||||
/** |
||||
* Created by Aria.Lao on 2017/7/27. |
||||
* 文件上传器 |
||||
*/ |
||||
public class Uploader implements Runnable, IUploadUtil { |
||||
|
||||
private IUploadListener mListener; |
||||
private UploadTaskEntity mTaskEntity; |
||||
private UploadEntity mEntity; |
||||
private long mCurrentLocation = 0; |
||||
|
||||
private Timer mTimer; |
||||
private boolean isRunning; |
||||
|
||||
Uploader(IUploadListener listener, UploadTaskEntity taskEntity) { |
||||
mListener = listener; |
||||
mTaskEntity = taskEntity; |
||||
mEntity = mTaskEntity.getEntity(); |
||||
} |
||||
|
||||
@Override public long getFileSize() { |
||||
return mEntity.getFileSize(); |
||||
} |
||||
|
||||
@Override public long getCurrentLocation() { |
||||
return mCurrentLocation; |
||||
} |
||||
|
||||
@Override public boolean isUploading() { |
||||
return isRunning; |
||||
} |
||||
|
||||
@Override public void cancelUpload() { |
||||
isRunning = false; |
||||
} |
||||
|
||||
@Override public void stopUpload() { |
||||
isRunning = false; |
||||
} |
||||
|
||||
@Override public void startUpload() { |
||||
new Thread(this).start(); |
||||
} |
||||
|
||||
@Override public void resumeUpload() { |
||||
startUpload(); |
||||
} |
||||
|
||||
@Override public void setMaxSpeed(double maxSpeed) { |
||||
|
||||
} |
||||
|
||||
@Override public void run() { |
||||
isRunning = true; |
||||
} |
||||
|
||||
/** |
||||
* 启动进度获取定时器 |
||||
*/ |
||||
private void startTimer() { |
||||
mTimer = new Timer(true); |
||||
mTimer.schedule(new TimerTask() { |
||||
@Override public void run() { |
||||
//if (mConstance.isComplete() || !mConstance.isDownloading) {
|
||||
// closeTimer();
|
||||
//} else if (mConstance.CURRENT_LOCATION >= 0) {
|
||||
// mListener.onProgress(mConstance.CURRENT_LOCATION);
|
||||
//}
|
||||
} |
||||
}, 0, 1000); |
||||
} |
||||
|
||||
private void closeTimer() { |
||||
if (mTimer != null) { |
||||
mTimer.purge(); |
||||
mTimer.cancel(); |
||||
} |
||||
} |
||||
} |
Loading…
Reference in new issue