parent
d129e0a802
commit
7ee1347ab4
@ -1,65 +0,0 @@ |
|||||||
/* |
|
||||||
* 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.download.group; |
|
||||||
|
|
||||||
import com.arialyy.aria.core.common.AbsNormalTarget; |
|
||||||
import java.util.List; |
|
||||||
|
|
||||||
/** |
|
||||||
* @Author aria |
|
||||||
* @Date 2019-09-05 |
|
||||||
*/ |
|
||||||
public class GroupTargetFactory { |
|
||||||
|
|
||||||
public static volatile GroupTargetFactory INSTANCE; |
|
||||||
|
|
||||||
private GroupTargetFactory() { |
|
||||||
|
|
||||||
} |
|
||||||
|
|
||||||
public static GroupTargetFactory getInstance() { |
|
||||||
|
|
||||||
if (INSTANCE == null) { |
|
||||||
synchronized (GroupTargetFactory.class) { |
|
||||||
if (INSTANCE == null) { |
|
||||||
INSTANCE = new GroupTargetFactory(); |
|
||||||
} |
|
||||||
} |
|
||||||
} |
|
||||||
|
|
||||||
return INSTANCE; |
|
||||||
} |
|
||||||
|
|
||||||
public <T extends AbsNormalTarget> T generateNormalTarget(Class<T> clazz, long taskId, |
|
||||||
String targetName) { |
|
||||||
T target = null; |
|
||||||
if (clazz == GroupNormalTarget.class) { |
|
||||||
target = (T) new GroupNormalTarget(taskId, targetName); |
|
||||||
} else if (clazz == FtpDirNormalTarget.class) { |
|
||||||
target = (T) new FtpDirNormalTarget(taskId, targetName); |
|
||||||
} |
|
||||||
|
|
||||||
return target; |
|
||||||
} |
|
||||||
|
|
||||||
public FtpDirBuilderTarget generateDirBuilderTarget(String url, String targetName) { |
|
||||||
return new FtpDirBuilderTarget(url, targetName); |
|
||||||
} |
|
||||||
|
|
||||||
public GroupBuilderTarget generateGroupBuilderTarget(List<String> urls, String targetName) { |
|
||||||
return new GroupBuilderTarget(urls, targetName); |
|
||||||
} |
|
||||||
} |
|
@ -0,0 +1,73 @@ |
|||||||
|
/* |
||||||
|
* 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.download.target; |
||||||
|
|
||||||
|
import androidx.annotation.CheckResult; |
||||||
|
import androidx.annotation.NonNull; |
||||||
|
import com.arialyy.aria.core.common.AbsBuilderTarget; |
||||||
|
import com.arialyy.aria.core.common.Suggest; |
||||||
|
import com.arialyy.aria.core.download.tcp.TcpDelegate; |
||||||
|
import com.arialyy.aria.core.inf.ITaskWrapper; |
||||||
|
|
||||||
|
/** |
||||||
|
* @Author aria |
||||||
|
* @Date 2019-09-06 |
||||||
|
*/ |
||||||
|
public class TcpBuilderTarget extends AbsBuilderTarget<TcpBuilderTarget> { |
||||||
|
|
||||||
|
private DNormalConfigHandler mConfigHandler; |
||||||
|
|
||||||
|
TcpBuilderTarget(String ip, int port) { |
||||||
|
mConfigHandler = new DNormalConfigHandler<>(this, -1); |
||||||
|
getTaskWrapper().setRequestType(ITaskWrapper.D_TCP); |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* 设置tcp相应信息 |
||||||
|
*/ |
||||||
|
@CheckResult(suggest = Suggest.TASK_CONTROLLER) |
||||||
|
public TcpDelegate<TcpBuilderTarget> option() { |
||||||
|
return new TcpDelegate<>(this, getTaskWrapper()); |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* 设置文件存储路径,如果需要修改新的文件名,修改路径便可。 |
||||||
|
* 如:原文件路径 /mnt/sdcard/test.zip |
||||||
|
* 如果需要将test.zip改为game.zip,只需要重新设置文件路径为:/mnt/sdcard/game.zip |
||||||
|
* |
||||||
|
* @param filePath 路径必须为文件路径,不能为文件夹路径 |
||||||
|
*/ |
||||||
|
@CheckResult(suggest = Suggest.TASK_CONTROLLER) |
||||||
|
public TcpBuilderTarget setFilePath(@NonNull String filePath) { |
||||||
|
mConfigHandler.setTempFilePath(filePath); |
||||||
|
return this; |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* 设置文件存储路径,如果需要修改新的文件名,修改路径便可。 |
||||||
|
* 如:原文件路径 /mnt/sdcard/test.zip |
||||||
|
* 如果需要将test.zip改为game.zip,只需要重新设置文件路径为:/mnt/sdcard/game.zip |
||||||
|
* |
||||||
|
* @param filePath 路径必须为文件路径,不能为文件夹路径 |
||||||
|
* @param forceDownload {@code true}强制下载,不考虑文件路径是否被占用 |
||||||
|
*/ |
||||||
|
@CheckResult(suggest = Suggest.TASK_CONTROLLER) |
||||||
|
public TcpBuilderTarget setFilePath(@NonNull String filePath, boolean forceDownload) { |
||||||
|
mConfigHandler.setTempFilePath(filePath); |
||||||
|
mConfigHandler.setForceDownload(forceDownload); |
||||||
|
return this; |
||||||
|
} |
||||||
|
} |
@ -0,0 +1,97 @@ |
|||||||
|
/* |
||||||
|
* 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.download.tcp; |
||||||
|
|
||||||
|
import android.text.TextUtils; |
||||||
|
import androidx.annotation.CheckResult; |
||||||
|
import com.arialyy.aria.core.common.BaseDelegate; |
||||||
|
import com.arialyy.aria.core.common.Suggest; |
||||||
|
import com.arialyy.aria.core.download.DTaskWrapper; |
||||||
|
import com.arialyy.aria.core.inf.AbsTarget; |
||||||
|
import com.arialyy.aria.core.inf.AbsTaskWrapper; |
||||||
|
import com.arialyy.aria.util.ALog; |
||||||
|
import java.nio.charset.Charset; |
||||||
|
|
||||||
|
/** |
||||||
|
* @Author aria |
||||||
|
* @Date 2019-09-06 |
||||||
|
*/ |
||||||
|
public class TcpDelegate<TARGET extends AbsTarget> extends BaseDelegate<TARGET> { |
||||||
|
|
||||||
|
private TcpTaskConfig mTcpConfig; |
||||||
|
|
||||||
|
public TcpDelegate(TARGET target, AbsTaskWrapper wrapper) { |
||||||
|
super(target, wrapper); |
||||||
|
|
||||||
|
mTcpConfig = ((DTaskWrapper) wrapper).asTcp(); |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* 上传给tcp服务的初始数据,一般是文件名、文件路径等信息 |
||||||
|
*/ |
||||||
|
@CheckResult(suggest = Suggest.TO_CONTROLLER) |
||||||
|
public TcpDelegate<TARGET> setParam(String params) { |
||||||
|
if (TextUtils.isEmpty(params)) { |
||||||
|
ALog.w(TAG, "tcp传输的数据不能为空"); |
||||||
|
return this; |
||||||
|
} |
||||||
|
mTcpConfig.setParams(params); |
||||||
|
return this; |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* 设置心跳包传输的数据 |
||||||
|
* |
||||||
|
* @param heartbeatInfo 心跳包数据 |
||||||
|
*/ |
||||||
|
@CheckResult(suggest = Suggest.TO_CONTROLLER) |
||||||
|
public TcpDelegate<TARGET> setHeartbeatInfo(String heartbeatInfo) { |
||||||
|
if (TextUtils.isEmpty(heartbeatInfo)) { |
||||||
|
ALog.w(TAG, "心跳包传输的数据不能为空"); |
||||||
|
return this; |
||||||
|
} |
||||||
|
mTcpConfig.setHeartbeat(heartbeatInfo); |
||||||
|
return this; |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* 心跳间隔,默认1s |
||||||
|
* |
||||||
|
* @param interval 单位毫秒 |
||||||
|
*/ |
||||||
|
@CheckResult(suggest = Suggest.TO_CONTROLLER) |
||||||
|
public TcpDelegate<TARGET> setHeartbeatInterval(long interval) { |
||||||
|
if (interval <= 0) { |
||||||
|
ALog.w(TAG, "心跳间隔不能小于1毫秒"); |
||||||
|
return this; |
||||||
|
} |
||||||
|
mTcpConfig.setHeartbeatInterval(interval); |
||||||
|
return this; |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* 数据传输编码,默认"utf-8" |
||||||
|
*/ |
||||||
|
public TcpDelegate<TARGET> setCharset(String charset) { |
||||||
|
if (!Charset.isSupported(charset)) { |
||||||
|
ALog.w(TAG, "不支持的编码"); |
||||||
|
return this; |
||||||
|
} |
||||||
|
|
||||||
|
mTcpConfig.setCharset(charset); |
||||||
|
return this; |
||||||
|
} |
||||||
|
} |
@ -0,0 +1,77 @@ |
|||||||
|
/* |
||||||
|
* 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.download.tcp; |
||||||
|
|
||||||
|
/** |
||||||
|
* tcp任务配置 |
||||||
|
* |
||||||
|
* @Author aria |
||||||
|
* @Date 2019-09-06 |
||||||
|
*/ |
||||||
|
public class TcpTaskConfig { |
||||||
|
|
||||||
|
/** |
||||||
|
* 上传给tcp服务的初始数据,一般是文件名等信息 |
||||||
|
*/ |
||||||
|
private String params; |
||||||
|
|
||||||
|
/** |
||||||
|
* 心跳包传输的数据 |
||||||
|
*/ |
||||||
|
private String heartbeat; |
||||||
|
|
||||||
|
/** |
||||||
|
* 心跳间隔,单位毫秒,默认1s |
||||||
|
*/ |
||||||
|
private long heartbeatInterval = 1000; |
||||||
|
|
||||||
|
/** |
||||||
|
* 数据传输编码,默认"utf-8" |
||||||
|
*/ |
||||||
|
private String charset = "utf-8"; |
||||||
|
|
||||||
|
public String getCharset() { |
||||||
|
return charset; |
||||||
|
} |
||||||
|
|
||||||
|
public void setCharset(String charset) { |
||||||
|
this.charset = charset; |
||||||
|
} |
||||||
|
|
||||||
|
public String getHeartbeat() { |
||||||
|
return heartbeat; |
||||||
|
} |
||||||
|
|
||||||
|
public void setHeartbeat(String heartbeat) { |
||||||
|
this.heartbeat = heartbeat; |
||||||
|
} |
||||||
|
|
||||||
|
public long getHeartbeatInterval() { |
||||||
|
return heartbeatInterval; |
||||||
|
} |
||||||
|
|
||||||
|
public void setHeartbeatInterval(long heartbeatInterval) { |
||||||
|
this.heartbeatInterval = heartbeatInterval; |
||||||
|
} |
||||||
|
|
||||||
|
public String getParams() { |
||||||
|
return params; |
||||||
|
} |
||||||
|
|
||||||
|
public void setParams(String params) { |
||||||
|
this.params = params; |
||||||
|
} |
||||||
|
} |
@ -0,0 +1 @@ |
|||||||
|
/build |
@ -0,0 +1,32 @@ |
|||||||
|
apply plugin: 'com.android.library' |
||||||
|
|
||||||
|
android { |
||||||
|
compileSdkVersion rootProject.ext.compileSdkVersion |
||||||
|
buildToolsVersion rootProject.ext.buildToolsVersion |
||||||
|
|
||||||
|
defaultConfig { |
||||||
|
minSdkVersion rootProject.ext.minSdkVersion |
||||||
|
targetSdkVersion rootProject.ext.targetSdkVersion |
||||||
|
versionCode 1 |
||||||
|
versionName "1.0" |
||||||
|
|
||||||
|
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" |
||||||
|
consumerProguardFiles 'consumer-rules.pro' |
||||||
|
} |
||||||
|
|
||||||
|
buildTypes { |
||||||
|
release { |
||||||
|
minifyEnabled false |
||||||
|
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro' |
||||||
|
} |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
dependencies { |
||||||
|
implementation fileTree(dir: 'libs', include: ['*.jar']) |
||||||
|
|
||||||
|
implementation "androidx.appcompat:appcompat:${rootProject.ext.XAppcompatVersion}" |
||||||
|
|
||||||
|
testImplementation 'junit:junit:4.12' |
||||||
|
implementation project(path: ':AriaFtpPlug') |
||||||
|
} |
@ -0,0 +1,21 @@ |
|||||||
|
# Add project specific ProGuard rules here. |
||||||
|
# You can control the set of applied configuration files using the |
||||||
|
# proguardFiles setting in build.gradle. |
||||||
|
# |
||||||
|
# For more details, see |
||||||
|
# http://developer.android.com/guide/developing/tools/proguard.html |
||||||
|
|
||||||
|
# If your project uses WebView with JS, uncomment the following |
||||||
|
# and specify the fully qualified class name to the JavaScript interface |
||||||
|
# class: |
||||||
|
#-keepclassmembers class fqcn.of.javascript.interface.for.webview { |
||||||
|
# public *; |
||||||
|
#} |
||||||
|
|
||||||
|
# Uncomment this to preserve the line number information for |
||||||
|
# debugging stack traces. |
||||||
|
#-keepattributes SourceFile,LineNumberTable |
||||||
|
|
||||||
|
# If you keep the line number information, uncomment this to |
||||||
|
# hide the original source file name. |
||||||
|
#-renamesourcefileattribute SourceFile |
@ -0,0 +1,26 @@ |
|||||||
|
package com.example.ariaftpcomponent; |
||||||
|
|
||||||
|
import android.content.Context; |
||||||
|
import androidx.test.platform.app.InstrumentationRegistry; |
||||||
|
import androidx.test.ext.junit.runners.AndroidJUnit4; |
||||||
|
|
||||||
|
import org.junit.Test; |
||||||
|
import org.junit.runner.RunWith; |
||||||
|
|
||||||
|
import static org.junit.Assert.*; |
||||||
|
|
||||||
|
/** |
||||||
|
* Instrumented test, which will execute on an Android device. |
||||||
|
* |
||||||
|
* @see <a href="http://d.android.com/tools/testing">Testing documentation</a> |
||||||
|
*/ |
||||||
|
@RunWith(AndroidJUnit4.class) |
||||||
|
public class ExampleInstrumentedTest { |
||||||
|
@Test |
||||||
|
public void useAppContext() { |
||||||
|
// Context of the app under test.
|
||||||
|
Context appContext = InstrumentationRegistry.getInstrumentation().getTargetContext(); |
||||||
|
|
||||||
|
assertEquals("com.example.ariaftpcomponent.test", appContext.getPackageName()); |
||||||
|
} |
||||||
|
} |
@ -0,0 +1,2 @@ |
|||||||
|
<manifest xmlns:android="http://schemas.android.com/apk/res/android" |
||||||
|
package="com.example.ariaftpcomponent" /> |
@ -0,0 +1,4 @@ |
|||||||
|
package com.arialyy.aria.ftpcomponent; |
||||||
|
|
||||||
|
public class bb { |
||||||
|
} |
@ -0,0 +1,3 @@ |
|||||||
|
<resources> |
||||||
|
<string name="app_name">AriaFtpComponent</string> |
||||||
|
</resources> |
@ -0,0 +1,17 @@ |
|||||||
|
package com.example.ariaftpcomponent; |
||||||
|
|
||||||
|
import org.junit.Test; |
||||||
|
|
||||||
|
import static org.junit.Assert.*; |
||||||
|
|
||||||
|
/** |
||||||
|
* Example local unit test, which will execute on the development machine (host). |
||||||
|
* |
||||||
|
* @see <a href="http://d.android.com/tools/testing">Testing documentation</a> |
||||||
|
*/ |
||||||
|
public class ExampleUnitTest { |
||||||
|
@Test |
||||||
|
public void addition_isCorrect() { |
||||||
|
assertEquals(4, 2 + 2); |
||||||
|
} |
||||||
|
} |
@ -1 +1 @@ |
|||||||
include ':app', ':Aria', ':AriaAnnotations', ':AriaCompiler', ':AriaFtpPlug', ':AppFrame' |
include ':app', ':Aria', ':AriaAnnotations', ':AriaCompiler', ':AriaFtpPlug', ':AppFrame', ':AriaFtpComponent' |
||||||
|
Loading…
Reference in new issue