v9.5.0: 主方案试用策略 — 首7天不限时→第8天起每日1小时 + 倒计时显性化 + 接通到期付费墙(showTrialExpired原为死代码)
This commit is contained in:
1 parent
087bbf52d4
commit
42b38f5b81
3 files changed
+58
-8
No files matched your search
@@ -19,8 +19,8 @@ android {
|
|||||||
applicationId = "com.iptv807.tv"
|
applicationId = "com.iptv807.tv"
|
||||||
minSdk = 21
|
minSdk = 21
|
||||||
targetSdk = 35
|
targetSdk = 35
|
||||||
versionCode = 949
|
versionCode = 950
|
||||||
versionName = "9.4.9"
|
versionName = "9.5.0"
|
||||||
}
|
}
|
||||||
|
|
||||||
signingConfigs {
|
signingConfigs {
|
||||||
|
|||||||
@@ -92,8 +92,33 @@ object LicenseClient {
|
|||||||
return code
|
return code
|
||||||
}
|
}
|
||||||
|
|
||||||
// ===== 免费时长控制(每天1小时)=====
|
// ===== 免费时长控制 =====
|
||||||
|
// 主方案:首 7 天完整体验(不限时)→ 第 8 天起每天 1 小时
|
||||||
const val FREE_DAILY_MS = 60 * 60 * 1000L
|
const val FREE_DAILY_MS = 60 * 60 * 1000L
|
||||||
|
const val FREE_TRIAL_DAYS = 7
|
||||||
|
|
||||||
|
/** 首次安装时间(卸载重装会重新计时,即重新获得 7 天完整体验) */
|
||||||
|
private fun firstInstallAt(ctx: Context): Long {
|
||||||
|
val prefs = ctx.getSharedPreferences("iptv_license", Context.MODE_PRIVATE)
|
||||||
|
val saved = prefs.getLong("first_install_at", 0L)
|
||||||
|
if (saved > 0L) return saved
|
||||||
|
val now = System.currentTimeMillis()
|
||||||
|
prefs.edit().putLong("first_install_at", now).apply()
|
||||||
|
return now
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 免费试用剩余天数:>0 表示还在完整试用期,0 表示已降级为每日 1 小时
|
||||||
|
* 试用期内:不限时长、不计用量
|
||||||
|
*/
|
||||||
|
fun trialDaysLeft(ctx: Context): Int {
|
||||||
|
val start = firstInstallAt(ctx)
|
||||||
|
val day = ((System.currentTimeMillis() - start) / (24 * 60 * 60 * 1000L)).toInt()
|
||||||
|
return (FREE_TRIAL_DAYS - day).coerceAtLeast(0)
|
||||||
|
}
|
||||||
|
|
||||||
|
/** 是否在首 7 天完整试用期 */
|
||||||
|
fun isInTrial(ctx: Context): Boolean = trialDaysLeft(ctx) > 0
|
||||||
|
|
||||||
/** 今天已用免费毫秒数 */
|
/** 今天已用免费毫秒数 */
|
||||||
fun freeUsedTodayMs(ctx: Context): Long {
|
fun freeUsedTodayMs(ctx: Context): Long {
|
||||||
@@ -104,14 +129,22 @@ object LicenseClient {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fun addFreeUsedMs(ctx: Context, delta: Long) {
|
fun addFreeUsedMs(ctx: Context, delta: Long) {
|
||||||
|
if (isInTrial(ctx)) return // 试用期不计用量
|
||||||
val prefs = ctx.getSharedPreferences("iptv_license", Context.MODE_PRIVATE)
|
val prefs = ctx.getSharedPreferences("iptv_license", Context.MODE_PRIVATE)
|
||||||
val today = todayKey()
|
val today = todayKey()
|
||||||
val used = if (prefs.getString("free_date", "") == today) prefs.getLong("free_used_ms", 0) else 0
|
val used = if (prefs.getString("free_date", "") == today) prefs.getLong("free_used_ms", 0) else 0
|
||||||
prefs.edit().putString("free_date", today).putLong("free_used_ms", used + delta).apply()
|
prefs.edit().putString("free_date", today).putLong("free_used_ms", used + delta).apply()
|
||||||
}
|
}
|
||||||
|
|
||||||
fun freeRemainingMs(ctx: Context): Long =
|
/**
|
||||||
(FREE_DAILY_MS - freeUsedTodayMs(ctx)).coerceAtLeast(0)
|
* 今日剩余免费时长
|
||||||
|
* 试用期内返回 7 天的毫秒数(远大于每日额度 → UI 不会显示"今日已用完",
|
||||||
|
* 同时也不会把 %s 分 %s 秒 显示成一个夸张的数字,UI 侧会用 trialDaysLeft 分支覆盖显示)
|
||||||
|
*/
|
||||||
|
fun freeRemainingMs(ctx: Context): Long {
|
||||||
|
if (isInTrial(ctx)) return FREE_TRIAL_DAYS * 24 * 60 * 60 * 1000L
|
||||||
|
return (FREE_DAILY_MS - freeUsedTodayMs(ctx)).coerceAtLeast(0)
|
||||||
|
}
|
||||||
|
|
||||||
/** 日期键北京时间 */
|
/** 日期键北京时间 */
|
||||||
private fun todayKey(): String {
|
private fun todayKey(): String {
|
||||||
|
|||||||
@@ -113,6 +113,8 @@ class MainActivity : Activity() {
|
|||||||
private var annTypeTv: TextView? = null
|
private var annTypeTv: TextView? = null
|
||||||
private var curAnnId = 0
|
private var curAnnId = 0
|
||||||
private var annRetry = 0
|
private var annRetry = 0
|
||||||
|
/** 到期引导页只弹一次(防止 showTrialExpired 重复触发) */
|
||||||
|
private var trialExpiredShown = false
|
||||||
/** 更新弹窗的可聚焦按钮 + 当前焦点索引(遥控器左右切换用) */
|
/** 更新弹窗的可聚焦按钮 + 当前焦点索引(遥控器左右切换用) */
|
||||||
private var updBtns: Array<TextView?> = emptyArray()
|
private var updBtns: Array<TextView?> = emptyArray()
|
||||||
private var updFocusIdx = 0
|
private var updFocusIdx = 0
|
||||||
@@ -535,12 +537,27 @@ class MainActivity : Activity() {
|
|||||||
|
|
||||||
private fun onUiTick() {
|
private fun onUiTick() {
|
||||||
if (isVip) return
|
if (isVip) return
|
||||||
// 每秒累计一次免费用量,这样右上角倒计时才会真正走动
|
// 每秒累计一次免费用量(试用期内 LicenseClient 内部会跳过,不计用量)
|
||||||
if (player?.isPlaying == true) LicenseClient.addFreeUsedMs(this, 1000)
|
if (player?.isPlaying == true) LicenseClient.addFreeUsedMs(this, 1000)
|
||||||
val r = freeRemainingMs()
|
val r = freeRemainingMs()
|
||||||
|
val days = LicenseClient.trialDaysLeft(this)
|
||||||
trialText.visibility = View.VISIBLE
|
trialText.visibility = View.VISIBLE
|
||||||
trialText.text = if (r <= 0) "⏳ 今日免費已用完"
|
trialText.text = when {
|
||||||
else "⏳ 今日免費 ${r / 60000}分${((r % 60000) / 1000).toString().padStart(2, '0')}秒"
|
// ★ 首 7 天完整试用期:显性化"还剩几天"(制造到期紧迫感)
|
||||||
|
days > 0 -> if (days == 1) "🎁 免费试用 · 明天起每天限 1 小时"
|
||||||
|
else "🎁 免费试用 · 还剩 $days 天"
|
||||||
|
r <= 0 -> "⏳ 今日免費已用完"
|
||||||
|
else -> "⏳ 今日免費 ${r / 60000}分${((r % 60000) / 1000).toString().padStart(2, '0')}秒"
|
||||||
|
}
|
||||||
|
|
||||||
|
// ★ 到期钩子:试用期结束(第 8 天起)且今日额度用完 → 弹购买引导页
|
||||||
|
// (原来 showTrialExpired 是死代码、从未被调用,用户只看到文字、画面停住,没有任何付费入口)
|
||||||
|
if (days <= 0 && r <= 0 && !trialExpiredShown) {
|
||||||
|
trialExpiredShown = true
|
||||||
|
handler.removeCallbacks(uiTick)
|
||||||
|
handler.postDelayed({ showTrialExpired() }, 1200) // 让用户看清"已用完"再跳转
|
||||||
|
return
|
||||||
|
}
|
||||||
handler.postDelayed(uiTick, 1000)
|
handler.postDelayed(uiTick, 1000)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in new issue
Block a user