v8.4.0 设置页支持输入卡密激活;返回播放页即时生效

This commit is contained in:
Hermes Agent committed 2026-10-08 13:01:50 +08:00
1 parent 1d2449ec44
commit e1cc0b6bbd
3 files changed
+72 -2

No files matched your search

+2 -2
View File
@@ -11,8 +11,8 @@ android {
applicationId = "com.iptv807.tv" applicationId = "com.iptv807.tv"
minSdk = 21 minSdk = 21
targetSdk = 35 targetSdk = 35
versionCode = 830 versionCode = 840
versionName = "8.3.0" versionName = "8.4.0"
} }
buildTypes { buildTypes {
@@ -684,6 +684,17 @@ class MainActivity : Activity() {
override fun onResume() { override fun onResume() {
super.onResume() super.onResume()
// 从设置页输入卡密激活后,回来立即生效
run {
val prefs = getSharedPreferences("iptv_license", MODE_PRIVATE)
val nowVip = prefs.getBoolean("is_vip", false)
val card = prefs.getString("card_key", "") ?: ""
if (nowVip && (card.isNotEmpty() || !isVip)) {
isVip = true
trialText.visibility = View.GONE
handler.removeCallbacks(uiTick)
}
}
// 从桌面/设置返回:先尝试续播,失败则显示「继续播放」按钮 // 从桌面/设置返回:先尝试续播,失败则显示「继续播放」按钮
if (wasStopped) { if (wasStopped) {
wasStopped = false wasStopped = false
@@ -12,6 +12,7 @@ import android.view.KeyEvent
import android.view.View import android.view.View
import android.view.ViewGroup import android.view.ViewGroup
import android.widget.Button import android.widget.Button
import android.widget.EditText
import android.widget.LinearLayout import android.widget.LinearLayout
import android.widget.Switch import android.widget.Switch
import android.widget.TextView import android.widget.TextView
@@ -123,6 +124,34 @@ class SettingsActivity : Activity() {
ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT).apply { bottomMargin = 24 }) ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT).apply { bottomMargin = 24 })
// ===== 卡密激活 =====
root.addView(TextView(this).apply {
text = "卡密激活"
textSize = 15f; setTextColor(Color.parseColor("#7AA7D9"))
setPadding(0, 8, 0, 8)
})
val cardInput = EditText(this).apply {
hint = "请输入卡密"
textSize = 16f
setTextColor(Color.WHITE)
setHintTextColor(Color.parseColor("#888888"))
setBackgroundColor(Color.parseColor("#1C2028"))
setPadding(24, 20, 24, 20)
isSingleLine = true
inputType = android.text.InputType.TYPE_CLASS_TEXT
}
root.addView(cardInput, LinearLayout.LayoutParams(
ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT).apply { bottomMargin = 12 })
val actBtn = Button(this).apply {
text = "激活"
textSize = 17f
setBackgroundColor(Color.parseColor("#1B6EF3"))
setOnClickListener { doActivate(cardInput.text.toString().trim()) }
}
root.addView(actBtn, LinearLayout.LayoutParams(
ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT).apply { bottomMargin = 40 })
if (isVip) { if (isVip) {
root.addView(TextView(this).apply { root.addView(TextView(this).apply {
text = "✓ 已经是会员" text = "✓ 已经是会员"
@@ -141,6 +170,36 @@ class SettingsActivity : Activity() {
} }
} }
/** 输入卡密激活 */
private fun doActivate(key: String) {
if (key.isEmpty()) { statusText.text = "请先输入卡密"; return }
statusText.text = "正在验证卡密…"
Thread {
val r = try {
LicenseClient.verify(key, LicenseClient.machineCode(this))
} catch (e: Exception) {
LicenseClient.Result(false, "网络错误: ${e.javaClass.simpleName}")
}
runOnUiThread {
val prefs = getSharedPreferences("iptv_license", MODE_PRIVATE)
prefs.edit()
.putBoolean("is_vip", r.ok)
.putString("card_key", if (r.ok) key else "")
.putString("vip_expire", r.expireTime)
.putBoolean("is_permanent", r.isPermanent)
.apply()
statusText.text = if (r.ok) {
"✓ 激活成功!\n${if (r.isPermanent) "永久有效" else "有效期至:${r.expireTime}"}\n卡号:$key"
} else {
"✗ 激活失败:${r.message}\n请检查卡密是否正确 / 是否已被使用"
}
android.widget.Toast.makeText(this@SettingsActivity,
if (r.ok) "激活成功" else "激活失败:${r.message}",
android.widget.Toast.LENGTH_LONG).show()
}
}.start()
}
private fun isBootReceiverEnabled(): Boolean = private fun isBootReceiverEnabled(): Boolean =
packageManager.getComponentEnabledSetting(ComponentName(this, BootReceiver::class.java)) == packageManager.getComponentEnabledSetting(ComponentName(this, BootReceiver::class.java)) ==
PackageManager.COMPONENT_ENABLED_STATE_ENABLED PackageManager.COMPONENT_ENABLED_STATE_ENABLED