礼包详情重复淘号,从存号箱和普通列表进去礼包详情 数据同步

This commit is contained in:
kehaoyuan
2017-09-21 16:09:06 +08:00
parent d36dcac817
commit 949c8331d2
9 changed files with 119 additions and 84 deletions

View File

@ -50,7 +50,7 @@ public class DetailDownloadUtils {
viewHolder.downloadPb.setVisibility(View.GONE);
viewHolder.downloadPer.setVisibility(View.GONE);
boolean isInstalled = false;
if (viewHolder.gameEntity.getApk() != null && viewHolder.gameEntity.getApk().size() == 1
if (viewHolder.gameEntity.getApk().size() == 1
&& PackageManager.isInstalled(viewHolder.gameEntity.getApk().get(0).getPackageName())) {
isInstalled = true;
}
@ -122,7 +122,6 @@ public class DetailDownloadUtils {
}
}
if (isCheck && viewHolder.gameEntity != null
&& viewHolder.gameEntity.getApk() != null
&& viewHolder.gameEntity.getApk().size() == 1) {
String url = viewHolder.gameEntity.getApk().get(0).getUrl();
DownloadEntity downloadEntity = DownloadManager.getInstance(viewHolder.context).getDownloadEntityByUrl(url);

View File

@ -4,8 +4,8 @@ import android.content.ClipboardManager;
import android.content.Context;
import android.content.Intent;
import android.content.pm.PackageInfo;
import android.content.res.ColorStateList;
import android.graphics.Color;
import android.support.v4.content.ContextCompat;
import android.text.Html;
import android.text.Spanned;
import android.text.TextUtils;
@ -214,25 +214,14 @@ public class LibaoUtils {
libaoBtn.setBackgroundResource(R.drawable.textview_cancel_up);
break;
case "linged":
int[][] states = new int[2][];
states[0] = new int[]{android.R.attr.state_pressed};
states[1] = new int[]{};
int[] colors = new int[]{Color.WHITE,
Color.parseColor("#06D0A8")};
ColorStateList sl = new ColorStateList(states, colors);
libaoBtn.setText("已领取");
libaoBtn.setBackgroundResource(R.drawable.libao_linged_style);
libaoBtn.setTextColor(sl);
libaoBtn.setTextColor(ContextCompat.getColorStateList(context, R.color.libao_linged_selector));
break;
case "taoed":
int[][] states2 = new int[2][];
states2[0] = new int[]{android.R.attr.state_pressed};
states2[1] = new int[]{};
int[] colors2 = new int[]{Color.WHITE, Color.parseColor("#ffb13c")};
ColorStateList sl2 = new ColorStateList(states2, colors2);
libaoBtn.setText("已淘号");
libaoBtn.setBackgroundResource(R.drawable.libao_taoed_style);
libaoBtn.setTextColor(sl2);
libaoBtn.setTextColor(ContextCompat.getColorStateList(context, R.color.libao_taoed_selector));
break;
case "copy":
libaoBtn.setText("复制");
@ -240,15 +229,9 @@ public class LibaoUtils {
break;
case "repeatLing":
if (adapter == null) {
int[][] states3 = new int[2][];
states3[0] = new int[]{android.R.attr.state_pressed};
states3[1] = new int[]{};
int[] colors3 = new int[]{Color.WHITE,
Color.parseColor("#06D0A8")};
ColorStateList sl3 = new ColorStateList(states3, colors3);
libaoBtn.setText("已领取");
libaoBtn.setBackgroundResource(R.drawable.libao_linged_style);
libaoBtn.setTextColor(sl3);
libaoBtn.setTextColor(ContextCompat.getColorStateList(context, R.color.libao_linged_selector));
} else {
libaoBtn.setText("再领一个");
libaoBtn.setBackgroundResource(R.drawable.textview_cancel_up);
@ -256,20 +239,35 @@ public class LibaoUtils {
break;
case "repeatLinged":
if (adapter == null) {
int[][] states4 = new int[2][];
states4[0] = new int[]{android.R.attr.state_pressed};
states4[1] = new int[]{};
int[] colors4 = new int[]{Color.WHITE,
Color.parseColor("#06D0A8")};
ColorStateList sl4 = new ColorStateList(states4, colors4);
libaoBtn.setText("已领取");
libaoBtn.setBackgroundResource(R.drawable.libao_linged_style);
libaoBtn.setTextColor(sl4);
libaoBtn.setTextColor(ContextCompat.getColorStateList(context, R.color.libao_linged_selector));
} else {
libaoBtn.setText("再领一个");
libaoBtn.setBackgroundResource(R.drawable.textview_green_style);
}
break;
case "repeatTao":
if (adapter == null) {
libaoBtn.setText("已淘号");
libaoBtn.setBackgroundResource(R.drawable.libao_taoed_style);
libaoBtn.setTextColor(ContextCompat.getColorStateList(context, R.color.libao_taoed_selector));
} else {
libaoBtn.setText("再淘一个");
libaoBtn.setBackgroundResource(R.drawable.textview_cancel_up);
}
break;
case "repeatTaoed":
if (adapter == null) {
libaoBtn.setText("已淘号");
libaoBtn.setBackgroundResource(R.drawable.libao_taoed_style);
libaoBtn.setTextColor(ContextCompat.getColorStateList(context, R.color.libao_taoed_selector));
} else {
libaoBtn.setText("再领一个");
libaoBtn.setBackgroundResource(R.drawable.textview_orange_style);
}
break;
default:
libaoBtn.setBackgroundResource(R.drawable.textview_cancel_style);
libaoBtn.setText("异常");
@ -324,7 +322,12 @@ public class LibaoUtils {
libaoLing(context, libaoBtn, libaoEntity, adapter, isInstallRequired, null, entrance);
}
break;
case "再淘一个":
case "淘号":
if (status.equals("repeatTao")) {
Utils.toast(context, "没到重复淘号时间, 礼包每天0点刷新");
return;
}
postLibaoTao(context, libaoEntity.getId(), true, new PostLibaoListener() {
@Override
public void postSucced(Object response) {
@ -414,15 +417,9 @@ public class LibaoUtils {
Utils.toast(context, "你已领过这个礼包了");
getCunHaoXiang(context);
int[][] states2 = new int[2][];
states2[0] = new int[]{android.R.attr.state_pressed};
states2[1] = new int[]{};
int[] colors2 = new int[]{Color.WHITE,
Color.parseColor("#ffb13c")};
ColorStateList sl2 = new ColorStateList(states2, colors2);
libaoBtn.setText("已淘号");
libaoBtn.setBackgroundResource(R.drawable.libao_taoed_style);
libaoBtn.setTextColor(sl2);
libaoBtn.setTextColor(ContextCompat.getColorStateList(context, R.color.libao_taoed_selector));
libaoEntity.setStatus("taoed");
break;
case "try tao":
@ -546,15 +543,9 @@ public class LibaoUtils {
getCunHaoXiang(context);
}
int[][] states = new int[2][];
states[0] = new int[]{android.R.attr.state_pressed};
states[1] = new int[]{};
int[] colors = new int[]{Color.WHITE,
Color.parseColor("#06D0A8")};
ColorStateList sl = new ColorStateList(states, colors);
libaoBtn.setText("已领取");
libaoBtn.setBackgroundResource(R.drawable.libao_linged_style);
libaoBtn.setTextColor(sl);
libaoBtn.setTextColor(ContextCompat.getColorStateList(context, R.color.libao_linged_selector));
libaoEntity.setStatus("linged");
break;

View File

@ -109,7 +109,12 @@ public class LibaoDetailActivity extends BaseActivity implements LibaoDetailAdap
}
handler.sendEmptyMessageDelayed(1, delayedTime);
} else if (msg.what == 1) {
mLibaoEntity.setStatus("repeatLinged");
String beforeStatus = mLibaoEntity.getBeforeStatus();
if ("ling".equals(beforeStatus)) {
mLibaoEntity.setStatus("repeatLinged"); // 可以重复领取
} else {
mLibaoEntity.setStatus("repeatTaoed"); // 可以重复领取
}
mAdapter.notifyItemChanged(0);
}
}
@ -188,7 +193,7 @@ public class LibaoDetailActivity extends BaseActivity implements LibaoDetailAdap
handler.postDelayed(new Runnable() {
@Override
public void run() {
getGameDigest(LibaoDetailActivity.this);
getGameDigest();
}
}, 1000);
}
@ -200,7 +205,8 @@ public class LibaoDetailActivity extends BaseActivity implements LibaoDetailAdap
getLibaoDigest(this, id);
}
} else {
init();
getGameDigest();
checkLibaoStatus();
}
}
@ -214,7 +220,6 @@ public class LibaoDetailActivity extends BaseActivity implements LibaoDetailAdap
protected void onResume() {
super.onResume();
if (mGameEntity != null
&& mGameEntity.getApk() != null
&& mGameEntity.getApk().size() == 1) {
DetailDownloadUtils.detailInitDownload(getDetailViewHolder(), true);
}
@ -227,19 +232,22 @@ public class LibaoDetailActivity extends BaseActivity implements LibaoDetailAdap
}
private void init() {
if (mLibaoEntity != null && mLibaoEntity.getGame() != null && mLibaoEntity.getGame().getId() != null) {
private void checkLibaoStatus() {
if (mLibaoEntity != null) {
mTitle = mLibaoEntity.getName();
getGameDigest(this);
String status = mLibaoEntity.getStatus();
String beforeStatus = mLibaoEntity.getBeforeStatus();
if (mLibaoEntity.getRepeat() > 0 &&
(("linged").equals(status) || ("taoed").equals(status)) &&
("ling".equals(beforeStatus) || "tao".equals(beforeStatus))) {
if (isCanLing()) { // 再次检查重复重复领取条件,防止再礼包列表逗留时间过长,导致到了可领取时间
if (isCanLing()) {
handler.sendEmptyMessage(1);
} else {
mLibaoEntity.setStatus("repeatLing"); // 预备重复领取
if ("ling".equals(beforeStatus)) {
mLibaoEntity.setStatus("repeatLing"); // 预备重复领取
} else {
mLibaoEntity.setStatus("repeatTao"); // 预备重复领取
}
mAdapter.notifyItemChanged(0);
TokenUtils.getTime(LibaoDetailActivity.this);
@ -250,14 +258,24 @@ public class LibaoDetailActivity extends BaseActivity implements LibaoDetailAdap
}
/**
* 礼包重复领取
* 一个礼包最后领取时间不是当天
* 检查是否可以领取/淘号
* 未达到领取总数且一个礼包最后领取/淘号时间不是当天
*/
public boolean isCanLing() {
UserDataEntity userData = mLibaoEntity.getUserData();
if (userData == null) return false;
List<UserDataLibaoEntity> userDataLibaoList = userData.getUserDataLibaoList();
if (userDataLibaoList != null && userDataLibaoList.size() > 0) {
int repeat = mLibaoEntity.getRepeat();
String beforeStatus = mLibaoEntity.getBeforeStatus();
int curStatusCount = 0; // 当前状态的领取/淘号数量
for (UserDataLibaoEntity userDataLibaoEntity : userDataLibaoList) {
if (beforeStatus != null && beforeStatus.equals(userDataLibaoEntity.getType())) {
curStatusCount ++;
}
}
if (repeat > curStatusCount) return false;
UserDataLibaoEntity userDataLibaoEntity = userDataLibaoList.get(userDataLibaoList.size() - 1);
SimpleDateFormat formatDay = new SimpleDateFormat("dd", Locale.CHINA);
long lingTime = userDataLibaoEntity.getTime() * 1000;
@ -287,14 +305,17 @@ public class LibaoDetailActivity extends BaseActivity implements LibaoDetailAdap
mLibaoEntity = response;
mAdapter.setLibaoEntity(mLibaoEntity);
mAdapter.notifyDataSetChanged();
init();
getGameDigest();
checkLibaoStatus();
}
});
}
// 获取游戏摘要
private void getGameDigest(final Context context) {
RetrofitManager.getInstance(context).getApi().getGameNewsDigest(mLibaoEntity.getGame().getId())
private void getGameDigest() {
if (mLibaoEntity.getGame() == null) return;
String gameId = mLibaoEntity.getGame().getId();
RetrofitManager.getInstance(this).getApi().getGameNewsDigest(gameId)
.subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread())
.subscribe(new Response<GameEntity>() {
@ -307,7 +328,7 @@ public class LibaoDetailActivity extends BaseActivity implements LibaoDetailAdap
mDownloadOffText = mGameEntity.getDownloadOffText();
DetailDownloadUtils.detailInitDownload(getDetailViewHolder(), true);
mAdapter.addLibaoDetail(context);
mAdapter.addLibaoDetail(LibaoDetailActivity.this);
}
@Override
@ -337,13 +358,20 @@ public class LibaoDetailActivity extends BaseActivity implements LibaoDetailAdap
mLlLoading.setVisibility(View.GONE);
mLibaoDetailRv.setVisibility(View.VISIBLE);
}
// 从存号箱进入 获取userData后 检查领取状态(是否可以重复领取/重复淘号)
if (mLibaoEntity.isActive() || mLibaoEntity.getUserData() != null) {
checkLibaoStatus();
}
}
@Override
public void loadDone(Object obj) { // 在当前详情页领取获取淘号的数据
Intent data = new Intent();
data.putExtra("UserDataLibaoEntity", (UserDataLibaoEntity)obj);
setResult(0x122, data);
if (obj != null) {
Intent data = new Intent();
data.putExtra("UserDataLibaoEntity", (UserDataLibaoEntity)obj);
setResult(0x122, data);
}
}
@Override
@ -376,7 +404,6 @@ public class LibaoDetailActivity extends BaseActivity implements LibaoDetailAdap
public void onEvent(EBDownloadStatus status) {
if ("delete".equals(status.getStatus())
&& mGameEntity != null
&& mGameEntity.getApk() != null
&& mGameEntity.getApk().size() == 1) {
String url = mGameEntity.getApk().get(0).getUrl();
if (url.equals(status.getUrl())) {
@ -389,7 +416,6 @@ public class LibaoDetailActivity extends BaseActivity implements LibaoDetailAdap
@Subscribe(threadMode = ThreadMode.MAIN)
public void onEventMainThread(EBPackage busFour) {
if (mGameEntity != null
&& mGameEntity.getApk() != null
&& mGameEntity.getApk().size() > 0) {
for (ApkEntity apkEntity : mGameEntity.getApk()) {
String packageName = apkEntity.getPackageName();

View File

@ -78,7 +78,12 @@ public class LibaoDetailAdapter extends BaseRecyclerAdapter<ViewHolder> {
@Override
public void onResponse(LibaoDetailEntity response) {
mLibaoDetailEntity = response;
mOnRequestCallBackListener.loadDone();
UserDataEntity userData = response.getUserData();
if (mLibaoEntity.isActive() && userData != null) { // 以active判断礼包入口 true 为存号箱入口
// 合并userData数据
mLibaoEntity.setUserData(userData);
}
mOnRequestCallBackListener.loadDone(); // 回调 检查领取状态(是否可以重复领取/重复淘号)
notifyDataSetChanged();
}

View File

@ -17,4 +17,7 @@ class LibaoDetailEntity {
var time: LibaoDetailTimeEntity? = null
@SerializedName("user_data")
var userData: UserDataEntity? = null
}

View File

@ -75,6 +75,9 @@ class Libao3FragmentAdapter extends BaseRecyclerAdapter<RecyclerView.ViewHolder>
}
void loadData(int offset) {
if (offset == 0) {
mLibaoList.clear();
}
RetrofitManager.getInstance(mContext)
.getApi().getCunHaoXiang(offset)
.subscribeOn(Schedulers.io())

View File

@ -7,14 +7,12 @@ import com.gh.gamecenter.Injection;
import com.gh.gamecenter.retrofit.service.ApiService;
import com.gh.gamecenter.retrofit.service.DataService;
import com.gh.gamecenter.retrofit.service.UserseaService;
import com.lightgame.utils.Utils;
import java.io.File;
import java.util.concurrent.TimeUnit;
import okhttp3.Cache;
import okhttp3.OkHttpClient;
import okhttp3.logging.HttpLoggingInterceptor;
import retrofit2.Retrofit;
import retrofit2.adapter.rxjava.RxJavaCallAdapterFactory;
import retrofit2.converter.gson.GsonConverterFactory;
@ -40,28 +38,28 @@ public class RetrofitManager {
}
private RetrofitManager(Context context) {
HttpLoggingInterceptor loggingInterceptor = new HttpLoggingInterceptor(new HttpLoggingInterceptor.Logger() {
@Override
public void log(String message) {
//分段打印retrofit日志
if(message.length() > 4000) {
for(int i=0;i<message.length();i+=4000){
if(i+4000<message.length())
Utils.log("RetrofitLog::"+i,message.substring(i, i+4000));
else
Utils.log("RetrofitLog::"+i,message.substring(i, message.length()));
}
} else
Utils.log("RetrofitLog::",message);
}
});
loggingInterceptor.setLevel(HttpLoggingInterceptor.Level.BODY);
// HttpLoggingInterceptor loggingInterceptor = new HttpLoggingInterceptor(new HttpLoggingInterceptor.Logger() {
// @Override
// public void log(String message) {
// //分段打印retrofit日志
// if(message.length() > 4000) {
// for(int i=0;i<message.length();i+=4000){
// if(i+4000<message.length())
// Utils.log("RetrofitLog::"+i,message.substring(i, i+4000));
// else
// Utils.log("RetrofitLog::"+i,message.substring(i, message.length()));
// }
// } else
// Utils.log("RetrofitLog::",message);
// }
// });
// loggingInterceptor.setLevel(HttpLoggingInterceptor.Level.BODY);
final Cache cache = new Cache(new File(OkHttpCache.getCachePath(context)), 10 * 1024 * 1024); // 10Mb
final OkHttpClient okHttpClient = Injection.provideRetrofitBuilder()
.addInterceptor(new OkHttpCacheInterceptor(context))
.addInterceptor(new OkHttpRetryInterceptor(context))
.addInterceptor(loggingInterceptor)
// .addInterceptor(loggingInterceptor)
.addNetworkInterceptor(new OkHttpNetworkInterceptor(context))
.connectTimeout(8, TimeUnit.SECONDS)
.cache(cache)

View File

@ -0,0 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android = "http://schemas.android.com/apk/res/android" >
<item android:color = "@android:color/white" android:state_pressed = "true" />
<item android:color = "@color/btn_plugin" />
</selector >

View File

@ -0,0 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android = "http://schemas.android.com/apk/res/android" >
<item android:color = "@android:color/white" android:state_pressed = "true" />
<item android:color = "@color/btn_open" />
</selector >