Commit dcc89779 authored by fallenstardust's avatar fallenstardust Committed by GitHub

Merge pull request #123 from zhuhongbozhuhongbo/master

修复上版本在添加先行卡服务器时存在的问题
parents 0f418747 2cd758ed
...@@ -162,16 +162,16 @@ public interface Constants { ...@@ -162,16 +162,16 @@ public interface Constants {
String ID1 = "[versionname]"; String ID1 = "[versionname]";
String ID2 = "[download_link]"; String ID2 = "[download_link]";
String ID3 = "#pre_release_code"; String ID3 = "#pre_release_code";
String URL_YGO233_DOWNLOAD_LINK = "https://ygo233.com/download/ygomobile"; //String URL_YGO233_DOWNLOAD_LINK = "https://ygo233.com/download/ygomobile";
String URL_YGO233_ADVANCE = "";//"https://ygo233.com/pre#pre_release_cards";//关闭233先行卡服务器,但不要删除该字段,许多未调用的遗留代码使用该contant String URL_YGO233_ADVANCE = "";//"https://ygo233.com/pre#pre_release_cards";//关闭233先行卡服务器,但不要删除该字段,许多未调用的遗留代码使用该contant
String URL_YGO233_DATAVER = "https://cdn02.moecube.com:444/ygopro-super-pre/data/version.txt"; String URL_YGO233_DATAVER = "https://cdn02.moecube.com:444/ygopro-super-pre/data/version.txt";
String URL_PRE_CARD = "https://cdn02.moecube.com:444/ygopro-super-pre/data/test-release.json"; String URL_PRE_CARD = "https://cdn02.moecube.com:444/ygopro-super-pre/data/test-release.json";
String URL_YGO233_FILE = "https://cdn02.moecube.com:444/ygopro-super-pre/archive/ygopro-super-pre.ypk"; String URL_YGO233_FILE = "https://cdn02.moecube.com:444/ygopro-super-pre/archive/ygopro-super-pre.ypk";
String URL_YGO233_FILE_ALT = "https://cdn02.moecube.com:444/ygopro-super-pre/archive/ygopro-super-pre.ypk"; String URL_YGO233_FILE_ALT = "https://cdn02.moecube.com:444/ygopro-super-pre/archive/ygopro-super-pre.ypk";
String URL_YGO233_BUG_REPORT = "https://ygo233.com/pre#faq"; String URL_YGO233_BUG_REPORT = "https://ygo233.com/pre#faq";
int PORT_YGO233 = 23333; int PORT_Mycard_Super_Pre_Server = 888;
String URL_YGO233_1 = "s1.ygo233.com"; String URL_Mycard_Super_Pre_Server = "mygo.superpre.pro";
String URL_YGO233_2 = "s2.ygo233.com"; //String URL_YGO233_2 = "s2.ygo233.com";
String SERVER_FILE = "server_list.xml"; String SERVER_FILE = "server_list.xml";
String SHARE_FILE = ".share_deck.png"; String SHARE_FILE = ".share_deck.png";
......
...@@ -4,6 +4,9 @@ import net.kk.xml.annotations.XmlElement; ...@@ -4,6 +4,9 @@ import net.kk.xml.annotations.XmlElement;
import java.util.List; import java.util.List;
/**
* 将服务器列表写入xml文件时利用的PO类
*/
@XmlElement("servers") @XmlElement("servers")
public class ServerList { public class ServerList {
@XmlElement("version") @XmlElement("version")
...@@ -20,7 +23,7 @@ public class ServerList { ...@@ -20,7 +23,7 @@ public class ServerList {
} }
public ServerList(int version, List<ServerInfo> serverInfoList) { public ServerList(int version, List<ServerInfo> serverInfoList) {
mServerInfoList = serverInfoList; this.mServerInfoList = serverInfoList;
this.vercode = version; this.vercode = version;
} }
......
package cn.garymb.ygomobile.bean.events; package cn.garymb.ygomobile.bean.events;
/**
* 用于EventBus的事件类型。
*/
public class CardInfoEvent { public class CardInfoEvent {
public int position; public int position;
public boolean toMain; public boolean toMain;
......
package cn.garymb.ygomobile.bean.events; package cn.garymb.ygomobile.bean.events;
/** /**
* 用于EventBus发布的时间类型。 * 用于EventBus的事件类型。
*/ */
public class ExCardEvent { public class ExCardEvent {
public enum EventType { public enum EventType {
......
package cn.garymb.ygomobile.bean.events; package cn.garymb.ygomobile.bean.events;
import cn.garymb.ygomobile.bean.ServerInfo; import cn.garymb.ygomobile.bean.ServerInfo;
/**
* 用于EventBus的事件类型。
*/
public class ServerInfoEvent { public class ServerInfoEvent {
public int position; public int position;
public ServerInfo serverInfo;//为了让接受event的HomeFragment能获取到当前server的端口号等信息,加入该属性 public ServerInfo serverInfo;//为了让接受event的HomeFragment能获取到当前server的端口号等信息,加入该属性
......
...@@ -9,6 +9,7 @@ import com.google.android.material.tabs.TabLayout; ...@@ -9,6 +9,7 @@ import com.google.android.material.tabs.TabLayout;
import cn.garymb.ygomobile.lite.R; import cn.garymb.ygomobile.lite.R;
import cn.garymb.ygomobile.ui.activities.BaseActivity; import cn.garymb.ygomobile.ui.activities.BaseActivity;
import cn.garymb.ygomobile.utils.LogUtil; import cn.garymb.ygomobile.utils.LogUtil;
import cn.garymb.ygomobile.utils.YGOUtil;
public class ExCardActivity extends BaseActivity { public class ExCardActivity extends BaseActivity {
private static final String TAG = String.valueOf(ExCardActivity.class); private static final String TAG = String.valueOf(ExCardActivity.class);
...@@ -47,18 +48,19 @@ public class ExCardActivity extends BaseActivity { ...@@ -47,18 +48,19 @@ public class ExCardActivity extends BaseActivity {
return true; return true;
} }
private int backCounter = 0;
//todo 当未下载完先行卡就退出页面时,会导致软件错误退出。未来通过监听返回事件,判断下载状态,若正在下载则阻拦返回键。 //todo 当未下载完先行卡就退出页面时,会导致软件错误退出。未来通过监听返回事件,判断下载状态,若正在下载则阻拦返回键。
//若发生错误或已完成,则不阻拦返回。 //若发生错误或已完成,则不阻拦返回。
@Override @Override
public void onBackPressed() { public void onBackPressed() {
// 完全由自己控制返回键逻辑,系统不再控制,但是有个前提是: if (ExCardListFragment.downloadState == ExCardListFragment.DownloadState.DOWNLOAD_ING) {
// 不要在Activity的onKeyDown或者OnKeyUp中拦截掉返回键 if (backCounter < 1) {
backCounter++;
// 拦截:就是在OnKeyDown或者OnKeyUp中自己处理了返回键 YGOUtil.showTextToast("下载中,建议不要退出页面,再次按返回键可以退出页面");
//(这里处理之后return true.或者return false都会导致onBackPressed不会执行) return;
}
// 不拦截:在OnKeyDown和OnKeyUp中返回super对应的方法 }
//(如果两个方法都被覆写就分别都要返回super.onKeyDown,super.onKeyUp)
super.onBackPressed(); super.onBackPressed();
} }
......
...@@ -16,7 +16,6 @@ import android.view.View; ...@@ -16,7 +16,6 @@ import android.view.View;
import android.view.ViewGroup; import android.view.ViewGroup;
import android.widget.LinearLayout; import android.widget.LinearLayout;
import android.widget.TextView; import android.widget.TextView;
import android.widget.Toast;
import androidx.annotation.NonNull; import androidx.annotation.NonNull;
import androidx.fragment.app.Fragment; import androidx.fragment.app.Fragment;
...@@ -62,7 +61,7 @@ public class ExCardListFragment extends Fragment { ...@@ -62,7 +61,7 @@ public class ExCardListFragment extends Fragment {
NO_DOWNLOAD NO_DOWNLOAD
} }
private DownloadState downloadState; public static DownloadState downloadState;
@Override @Override
...@@ -126,7 +125,7 @@ public class ExCardListFragment extends Fragment { ...@@ -126,7 +125,7 @@ public class ExCardListFragment extends Fragment {
} else if (ServerUtil.exCardState == ServerUtil.ExCardState.ERROR) { } else if (ServerUtil.exCardState == ServerUtil.ExCardState.ERROR) {
/* 查询不到版本号时,提示toast */ /* 查询不到版本号时,提示toast */
textDownload.setText(R.string.Download); textDownload.setText(R.string.Download);
Toast.makeText(getActivity(), R.string.ex_card_check_toast_message_iii, Toast.LENGTH_LONG).show(); YGOUtil.showTextToast("error" + getString(R.string.ex_card_check_toast_message_iii));
//WebActivity.open(getActivity(), getString(R.string.ex_card_list_title), URL_YGO233_ADVANCE); //WebActivity.open(getActivity(), getString(R.string.ex_card_list_title), URL_YGO233_ADVANCE);
} else if (ServerUtil.exCardState == ServerUtil.ExCardState.UNCHECKED) { } else if (ServerUtil.exCardState == ServerUtil.ExCardState.UNCHECKED) {
//do nothing //do nothing
...@@ -149,10 +148,10 @@ public class ExCardListFragment extends Fragment { ...@@ -149,10 +148,10 @@ public class ExCardListFragment extends Fragment {
downloadState = DownloadState.NO_DOWNLOAD; downloadState = DownloadState.NO_DOWNLOAD;
++FailedCount; ++FailedCount;
if (FailedCount <= 2) { if (FailedCount <= 2) {
Toast.makeText(getActivity(), R.string.Ask_to_Change_Other_Way, Toast.LENGTH_SHORT).show(); YGOUtil.showTextToast(getString(R.string.Ask_to_Change_Other_Way));
downloadfromWeb(URL_YGO233_FILE_ALT); downloadfromWeb(URL_YGO233_FILE_ALT);
} }
YGOUtil.showTextToast("error" + getString(R.string.Download_precard_failed)); YGOUtil.showTextToast("error:" + getString(R.string.Download_Precard_Failed));
break; break;
// case UnzipUtils.ZIP_READY: // case UnzipUtils.ZIP_READY:
// textDownload.setText(R.string.title_use_ex); // textDownload.setText(R.string.title_use_ex);
...@@ -161,15 +160,16 @@ public class ExCardListFragment extends Fragment { ...@@ -161,15 +160,16 @@ public class ExCardListFragment extends Fragment {
downloadState = DownloadState.NO_DOWNLOAD; downloadState = DownloadState.NO_DOWNLOAD;
/* 将先行服务器信息添加到服务器列表中 */ /* 将先行服务器信息添加到服务器列表中 */
String servername = ""; String servername = "";
//todo 改成用安卓的localization机制strings.xml
if (AppsSettings.get().getDataLanguage() == AppsSettings.languageEnum.Chinese.code) if (AppsSettings.get().getDataLanguage() == AppsSettings.languageEnum.Chinese.code)
servername = "23333先行服务器"; servername = "萌卡超先行服";
if (AppsSettings.get().getDataLanguage() == AppsSettings.languageEnum.Korean.code) if (AppsSettings.get().getDataLanguage() == AppsSettings.languageEnum.Korean.code)
servername = "YGOPRO ?? ?? ????"; servername = "Mycard Super-pre Server";
if (AppsSettings.get().getDataLanguage() == AppsSettings.languageEnum.English.code) if (AppsSettings.get().getDataLanguage() == AppsSettings.languageEnum.English.code)
servername = "Mercury23333 OCG/TCG Pre-release"; servername = "Mycard Super-pre Server";
if (AppsSettings.get().getDataLanguage() == AppsSettings.languageEnum.Spanish.code) if (AppsSettings.get().getDataLanguage() == AppsSettings.languageEnum.Spanish.code)
servername = "Mercury23333 OCG/TCG Pre-release"; servername = "Mycard Super-pre Server";
AddServer(getActivity(), servername, "s1.ygo233.com", 23333, "Knight of Hanoi"); AddServer(getActivity(), servername, Constants.URL_Mycard_Super_Pre_Server, Constants.PORT_Mycard_Super_Pre_Server, "Knight of Hanoi");
//changeDownloadButton();在下载完成后,通过EventBus通知下载完成(加入用户点击下载后临时切出本fragment,又在下载完成后切回,通过eventbus能保证按钮样式正确更新 //changeDownloadButton();在下载完成后,通过EventBus通知下载完成(加入用户点击下载后临时切出本fragment,又在下载完成后切回,通过eventbus能保证按钮样式正确更新
/* 注意,要先更新版本号 */ /* 注意,要先更新版本号 */
...@@ -179,8 +179,7 @@ public class ExCardListFragment extends Fragment { ...@@ -179,8 +179,7 @@ public class ExCardListFragment extends Fragment {
DataManager.get().load(true); DataManager.get().load(true);
Toast.makeText(context, R.string.ypk_installed, Toast.LENGTH_LONG).show(); YGOUtil.showTextToast(getString(R.string.ypk_installed));
LogUtil.i("webCrawler", "Ex-card package is installed"); LogUtil.i("webCrawler", "Ex-card package is installed");
/* 如果未开启先行卡设置,则跳转到设置页面 */ /* 如果未开启先行卡设置,则跳转到设置页面 */
...@@ -189,26 +188,11 @@ public class ExCardListFragment extends Fragment { ...@@ -189,26 +188,11 @@ public class ExCardListFragment extends Fragment {
Intent startSetting = new Intent(context, MainActivity.class); Intent startSetting = new Intent(context, MainActivity.class);
startSetting.putExtra("flag", 4); startSetting.putExtra("flag", 4);
startActivity(startSetting); startActivity(startSetting);
Toast.makeText(context, R.string.ypk_go_setting, Toast.LENGTH_LONG).show(); YGOUtil.showTextToast(getString(R.string.ypk_go_setting));
} }
break; break;
// case UnzipUtils.ZIP_UNZIP_EXCEPTION:
// Toast.makeText(context, getString(R.string.install_failed_bcos) + msg.obj,
// Toast.LENGTH_SHORT).show();
// break;
// case HomeFragment.TYPE_GET_DATA_VER_OK:
// WebActivity.exCardVer = msg.obj.toString();
// String oldVer = SharedPreferenceUtil.getExpansionDataVer();
// if (!TextUtils.isEmpty(WebActivity.exCardVer)) {
// if (!WebActivity.exCardVer.equals(oldVer)) {
// //btn_download展示默认视图
// } else {
// btnDownload.setText(R.string.tip_redownload);
// }
// } else {
// showExNew();
// }
} }
} }
}; };
......
...@@ -169,6 +169,32 @@ public class ServerUtil { ...@@ -169,6 +169,32 @@ public class ServerUtil {
} }
} }
/**
* 读取xmlFile指定的本地文件server_list.xml和apk资源文件(assets)下的serverlist.xml,返回其中版本最新的
*
* @param context
* @param xmlFile 指定的本地文件server_list.xml
* @return
* @throws IOException
*/
private static ServerList mergeServerList(Context context, File xmlFile) throws IOException {
/* 读取apk中assets文件夹下的serverlist.xml文件 */
ServerList assetList = ServerListManager.readList(context.getAssets().open(ASSET_SERVER_LIST));
ServerList fileList = xmlFile.exists() ? ServerListManager.readList(new FileInputStream(xmlFile)) : null;
if (fileList == null) {
return assetList;
}
/* 如果apk下assets中的版本号更大,则返回assets下的server列表 */
if (fileList.getVercode() < assetList.getVercode()) {
xmlFile.delete();
return assetList;
}
return fileList;
}
/** /**
* 从资源文件serverlist.xml(或本地文件server_list.xml)解析服务器列表,并将新添加的服务器信息(name,addr,port)合并到服务器列表中。 * 从资源文件serverlist.xml(或本地文件server_list.xml)解析服务器列表,并将新添加的服务器信息(name,addr,port)合并到服务器列表中。
* *
...@@ -178,26 +204,21 @@ public class ServerUtil { ...@@ -178,26 +204,21 @@ public class ServerUtil {
* @param playerName * @param playerName
*/ */
public static void AddServer(Context context, String name, String Addr, int port, String playerName) { public static void AddServer(Context context, String name, String Addr, int port, String playerName) {
/* 读取本地文件server_list.xml */
File xmlFile = new File(context.getFilesDir(), Constants.SERVER_FILE);//读取文件路径下的server_list.xml File xmlFile = new File(context.getFilesDir(), Constants.SERVER_FILE);//读取文件路径下的server_list.xml
List<ServerInfo> serverInfos = new ArrayList<>();
ServerInfo mServerInfo = new ServerInfo();
mServerInfo.setName(name);
mServerInfo.setServerAddr(Addr);
mServerInfo.setPort(port);
mServerInfo.setPlayerName(playerName);
VUiKit.defer().when(() -> { VUiKit.defer().when(() -> {
/* 读取本地文件server_list.xml和资源文件(assets)下的serverlist.xml,返回其中版本最新的 */ return mergeServerList(context, xmlFile);
ServerList assetList = ServerListManager.readList(context.getAssets().open(ASSET_SERVER_LIST));//读取serverlist.xml文件
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) -> { }).done((list) -> {
List<ServerInfo> serverInfos = new ArrayList<>();
ServerInfo mServerInfo = new ServerInfo();
mServerInfo.setName(name);
mServerInfo.setServerAddr(Addr);
mServerInfo.setPort(port);
mServerInfo.setPlayerName(playerName);
boolean hasServer = false; boolean hasServer = false;
if (list != null) { if (list != null) {
serverInfos.clear(); serverInfos.clear();
...@@ -210,7 +231,7 @@ public class ServerUtil { ...@@ -210,7 +231,7 @@ public class ServerUtil {
hasServer = false; hasServer = false;
} }
} }
if (!hasServer && !serverInfos.contains(mServerInfo)) { if (!hasServer && !serverInfos.contains(mServerInfo)) {//todo serverInfos.contains(mServerInfo)好像没必要
serverInfos.add(mServerInfo); serverInfos.add(mServerInfo);
} }
} }
...@@ -234,9 +255,7 @@ public class ServerUtil { ...@@ -234,9 +255,7 @@ public class ServerUtil {
} }
public static boolean isPreServer(int port, String addr) { public static boolean isPreServer(int port, String addr) {
return (port == Constants.PORT_YGO233 && addr.equals(Constants.URL_YGO233_1)) || return (port == Constants.PORT_Mycard_Super_Pre_Server && addr.equals(Constants.URL_Mycard_Super_Pre_Server));
(port == Constants.PORT_YGO233 && addr.equals(Constants.URL_YGO233_2));
} }
} }
...@@ -269,7 +269,8 @@ ...@@ -269,7 +269,8 @@
<string name="Checking_Update">检查更新中,请稍候</string> <string name="Checking_Update">检查更新中,请稍候</string>
<string name="Found_Update">发现新版本,前往下载?</string> <string name="Found_Update">发现新版本,前往下载?</string>
<string name="Checking_Update_Failed">检查更新失败</string> <string name="Checking_Update_Failed">检查更新失败</string>
<string name="Download_precard_failed">先行卡下载失败</string> <string name="Download_Precard_Failed">先行卡下载失败</string>
<string name="Pre_Server_Name">萌卡超先行服</string>
<string name="Ask_to_Change_Other_Way">主线获取失败,尝试备选线路中...</string> <string name="Ask_to_Change_Other_Way">主线获取失败,尝试备选线路中...</string>
<string name="DuelAssistant">决斗助手启用中</string> <string name="DuelAssistant">决斗助手启用中</string>
<string name="masterrule">学习大师规则</string> <string name="masterrule">学习大师规则</string>
......
...@@ -266,7 +266,8 @@ ...@@ -266,7 +266,8 @@
<string name="Checking_Update">Now Checking Update</string> <string name="Checking_Update">Now Checking Update</string>
<string name="Found_Update">New upGrade is Founded, Download?</string> <string name="Found_Update">New upGrade is Founded, Download?</string>
<string name="Checking_Update_Failed">Checking Update Failed</string> <string name="Checking_Update_Failed">Checking Update Failed</string>
<string name="Download_precard_failed">Download pre-cards failed</string> <string name="Download_Precard_Failed">Download pre-cards failed</string>
<string name="Pre_Server_Name">Mycard Super-pre Server</string>
<string name="Ask_to_Change_Other_Way">trying other way...</string> <string name="Ask_to_Change_Other_Way">trying other way...</string>
<string name="DuelAssistant">DuelAssiatant is On</string> <string name="DuelAssistant">DuelAssiatant is On</string>
<string name="masterrule">Master Rule</string> <string name="masterrule">Master Rule</string>
......
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