Commit 985df11d authored by wangfugui's avatar wangfugui

当网络问题导致无法打开原生先行卡页面时,自动切换为webview页面

parent 08670693
...@@ -277,13 +277,13 @@ public class GameUriManager { ...@@ -277,13 +277,13 @@ public class GameUriManager {
} else { } else {
YGODAUtil.deDeckListener(uri, (uri1, mainList, exList, sideList, isCompleteDeck, exception) -> { YGODAUtil.deDeckListener(uri, (uri1, mainList, exList, sideList, isCompleteDeck, exception) -> {
if (!TextUtils.isEmpty(exception)) { if (!TextUtils.isEmpty(exception)) {
YGOUtil.show("卡组解析失败,原因为:" + exception); YGOUtil.showTextToast("卡组解析失败,原因为:" + exception);
return; return;
} }
Deck deckInfo = new Deck(uri, mainList, exList, sideList); Deck deckInfo = new Deck(uri, mainList, exList, sideList);
File file = deckInfo.saveTemp(AppsSettings.get().getDeckDir()); File file = deckInfo.saveTemp(AppsSettings.get().getDeckDir());
if (!deckInfo.isCompleteDeck()) { if (!deckInfo.isCompleteDeck()) {
YGOUtil.show(activity.getString(R.string.tip_deckInfo_isNot_completeDeck)); YGOUtil.showTextToast("当前卡组缺少完整信息,将只显示已有卡片");
} }
startSetting.putExtra(Intent.EXTRA_TEXT, file.getAbsolutePath()); startSetting.putExtra(Intent.EXTRA_TEXT, file.getAbsolutePath());
activity.startActivity(startSetting); activity.startActivity(startSetting);
...@@ -295,7 +295,7 @@ public class GameUriManager { ...@@ -295,7 +295,7 @@ public class GameUriManager {
if (activity instanceof MainActivity) { if (activity instanceof MainActivity) {
((HomeActivity) activity).fragment_home.quickjoinRoom(host1, port, password); ((HomeActivity) activity).fragment_home.quickjoinRoom(host1, port, password);
} else { } else {
YGOUtil.show(exception); YGOUtil.showTextToast(exception);
} }
}); });
} }
......
...@@ -13,7 +13,6 @@ import android.content.Intent; ...@@ -13,7 +13,6 @@ import android.content.Intent;
import android.os.Bundle; import android.os.Bundle;
import android.os.Handler; import android.os.Handler;
import android.os.Message; import android.os.Message;
import android.util.Log;
import android.view.LayoutInflater; import android.view.LayoutInflater;
import android.view.View; import android.view.View;
import android.view.ViewGroup; import android.view.ViewGroup;
...@@ -50,6 +49,7 @@ import cn.garymb.ygomobile.ui.plus.VUiKit; ...@@ -50,6 +49,7 @@ import cn.garymb.ygomobile.ui.plus.VUiKit;
import cn.garymb.ygomobile.utils.DownloadUtil; import cn.garymb.ygomobile.utils.DownloadUtil;
import cn.garymb.ygomobile.utils.FileUtils; import cn.garymb.ygomobile.utils.FileUtils;
import cn.garymb.ygomobile.utils.IOUtils; import cn.garymb.ygomobile.utils.IOUtils;
import cn.garymb.ygomobile.utils.LogUtil;
import cn.garymb.ygomobile.utils.ServerUtil; import cn.garymb.ygomobile.utils.ServerUtil;
import cn.garymb.ygomobile.utils.SharedPreferenceUtil; import cn.garymb.ygomobile.utils.SharedPreferenceUtil;
import cn.garymb.ygomobile.utils.SystemUtils; import cn.garymb.ygomobile.utils.SystemUtils;
...@@ -70,7 +70,7 @@ public class ExCardListFragment extends Fragment implements View.OnClickListener ...@@ -70,7 +70,7 @@ public class ExCardListFragment extends Fragment implements View.OnClickListener
private int FailedCount; private int FailedCount;
/** /**
* 用于标志当前下载状态,用于防止用户多次重复点击“下载按钮” * 用于标志当前下载状态,用于防止用户多次重复点击“下载按钮”
* Mark the download state, which can prevent user from clicking the download button * Mark the download state, which can prevent user from clicking the download button
* repeatedly. * repeatedly.
*/ */
...@@ -91,7 +91,7 @@ public class ExCardListFragment extends Fragment implements View.OnClickListener ...@@ -91,7 +91,7 @@ public class ExCardListFragment extends Fragment implements View.OnClickListener
this.context = getContext(); this.context = getContext();
initView(layoutView); initView(layoutView);
if (!EventBus.getDefault().isRegistered(this)) {//加上判断 if (!EventBus.getDefault().isRegistered(this)) {//加上判断
EventBus.getDefault().register(this); EventBus.getDefault().register(this);
} }
return layoutView; return layoutView;
...@@ -100,8 +100,8 @@ public class ExCardListFragment extends Fragment implements View.OnClickListener ...@@ -100,8 +100,8 @@ public class ExCardListFragment extends Fragment implements View.OnClickListener
@Override @Override
public void onStop() { public void onStop() {
super.onStop(); super.onStop();
Log.i(TAG, "excard fragment on stop"); LogUtil.i(TAG, "excard fragment on stop");
if (EventBus.getDefault().isRegistered(this))//加上判断 if (EventBus.getDefault().isRegistered(this))//加上判断
EventBus.getDefault().unregister(this); EventBus.getDefault().unregister(this);
} }
...@@ -123,6 +123,7 @@ public class ExCardListFragment extends Fragment implements View.OnClickListener ...@@ -123,6 +123,7 @@ public class ExCardListFragment extends Fragment implements View.OnClickListener
public void onClick(View v) { public void onClick(View v) {
switch (v.getId()) { switch (v.getId()) {
case R.id.btn_download_prerelease: case R.id.btn_download_prerelease:
LogUtil.i(TAG, "start download");
if (downloadState != DownloadState.DOWNLOAD_ING) { if (downloadState != DownloadState.DOWNLOAD_ING) {
downloadState = DownloadState.DOWNLOAD_ING; downloadState = DownloadState.DOWNLOAD_ING;
downloadfromWeb(URL_YGO233_FILE); downloadfromWeb(URL_YGO233_FILE);
...@@ -133,11 +134,11 @@ public class ExCardListFragment extends Fragment implements View.OnClickListener ...@@ -133,11 +134,11 @@ public class ExCardListFragment extends Fragment implements View.OnClickListener
} }
/** /**
* 根据先行卡包状态改变按钮样式 * 根据先行卡包状态改变按钮样式
*/ */
public void changeDownloadText() { public void changeDownloadText() {
if (ServerUtil.exCardState == ServerUtil.ExCardState.UPDATED) { if (ServerUtil.exCardState == ServerUtil.ExCardState.UPDATED) {
//btn_download展示默认视图 //btn_download展示默认视图
textDownload.setText(R.string.tip_redownload); textDownload.setText(R.string.tip_redownload);
} else if (ServerUtil.exCardState == ServerUtil.ExCardState.NEED_UPDATE) { } else if (ServerUtil.exCardState == ServerUtil.ExCardState.NEED_UPDATE) {
textDownload.setText(R.string.Download); textDownload.setText(R.string.Download);
...@@ -164,38 +165,38 @@ public class ExCardListFragment extends Fragment implements View.OnClickListener ...@@ -164,38 +165,38 @@ public class ExCardListFragment extends Fragment implements View.OnClickListener
Toast.makeText(getActivity(), R.string.Ask_to_Change_Other_Way, Toast.LENGTH_SHORT).show(); Toast.makeText(getActivity(), R.string.Ask_to_Change_Other_Way, Toast.LENGTH_SHORT).show();
downloadfromWeb(URL_YGO233_FILE_ALT); downloadfromWeb(URL_YGO233_FILE_ALT);
} }
YGOUtil.show("error" + msg.obj); YGOUtil.showTextToast("error" + msg.obj);
break; break;
case UnzipUtils.ZIP_READY: case UnzipUtils.ZIP_READY:
textDownload.setText(R.string.title_use_ex); textDownload.setText(R.string.title_use_ex);
break; break;
case UnzipUtils.ZIP_UNZIP_OK: case UnzipUtils.ZIP_UNZIP_OK:
/* 将先行服务器信息添加到服务器列表中 */ /* 将先行服务器信息添加到服务器列表中 */
String servername = ""; String servername = "";
if (AppsSettings.get().getDataLanguage() == 0) if (AppsSettings.get().getDataLanguage() == 0)
servername = "23333先行服务器"; servername = "23333先行服务器";
if (AppsSettings.get().getDataLanguage() == 1) if (AppsSettings.get().getDataLanguage() == 1)
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(getActivity(), servername, "s1.ygo233.com", 23333, "Knight of Hanoi"); AddServer(getActivity(), servername, "s1.ygo233.com", 23333, "Knight of Hanoi");
//changeDownloadButton();在下载完成后,通过EventBus通知下载完成(加入用户点击下载后临时切出本fragment,又在下载完成后切回,通过eventbus能保证按钮样式正确更新 //changeDownloadButton();在下载完成后,通过EventBus通知下载完成(加入用户点击下载后临时切出本fragment,又在下载完成后切回,通过eventbus能保证按钮样式正确更新
/* 注意,要先更新版本号 */ /* 注意,要先更新版本号 */
SharedPreferenceUtil.setExpansionDataVer(ServerUtil.serverExCardVersion); SharedPreferenceUtil.setExpansionDataVer(ServerUtil.serverExCardVersion);
ServerUtil.exCardState = ServerUtil.ExCardState.UPDATED; ServerUtil.exCardState = ServerUtil.ExCardState.UPDATED;
EventBus.getDefault().postSticky(new ExCardEvent(ExCardEvent.EventType.exCardPackageChange));//安装后,通知UI做更新 EventBus.getDefault().postSticky(new ExCardEvent(ExCardEvent.EventType.exCardPackageChange));//安装后,通知UI做更新
DataManager.get().load(true); DataManager.get().load(true);
Toast.makeText(context, R.string.ypk_installed, Toast.LENGTH_LONG).show(); Toast.makeText(context, R.string.ypk_installed, Toast.LENGTH_LONG).show();
Log.i("webCrawler", "Ex-card package is installed"); LogUtil.i("webCrawler", "Ex-card package is installed");
/* 如果未开启先行卡设置,则跳转到设置页面 */ /* 如果未开启先行卡设置,则跳转到设置页面 */
if (!AppsSettings.get().isReadExpansions()) {//解压完毕,但此时 if (!AppsSettings.get().isReadExpansions()) {//解压完毕,但此时
Log.i("webCrawler", "Ex-card setting is not opened"); LogUtil.i("webCrawler", "Ex-card setting is not opened");
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);
...@@ -212,7 +213,7 @@ public class ExCardListFragment extends Fragment implements View.OnClickListener ...@@ -212,7 +213,7 @@ public class ExCardListFragment extends Fragment implements View.OnClickListener
// String oldVer = SharedPreferenceUtil.getExpansionDataVer(); // String oldVer = SharedPreferenceUtil.getExpansionDataVer();
// if (!TextUtils.isEmpty(WebActivity.exCardVer)) { // if (!TextUtils.isEmpty(WebActivity.exCardVer)) {
// if (!WebActivity.exCardVer.equals(oldVer)) { // if (!WebActivity.exCardVer.equals(oldVer)) {
// //btn_download展示默认视图 // //btn_download展示默认视图
// } else { // } else {
// btnDownload.setText(R.string.tip_redownload); // btnDownload.setText(R.string.tip_redownload);
// } // }
...@@ -233,7 +234,7 @@ public class ExCardListFragment extends Fragment implements View.OnClickListener ...@@ -233,7 +234,7 @@ public class ExCardListFragment extends Fragment implements View.OnClickListener
} }
} }
private void downloadfromWeb(String fileUrl) { private void downloadfromWeb(String fileUrl) {
textDownload.setText("0%");//点击下载后,距离onDownloading触发要等几秒,这一延迟会造成软件响应慢的错觉 textDownload.setText("0%");//点击下载后,距离onDownloading触发要等几秒,这一延迟会造成软件响应慢的错觉,因此在下载函数开始就设置文本
File file = new File(AppsSettings.get().getResourcePath() + "-preRlease.zip"); File file = new File(AppsSettings.get().getResourcePath() + "-preRlease.zip");
if (file.exists()) { if (file.exists()) {
FileUtils.deleteFile(file); FileUtils.deleteFile(file);
...@@ -255,7 +256,7 @@ public class ExCardListFragment extends Fragment implements View.OnClickListener ...@@ -255,7 +256,7 @@ public class ExCardListFragment extends Fragment implements View.OnClickListener
} catch (Exception e) { } catch (Exception e) {
message.what = UnzipUtils.ZIP_UNZIP_EXCEPTION; message.what = UnzipUtils.ZIP_UNZIP_EXCEPTION;
} finally { } finally {
message.what = UnzipUtils.ZIP_UNZIP_OK;//TODO 不对吧,finally是一定执行,这样即使有exception也会发unzip_ok啊 message.what = UnzipUtils.ZIP_UNZIP_OK;//TODO 不对吧,finally是一定执行,这样即使有exception也会发unzip_ok啊
} }
handler.sendMessage(message); handler.sendMessage(message);
} }
...@@ -271,7 +272,7 @@ public class ExCardListFragment extends Fragment implements View.OnClickListener ...@@ -271,7 +272,7 @@ public class ExCardListFragment extends Fragment implements View.OnClickListener
@Override @Override
public void onDownloadFailed(Exception e) { public void onDownloadFailed(Exception e) {
//下载失败后删除下载的文件 //下载失败后删除下载的文件
FileUtils.deleteFile(file); FileUtils.deleteFile(file);
Message message = new Message(); Message message = new Message();
message.what = TYPE_DOWNLOAD_EXCEPTION; message.what = TYPE_DOWNLOAD_EXCEPTION;
......
...@@ -73,6 +73,7 @@ import cn.garymb.ygomobile.ui.plus.VUiKit; ...@@ -73,6 +73,7 @@ import cn.garymb.ygomobile.ui.plus.VUiKit;
import cn.garymb.ygomobile.ui.widget.Shimmer; import cn.garymb.ygomobile.ui.widget.Shimmer;
import cn.garymb.ygomobile.ui.widget.ShimmerTextView; import cn.garymb.ygomobile.ui.widget.ShimmerTextView;
import cn.garymb.ygomobile.utils.FileLogUtil; import cn.garymb.ygomobile.utils.FileLogUtil;
import cn.garymb.ygomobile.utils.LogUtil;
import cn.garymb.ygomobile.utils.ServerUtil; import cn.garymb.ygomobile.utils.ServerUtil;
import cn.garymb.ygomobile.utils.YGOUtil; import cn.garymb.ygomobile.utils.YGOUtil;
import ocgcore.CardManager; import ocgcore.CardManager;
...@@ -139,7 +140,7 @@ public class HomeFragment extends BaseFragemnt implements OnDuelAssistantListene ...@@ -139,7 +140,7 @@ public class HomeFragment extends BaseFragemnt implements OnDuelAssistantListene
if (!EventBus.getDefault().isRegistered(this)) {//加上判断 if (!EventBus.getDefault().isRegistered(this)) {//加上判断
EventBus.getDefault().register(this); EventBus.getDefault().register(this);
} }
ServerUtil.initExCardState();//HomeActivity中会调用一次本函数,此处再次调用是因为有时候HomeFragment的onCreateView()函数执行较慢,导致initExCardState()中eventbus事件发布完毕后仍未注册,因此在此处再调用一次检查,再次发布 ServerUtil.initExCardState();//HomeActivity中会调用一次本函数,此处再次调用的原因:有时HomeFragment的onCreateView()函数执行较慢,导致initExCardState()中eventbus事件发布完毕后仍未注册,因此在此处再调用一次检查,再次发布
changeColor(); changeColor();
//showNewbieGuide("homePage"); //showNewbieGuide("homePage");
return layoutView; return layoutView;
...@@ -280,7 +281,7 @@ public class HomeFragment extends BaseFragemnt implements OnDuelAssistantListene ...@@ -280,7 +281,7 @@ public class HomeFragment extends BaseFragemnt implements OnDuelAssistantListene
* ServerUtil获取到版本状态后会通过eventmessage通知调用本函数,不需要在主函数显式调用 * ServerUtil获取到版本状态后会通过eventmessage通知调用本函数,不需要在主函数显式调用
*/ */
public void changeExCardNewMark() { public void changeExCardNewMark() {
Log.i(TAG, "check excard new mark, version:" + ServerUtil.exCardState); LogUtil.i(TAG, "check excard new mark, version:" + ServerUtil.exCardState);
if (ServerUtil.exCardState == ServerUtil.ExCardState.UPDATED) { if (ServerUtil.exCardState == ServerUtil.ExCardState.UPDATED) {
ll_new_notice.setVisibility(View.GONE); ll_new_notice.setVisibility(View.GONE);
} else if (ServerUtil.exCardState == ServerUtil.ExCardState.NEED_UPDATE) { } else if (ServerUtil.exCardState == ServerUtil.ExCardState.NEED_UPDATE) {
...@@ -528,7 +529,7 @@ public class HomeFragment extends BaseFragemnt implements OnDuelAssistantListene ...@@ -528,7 +529,7 @@ public class HomeFragment extends BaseFragemnt implements OnDuelAssistantListene
public void saveDeck(Uri uri, List<Integer> mainList, List<Integer> exList, List<Integer> sideList, boolean isCompleteDeck, String exception) { public void saveDeck(Uri uri, List<Integer> mainList, List<Integer> exList, List<Integer> sideList, boolean isCompleteDeck, String exception) {
if (!TextUtils.isEmpty(exception)) { if (!TextUtils.isEmpty(exception)) {
YGOUtil.show("卡组解析失败,原因为:" + exception); YGOUtil.showTextToast("卡组解析失败,原因为:" + exception);
return; return;
} }
DialogPlus dialog = new DialogPlus(getContext()); DialogPlus dialog = new DialogPlus(getContext());
...@@ -553,7 +554,9 @@ public class HomeFragment extends BaseFragemnt implements OnDuelAssistantListene ...@@ -553,7 +554,9 @@ public class HomeFragment extends BaseFragemnt implements OnDuelAssistantListene
deckInfo.setCompleteDeck(isCompleteDeck); deckInfo.setCompleteDeck(isCompleteDeck);
File file = deckInfo.saveTemp(AppsSettings.get().getDeckDir()); File file = deckInfo.saveTemp(AppsSettings.get().getDeckDir());
if (!deckInfo.isCompleteDeck()) { if (!deckInfo.isCompleteDeck()) {
YGOUtil.show(activity.getString(R.string.tip_deckInfo_isNot_completeDeck));
YGOUtil.showTextToast(activity.getString(R.string.tip_deckInfo_isNot_completeDeck));
} }
if (!file.getAbsolutePath().isEmpty()) { if (!file.getAbsolutePath().isEmpty()) {
mBundle.putString("setDeck", file.getAbsolutePath()); mBundle.putString("setDeck", file.getAbsolutePath());
...@@ -723,13 +726,22 @@ public class HomeFragment extends BaseFragemnt implements OnDuelAssistantListene ...@@ -723,13 +726,22 @@ public class HomeFragment extends BaseFragemnt implements OnDuelAssistantListene
getFragmentManager().beginTransaction().remove(activity.fragment_deck_cards).commit(); getFragmentManager().beginTransaction().remove(activity.fragment_deck_cards).commit();
break; break;
case R.id.action_download_ex: case R.id.action_download_ex:
/*不检查先行卡设置,无论是否开启先行卡都要求能够打开先行卡页面,因此注释掉下面代码*/
// if (!AppsSettings.get().isReadExpansions()) {//如果未开启扩展卡设置,直接跳过 // if (!AppsSettings.get().isReadExpansions()) {//如果未开启扩展卡设置,直接跳过
// Toast.makeText(getActivity(), R.string.ypk_go_setting, Toast.LENGTH_LONG).show(); // Toast.makeText(getActivity(), R.string.ypk_go_setting, Toast.LENGTH_LONG).show();
// break; // break;
// } // }
/* using Web crawler to extract the information of pre card */
Intent exCardIntent = new Intent(getActivity(), ExCardActivity.class); if (ServerUtil.exCardState == ServerUtil.ExCardState.ERROR) {
startActivity(exCardIntent); WebActivity.open(getContext(), getString(R.string.action_download_expansions), Constants.URL_YGO233_ADVANCE);
LogUtil.i(TAG, "cannot connect to ex card server, open webactivity");
} else {
/* using Web crawler to extract the information of pre card */
LogUtil.i(TAG, "connect to ex card http server, open webactivity");
Intent exCardIntent = new Intent(getActivity(), ExCardActivity.class);
startActivity(exCardIntent);
}
break; break;
case R.id.action_help: { case R.id.action_help: {
final DialogPlus dialog = new DialogPlus(getContext()); final DialogPlus dialog = new DialogPlus(getContext());
......
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