Commit 55b92a24 authored by fallenstardust's avatar fallenstardust

webactivity调用相同addserver方法

parent 4792f85f
...@@ -5,6 +5,8 @@ import static cn.garymb.ygomobile.Constants.URL_YGO233_ADVANCE; ...@@ -5,6 +5,8 @@ import static cn.garymb.ygomobile.Constants.URL_YGO233_ADVANCE;
import static cn.garymb.ygomobile.Constants.URL_YGO233_FILE; import static cn.garymb.ygomobile.Constants.URL_YGO233_FILE;
import static cn.garymb.ygomobile.Constants.URL_YGO233_FILE_ALT; import static cn.garymb.ygomobile.Constants.URL_YGO233_FILE_ALT;
import static cn.garymb.ygomobile.utils.DownloadUtil.TYPE_DOWNLOAD_EXCEPTION; import static cn.garymb.ygomobile.utils.DownloadUtil.TYPE_DOWNLOAD_EXCEPTION;
import static cn.garymb.ygomobile.utils.DownloadUtil.get;
import static cn.garymb.ygomobile.utils.ServerUtil.AddServer;
import android.annotation.SuppressLint; import android.annotation.SuppressLint;
import android.content.Context; import android.content.Context;
...@@ -121,7 +123,7 @@ public class WebActivity extends BaseActivity implements View.OnClickListener { ...@@ -121,7 +123,7 @@ public class WebActivity extends BaseActivity implements View.OnClickListener {
servername = "YGOPRO 사전 게시 중국서버"; servername = "YGOPRO 사전 게시 중국서버";
if (AppsSettings.get().getDataLanguage() == 2) if (AppsSettings.get().getDataLanguage() == 2)
servername = "Mercury23333 OCG/TCG Pre-release"; servername = "Mercury23333 OCG/TCG Pre-release";
AddServer(servername, "s1.ygo233.com", 23333, "Knight of Hanoi"); AddServer(getActivity(), servername, "s1.ygo233.com", 23333, "Knight of Hanoi");
btn_download.setVisibility(View.GONE); btn_download.setVisibility(View.GONE);
SharedPreferenceUtil.setExpansionDataVer(WebActivity.exCardVer); SharedPreferenceUtil.setExpansionDataVer(WebActivity.exCardVer);
break; break;
...@@ -349,57 +351,6 @@ public class WebActivity extends BaseActivity implements View.OnClickListener { ...@@ -349,57 +351,6 @@ public class WebActivity extends BaseActivity implements View.OnClickListener {
WebActivity.open(context, cardInfo.Name, uri); WebActivity.open(context, cardInfo.Name, uri);
} }
public void AddServer(String name, String Addr, int port, String playername) {
mServerInfo = new ServerInfo();
mServerInfo.setName(name);
mServerInfo.setServerAddr(Addr);
mServerInfo.setPort(port);
mServerInfo.setPlayerName(playername);
VUiKit.defer().when(() -> {
ServerList assetList = ServerListManager.readList(this.getAssets().open(ASSET_SERVER_LIST));
ServerList fileList = xmlFile.exists() ? ServerListManager.readList(new FileInputStream(xmlFile)) : null;
if (fileList == null) {
return assetList;
}
if (fileList.getVercode() < assetList.getVercode()) {
xmlFile.delete();
return assetList;
}
return fileList;
}).done((list) -> {
if (list != null) {
serverInfos.clear();
serverInfos.addAll(list.getServerInfoList());
boolean hasServer = false;
for (int i = 0; i < list.getServerInfoList().size(); i++) {
if (mServerInfo.getPort() != serverInfos.get(i).getPort() && mServerInfo.getServerAddr() != serverInfos.get(i).getServerAddr()) {
continue;
} else {
hasServer = true;
break;
}
}
if (!hasServer && !serverInfos.contains(mServerInfo)) {
serverInfos.add(mServerInfo);
}
saveItems();
}
});
}
public void saveItems() {
OutputStream outputStream = null;
try {
outputStream = new FileOutputStream(xmlFile);
XmlUtils.get().saveXml(new ServerList(SystemUtils.getVersion(getContext()), serverInfos), outputStream);
} catch (Exception e) {
e.printStackTrace();
} finally {
IOUtils.close(outputStream);
}
}
private void downloadfromWeb(String fileUrl) { private void downloadfromWeb(String fileUrl) {
File file = new File(AppsSettings.get().getResourcePath() + "-preRlease.zip"); File file = new File(AppsSettings.get().getResourcePath() + "-preRlease.zip");
if (file.exists()) { if (file.exists()) {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment