Files
assistant-android/app/src/main/java/com/gh/gamecenter/GameDetailActivity.java
huangzhuanghua 3cbc850d12 项目整理
2016-12-12 16:34:19 +08:00

236 lines
8.1 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.os.Bundle;
import android.support.v7.widget.LinearLayoutManager;
import android.text.TextUtils;
import android.view.KeyEvent;
import android.view.View;
import android.widget.RelativeLayout;
import com.gh.base.AppController;
import com.gh.base.BaseDetailActivity;
import com.gh.common.util.DataCollectionUtils;
import com.gh.common.util.DataUtils;
import com.gh.common.util.DialogUtils;
import com.gh.gamecenter.changeskin.ChangeSkinUtils;
import com.gh.gamecenter.entity.GameEntity;
import com.gh.gamecenter.eventbus.EBConcernChanged;
import com.gh.gamecenter.gamedetail.GameDetailAdapter;
import com.gh.gamecenter.retrofit.Response;
import com.gh.gamecenter.retrofit.RetrofitManager;
import java.util.HashMap;
import java.util.Map;
import rx.android.schedulers.AndroidSchedulers;
import rx.schedulers.Schedulers;
/**
* Created by khy on 2016/8/12.
*
*/
public class GameDetailActivity extends BaseDetailActivity implements View.OnClickListener{
private GameDetailAdapter adapter;
private String gameId;
private long start;
private boolean isSentReport;
private RelativeLayout actionbar_rl_back;
@Override
protected void onSaveInstanceState(Bundle outState) {
super.onSaveInstanceState(outState);
AppController.put("GameEntity", gameEntity);
}
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
start = System.currentTimeMillis();
name = "游戏详情";
isSentReport = false;
gameId = getIntent().getStringExtra("gameId");
if (getIntent().getBundleExtra("data") != null) {
gameId = getIntent().getBundleExtra("data").getString("gameId");
}
if (gameId == null) {
gameEntity = (GameEntity) AppController.get("GameEntity", true);
if (gameEntity != null) {
title = gameEntity.getName();
actionbar_tv_title.setText(gameEntity.getName());
}
}
adapter = new GameDetailAdapter(this, entrance);
detail_rv_show.setLayoutManager(new LinearLayoutManager(this));
detail_rv_show.setAdapter(adapter);
detail_ll_bottom.setOnClickListener(this);
detail_tv_download.setOnClickListener(this);
detail_tv_per.setOnClickListener(this);
reuse_no_connection.setOnClickListener(this);
actionbar_rl_back.setOnClickListener(this);
if (gameEntity != null) {
adapter.setGameEntity(gameEntity);
adapter.getGameDetail();
} else if (gameId != null) {
getGameDigest();
} else {
reuse_ll_loading.setVisibility(View.GONE);
reuse_no_connection.setVisibility(View.VISIBLE);
}
}
@Override
public void loadDone() {
if (reuse_ll_loading.getVisibility() == View.VISIBLE) {
reuse_ll_loading.setVisibility(View.GONE);
}
if (!TextUtils.isEmpty(adapter.getGameDetailEntity().getShareCode())) {
iv_share.setVisibility(View.VISIBLE);
}
downloadAddWord = adapter.getGameDetailEntity().getDownloadAddWord();
downloadOffText = adapter.getGameDetailEntity().getDownloadOffText();
initDownload(true);
}
@Override
public void loadError() {
reuse_ll_loading.setVisibility(View.GONE);
reuse_no_connection.setVisibility(View.VISIBLE);
}
@Override
public void onClick(View v) {
super.onClick(v);
if (v == reuse_no_connection) {
reuse_no_connection.setVisibility(View.GONE);
reuse_ll_loading.setVisibility(View.VISIBLE);
handler.postDelayed(new Runnable() {
@Override
public void run() {
if (gameEntity != null) {
adapter.getGameDetail();
} else if (gameId != null) {
getGameDigest();
} else {
reuse_ll_loading.setVisibility(View.GONE);
reuse_no_connection.setVisibility(View.VISIBLE);
}
}
}, 1000);
} else if (v == iv_share) {
Map<String, Object> kv = new HashMap<>();
kv.put("点击", "分享");
DataUtils.onEvent(this, "插件数据", gameEntity.getName(), kv);
DataCollectionUtils.uploadClick(this, "分享", "游戏详情", gameEntity.getName());
String url = "http://www.ghzhushou.com/game/" + adapter.getGameDetailEntity().getShareCode();
showShare(url, gameEntity.getName(), gameEntity.getIcon(), null, gameEntity.getTag(), entrance, "游戏");
} else if (v == actionbar_rl_back) {
if (ChangeSkinUtils.isChecking) {
DialogUtils.showWarningDialog(GameDetailActivity.this, "退出提示",
"素材更新还在检测中,如果强行退出会中断所有进度,确定退出?",
"取消", "强行退出", new DialogUtils.ConfiremListener() {
@Override
public void onConfirem() {
finish();
}
}, null);
} else {
finish();
}
}
}
// 获取游戏摘要
private void getGameDigest() {
RetrofitManager.getApi().getGameDigest(gameId)
.subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread())
.subscribe(new Response<GameEntity>() {
@Override
public void onResponse(GameEntity response) {
gameEntity = response;
title = gameEntity.getName();
actionbar_tv_title.setText(gameEntity.getName());
adapter.setGameEntity(gameEntity);
adapter.getGameDetail();
}
@Override
public void onFailure(Throwable e) {
reuse_no_connection.setVisibility(View.VISIBLE);
}
});
}
// 关注事件
public void onEventMainThread(EBConcernChanged changed) {
if (!TextUtils.isEmpty(gameId) && changed.isSingle() && changed.getGameId().equals(gameId)) {
adapter.notifyItemChanged(0);
}
}
@Override
protected void onPause() {
super.onPause();
if (!isSentReport) {
long end = System.currentTimeMillis();
int seconds = (int) ((end - start) / 1000);
String cost;
if (seconds < 5) {
cost = "小于5秒";
} else if (seconds < 30) {
cost = "5秒30秒";
} else if (seconds < 60) {
cost = "30秒60秒";
} else {
cost = "大于60秒";
}
if (gameEntity != null && !TextUtils.isEmpty(gameEntity.getName())) {
Map<String, Object> kv = new HashMap<>();
kv.put("停留时长", cost);
DataUtils.onEvent(this, "插件数据", gameEntity.getName(), kv);
if (seconds > 0) {
DataCollectionUtils.uploadGame(this, gameEntity, seconds, entrance);
}
}
isSentReport = true;
}
}
@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
if (keyCode == KeyEvent.KEYCODE_BACK && event.getRepeatCount() == 0 && ChangeSkinUtils.isChecking) {
DialogUtils.showWarningDialog(GameDetailActivity.this, "退出提示",
"素材更新还在检测中,如果强行退出会中断所有进度,确定退出?",
"取消", "强行退出", new DialogUtils.ConfiremListener() {
@Override
public void onConfirem() {
finish();
}
}, null);
return true;
}
return super.onKeyDown(keyCode, event);
}
}