Files
assistant-android/app/src/main/java/com/gh/gamecenter/WebActivity.java

206 lines
9.1 KiB
Java

package com.gh.gamecenter;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import com.gh.common.constant.Constants;
import com.gh.common.util.EntranceUtils;
import com.gh.gamecenter.entity.ConcernEntity;
import com.gh.gamecenter.entity.NewsEntity;
import com.gh.gamecenter.entity.ToolBoxEntity;
import com.halo.assistant.fragment.WebFragment;
import java.net.URLEncoder;
import java.util.Date;
import java.util.Locale;
import androidx.annotation.NonNull;
/**
* Created by khy on 2016/10/18.
*/
@Deprecated
public class WebActivity extends NormalActivity {
@Override
protected Intent provideNormalIntent() {
return getTargetIntent(this, WebActivity.class, WebFragment.class);
}
@NonNull
public static Intent getWebIntentByShare(Context context, String url, boolean showWebShare) {
Bundle bundle = new Bundle();
bundle.putBoolean(EntranceUtils.KEY_WEB_SHARE, showWebShare);
bundle.putString(EntranceUtils.KEY_URL, url);
return getTargetIntent(context, WebActivity.class, WebFragment.class, bundle);
}
@NonNull
public static Intent getCommunityRuleIntent(Context context) {
Bundle bundle = new Bundle();
bundle.putString(EntranceUtils.KEY_GAMENAME, context.getString(R.string.community_rule_title));
bundle.putString(EntranceUtils.KEY_URL, context.getString(R.string.community_rule_url));
return getTargetIntent(context, WebActivity.class, WebFragment.class, bundle);
}
@NonNull
public static Intent getWebIntent(Context context) {
Bundle bundle = new Bundle();
bundle.putString(EntranceUtils.KEY_GAMENAME, context.getString(R.string.disclaimer_title));
bundle.putString(EntranceUtils.KEY_URL, context.getString(R.string.disclaimer_url));
return getTargetIntent(context, WebActivity.class, WebFragment.class, bundle);
}
@NonNull
public static Intent getUploadProtocolIntent(Context context) {
Bundle bundle = new Bundle();
bundle.putString(EntranceUtils.KEY_GAMENAME, context.getString(R.string.upload_protocol_title));
bundle.putString(EntranceUtils.KEY_URL, context.getString(R.string.upload_protocol_url));
return getTargetIntent(context, WebActivity.class, WebFragment.class, bundle);
}
@NonNull
public static Intent getPrivacyPolicyIntent(Context context) {
Bundle bundle = new Bundle();
bundle.putString(EntranceUtils.KEY_GAMENAME, context.getString(R.string.privacy_policy_title));
bundle.putString(EntranceUtils.KEY_URL, context.getString(R.string.privacy_policy_url));
return getTargetIntent(context, WebActivity.class, WebFragment.class, bundle);
}
@NonNull
public static Intent getUploadPolicyIntent(Context context) {
Bundle bundle = new Bundle();
bundle.putString(EntranceUtils.KEY_GAMENAME, context.getString(R.string.upload_game_policy_title));
bundle.putString(EntranceUtils.KEY_URL, context.getString(R.string.upload_game_policy_url));
return getTargetIntent(context, WebActivity.class, WebFragment.class, bundle);
}
@NonNull
public static Intent getCommentRulesIntent(Context context) {
Bundle bundle = new Bundle();
bundle.putString(EntranceUtils.KEY_GAMENAME, context.getString(R.string.comment_rules_title));
bundle.putString(EntranceUtils.KEY_URL, context.getString(R.string.comment_rules_url));
return getTargetIntent(context, WebActivity.class, WebFragment.class, bundle);
}
@NonNull
public static Intent getSecurityCertificationIntent(Context context) {
Bundle bundle = new Bundle();
bundle.putString(EntranceUtils.KEY_GAMENAME, context.getString(R.string.comment_security_certification));
bundle.putString(EntranceUtils.KEY_URL, context.getString(R.string.comment_security_certification_url));
bundle.putBoolean(WebFragment.KEY_IS_SECURITY_CERTIFICATION, true);
return getTargetIntent(context, WebActivity.class, WebFragment.class, bundle);
}
@NonNull
public static Intent getWebByCollectionTools(Context context, ToolBoxEntity toolBoxEntity, boolean isCollectionTools) {
Bundle bundle = new Bundle();
bundle.putString(EntranceUtils.KEY_URL, toolBoxEntity.getUrl());
bundle.putBoolean(WebFragment.KEY_ISTOOLS, true);
bundle.putString(EntranceUtils.KEY_GAMENAME, toolBoxEntity.getName());
bundle.putParcelable(ToolBoxEntity.TAG, toolBoxEntity);
bundle.putBoolean(WebFragment.KEY_ISCOLLECTIONTOOLS, isCollectionTools);
return getTargetIntent(context, WebActivity.class, WebFragment.class, bundle);
}
@SuppressWarnings("ConstantConditions")
public static Intent getBindWechatIntent(Context context) {
String url;
if (("internal").equals(BuildConfig.FLAVOR)) {
url = Constants.WECHAT_BIND_ADDRESS_DEV;
} else {
url = Constants.WECHAT_BIND_ADDRESS;
}
Bundle bundle = new Bundle();
bundle.putString(EntranceUtils.KEY_URL, url);
bundle.putBoolean(WebFragment.KEY_IS_BIND_WECHAT, true);
return getTargetIntent(context, WebActivity.class, WebFragment.class, bundle);
}
@SuppressWarnings("ConstantConditions")
public static Intent getBadgeCenterIntent(Context context, String userId, String name, String icon) {
String url;
if (("internal").equals(BuildConfig.FLAVOR)) {
url = Constants.BADGE_ADDRESS_DEV;
} else {
url = Constants.BADGE_ADDRESS;
}
url = String.format(Locale.CHINA, "%s?user_id=%s&name=%s&icon=%s&timestamp=%d", url, userId, name, URLEncoder.encode(icon), Math.round((new Date().getTime() / 1000) / 1000));
Bundle bundle = new Bundle();
bundle.putString(EntranceUtils.KEY_URL, url);
bundle.putBoolean(WebFragment.KEY_LEAVE_WEB_PAGE_TO_HANDLE_TITLE, true);
return getTargetIntent(context, WebActivity.class, WebFragment.class, bundle);
}
@NonNull
public static Intent getIntentByNews(Context context, ConcernEntity concernEntity, String entrance) {
Bundle bundle = new Bundle();
bundle.putString(EntranceUtils.KEY_URL, concernEntity.getLink());
bundle.putString(EntranceUtils.KEY_GAMENAME, concernEntity.getGameName());
bundle.putString(EntranceUtils.KEY_NEWSID, concernEntity.getId());
bundle.putString(EntranceUtils.KEY_ENTRANCE, entrance);
return getTargetIntent(context, WebActivity.class, WebFragment.class, bundle);
}
@NonNull
public static Intent getIntentByNews(Context context, NewsEntity newsEntity, String entrance) {
Bundle bundle = new Bundle();
bundle.putString(EntranceUtils.KEY_URL, newsEntity.getLink());
bundle.putString(EntranceUtils.KEY_GAMENAME, newsEntity.getGameName());
bundle.putString(EntranceUtils.KEY_NEWSID, newsEntity.getId());
bundle.putString(EntranceUtils.KEY_ENTRANCE, entrance);
return getTargetIntent(context, WebActivity.class, WebFragment.class, bundle);
}
@NonNull
public static Intent getIntent(Context context, String url, boolean autoCompletionTitle) {
Bundle bundle = new Bundle();
bundle.putString(EntranceUtils.KEY_URL, url);
bundle.putBoolean(WebFragment.KEY_COMPLETION_TITLE, autoCompletionTitle);
bundle.putBoolean(WebFragment.KEY_LEAVE_WEB_PAGE_TO_HANDLE_TITLE, false);
return getTargetIntent(context, WebActivity.class, WebFragment.class, bundle);
}
@NonNull
public static Intent getIntentByUrl(Context context, String url) {
return getIntentByUrl(context, url, false);
}
@NonNull
public static Intent getIntentByUrl(Context context, String url, boolean leaveWebPageHandleTitle) {
Bundle bundle = new Bundle();
bundle.putString(EntranceUtils.KEY_URL, url);
bundle.putBoolean(WebFragment.KEY_LEAVE_WEB_PAGE_TO_HANDLE_TITLE, leaveWebPageHandleTitle);
return getTargetIntent(context, WebActivity.class, WebFragment.class, bundle);
}
public static Intent getIntentForWebGame(Context context, String url, String gameName, boolean interveneBackpress) {
Bundle bundle = new Bundle();
bundle.putString(EntranceUtils.KEY_URL, url);
bundle.putString(WebFragment.KEY_GAME_NAME, gameName);
bundle.putBoolean(WebFragment.KEY_LEAVE_WEB_PAGE_TO_HANDLE_TITLE, true);
if (interveneBackpress) {
bundle.putBoolean(WebFragment.KEY_REQUIRE_BACK_CONFIRMATION, true);
bundle.putString(WebFragment.KEY_BACK_CONFIRMATION_CONTENT, "退出后将不保存当前游戏进度,确定退出吗?");
}
return getTargetIntent(context, WebActivity.class, WebFragment.class, bundle);
}
@Override
protected View.OnClickListener provideNavigationItemClickListener() {
Bundle bundle = getIntent().getBundleExtra(NORMAL_FRAGMENT_BUNDLE);
if (bundle != null && bundle.getBoolean(WebFragment.KEY_ISTOOLS, false)) {
return view -> finish();
} else {
return super.provideNavigationItemClickListener();
}
}
}