任务设置修改

This commit is contained in:
laoyuyu
2019-10-16 20:14:44 +08:00
parent df310b7fbe
commit 550455084f
39 changed files with 802 additions and 809 deletions

View File

@@ -15,8 +15,11 @@
*/
package com.arialyy.aria.core;
import com.arialyy.aria.core.common.BaseOption;
import com.arialyy.aria.core.inf.IEventHandler;
import com.arialyy.aria.core.inf.IOptionConstant;
import com.arialyy.aria.util.CommonUtil;
import java.lang.reflect.Field;
import java.util.HashMap;
import java.util.Map;
@@ -38,6 +41,34 @@ public class TaskOptionParams {
*/
private Map<String, IEventHandler> handler = new HashMap<>();
/**
* 设置任务参数
*
* @param option 任务配置
*/
public void setParams(BaseOption option) {
Field[] fields = CommonUtil.getFields(option.getClass());
for (Field field : fields) {
field.setAccessible(true);
try {
if (field.getType() == IEventHandler.class) {
Object eventHandler = field.get(option);
if (eventHandler != null) {
setObjs(field.getName(), (IEventHandler) eventHandler);
}
} else {
Object params = field.get(option);
if (params != null) {
setParams(field.getName(), params);
}
}
} catch (Exception e) {
e.printStackTrace();
}
}
}
/**
* 设置普通参数
*
@@ -60,11 +91,11 @@ public class TaskOptionParams {
return params;
}
public Object getParam(String key){
public Object getParam(String key) {
return params.get(key);
}
public IEventHandler getHandler(String key){
public IEventHandler getHandler(String key) {
return handler.get(key);
}

View File

@@ -0,0 +1,26 @@
/*
* 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.common;
import com.arialyy.aria.util.CommonUtil;
public abstract class BaseOption {
protected final String TAG;
public BaseOption() {
TAG = CommonUtil.getClassName(getClass());
}
}

View File

@@ -21,17 +21,10 @@ import android.content.Intent;
import android.content.SharedPreferences;
import android.net.Uri;
import android.os.Environment;
import android.os.Handler;
import android.text.TextUtils;
import android.util.Base64;
import com.arialyy.aria.core.AriaConfig;
import com.arialyy.aria.core.FtpUrlEntity;
import com.arialyy.aria.core.TaskOptionParams;
import com.arialyy.aria.core.inf.IEventHandler;
import com.arialyy.aria.core.inf.ITaskOption;
import com.arialyy.aria.core.listener.IEventListener;
import com.arialyy.aria.core.task.ITask;
import com.arialyy.aria.core.wrapper.ITaskWrapper;
import dalvik.system.DexFile;
import java.io.File;
import java.io.FileFilter;
@@ -41,7 +34,6 @@ import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.UnsupportedEncodingException;
import java.lang.ref.SoftReference;
import java.lang.reflect.Field;
import java.lang.reflect.ParameterizedType;
import java.lang.reflect.Type;
@@ -69,7 +61,6 @@ public class CommonUtil {
public static final String SERVER_CHARSET = "ISO-8859-1";
private static long lastClickTime;
/**
* 检查sql的expression是否合法
*