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

248 lines
10 KiB
Java
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

package com.gh.gamecenter;
import android.content.Context;
import android.content.ContextWrapper;
import android.content.Intent;
import android.os.Bundle;
import com.gh.common.exposure.ExposureEvent;
import com.gh.common.exposure.ExposureManager;
import com.gh.common.exposure.ExposureTraceUtils;
import com.gh.common.exposure.ExposureType;
import com.gh.common.util.DataUtils;
import com.gh.common.util.DisplayUtils;
import com.gh.common.util.EntranceUtils;
import com.gh.download.DownloadManager;
import com.gh.gamecenter.entity.GameEntity;
import com.gh.gamecenter.gamedetail.GameDetailFragment;
import com.halo.assistant.HaloApp;
import static com.gh.common.constant.Constants.GAME_DETAIL_COME_IN;
/**
* TODO 合并构建 intent 的重复代码
* Created by khy on 2017/3/24.
* 游戏详情适配器
*/
public class GameDetailActivity extends NormalActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
DownloadManager.getInstance(this).updateSpeedLimitationReleaseDelay(10);
DisplayUtils.transparentStatusBar(this);
}
@Override
protected Intent provideNormalIntent() {
return getTargetIntent(this, GameDetailActivity.class, GameDetailFragment.class);
}
@Override
protected int getLayoutId() {
return R.layout.activity_game_detail;
}
/**
* 启动游戏详情页面
*/
public static void startGameDetailActivity(Context context, GameEntity gameEntity, String entrance) {
DataUtils.onMtaEvent(context, "详情页面", "游戏详情", gameEntity != null ? gameEntity.getName() : "");
Bundle bundle = new Bundle();
bundle.putString(EntranceUtils.KEY_ENTRANCE, entrance);
bundle.putParcelable(GameEntity.TAG, gameEntity);
context.startActivity(getTargetIntent(context, GameDetailActivity.class, GameDetailFragment.class, bundle));
}
/**
* 启动游戏详情页面
*/
public static void startGameDetailActivity(Context context, String gameId, String entrance) {
Bundle bundle = new Bundle();
bundle.putString(EntranceUtils.KEY_GAMEID, gameId);
bundle.putString(EntranceUtils.KEY_ENTRANCE, entrance);
context.startActivity(getTargetIntent(context, GameDetailActivity.class, GameDetailFragment.class, bundle));
}
/**
* 启动游戏详情页面 with 曝光事件
*/
public static void startGameDetailActivity(Context context, GameEntity gameEntity, String entrance, ExposureEvent traceEvent) {
startGameDetailActivity(context, gameEntity, entrance, -1, traceEvent);
}
public static void startGameDetailActivity(Context context, GameEntity gameEntity, String entrance, int defaultTab, ExposureEvent traceEvent) {
DataUtils.onMtaEvent(context, "详情页面", "游戏详情", gameEntity != null ? gameEntity.getName() : "");
Bundle bundle = new Bundle();
// TODO TraceEvent 为空时不该调用此方法才对
if (BuildConfig.DEBUG) {
if (traceEvent == null) {
throw new IllegalArgumentException("没有曝光的 TraceEvent 不要调用这个方法");
}
}
if (traceEvent != null) {
ExposureEvent clickEvent = ExposureEvent.Companion.createEvent(gameEntity, traceEvent.getSource(), ExposureTraceUtils.INSTANCE
.appendTrace(traceEvent), ExposureType.CLICK);
ExposureManager.INSTANCE.log(clickEvent);
bundle.putParcelable(EntranceUtils.KEY_TRACE_EVENT, clickEvent);
}
if (gameEntity != null
&& traceEvent != null
&& gameEntity.getId() != null
&& !gameEntity.getId().equals(traceEvent.getPayload().getGameId())) {
// 当游戏 ID 跟曝光 traceEvent 的游戏ID 不一样的时候更新 traceEvent 的游戏ID
ExposureEvent forNewPayload = ExposureEvent.Companion.createEvent(gameEntity,
traceEvent.getSource(),
ExposureTraceUtils.INSTANCE.appendTrace(traceEvent),
ExposureType.EXPOSURE);
traceEvent.setPayload(forNewPayload.getPayload());
}
if (defaultTab != -1) {
bundle.putInt(EntranceUtils.KEY_TARGET, defaultTab);
}
bundle.putString(EntranceUtils.KEY_ENTRANCE, entrance);
bundle.putParcelable(GameEntity.TAG, gameEntity);
context.startActivity(getTargetIntent(context, GameDetailActivity.class, GameDetailFragment.class, bundle));
}
/**
* 启动游戏详情页面 with 曝光事件
*/
public static void startGameDetailActivity(Context context, String gameId, String entrance, ExposureEvent traceEvent) {
startGameDetailActivity(context, gameId, entrance, -1, traceEvent);
}
public static void startGameDetailActivity(Context context, String gameId, String entrance, int defaultTab, ExposureEvent traceEvent) {
Bundle bundle = new Bundle();
// TODO TraceEvent 为空时不该调用此方法才对
if (BuildConfig.DEBUG) {
if (traceEvent == null) {
throw new IllegalArgumentException("没有曝光的 TraceEvent 不要调用这个方法");
}
}
if (traceEvent != null) {
ExposureEvent clickEvent = ExposureEvent.Companion.createEvent(new GameEntity(gameId), traceEvent.getSource(), ExposureTraceUtils.INSTANCE.appendTrace(traceEvent), ExposureType.CLICK);
ExposureManager.INSTANCE.log(clickEvent);
bundle.putParcelable(EntranceUtils.KEY_TRACE_EVENT, clickEvent);
}
if (traceEvent != null
&& !gameId.equals(traceEvent.getPayload().getGameId())) {
// 当游戏 ID 跟曝光 traceEvent 的游戏ID 不一样的时候更新 traceEvent 的游戏ID
ExposureEvent forNewPayload = ExposureEvent.Companion.createEvent(new GameEntity(gameId),
traceEvent.getSource(),
ExposureTraceUtils.INSTANCE.appendTrace(traceEvent),
ExposureType.EXPOSURE);
traceEvent.setPayload(forNewPayload.getPayload());
}
if (defaultTab != -1) {
bundle.putInt(EntranceUtils.KEY_TARGET, defaultTab);
}
bundle.putString(EntranceUtils.KEY_GAMEID, gameId);
bundle.putString(EntranceUtils.KEY_ENTRANCE, entrance);
context.startActivity(getTargetIntent(context, GameDetailActivity.class, GameDetailFragment.class, bundle));
}
/**
* 启动游戏详情页面,自动定位到评论页面
*/
public static void startGameDetailCommentActivity(Context context, String gameId, String entrance) {
Bundle bundle = new Bundle();
bundle.putString(EntranceUtils.KEY_GAMEID, gameId);
bundle.putString(EntranceUtils.KEY_ENTRANCE, entrance);
bundle.putBoolean(EntranceUtils.KEY_SKIP_GAME_COMMENT, true);
context.startActivity(getTargetIntent(context, GameDetailActivity.class, GameDetailFragment.class, bundle));
}
/**
* 启动游戏详情页面,自动定位到评论页面
*/
public static void startGameDetailCommentActivity(Context context, GameEntity game, String entrance) {
Bundle bundle = new Bundle();
bundle.putParcelable(GameEntity.TAG, game);
bundle.putString(EntranceUtils.KEY_ENTRANCE, entrance);
bundle.putBoolean(EntranceUtils.KEY_SKIP_GAME_COMMENT, true);
context.startActivity(getTargetIntent(context, GameDetailActivity.class, GameDetailFragment.class, bundle));
}
/**
* 启动游戏详情页面并定位到第一个或第二个 tab
*/
public static void startGameDetailByShortcut(Context context, GameEntity game, int tab, String entrance) {
Bundle bundle = new Bundle();
bundle.putParcelable(GameEntity.TAG, game);
bundle.putString(EntranceUtils.KEY_ENTRANCE, entrance);
bundle.putInt(EntranceUtils.KEY_TARGET, tab);
context.startActivity(getTargetIntent(context, GameDetailActivity.class, GameDetailFragment.class, bundle));
}
/**
* 启动游戏详情页面并定位到 介绍tab并打开视频流
*/
public static void startGameDetailToVideoStreaming(Context context, String gameId, String entrance) {
Bundle bundle = new Bundle();
bundle.putString(EntranceUtils.KEY_GAMEID, gameId);
bundle.putString(EntranceUtils.KEY_ENTRANCE, entrance);
bundle.putBoolean(EntranceUtils.KEY_OPEN_VIDEO_STREAMING, true);
bundle.putInt(EntranceUtils.KEY_TARGET, GameDetailFragment.INDEX_DESC);
context.startActivity(getTargetIntent(context, GameDetailActivity.class, GameDetailFragment.class, bundle));
}
/**
* 如果存在多个游戏平台则打开
*/
public static void startGameDetailActivityByVote(Context context, String gameId, String entrance) {
Bundle bundle = new Bundle();
bundle.putString(EntranceUtils.KEY_GAMEID, gameId);
bundle.putString(EntranceUtils.KEY_ENTRANCE, entrance);
bundle.putBoolean(EntranceUtils.KEY_OPEN_PLATFORM_WINDOW, true);
context.startActivity(getTargetIntent(context, GameDetailActivity.class, GameDetailFragment.class, bundle));
}
@Override
public boolean showToolbarAtLeft() {
return true;
}
@Override
protected boolean showDownloadMenu() {
return true;
}
@Override
protected void onDestroy() {
super.onDestroy();
HaloApp.remove(GAME_DETAIL_COME_IN);
}
@Override
public String getActivityNameInChinese() {
return "游戏详情";
}
@Override
protected void attachBaseContext(Context newBase) {
super.attachBaseContext(new ContextWrapper(newBase) {
@Override
public Object getSystemService(String name) {
// 解决 VideoView 中 AudioManager 造成的内存泄漏
if (Context.AUDIO_SERVICE.equals(name)) {
return getApplicationContext().getSystemService(name);
}
return super.getSystemService(name);
}
});
}
}