mirror of
https://github.com/lizongying/my-tv.git
synced 2026-11-08 20:46:31 +08:00
Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
9450de2c91 | ||
|
|
d03de91c1e | ||
|
|
7057e4a8b4 | ||
|
|
188431a29f | ||
|
|
5c0152e36c | ||
|
|
a63463559f |
@@ -20,6 +20,11 @@
|
|||||||
* 凤凰卫视增强画质
|
* 凤凰卫视增强画质
|
||||||
* 凤凰卫视增加EPG
|
* 凤凰卫视增加EPG
|
||||||
|
|
||||||
|
### v1.6.5(安卓5及以上专用)
|
||||||
|
|
||||||
|
* 增加CETV1图标
|
||||||
|
* 稳定性提升
|
||||||
|
|
||||||
### v1.6.4(通用)
|
### v1.6.4(通用)
|
||||||
|
|
||||||
* 增加CETV1
|
* 增加CETV1
|
||||||
@@ -230,6 +235,7 @@ adb install my-tv.apk
|
|||||||
* 节目增加预告
|
* 节目增加预告
|
||||||
* 频道列表优化
|
* 频道列表优化
|
||||||
* epg更新后菜单更新
|
* epg更新后菜单更新
|
||||||
|
* 防止菜单第一个获取焦点
|
||||||
|
|
||||||
## 赞赏
|
## 赞赏
|
||||||
|
|
||||||
|
|||||||
+1
-1
@@ -81,7 +81,7 @@ static def VersionCode() {
|
|||||||
|
|
||||||
static def VersionName() {
|
static def VersionName() {
|
||||||
try {
|
try {
|
||||||
def process = 'git describe --tags --always'.execute()
|
def process = "git describe --tags --always | sed 's/v/ /g' | sed 's/\\./ /g' | sed 's/-/ /g' | awk '{print \$1*16777216+\$2*65536+\$3*256+\$4}'".execute()
|
||||||
process.waitFor()
|
process.waitFor()
|
||||||
return process.text.trim() - "v"
|
return process.text.trim() - "v"
|
||||||
} catch (ignored) {
|
} catch (ignored) {
|
||||||
|
|||||||
Binary file not shown.
Binary file not shown.
@@ -7,8 +7,8 @@ import android.view.View
|
|||||||
import android.view.ViewGroup
|
import android.view.ViewGroup
|
||||||
import android.view.animation.ScaleAnimation
|
import android.view.animation.ScaleAnimation
|
||||||
import android.widget.ImageView
|
import android.widget.ImageView
|
||||||
|
import androidx.core.view.updatePadding
|
||||||
import androidx.leanback.widget.ImageCardView
|
import androidx.leanback.widget.ImageCardView
|
||||||
import androidx.lifecycle.LifecycleOwner
|
|
||||||
import androidx.recyclerview.widget.RecyclerView
|
import androidx.recyclerview.widget.RecyclerView
|
||||||
import com.bumptech.glide.Glide
|
import com.bumptech.glide.Glide
|
||||||
import com.lizongying.mytv.models.TVListViewModel
|
import com.lizongying.mytv.models.TVListViewModel
|
||||||
@@ -17,21 +17,22 @@ import com.lizongying.mytv.models.TVViewModel
|
|||||||
|
|
||||||
class CardAdapter(
|
class CardAdapter(
|
||||||
private val recyclerView: RecyclerView,
|
private val recyclerView: RecyclerView,
|
||||||
private val owner: LifecycleOwner,
|
private val mainFragment: MainFragment,
|
||||||
private var tvListViewModel: TVListViewModel,
|
private var tvListViewModel: TVListViewModel,
|
||||||
) :
|
) :
|
||||||
RecyclerView.Adapter<CardAdapter.ViewHolder>() {
|
RecyclerView.Adapter<CardAdapter.ViewHolder>() {
|
||||||
|
|
||||||
private var listener: ItemListener? = null
|
private var listener: ItemListener? = null
|
||||||
private var focused: View? = null
|
private var focused: View? = null
|
||||||
private var defaultFocused = false
|
|
||||||
var defaultFocus: Int = -1
|
var visiable = false
|
||||||
|
|
||||||
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ViewHolder {
|
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ViewHolder {
|
||||||
val cardView = object :
|
val cardView = object :
|
||||||
ImageCardView(ContextThemeWrapper(parent.context, R.style.CustomImageCardTheme)) {}
|
ImageCardView(ContextThemeWrapper(parent.context, R.style.CustomImageCardTheme)) {}
|
||||||
cardView.isFocusable = true
|
cardView.isFocusable = true
|
||||||
cardView.isFocusableInTouchMode = true
|
cardView.isFocusableInTouchMode = true
|
||||||
|
cardView.updatePadding(1, 1, 1, 1)
|
||||||
return ViewHolder(cardView)
|
return ViewHolder(cardView)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -57,19 +58,23 @@ class CardAdapter(
|
|||||||
|
|
||||||
val tvViewModel = item as TVViewModel
|
val tvViewModel = item as TVViewModel
|
||||||
val cardView = viewHolder.view as ImageCardView
|
val cardView = viewHolder.view as ImageCardView
|
||||||
|
cardView.tag = tvViewModel
|
||||||
|
|
||||||
if (!defaultFocused && item.id.value == defaultFocus) {
|
val onFocusChangeListener = View.OnFocusChangeListener { view, hasFocus ->
|
||||||
cardView.requestFocus()
|
|
||||||
defaultFocused = true
|
|
||||||
}
|
|
||||||
|
|
||||||
val onFocusChangeListener = View.OnFocusChangeListener { _, hasFocus ->
|
|
||||||
listener?.onItemFocusChange(item, hasFocus)
|
|
||||||
|
|
||||||
// if (hasFocus && defaultFocus == item.id.value) {
|
|
||||||
if (hasFocus) {
|
if (hasFocus) {
|
||||||
|
listener?.onItemHasFocus(item)
|
||||||
focused = cardView
|
focused = cardView
|
||||||
|
|
||||||
startScaleAnimation(cardView, 0.9f, 1.0f, 200)
|
startScaleAnimation(cardView, 0.9f, 1.0f, 200)
|
||||||
|
//
|
||||||
|
// if (mainFragment.shouldHasFocus(view.tag as TVViewModel)) {
|
||||||
|
// }
|
||||||
|
|
||||||
|
// if (visiable) {
|
||||||
|
// startScaleAnimation(cardView, 0.9f, 1.0f, 200)
|
||||||
|
// } else {
|
||||||
|
// visiable = true
|
||||||
|
// }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -110,8 +115,16 @@ class CardAdapter(
|
|||||||
val view = itemView
|
val view = itemView
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fun toPosition(position: Int) {
|
||||||
|
recyclerView.post {
|
||||||
|
recyclerView.scrollToPosition(position)
|
||||||
|
recyclerView.getChildAt(position)?.isSelected
|
||||||
|
recyclerView.getChildAt(position)?.requestFocus()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
interface ItemListener {
|
interface ItemListener {
|
||||||
fun onItemFocusChange(tvViewModel: TVViewModel, hasFocus: Boolean)
|
fun onItemHasFocus(tvViewModel: TVViewModel)
|
||||||
fun onItemClicked(tvViewModel: TVViewModel)
|
fun onItemClicked(tvViewModel: TVViewModel)
|
||||||
fun onKey(keyCode: Int): Boolean
|
fun onKey(keyCode: Int): Boolean
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,84 @@
|
|||||||
|
@file:Suppress("DEPRECATION")
|
||||||
|
|
||||||
|
package com.lizongying.mytv
|
||||||
|
|
||||||
|
import android.content.Context
|
||||||
|
import android.content.pm.PackageInfo
|
||||||
|
import android.content.pm.PackageManager
|
||||||
|
import android.content.pm.Signature
|
||||||
|
import android.content.pm.SigningInfo
|
||||||
|
import android.os.Build
|
||||||
|
import android.util.Log
|
||||||
|
import java.security.MessageDigest
|
||||||
|
|
||||||
|
private const val TAG = "Extensions"
|
||||||
|
|
||||||
|
private val Context.packageInfo: PackageInfo
|
||||||
|
get() {
|
||||||
|
val flag = if (Build.VERSION.SDK_INT < Build.VERSION_CODES.P) {
|
||||||
|
PackageManager.GET_SIGNATURES
|
||||||
|
} else {
|
||||||
|
PackageManager.GET_SIGNING_CERTIFICATES
|
||||||
|
}
|
||||||
|
return if (Build.VERSION.SDK_INT < Build.VERSION_CODES.TIRAMISU) {
|
||||||
|
packageManager.getPackageInfo(packageName, flag)
|
||||||
|
} else {
|
||||||
|
packageManager.getPackageInfo(
|
||||||
|
packageName,
|
||||||
|
PackageManager.PackageInfoFlags.of(PackageManager.GET_SIGNING_CERTIFICATES.toLong())
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Return the version code of the app which is defined in build.gradle.
|
||||||
|
* eg:100
|
||||||
|
*/
|
||||||
|
val Context.appVersionCode: Long
|
||||||
|
get() {
|
||||||
|
val packageInfo = this.packageInfo
|
||||||
|
return if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) {
|
||||||
|
packageInfo.longVersionCode
|
||||||
|
} else {
|
||||||
|
packageInfo.versionCode.toLong()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Return the version name of the app which is defined in build.gradle.
|
||||||
|
* eg:1.0.0
|
||||||
|
*/
|
||||||
|
val Context.appVersionName: String get() = packageInfo.versionName ?: ""
|
||||||
|
|
||||||
|
val Context.appSignature: String
|
||||||
|
get() {
|
||||||
|
val packageInfo = this.packageInfo
|
||||||
|
var sign: Signature? = null
|
||||||
|
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.P) {
|
||||||
|
val signatures: Array<out Signature>? = packageInfo.signatures
|
||||||
|
if (signatures != null) {
|
||||||
|
sign = signatures[0]
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
val signingInfo: SigningInfo? = packageInfo.signingInfo
|
||||||
|
if (signingInfo != null) {
|
||||||
|
sign = signingInfo.apkContentsSigners[0]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (sign == null) {
|
||||||
|
return ""
|
||||||
|
}
|
||||||
|
return hashSignature(sign)
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun hashSignature(signature: Signature): String {
|
||||||
|
return try {
|
||||||
|
val md = MessageDigest.getInstance("MD5")
|
||||||
|
md.update(signature.toByteArray())
|
||||||
|
val digest = md.digest()
|
||||||
|
digest.let { it -> it.joinToString("") { "%02x".format(it) } }
|
||||||
|
} catch (e: Exception) {
|
||||||
|
Log.e(TAG, "Error hashing signature", e)
|
||||||
|
""
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -6,6 +6,7 @@ import android.graphics.Paint
|
|||||||
import android.graphics.Rect
|
import android.graphics.Rect
|
||||||
import android.view.View
|
import android.view.View
|
||||||
import androidx.core.content.ContextCompat
|
import androidx.core.content.ContextCompat
|
||||||
|
import androidx.leanback.widget.ImageCardView
|
||||||
import androidx.recyclerview.widget.RecyclerView
|
import androidx.recyclerview.widget.RecyclerView
|
||||||
|
|
||||||
class GrayOverlayItemDecoration(private val context: Context) : RecyclerView.ItemDecoration() {
|
class GrayOverlayItemDecoration(private val context: Context) : RecyclerView.ItemDecoration() {
|
||||||
@@ -22,17 +23,19 @@ class GrayOverlayItemDecoration(private val context: Context) : RecyclerView.Ite
|
|||||||
for (i in 0 until childCount) {
|
for (i in 0 until childCount) {
|
||||||
val child = parent.getChildAt(i)
|
val child = parent.getChildAt(i)
|
||||||
if (!child.hasFocus()) {
|
if (!child.hasFocus()) {
|
||||||
// child.alpha = 0.7f
|
(child as ImageCardView).setInfoAreaBackgroundColor(ContextCompat.getColor(context, R.color.blur))
|
||||||
|
// child.alpha = 0.5f
|
||||||
// 计算遮罩层的大小
|
// 计算遮罩层的大小
|
||||||
val overlayRect = Rect(
|
// val overlayRect = Rect(
|
||||||
child.left,
|
// child.left,
|
||||||
child.top,
|
// child.top,
|
||||||
child.right,
|
// child.right,
|
||||||
child.bottom
|
// child.bottom
|
||||||
)
|
// )
|
||||||
// 绘制灰色遮罩层
|
// // 绘制灰色遮罩层
|
||||||
c.drawRect(overlayRect, grayOverlayPaint)
|
// c.drawRect(overlayRect, grayOverlayPaint)
|
||||||
} else {
|
} else {
|
||||||
|
(child as ImageCardView).setInfoAreaBackgroundColor(ContextCompat.getColor(context, R.color.focus))
|
||||||
// child.alpha = 1f
|
// child.alpha = 1f
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,10 +1,5 @@
|
|||||||
package com.lizongying.mytv
|
package com.lizongying.mytv
|
||||||
|
|
||||||
import android.content.pm.PackageInfo
|
|
||||||
import android.content.pm.PackageManager
|
|
||||||
import android.content.pm.Signature
|
|
||||||
import android.content.pm.SigningInfo
|
|
||||||
import android.os.Build
|
|
||||||
import android.os.Bundle
|
import android.os.Bundle
|
||||||
import android.os.Handler
|
import android.os.Handler
|
||||||
import android.os.Looper
|
import android.os.Looper
|
||||||
@@ -16,23 +11,17 @@ import android.view.View.SYSTEM_UI_FLAG_HIDE_NAVIGATION
|
|||||||
import android.view.WindowManager
|
import android.view.WindowManager
|
||||||
import android.widget.Toast
|
import android.widget.Toast
|
||||||
import androidx.fragment.app.FragmentActivity
|
import androidx.fragment.app.FragmentActivity
|
||||||
import androidx.lifecycle.lifecycleScope
|
|
||||||
import com.lizongying.mytv.models.TVViewModel
|
import com.lizongying.mytv.models.TVViewModel
|
||||||
import kotlinx.coroutines.CoroutineStart
|
|
||||||
import kotlinx.coroutines.Dispatchers
|
|
||||||
import kotlinx.coroutines.async
|
|
||||||
import kotlinx.coroutines.launch
|
|
||||||
import java.security.MessageDigest
|
|
||||||
|
|
||||||
|
|
||||||
class MainActivity : FragmentActivity(), Request.RequestListener {
|
class MainActivity : FragmentActivity(), Request.RequestListener {
|
||||||
|
|
||||||
private var ready = 0
|
private var ready = 0
|
||||||
private var playerFragment = PlayerFragment()
|
private val playerFragment = PlayerFragment()
|
||||||
private var mainFragment = MainFragment()
|
private val mainFragment = MainFragment()
|
||||||
private var infoFragment = InfoFragment()
|
private val infoFragment = InfoFragment()
|
||||||
private var channelFragment = ChannelFragment()
|
private val channelFragment = ChannelFragment()
|
||||||
private lateinit var settingFragment: SettingFragment
|
private val settingFragment = SettingFragment()
|
||||||
|
|
||||||
private var doubleBackToExitPressedOnce = false
|
private var doubleBackToExitPressedOnce = false
|
||||||
|
|
||||||
@@ -64,20 +53,6 @@ class MainActivity : FragmentActivity(), Request.RequestListener {
|
|||||||
.commit()
|
.commit()
|
||||||
}
|
}
|
||||||
gestureDetector = GestureDetector(this, GestureListener())
|
gestureDetector = GestureDetector(this, GestureListener())
|
||||||
val packageInfo = getPackageInfo()
|
|
||||||
val versionName = packageInfo.versionName
|
|
||||||
val versionCode = if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) {
|
|
||||||
packageInfo.longVersionCode
|
|
||||||
} else {
|
|
||||||
packageInfo.versionCode.toLong()
|
|
||||||
}
|
|
||||||
settingFragment = SettingFragment(
|
|
||||||
versionName,
|
|
||||||
versionCode,
|
|
||||||
SP.channelReversal,
|
|
||||||
SP.channelNum,
|
|
||||||
SP.bootStartup
|
|
||||||
)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fun showInfoFragment(tvViewModel: TVViewModel) {
|
fun showInfoFragment(tvViewModel: TVViewModel) {
|
||||||
@@ -448,56 +423,7 @@ class MainActivity : FragmentActivity(), Request.RequestListener {
|
|||||||
return super.onKeyDown(keyCode, event)
|
return super.onKeyDown(keyCode, event)
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun getPackageInfo(): PackageInfo {
|
private fun getAppSignature() = this.appSignature
|
||||||
val flag = if (Build.VERSION.SDK_INT < Build.VERSION_CODES.P) {
|
|
||||||
PackageManager.GET_SIGNATURES
|
|
||||||
} else {
|
|
||||||
PackageManager.GET_SIGNING_CERTIFICATES
|
|
||||||
}
|
|
||||||
|
|
||||||
return if (Build.VERSION.SDK_INT < Build.VERSION_CODES.TIRAMISU) {
|
|
||||||
packageManager.getPackageInfo(packageName, flag)
|
|
||||||
} else {
|
|
||||||
packageManager.getPackageInfo(
|
|
||||||
packageName,
|
|
||||||
PackageManager.PackageInfoFlags.of(PackageManager.GET_SIGNING_CERTIFICATES.toLong())
|
|
||||||
)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private fun getAppSignature(): String {
|
|
||||||
val packageInfo = getPackageInfo()
|
|
||||||
|
|
||||||
var sign: Signature? = null
|
|
||||||
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.P) {
|
|
||||||
val signatures: Array<out Signature>? = packageInfo.signatures
|
|
||||||
if (signatures != null) {
|
|
||||||
sign = signatures[0]
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
val signingInfo: SigningInfo? = packageInfo.signingInfo
|
|
||||||
if (signingInfo != null) {
|
|
||||||
sign = signingInfo.apkContentsSigners[0]
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (sign == null) {
|
|
||||||
return ""
|
|
||||||
}
|
|
||||||
|
|
||||||
return hashSignature(sign)
|
|
||||||
}
|
|
||||||
|
|
||||||
private fun hashSignature(signature: Signature): String {
|
|
||||||
return try {
|
|
||||||
val md = MessageDigest.getInstance("MD5")
|
|
||||||
md.update(signature.toByteArray())
|
|
||||||
val digest = md.digest()
|
|
||||||
digest.let { it -> it.joinToString("") { "%02x".format(it) } }
|
|
||||||
} catch (e: Exception) {
|
|
||||||
Log.e(TAG, "Error hashing signature", e)
|
|
||||||
""
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun onStart() {
|
override fun onStart() {
|
||||||
Log.i(TAG, "onStart")
|
Log.i(TAG, "onStart")
|
||||||
|
|||||||
@@ -10,6 +10,7 @@ import android.widget.Toast
|
|||||||
import androidx.fragment.app.Fragment
|
import androidx.fragment.app.Fragment
|
||||||
import androidx.lifecycle.lifecycleScope
|
import androidx.lifecycle.lifecycleScope
|
||||||
import androidx.recyclerview.widget.GridLayoutManager
|
import androidx.recyclerview.widget.GridLayoutManager
|
||||||
|
import androidx.recyclerview.widget.LinearLayoutManager
|
||||||
import androidx.recyclerview.widget.RecyclerView
|
import androidx.recyclerview.widget.RecyclerView
|
||||||
import com.lizongying.mytv.Utils.dpToPx
|
import com.lizongying.mytv.Utils.dpToPx
|
||||||
import com.lizongying.mytv.api.YSP
|
import com.lizongying.mytv.api.YSP
|
||||||
@@ -72,7 +73,7 @@ class MainFragment : Fragment(), CardAdapter.ItemListener {
|
|||||||
val adapter =
|
val adapter =
|
||||||
CardAdapter(
|
CardAdapter(
|
||||||
itemBinding.rowItems,
|
itemBinding.rowItems,
|
||||||
viewLifecycleOwner,
|
this,
|
||||||
tvListViewModelCurrent,
|
tvListViewModelCurrent,
|
||||||
)
|
)
|
||||||
rowList.add(itemBinding.rowItems)
|
rowList.add(itemBinding.rowItems)
|
||||||
@@ -82,10 +83,6 @@ class MainFragment : Fragment(), CardAdapter.ItemListener {
|
|||||||
itemBinding.rowHeader.text = k
|
itemBinding.rowHeader.text = k
|
||||||
itemBinding.rowItems.tag = idx.toInt()
|
itemBinding.rowItems.tag = idx.toInt()
|
||||||
itemBinding.rowItems.adapter = adapter
|
itemBinding.rowItems.adapter = adapter
|
||||||
itemBinding.rowItems.layoutManager =
|
|
||||||
GridLayoutManager(context, 6)
|
|
||||||
itemBinding.rowItems.layoutParams.height =
|
|
||||||
dpToPx(92 * ((tvListViewModelCurrent.size() + 6 - 1) / 6))
|
|
||||||
|
|
||||||
itemBinding.rowItems.addOnScrollListener(object : RecyclerView.OnScrollListener() {
|
itemBinding.rowItems.addOnScrollListener(object : RecyclerView.OnScrollListener() {
|
||||||
override fun onScrolled(recyclerView: RecyclerView, dx: Int, dy: Int) {
|
override fun onScrolled(recyclerView: RecyclerView, dx: Int, dy: Int) {
|
||||||
@@ -99,6 +96,16 @@ class MainFragment : Fragment(), CardAdapter.ItemListener {
|
|||||||
itemBinding.rowItems.addItemDecoration(itemDecoration)
|
itemBinding.rowItems.addItemDecoration(itemDecoration)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (SP.grid) {
|
||||||
|
itemBinding.rowItems.layoutManager =
|
||||||
|
GridLayoutManager(context, 6)
|
||||||
|
itemBinding.rowItems.layoutParams.height =
|
||||||
|
dpToPx(92 * ((tvListViewModelCurrent.size() + 6 - 1) / 6))
|
||||||
|
} else {
|
||||||
|
itemBinding.rowItems.layoutManager =
|
||||||
|
LinearLayoutManager(context, LinearLayoutManager.HORIZONTAL, false)
|
||||||
|
}
|
||||||
|
|
||||||
val layoutParams = itemBinding.row.layoutParams as ViewGroup.MarginLayoutParams
|
val layoutParams = itemBinding.row.layoutParams as ViewGroup.MarginLayoutParams
|
||||||
layoutParams.topMargin = dpToPx(11F)
|
layoutParams.topMargin = dpToPx(11F)
|
||||||
itemBinding.row.layoutParams = layoutParams
|
itemBinding.row.layoutParams = layoutParams
|
||||||
@@ -111,14 +118,6 @@ class MainFragment : Fragment(), CardAdapter.ItemListener {
|
|||||||
itemPosition = 0
|
itemPosition = 0
|
||||||
}
|
}
|
||||||
|
|
||||||
val tv = tvListViewModel.getTVViewModel(itemPosition)
|
|
||||||
for (i in rowList) {
|
|
||||||
if (i.tag as Int == tv?.getRowPosition()) {
|
|
||||||
((i as RecyclerView).adapter as CardAdapter).defaultFocus = itemPosition
|
|
||||||
break
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
tvListViewModel.setItemPosition(itemPosition)
|
tvListViewModel.setItemPosition(itemPosition)
|
||||||
tvListViewModel.tvListViewModel.value?.forEach { tvViewModel ->
|
tvListViewModel.tvListViewModel.value?.forEach { tvViewModel ->
|
||||||
tvViewModel.errInfo.observe(viewLifecycleOwner) { _ ->
|
tvViewModel.errInfo.observe(viewLifecycleOwner) { _ ->
|
||||||
@@ -191,20 +190,18 @@ class MainFragment : Fragment(), CardAdapter.ItemListener {
|
|||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onItemFocusChange(tvViewModel: TVViewModel, hasFocus: Boolean) {
|
override fun onItemHasFocus(tvViewModel: TVViewModel) {
|
||||||
if (hasFocus) {
|
tvListViewModel.setItemPositionCurrent(tvViewModel.id.value!!)
|
||||||
tvListViewModel.setItemPositionCurrent(tvViewModel.id.value!!)
|
|
||||||
|
|
||||||
val row = tvViewModel.getRowPosition()
|
val row = tvViewModel.getRowPosition()
|
||||||
|
|
||||||
for (i in rowList) {
|
for (i in rowList) {
|
||||||
if (i.tag as Int != row) {
|
if (i.tag as Int != row) {
|
||||||
((i as RecyclerView).adapter as CardAdapter).clear()
|
((i as RecyclerView).adapter as CardAdapter).clear()
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
(activity as MainActivity).mainActive()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
(activity as MainActivity).mainActive()
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onItemClicked(tvViewModel: TVViewModel) {
|
override fun onItemClicked(tvViewModel: TVViewModel) {
|
||||||
@@ -224,21 +221,27 @@ class MainFragment : Fragment(), CardAdapter.ItemListener {
|
|||||||
|
|
||||||
fun setPosition() {
|
fun setPosition() {
|
||||||
val tvViewModel = tvListViewModel.getTVViewModel(itemPosition)
|
val tvViewModel = tvListViewModel.getTVViewModel(itemPosition)
|
||||||
rowList[tvViewModel!!.getRowPosition()].post {
|
val rowPosition = tvViewModel!!.getRowPosition()
|
||||||
((rowList[tvViewModel.getRowPosition()] as RecyclerView).layoutManager as GridLayoutManager).findViewByPosition(
|
val itemPosition = tvViewModel.getItemPosition()
|
||||||
tvViewModel.getItemPosition()
|
setPosition(rowPosition, itemPosition)
|
||||||
)?.requestFocus()
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fun setPosition(rowPosition: Int, itemPosition: Int) {
|
fun setPosition(rowPosition: Int, itemPosition: Int) {
|
||||||
rowList[rowPosition].post {
|
rowList[rowPosition].post {
|
||||||
((rowList[rowPosition] as RecyclerView).layoutManager as GridLayoutManager).findViewByPosition(
|
when (val layoutManager = (rowList[rowPosition] as RecyclerView).layoutManager) {
|
||||||
itemPosition
|
is GridLayoutManager -> {
|
||||||
)?.requestFocus()
|
layoutManager.findViewByPosition(
|
||||||
}
|
itemPosition
|
||||||
|
)?.requestFocus()
|
||||||
|
}
|
||||||
|
|
||||||
((rowList[rowPosition] as RecyclerView).adapter as CardAdapter).defaultFocus = itemPosition
|
is LinearLayoutManager -> {
|
||||||
|
layoutManager.findViewByPosition(
|
||||||
|
itemPosition
|
||||||
|
)?.requestFocus()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fun check(tvViewModel: TVViewModel): Boolean {
|
fun check(tvViewModel: TVViewModel): Boolean {
|
||||||
@@ -304,6 +307,32 @@ class MainFragment : Fragment(), CardAdapter.ItemListener {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fun shouldHasFocus(tvModel: TVViewModel): Boolean {
|
||||||
|
return tvModel == tvListViewModel.getTVViewModel(itemPosition)
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun onHiddenChanged(hidden: Boolean) {
|
||||||
|
super.onHiddenChanged(hidden)
|
||||||
|
if (!hidden) {
|
||||||
|
val tvModel = tvListViewModel.getTVViewModel(itemPosition)
|
||||||
|
val rowPosition = tvModel?.getRowPosition()
|
||||||
|
val itemPosition = tvModel?.getItemPosition()
|
||||||
|
Log.i(TAG, "toPosition $rowPosition $itemPosition")
|
||||||
|
for (i in rowList) {
|
||||||
|
if (i.tag as Int == rowPosition) {
|
||||||
|
((i as RecyclerView).adapter as CardAdapter).toPosition(itemPosition!!)
|
||||||
|
break
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
view?.post {
|
||||||
|
// for (i in rowList) {
|
||||||
|
// ((i as RecyclerView).adapter as CardAdapter).visiable = false
|
||||||
|
// }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
override fun onResume() {
|
override fun onResume() {
|
||||||
Log.i(TAG, "onResume")
|
Log.i(TAG, "onResume")
|
||||||
super.onResume()
|
super.onResume()
|
||||||
|
|||||||
@@ -56,6 +56,9 @@ object Request {
|
|||||||
|
|
||||||
private var listener: RequestListener? = null
|
private var listener: RequestListener? = null
|
||||||
|
|
||||||
|
private var initRetryTimes = 0
|
||||||
|
private var initRetryMaxTimes = 1
|
||||||
|
|
||||||
fun onCreate() {
|
fun onCreate() {
|
||||||
Log.i(TAG, "onCreate")
|
Log.i(TAG, "onCreate")
|
||||||
fetchInfoV2()
|
fetchInfoV2()
|
||||||
@@ -66,18 +69,28 @@ object Request {
|
|||||||
handler.removeCallbacks(tokenRunnable)
|
handler.removeCallbacks(tokenRunnable)
|
||||||
}
|
}
|
||||||
|
|
||||||
var call: Call<LiveInfo>? = null
|
private var call: Call<LiveInfo>? = null
|
||||||
private var callAuth: Call<Auth>? = null
|
private var callAuth: Call<Auth>? = null
|
||||||
|
private var callInfo: Call<Info>? = null
|
||||||
|
private var callFAuth: Call<FAuth>? = null
|
||||||
|
private var callPage: Call<pageModel.Response>? = null
|
||||||
|
|
||||||
|
private fun cancelCall() {
|
||||||
|
call?.cancel()
|
||||||
|
callAuth?.cancel()
|
||||||
|
callInfo?.cancel()
|
||||||
|
callFAuth?.cancel()
|
||||||
|
callPage?.cancel()
|
||||||
|
}
|
||||||
|
|
||||||
private fun fetchAuth(tvModel: TVViewModel, cookie: String) {
|
private fun fetchAuth(tvModel: TVViewModel, cookie: String) {
|
||||||
callAuth?.cancel()
|
cancelCall()
|
||||||
|
|
||||||
val title = tvModel.title.value
|
val title = tvModel.title.value
|
||||||
|
|
||||||
val data = YSP.getAuthData(tvModel)
|
val data = YSP.getAuthData(tvModel)
|
||||||
val request = AuthRequest(data)
|
val request = AuthRequest(data)
|
||||||
callAuth = request.let { yspApiService.getAuth("guid=${YSP.getGuid()}; $cookie", it) }
|
callAuth = request.let { yspApiService.getAuth("guid=${YSP.getGuid()}; $cookie", it) }
|
||||||
|
|
||||||
callAuth?.enqueue(object : Callback<Auth> {
|
callAuth?.enqueue(object : Callback<Auth> {
|
||||||
override fun onResponse(call: Call<Auth>, response: Response<Auth>) {
|
override fun onResponse(call: Call<Auth>, response: Response<Auth>) {
|
||||||
if (response.isSuccessful) {
|
if (response.isSuccessful) {
|
||||||
@@ -92,12 +105,12 @@ object Request {
|
|||||||
if (tvModel.retryTimes < tvModel.retryMaxTimes) {
|
if (tvModel.retryTimes < tvModel.retryMaxTimes) {
|
||||||
tvModel.retryTimes++
|
tvModel.retryTimes++
|
||||||
if (tvModel.getTV().needToken) {
|
if (tvModel.getTV().needToken) {
|
||||||
if (tvModel.tokenRetryTimes == tvModel.tokenRetryMaxTimes) {
|
if (tvModel.tokenYSPRetryTimes == tvModel.tokenYSPRetryMaxTimes) {
|
||||||
if (!tvModel.getTV().mustToken) {
|
if (!tvModel.getTV().mustToken) {
|
||||||
fetchAuth(tvModel, cookie)
|
fetchAuth(tvModel, cookie)
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
token = ""
|
tvModel.needGetToken = true
|
||||||
fetchAuth(tvModel)
|
fetchAuth(tvModel)
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
@@ -110,12 +123,12 @@ object Request {
|
|||||||
if (tvModel.retryTimes < tvModel.retryMaxTimes) {
|
if (tvModel.retryTimes < tvModel.retryMaxTimes) {
|
||||||
tvModel.retryTimes++
|
tvModel.retryTimes++
|
||||||
if (tvModel.getTV().needToken) {
|
if (tvModel.getTV().needToken) {
|
||||||
if (tvModel.tokenRetryTimes == tvModel.tokenRetryMaxTimes) {
|
if (tvModel.tokenYSPRetryTimes == tvModel.tokenYSPRetryMaxTimes) {
|
||||||
if (!tvModel.getTV().mustToken) {
|
if (!tvModel.getTV().mustToken) {
|
||||||
fetchAuth(tvModel, cookie)
|
fetchAuth(tvModel, cookie)
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
token = ""
|
tvModel.needGetToken = true
|
||||||
fetchAuth(tvModel)
|
fetchAuth(tvModel)
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
@@ -130,12 +143,12 @@ object Request {
|
|||||||
if (tvModel.retryTimes < tvModel.retryMaxTimes) {
|
if (tvModel.retryTimes < tvModel.retryMaxTimes) {
|
||||||
tvModel.retryTimes++
|
tvModel.retryTimes++
|
||||||
if (tvModel.getTV().needToken) {
|
if (tvModel.getTV().needToken) {
|
||||||
if (tvModel.tokenRetryTimes == tvModel.tokenRetryMaxTimes) {
|
if (tvModel.tokenYSPRetryTimes == tvModel.tokenYSPRetryMaxTimes) {
|
||||||
if (!tvModel.getTV().mustToken) {
|
if (!tvModel.getTV().mustToken) {
|
||||||
fetchAuth(tvModel, cookie)
|
fetchAuth(tvModel, cookie)
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
token = ""
|
tvModel.needGetToken = true
|
||||||
fetchAuth(tvModel)
|
fetchAuth(tvModel)
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
@@ -146,8 +159,9 @@ object Request {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
fun fetchVideo(tvModel: TVViewModel, cookie: String) {
|
private fun fetchVideo(tvModel: TVViewModel, cookie: String) {
|
||||||
call?.cancel()
|
cancelCall()
|
||||||
|
|
||||||
if (::btraceRunnable.isInitialized) {
|
if (::btraceRunnable.isInitialized) {
|
||||||
handler.removeCallbacks(btraceRunnable)
|
handler.removeCallbacks(btraceRunnable)
|
||||||
}
|
}
|
||||||
@@ -197,13 +211,13 @@ object Request {
|
|||||||
if (tvModel.retryTimes < tvModel.retryMaxTimes) {
|
if (tvModel.retryTimes < tvModel.retryMaxTimes) {
|
||||||
tvModel.retryTimes++
|
tvModel.retryTimes++
|
||||||
if (tvModel.getTV().needToken) {
|
if (tvModel.getTV().needToken) {
|
||||||
if (tvModel.tokenRetryTimes == tvModel.tokenRetryMaxTimes) {
|
if (tvModel.tokenYSPRetryTimes == tvModel.tokenYSPRetryMaxTimes) {
|
||||||
if (!tvModel.getTV().mustToken) {
|
if (!tvModel.getTV().mustToken) {
|
||||||
fetchVideo(tvModel, cookie)
|
fetchVideo(tvModel, cookie)
|
||||||
// fetchAuth(tvModel, cookie)
|
// fetchAuth(tvModel, cookie)
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
token = ""
|
tvModel.needGetToken = true
|
||||||
fetchVideo(tvModel)
|
fetchVideo(tvModel)
|
||||||
// fetchAuth(tvModel)
|
// fetchAuth(tvModel)
|
||||||
}
|
}
|
||||||
@@ -222,13 +236,13 @@ object Request {
|
|||||||
if (tvModel.retryTimes < tvModel.retryMaxTimes) {
|
if (tvModel.retryTimes < tvModel.retryMaxTimes) {
|
||||||
tvModel.retryTimes++
|
tvModel.retryTimes++
|
||||||
if (tvModel.getTV().needToken) {
|
if (tvModel.getTV().needToken) {
|
||||||
if (tvModel.tokenRetryTimes == tvModel.tokenRetryMaxTimes) {
|
if (tvModel.tokenYSPRetryTimes == tvModel.tokenYSPRetryMaxTimes) {
|
||||||
if (!tvModel.getTV().mustToken) {
|
if (!tvModel.getTV().mustToken) {
|
||||||
fetchVideo(tvModel, cookie)
|
fetchVideo(tvModel, cookie)
|
||||||
// fetchAuth(tvModel, cookie)
|
// fetchAuth(tvModel, cookie)
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
token = ""
|
tvModel.needGetToken = true
|
||||||
fetchVideo(tvModel)
|
fetchVideo(tvModel)
|
||||||
// fetchAuth(tvModel)
|
// fetchAuth(tvModel)
|
||||||
}
|
}
|
||||||
@@ -244,13 +258,13 @@ object Request {
|
|||||||
if (tvModel.retryTimes < tvModel.retryMaxTimes) {
|
if (tvModel.retryTimes < tvModel.retryMaxTimes) {
|
||||||
tvModel.retryTimes++
|
tvModel.retryTimes++
|
||||||
if (tvModel.getTV().needToken) {
|
if (tvModel.getTV().needToken) {
|
||||||
if (tvModel.tokenRetryTimes == tvModel.tokenRetryMaxTimes) {
|
if (tvModel.tokenYSPRetryTimes == tvModel.tokenYSPRetryMaxTimes) {
|
||||||
if (!tvModel.getTV().mustToken) {
|
if (!tvModel.getTV().mustToken) {
|
||||||
fetchVideo(tvModel, cookie)
|
fetchVideo(tvModel, cookie)
|
||||||
// fetchAuth(tvModel, cookie)
|
// fetchAuth(tvModel, cookie)
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
token = ""
|
tvModel.needGetToken = true
|
||||||
fetchVideo(tvModel)
|
fetchVideo(tvModel)
|
||||||
// fetchAuth(tvModel)
|
// fetchAuth(tvModel)
|
||||||
}
|
}
|
||||||
@@ -267,12 +281,12 @@ object Request {
|
|||||||
if (tvModel.retryTimes < tvModel.retryMaxTimes) {
|
if (tvModel.retryTimes < tvModel.retryMaxTimes) {
|
||||||
tvModel.retryTimes++
|
tvModel.retryTimes++
|
||||||
if (tvModel.getTV().needToken) {
|
if (tvModel.getTV().needToken) {
|
||||||
if (tvModel.tokenRetryTimes == tvModel.tokenRetryMaxTimes) {
|
if (tvModel.tokenYSPRetryTimes == tvModel.tokenYSPRetryMaxTimes) {
|
||||||
if (!tvModel.getTV().mustToken) {
|
if (!tvModel.getTV().mustToken) {
|
||||||
fetchVideo(tvModel, cookie)
|
fetchVideo(tvModel, cookie)
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
token = ""
|
tvModel.needGetToken = true
|
||||||
fetchVideo(tvModel)
|
fetchVideo(tvModel)
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
@@ -283,37 +297,31 @@ object Request {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
fun fetchAuth(tvModel: TVViewModel) {
|
private fun fetchAuth(tvModel: TVViewModel) {
|
||||||
if (token == "") {
|
cancelCall()
|
||||||
yspTokenService.getInfo("")
|
if (tvModel.needGetToken) {
|
||||||
.enqueue(object : Callback<Info> {
|
callInfo = yspTokenService.getInfo("")
|
||||||
override fun onResponse(call: Call<Info>, response: Response<Info>) {
|
callInfo?.enqueue(object : Callback<Info> {
|
||||||
if (response.isSuccessful) {
|
override fun onResponse(call: Call<Info>, response: Response<Info>) {
|
||||||
token = response.body()?.data?.token!!
|
if (response.isSuccessful && response.body()?.data?.token != null) {
|
||||||
Log.i(TAG, "info success $token")
|
token = response.body()?.data?.token!!
|
||||||
val cookie =
|
Log.i(TAG, "info success $token")
|
||||||
"versionName=99.99.99; versionCode=999999; vplatform=109; platformVersion=Chrome; deviceModel=120; appid=1400421205; yspappid=519748109;yspopenid=vu0-8lgGV2LW9QjDeuBFsX8yMnzs37Q3_HZF6XyVDpGR_I; vusession=$token"
|
tvModel.needGetToken = false
|
||||||
fetchAuth(tvModel, cookie)
|
tvModel.tokenYSPRetryTimes = 0
|
||||||
} else {
|
val cookie =
|
||||||
Log.e(TAG, "info status error")
|
"versionName=99.99.99; versionCode=999999; vplatform=109; platformVersion=Chrome; deviceModel=120; appid=1400421205; yspappid=519748109;yspopenid=vu0-8lgGV2LW9QjDeuBFsX8yMnzs37Q3_HZF6XyVDpGR_I; vusession=$token"
|
||||||
if (tvModel.tokenRetryTimes < tvModel.tokenRetryMaxTimes) {
|
fetchAuth(tvModel, cookie)
|
||||||
tvModel.tokenRetryTimes++
|
} else if (response.code() == 304) {
|
||||||
fetchAuth(tvModel)
|
tvModel.needGetToken = false
|
||||||
} else {
|
tvModel.tokenYSPRetryTimes = 0
|
||||||
if (!tvModel.getTV().mustToken) {
|
val cookie =
|
||||||
val cookie =
|
"versionName=99.99.99; versionCode=999999; vplatform=109; platformVersion=Chrome; deviceModel=120; appid=1400421205; yspappid=519748109; yspopenid=vu0-8lgGV2LW9QjDeuBFsX8yMnzs37Q3_HZF6XyVDpGR_I; vusession=$token"
|
||||||
"versionName=99.99.99; versionCode=999999; vplatform=109; platformVersion=Chrome; deviceModel=120; appid=1400421205; yspappid=519748109"
|
fetchVideo(tvModel, cookie)
|
||||||
fetchAuth(tvModel, cookie)
|
} else {
|
||||||
}
|
Log.e(TAG, "info status error")
|
||||||
}
|
if (tvModel.tokenYSPRetryTimes < tvModel.tokenYSPRetryMaxTimes) {
|
||||||
}
|
tvModel.tokenYSPRetryTimes++
|
||||||
}
|
fetchAuth(tvModel)
|
||||||
|
|
||||||
override fun onFailure(call: Call<Info>, t: Throwable) {
|
|
||||||
Log.e(TAG, "info request error $t")
|
|
||||||
if (tvModel.tokenRetryTimes < tvModel.tokenRetryMaxTimes) {
|
|
||||||
tvModel.tokenRetryTimes++
|
|
||||||
fetchVideo(tvModel)
|
|
||||||
} else {
|
} else {
|
||||||
if (!tvModel.getTV().mustToken) {
|
if (!tvModel.getTV().mustToken) {
|
||||||
val cookie =
|
val cookie =
|
||||||
@@ -322,7 +330,22 @@ object Request {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
})
|
}
|
||||||
|
|
||||||
|
override fun onFailure(call: Call<Info>, t: Throwable) {
|
||||||
|
Log.e(TAG, "info request error $t")
|
||||||
|
if (tvModel.tokenYSPRetryTimes < tvModel.tokenYSPRetryMaxTimes) {
|
||||||
|
tvModel.tokenYSPRetryTimes++
|
||||||
|
fetchVideo(tvModel)
|
||||||
|
} else {
|
||||||
|
if (!tvModel.getTV().mustToken) {
|
||||||
|
val cookie =
|
||||||
|
"versionName=99.99.99; versionCode=999999; vplatform=109; platformVersion=Chrome; deviceModel=120; appid=1400421205; yspappid=519748109"
|
||||||
|
fetchAuth(tvModel, cookie)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
})
|
||||||
} else {
|
} else {
|
||||||
val cookie =
|
val cookie =
|
||||||
"versionName=99.99.99; versionCode=999999; vplatform=109; platformVersion=Chrome; deviceModel=120; appid=1400421205; yspappid=519748109;yspopenid=vu0-8lgGV2LW9QjDeuBFsX8yMnzs37Q3_HZF6XyVDpGR_I; vusession=$token"
|
"versionName=99.99.99; versionCode=999999; vplatform=109; platformVersion=Chrome; deviceModel=120; appid=1400421205; yspappid=519748109;yspopenid=vu0-8lgGV2LW9QjDeuBFsX8yMnzs37Q3_HZF6XyVDpGR_I; vusession=$token"
|
||||||
@@ -330,37 +353,31 @@ object Request {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fun fetchVideo(tvModel: TVViewModel) {
|
private fun fetchVideo(tvModel: TVViewModel) {
|
||||||
|
cancelCall()
|
||||||
Log.d(TAG, "fetchVideo")
|
Log.d(TAG, "fetchVideo")
|
||||||
if (token == "") {
|
if (tvModel.needGetToken) {
|
||||||
yspTokenService.getInfo("")
|
callInfo = yspTokenService.getInfo("")
|
||||||
.enqueue(object : Callback<Info> {
|
callInfo?.enqueue(object : Callback<Info> {
|
||||||
override fun onResponse(call: Call<Info>, response: Response<Info>) {
|
override fun onResponse(call: Call<Info>, response: Response<Info>) {
|
||||||
if (response.isSuccessful && response.body()?.data?.token != null) {
|
if (response.isSuccessful && response.body()?.data?.token != null) {
|
||||||
token = response.body()?.data?.token!!
|
token = response.body()?.data?.token!!
|
||||||
Log.i(TAG, "info success $token")
|
Log.i(TAG, "info success $token")
|
||||||
val cookie =
|
tvModel.needGetToken = false
|
||||||
"versionName=99.99.99; versionCode=999999; vplatform=109; platformVersion=Chrome; deviceModel=120; appid=1400421205; yspappid=519748109; yspopenid=vu0-8lgGV2LW9QjDeuBFsX8yMnzs37Q3_HZF6XyVDpGR_I; vusession=$token"
|
tvModel.tokenYSPRetryTimes = 0
|
||||||
fetchVideo(tvModel, cookie)
|
val cookie =
|
||||||
} else {
|
"versionName=99.99.99; versionCode=999999; vplatform=109; platformVersion=Chrome; deviceModel=120; appid=1400421205; yspappid=519748109; yspopenid=vu0-8lgGV2LW9QjDeuBFsX8yMnzs37Q3_HZF6XyVDpGR_I; vusession=$token"
|
||||||
Log.e(TAG, "info status error")
|
fetchVideo(tvModel, cookie)
|
||||||
if (tvModel.tokenRetryTimes < tvModel.tokenRetryMaxTimes) {
|
} else if (response.code() == 304) {
|
||||||
tvModel.tokenRetryTimes++
|
tvModel.needGetToken = false
|
||||||
fetchVideo(tvModel)
|
tvModel.tokenYSPRetryTimes = 0
|
||||||
} else {
|
val cookie =
|
||||||
if (!tvModel.getTV().mustToken) {
|
"versionName=99.99.99; versionCode=999999; vplatform=109; platformVersion=Chrome; deviceModel=120; appid=1400421205; yspappid=519748109; yspopenid=vu0-8lgGV2LW9QjDeuBFsX8yMnzs37Q3_HZF6XyVDpGR_I; vusession=$token"
|
||||||
val cookie =
|
fetchVideo(tvModel, cookie)
|
||||||
"versionName=99.99.99; versionCode=999999; vplatform=109; platformVersion=Chrome; deviceModel=120; appid=1400421205; yspappid=519748109"
|
} else {
|
||||||
fetchVideo(tvModel, cookie)
|
Log.e(TAG, "info status error")
|
||||||
}
|
if (tvModel.tokenYSPRetryTimes < tvModel.tokenYSPRetryMaxTimes) {
|
||||||
}
|
tvModel.tokenYSPRetryTimes++
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun onFailure(call: Call<Info>, t: Throwable) {
|
|
||||||
Log.e(TAG, "info request error $t")
|
|
||||||
if (tvModel.tokenRetryTimes < tvModel.tokenRetryMaxTimes) {
|
|
||||||
tvModel.tokenRetryTimes++
|
|
||||||
fetchVideo(tvModel)
|
fetchVideo(tvModel)
|
||||||
} else {
|
} else {
|
||||||
if (!tvModel.getTV().mustToken) {
|
if (!tvModel.getTV().mustToken) {
|
||||||
@@ -370,7 +387,22 @@ object Request {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
})
|
}
|
||||||
|
|
||||||
|
override fun onFailure(call: Call<Info>, t: Throwable) {
|
||||||
|
Log.e(TAG, "info request error $t")
|
||||||
|
if (tvModel.tokenYSPRetryTimes < tvModel.tokenYSPRetryMaxTimes) {
|
||||||
|
tvModel.tokenYSPRetryTimes++
|
||||||
|
fetchVideo(tvModel)
|
||||||
|
} else {
|
||||||
|
if (!tvModel.getTV().mustToken) {
|
||||||
|
val cookie =
|
||||||
|
"versionName=99.99.99; versionCode=999999; vplatform=109; platformVersion=Chrome; deviceModel=120; appid=1400421205; yspappid=519748109"
|
||||||
|
fetchVideo(tvModel, cookie)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
})
|
||||||
} else {
|
} else {
|
||||||
val cookie =
|
val cookie =
|
||||||
"versionName=99.99.99; versionCode=999999; vplatform=109; platformVersion=Chrome; deviceModel=120; appid=1400421205; yspappid=519748109; yspopenid=vu0-8lgGV2LW9QjDeuBFsX8yMnzs37Q3_HZF6XyVDpGR_I; vusession=$token"
|
"versionName=99.99.99; versionCode=999999; vplatform=109; platformVersion=Chrome; deviceModel=120; appid=1400421205; yspappid=519748109; yspopenid=vu0-8lgGV2LW9QjDeuBFsX8yMnzs37Q3_HZF6XyVDpGR_I; vusession=$token"
|
||||||
@@ -378,11 +410,8 @@ object Request {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private var fAuth: Call<FAuth>? = null
|
private fun fetchFAuth(tvModel: TVViewModel) {
|
||||||
fun fetchFAuth(tvModel: TVViewModel) {
|
cancelCall()
|
||||||
call?.cancel()
|
|
||||||
callAuth?.cancel()
|
|
||||||
fAuth?.cancel()
|
|
||||||
|
|
||||||
val title = tvModel.title.value
|
val title = tvModel.title.value
|
||||||
|
|
||||||
@@ -391,19 +420,19 @@ object Request {
|
|||||||
qa = "FHD"
|
qa = "FHD"
|
||||||
}
|
}
|
||||||
|
|
||||||
fAuth = fAuthService.getAuth(tokenFH, tvModel.getTV().pid, qa)
|
callFAuth = fAuthService.getAuth(tokenFH, tvModel.getTV().pid, qa)
|
||||||
fAuth?.enqueue(object : Callback<FAuth> {
|
callFAuth?.enqueue(object : Callback<FAuth> {
|
||||||
override fun onResponse(call: Call<FAuth>, response: Response<FAuth>) {
|
override fun onResponse(call: Call<FAuth>, response: Response<FAuth>) {
|
||||||
if (response.isSuccessful && response.body()?.data?.live_url != null) {
|
if (response.isSuccessful && response.body()?.data?.live_url != null) {
|
||||||
val url = response.body()?.data?.live_url!!
|
val url = response.body()?.data?.live_url!!
|
||||||
// Log.d(TAG, "$title url $url")
|
// Log.d(TAG, "$title url $url")
|
||||||
tvModel.addVideoUrl(url)
|
tvModel.addVideoUrl(url)
|
||||||
tvModel.allReady()
|
tvModel.allReady()
|
||||||
tvModel.retryTimes = 0
|
tvModel.tokenFHRetryTimes = 0
|
||||||
} else {
|
} else {
|
||||||
Log.e(TAG, "auth status error")
|
Log.e(TAG, "auth status error ${response.code()}")
|
||||||
if (tvModel.tokenRetryTimes < tvModel.tokenRetryMaxTimes) {
|
if (tvModel.tokenFHRetryTimes < tvModel.tokenFHRetryMaxTimes) {
|
||||||
tvModel.tokenRetryTimes++
|
tvModel.tokenFHRetryTimes++
|
||||||
fetchFAuth(tvModel)
|
fetchFAuth(tvModel)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -411,8 +440,8 @@ object Request {
|
|||||||
|
|
||||||
override fun onFailure(call: Call<FAuth>, t: Throwable) {
|
override fun onFailure(call: Call<FAuth>, t: Throwable) {
|
||||||
Log.e(TAG, "auth request error $t")
|
Log.e(TAG, "auth request error $t")
|
||||||
if (tvModel.tokenRetryTimes < tvModel.tokenRetryMaxTimes) {
|
if (tvModel.tokenFHRetryTimes < tvModel.tokenFHRetryMaxTimes) {
|
||||||
tvModel.tokenRetryTimes++
|
tvModel.tokenFHRetryTimes++
|
||||||
fetchFAuth(tvModel)
|
fetchFAuth(tvModel)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -444,8 +473,7 @@ object Request {
|
|||||||
|
|
||||||
class TokenRunnable : Runnable {
|
class TokenRunnable : Runnable {
|
||||||
override fun run() {
|
override fun run() {
|
||||||
fetchToken()
|
// fetchToken()
|
||||||
handler.postDelayed(this, 600000)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -488,14 +516,20 @@ object Request {
|
|||||||
Utils.setBetween(c * 1000L)
|
Utils.setBetween(c * 1000L)
|
||||||
Log.i(TAG, "current time $c")
|
Log.i(TAG, "current time $c")
|
||||||
}
|
}
|
||||||
|
listener?.onRequestFinished()
|
||||||
} else {
|
} else {
|
||||||
Log.e(TAG, "token status error")
|
Log.e(TAG, "token status error")
|
||||||
handler.postDelayed(
|
handler.postDelayed(
|
||||||
tokenRunnable,
|
tokenRunnable,
|
||||||
30 * 60 * 1000
|
30 * 60 * 1000
|
||||||
)
|
)
|
||||||
|
if (initRetryTimes < initRetryMaxTimes) {
|
||||||
|
initRetryTimes++
|
||||||
|
fetchInfoV2()
|
||||||
|
} else {
|
||||||
|
listener?.onRequestFinished()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
listener?.onRequestFinished()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onFailure(call: Call<InfoV2>, t: Throwable) {
|
override fun onFailure(call: Call<InfoV2>, t: Throwable) {
|
||||||
@@ -504,7 +538,13 @@ object Request {
|
|||||||
tokenRunnable,
|
tokenRunnable,
|
||||||
30 * 60 * 1000
|
30 * 60 * 1000
|
||||||
)
|
)
|
||||||
listener?.onRequestFinished()
|
|
||||||
|
if (initRetryTimes < initRetryMaxTimes) {
|
||||||
|
initRetryTimes++
|
||||||
|
fetchInfoV2()
|
||||||
|
} else {
|
||||||
|
listener?.onRequestFinished()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
@@ -600,7 +640,8 @@ object Request {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fun fetchPage() {
|
fun fetchPage() {
|
||||||
yspProtoService.getPage().enqueue(object : Callback<pageModel.Response> {
|
callPage = yspProtoService.getPage()
|
||||||
|
callPage?.enqueue(object : Callback<pageModel.Response> {
|
||||||
override fun onResponse(
|
override fun onResponse(
|
||||||
call: Call<pageModel.Response>,
|
call: Call<pageModel.Response>,
|
||||||
response: Response<pageModel.Response>
|
response: Response<pageModel.Response>
|
||||||
|
|||||||
@@ -6,14 +6,21 @@ import android.content.SharedPreferences
|
|||||||
object SP {
|
object SP {
|
||||||
// Name of the sp file TODO Should use a meaningful name and do migrations
|
// Name of the sp file TODO Should use a meaningful name and do migrations
|
||||||
private const val SP_FILE_NAME = "MainActivity"
|
private const val SP_FILE_NAME = "MainActivity"
|
||||||
|
|
||||||
// If Change channel with up and down in reversed order or not
|
// If Change channel with up and down in reversed order or not
|
||||||
private const val KEY_CHANNEL_REVERSAL = "channel_reversal"
|
private const val KEY_CHANNEL_REVERSAL = "channel_reversal"
|
||||||
|
|
||||||
// If use channel num to select channel or not
|
// If use channel num to select channel or not
|
||||||
private const val KEY_CHANNEL_NUM = "channel_num"
|
private const val KEY_CHANNEL_NUM = "channel_num"
|
||||||
|
|
||||||
// If start app on device boot or not
|
// If start app on device boot or not
|
||||||
private const val KEY_BOOT_STARTUP = "boot_startup"
|
private const val KEY_BOOT_STARTUP = "boot_startup"
|
||||||
|
|
||||||
|
private const val KEY_GRID = "grid"
|
||||||
|
|
||||||
// Position in list of the selected channel item
|
// Position in list of the selected channel item
|
||||||
private const val KEY_POSITION = "position"
|
private const val KEY_POSITION = "position"
|
||||||
|
|
||||||
// guid
|
// guid
|
||||||
private const val KEY_GUID = "guid"
|
private const val KEY_GUID = "guid"
|
||||||
|
|
||||||
@@ -38,11 +45,15 @@ object SP {
|
|||||||
get() = sp.getBoolean(KEY_BOOT_STARTUP, false)
|
get() = sp.getBoolean(KEY_BOOT_STARTUP, false)
|
||||||
set(value) = sp.edit().putBoolean(KEY_BOOT_STARTUP, value).apply()
|
set(value) = sp.edit().putBoolean(KEY_BOOT_STARTUP, value).apply()
|
||||||
|
|
||||||
|
var grid: Boolean
|
||||||
|
get() = sp.getBoolean(KEY_GRID, false)
|
||||||
|
set(value) = sp.edit().putBoolean(KEY_GRID, value).apply()
|
||||||
|
|
||||||
var itemPosition: Int
|
var itemPosition: Int
|
||||||
get() = sp.getInt(KEY_POSITION, 0)
|
get() = sp.getInt(KEY_POSITION, 0)
|
||||||
set(value) = sp.edit().putInt(KEY_POSITION, value).apply()
|
set(value) = sp.edit().putInt(KEY_POSITION, value).apply()
|
||||||
|
|
||||||
var guid: String
|
var guid: String
|
||||||
get() = sp.getString(KEY_GUID, "") ?: ""
|
get() = sp.getString(KEY_GUID, "") ?: ""
|
||||||
set(value) = sp.edit().putString(KEY_GUID, value).apply()
|
set(value) = sp.edit().putString(KEY_GUID, value).apply()
|
||||||
}
|
}
|
||||||
@@ -8,14 +8,7 @@ import androidx.fragment.app.DialogFragment
|
|||||||
import com.lizongying.mytv.databinding.DialogBinding
|
import com.lizongying.mytv.databinding.DialogBinding
|
||||||
|
|
||||||
|
|
||||||
class SettingFragment(
|
class SettingFragment : DialogFragment() {
|
||||||
private val versionName: String,
|
|
||||||
private val versionCode: Long,
|
|
||||||
private val channelReversal: Boolean,
|
|
||||||
private val channelNum: Boolean,
|
|
||||||
private val bootStartup: Boolean,
|
|
||||||
) :
|
|
||||||
DialogFragment() {
|
|
||||||
|
|
||||||
private var _binding: DialogBinding? = null
|
private var _binding: DialogBinding? = null
|
||||||
private val binding get() = _binding!!
|
private val binding get() = _binding!!
|
||||||
@@ -32,33 +25,45 @@ class SettingFragment(
|
|||||||
container: ViewGroup?,
|
container: ViewGroup?,
|
||||||
savedInstanceState: Bundle?
|
savedInstanceState: Bundle?
|
||||||
): View {
|
): View {
|
||||||
|
val context = requireContext() // It‘s safe to get context here.
|
||||||
_binding = DialogBinding.inflate(inflater, container, false)
|
_binding = DialogBinding.inflate(inflater, container, false)
|
||||||
_binding?.version?.text =
|
binding.version.text =
|
||||||
"当前版本: $versionName\n获取最新: https://github.com/lizongying/my-tv/releases/"
|
"当前版本: ${context.appVersionName}\n获取最新: https://github.com/lizongying/my-tv/releases/"
|
||||||
|
|
||||||
val switchChannelReversal = _binding?.switchChannelReversal
|
binding.switchChannelReversal.run {
|
||||||
switchChannelReversal?.isChecked = channelReversal
|
isChecked = SP.channelReversal
|
||||||
switchChannelReversal?.setOnCheckedChangeListener { _, isChecked ->
|
setOnCheckedChangeListener { _, isChecked ->
|
||||||
SP.channelReversal = isChecked
|
SP.channelReversal = isChecked
|
||||||
(activity as MainActivity).settingActive()
|
(activity as MainActivity).settingActive()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
val switchChannelNum = _binding?.switchChannelNum
|
binding.switchChannelNum.run {
|
||||||
switchChannelNum?.isChecked = channelNum
|
isChecked = SP.channelNum
|
||||||
switchChannelNum?.setOnCheckedChangeListener { _, isChecked ->
|
setOnCheckedChangeListener { _, isChecked ->
|
||||||
SP.channelNum = isChecked
|
SP.channelNum = isChecked
|
||||||
(activity as MainActivity).settingActive()
|
(activity as MainActivity).settingActive()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
val switchBootStartup = _binding?.switchBootStartup
|
binding.switchBootStartup.run {
|
||||||
switchBootStartup?.isChecked = bootStartup
|
isChecked = SP.bootStartup
|
||||||
switchBootStartup?.setOnCheckedChangeListener { _, isChecked ->
|
setOnCheckedChangeListener { _, isChecked ->
|
||||||
SP.bootStartup = isChecked
|
SP.bootStartup = isChecked
|
||||||
(activity as MainActivity).settingActive()
|
(activity as MainActivity).settingActive()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
updateManager = UpdateManager(context, this, versionCode)
|
binding.switchGrid.run {
|
||||||
_binding?.checkVersion?.setOnClickListener(OnClickListenerCheckVersion(updateManager))
|
isChecked = SP.grid
|
||||||
|
setOnCheckedChangeListener { _, isChecked ->
|
||||||
|
SP.grid = isChecked
|
||||||
|
(activity as MainActivity).settingActive()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
updateManager = UpdateManager(context, this, context.appVersionCode)
|
||||||
|
binding.checkVersion.setOnClickListener(OnClickListenerCheckVersion(updateManager))
|
||||||
|
|
||||||
return binding.root
|
return binding.root
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -23,7 +23,7 @@ import java.io.File
|
|||||||
|
|
||||||
|
|
||||||
class UpdateManager(
|
class UpdateManager(
|
||||||
private var context: Context?,
|
private var context: Context,
|
||||||
private var settingFragment: SettingFragment,
|
private var settingFragment: SettingFragment,
|
||||||
private var versionCode: Long
|
private var versionCode: Long
|
||||||
) :
|
) :
|
||||||
@@ -67,7 +67,7 @@ class UpdateManager(
|
|||||||
val apkFileName = "my-tv-${release.data.versionName}.apk"
|
val apkFileName = "my-tv-${release.data.versionName}.apk"
|
||||||
Log.i(TAG, "apkFileName $apkFileName")
|
Log.i(TAG, "apkFileName $apkFileName")
|
||||||
val downloadManager =
|
val downloadManager =
|
||||||
context!!.getSystemService(Context.DOWNLOAD_SERVICE) as DownloadManager
|
context.getSystemService(Context.DOWNLOAD_SERVICE) as DownloadManager
|
||||||
val request = Request(Uri.parse(release.data.downloadUrl))
|
val request = Request(Uri.parse(release.data.downloadUrl))
|
||||||
Log.i(TAG, "url ${Uri.parse(release.data.downloadUrl)}")
|
Log.i(TAG, "url ${Uri.parse(release.data.downloadUrl)}")
|
||||||
request.setDestinationInExternalPublicDir(Environment.DIRECTORY_DOWNLOADS, apkFileName)
|
request.setDestinationInExternalPublicDir(Environment.DIRECTORY_DOWNLOADS, apkFileName)
|
||||||
@@ -77,22 +77,22 @@ class UpdateManager(
|
|||||||
// 获取下载任务的引用
|
// 获取下载任务的引用
|
||||||
val downloadReference = downloadManager.enqueue(request)
|
val downloadReference = downloadManager.enqueue(request)
|
||||||
|
|
||||||
downloadReceiver = DownloadReceiver(context!!, apkFileName, downloadReference)
|
downloadReceiver = DownloadReceiver(context, apkFileName, downloadReference)
|
||||||
|
|
||||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
|
||||||
context!!.registerReceiver(
|
context.registerReceiver(
|
||||||
downloadReceiver,
|
downloadReceiver,
|
||||||
IntentFilter(DownloadManager.ACTION_DOWNLOAD_COMPLETE),
|
IntentFilter(DownloadManager.ACTION_DOWNLOAD_COMPLETE),
|
||||||
Context.RECEIVER_NOT_EXPORTED,
|
Context.RECEIVER_NOT_EXPORTED,
|
||||||
)
|
)
|
||||||
} else {
|
} else {
|
||||||
context!!.registerReceiver(
|
context.registerReceiver(
|
||||||
downloadReceiver,
|
downloadReceiver,
|
||||||
IntentFilter(DownloadManager.ACTION_DOWNLOAD_COMPLETE)
|
IntentFilter(DownloadManager.ACTION_DOWNLOAD_COMPLETE)
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
getDownloadProgress(context!!, downloadReference) { progress ->
|
getDownloadProgress(context, downloadReference) { progress ->
|
||||||
println("Download progress: $progress%")
|
println("Download progress: $progress%")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -182,7 +182,7 @@ class UpdateManager(
|
|||||||
|
|
||||||
fun destroy() {
|
fun destroy() {
|
||||||
if (downloadReceiver != null) {
|
if (downloadReceiver != null) {
|
||||||
context!!.unregisterReceiver(downloadReceiver)
|
context.unregisterReceiver(downloadReceiver)
|
||||||
Log.i(TAG, "destroy downloadReceiver")
|
Log.i(TAG, "destroy downloadReceiver")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,7 +1,11 @@
|
|||||||
package com.lizongying.mytv.api
|
package com.lizongying.mytv.api
|
||||||
|
|
||||||
|
|
||||||
|
import android.os.Build
|
||||||
|
import android.util.Log
|
||||||
|
import okhttp3.ConnectionSpec
|
||||||
import okhttp3.OkHttpClient
|
import okhttp3.OkHttpClient
|
||||||
|
import okhttp3.TlsVersion
|
||||||
import retrofit2.Retrofit
|
import retrofit2.Retrofit
|
||||||
import retrofit2.converter.gson.GsonConverterFactory
|
import retrofit2.converter.gson.GsonConverterFactory
|
||||||
import retrofit2.converter.protobuf.ProtoConverterFactory
|
import retrofit2.converter.protobuf.ProtoConverterFactory
|
||||||
@@ -68,6 +72,36 @@ class ApiClient {
|
|||||||
.build().create(FAuthService::class.java)
|
.build().create(FAuthService::class.java)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private fun enableTls12OnPreLollipop(client: OkHttpClient.Builder): OkHttpClient.Builder {
|
||||||
|
if (Build.VERSION.SDK_INT >= 16 && Build.VERSION.SDK_INT < 22) {
|
||||||
|
try {
|
||||||
|
val sc = SSLContext.getInstance("TLSv1.2")
|
||||||
|
|
||||||
|
sc.init(null, null, null)
|
||||||
|
|
||||||
|
// a more robust version is to pass a custom X509TrustManager
|
||||||
|
// as the second parameter and make checkServerTrusted to accept your server.
|
||||||
|
// Credits: https://github.com/square/okhttp/issues/2372#issuecomment-1774955225
|
||||||
|
client.sslSocketFactory(Tls12SocketFactory(sc.socketFactory))
|
||||||
|
|
||||||
|
val cs = ConnectionSpec.Builder(ConnectionSpec.MODERN_TLS)
|
||||||
|
.tlsVersions(TlsVersion.TLS_1_2)
|
||||||
|
.build()
|
||||||
|
|
||||||
|
val specs: MutableList<ConnectionSpec> = ArrayList()
|
||||||
|
specs.add(cs)
|
||||||
|
specs.add(ConnectionSpec.COMPATIBLE_TLS)
|
||||||
|
specs.add(ConnectionSpec.CLEARTEXT)
|
||||||
|
|
||||||
|
client.connectionSpecs(specs)
|
||||||
|
} catch (exc: java.lang.Exception) {
|
||||||
|
Log.e("OkHttpTLSCompat", "Error while setting TLS 1.2", exc)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return client
|
||||||
|
}
|
||||||
|
|
||||||
private fun getUnsafeOkHttpClient(): OkHttpClient {
|
private fun getUnsafeOkHttpClient(): OkHttpClient {
|
||||||
try {
|
try {
|
||||||
val trustAllCerts: Array<TrustManager> = arrayOf(
|
val trustAllCerts: Array<TrustManager> = arrayOf(
|
||||||
@@ -93,11 +127,12 @@ class ApiClient {
|
|||||||
val sslContext = SSLContext.getInstance("SSL")
|
val sslContext = SSLContext.getInstance("SSL")
|
||||||
sslContext.init(null, trustAllCerts, java.security.SecureRandom())
|
sslContext.init(null, trustAllCerts, java.security.SecureRandom())
|
||||||
|
|
||||||
return OkHttpClient.Builder()
|
val builder = OkHttpClient.Builder()
|
||||||
.sslSocketFactory(sslContext.socketFactory, trustAllCerts[0] as X509TrustManager)
|
.sslSocketFactory(sslContext.socketFactory, trustAllCerts[0] as X509TrustManager)
|
||||||
.hostnameVerifier { _, _ -> true }
|
.hostnameVerifier { _, _ -> true }
|
||||||
.dns(DnsCache())
|
.dns(DnsCache())
|
||||||
.build()
|
|
||||||
|
return enableTls12OnPreLollipop(builder).build()
|
||||||
|
|
||||||
} catch (e: Exception) {
|
} catch (e: Exception) {
|
||||||
throw RuntimeException(e)
|
throw RuntimeException(e)
|
||||||
|
|||||||
@@ -0,0 +1,74 @@
|
|||||||
|
package com.lizongying.mytv.api
|
||||||
|
|
||||||
|
import java.io.IOException
|
||||||
|
import java.net.InetAddress
|
||||||
|
import java.net.Socket
|
||||||
|
import java.net.UnknownHostException
|
||||||
|
import javax.net.ssl.SSLSocket
|
||||||
|
import javax.net.ssl.SSLSocketFactory
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Enables TLS v1.2 when creating SSLSockets.
|
||||||
|
*
|
||||||
|
*
|
||||||
|
* For some reason, android supports TLS v1.2 from API 16, but enables it by
|
||||||
|
* default only from API 20.
|
||||||
|
* @link https://developer.android.com/reference/javax/net/ssl/SSLSocket.html
|
||||||
|
* @see SSLSocketFactory
|
||||||
|
*/
|
||||||
|
class Tls12SocketFactory(val delegate: SSLSocketFactory) : SSLSocketFactory() {
|
||||||
|
override fun getDefaultCipherSuites(): Array<String> {
|
||||||
|
return delegate.defaultCipherSuites
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun getSupportedCipherSuites(): Array<String> {
|
||||||
|
return delegate.supportedCipherSuites
|
||||||
|
}
|
||||||
|
|
||||||
|
@Throws(IOException::class)
|
||||||
|
override fun createSocket(s: Socket, host: String, port: Int, autoClose: Boolean): Socket {
|
||||||
|
return patch(delegate.createSocket(s, host, port, autoClose))
|
||||||
|
}
|
||||||
|
|
||||||
|
@Throws(IOException::class, UnknownHostException::class)
|
||||||
|
override fun createSocket(host: String, port: Int): Socket {
|
||||||
|
return patch(delegate.createSocket(host, port))
|
||||||
|
}
|
||||||
|
|
||||||
|
@Throws(IOException::class, UnknownHostException::class)
|
||||||
|
override fun createSocket(
|
||||||
|
host: String,
|
||||||
|
port: Int,
|
||||||
|
localHost: InetAddress,
|
||||||
|
localPort: Int
|
||||||
|
): Socket {
|
||||||
|
return patch(delegate.createSocket(host, port, localHost, localPort))
|
||||||
|
}
|
||||||
|
|
||||||
|
@Throws(IOException::class)
|
||||||
|
override fun createSocket(host: InetAddress, port: Int): Socket {
|
||||||
|
return patch(delegate.createSocket(host, port))
|
||||||
|
}
|
||||||
|
|
||||||
|
@Throws(IOException::class)
|
||||||
|
override fun createSocket(
|
||||||
|
address: InetAddress,
|
||||||
|
port: Int,
|
||||||
|
localAddress: InetAddress,
|
||||||
|
localPort: Int
|
||||||
|
): Socket {
|
||||||
|
return patch(delegate.createSocket(address, port, localAddress, localPort))
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun patch(s: Socket): Socket {
|
||||||
|
if (s is SSLSocket) {
|
||||||
|
s.enabledProtocols = TLS_V12_ONLY
|
||||||
|
}
|
||||||
|
return s
|
||||||
|
}
|
||||||
|
|
||||||
|
companion object {
|
||||||
|
private val TLS_V12_ONLY = arrayOf("TLSv1.2")
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -22,10 +22,13 @@ class TVViewModel(private var tv: TV) : ViewModel() {
|
|||||||
private var itemPosition: Int = 0
|
private var itemPosition: Int = 0
|
||||||
|
|
||||||
var retryTimes = 0
|
var retryTimes = 0
|
||||||
var tokenRetryTimes = 0
|
|
||||||
var retryMaxTimes = 8
|
var retryMaxTimes = 8
|
||||||
var tokenRetryMaxTimes = 2
|
var tokenYSPRetryTimes = 0
|
||||||
var programUpdateTime: Long = 0
|
var tokenYSPRetryMaxTimes = 0
|
||||||
|
var tokenFHRetryTimes = 0
|
||||||
|
var tokenFHRetryMaxTimes = 2
|
||||||
|
|
||||||
|
var needGetToken = false
|
||||||
|
|
||||||
private val _errInfo = MutableLiveData<String>()
|
private val _errInfo = MutableLiveData<String>()
|
||||||
val errInfo: LiveData<String>
|
val errInfo: LiveData<String>
|
||||||
@@ -170,19 +173,13 @@ class TVViewModel(private var tv: TV) : ViewModel() {
|
|||||||
_epg.value = p.map { EPG(it.title, formatFTime(it.event_time)) }.toMutableList()
|
_epg.value = p.map { EPG(it.title, formatFTime(it.event_time)) }.toMutableList()
|
||||||
}
|
}
|
||||||
|
|
||||||
private var mHeaders: Map<String, String>? = mapOf()
|
|
||||||
|
|
||||||
fun setHeaders(headers: Map<String, String>) {
|
|
||||||
mHeaders = headers
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* (playerView?.player as ExoPlayer).setMediaSource(tvViewModel.buildSource())
|
* (playerView?.player as ExoPlayer).setMediaSource(tvViewModel.buildSource())
|
||||||
*/
|
*/
|
||||||
@OptIn(UnstableApi::class)
|
@OptIn(UnstableApi::class)
|
||||||
fun buildSource(): HlsMediaSource {
|
fun buildSource(): HlsMediaSource {
|
||||||
val httpDataSource = DefaultHttpDataSource.Factory()
|
val httpDataSource = DefaultHttpDataSource.Factory()
|
||||||
mHeaders?.let { httpDataSource.setDefaultRequestProperties(it) }
|
// mHeaders?.let { httpDataSource.setDefaultRequestProperties(it) }
|
||||||
|
|
||||||
return HlsMediaSource.Factory(httpDataSource).createMediaSource(
|
return HlsMediaSource.Factory(httpDataSource).createMediaSource(
|
||||||
MediaItem.fromUri(
|
MediaItem.fromUri(
|
||||||
|
|||||||
@@ -70,6 +70,12 @@
|
|||||||
android:layout_marginTop="10dp"
|
android:layout_marginTop="10dp"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="wrap_content" />
|
android:layout_height="wrap_content" />
|
||||||
|
<Switch
|
||||||
|
android:id="@+id/switch_grid"
|
||||||
|
android:text="@string/title_grid"
|
||||||
|
android:layout_marginTop="10dp"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content" />
|
||||||
</LinearLayout>
|
</LinearLayout>
|
||||||
<ImageView
|
<ImageView
|
||||||
android:layout_width="300dp"
|
android:layout_width="300dp"
|
||||||
|
|||||||
@@ -130,7 +130,7 @@
|
|||||||
"programId": "600004078",
|
"programId": "600004078",
|
||||||
"needToken": true,
|
"needToken": true,
|
||||||
"mustToken": false,
|
"mustToken": false,
|
||||||
"title": "CCTV9 记录",
|
"title": "CCTV9 纪录",
|
||||||
"videoUrl": [
|
"videoUrl": [
|
||||||
"http://dbiptv.sn.chinamobile.com/PLTV/88888890/224/3221226197/index.m3u8"
|
"http://dbiptv.sn.chinamobile.com/PLTV/88888890/224/3221226197/index.m3u8"
|
||||||
]
|
]
|
||||||
|
|||||||
@@ -3,4 +3,6 @@
|
|||||||
<color name="black">#000</color>
|
<color name="black">#000</color>
|
||||||
<color name="white">#FFF</color>
|
<color name="white">#FFF</color>
|
||||||
<color name="gray_overlay">#7F000000</color>
|
<color name="gray_overlay">#7F000000</color>
|
||||||
|
<color name="focus">#0096a6</color>
|
||||||
|
<color name="blur">#FF263238</color>
|
||||||
</resources>
|
</resources>
|
||||||
@@ -4,4 +4,5 @@
|
|||||||
<string name="title_channel_num">数字选台</string>
|
<string name="title_channel_num">数字选台</string>
|
||||||
<string name="check_version">检查更新</string>
|
<string name="check_version">检查更新</string>
|
||||||
<string name="title_boot_startup">开机自启</string>
|
<string name="title_boot_startup">开机自启</string>
|
||||||
|
<string name="title_grid">网格样式</string>
|
||||||
</resources>
|
</resources>
|
||||||
Reference in New Issue
Block a user