From 5d4648b3d264e4f623db88947950e97490050e24 Mon Sep 17 00:00:00 2001 From: chenjuntao Date: Wed, 27 Nov 2024 15:59:53 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E6=8E=A8=E5=B9=BF=E5=8C=85=E5=BF=AB?= =?UTF-8?q?=E6=89=8BAPI=E6=96=B0=E5=A2=9E=E6=AC=A1=E7=95=99=E4=B8=8A?= =?UTF-8?q?=E6=8A=A5=20https://jira.shanqu.cc/browse/GHZSCY-7048?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/gh/common/util/ActivationHelper.kt | 38 +++++++++++++++++-- .../retrofit/service/ApiService.java | 7 ++++ .../main/java/com/halo/assistant/HaloApp.java | 3 ++ .../com/gh/gamecenter/core/utils/TimeUtils.kt | 18 +++++++++ 4 files changed, 63 insertions(+), 3 deletions(-) diff --git a/app/src/main/java/com/gh/common/util/ActivationHelper.kt b/app/src/main/java/com/gh/common/util/ActivationHelper.kt index 365024162e..73d60792a6 100644 --- a/app/src/main/java/com/gh/common/util/ActivationHelper.kt +++ b/app/src/main/java/com/gh/common/util/ActivationHelper.kt @@ -2,6 +2,7 @@ package com.gh.common.util import com.gh.gamecenter.core.utils.SPUtils import com.gh.gamecenter.common.retrofit.Response +import com.gh.gamecenter.core.utils.TimeUtils import com.gh.gamecenter.retrofit.RetrofitManager import io.reactivex.schedulers.Schedulers import okhttp3.ResponseBody @@ -12,15 +13,18 @@ import okhttp3.ResponseBody object ActivationHelper { private const val HAS_SENT_ACTIVATED_INFO = "has_sent_activated_info" + private const val SENT_ACTIVATED_INFO_TIME = "sent_activated_info_time" + private const val HAS_SENT_RETENTION_INFO = "has_sent_retention_info" - var mHasSentActivatedInfo = SPUtils.getBoolean(HAS_SENT_ACTIVATED_INFO, false) + private var hasSentActivatedInfo = SPUtils.getBoolean(HAS_SENT_ACTIVATED_INFO, false) + private var hasSentRetentionInfo = SPUtils.getBoolean(HAS_SENT_RETENTION_INFO, false) /** * 发送激活信息 (用于推广) */ @JvmStatic fun sendActivationInfo() { - if (!mHasSentActivatedInfo) { + if (!hasSentActivatedInfo) { RetrofitManager.getInstance() .api.postActivationInfo() .subscribeOn(Schedulers.io()) @@ -28,8 +32,36 @@ object ActivationHelper { override fun onResponse(response: ResponseBody?) { super.onResponse(response) - mHasSentActivatedInfo = true + hasSentActivatedInfo = true SPUtils.setBoolean(HAS_SENT_ACTIVATED_INFO, true) + SPUtils.setLong(SENT_ACTIVATED_INFO_TIME, System.currentTimeMillis()) + } + }) + } + } + + /** + * 发送次日留存信息 (用于推广) + */ + @JvmStatic + fun sendRetentionInfo() { + if (hasSentActivatedInfo && !hasSentRetentionInfo) { + val activateTimeMillis = SPUtils.getLong(SENT_ACTIVATED_INFO_TIME, 0) + val currentTimeMillis = System.currentTimeMillis() + + if (!TimeUtils.isNextDay(activateTimeMillis, currentTimeMillis)) { + return + } + + RetrofitManager.getInstance() + .api.postRetentionInfo() + .subscribeOn(Schedulers.io()) + .subscribe(object : Response() { + override fun onResponse(response: ResponseBody?) { + super.onResponse(response) + + hasSentRetentionInfo = true + SPUtils.setBoolean(HAS_SENT_RETENTION_INFO, true) } }) } diff --git a/app/src/main/java/com/gh/gamecenter/retrofit/service/ApiService.java b/app/src/main/java/com/gh/gamecenter/retrofit/service/ApiService.java index 27156754cc..d1dadbfee5 100644 --- a/app/src/main/java/com/gh/gamecenter/retrofit/service/ApiService.java +++ b/app/src/main/java/com/gh/gamecenter/retrofit/service/ApiService.java @@ -1295,6 +1295,13 @@ public interface ApiService { @POST("./app:activate") Observable postActivationInfo(); + /** + * 次日留存 + */ + @POST("./app:retention") + Observable postRetentionInfo(); + + /** * 获取首页游戏补充库 */ diff --git a/app/src/main/java/com/halo/assistant/HaloApp.java b/app/src/main/java/com/halo/assistant/HaloApp.java index eaf7de5497..3372db9afc 100644 --- a/app/src/main/java/com/halo/assistant/HaloApp.java +++ b/app/src/main/java/com/halo/assistant/HaloApp.java @@ -354,6 +354,9 @@ public class HaloApp extends MultiDexApplication { LogUtils.uploadDevice(launchType); ActivationHelper.sendActivationInfo(); + } else { + // 发送次日留存信息 + ActivationHelper.sendRetentionInfo(); } return null; }); diff --git a/module_core/src/main/java/com/gh/gamecenter/core/utils/TimeUtils.kt b/module_core/src/main/java/com/gh/gamecenter/core/utils/TimeUtils.kt index 387cf584bb..9cd52af531 100644 --- a/module_core/src/main/java/com/gh/gamecenter/core/utils/TimeUtils.kt +++ b/module_core/src/main/java/com/gh/gamecenter/core/utils/TimeUtils.kt @@ -93,6 +93,24 @@ object TimeUtils { return false } + /** + * 判断时间戳2是不是时间戳1的第二天 + * + * @param previousTimeMillis 时间戳1 + * @param nextTimeMillis 时间戳2 + */ + fun isNextDay(previousTimeMillis: Long, nextTimeMillis: Long): Boolean { + val previousCalendar = Calendar.getInstance(TimeZone.getDefault()) + previousCalendar.timeInMillis = previousTimeMillis + + val nextCalendar = Calendar.getInstance(TimeZone.getDefault()) + nextCalendar.timeInMillis = nextTimeMillis + + return nextCalendar.get(Calendar.YEAR) == previousCalendar.get(Calendar.YEAR) + && nextCalendar.get(Calendar.DAY_OF_YEAR) == previousCalendar.get(Calendar.DAY_OF_YEAR) + 1 + } + + //判断是不是本周 fun isThisWeek(timestamp: Long): Boolean { val calendar = Calendar.getInstance()