Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
f6b9a5caa7 | ||
|
|
1d0fefdecf | ||
|
|
65dd927d07 | ||
|
|
42b38f5b81 | ||
|
|
087bbf52d4 | ||
|
|
2b8e9b7923 | ||
|
|
855fa3e970 | ||
|
|
0849ff3875 | ||
|
|
ebe6df7072 | ||
|
|
a2b58ec078 | ||
|
|
b8d2cbeb08 | ||
|
|
1c35ecec2b | ||
|
|
74ef196ee5 | ||
|
|
7a608a1ba3 | ||
|
|
92d497886e | ||
|
|
231ee78ac2 |
No files matched your search
@@ -6,3 +6,7 @@ local.properties
|
|||||||
!apk/*.apk
|
!apk/*.apk
|
||||||
tools/
|
tools/
|
||||||
notes.txt
|
notes.txt
|
||||||
|
keystore.properties
|
||||||
|
*.jks
|
||||||
|
*.keystore
|
||||||
|
*.aab
|
||||||
@@ -3,7 +3,8 @@
|
|||||||
<h1>港澳台直播 · Android TV</h1>
|
<h1>港澳台直播 · Android TV</h1>
|
||||||
<p><b>港澳台 55 个频道,装上就能看,遥控器一点就换台</b></p>
|
<p><b>港澳台 55 个频道,装上就能看,遥控器一点就换台</b></p>
|
||||||
<p>
|
<p>
|
||||||
<a href="https://github.com/personal82555/gangao-tv/releases/latest"><img src="https://img.shields.io/badge/下载-APK-1B6EF3?style=for-the-badge" alt="下载"></a>
|
<a href="https://gitee.com/jinghui111/gangao-tv/releases"><img src="https://img.shields.io/badge/下载-APK-1B6EF3?style=for-the-badge" alt="下载"></a>
|
||||||
|
<a href="https://t.me/+7YVPMu9EOChkYmM1"><img src="https://img.shields.io/badge/Telegram-加入交流群-26A5E4?style=for-the-badge&logo=telegram&logoColor=white" alt="Telegram"></a>
|
||||||
<img src="https://img.shields.io/badge/Android-5.0%2B-3DDC84?style=for-the-badge&logo=android&logoColor=white" alt="Android 5.0+">
|
<img src="https://img.shields.io/badge/Android-5.0%2B-3DDC84?style=for-the-badge&logo=android&logoColor=white" alt="Android 5.0+">
|
||||||
<img src="https://img.shields.io/badge/平台-Android%20TV%20%7C%20电视盒子%20%7C%20手机-555?style=for-the-badge" alt="平台">
|
<img src="https://img.shields.io/badge/平台-Android%20TV%20%7C%20电视盒子%20%7C%20手机-555?style=for-the-badge" alt="平台">
|
||||||
</p>
|
</p>
|
||||||
@@ -57,6 +58,24 @@
|
|||||||
- 包名:`com.iptv807.tv` | 支持 Android 5.0 及以上 | 横屏
|
- 包名:`com.iptv807.tv` | 支持 Android 5.0 及以上 | 横屏
|
||||||
- TV 桌面会自动出现横幅图标(Leanback)
|
- TV 桌面会自动出现横幅图标(Leanback)
|
||||||
|
|
||||||
|
## 💬 加入交流群
|
||||||
|
|
||||||
|
有问题、有建议、想第一时间拿到新版本,欢迎进群里聊。
|
||||||
|
|
||||||
|
**👉 [点此加入 Telegram 交流群](https://t.me/+7YVPMu9EOChkYmM1)**
|
||||||
|
|
||||||
|
群里能拿到这些:
|
||||||
|
|
||||||
|
| | 好处 |
|
||||||
|
|---|---|
|
||||||
|
| 📢 | **新版本第一时间通知** —— 版本推送发布后群内同步提醒,不用天天来盯 Releases 页面 |
|
||||||
|
| 🔧 | **装不上 / 播不出来直接问** —— 带上电视型号和屏幕上的报错文字,通常几分钟就能定位 |
|
||||||
|
| 📡 | **频道与线路问题互通** —— 哪个台挂了、哪条线更稳,大家互相同步,修得更快 |
|
||||||
|
| 💡 | **功能建议真的会被采纳** —— 数字键换台、选中高亮、收藏置顶、开机自启,这些都来自群里的反馈 |
|
||||||
|
| 🎁 | **内测机会** —— 新版本上线前优先发到群里试用 |
|
||||||
|
|
||||||
|
> 进群免费,不发广告;遇到问题先看群公告,多数都能自查解决。
|
||||||
|
|
||||||
## 💳 会员与激活
|
## 💳 会员与激活
|
||||||
|
|
||||||
- **免费**:未激活也能看,每天 1 小时
|
- **免费**:未激活也能看,每天 1 小时
|
||||||
|
|||||||
@@ -1,8 +1,16 @@
|
|||||||
|
import java.util.Properties
|
||||||
|
|
||||||
plugins {
|
plugins {
|
||||||
id("com.android.application")
|
id("com.android.application")
|
||||||
id("org.jetbrains.kotlin.android")
|
id("org.jetbrains.kotlin.android")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// release 签名:从仓库根的 keystore.properties 读取(该文件已 .gitignore,缺失时不影响 debug 构建)
|
||||||
|
val ksProps = Properties().apply {
|
||||||
|
val f = rootProject.file("keystore.properties")
|
||||||
|
if (f.exists()) f.inputStream().use { load(it) }
|
||||||
|
}
|
||||||
|
|
||||||
android {
|
android {
|
||||||
namespace = "com.iptv807.tv"
|
namespace = "com.iptv807.tv"
|
||||||
compileSdk = 35
|
compileSdk = 35
|
||||||
@@ -11,13 +19,25 @@ android {
|
|||||||
applicationId = "com.iptv807.tv"
|
applicationId = "com.iptv807.tv"
|
||||||
minSdk = 21
|
minSdk = 21
|
||||||
targetSdk = 35
|
targetSdk = 35
|
||||||
versionCode = 930
|
versionCode = 961
|
||||||
versionName = "9.3.0"
|
versionName = "9.6.1"
|
||||||
|
}
|
||||||
|
|
||||||
|
signingConfigs {
|
||||||
|
if (ksProps.isNotEmpty()) {
|
||||||
|
create("release") {
|
||||||
|
storeFile = rootProject.file(ksProps.getProperty("storeFile", ""))
|
||||||
|
storePassword = ksProps.getProperty("storePassword")
|
||||||
|
keyAlias = ksProps.getProperty("keyAlias")
|
||||||
|
keyPassword = ksProps.getProperty("keyPassword")
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
buildTypes {
|
buildTypes {
|
||||||
release {
|
release {
|
||||||
isMinifyEnabled = false
|
isMinifyEnabled = false
|
||||||
|
signingConfig = signingConfigs.findByName("release")
|
||||||
proguardFiles(getDefaultProguardFile("proguard-android-optimize.txt"), "proguard-rules.pro")
|
proguardFiles(getDefaultProguardFile("proguard-android-optimize.txt"), "proguard-rules.pro")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -96,4 +96,8 @@ class AiSettingsActivity : Activity() {
|
|||||||
}.start()
|
}.start()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
override fun onKeyDown(keyCode: Int, event: android.view.KeyEvent?): Boolean {
|
||||||
|
if (keyCode == android.view.KeyEvent.KEYCODE_BACK) { finish(); return true }
|
||||||
|
return super.onKeyDown(keyCode, event)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -45,6 +45,18 @@ object AuthApi {
|
|||||||
val installId: Long = 0
|
val installId: Long = 0
|
||||||
)
|
)
|
||||||
|
|
||||||
|
/** 授权系统公告(AnnouncementController → GET /api/public/announcements) */
|
||||||
|
data class Announcement(
|
||||||
|
val id: Int = 0,
|
||||||
|
val title: String = "",
|
||||||
|
val content: String = "",
|
||||||
|
val type: String = "notice", // system / update / promo / notice
|
||||||
|
val isTop: Boolean = false,
|
||||||
|
val isPopup: Boolean = false, // 后台「弹窗」开关
|
||||||
|
val linkUrl: String = "",
|
||||||
|
val createdAt: String = ""
|
||||||
|
)
|
||||||
|
|
||||||
/** 当前应用版本号(用于 client_version 与版本比较) */
|
/** 当前应用版本号(用于 client_version 与版本比较) */
|
||||||
fun clientVersion(ctx: Context): String = try {
|
fun clientVersion(ctx: Context): String = try {
|
||||||
ctx.packageManager.getPackageInfo(ctx.packageName, 0).versionName ?: "0.0.0"
|
ctx.packageManager.getPackageInfo(ctx.packageName, 0).versionName ?: "0.0.0"
|
||||||
@@ -93,6 +105,39 @@ object AuthApi {
|
|||||||
return info
|
return info
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 拉取授权系统公告(网络请求,必须放后台线程)
|
||||||
|
* GET /api/public/announcements?target=client&project_id=2&limit=10
|
||||||
|
* 无需 X-Api-Key(实测无 Key 也 200)
|
||||||
|
* 过滤:status=1 + 生效期内 + target∈{all,client} + project_id∈{null,2}
|
||||||
|
* 返回:data.list 全部有效公告;data.popup 里 is_popup=1 的(后台"弹窗"开关)
|
||||||
|
*/
|
||||||
|
fun fetchAnnouncements(projectId: Int = 2, limit: Int = 10): List<Announcement> {
|
||||||
|
val path = "/api/public/announcements?target=client&project_id=$projectId&limit=" +
|
||||||
|
limit.coerceIn(1, 50)
|
||||||
|
val r = get(path)
|
||||||
|
if (r.optInt("code", 0) != 200) {
|
||||||
|
lastError = "公告 code=${r.optInt("code", 0)} ${r.optString("message")}"
|
||||||
|
return emptyList()
|
||||||
|
}
|
||||||
|
val arr = r.optJSONObject("data")?.optJSONArray("list") ?: return emptyList()
|
||||||
|
val out = ArrayList<Announcement>()
|
||||||
|
for (i in 0 until arr.length()) {
|
||||||
|
val o = arr.optJSONObject(i) ?: continue
|
||||||
|
out.add(Announcement(
|
||||||
|
id = o.optInt("id", 0),
|
||||||
|
title = o.optString("title"),
|
||||||
|
content = o.optString("content"),
|
||||||
|
type = o.optString("type", "notice"),
|
||||||
|
isTop = o.optInt("is_top", 0) == 1,
|
||||||
|
isPopup = o.optInt("is_popup", 0) == 1,
|
||||||
|
linkUrl = o.optString("link_url"),
|
||||||
|
createdAt = o.optString("created_at")
|
||||||
|
))
|
||||||
|
}
|
||||||
|
return out
|
||||||
|
}
|
||||||
|
|
||||||
/** 心跳:仅更新在线时间(网络请求,必须放后台线程) */
|
/** 心跳:仅更新在线时间(网络请求,必须放后台线程) */
|
||||||
@JvmOverloads
|
@JvmOverloads
|
||||||
fun heartbeat(machineId: String, cardKey: String = "", ctx: Context? = null): Boolean {
|
fun heartbeat(machineId: String, cardKey: String = "", ctx: Context? = null): Boolean {
|
||||||
@@ -107,6 +152,25 @@ object AuthApi {
|
|||||||
return ok
|
return ok
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** GET 请求(公告接口是 GET,且不需要 X-Api-Key) */
|
||||||
|
private fun get(path: String): JSONObject = try {
|
||||||
|
val conn = (URL(BASE + path).openConnection() as HttpURLConnection).apply {
|
||||||
|
requestMethod = "GET"
|
||||||
|
connectTimeout = 10_000
|
||||||
|
readTimeout = 15_000
|
||||||
|
setRequestProperty("Accept", "application/json")
|
||||||
|
setRequestProperty("User-Agent", "iptv807-tv")
|
||||||
|
}
|
||||||
|
val code = conn.responseCode
|
||||||
|
val stream = if (code in 200..299) conn.inputStream else conn.errorStream
|
||||||
|
val text = stream?.bufferedReader()?.use(BufferedReader::readText) ?: ""
|
||||||
|
conn.disconnect()
|
||||||
|
JSONObject(if (text.isBlank()) "{}" else text)
|
||||||
|
} catch (e: Exception) {
|
||||||
|
lastError = "GET ${e.javaClass.simpleName}: ${e.message}"
|
||||||
|
JSONObject()
|
||||||
|
}
|
||||||
|
|
||||||
private fun post(path: String, body: JSONObject): JSONObject {
|
private fun post(path: String, body: JSONObject): JSONObject {
|
||||||
return try {
|
return try {
|
||||||
val conn = (URL(BASE + path).openConnection() as HttpURLConnection).apply {
|
val conn = (URL(BASE + path).openConnection() as HttpURLConnection).apply {
|
||||||
|
|||||||
@@ -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 {
|
||||||
|
|||||||
@@ -140,4 +140,9 @@ class LoginActivity : Activity() {
|
|||||||
startActivity(Intent(this, MainActivity::class.java))
|
startActivity(Intent(this, MainActivity::class.java))
|
||||||
finish()
|
finish()
|
||||||
}
|
}
|
||||||
|
/** ★ 返回键显式处理(原来缺失 → 走系统默认,用户按返回无提示) */
|
||||||
|
override fun onKeyDown(keyCode: Int, event: android.view.KeyEvent?): Boolean {
|
||||||
|
if (keyCode == android.view.KeyEvent.KEYCODE_BACK) { finish(); return true }
|
||||||
|
return super.onKeyDown(keyCode, event)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -97,10 +97,39 @@ class MainActivity : Activity() {
|
|||||||
private var downT = 0L
|
private var downT = 0L
|
||||||
private var exitHint: TextView? = null
|
private var exitHint: TextView? = null
|
||||||
private var confirmOverlay: View? = null
|
private var confirmOverlay: View? = null
|
||||||
|
/** 右上角「立即授权」按钮(未授权时显示) */
|
||||||
|
private var authBtn: TextView? = null
|
||||||
|
/** 右下角「已授权」小字标识(已授权时显示,未授权隐藏) */
|
||||||
|
private var authStateText: TextView? = null
|
||||||
|
/** 首次启动简易教程遮罩 */
|
||||||
|
private var tutorialOverlay: View? = null
|
||||||
|
private var tutorialVisible = false
|
||||||
|
/** 公告弹窗(授权系统 AnnouncementController 发布的) */
|
||||||
|
private var annOverlay: View? = null
|
||||||
|
private var annVisible = false
|
||||||
|
private var annOkBtn: TextView? = null
|
||||||
|
private var annTitle: TextView? = null
|
||||||
|
private var annBody: TextView? = null
|
||||||
|
private var annTypeTv: TextView? = null
|
||||||
|
private var curAnnId = 0
|
||||||
|
private var annRetry = 0
|
||||||
|
/** 到期引导页只弹一次(防止 showTrialExpired 重复触发) */
|
||||||
|
private var trialExpiredShown = false
|
||||||
|
/** 更新弹窗的可聚焦按钮 + 当前焦点索引(遥控器左右切换用) */
|
||||||
|
private var updBtns: Array<TextView?> = emptyArray()
|
||||||
|
private var updFocusIdx = 0
|
||||||
|
private var updForce = false
|
||||||
// 安装统计 + 版本推送
|
// 安装统计 + 版本推送
|
||||||
private var updateOverlay: View? = null
|
private var updateOverlay: View? = null
|
||||||
private var pendingUpdate: AuthApi.UpdateInfo? = null
|
private var pendingUpdate: AuthApi.UpdateInfo? = null
|
||||||
private var downloadId = -1L
|
private var downloadId = -1L
|
||||||
|
/**
|
||||||
|
* ★ 2026-10-15 起:暂时全面免费 —— 关闭授权限制与全部授权提示。
|
||||||
|
* 保留不变:安装统计(check-update)、在线统计(heartbeat 心跳)、公告推送(announcements)。
|
||||||
|
* 将来恢复授权:把这里改回 true 即可(限制与提示逻辑均原样保留在下方各分支里)。
|
||||||
|
*/
|
||||||
|
private val authGateEnabled = false
|
||||||
|
|
||||||
private val heartbeatTask = object : Runnable {
|
private val heartbeatTask = object : Runnable {
|
||||||
override fun run() {
|
override fun run() {
|
||||||
Thread {
|
Thread {
|
||||||
@@ -178,18 +207,53 @@ class MainActivity : Activity() {
|
|||||||
root.addView(statusText, FrameLayout.LayoutParams(
|
root.addView(statusText, FrameLayout.LayoutParams(
|
||||||
ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT))
|
ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT))
|
||||||
|
|
||||||
// 4) 右上:免费时长 + 模式
|
// 4) 右上:免费时长 + 模式 + 【立即授权】按钮(横排,按钮在倒计时右边)
|
||||||
val rightCol = LinearLayout(this).apply { orientation = LinearLayout.VERTICAL }
|
val rightCol = LinearLayout(this).apply { orientation = LinearLayout.HORIZONTAL }
|
||||||
trialText = TextView(this).apply {
|
trialText = TextView(this).apply {
|
||||||
textSize = 14f; setTextColor(Color.WHITE)
|
textSize = 14f; setTextColor(Color.WHITE)
|
||||||
setBackgroundColor(0x88000000u.toInt())
|
setBackgroundColor(0x88000000u.toInt())
|
||||||
setPadding(20, 10, 20, 10)
|
setPadding(20, 10, 20, 10)
|
||||||
}
|
}
|
||||||
rightCol.addView(trialText)
|
rightCol.addView(trialText)
|
||||||
|
|
||||||
|
authBtn = TextView(this).apply {
|
||||||
|
text = "🔑 立即授权"
|
||||||
|
textSize = 14f
|
||||||
|
setTextColor(Color.WHITE)
|
||||||
|
setBackgroundColor(0xFF1B6EF3.toInt())
|
||||||
|
setPadding(26, 10, 26, 10)
|
||||||
|
isFocusable = true
|
||||||
|
isFocusableInTouchMode = true
|
||||||
|
visibility = View.GONE // 授权成功后隐藏
|
||||||
|
// 遥控器聚焦高亮:蓝底加白框
|
||||||
|
val pad = (4 * resources.displayMetrics.density).toInt()
|
||||||
|
setOnFocusChangeListener { v, has ->
|
||||||
|
v.setBackgroundColor(if (has) 0xFF3D8BFF.toInt() else 0xFF1B6EF3.toInt())
|
||||||
|
v.setPadding(26, 10, 26, 10)
|
||||||
|
if (has) v.alpha = 1f else v.alpha = 0.95f
|
||||||
|
}
|
||||||
|
setOnClickListener { openAuthPage() }
|
||||||
|
}
|
||||||
|
rightCol.addView(authBtn, LinearLayout.LayoutParams(
|
||||||
|
ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT).apply { leftMargin = 8 })
|
||||||
val rcLP = FrameLayout.LayoutParams(
|
val rcLP = FrameLayout.LayoutParams(
|
||||||
ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT, Gravity.TOP or Gravity.END)
|
ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT, Gravity.TOP or Gravity.END)
|
||||||
root.addView(rightCol, rcLP)
|
root.addView(rightCol, rcLP)
|
||||||
|
|
||||||
|
// 4b) 右下角:已授权标识(小字,不打扰观看;未授权时隐藏)
|
||||||
|
authStateText = TextView(this).apply {
|
||||||
|
text = "✓ 已授权"
|
||||||
|
textSize = 12f
|
||||||
|
setTextColor(0xB3FFFFFF.toInt()) // 70% 白,弱化存在感
|
||||||
|
setBackgroundColor(0x59000000.toInt()) // 35% 黑底,保证在亮画面上也看得清
|
||||||
|
setPadding(14, 6, 14, 6)
|
||||||
|
setShadowLayer(3f, 1f, 1f, Color.BLACK)
|
||||||
|
visibility = View.GONE
|
||||||
|
}
|
||||||
|
root.addView(authStateText, FrameLayout.LayoutParams(
|
||||||
|
ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT,
|
||||||
|
Gravity.BOTTOM or Gravity.END).apply { setMargins(0, 0, 26, 26) })
|
||||||
|
|
||||||
// 5) 数字键大字
|
// 5) 数字键大字
|
||||||
digitText = TextView(this).apply {
|
digitText = TextView(this).apply {
|
||||||
textSize = 56f; setTextColor(Color.WHITE)
|
textSize = 56f; setTextColor(Color.WHITE)
|
||||||
@@ -203,8 +267,9 @@ class MainActivity : Activity() {
|
|||||||
// 6) 加载罩
|
// 6) 加载罩
|
||||||
loadingMask = FrameLayout(this).apply { setBackgroundColor(0xB2000000u.toInt()); visibility = View.GONE }
|
loadingMask = FrameLayout(this).apply { setBackgroundColor(0xB2000000u.toInt()); visibility = View.GONE }
|
||||||
loadingText = TextView(this).apply {
|
loadingText = TextView(this).apply {
|
||||||
textSize = 28f; setTextColor(Color.WHITE); gravity = Gravity.CENTER
|
textSize = 16f; setTextColor(0xE6FFFFFF.toInt()); gravity = Gravity.CENTER
|
||||||
setShadowLayer(6f, 3f, 3f, Color.BLACK)
|
setShadowLayer(4f, 2f, 2f, Color.BLACK)
|
||||||
|
setPadding(32, 0, 32, 0)
|
||||||
}
|
}
|
||||||
loadingMask.addView(loadingText, FrameLayout.LayoutParams(
|
loadingMask.addView(loadingText, FrameLayout.LayoutParams(
|
||||||
ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT))
|
ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT))
|
||||||
@@ -274,12 +339,15 @@ class MainActivity : Activity() {
|
|||||||
window.addFlags(android.view.WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON)
|
window.addFlags(android.view.WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON)
|
||||||
checkLicense()
|
checkLicense()
|
||||||
startInstallTracking() // 安装统计 + 检查新版本
|
startInstallTracking() // 安装统计 + 检查新版本
|
||||||
|
fetchAnnouncement() // ★ 拉取授权系统公告(3 秒后,避开启动高峰;更新弹窗优先)
|
||||||
if (savedInstanceState == null && channels.isNotEmpty()) {
|
if (savedInstanceState == null && channels.isNotEmpty()) {
|
||||||
val defIdx = channels.indexOfFirst { it.name.contains("TVB翡翠台") }.let { if (it >= 0) it else 0 }
|
val defIdx = channels.indexOfFirst { it.name.contains("TVB翡翠台") }.let { if (it >= 0) it else 0 }
|
||||||
playChannel(defIdx)
|
playChannel(defIdx)
|
||||||
// 启动后预取默认频道的相邻频道(很轻量,1 个一个来)
|
// 启动后预取默认频道的相邻频道(很轻量,1 个一个来)
|
||||||
handler.postDelayed({ schedulePrefetch(channels.getOrNull(defIdx)) }, 2000)
|
handler.postDelayed({ schedulePrefetch(channels.getOrNull(defIdx)) }, 2000)
|
||||||
}
|
}
|
||||||
|
// 新安装首次打开 → 简易使用教程(可关闭,只弹一次)
|
||||||
|
maybeShowTutorial()
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun setMode(m: Int) { mode = m }
|
private fun setMode(m: Int) { mode = m }
|
||||||
@@ -319,25 +387,191 @@ class MainActivity : Activity() {
|
|||||||
runOnUiThread {
|
runOnUiThread {
|
||||||
isVip = r.ok
|
isVip = r.ok
|
||||||
prefs.edit().putBoolean("is_vip", r.ok).apply()
|
prefs.edit().putBoolean("is_vip", r.ok).apply()
|
||||||
if (r.ok) { trialText.visibility = View.GONE; trialText.text = "VIP" } else enterFreeMode()
|
if (!authGateEnabled) {
|
||||||
|
// 暂时全面免费:隐藏所有授权相关 UI,不进入任何限制模式
|
||||||
|
trialText.visibility = View.GONE
|
||||||
|
showAuthButton(false)
|
||||||
|
showAuthState(false)
|
||||||
|
} else if (r.ok) {
|
||||||
|
trialText.visibility = View.GONE; trialText.text = "VIP"
|
||||||
|
showAuthButton(false)
|
||||||
|
showAuthState(true) // 右下角显示「✓ 已授权」
|
||||||
|
} else enterFreeMode()
|
||||||
}
|
}
|
||||||
}.start()
|
}.start()
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun enterFreeMode() {
|
private fun enterFreeMode() {
|
||||||
trialText.visibility = View.VISIBLE
|
trialText.visibility = View.VISIBLE
|
||||||
|
showAuthButton(true)
|
||||||
|
showAuthState(false) // 免费模式下不显示右下角标识
|
||||||
handler.removeCallbacks(uiTick)
|
handler.removeCallbacks(uiTick)
|
||||||
handler.post(uiTick)
|
handler.post(uiTick)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** 右下角「✓ 已授权」标识 显示/隐藏 */
|
||||||
|
private fun showAuthState(show: Boolean) {
|
||||||
|
runOnUiThread {
|
||||||
|
val t = authStateText ?: return@runOnUiThread
|
||||||
|
t.visibility = if (show) View.VISIBLE else View.GONE
|
||||||
|
t.text = if (show) "✓ 已授权" else ""
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/** 显示/隐藏右上角「立即授权」按钮 */
|
||||||
|
private fun showAuthButton(show: Boolean) {
|
||||||
|
runOnUiThread {
|
||||||
|
val b = authBtn ?: return@runOnUiThread
|
||||||
|
b.visibility = if (show) View.VISIBLE else View.GONE
|
||||||
|
if (show) {
|
||||||
|
// 首次出现时自动聚焦,遥控器按 OK 直接进授权页
|
||||||
|
b.postDelayed({
|
||||||
|
if (b.visibility == View.VISIBLE && !isPanelVisible() && tutorialOverlay?.visibility != View.VISIBLE) {
|
||||||
|
b.requestFocus()
|
||||||
|
}
|
||||||
|
}, 600)
|
||||||
|
} else {
|
||||||
|
b.clearFocus()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/** 菜单键/其他入口统一打开设置页;带三重诊断,打不开时屏幕上有原因 */
|
||||||
|
private fun openSettingsPage() {
|
||||||
|
val intent = Intent(this, SettingsActivity::class.java)
|
||||||
|
// ① 预检查:系统能否解析到这个 Activity(manifest 没注册会返回 null)
|
||||||
|
val resolve = try { packageManager.resolveActivity(intent, 0) } catch (e: Exception) { null }
|
||||||
|
if (resolve == null) {
|
||||||
|
statusText.text = "⚠ 设置页无法解析:manifest 未注册 SettingsActivity"
|
||||||
|
android.widget.Toast.makeText(this, "设置页无法解析(manifest 未注册)", android.widget.Toast.LENGTH_LONG).show()
|
||||||
|
return
|
||||||
|
}
|
||||||
|
// ② 启动
|
||||||
|
val before = try { getSharedPreferences("iptv_main", MODE_PRIVATE).getLong("settings_opened_at", 0L) } catch (e: Exception) { 0L }
|
||||||
|
try {
|
||||||
|
startActivity(intent)
|
||||||
|
} catch (e: Exception) {
|
||||||
|
statusText.text = "⚠ 打开设置失败: ${e.javaClass.simpleName}: ${e.message}"
|
||||||
|
android.widget.Toast.makeText(this, "打开设置失败: ${e.message}", android.widget.Toast.LENGTH_LONG).show()
|
||||||
|
return
|
||||||
|
}
|
||||||
|
// ③ 1.4 秒后核对:SettingsActivity.onCreate 有没有真的跑起来
|
||||||
|
handler.postDelayed({
|
||||||
|
val after = try { getSharedPreferences("iptv_main", MODE_PRIVATE).getLong("settings_opened_at", 0L) } catch (e: Exception) { 0L }
|
||||||
|
if (after <= before) {
|
||||||
|
statusText.text = "⚠ 设置页未响应:onCreate 未执行(启动被拦截或立刻结束)"
|
||||||
|
android.widget.Toast.makeText(this, "设置页未响应,请把这行字告诉我", android.widget.Toast.LENGTH_LONG).show()
|
||||||
|
}
|
||||||
|
}, 1400)
|
||||||
|
}
|
||||||
|
|
||||||
|
/** 打开授权/激活页面(就是设置页:卡密激活 + 购买入口 + 撤销授权) */
|
||||||
|
private fun openAuthPage() { openSettingsPage() }
|
||||||
|
|
||||||
|
/** 首次启动:简易使用教程(可关闭,只弹一次) */
|
||||||
|
private fun maybeShowTutorial() {
|
||||||
|
try {
|
||||||
|
if (getSharedPreferences("iptv_main", MODE_PRIVATE).getBoolean("tutorial_done", false)) return
|
||||||
|
|
||||||
|
val mask = FrameLayout(this).apply {
|
||||||
|
setBackgroundColor(0xE6000000.toInt())
|
||||||
|
isClickable = true // 挡住底层点击
|
||||||
|
}
|
||||||
|
val card = LinearLayout(this).apply {
|
||||||
|
orientation = LinearLayout.VERTICAL
|
||||||
|
setBackgroundColor(0xFF161B26.toInt())
|
||||||
|
setPadding(64, 48, 64, 56)
|
||||||
|
}
|
||||||
|
card.addView(TextView(this).apply {
|
||||||
|
text = "📺 欢迎使用「港澳台直播」"
|
||||||
|
textSize = 24f; setTextColor(Color.WHITE); setPadding(0, 0, 0, 6)
|
||||||
|
})
|
||||||
|
card.addView(TextView(this).apply {
|
||||||
|
text = "花 30 秒知道怎么用,功能一个不少"
|
||||||
|
textSize = 14f; setTextColor(0xFF93A1B8.toInt()); setPadding(0, 0, 0, 26)
|
||||||
|
})
|
||||||
|
|
||||||
|
val steps = listOf(
|
||||||
|
"1️⃣ 按遥控器 OK 键 → 打开选台面板",
|
||||||
|
"2️⃣ 上下键选频道(选中行蓝底高亮),左右键切换香港 / 澳门 / 台湾分组",
|
||||||
|
"3️⃣ 直接按数字键 → 快速跳到对应频道(按 9 就是 9 号台)",
|
||||||
|
"4️⃣ 菜单键 → 收藏 / 取消收藏当前频道",
|
||||||
|
"5️⃣ 连滑两次 或 按返回键 → 退出应用(都会先弹确认框)",
|
||||||
|
"6️⃣ 断线自动重连、10 条线路自动切换,画面卡住点「▶ 继续播放」即可"
|
||||||
|
)
|
||||||
|
for (t in steps) {
|
||||||
|
card.addView(TextView(this).apply {
|
||||||
|
text = t; textSize = 16f; setTextColor(0xFFE6ECF7.toInt())
|
||||||
|
setLineSpacing(0f, 1.35f); setPadding(0, 9, 0, 9)
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
val okBtn = android.widget.Button(this).apply {
|
||||||
|
text = "知道了,开始观看"
|
||||||
|
textSize = 17f
|
||||||
|
isFocusable = true; isFocusableInTouchMode = true
|
||||||
|
setBackgroundColor(0xFF1B6EF3.toInt())
|
||||||
|
setTextColor(Color.WHITE)
|
||||||
|
setOnClickListener { closeTutorial() }
|
||||||
|
}
|
||||||
|
card.addView(okBtn, LinearLayout.LayoutParams(
|
||||||
|
ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT).apply { topMargin = 34 })
|
||||||
|
|
||||||
|
val scroll = android.widget.ScrollView(this).apply {
|
||||||
|
setBackgroundColor(Color.TRANSPARENT)
|
||||||
|
isFillViewport = true
|
||||||
|
addView(card)
|
||||||
|
}
|
||||||
|
mask.addView(scroll, FrameLayout.LayoutParams(
|
||||||
|
ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT, Gravity.CENTER
|
||||||
|
).apply { setMargins(260, 90, 260, 90) })
|
||||||
|
|
||||||
|
root.addView(mask, FrameLayout.LayoutParams(
|
||||||
|
ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT))
|
||||||
|
tutorialOverlay = mask
|
||||||
|
tutorialVisible = true
|
||||||
|
okBtn.post { okBtn.requestFocus() } // 遥控器 OK 直接关闭
|
||||||
|
} catch (e: Exception) {
|
||||||
|
// 教程失败不能影响正常播放
|
||||||
|
tutorialVisible = false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/** 关闭教程并记住(之后不再显示) */
|
||||||
|
private fun closeTutorial() {
|
||||||
|
tutorialVisible = false
|
||||||
|
try {
|
||||||
|
getSharedPreferences("iptv_main", MODE_PRIVATE).edit().putBoolean("tutorial_done", true).apply()
|
||||||
|
} catch (e: Exception) { }
|
||||||
|
root.removeView(tutorialOverlay)
|
||||||
|
tutorialOverlay = null
|
||||||
|
}
|
||||||
|
|
||||||
private fun onUiTick() {
|
private fun onUiTick() {
|
||||||
|
// ★ 暂时全面免费:不显示任何倒计时/试用提示,也不触发到期引导页
|
||||||
|
if (!authGateEnabled) { trialText.visibility = View.GONE; return }
|
||||||
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)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -439,8 +673,7 @@ class MainActivity : Activity() {
|
|||||||
setItemsCanFocus(false)
|
setItemsCanFocus(false)
|
||||||
onItemClickListener = AdapterView.OnItemClickListener { _, _, pos, _ ->
|
onItemClickListener = AdapterView.OnItemClickListener { _, _, pos, _ ->
|
||||||
if (pos == 0) {
|
if (pos == 0) {
|
||||||
startActivity(Intent(this@MainActivity, SettingsActivity::class.java))
|
openSettingsPage(); hidePanel(); return@OnItemClickListener
|
||||||
hidePanel(); return@OnItemClickListener
|
|
||||||
}
|
}
|
||||||
if (pos == 0) return@OnItemClickListener
|
if (pos == 0) return@OnItemClickListener
|
||||||
curGroupPos = pos - 1
|
curGroupPos = pos - 1
|
||||||
@@ -679,11 +912,67 @@ class MainActivity : Activity() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
override fun onKeyDown(keyCode: Int, event: KeyEvent?): Boolean {
|
override fun onKeyDown(keyCode: Int, event: KeyEvent?): Boolean {
|
||||||
|
// 首次教程显示时:返回/OK 都可关闭
|
||||||
|
if (tutorialVisible) {
|
||||||
|
if (keyCode == KeyEvent.KEYCODE_BACK ||
|
||||||
|
keyCode == KeyEvent.KEYCODE_DPAD_CENTER ||
|
||||||
|
keyCode == KeyEvent.KEYCODE_ENTER) {
|
||||||
|
closeTutorial(); return true
|
||||||
|
}
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
// ★ 更新弹窗显示时:所有按键都由弹窗接管。
|
||||||
|
// 否则会落到下面的 showPanel()/exitApp()/换台 —— 遥控器就"选不了"了
|
||||||
|
if (isUpdateDialogVisible()) {
|
||||||
|
when (keyCode) {
|
||||||
|
KeyEvent.KEYCODE_BACK -> { hideUpdateDialog(); return true }
|
||||||
|
|
||||||
|
KeyEvent.KEYCODE_DPAD_CENTER, KeyEvent.KEYCODE_ENTER,
|
||||||
|
KeyEvent.KEYCODE_NUMPAD_ENTER, KeyEvent.KEYCODE_SPACE -> {
|
||||||
|
val btn = updBtns.getOrNull(updFocusIdx)
|
||||||
|
?.takeIf { it.visibility == View.VISIBLE }
|
||||||
|
?: updBtns.filterNotNull().firstOrNull { it.visibility == View.VISIBLE }
|
||||||
|
btn?.performClick()
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
|
||||||
|
KeyEvent.KEYCODE_DPAD_LEFT, KeyEvent.KEYCODE_DPAD_UP -> { moveUpdateFocus(-1); return true }
|
||||||
|
KeyEvent.KEYCODE_DPAD_RIGHT, KeyEvent.KEYCODE_DPAD_DOWN -> { moveUpdateFocus( 1); return true }
|
||||||
|
|
||||||
|
else -> return true // 数字键 / 菜单键 等全部吞掉(弹窗期间不能换台、不能进设置)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// ★ 公告弹窗显示时:按键由弹窗接管(OK/返回都 = 确认关闭;吞掉数字键/菜单键)
|
||||||
|
if (isAnnDialogVisible()) {
|
||||||
|
when (keyCode) {
|
||||||
|
KeyEvent.KEYCODE_BACK,
|
||||||
|
KeyEvent.KEYCODE_DPAD_CENTER, KeyEvent.KEYCODE_ENTER,
|
||||||
|
KeyEvent.KEYCODE_NUMPAD_ENTER, KeyEvent.KEYCODE_SPACE -> {
|
||||||
|
hideAnnouncement(); return true
|
||||||
|
}
|
||||||
|
else -> return true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// 退出确认框显示时:返回=取消,其余交给按钮焦点系统处理(左右切换,OK 确认)
|
// 退出确认框显示时:返回=取消,其余交给按钮焦点系统处理(左右切换,OK 确认)
|
||||||
if (confirmVisible) {
|
if (confirmVisible) {
|
||||||
if (keyCode == KeyEvent.KEYCODE_BACK) { hideExitConfirm(); return true }
|
if (keyCode == KeyEvent.KEYCODE_BACK) { hideExitConfirm(); return true }
|
||||||
return super.onKeyDown(keyCode, event)
|
return super.onKeyDown(keyCode, event)
|
||||||
}
|
}
|
||||||
|
// 右上角「立即授权」按钮聚焦时:OK 进授权页,返回取消聚焦,方向键清焦点后继续正常换台
|
||||||
|
if (authBtn?.visibility == View.VISIBLE && authBtn?.isFocused == true) {
|
||||||
|
when (keyCode) {
|
||||||
|
KeyEvent.KEYCODE_DPAD_CENTER, KeyEvent.KEYCODE_ENTER, KeyEvent.KEYCODE_NUMPAD_ENTER -> {
|
||||||
|
openAuthPage(); return true
|
||||||
|
}
|
||||||
|
KeyEvent.KEYCODE_BACK -> { authBtn?.clearFocus(); return true }
|
||||||
|
KeyEvent.KEYCODE_DPAD_UP, KeyEvent.KEYCODE_DPAD_DOWN,
|
||||||
|
KeyEvent.KEYCODE_DPAD_LEFT, KeyEvent.KEYCODE_DPAD_RIGHT -> {
|
||||||
|
authBtn?.clearFocus() // 不 return:落到下面正常换台/开面板逻辑
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
// 「继续播放」按钮可见时,遥控 OK/确认 直接触发
|
// 「继续播放」按钮可见时,遥控 OK/确认 直接触发
|
||||||
if (resumeBtn?.visibility == View.VISIBLE &&
|
if (resumeBtn?.visibility == View.VISIBLE &&
|
||||||
(keyCode == KeyEvent.KEYCODE_DPAD_CENTER || keyCode == KeyEvent.KEYCODE_ENTER ||
|
(keyCode == KeyEvent.KEYCODE_DPAD_CENTER || keyCode == KeyEvent.KEYCODE_ENTER ||
|
||||||
@@ -748,7 +1037,10 @@ class MainActivity : Activity() {
|
|||||||
KeyEvent.KEYCODE_DPAD_CENTER, KeyEvent.KEYCODE_ENTER, KeyEvent.KEYCODE_NUMPAD_ENTER -> {
|
KeyEvent.KEYCODE_DPAD_CENTER, KeyEvent.KEYCODE_ENTER, KeyEvent.KEYCODE_NUMPAD_ENTER -> {
|
||||||
if (panelCol == 0) {
|
if (panelCol == 0) {
|
||||||
val np = groupAdapter?.selected ?: 0
|
val np = groupAdapter?.selected ?: 0
|
||||||
if (np == 0) { startActivity(Intent(this, SettingsActivity::class.java)); hidePanel() }
|
if (np == 0) {
|
||||||
|
openSettingsPage() // 统一走带诊断的入口
|
||||||
|
hidePanel()
|
||||||
|
}
|
||||||
else { curGroupPos = np - 1; updateChannelListOfGroup(curGroupPos); panelCol = 1; refreshPanelHighlight() }
|
else { curGroupPos = np - 1; updateChannelListOfGroup(curGroupPos); panelCol = 1; refreshPanelHighlight() }
|
||||||
} else {
|
} else {
|
||||||
val pos = channelAdapter?.selected ?: -1
|
val pos = channelAdapter?.selected ?: -1
|
||||||
@@ -761,7 +1053,11 @@ class MainActivity : Activity() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
when (keyCode) {
|
when (keyCode) {
|
||||||
KeyEvent.KEYCODE_MENU -> { autoSwitchLine(); return true }
|
// ★ 修复:返回键必须弹退出确认,绝不直接 finish(原来漏了这个分支,
|
||||||
|
// 导致 BACK 落到 super.onKeyDown() = 系统默认无提示退出)
|
||||||
|
KeyEvent.KEYCODE_BACK -> { exitApp(); return true }
|
||||||
|
// ★ 菜单键 → 打开设置页(原来这里是「换线」,换线已移到设置页里)
|
||||||
|
KeyEvent.KEYCODE_MENU -> { openSettingsPage(); return true }
|
||||||
KeyEvent.KEYCODE_CHANNEL_UP -> { playChannel((currentChannel - 1 + channels.size) % channels.size); return true }
|
KeyEvent.KEYCODE_CHANNEL_UP -> { playChannel((currentChannel - 1 + channels.size) % channels.size); return true }
|
||||||
KeyEvent.KEYCODE_CHANNEL_DOWN -> { playChannel((currentChannel + 1) % channels.size); return true }
|
KeyEvent.KEYCODE_CHANNEL_DOWN -> { playChannel((currentChannel + 1) % channels.size); return true }
|
||||||
KeyEvent.KEYCODE_DPAD_UP, KeyEvent.KEYCODE_DPAD_DOWN -> {
|
KeyEvent.KEYCODE_DPAD_UP, KeyEvent.KEYCODE_DPAD_DOWN -> {
|
||||||
@@ -836,58 +1132,192 @@ class MainActivity : Activity() {
|
|||||||
}.getOrDefault(AuthApi.UpdateInfo(msg = AuthApi.lastError))
|
}.getOrDefault(AuthApi.UpdateInfo(msg = AuthApi.lastError))
|
||||||
runOnUiThread {
|
runOnUiThread {
|
||||||
if (info.ok) {
|
if (info.ok) {
|
||||||
val sb = StringBuilder("安装上报 ok #${info.installId} · v${AuthApi.clientVersion(this)}")
|
// ★ 不再把「安装上报 ok #xxx」写到左上角(用户要求去掉该提示);
|
||||||
if (info.updateAvailable) sb.append(" · 发现新版 v${info.latestVersion}")
|
// 上报请求本身照常发出 → 安装统计 / 在线统计 / 版本检查均不受影响。
|
||||||
statusText.text = sb.toString()
|
// statusText 交回频道显示逻辑(切换频道时显示「▶ 频道号 频道名」)。
|
||||||
handler.postDelayed({
|
|
||||||
val c = channels.getOrNull(currentChannel)
|
|
||||||
if (c != null) statusText.text = "▶ ${c.num} ${c.name}"
|
|
||||||
}, 8000)
|
|
||||||
if (info.updateAvailable) {
|
if (info.updateAvailable) {
|
||||||
pendingUpdate = info
|
pendingUpdate = info
|
||||||
showUpdateDialog(info)
|
showUpdateDialog(info)
|
||||||
}
|
}
|
||||||
} else {
|
|
||||||
statusText.text = "安装上报失败: ${info.msg}"
|
|
||||||
}
|
}
|
||||||
|
// 上报失败也不再提示(保持界面干净),失败信息静默丢弃
|
||||||
}
|
}
|
||||||
}.start()
|
}.start()
|
||||||
handler.removeCallbacks(heartbeatTask)
|
handler.removeCallbacks(heartbeatTask)
|
||||||
handler.postDelayed(heartbeatTask, 60 * 1000L) // 1 分钟后首次心跳
|
handler.postDelayed(heartbeatTask, 60 * 1000L) // 1 分钟后首次心跳
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 拉取授权系统公告,若有「弹窗」开关打开且未读过的,则弹给用户看。
|
||||||
|
* 去重:iptv_main 的 ann_seen_id 记录最后看过的公告 id,同一条只弹一次。
|
||||||
|
*/
|
||||||
|
private fun fetchAnnouncement(delayMs: Long = 3000L) {
|
||||||
|
handler.postDelayed({
|
||||||
|
Thread {
|
||||||
|
val list = try { AuthApi.fetchAnnouncements(projectId = 2, limit = 10) }
|
||||||
|
catch (e: Exception) { emptyList() }
|
||||||
|
// 只弹 is_popup=1 的;按 id 升序取最新一条未读
|
||||||
|
val sp = getSharedPreferences("iptv_main", MODE_PRIVATE)
|
||||||
|
val seen = sp.getInt("ann_seen_id", 0)
|
||||||
|
val target = list.filter { it.isPopup && it.id > seen }
|
||||||
|
.maxByOrNull { it.id }
|
||||||
|
if (target != null) {
|
||||||
|
runOnUiThread {
|
||||||
|
// 更新弹窗优先:它没关掉就延迟再试(最多 15 次 x 2 秒)
|
||||||
|
if (isUpdateDialogVisible() && annRetry < 15) {
|
||||||
|
annRetry++
|
||||||
|
fetchAnnouncement(2000L)
|
||||||
|
} else if (!annVisible) {
|
||||||
|
showAnnouncement(target)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}.start()
|
||||||
|
}, delayMs)
|
||||||
|
}
|
||||||
|
|
||||||
|
/** 公告弹窗(自绘,和更新弹窗同一套三件套:focusable + requestFocus + onKeyDown 分支) */
|
||||||
|
private fun showAnnouncement(a: AuthApi.Announcement) {
|
||||||
|
if (annOverlay == null) {
|
||||||
|
val dm = resources.displayMetrics
|
||||||
|
val wDp = dm.widthPixels / dm.density
|
||||||
|
val sc = when {
|
||||||
|
wDp < 500f -> 0.62f // 手机竖屏
|
||||||
|
wDp < 760f -> 0.80f // 手机横屏 / 小平板
|
||||||
|
else -> 1.00f // TV
|
||||||
|
}
|
||||||
|
fun sp(v: Float): Float = v * sc
|
||||||
|
fun px(v: Int): Int = (v * sc).toInt()
|
||||||
|
|
||||||
|
val mask = FrameLayout(this).apply { setBackgroundColor(0xCC000000u.toInt()); isClickable = true }
|
||||||
|
val card = LinearLayout(this).apply {
|
||||||
|
orientation = LinearLayout.VERTICAL
|
||||||
|
setBackgroundColor(Color.parseColor("#22262E"))
|
||||||
|
setPadding(px(56), px(40), px(56), px(40))
|
||||||
|
}
|
||||||
|
annTypeTv = TextView(this).apply {
|
||||||
|
tag = "anntype"; textSize = sp(16f); setTextColor(Color.parseColor("#FFC107"))
|
||||||
|
gravity = Gravity.CENTER; setPadding(0, 0, 0, px(14))
|
||||||
|
}
|
||||||
|
card.addView(annTypeTv)
|
||||||
|
annTitle = TextView(this).apply {
|
||||||
|
tag = "anntitle"; textSize = sp(22f); setTextColor(Color.WHITE)
|
||||||
|
gravity = Gravity.CENTER; setLineSpacing(0f, 1.25f); setPadding(0, 0, 0, px(16))
|
||||||
|
}
|
||||||
|
card.addView(annTitle)
|
||||||
|
annBody = TextView(this).apply {
|
||||||
|
tag = "annbody"; textSize = sp(15f); setTextColor(Color.parseColor("#D8DEE9"))
|
||||||
|
setBackgroundColor(Color.parseColor("#1C2028"))
|
||||||
|
setPadding(px(24), px(20), px(24), px(20)); setLineSpacing(0f, 1.3f)
|
||||||
|
maxLines = 8; ellipsize = android.text.TextUtils.TruncateAt.END
|
||||||
|
maxHeight = (dm.heightPixels * 0.34f).toInt()
|
||||||
|
}
|
||||||
|
card.addView(annBody)
|
||||||
|
annOkBtn = TextView(this).apply {
|
||||||
|
tag = "annok"; text = "确认关闭"; textSize = sp(18f)
|
||||||
|
setTextColor(Color.WHITE); gravity = Gravity.CENTER
|
||||||
|
setPadding(px(64), px(22), px(64), px(22))
|
||||||
|
isFocusable = true; isFocusableInTouchMode = true
|
||||||
|
background = android.graphics.drawable.StateListDrawable().apply {
|
||||||
|
addState(intArrayOf(android.R.attr.state_focused),
|
||||||
|
android.graphics.drawable.ColorDrawable(Color.parseColor("#1B6EF3")))
|
||||||
|
addState(intArrayOf(),
|
||||||
|
android.graphics.drawable.ColorDrawable(Color.parseColor("#3A4150")))
|
||||||
|
}
|
||||||
|
setOnClickListener { hideAnnouncement() }
|
||||||
|
}
|
||||||
|
val rowLp = LinearLayout.LayoutParams(
|
||||||
|
ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT
|
||||||
|
).apply { gravity = Gravity.CENTER_HORIZONTAL; topMargin = px(28) }
|
||||||
|
card.addView(annOkBtn, rowLp)
|
||||||
|
|
||||||
|
val cardW = (dm.widthPixels * 0.90f).toInt()
|
||||||
|
mask.addView(card, FrameLayout.LayoutParams(
|
||||||
|
cardW, ViewGroup.LayoutParams.WRAP_CONTENT, Gravity.CENTER))
|
||||||
|
root.addView(mask, FrameLayout.LayoutParams(
|
||||||
|
ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT))
|
||||||
|
annOverlay = mask
|
||||||
|
}
|
||||||
|
val typeLabel = when (a.type) {
|
||||||
|
"system" -> "🔔 系统公告"
|
||||||
|
"update" -> "🔄 更新公告"
|
||||||
|
"promo" -> "🎁 活动公告"
|
||||||
|
else -> "📢 通知公告"
|
||||||
|
}
|
||||||
|
curAnnId = a.id
|
||||||
|
annTypeTv?.text = typeLabel
|
||||||
|
annTitle?.text = a.title.ifEmpty { "公告" }
|
||||||
|
annBody?.text = a.content.ifEmpty { "(无内容)" }
|
||||||
|
annOverlay?.visibility = View.VISIBLE
|
||||||
|
annVisible = true
|
||||||
|
// ★ 三件套之二:主动聚焦(否则遥控器按 OK 不命中)
|
||||||
|
handler.postDelayed({
|
||||||
|
if (annVisible) annOkBtn?.requestFocus()
|
||||||
|
}, 120)
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun hideAnnouncement() {
|
||||||
|
// ★ 去重:记录已读的最大公告 id,同一条不再弹(新公告 id 更大,仍会弹)
|
||||||
|
try {
|
||||||
|
val sp = getSharedPreferences("iptv_main", MODE_PRIVATE)
|
||||||
|
val seen = sp.getInt("ann_seen_id", 0)
|
||||||
|
if (curAnnId > seen) sp.edit().putInt("ann_seen_id", curAnnId).apply()
|
||||||
|
} catch (e: Exception) { }
|
||||||
|
curAnnId = 0
|
||||||
|
annOverlay?.visibility = View.GONE
|
||||||
|
annVisible = false
|
||||||
|
annOkBtn?.clearFocus() // 三件套之四:清焦点残留
|
||||||
|
annRetry = 0
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun isAnnDialogVisible(): Boolean = annOverlay?.visibility == View.VISIBLE
|
||||||
|
|
||||||
/** 新版本提示(自绘浮层,电视全屏主题下 AlertDialog 不可靠) */
|
/** 新版本提示(自绘浮层,电视全屏主题下 AlertDialog 不可靠) */
|
||||||
private fun showUpdateDialog(info: AuthApi.UpdateInfo) {
|
private fun showUpdateDialog(info: AuthApi.UpdateInfo) {
|
||||||
if (updateOverlay == null) {
|
if (updateOverlay == null) {
|
||||||
|
// ★ 尺寸自适应:原字号/内边距按 TV 写死且卡片宽度无约束,手机竖屏会溢出
|
||||||
|
val dm = resources.displayMetrics
|
||||||
|
val wDp = dm.widthPixels / dm.density
|
||||||
|
val s = when {
|
||||||
|
wDp < 500f -> 0.62f // 手机竖屏(约 360-430dp 宽)
|
||||||
|
wDp < 760f -> 0.80f // 手机横屏 / 小平板
|
||||||
|
else -> 1.00f // 电视 / 平板横屏(960dp+)保持原样
|
||||||
|
}
|
||||||
|
fun sp(v: Float): Float = v * s
|
||||||
|
fun px(v: Int): Int = (v * s).toInt()
|
||||||
|
|
||||||
val mask = FrameLayout(this).apply { setBackgroundColor(0xCC000000u.toInt()) }
|
val mask = FrameLayout(this).apply { setBackgroundColor(0xCC000000u.toInt()) }
|
||||||
val card = LinearLayout(this).apply {
|
val card = LinearLayout(this).apply {
|
||||||
orientation = LinearLayout.VERTICAL
|
orientation = LinearLayout.VERTICAL
|
||||||
setBackgroundColor(Color.parseColor("#22262E"))
|
setBackgroundColor(Color.parseColor("#22262E"))
|
||||||
setPadding(64, 48, 64, 48)
|
setPadding(px(64), px(48), px(64), px(48))
|
||||||
}
|
}
|
||||||
card.addView(TextView(this).apply {
|
card.addView(TextView(this).apply {
|
||||||
text = "发现新版本"; textSize = 24f; setTextColor(Color.WHITE)
|
text = "发现新版本"; textSize = sp(24f); setTextColor(Color.WHITE)
|
||||||
gravity = Gravity.CENTER; setPadding(0, 0, 0, 12)
|
gravity = Gravity.CENTER; setPadding(0, 0, 0, px(12))
|
||||||
})
|
})
|
||||||
card.addView(TextView(this).apply {
|
card.addView(TextView(this).apply {
|
||||||
tag = "ver"; textSize = 40f; setTextColor(Color.parseColor("#4CAF50"))
|
tag = "ver"; textSize = sp(40f); setTextColor(Color.parseColor("#4CAF50"))
|
||||||
gravity = Gravity.CENTER; setPadding(0, 0, 0, 16)
|
gravity = Gravity.CENTER; setPadding(0, 0, 0, px(16))
|
||||||
})
|
})
|
||||||
card.addView(TextView(this).apply {
|
card.addView(TextView(this).apply {
|
||||||
tag = "meta"; textSize = 15f; setTextColor(Color.LTGRAY)
|
tag = "meta"; textSize = sp(15f); setTextColor(Color.LTGRAY)
|
||||||
gravity = Gravity.CENTER; setLineSpacing(0f, 1.2f); setPadding(0, 0, 0, 24)
|
gravity = Gravity.CENTER; setLineSpacing(0f, 1.2f); setPadding(0, 0, 0, px(24))
|
||||||
})
|
})
|
||||||
card.addView(TextView(this).apply {
|
card.addView(TextView(this).apply {
|
||||||
tag = "chg"; textSize = 15f; setTextColor(Color.WHITE)
|
tag = "chg"; textSize = sp(15f); setTextColor(Color.WHITE)
|
||||||
setBackgroundColor(Color.parseColor("#1C2028"))
|
setBackgroundColor(Color.parseColor("#1C2028"))
|
||||||
setPadding(24, 20, 24, 20); setLineSpacing(0f, 1.25f)
|
setPadding(px(24), px(20), px(24), px(20)); setLineSpacing(0f, 1.25f)
|
||||||
maxLines = 8; gravity = Gravity.CENTER
|
// ★ 限行 + 省略 + 高度上限:长 changelog 不再把卡片撑出屏幕
|
||||||
|
maxLines = 6; ellipsize = android.text.TextUtils.TruncateAt.END
|
||||||
|
maxHeight = (dm.heightPixels * 0.34f).toInt()
|
||||||
|
gravity = Gravity.CENTER
|
||||||
})
|
})
|
||||||
val row = LinearLayout(this).apply { orientation = LinearLayout.HORIZONTAL; gravity = Gravity.CENTER; setPadding(0, 28, 0, 0) }
|
val row = LinearLayout(this).apply { orientation = LinearLayout.HORIZONTAL; gravity = Gravity.CENTER; setPadding(0, px(28), 0, 0) }
|
||||||
fun mkBtn(label: String, focusable: Boolean, onClick: () -> Unit): TextView =
|
fun mkBtn(label: String, focusable: Boolean, onClick: () -> Unit): TextView =
|
||||||
TextView(this).apply {
|
TextView(this).apply {
|
||||||
text = label; textSize = 18f; setTextColor(Color.WHITE); gravity = Gravity.CENTER
|
text = label; textSize = sp(18f); setTextColor(Color.WHITE); gravity = Gravity.CENTER
|
||||||
setPadding(56, 22, 56, 22); isFocusable = focusable; isFocusableInTouchMode = focusable
|
setPadding(px(56), px(22), px(56), px(22)); isFocusable = focusable; isFocusableInTouchMode = focusable
|
||||||
if (focusable) background = android.graphics.drawable.StateListDrawable().apply {
|
if (focusable) background = android.graphics.drawable.StateListDrawable().apply {
|
||||||
addState(intArrayOf(android.R.attr.state_focused),
|
addState(intArrayOf(android.R.attr.state_focused),
|
||||||
android.graphics.drawable.ColorDrawable(Color.parseColor("#1B6EF3")))
|
android.graphics.drawable.ColorDrawable(Color.parseColor("#1B6EF3")))
|
||||||
@@ -895,17 +1325,20 @@ class MainActivity : Activity() {
|
|||||||
} else setBackgroundColor(Color.parseColor("#2A2F3A"))
|
} else setBackgroundColor(Color.parseColor("#2A2F3A"))
|
||||||
setOnClickListener { onClick() }
|
setOnClickListener { onClick() }
|
||||||
}
|
}
|
||||||
val laterBtn = mkBtn("稍后", true) { hideUpdateDialog() }
|
// ★ 两个按钮都必须可聚焦,否则遥控器永远选不到「立即更新」
|
||||||
val dlBtn = mkBtn("立即更新", false) {
|
val laterBtn = mkBtn("稍后", true) { hideUpdateDialog() }.apply { tag = "later" }
|
||||||
|
val dlBtn = mkBtn("立即更新", true) {
|
||||||
pendingUpdate?.let { startUpdateDownload(it) }; hideUpdateDialog()
|
pendingUpdate?.let { startUpdateDownload(it) }; hideUpdateDialog()
|
||||||
}
|
}.apply { tag = "dl" }
|
||||||
row.addView(laterBtn, LinearLayout.LayoutParams(
|
row.addView(laterBtn, LinearLayout.LayoutParams(
|
||||||
ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT).apply { rightMargin = 32 })
|
ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT).apply { rightMargin = px(32) })
|
||||||
row.addView(dlBtn, LinearLayout.LayoutParams(
|
row.addView(dlBtn, LinearLayout.LayoutParams(
|
||||||
ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT))
|
ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT))
|
||||||
card.addView(row)
|
card.addView(row)
|
||||||
|
// ★ 卡片宽度 = 屏幕 90%(左右各留 5%),任何屏幕都不会溢出
|
||||||
|
val cardW = (dm.widthPixels * 0.90f).toInt()
|
||||||
mask.addView(card, FrameLayout.LayoutParams(
|
mask.addView(card, FrameLayout.LayoutParams(
|
||||||
ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT, Gravity.CENTER))
|
cardW, ViewGroup.LayoutParams.WRAP_CONTENT, Gravity.CENTER))
|
||||||
root.addView(mask, FrameLayout.LayoutParams(
|
root.addView(mask, FrameLayout.LayoutParams(
|
||||||
ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT))
|
ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT))
|
||||||
updateOverlay = mask
|
updateOverlay = mask
|
||||||
@@ -920,12 +1353,48 @@ class MainActivity : Activity() {
|
|||||||
meta.text = "当前 v${AuthApi.clientVersion(this)}" + (if (mb.isNotEmpty()) " · $mb" else "") +
|
meta.text = "当前 v${AuthApi.clientVersion(this)}" + (if (mb.isNotEmpty()) " · $mb" else "") +
|
||||||
(if (force) "\n⚠ 请升级到此版本" else "")
|
(if (force) "\n⚠ 请升级到此版本" else "")
|
||||||
chg.text = info.changelog.ifEmpty { "本次更新包含功能优化与问题修复" }
|
chg.text = info.changelog.ifEmpty { "本次更新包含功能优化与问题修复" }
|
||||||
|
|
||||||
|
// ★ 强制更新时不给「稍后」(原代码只写了注释没实现)
|
||||||
|
val laterB = updateOverlay!!.findViewWithTag<TextView>("later")
|
||||||
|
val dlB = updateOverlay!!.findViewWithTag<TextView>("dl")
|
||||||
|
updForce = info.updateRequired || (info.minClientVersion.isNotEmpty() &&
|
||||||
|
compareVersion(AuthApi.clientVersion(this), info.minClientVersion) < 0)
|
||||||
|
laterB?.visibility = if (updForce) View.GONE else View.VISIBLE
|
||||||
|
// 可见的按钮列表(强制更新时只剩「立即更新」)
|
||||||
|
updBtns = arrayOf(if (updForce) null else laterB, dlB)
|
||||||
|
updFocusIdx = if (updForce) 1 else 1 // 默认聚焦「立即更新」(主操作)
|
||||||
|
|
||||||
updateOverlay!!.visibility = View.VISIBLE
|
updateOverlay!!.visibility = View.VISIBLE
|
||||||
// 强制更新时不给"稍后"
|
// ★ 必须主动聚焦,否则遥控器按 OK 不会命中任何按钮
|
||||||
updateOverlay!!.findViewWithTag<TextView>("ver") // touch to ensure rendered
|
handler.postDelayed({
|
||||||
|
if (updateOverlay?.visibility == View.VISIBLE) {
|
||||||
|
updBtns.getOrNull(updFocusIdx)?.requestFocus()
|
||||||
|
}
|
||||||
|
}, 120)
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun hideUpdateDialog() { updateOverlay?.visibility = View.GONE }
|
private fun hideUpdateDialog() {
|
||||||
|
updateOverlay?.visibility = View.GONE
|
||||||
|
// 清掉焦点,避免残留焦点挡住后续按键
|
||||||
|
updBtns.forEach { it?.clearFocus() }
|
||||||
|
updFocusIdx = 0
|
||||||
|
}
|
||||||
|
|
||||||
|
/** 更新弹窗内切换按钮焦点(遥控器左右/上下) */
|
||||||
|
private fun moveUpdateFocus(delta: Int) {
|
||||||
|
val visible = updBtns.filterNotNull().filter { it.visibility == View.VISIBLE }
|
||||||
|
if (visible.isEmpty()) return
|
||||||
|
val cur = updBtns.getOrNull(updFocusIdx)
|
||||||
|
var i = visible.indexOf(cur)
|
||||||
|
if (i < 0) i = 0
|
||||||
|
i = (i + delta + visible.size) % visible.size
|
||||||
|
val target = visible[i]
|
||||||
|
updFocusIdx = updBtns.indexOf(target)
|
||||||
|
target.requestFocus()
|
||||||
|
}
|
||||||
|
|
||||||
|
/** 更新弹窗是否显示 */
|
||||||
|
private fun isUpdateDialogVisible(): Boolean = updateOverlay?.visibility == View.VISIBLE
|
||||||
|
|
||||||
/** 比较 "9.10.0" vs "9.3.0" 之类 */
|
/** 比较 "9.10.0" vs "9.3.0" 之类 */
|
||||||
fun compareVersion(a: String, b: String): Int {
|
fun compareVersion(a: String, b: String): Int {
|
||||||
@@ -1066,7 +1535,14 @@ class MainActivity : Activity() {
|
|||||||
if (nowVip && (card.isNotEmpty() || !isVip)) {
|
if (nowVip && (card.isNotEmpty() || !isVip)) {
|
||||||
isVip = true
|
isVip = true
|
||||||
trialText.visibility = View.GONE
|
trialText.visibility = View.GONE
|
||||||
|
showAuthButton(false)
|
||||||
|
showAuthState(true) // 右下角显示「✓ 已授权」
|
||||||
handler.removeCallbacks(uiTick)
|
handler.removeCallbacks(uiTick)
|
||||||
|
} else if (!nowVip && isVip) {
|
||||||
|
// ★ 设置页里撤销了授权 → 回到免费模式(倒计时 + 立即授权按钮都恢复)
|
||||||
|
isVip = false
|
||||||
|
showAuthState(false) // 右下角标识隐藏
|
||||||
|
enterFreeMode()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// 从桌面/设置返回:先尝试续播,失败则显示「继续播放」按钮
|
// 从桌面/设置返回:先尝试续播,失败则显示「继续播放」按钮
|
||||||
@@ -1096,6 +1572,14 @@ class MainActivity : Activity() {
|
|||||||
playRequested = -1
|
playRequested = -1
|
||||||
if (idx >= 0) playChannel(idx)
|
if (idx >= 0) playChannel(idx)
|
||||||
}
|
}
|
||||||
|
// 设置页点「切换线路」→ 回来执行(原菜单键功能,现已移到设置页)
|
||||||
|
run {
|
||||||
|
val sp = getSharedPreferences("iptv_main", MODE_PRIVATE)
|
||||||
|
if (sp.getString("pending_action", "") == "switch_line") {
|
||||||
|
sp.edit().remove("pending_action").apply()
|
||||||
|
autoSwitchLine()
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/** 点「继续播放」→ 重新连接当前频道(直播流最稳的恢复方式) */
|
/** 点「继续播放」→ 重新连接当前频道(直播流最稳的恢复方式) */
|
||||||
|
|||||||
@@ -87,10 +87,7 @@ class SettingsActivity : Activity() {
|
|||||||
} catch (e: Exception) { "1.0" }
|
} catch (e: Exception) { "1.0" }
|
||||||
|
|
||||||
val prefs = getSharedPreferences("iptv_license", MODE_PRIVATE)
|
val prefs = getSharedPreferences("iptv_license", MODE_PRIVATE)
|
||||||
val isVip = prefs.getBoolean("is_vip", false)
|
// v9.6.1:暂时全面免费,本页不再读取/展示任何授权状态(isVip/expire/permanent/cardKey 已移除)
|
||||||
val expire = prefs.getString("vip_expire", "")
|
|
||||||
val permanent = prefs.getBoolean("is_permanent", false)
|
|
||||||
val cardKey = prefs.getString("card_key", "")
|
|
||||||
|
|
||||||
root.addView(TextView(this).apply {
|
root.addView(TextView(this).apply {
|
||||||
text = "版本信息"
|
text = "版本信息"
|
||||||
@@ -98,7 +95,8 @@ class SettingsActivity : Activity() {
|
|||||||
setPadding(0, 0, 0, 8)
|
setPadding(0, 0, 0, 8)
|
||||||
})
|
})
|
||||||
root.addView(TextView(this).apply {
|
root.addView(TextView(this).apply {
|
||||||
text = "App 版本:$versionName\n授权系统:CardAuth(app.88531.cn)\n机器码:${LicenseClient.machineCode(this@SettingsActivity)}"
|
// v9.6.1:暂时全面免费,不再显示授权系统 / 机器码等收费痕迹,只留版本号
|
||||||
|
text = "App 版本:$versionName\n本软件完全免费 · 无广告 · 无第三方 SDK"
|
||||||
textSize = 15f; setTextColor(Color.WHITE)
|
textSize = 15f; setTextColor(Color.WHITE)
|
||||||
setLineSpacing(0f, 1.15f)
|
setLineSpacing(0f, 1.15f)
|
||||||
setBackgroundColor(Color.parseColor("#1C2028"))
|
setBackgroundColor(Color.parseColor("#1C2028"))
|
||||||
@@ -134,22 +132,14 @@ class SettingsActivity : Activity() {
|
|||||||
root.addView(bootSwitch, LinearLayout.LayoutParams(
|
root.addView(bootSwitch, LinearLayout.LayoutParams(
|
||||||
ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT).apply { bottomMargin = 40 })
|
ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT).apply { bottomMargin = 40 })
|
||||||
|
|
||||||
// ===== 会员状态 =====
|
// ===== 状态提示条(切换线路等操作的结果显示在这里)=====
|
||||||
root.addView(TextView(this).apply {
|
// v9.6.1:原来的「会员状态」区块已移除(暂时全面免费,不暴露授权/收费信息)
|
||||||
text = "会员状态"
|
|
||||||
textSize = 15f; setTextColor(Color.parseColor("#7AA7D9"))
|
|
||||||
setPadding(0, 0, 0, 8)
|
|
||||||
})
|
|
||||||
statusText = TextView(this).apply {
|
statusText = TextView(this).apply {
|
||||||
textSize = 15f; setLineSpacing(0f, 1.15f)
|
textSize = 15f; setLineSpacing(0f, 1.15f)
|
||||||
setTextColor(Color.WHITE)
|
setTextColor(Color.WHITE)
|
||||||
setBackgroundColor(Color.parseColor("#1C2028"))
|
setBackgroundColor(Color.parseColor("#1C2028"))
|
||||||
setPadding(24, 20, 24, 20)
|
setPadding(24, 20, 24, 20)
|
||||||
text = if (isVip) {
|
text = ""
|
||||||
"✓ 已是会员\n${if (permanent) "永久有效" else "有效期至:$expire"}${if (cardKey?.isNotEmpty() == true) "\n卡号:$cardKey" else ""}"
|
|
||||||
} else {
|
|
||||||
"当前为免费用户(每天 1 小时)\n尚未成为会员"
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
root.addView(statusText, LinearLayout.LayoutParams(
|
root.addView(statusText, LinearLayout.LayoutParams(
|
||||||
ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT).apply { bottomMargin = 24 })
|
ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT).apply { bottomMargin = 24 })
|
||||||
@@ -165,7 +155,7 @@ class SettingsActivity : Activity() {
|
|||||||
textSize = 15f; setLineSpacing(0f, 1.15f)
|
textSize = 15f; setLineSpacing(0f, 1.15f)
|
||||||
setTextColor(Color.WHITE); setBackgroundColor(Color.parseColor("#1C2028"))
|
setTextColor(Color.WHITE); setBackgroundColor(Color.parseColor("#1C2028"))
|
||||||
setPadding(24, 20, 24, 20)
|
setPadding(24, 20, 24, 20)
|
||||||
text = "点击右侧按钮检查是否有新版本\n(安装统计会在启动时自动上报)"
|
text = "点击右侧按钮检查是否有新版本"
|
||||||
}
|
}
|
||||||
root.addView(statusText2, LinearLayout.LayoutParams(
|
root.addView(statusText2, LinearLayout.LayoutParams(
|
||||||
ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT).apply { bottomMargin = 12 })
|
ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT).apply { bottomMargin = 12 })
|
||||||
@@ -174,44 +164,81 @@ class SettingsActivity : Activity() {
|
|||||||
root.addView(checkBtn, LinearLayout.LayoutParams(
|
root.addView(checkBtn, LinearLayout.LayoutParams(
|
||||||
ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT).apply { bottomMargin = 40 })
|
ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT).apply { bottomMargin = 40 })
|
||||||
|
|
||||||
// ===== 卡密激活 =====
|
// ===== 卡密激活:v9.6.1 起暂时全面免费,此区块整块移除(恢复见 git 历史)=====
|
||||||
|
|
||||||
|
// ===== ★ 售后联系方式(安装 / 播放遇到问题时能找到人)=====
|
||||||
root.addView(TextView(this).apply {
|
root.addView(TextView(this).apply {
|
||||||
text = "卡密激活"
|
text = "💬 售后微信:q3970260761\n安装、播放有问题都可以找我"
|
||||||
|
textSize = 16f
|
||||||
|
setTextColor(Color.parseColor("#FFC107")) // 橙色醒目
|
||||||
|
gravity = Gravity.CENTER
|
||||||
|
setLineSpacing(0f, 1.3f)
|
||||||
|
setPadding(24, 18, 24, 18)
|
||||||
|
isFocusable = true
|
||||||
|
isFocusableInTouchMode = true
|
||||||
|
background = focusBg(normal = 0xFF2E2510.toInt()) // 橙底,聚焦变蓝
|
||||||
|
setOnClickListener { copyWechat() }
|
||||||
|
}, LinearLayout.LayoutParams(
|
||||||
|
ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT).apply { bottomMargin = 40 })
|
||||||
|
|
||||||
|
// v9.6.1:已移除「撤销本机授权」与「支付成为会员」入口(暂时全面免费,不出现任何收费/授权入口)
|
||||||
|
|
||||||
|
// ===== 其它操作 =====
|
||||||
|
root.addView(TextView(this).apply {
|
||||||
|
text = "其它操作"
|
||||||
textSize = 15f; setTextColor(Color.parseColor("#7AA7D9"))
|
textSize = 15f; setTextColor(Color.parseColor("#7AA7D9"))
|
||||||
setPadding(0, 8, 0, 8)
|
setPadding(0, 8, 0, 8)
|
||||||
})
|
})
|
||||||
val cardInput = EditText(this).apply {
|
// 原菜单键的功能(手动换线),现在放在这里
|
||||||
hint = "请输入卡密"
|
val switchBtn = mkAction("切换线路(当前线路不通时手动换)") {
|
||||||
textSize = 16f
|
try {
|
||||||
setTextColor(Color.WHITE)
|
getSharedPreferences("iptv_main", MODE_PRIVATE).edit()
|
||||||
setHintTextColor(Color.parseColor("#888888"))
|
.putString("pending_action", "switch_line").apply()
|
||||||
setPadding(24, 20, 24, 20)
|
} catch (e: Exception) { }
|
||||||
isSingleLine = true
|
statusText.text = "已请求切换线路,返回主界面后生效"
|
||||||
isFocusable = true
|
android.widget.Toast.makeText(this, "返回主界面后自动切换线路", android.widget.Toast.LENGTH_LONG).show()
|
||||||
isFocusableInTouchMode = true
|
try { finish() } catch (e: Exception) { }
|
||||||
background = focusBg(normal = 0xFF1C2028.toInt())
|
|
||||||
inputType = android.text.InputType.TYPE_CLASS_TEXT
|
|
||||||
}
|
}
|
||||||
root.addView(cardInput, LinearLayout.LayoutParams(
|
root.addView(switchBtn, LinearLayout.LayoutParams(
|
||||||
ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT).apply { bottomMargin = 12 })
|
ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT).apply { bottomMargin = 20 })
|
||||||
|
|
||||||
val actBtn = mkAction("激活") { doActivate(cardInput.text.toString().trim()) }
|
// ★ 诊断标记:证明本页 onCreate 确实跑到了(主界面 1.4 秒后会核对)
|
||||||
root.addView(actBtn, LinearLayout.LayoutParams(
|
try {
|
||||||
ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT).apply { bottomMargin = 40 })
|
getSharedPreferences("iptv_main", MODE_PRIVATE).edit()
|
||||||
|
.putLong("settings_opened_at", System.currentTimeMillis()).apply()
|
||||||
|
} catch (e: Exception) { }
|
||||||
|
}
|
||||||
|
|
||||||
if (isVip) {
|
/** 复制售后微信号(TV 上也会 Toast 出来便于手抄) */
|
||||||
root.addView(TextView(this).apply {
|
private fun copyWechat() {
|
||||||
text = "✓ 已经是会员"
|
val wx = "q3970260761"
|
||||||
textSize = 18f; setTextColor(Color.parseColor("#4CAF50"))
|
try {
|
||||||
gravity = Gravity.CENTER; setPadding(0, 24, 0, 24)
|
val cm = getSystemService(android.content.Context.CLIPBOARD_SERVICE) as android.content.ClipboardManager
|
||||||
})
|
cm.setPrimaryClip(android.content.ClipData.newPlainText("wechat", wx))
|
||||||
} else {
|
android.widget.Toast.makeText(this, "微信号已复制:$wx", android.widget.Toast.LENGTH_SHORT).show()
|
||||||
val btn = mkAction("支付成为会员(月/季/年)") {
|
} catch (e: Exception) {
|
||||||
startActivity(Intent(this@SettingsActivity, ShopActivity::class.java))
|
android.widget.Toast.makeText(this, "售后微信:$wx", android.widget.Toast.LENGTH_SHORT).show()
|
||||||
}
|
}
|
||||||
root.addView(btn, LinearLayout.LayoutParams(
|
|
||||||
ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT))
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** 撤销本机授权:清除本地授权信息 → 恢复免费模式,可重新输入卡密或换机 */
|
||||||
|
private fun doRevoke() {
|
||||||
|
try {
|
||||||
|
getSharedPreferences("iptv_license", MODE_PRIVATE).edit()
|
||||||
|
.putBoolean("is_vip", false)
|
||||||
|
.putString("card_key", "")
|
||||||
|
.putString("vip_expire", "")
|
||||||
|
.putBoolean("is_permanent", false)
|
||||||
|
.remove("token")
|
||||||
|
.apply()
|
||||||
|
} catch (e: Exception) { }
|
||||||
|
statusText.text = "✓ 已撤销本机授权\n当前为免费用户(每天 1 小时)\n可在下方重新输入卡密激活"
|
||||||
|
android.widget.Toast.makeText(this, "已撤销授权,可重新激活", android.widget.Toast.LENGTH_LONG).show()
|
||||||
|
// 重开本页以刷新界面状态(会员按钮 ↔ 支付按钮)
|
||||||
|
try {
|
||||||
|
startActivity(Intent(this@SettingsActivity, SettingsActivity::class.java))
|
||||||
|
finish()
|
||||||
|
} catch (e: Exception) { }
|
||||||
}
|
}
|
||||||
|
|
||||||
/** 输入卡密激活 */
|
/** 输入卡密激活 */
|
||||||
@@ -235,7 +262,7 @@ class SettingsActivity : Activity() {
|
|||||||
statusText.text = if (r.ok) {
|
statusText.text = if (r.ok) {
|
||||||
"✓ 激活成功!\n${if (r.isPermanent) "永久有效" else "有效期至:${r.expireTime}"}\n卡号:$key"
|
"✓ 激活成功!\n${if (r.isPermanent) "永久有效" else "有效期至:${r.expireTime}"}\n卡号:$key"
|
||||||
} else {
|
} else {
|
||||||
"✗ 激活失败:${r.message}\n请检查卡密是否正确 / 是否已被使用"
|
"✗ 激活失败:${r.message}\n请检查卡密是否正确 / 是否已被使用\n\n售后微信:q3970260761(可点下方橙色条复制)"
|
||||||
}
|
}
|
||||||
android.widget.Toast.makeText(this@SettingsActivity,
|
android.widget.Toast.makeText(this@SettingsActivity,
|
||||||
if (r.ok) "激活成功" else "激活失败:${r.message}",
|
if (r.ok) "激活成功" else "激活失败:${r.message}",
|
||||||
|
|||||||
@@ -48,16 +48,40 @@ class TrialExpiredActivity : Activity() {
|
|||||||
gravity = android.view.Gravity.CENTER; setPadding(0, 0, 0, 56)
|
gravity = android.view.Gravity.CENTER; setPadding(0, 0, 0, 56)
|
||||||
})
|
})
|
||||||
|
|
||||||
root.addView(Button(this).apply {
|
// ★ 可聚焦按钮 + 遥控器高亮(原来 Button 无人聚焦,遥控器按 OK 没反应)
|
||||||
text = "购买套餐(OK键)"
|
fun focusableBtn(label: String, size: Float, onClick: () -> Unit) =
|
||||||
textSize = 19f
|
Button(this).apply {
|
||||||
setOnClickListener { startActivity(android.content.Intent(this@TrialExpiredActivity, ShopActivity::class.java)); finish() }
|
text = label; textSize = size
|
||||||
})
|
isFocusable = true; isFocusableInTouchMode = true
|
||||||
|
setTextColor(0xFFFFFFFFu.toInt())
|
||||||
|
background = android.graphics.drawable.StateListDrawable().apply {
|
||||||
|
addState(intArrayOf(android.R.attr.state_focused),
|
||||||
|
android.graphics.drawable.ColorDrawable(0xFF1B6EF3.toInt()))
|
||||||
|
addState(intArrayOf(),
|
||||||
|
android.graphics.drawable.ColorDrawable(0xFF2A2F3A.toInt()))
|
||||||
|
}
|
||||||
|
setPadding(48, 26, 48, 26)
|
||||||
|
setOnClickListener { onClick() }
|
||||||
|
}
|
||||||
|
|
||||||
|
val buyBtn = focusableBtn("购买套餐(OK 键)", 19f) {
|
||||||
|
try {
|
||||||
|
startActivity(android.content.Intent(this@TrialExpiredActivity, ShopActivity::class.java))
|
||||||
|
} catch (e: Exception) { }
|
||||||
|
finish()
|
||||||
|
}
|
||||||
|
root.addView(buyBtn, LinearLayout.LayoutParams(
|
||||||
|
ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT).apply { bottomMargin = 20 })
|
||||||
|
|
||||||
|
// ★ 新增:明确的关闭入口(原来只能靠按 BACK,而 BACK 走的是系统默认)
|
||||||
|
val closeBtn = focusableBtn("关闭(返回键也可以)", 17f) { finish() }
|
||||||
|
root.addView(closeBtn, LinearLayout.LayoutParams(
|
||||||
|
ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT).apply { bottomMargin = 8 })
|
||||||
|
|
||||||
root.addView(TextView(this).apply {
|
root.addView(TextView(this).apply {
|
||||||
text = "或直接访问:http://app.88531.cn:8881/#/shop"
|
text = "或直接访问:http://app.88531.cn:8881/#/shop"
|
||||||
textSize = 13f; setTextColor(0xFF888888u.toInt())
|
textSize = 13f; setTextColor(0xFF888888u.toInt())
|
||||||
gravity = android.view.Gravity.CENTER; setPadding(0, 32, 0, 0)
|
gravity = android.view.Gravity.CENTER; setPadding(0, 28, 0, 0)
|
||||||
})
|
})
|
||||||
|
|
||||||
root.addView(TextView(this).apply {
|
root.addView(TextView(this).apply {
|
||||||
@@ -65,6 +89,15 @@ class TrialExpiredActivity : Activity() {
|
|||||||
textSize = 14f; setTextColor(0xFF7799AAu.toInt())
|
textSize = 14f; setTextColor(0xFF7799AAu.toInt())
|
||||||
gravity = android.view.Gravity.CENTER; setPadding(0, 24, 0, 0)
|
gravity = android.view.Gravity.CENTER; setPadding(0, 24, 0, 0)
|
||||||
})
|
})
|
||||||
|
|
||||||
|
// 默认聚焦「购买套餐」,遥控器 OK 直接可按;左右/上下在两个按钮间切换
|
||||||
|
buyBtn.post { buyBtn.requestFocus() }
|
||||||
|
}
|
||||||
|
|
||||||
|
/** ★ 返回键显式处理(原来没有,走系统默认,用户不知道能关) */
|
||||||
|
override fun onKeyDown(keyCode: Int, event: android.view.KeyEvent?): Boolean {
|
||||||
|
if (keyCode == android.view.KeyEvent.KEYCODE_BACK) { finish(); return true }
|
||||||
|
return super.onKeyDown(keyCode, event)
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun openShop() {
|
private fun openShop() {
|
||||||
|
|||||||
|
Before Width: | Height: | Size: 80 KiB After Width: | Height: | Size: 28 KiB |
|
Before Width: | Height: | Size: 6.3 KiB After Width: | Height: | Size: 4.3 KiB |
|
Before Width: | Height: | Size: 3.5 KiB After Width: | Height: | Size: 2.5 KiB |
|
Before Width: | Height: | Size: 9.7 KiB After Width: | Height: | Size: 6.3 KiB |
|
Before Width: | Height: | Size: 18 KiB After Width: | Height: | Size: 11 KiB |
|
Before Width: | Height: | Size: 28 KiB After Width: | Height: | Size: 15 KiB |
|
Before Width: | Height: | Size: 52 KiB After Width: | Height: | Size: 41 KiB |
|
Before Width: | Height: | Size: 79 KiB After Width: | Height: | Size: 33 KiB |
|
Before Width: | Height: | Size: 52 KiB After Width: | Height: | Size: 33 KiB |
|
Before Width: | Height: | Size: 79 KiB After Width: | Height: | Size: 33 KiB |