配置文件修改
This commit is contained in:
@ -26,6 +26,7 @@ import android.os.Build;
|
||||
import android.os.Bundle;
|
||||
import android.support.v4.app.Fragment;
|
||||
import android.text.TextUtils;
|
||||
import android.util.Log;
|
||||
import android.widget.PopupWindow;
|
||||
import com.arialyy.aria.core.download.DownloadReceiver;
|
||||
import com.arialyy.aria.core.inf.ICmd;
|
||||
@ -65,8 +66,8 @@ import org.xml.sax.SAXException;
|
||||
DbUtil.init(context.getApplicationContext());
|
||||
APP = context.getApplicationContext();
|
||||
regAppLifeCallback(context);
|
||||
File dFile = new File(Configuration.DOWNLOAD_CONFIG_FILE);
|
||||
File uFile = new File(Configuration.UPLOAD_CONFIG_FILE);
|
||||
File dFile = new File(APP.getFilesDir().getPath() + Configuration.DOWNLOAD_CONFIG_FILE);
|
||||
File uFile = new File(APP.getFilesDir().getPath() +Configuration.UPLOAD_CONFIG_FILE);
|
||||
if (!dFile.exists() || !uFile.exists()) {
|
||||
loadConfig();
|
||||
}
|
||||
@ -105,7 +106,7 @@ import org.xml.sax.SAXException;
|
||||
* 如果需要在代码中修改下载配置,请使用以下方法
|
||||
*
|
||||
* @<code> //修改最大任务队列数
|
||||
* Aria.get(this).getDownloadConfig().setMaxTaskNum(3).save();
|
||||
* Aria.get(this).getDownloadConfig().setMaxTaskNum(3).saveAll();
|
||||
* </code>
|
||||
*/
|
||||
public Configuration.DownloadConfig getDownloadConfig() {
|
||||
@ -116,7 +117,7 @@ import org.xml.sax.SAXException;
|
||||
* 如果需要在代码中修改下载配置,请使用以下方法
|
||||
*
|
||||
* @<code> //修改最大任务队列数
|
||||
* Aria.get(this).getUploadConfig().setMaxTaskNum(3).save();
|
||||
* Aria.get(this).getUploadConfig().setMaxTaskNum(3).saveAll();
|
||||
* </code>
|
||||
*/
|
||||
public Configuration.UploadConfig getUploadConfig() {
|
||||
|
@ -215,7 +215,7 @@ public class ConfigHelper extends DefaultHandler {
|
||||
|
||||
@Override public void endDocument() throws SAXException {
|
||||
super.endDocument();
|
||||
mDownloadConfig.save();
|
||||
mUploadConfig.save();
|
||||
mDownloadConfig.saveAll();
|
||||
mUploadConfig.saveAll();
|
||||
}
|
||||
}
|
||||
|
@ -15,6 +15,8 @@
|
||||
*/
|
||||
package com.arialyy.aria.core;
|
||||
|
||||
import android.util.Log;
|
||||
import com.arialyy.aria.core.queue.DownloadTaskQueue;
|
||||
import com.arialyy.aria.util.CommonUtil;
|
||||
import com.arialyy.aria.util.ReflectionUtil;
|
||||
import java.io.File;
|
||||
@ -35,6 +37,10 @@ class Configuration {
|
||||
* 通用配置
|
||||
*/
|
||||
public static class BaseConfig {
|
||||
/**
|
||||
* 旧任务数
|
||||
*/
|
||||
public static int oldMaxTaskNum = 2;
|
||||
|
||||
/**
|
||||
* 是否发送任务广播,true,发送
|
||||
@ -63,6 +69,7 @@ class Configuration {
|
||||
|
||||
public BaseConfig setOpenBreadCast(boolean openBreadCast) {
|
||||
isOpenBreadCast = openBreadCast;
|
||||
saveKey("isOpenBreadCast", openBreadCast + "");
|
||||
return this;
|
||||
}
|
||||
|
||||
@ -71,7 +78,10 @@ class Configuration {
|
||||
}
|
||||
|
||||
public BaseConfig setMaxTaskNum(int maxTaskNum) {
|
||||
oldMaxTaskNum = this.maxTaskNum;
|
||||
this.maxTaskNum = maxTaskNum;
|
||||
saveKey("maxTaskNum", maxTaskNum + "");
|
||||
DownloadTaskQueue.getInstance().setDownloadNum(maxTaskNum);
|
||||
return this;
|
||||
}
|
||||
|
||||
@ -81,6 +91,7 @@ class Configuration {
|
||||
|
||||
public BaseConfig setReTryNum(int reTryNum) {
|
||||
this.reTryNum = reTryNum;
|
||||
saveKey("reTryNum", reTryNum + "");
|
||||
return this;
|
||||
}
|
||||
|
||||
@ -90,6 +101,7 @@ class Configuration {
|
||||
|
||||
public BaseConfig setReTryInterval(long reTryInterval) {
|
||||
this.reTryInterval = reTryInterval;
|
||||
saveKey("reTryInterval", reTryInterval + "");
|
||||
return this;
|
||||
}
|
||||
|
||||
@ -99,9 +111,25 @@ class Configuration {
|
||||
|
||||
public BaseConfig setConnectTimeOut(long connectTimeOut) {
|
||||
this.connectTimeOut = connectTimeOut;
|
||||
saveKey("connectTimeOut", connectTimeOut + "");
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* 保存key
|
||||
*/
|
||||
void saveKey(String key, String value) {
|
||||
boolean isDownload = this instanceof DownloadConfig;
|
||||
File file = new File(
|
||||
AriaManager.APP.getFilesDir().getPath() + (isDownload ? DOWNLOAD_CONFIG_FILE
|
||||
: UPLOAD_CONFIG_FILE));
|
||||
if (file.exists()) {
|
||||
Properties properties = CommonUtil.loadConfig(file);
|
||||
properties.setProperty(key, value);
|
||||
CommonUtil.saveConfig(file, properties);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 加载配置
|
||||
*/
|
||||
@ -145,7 +173,7 @@ class Configuration {
|
||||
/**
|
||||
* 保存配置
|
||||
*/
|
||||
public void save() {
|
||||
void saveAll() {
|
||||
List<Field> fields = ReflectionUtil.getAllFields(getClass());
|
||||
boolean isDownload = this instanceof DownloadConfig;
|
||||
try {
|
||||
@ -199,6 +227,7 @@ class Configuration {
|
||||
|
||||
public DownloadConfig setiOTimeOut(long iOTimeOut) {
|
||||
this.iOTimeOut = iOTimeOut;
|
||||
saveKey("iOTimeOut", iOTimeOut + "");
|
||||
return this;
|
||||
}
|
||||
|
||||
@ -208,6 +237,7 @@ class Configuration {
|
||||
|
||||
public DownloadConfig setBuffSize(int buffSize) {
|
||||
this.buffSize = buffSize;
|
||||
saveKey("buffSize", buffSize + "");
|
||||
return this;
|
||||
}
|
||||
|
||||
@ -217,6 +247,7 @@ class Configuration {
|
||||
|
||||
public DownloadConfig setCaPath(String caPath) {
|
||||
this.caPath = caPath;
|
||||
saveKey("caPath", caPath);
|
||||
return this;
|
||||
}
|
||||
|
||||
@ -226,6 +257,7 @@ class Configuration {
|
||||
|
||||
public DownloadConfig setCaName(String caName) {
|
||||
this.caName = caName;
|
||||
saveKey("caName", caName);
|
||||
return this;
|
||||
}
|
||||
|
||||
|
@ -122,7 +122,7 @@ public class DownloadTaskQueue
|
||||
|
||||
@Override public void setDownloadNum(int downloadNum) {
|
||||
//原始长度
|
||||
int size = AriaManager.getInstance(AriaManager.APP).getUploadConfig().getMaxTaskNum();
|
||||
int size = AriaManager.getInstance(AriaManager.APP).getDownloadConfig().oldMaxTaskNum;
|
||||
int diff = downloadNum - size;
|
||||
if (size == downloadNum) {
|
||||
Log.d(TAG, "设置的下载任务数和配置文件的下载任务数一直,跳过");
|
||||
|
@ -66,11 +66,11 @@ public interface ITaskQueue<TASK extends ITask, TASK_ENTITY extends ITaskEntity,
|
||||
public int size();
|
||||
|
||||
/**
|
||||
* 设置下载任务数
|
||||
* 设置最大任务数
|
||||
*
|
||||
* @param downloadNum 下载任务数
|
||||
* @param newMaxNum 下载任务数
|
||||
*/
|
||||
public void setDownloadNum(int downloadNum);
|
||||
public void setDownloadNum(int newMaxNum);
|
||||
|
||||
/**
|
||||
* 创建一个新的任务,创建时只是将新任务存储到缓存池
|
||||
|
@ -37,10 +37,8 @@ public class ExecutePool<TASK extends ITask> implements IPool<TASK> {
|
||||
private ArrayBlockingQueue<TASK> mExecuteQueue;
|
||||
private Map<String, TASK> mExecuteArray;
|
||||
private int mSize;
|
||||
private boolean isDownload;
|
||||
|
||||
public ExecutePool(boolean isDownload) {
|
||||
this.isDownload = isDownload;
|
||||
if (isDownload) {
|
||||
mSize = AriaManager.getInstance(AriaManager.APP).getDownloadConfig().getMaxTaskNum();
|
||||
} else {
|
||||
@ -87,11 +85,6 @@ public class ExecutePool<TASK extends ITask> implements IPool<TASK> {
|
||||
}
|
||||
mExecuteQueue = temp;
|
||||
mSize = downloadNum;
|
||||
if (isDownload) {
|
||||
AriaManager.getInstance(AriaManager.APP).getDownloadConfig().setMaxTaskNum(downloadNum);
|
||||
} else {
|
||||
AriaManager.getInstance(AriaManager.APP).getUploadConfig().setMaxTaskNum(downloadNum);
|
||||
}
|
||||
} catch (InterruptedException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
@ -25,7 +25,7 @@
|
||||
|
||||
</string-array>
|
||||
<string-array name="download_url">
|
||||
<item>http://g37.gdl.netease.com/onmyoji_netease_1.apk</item>
|
||||
<item>https://g37.gdl.netease.com/onmyoji_netease_10_1.0.20.apk</item>
|
||||
<item>http://static.gaoshouyou.com/d/eb/f2/dfeba30541f209ab8a50d847fc1661ce.apk</item>
|
||||
<item>http://rs.0.gaoshouyou.com/d/51/46/58514d126c46b8a3f27fc8c7db3b09ec.apk</item>
|
||||
<item>http://rs.0.gaoshouyou.com/d/23/69/07238f952669727878d7a0e180534c8b.apk</item>
|
||||
|
Reference in New Issue
Block a user