Commit 817d2f2e authored by fallenstardust's avatar fallenstardust

优化子线程与主线程通信

parent fc270e13
...@@ -50,7 +50,7 @@ import ocgcore.DataManager; ...@@ -50,7 +50,7 @@ import ocgcore.DataManager;
import ocgcore.data.Card; import ocgcore.data.Card;
public class WebActivity extends BaseActivity { public class WebActivity extends BaseActivity {
public static String dataVer = ""; public static String dataVer;
private WebViewPlus mWebViewPlus; private WebViewPlus mWebViewPlus;
private String mUrl; private String mUrl;
private String mTitle; private String mTitle;
......
...@@ -94,6 +94,7 @@ public class HomeFragment extends BaseFragemnt implements OnDuelAssistantListene ...@@ -94,6 +94,7 @@ public class HomeFragment extends BaseFragemnt implements OnDuelAssistantListene
private static final int TYPE_BANNER_QUERY_OK = 0; private static final int TYPE_BANNER_QUERY_OK = 0;
private static final int TYPE_BANNER_QUERY_EXCEPTION = 1; private static final int TYPE_BANNER_QUERY_EXCEPTION = 1;
private static final int TYPE_RES_LOADING_OK = 2; private static final int TYPE_RES_LOADING_OK = 2;
private static final int TYPE_GET_DATA_VER_OK = 3;
private static final String ARG_MC_NEWS_LIST = "mcNewsList"; private static final String ARG_MC_NEWS_LIST = "mcNewsList";
private boolean isMcNewsLoadException = false; private boolean isMcNewsLoadException = false;
...@@ -209,7 +210,6 @@ public class HomeFragment extends BaseFragemnt implements OnDuelAssistantListene ...@@ -209,7 +210,6 @@ public class HomeFragment extends BaseFragemnt implements OnDuelAssistantListene
//轮播图 //轮播图
public void initBanner(View view, Bundle saveBundle) { public void initBanner(View view, Bundle saveBundle) {
Log.i("3.10.0看看saveBundle", saveBundle + "");
xb_banner = view.findViewById(R.id.xb_banner); xb_banner = view.findViewById(R.id.xb_banner);
cv_banner = view.findViewById(R.id.cv_banner); cv_banner = view.findViewById(R.id.cv_banner);
cv_banner.post(() -> { cv_banner.post(() -> {
...@@ -269,6 +269,15 @@ public class HomeFragment extends BaseFragemnt implements OnDuelAssistantListene ...@@ -269,6 +269,15 @@ public class HomeFragment extends BaseFragemnt implements OnDuelAssistantListene
tv_banner_loading.setText(R.string.loading_failed); tv_banner_loading.setText(R.string.loading_failed);
isMcNewsLoadException = true; isMcNewsLoadException = true;
break; break;
case TYPE_GET_DATA_VER_OK:
WebActivity.dataVer = msg.obj.toString();
String oldVer = SharedPreferenceUtil.getExpansionDataVer();
if (!TextUtils.isEmpty(WebActivity.dataVer) && !WebActivity.dataVer.equals(oldVer)) {
ll_new_notice.setVisibility(View.VISIBLE);
} else {
showExNew();
ll_new_notice.setVisibility(View.GONE);
}
} }
} }
...@@ -276,31 +285,23 @@ public class HomeFragment extends BaseFragemnt implements OnDuelAssistantListene ...@@ -276,31 +285,23 @@ public class HomeFragment extends BaseFragemnt implements OnDuelAssistantListene
private void showExNew() { private void showExNew() {
if (AppsSettings.get().isReadExpansions()) { if (AppsSettings.get().isReadExpansions()) {
String oldVer = SharedPreferenceUtil.getExpansionDataVer(); OkhttpUtil.get(URL_YGO233_DATAVER, new Callback() {
findExPansionsDataVer(); @Override
Log.i(BuildConfig.VERSION_NAME, WebActivity.dataVer); public void onFailure(Call call, IOException e) {
if (!TextUtils.isEmpty(WebActivity.dataVer) && !WebActivity.dataVer.equals(oldVer)) { showExNew();
findExPansionsDataVer(); }
ll_new_notice.setVisibility(View.VISIBLE);
} else {
ll_new_notice.setVisibility(View.GONE);
}
}
}
private static void findExPansionsDataVer() {
OkhttpUtil.get(URL_YGO233_DATAVER, new Callback() {
@Override
public void onFailure(Call call, IOException e) {
findExPansionsDataVer();
}
@Override
public void onResponse(Call call, Response response) throws IOException {
WebActivity.dataVer = response.body().string();
}
});
@Override
public void onResponse(Call call, Response response) throws IOException {
String json = response.body().string();
Message message = new Message();
message.what = TYPE_GET_DATA_VER_OK;
message.obj = json;
handler.sendMessage(message);
Log.i(BuildConfig.VERSION_NAME, WebActivity.dataVer + "dataver内");
}
});
}
} }
private void findMcNews() { private void findMcNews() {
......
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