From 949c8331d2ef69a98317adeba64cb284bd6a2e32 Mon Sep 17 00:00:00 2001 From: kehaoyuan Date: Thu, 21 Sep 2017 16:09:06 +0800 Subject: [PATCH] =?UTF-8?q?=E7=A4=BC=E5=8C=85=E8=AF=A6=E6=83=85=E9=87=8D?= =?UTF-8?q?=E5=A4=8D=E6=B7=98=E5=8F=B7,=E4=BB=8E=E5=AD=98=E5=8F=B7?= =?UTF-8?q?=E7=AE=B1=E5=92=8C=E6=99=AE=E9=80=9A=E5=88=97=E8=A1=A8=E8=BF=9B?= =?UTF-8?q?=E5=8E=BB=E7=A4=BC=E5=8C=85=E8=AF=A6=E6=83=85=20=E6=95=B0?= =?UTF-8?q?=E6=8D=AE=E5=90=8C=E6=AD=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../gh/common/util/DetailDownloadUtils.java | 3 +- .../java/com/gh/common/util/LibaoUtils.java | 75 ++++++++----------- .../gh/gamecenter/LibaoDetailActivity.java | 66 +++++++++++----- .../adapter/LibaoDetailAdapter.java | 7 +- .../gh/gamecenter/entity/LibaoDetailEntity.kt | 3 + .../libao/Libao3FragmentAdapter.java | 3 + .../gamecenter/retrofit/RetrofitManager.java | 36 +++++---- .../main/res/color/libao_linged_selector.xml | 5 ++ .../main/res/color/libao_taoed_selector.xml | 5 ++ 9 files changed, 119 insertions(+), 84 deletions(-) create mode 100644 app/src/main/res/color/libao_linged_selector.xml create mode 100644 app/src/main/res/color/libao_taoed_selector.xml diff --git a/app/src/main/java/com/gh/common/util/DetailDownloadUtils.java b/app/src/main/java/com/gh/common/util/DetailDownloadUtils.java index aa7a50b18b..0eb59a1ba7 100644 --- a/app/src/main/java/com/gh/common/util/DetailDownloadUtils.java +++ b/app/src/main/java/com/gh/common/util/DetailDownloadUtils.java @@ -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); diff --git a/app/src/main/java/com/gh/common/util/LibaoUtils.java b/app/src/main/java/com/gh/common/util/LibaoUtils.java index 4c76f38efc..49a2963ff6 100644 --- a/app/src/main/java/com/gh/common/util/LibaoUtils.java +++ b/app/src/main/java/com/gh/common/util/LibaoUtils.java @@ -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; diff --git a/app/src/main/java/com/gh/gamecenter/LibaoDetailActivity.java b/app/src/main/java/com/gh/gamecenter/LibaoDetailActivity.java index d338ebe2f2..1b848de780 100644 --- a/app/src/main/java/com/gh/gamecenter/LibaoDetailActivity.java +++ b/app/src/main/java/com/gh/gamecenter/LibaoDetailActivity.java @@ -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 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() { @@ -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(); diff --git a/app/src/main/java/com/gh/gamecenter/adapter/LibaoDetailAdapter.java b/app/src/main/java/com/gh/gamecenter/adapter/LibaoDetailAdapter.java index 3f60dc8bdd..13fe51db00 100644 --- a/app/src/main/java/com/gh/gamecenter/adapter/LibaoDetailAdapter.java +++ b/app/src/main/java/com/gh/gamecenter/adapter/LibaoDetailAdapter.java @@ -78,7 +78,12 @@ public class LibaoDetailAdapter extends BaseRecyclerAdapter { @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(); } diff --git a/app/src/main/java/com/gh/gamecenter/entity/LibaoDetailEntity.kt b/app/src/main/java/com/gh/gamecenter/entity/LibaoDetailEntity.kt index f64f1821d2..c58efeb4fe 100644 --- a/app/src/main/java/com/gh/gamecenter/entity/LibaoDetailEntity.kt +++ b/app/src/main/java/com/gh/gamecenter/entity/LibaoDetailEntity.kt @@ -17,4 +17,7 @@ class LibaoDetailEntity { var time: LibaoDetailTimeEntity? = null + @SerializedName("user_data") + var userData: UserDataEntity? = null + } diff --git a/app/src/main/java/com/gh/gamecenter/libao/Libao3FragmentAdapter.java b/app/src/main/java/com/gh/gamecenter/libao/Libao3FragmentAdapter.java index 5f216aebec..3b5587843b 100644 --- a/app/src/main/java/com/gh/gamecenter/libao/Libao3FragmentAdapter.java +++ b/app/src/main/java/com/gh/gamecenter/libao/Libao3FragmentAdapter.java @@ -75,6 +75,9 @@ class Libao3FragmentAdapter extends BaseRecyclerAdapter } void loadData(int offset) { + if (offset == 0) { + mLibaoList.clear(); + } RetrofitManager.getInstance(mContext) .getApi().getCunHaoXiang(offset) .subscribeOn(Schedulers.io()) diff --git a/app/src/main/java/com/gh/gamecenter/retrofit/RetrofitManager.java b/app/src/main/java/com/gh/gamecenter/retrofit/RetrofitManager.java index 667b593dd7..b305d69563 100644 --- a/app/src/main/java/com/gh/gamecenter/retrofit/RetrofitManager.java +++ b/app/src/main/java/com/gh/gamecenter/retrofit/RetrofitManager.java @@ -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 4000) { +// for(int i=0;i + + + + \ No newline at end of file diff --git a/app/src/main/res/color/libao_taoed_selector.xml b/app/src/main/res/color/libao_taoed_selector.xml new file mode 100644 index 0000000000..176f1735ab --- /dev/null +++ b/app/src/main/res/color/libao_taoed_selector.xml @@ -0,0 +1,5 @@ + + + + + \ No newline at end of file