251 lines
9.2 KiB
Java
251 lines
9.2 KiB
Java
package com.gh.gamecenter;
|
|
|
|
import android.content.Context;
|
|
import android.content.Intent;
|
|
import android.os.Bundle;
|
|
import android.os.Handler;
|
|
import android.os.Message;
|
|
import android.support.annotation.NonNull;
|
|
import android.support.v7.widget.LinearLayoutManager;
|
|
import android.text.TextUtils;
|
|
import android.view.View;
|
|
|
|
import com.gh.base.BaseDetailActivity;
|
|
import com.gh.common.util.ApkActiveUtils;
|
|
import com.gh.common.util.EntranceUtils;
|
|
import com.gh.common.util.LibaoUtils;
|
|
import com.gh.common.util.TokenUtils;
|
|
import com.gh.common.util.Utils;
|
|
import com.gh.common.view.VerticalItemDecoration;
|
|
import com.gh.gamecenter.adapter.LibaoDetailAdapter;
|
|
import com.gh.gamecenter.db.LibaoDao;
|
|
import com.gh.gamecenter.entity.GameEntity;
|
|
import com.gh.gamecenter.entity.LibaoEntity;
|
|
import com.gh.gamecenter.eventbus.EBUISwitch;
|
|
import com.gh.gamecenter.retrofit.Response;
|
|
import com.gh.gamecenter.retrofit.RetrofitManager;
|
|
|
|
import org.greenrobot.eventbus.Subscribe;
|
|
import org.greenrobot.eventbus.ThreadMode;
|
|
|
|
import java.util.Calendar;
|
|
import java.util.Date;
|
|
|
|
import retrofit2.HttpException;
|
|
import rx.android.schedulers.AndroidSchedulers;
|
|
import rx.schedulers.Schedulers;
|
|
|
|
/**
|
|
* Created by khy on 2016/12/13.
|
|
*/
|
|
public class LibaoDetailActivity extends BaseDetailActivity implements LibaoDetailAdapter.OnCodeScrollListener {
|
|
|
|
private LibaoDetailAdapter mAdapter;
|
|
|
|
private LibaoEntity mLibaoEntity;
|
|
|
|
private boolean mIsScroll;
|
|
|
|
private Handler handler = new Handler() {
|
|
@Override
|
|
public void handleMessage(Message msg) {
|
|
super.handleMessage(msg);
|
|
if (msg.what == 0) {
|
|
long time = Utils.getTime(LibaoDetailActivity.this) - 5; // -5 防止获取服务器时间延迟发生的计算错误()
|
|
Calendar calendar = Calendar.getInstance();
|
|
Date date = new Date(time * 1000);
|
|
calendar.setTime(date);
|
|
calendar.set(Calendar.HOUR_OF_DAY, 24);
|
|
calendar.set(Calendar.SECOND, 0);
|
|
calendar.set(Calendar.MINUTE, 0);
|
|
calendar.set(Calendar.MILLISECOND, 0);
|
|
|
|
long targetTime = calendar.getTimeInMillis();
|
|
long delayedTime = targetTime - time * 1000;
|
|
Utils.log("=========delayedTime::" + delayedTime);
|
|
if (BuildConfig.DEBUG) {
|
|
toast("领取时间剩余: " + (delayedTime / 1000) + " 秒");
|
|
}
|
|
handler.sendEmptyMessageDelayed(1, delayedTime);
|
|
} else if (msg.what == 1) {
|
|
mLibaoEntity.setStatus(mLibaoEntity.getBeforeStatus());
|
|
mAdapter.notifyItemChanged(0);
|
|
}
|
|
}
|
|
};
|
|
|
|
@NonNull
|
|
public static Intent getIntent(Context context, LibaoEntity libaoEntity, String entrance) {
|
|
Intent intent = new Intent(context, LibaoDetailActivity.class);
|
|
intent.putExtra(EntranceUtils.KEY_ENTRANCE, entrance);
|
|
intent.putExtra(LibaoDetailActivity.class.getSimpleName(), libaoEntity);
|
|
return intent;
|
|
}
|
|
|
|
@Override
|
|
protected void onSaveInstanceState(Bundle outState) {
|
|
super.onSaveInstanceState(outState);
|
|
outState.putParcelable(LibaoDetailActivity.class.getSimpleName(), mAdapter.getLibaoEntity());
|
|
}
|
|
|
|
@Override
|
|
protected void onCreate(Bundle savedInstanceState) {
|
|
super.onCreate(savedInstanceState);
|
|
actionbar_tv_title.setText("礼包详情");
|
|
|
|
if (savedInstanceState != null) {
|
|
mLibaoEntity = savedInstanceState.getParcelable(LibaoDetailActivity.class.getSimpleName());
|
|
} else {
|
|
mLibaoEntity = getIntent().getParcelableExtra(LibaoDetailActivity.class.getSimpleName());
|
|
}
|
|
name = "礼包详情";
|
|
|
|
iv_share.setVisibility(View.GONE);
|
|
|
|
mIsScroll = true;
|
|
|
|
mAdapter = new LibaoDetailAdapter(this, this, this, mLibaoEntity, detail_tv_download, mEntrance);
|
|
detail_rv_show.setLayoutManager(new LinearLayoutManager(this) {
|
|
@Override
|
|
public boolean canScrollVertically() {
|
|
return mIsScroll;
|
|
}
|
|
});
|
|
detail_rv_show.addItemDecoration(new VerticalItemDecoration(this, 8, true));
|
|
detail_rv_show.setAdapter(mAdapter);
|
|
|
|
reuse_no_connection.setOnClickListener(new View.OnClickListener() {
|
|
@Override
|
|
public void onClick(View v) {
|
|
reuse_no_connection.setVisibility(View.GONE);
|
|
reuse_ll_loading.setVisibility(View.VISIBLE);
|
|
handler.postDelayed(new Runnable() {
|
|
@Override
|
|
public void run() {
|
|
getGameDigest();
|
|
}
|
|
}, 1000);
|
|
}
|
|
});
|
|
|
|
if (mLibaoEntity == null) {
|
|
String id = getIntent().getStringExtra("id");
|
|
if (!TextUtils.isEmpty(id)) {
|
|
getLibaoDigest(id);
|
|
}
|
|
} else {
|
|
init();
|
|
}
|
|
}
|
|
|
|
private void init() {
|
|
if (mLibaoEntity != null && mLibaoEntity.getGame() != null && mLibaoEntity.getGame().getId() != null) {
|
|
title = mLibaoEntity.getName();
|
|
getGameDigest();
|
|
String status = mLibaoEntity.getStatus();
|
|
String beforeStatus = mLibaoEntity.getBeforeStatus();
|
|
if (mLibaoEntity.getRepeat() > 0 &&
|
|
(("linged").equals(status) || ("taoed").equals(status)) &&
|
|
("ling".equals(beforeStatus) || "tao".equals(beforeStatus))) {
|
|
LibaoDao libaoDao = new LibaoDao(this);
|
|
if (libaoDao.isCanLing(mLibaoEntity.getLibaoId(), this)) { // 再次检查重复重复领取条件,防止再礼包列表逗留时间过长,导致到了可领取时间
|
|
handler.sendEmptyMessage(1);
|
|
} else {
|
|
TokenUtils.getTime(LibaoDetailActivity.this);
|
|
handler.sendEmptyMessageDelayed(0, 5000);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
private void getLibaoDigest(String libao_id) {
|
|
RetrofitManager.getLibao().getLibaoDigest(libao_id)
|
|
.subscribeOn(Schedulers.io())
|
|
.observeOn(AndroidSchedulers.mainThread())
|
|
.subscribe(new Response<LibaoEntity>() {
|
|
@Override
|
|
public void onResponse(LibaoEntity response) {
|
|
mLibaoEntity = response;
|
|
mAdapter.setLibaoEntity(mLibaoEntity);
|
|
mAdapter.notifyDataSetChanged();
|
|
init();
|
|
}
|
|
});
|
|
}
|
|
|
|
// 获取游戏摘要
|
|
private void getGameDigest() {
|
|
RetrofitManager.getApi().getGameNewsDigest(mLibaoEntity.getGame().getId())
|
|
.subscribeOn(Schedulers.io())
|
|
.observeOn(AndroidSchedulers.mainThread())
|
|
.subscribe(new Response<GameEntity>() {
|
|
@Override
|
|
public void onResponse(GameEntity response) {
|
|
ApkActiveUtils.filterHideApk(response);
|
|
gameEntity = response;
|
|
|
|
downloadAddWord = gameEntity.getDownloadAddWord();
|
|
downloadOffText = gameEntity.getDownloadOffText();
|
|
initDownload(true);
|
|
|
|
mAdapter.addLibaoDetail();
|
|
}
|
|
|
|
@Override
|
|
public void onFailure(HttpException e) {
|
|
detail_rv_show.setVisibility(View.GONE);
|
|
reuse_ll_loading.setVisibility(View.GONE);
|
|
detail_ll_bottom.setVisibility(View.GONE);
|
|
detail_rv_show.setPadding(0, 0, 0, 0);
|
|
reuse_no_connection.setVisibility(View.VISIBLE);
|
|
}
|
|
});
|
|
}
|
|
|
|
@Override
|
|
public void isScroll(boolean isScroll) {
|
|
mIsScroll = isScroll;
|
|
}
|
|
|
|
@Override
|
|
protected void onDestroy() {
|
|
super.onDestroy();
|
|
handler.removeCallbacksAndMessages(null);
|
|
}
|
|
|
|
@Override
|
|
public void loadDone() {
|
|
if (reuse_ll_loading != null) {
|
|
reuse_ll_loading.setVisibility(View.GONE);
|
|
detail_rv_show.setVisibility(View.VISIBLE);
|
|
}
|
|
}
|
|
|
|
@Override
|
|
public void loadError() {
|
|
detail_rv_show.setVisibility(View.GONE);
|
|
reuse_ll_loading.setVisibility(View.GONE);
|
|
detail_ll_bottom.setVisibility(View.GONE);
|
|
detail_rv_show.setPadding(0, 0, 0, 0);
|
|
reuse_no_connection.setVisibility(View.VISIBLE);
|
|
}
|
|
|
|
@Override
|
|
public void loadEmpty() {
|
|
detail_rv_show.setVisibility(View.GONE);
|
|
reuse_ll_loading.setVisibility(View.GONE);
|
|
detail_ll_bottom.setVisibility(View.GONE);
|
|
detail_rv_show.setPadding(0, 0, 0, 0);
|
|
reuse_tv_none_data.setText("天了噜~页面不见了");
|
|
reuse_none_data.setVisibility(View.VISIBLE);
|
|
}
|
|
|
|
// 领取/淘号失败,根据返回的时间重新倒数
|
|
@Subscribe(threadMode = ThreadMode.MAIN)
|
|
public void onEventMainThread(EBUISwitch swith) {
|
|
if (LibaoUtils.REFRESH_LIBAO_TIME.equals(swith.getFrom())) {
|
|
handler.sendEmptyMessageDelayed(1, swith.getPosition());
|
|
}
|
|
}
|
|
}
|