248 lines
8.6 KiB
Java
248 lines
8.6 KiB
Java
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 com.jakewharton.rxbinding.view.RxView;
|
||
|
||
import java.util.HashMap;
|
||
import java.util.Map;
|
||
import java.util.concurrent.TimeUnit;
|
||
|
||
import retrofit2.adapter.rxjava.HttpException;
|
||
import rx.android.schedulers.AndroidSchedulers;
|
||
import rx.functions.Action1;
|
||
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);
|
||
}
|
||
|
||
// 防抖处理
|
||
RxView.clicks(iv_share)
|
||
.throttleFirst(1, TimeUnit.SECONDS)
|
||
.subscribe(new Action1<Void>() {
|
||
@Override
|
||
public void call(Void aVoid) {
|
||
Map<String, Object> kv = new HashMap<>();
|
||
kv.put("点击", "分享");
|
||
DataUtils.onEvent(GameDetailActivity.this, "插件数据", gameEntity.getName(), kv);
|
||
|
||
DataCollectionUtils.uploadClick(GameDetailActivity.this, "分享", "游戏详情", gameEntity.getName());
|
||
|
||
String url = "http://www.ghzhushou.com/game/" + adapter.getGameDetailEntity().getShareCode();
|
||
showShare(url, gameEntity.getName(), gameEntity.getIcon(), null, gameEntity.getTag());
|
||
}
|
||
});
|
||
}
|
||
|
||
@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 == 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(HttpException 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);
|
||
}
|
||
}
|