diff --git a/app/build.gradle.kts b/app/build.gradle.kts index 10db0b6..e4c6ef9 100644 --- a/app/build.gradle.kts +++ b/app/build.gradle.kts @@ -19,8 +19,8 @@ android { applicationId = "com.iptv807.tv" minSdk = 21 targetSdk = 35 - versionCode = 949 - versionName = "9.4.9" + versionCode = 950 + versionName = "9.5.0" } signingConfigs { diff --git a/app/src/main/java/com/iptv807/tv/LicenseClient.kt b/app/src/main/java/com/iptv807/tv/LicenseClient.kt index 065d84b..1e1dda6 100644 --- a/app/src/main/java/com/iptv807/tv/LicenseClient.kt +++ b/app/src/main/java/com/iptv807/tv/LicenseClient.kt @@ -92,8 +92,33 @@ object LicenseClient { return code } - // ===== 免费时长控制(每天1小时)===== + // ===== 免费时长控制 ===== + // 主方案:首 7 天完整体验(不限时)→ 第 8 天起每天 1 小时 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 { @@ -104,14 +129,22 @@ object LicenseClient { } fun addFreeUsedMs(ctx: Context, delta: Long) { + if (isInTrial(ctx)) return // 试用期不计用量 val prefs = ctx.getSharedPreferences("iptv_license", Context.MODE_PRIVATE) val today = todayKey() 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() } - 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 { diff --git a/app/src/main/java/com/iptv807/tv/MainActivity.kt b/app/src/main/java/com/iptv807/tv/MainActivity.kt index d4a4035..8046cf1 100644 --- a/app/src/main/java/com/iptv807/tv/MainActivity.kt +++ b/app/src/main/java/com/iptv807/tv/MainActivity.kt @@ -113,6 +113,8 @@ class MainActivity : Activity() { private var annTypeTv: TextView? = null private var curAnnId = 0 private var annRetry = 0 + /** 到期引导页只弹一次(防止 showTrialExpired 重复触发) */ + private var trialExpiredShown = false /** 更新弹窗的可聚焦按钮 + 当前焦点索引(遥控器左右切换用) */ private var updBtns: Array = emptyArray() private var updFocusIdx = 0 @@ -535,12 +537,27 @@ class MainActivity : Activity() { private fun onUiTick() { if (isVip) return - // 每秒累计一次免费用量,这样右上角倒计时才会真正走动 + // 每秒累计一次免费用量(试用期内 LicenseClient 内部会跳过,不计用量) if (player?.isPlaying == true) LicenseClient.addFreeUsedMs(this, 1000) val r = freeRemainingMs() + val days = LicenseClient.trialDaysLeft(this) trialText.visibility = View.VISIBLE - trialText.text = if (r <= 0) "⏳ 今日免費已用完" - else "⏳ 今日免費 ${r / 60000}分${((r % 60000) / 1000).toString().padStart(2, '0')}秒" + trialText.text = when { + // ★ 首 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) }