配置文件修改

pull/330/head
AriaLyy 8 years ago
parent e4ba3df523
commit b67ff4ca11
  1. 9
      Aria/src/main/java/com/arialyy/aria/core/AriaManager.java
  2. 4
      Aria/src/main/java/com/arialyy/aria/core/ConfigHelper.java
  3. 34
      Aria/src/main/java/com/arialyy/aria/core/Configuration.java
  4. 2
      Aria/src/main/java/com/arialyy/aria/core/queue/DownloadTaskQueue.java
  5. 6
      Aria/src/main/java/com/arialyy/aria/core/queue/ITaskQueue.java
  6. 7
      Aria/src/main/java/com/arialyy/aria/core/queue/pool/ExecutePool.java
  7. 2
      app/src/main/res/values/strings.xml

@ -26,6 +26,7 @@ import android.os.Build;
import android.os.Bundle; import android.os.Bundle;
import android.support.v4.app.Fragment; import android.support.v4.app.Fragment;
import android.text.TextUtils; import android.text.TextUtils;
import android.util.Log;
import android.widget.PopupWindow; import android.widget.PopupWindow;
import com.arialyy.aria.core.download.DownloadReceiver; import com.arialyy.aria.core.download.DownloadReceiver;
import com.arialyy.aria.core.inf.ICmd; import com.arialyy.aria.core.inf.ICmd;
@ -65,8 +66,8 @@ import org.xml.sax.SAXException;
DbUtil.init(context.getApplicationContext()); DbUtil.init(context.getApplicationContext());
APP = context.getApplicationContext(); APP = context.getApplicationContext();
regAppLifeCallback(context); regAppLifeCallback(context);
File dFile = new File(Configuration.DOWNLOAD_CONFIG_FILE); File dFile = new File(APP.getFilesDir().getPath() + Configuration.DOWNLOAD_CONFIG_FILE);
File uFile = new File(Configuration.UPLOAD_CONFIG_FILE); File uFile = new File(APP.getFilesDir().getPath() +Configuration.UPLOAD_CONFIG_FILE);
if (!dFile.exists() || !uFile.exists()) { if (!dFile.exists() || !uFile.exists()) {
loadConfig(); loadConfig();
} }
@ -105,7 +106,7 @@ import org.xml.sax.SAXException;
* 如果需要在代码中修改下载配置请使用以下方法 * 如果需要在代码中修改下载配置请使用以下方法
* *
* @<code> //修改最大任务队列数 * @<code> //修改最大任务队列数
* Aria.get(this).getDownloadConfig().setMaxTaskNum(3).save(); * Aria.get(this).getDownloadConfig().setMaxTaskNum(3).saveAll();
* </code> * </code>
*/ */
public Configuration.DownloadConfig getDownloadConfig() { public Configuration.DownloadConfig getDownloadConfig() {
@ -116,7 +117,7 @@ import org.xml.sax.SAXException;
* 如果需要在代码中修改下载配置请使用以下方法 * 如果需要在代码中修改下载配置请使用以下方法
* *
* @<code> //修改最大任务队列数 * @<code> //修改最大任务队列数
* Aria.get(this).getUploadConfig().setMaxTaskNum(3).save(); * Aria.get(this).getUploadConfig().setMaxTaskNum(3).saveAll();
* </code> * </code>
*/ */
public Configuration.UploadConfig getUploadConfig() { public Configuration.UploadConfig getUploadConfig() {

@ -215,7 +215,7 @@ public class ConfigHelper extends DefaultHandler {
@Override public void endDocument() throws SAXException { @Override public void endDocument() throws SAXException {
super.endDocument(); super.endDocument();
mDownloadConfig.save(); mDownloadConfig.saveAll();
mUploadConfig.save(); mUploadConfig.saveAll();
} }
} }

@ -15,6 +15,8 @@
*/ */
package com.arialyy.aria.core; 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.CommonUtil;
import com.arialyy.aria.util.ReflectionUtil; import com.arialyy.aria.util.ReflectionUtil;
import java.io.File; import java.io.File;
@ -35,6 +37,10 @@ class Configuration {
* 通用配置 * 通用配置
*/ */
public static class BaseConfig { public static class BaseConfig {
/**
* 旧任务数
*/
public static int oldMaxTaskNum = 2;
/** /**
* 是否发送任务广播true发送 * 是否发送任务广播true发送
@ -63,6 +69,7 @@ class Configuration {
public BaseConfig setOpenBreadCast(boolean openBreadCast) { public BaseConfig setOpenBreadCast(boolean openBreadCast) {
isOpenBreadCast = openBreadCast; isOpenBreadCast = openBreadCast;
saveKey("isOpenBreadCast", openBreadCast + "");
return this; return this;
} }
@ -71,7 +78,10 @@ class Configuration {
} }
public BaseConfig setMaxTaskNum(int maxTaskNum) { public BaseConfig setMaxTaskNum(int maxTaskNum) {
oldMaxTaskNum = this.maxTaskNum;
this.maxTaskNum = maxTaskNum; this.maxTaskNum = maxTaskNum;
saveKey("maxTaskNum", maxTaskNum + "");
DownloadTaskQueue.getInstance().setDownloadNum(maxTaskNum);
return this; return this;
} }
@ -81,6 +91,7 @@ class Configuration {
public BaseConfig setReTryNum(int reTryNum) { public BaseConfig setReTryNum(int reTryNum) {
this.reTryNum = reTryNum; this.reTryNum = reTryNum;
saveKey("reTryNum", reTryNum + "");
return this; return this;
} }
@ -90,6 +101,7 @@ class Configuration {
public BaseConfig setReTryInterval(long reTryInterval) { public BaseConfig setReTryInterval(long reTryInterval) {
this.reTryInterval = reTryInterval; this.reTryInterval = reTryInterval;
saveKey("reTryInterval", reTryInterval + "");
return this; return this;
} }
@ -99,9 +111,25 @@ class Configuration {
public BaseConfig setConnectTimeOut(long connectTimeOut) { public BaseConfig setConnectTimeOut(long connectTimeOut) {
this.connectTimeOut = connectTimeOut; this.connectTimeOut = connectTimeOut;
saveKey("connectTimeOut", connectTimeOut + "");
return this; 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()); List<Field> fields = ReflectionUtil.getAllFields(getClass());
boolean isDownload = this instanceof DownloadConfig; boolean isDownload = this instanceof DownloadConfig;
try { try {
@ -199,6 +227,7 @@ class Configuration {
public DownloadConfig setiOTimeOut(long iOTimeOut) { public DownloadConfig setiOTimeOut(long iOTimeOut) {
this.iOTimeOut = iOTimeOut; this.iOTimeOut = iOTimeOut;
saveKey("iOTimeOut", iOTimeOut + "");
return this; return this;
} }
@ -208,6 +237,7 @@ class Configuration {
public DownloadConfig setBuffSize(int buffSize) { public DownloadConfig setBuffSize(int buffSize) {
this.buffSize = buffSize; this.buffSize = buffSize;
saveKey("buffSize", buffSize + "");
return this; return this;
} }
@ -217,6 +247,7 @@ class Configuration {
public DownloadConfig setCaPath(String caPath) { public DownloadConfig setCaPath(String caPath) {
this.caPath = caPath; this.caPath = caPath;
saveKey("caPath", caPath);
return this; return this;
} }
@ -226,6 +257,7 @@ class Configuration {
public DownloadConfig setCaName(String caName) { public DownloadConfig setCaName(String caName) {
this.caName = caName; this.caName = caName;
saveKey("caName", caName);
return this; return this;
} }

@ -122,7 +122,7 @@ public class DownloadTaskQueue
@Override public void setDownloadNum(int downloadNum) { @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; int diff = downloadNum - size;
if (size == downloadNum) { if (size == downloadNum) {
Log.d(TAG, "设置的下载任务数和配置文件的下载任务数一直,跳过"); Log.d(TAG, "设置的下载任务数和配置文件的下载任务数一直,跳过");

@ -66,11 +66,11 @@ public interface ITaskQueue<TASK extends ITask, TASK_ENTITY extends ITaskEntity,
public int size(); 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 ArrayBlockingQueue<TASK> mExecuteQueue;
private Map<String, TASK> mExecuteArray; private Map<String, TASK> mExecuteArray;
private int mSize; private int mSize;
private boolean isDownload;
public ExecutePool(boolean isDownload) { public ExecutePool(boolean isDownload) {
this.isDownload = isDownload;
if (isDownload) { if (isDownload) {
mSize = AriaManager.getInstance(AriaManager.APP).getDownloadConfig().getMaxTaskNum(); mSize = AriaManager.getInstance(AriaManager.APP).getDownloadConfig().getMaxTaskNum();
} else { } else {
@ -87,11 +85,6 @@ public class ExecutePool<TASK extends ITask> implements IPool<TASK> {
} }
mExecuteQueue = temp; mExecuteQueue = temp;
mSize = downloadNum; mSize = downloadNum;
if (isDownload) {
AriaManager.getInstance(AriaManager.APP).getDownloadConfig().setMaxTaskNum(downloadNum);
} else {
AriaManager.getInstance(AriaManager.APP).getUploadConfig().setMaxTaskNum(downloadNum);
}
} catch (InterruptedException e) { } catch (InterruptedException e) {
e.printStackTrace(); e.printStackTrace();
} }

@ -25,7 +25,7 @@
</string-array> </string-array>
<string-array name="download_url"> <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://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/51/46/58514d126c46b8a3f27fc8c7db3b09ec.apk</item>
<item>http://rs.0.gaoshouyou.com/d/23/69/07238f952669727878d7a0e180534c8b.apk</item> <item>http://rs.0.gaoshouyou.com/d/23/69/07238f952669727878d7a0e180534c8b.apk</item>

Loading…
Cancel
Save