Compare commits

...
4 Commits
Author SHA1 Message Date
Li ZongYing 2b172ae615 fix retry bug 2024-05-01 17:00:33 +08:00
Li ZongYing 39e5cc7c1f opitimize request 2024-05-01 16:52:33 +08:00
Li ZongYing df5b006024 optimize style 2024-04-29 12:12:59 +08:00
Li ZongYing fe888c36ac left->start 2024-04-27 19:11:08 +08:00
26 changed files with 434 additions and 284 deletions
+9
View File
@@ -1,5 +1,14 @@
## 更新日志 ## 更新日志
### v1.9.0(通用)
* 减少视频播放失败情况
* 全面屏手机居中显示
### v1.8.8(通用)
* 样式优化
### v1.8.6(通用) ### v1.8.6(通用)
* 增加错误显示 * 增加错误显示
+5
View File
@@ -36,6 +36,9 @@
<category android:name="android.intent.category.LEANBACK_LAUNCHER" /> <category android:name="android.intent.category.LEANBACK_LAUNCHER" />
<category android:name="android.intent.category.LAUNCHER" /> <category android:name="android.intent.category.LAUNCHER" />
</intent-filter> </intent-filter>
<meta-data
android:name="android.windowLayoutInDisplayCutoutMode"
android:value="shortEdges" />
</activity> </activity>
<receiver <receiver
@@ -58,5 +61,7 @@
android:name=".InitializerProvider" android:name=".InitializerProvider"
android:authorities="${applicationId}.InitializerProvider" android:authorities="${applicationId}.InitializerProvider"
android:exported="false" /> android:exported="false" />
<meta-data android:name="android.max_aspect" android:value="2.5" />
</application> </application>
</manifest> </manifest>
Binary file not shown.
Binary file not shown.
@@ -6,7 +6,7 @@ import android.os.Handler
import android.view.LayoutInflater import android.view.LayoutInflater
import android.view.View import android.view.View
import android.view.ViewGroup import android.view.ViewGroup
import androidx.core.view.marginRight import androidx.core.view.marginEnd
import androidx.core.view.marginTop import androidx.core.view.marginTop
import androidx.fragment.app.Fragment import androidx.fragment.app.Fragment
import com.lizongying.mytv.databinding.ChannelBinding import com.lizongying.mytv.databinding.ChannelBinding
@@ -30,38 +30,20 @@ class ChannelFragment : Fragment() {
val application = requireActivity().applicationContext as MyTvApplication val application = requireActivity().applicationContext as MyTvApplication
val width = application.getWidth()
val height = application.getHeight()
val ratio = 16f / 9f
if (width.toFloat() / height > ratio) {
val x =
((Resources.getSystem().displayMetrics.widthPixels - height * ratio) / 2).toInt()
val originalLayoutParams =
binding.channel.layoutParams as ViewGroup.MarginLayoutParams
originalLayoutParams.rightMargin += x
binding.channel.layoutParams = originalLayoutParams
}
if (width.toFloat() / height < ratio) {
val y =
((height - Resources.getSystem().displayMetrics.widthPixels / ratio) / 2).toInt()
val originalLayoutParams =
binding.channel.layoutParams as ViewGroup.MarginLayoutParams
originalLayoutParams.topMargin += y
binding.channel.layoutParams = originalLayoutParams
}
binding.channel.layoutParams.width = application.px2Px(binding.channel.layoutParams.width) binding.channel.layoutParams.width = application.px2Px(binding.channel.layoutParams.width)
binding.channel.layoutParams.height = application.px2Px(binding.channel.layoutParams.height) binding.channel.layoutParams.height = application.px2Px(binding.channel.layoutParams.height)
val layoutParams = binding.channel.layoutParams as ViewGroup.MarginLayoutParams val layoutParams = binding.channel.layoutParams as ViewGroup.MarginLayoutParams
layoutParams.topMargin = application.px2Px(binding.channel.marginTop) layoutParams.topMargin = application.px2Px(binding.channel.marginTop)
layoutParams.rightMargin = application.px2Px(binding.channel.marginRight) layoutParams.marginEnd = application.px2Px(binding.channel.marginEnd)
binding.channel.layoutParams = layoutParams binding.channel.layoutParams = layoutParams
binding.content.textSize = application.px2PxFont(binding.content.textSize) binding.content.textSize = application.px2PxFont(binding.content.textSize)
(activity as MainActivity).fragmentReady("ChannelFragment") binding.main.layoutParams.width = application.shouldWidthPx()
binding.main.layoutParams.height = application.shouldHeightPx()
(activity as MainActivity).fragmentReady(TAG)
return binding.root return binding.root
} }
@@ -4,7 +4,7 @@ import android.os.Bundle
import android.view.LayoutInflater import android.view.LayoutInflater
import android.view.View import android.view.View
import android.view.ViewGroup import android.view.ViewGroup
import androidx.core.view.marginLeft import androidx.core.view.marginStart
import androidx.core.view.marginTop import androidx.core.view.marginTop
import androidx.fragment.app.Fragment import androidx.fragment.app.Fragment
import com.lizongying.mytv.databinding.ErrorBinding import com.lizongying.mytv.databinding.ErrorBinding
@@ -24,10 +24,6 @@ class ErrorFragment : Fragment() {
binding.logo.layoutParams.width = application.px2Px(binding.logo.layoutParams.width) binding.logo.layoutParams.width = application.px2Px(binding.logo.layoutParams.width)
binding.logo.layoutParams.height = application.px2Px(binding.logo.layoutParams.height) binding.logo.layoutParams.height = application.px2Px(binding.logo.layoutParams.height)
val layoutParamsMain = binding.main.layoutParams as ViewGroup.MarginLayoutParams
layoutParamsMain.leftMargin = application.px2Px(binding.main.marginLeft)
binding.main.layoutParams = layoutParamsMain
val layoutParams = binding.msg.layoutParams as ViewGroup.MarginLayoutParams val layoutParams = binding.msg.layoutParams as ViewGroup.MarginLayoutParams
layoutParams.topMargin = application.px2Px(binding.msg.marginTop) layoutParams.topMargin = application.px2Px(binding.msg.marginTop)
binding.msg.layoutParams = layoutParams binding.msg.layoutParams = layoutParams
@@ -8,7 +8,7 @@ import android.view.LayoutInflater
import android.view.View import android.view.View
import android.view.ViewGroup import android.view.ViewGroup
import androidx.core.view.marginBottom import androidx.core.view.marginBottom
import androidx.core.view.marginLeft import androidx.core.view.marginStart
import androidx.core.view.marginTop import androidx.core.view.marginTop
import androidx.core.view.setPadding import androidx.core.view.setPadding
import androidx.fragment.app.Fragment import androidx.fragment.app.Fragment
@@ -30,31 +30,21 @@ class InfoFragment : Fragment() {
_binding = InfoBinding.inflate(inflater, container, false) _binding = InfoBinding.inflate(inflater, container, false)
val application = requireActivity().applicationContext as MyTvApplication val application = requireActivity().applicationContext as MyTvApplication
val width = application.getWidth()
val height = application.getHeight()
val ratio = 16f / 9f
if (width.toFloat() / height < ratio) {
val y =
((height - Resources.getSystem().displayMetrics.widthPixels / ratio) / 2).toInt()
val originalLayoutParams = binding.info.layoutParams as ViewGroup.MarginLayoutParams
originalLayoutParams.bottomMargin += y
binding.info.layoutParams = originalLayoutParams
}
binding.info.layoutParams.width = application.px2Px(binding.info.layoutParams.width) binding.info.layoutParams.width = application.px2Px(binding.info.layoutParams.width)
binding.info.layoutParams.height = application.px2Px(binding.info.layoutParams.height) binding.info.layoutParams.height = application.px2Px(binding.info.layoutParams.height)
val layoutParams = binding.info.layoutParams as ViewGroup.MarginLayoutParams val layoutParams = binding.info.layoutParams as ViewGroup.MarginLayoutParams
layoutParams.bottomMargin = application.px2Px(binding.info.marginBottom) layoutParams.bottomMargin = application.px2Px(binding.info.marginBottom)
binding.info.layoutParams = layoutParams binding.info.layoutParams = layoutParams
binding.logo.layoutParams.width = application.px2Px(binding.logo.layoutParams.width) binding.logo.layoutParams.width = application.px2Px(binding.logo.layoutParams.width)
binding.logo.setPadding(application.px2Px(binding.logo.paddingTop)) binding.logo.setPadding(application.px2Px(binding.logo.paddingTop))
binding.main.layoutParams.width = application.px2Px(binding.main.layoutParams.width) binding.main.layoutParams.width = application.px2Px(binding.main.layoutParams.width)
binding.main.setPadding(application.px2Px(binding.main.paddingTop)) binding.main.setPadding(application.px2Px(binding.main.paddingTop))
val layoutParamsMain = binding.main.layoutParams as ViewGroup.MarginLayoutParams val layoutParamsMain = binding.main.layoutParams as ViewGroup.MarginLayoutParams
layoutParamsMain.leftMargin = application.px2Px(binding.main.marginLeft) layoutParamsMain.marginStart = application.px2Px(binding.main.marginStart)
binding.main.layoutParams = layoutParamsMain binding.main.layoutParams = layoutParamsMain
val layoutParamsDesc = binding.desc.layoutParams as ViewGroup.MarginLayoutParams val layoutParamsDesc = binding.desc.layoutParams as ViewGroup.MarginLayoutParams
@@ -64,13 +54,19 @@ class InfoFragment : Fragment() {
binding.title.textSize = application.px2PxFont(binding.title.textSize) binding.title.textSize = application.px2PxFont(binding.title.textSize)
binding.desc.textSize = application.px2PxFont(binding.desc.textSize) binding.desc.textSize = application.px2PxFont(binding.desc.textSize)
binding.container.layoutParams.width = application.shouldWidthPx()
binding.container.layoutParams.height = application.shouldHeightPx()
_binding!!.root.visibility = View.GONE _binding!!.root.visibility = View.GONE
(activity as MainActivity).fragmentReady("InfoFragment") (activity as MainActivity).fragmentReady(TAG)
return binding.root return binding.root
} }
fun show(tvViewModel: TVViewModel) { fun show(tvViewModel: TVViewModel) {
if (_binding == null) {
return
}
binding.title.text = tvViewModel.getTV().title binding.title.text = tvViewModel.getTV().title
Glide.with(this) Glide.with(this)
@@ -0,0 +1,37 @@
package com.lizongying.mytv
import android.os.Bundle
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.fragment.app.Fragment
import com.lizongying.mytv.databinding.LoadingBinding
class LoadingFragment : Fragment() {
private var _binding: LoadingBinding? = null
private val binding get() = _binding!!
override fun onCreateView(
inflater: LayoutInflater, container: ViewGroup?,
savedInstanceState: Bundle?
): View {
_binding = LoadingBinding.inflate(inflater, container, false)
val application = requireActivity().applicationContext as MyTvApplication
binding.bar.layoutParams.width = application.px2Px(binding.bar.layoutParams.width)
binding.bar.layoutParams.height = application.px2Px(binding.bar.layoutParams.height)
(activity as MainActivity).fragmentReady(TAG)
return binding.root
}
override fun onDestroyView() {
super.onDestroyView()
_binding = null
}
companion object {
private const val TAG = "LoadingFragment"
}
}
@@ -11,9 +11,13 @@ import android.util.Log
import android.view.GestureDetector import android.view.GestureDetector
import android.view.KeyEvent import android.view.KeyEvent
import android.view.MotionEvent import android.view.MotionEvent
import android.view.View.SYSTEM_UI_FLAG_FULLSCREEN
import android.view.View.SYSTEM_UI_FLAG_HIDE_NAVIGATION import android.view.View.SYSTEM_UI_FLAG_HIDE_NAVIGATION
import android.view.View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
import android.view.View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION
import android.view.WindowManager import android.view.WindowManager
import android.widget.Toast import android.widget.Toast
import androidx.fragment.app.Fragment
import androidx.fragment.app.FragmentActivity import androidx.fragment.app.FragmentActivity
import androidx.lifecycle.lifecycleScope import androidx.lifecycle.lifecycleScope
import com.lizongying.mytv.models.TVViewModel import com.lizongying.mytv.models.TVViewModel
@@ -29,6 +33,8 @@ class MainActivity : FragmentActivity(), Request.RequestListener {
private var ready = 0 private var ready = 0
private val playerFragment = PlayerFragment() private val playerFragment = PlayerFragment()
private val errorFragment = ErrorFragment() private val errorFragment = ErrorFragment()
// private val loadingFragment = LoadingFragment()
private val mainFragment = MainFragment() private val mainFragment = MainFragment()
private val infoFragment = InfoFragment() private val infoFragment = InfoFragment()
private val channelFragment = ChannelFragment() private val channelFragment = ChannelFragment()
@@ -56,47 +62,67 @@ class MainActivity : FragmentActivity(), Request.RequestListener {
override fun onCreate(savedInstanceState: Bundle?) { override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState) super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main) setContentView(R.layout.activity_main)
Request.setRequestListener(this) Request.setRequestListener(this)
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) {
val lp = window.attributes
lp.layoutInDisplayCutoutMode =
WindowManager.LayoutParams.LAYOUT_IN_DISPLAY_CUTOUT_MODE_SHORT_EDGES
window.setAttributes(lp)
}
window.addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON) window.addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON)
window.addFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN) window.addFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN)
window.decorView.systemUiVisibility = SYSTEM_UI_FLAG_HIDE_NAVIGATION window.decorView.systemUiVisibility =
SYSTEM_UI_FLAG_FULLSCREEN or
SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN or SYSTEM_UI_FLAG_HIDE_NAVIGATION or
SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION
// if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
// window.addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS)
// window.statusBarColor = Color.TRANSPARENT
// window.navigationBarColor = Color.TRANSPARENT
// }
if (savedInstanceState == null) { if (savedInstanceState == null) {
supportFragmentManager.beginTransaction() supportFragmentManager.beginTransaction()
.add(R.id.main_browse_fragment, playerFragment) .add(R.id.main_browse_fragment, playerFragment)
.add(R.id.main_browse_fragment, errorFragment) .add(R.id.main_browse_fragment, errorFragment)
// .add(R.id.main_browse_fragment, loadingFragment)
.add(R.id.main_browse_fragment, timeFragment) .add(R.id.main_browse_fragment, timeFragment)
.add(R.id.main_browse_fragment, infoFragment) .add(R.id.main_browse_fragment, infoFragment)
.add(R.id.main_browse_fragment, channelFragment) .add(R.id.main_browse_fragment, channelFragment)
.add(R.id.main_browse_fragment, mainFragment) .add(R.id.main_browse_fragment, mainFragment)
.hide(mainFragment) .hide(mainFragment)
.hide(errorFragment) .hide(errorFragment)
// .hide(loadingFragment)
.hide(timeFragment)
.commit() .commit()
} }
gestureDetector = GestureDetector(this, GestureListener()) gestureDetector = GestureDetector(this, GestureListener())
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) { // if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
val connectivityManager = // val connectivityManager =
getSystemService(Context.CONNECTIVITY_SERVICE) as ConnectivityManager // getSystemService(Context.CONNECTIVITY_SERVICE) as ConnectivityManager
connectivityManager.registerDefaultNetworkCallback(object : // connectivityManager.registerDefaultNetworkCallback(object :
ConnectivityManager.NetworkCallback() { // ConnectivityManager.NetworkCallback() {
override fun onAvailable(network: Network) { // override fun onAvailable(network: Network) {
super.onAvailable(network) // super.onAvailable(network)
Log.i(TAG, "net ${Build.VERSION.SDK_INT}") // Log.i(TAG, "net ${Build.VERSION.SDK_INT}")
if (this@MainActivity.isNetworkConnected) { // if (this@MainActivity.isNetworkConnected) {
Log.i(TAG, "net isNetworkConnected") // Log.i(TAG, "net isNetworkConnected")
ready++ // ready++
} // }
} // }
}) // })
} else { // } else {
Log.i(TAG, "net ${Build.VERSION.SDK_INT}") // Log.i(TAG, "net ${Build.VERSION.SDK_INT}")
ready++ // ready++
} // }
showTime()
mainFragment.changeMenu()
} }
fun showInfoFragment(tvViewModel: TVViewModel) { fun showInfoFragment(tvViewModel: TVViewModel) {
@@ -197,6 +223,7 @@ class MainActivity : FragmentActivity(), Request.RequestListener {
handler.removeCallbacks(hideSetting) handler.removeCallbacks(hideSetting)
handler.postDelayed(hideSetting, delayHideSetting) handler.postDelayed(hideSetting, delayHideSetting)
showTime() showTime()
mainFragment.changeMenu()
} }
fun settingNeverHide() { fun settingNeverHide() {
@@ -224,20 +251,37 @@ class MainActivity : FragmentActivity(), Request.RequestListener {
fun fragmentReady(tag: String) { fun fragmentReady(tag: String) {
ready++ ready++
Log.i(TAG, "ready $tag $ready ") Log.i(TAG, "ready $tag $ready ")
if (ready == 8) { if (ready == 7) {
mainFragment.fragmentReady() mainFragment.fragmentReady()
showTime()
} }
} }
private fun showTime() { private fun showTime() {
Log.i(TAG, "showTime ${SP.time}")
if (SP.time) { if (SP.time) {
timeFragment.show() showFragment(timeFragment)
} else { } else {
timeFragment.hide() hideFragment(timeFragment)
} }
mainFragment.changeStyle() }
private fun showFragment(fragment: Fragment) {
if (!fragment.isHidden) {
return
}
supportFragmentManager.beginTransaction()
.show(fragment)
.commitNow()
}
private fun hideFragment(fragment: Fragment) {
if (fragment.isHidden) {
return
}
supportFragmentManager.beginTransaction()
.hide(fragment)
.commitNow()
} }
override fun onTouchEvent(event: MotionEvent?): Boolean { override fun onTouchEvent(event: MotionEvent?): Boolean {
@@ -312,6 +356,7 @@ class MainActivity : FragmentActivity(), Request.RequestListener {
if (settingFragment.isVisible) { if (settingFragment.isVisible) {
settingFragment.dismiss() settingFragment.dismiss()
showTime() showTime()
mainFragment.changeMenu()
} }
} }
@@ -1,6 +1,7 @@
package com.lizongying.mytv package com.lizongying.mytv
import android.content.res.Resources import android.content.res.Resources
import android.graphics.Color
import android.os.Bundle import android.os.Bundle
import android.util.Log import android.util.Log
import android.view.KeyEvent import android.view.KeyEvent
@@ -9,7 +10,7 @@ import android.view.View
import android.view.ViewGroup import android.view.ViewGroup
import android.widget.Toast import android.widget.Toast
import androidx.core.view.marginBottom import androidx.core.view.marginBottom
import androidx.core.view.marginLeft import androidx.core.view.marginStart
import androidx.core.view.marginTop import androidx.core.view.marginTop
import androidx.fragment.app.Fragment import androidx.fragment.app.Fragment
import androidx.lifecycle.lifecycleScope import androidx.lifecycle.lifecycleScope
@@ -51,37 +52,10 @@ class MainFragment : Fragment(), CardAdapter.ItemListener {
application = requireActivity().applicationContext as MyTvApplication application = requireActivity().applicationContext as MyTvApplication
val width = application.getWidth() binding.menu.layoutParams.width = application.shouldWidthPx()
val height = application.getHeight() binding.menu.layoutParams.height = application.shouldHeightPx()
val ratio = 16f / 9f binding.container.setOnClickListener {
if (width.toFloat() / height > ratio) {
val x =
((Resources.getSystem().displayMetrics.widthPixels - height * ratio) / 2).toInt()
val originalLayoutParams =
binding.scroll.layoutParams as ViewGroup.MarginLayoutParams
originalLayoutParams.leftMargin += x
originalLayoutParams.rightMargin += x
binding.scroll.layoutParams = originalLayoutParams
Log.i(
TAG,
"binding.scroll ${Resources.getSystem().displayMetrics.widthPixels} ${height * ratio}"
)
}
if (width.toFloat() / height < ratio) {
val y =
((height - Resources.getSystem().displayMetrics.widthPixels / ratio) / 2).toInt()
val originalLayoutParams =
binding.scroll.layoutParams as ViewGroup.MarginLayoutParams
originalLayoutParams.topMargin += y
originalLayoutParams.bottomMargin += y
binding.scroll.layoutParams = originalLayoutParams
}
binding.menu.setOnClickListener {
hideSelf() hideSelf()
} }
@@ -166,7 +140,7 @@ class MainFragment : Fragment(), CardAdapter.ItemListener {
itemBinding.header.layoutParams as ViewGroup.MarginLayoutParams itemBinding.header.layoutParams as ViewGroup.MarginLayoutParams
layoutParamsHeader.topMargin = application.px2Px(itemBinding.header.marginTop) layoutParamsHeader.topMargin = application.px2Px(itemBinding.header.marginTop)
layoutParamsHeader.bottomMargin = application.px2Px(itemBinding.header.marginBottom) layoutParamsHeader.bottomMargin = application.px2Px(itemBinding.header.marginBottom)
layoutParamsHeader.leftMargin = application.px2Px(itemBinding.header.marginLeft) layoutParamsHeader.marginStart = application.px2Px(itemBinding.header.marginStart)
itemBinding.header.layoutParams = layoutParamsHeader itemBinding.header.layoutParams = layoutParamsHeader
itemBinding.header.textSize = application.px2PxFont(itemBinding.header.textSize) itemBinding.header.textSize = application.px2PxFont(itemBinding.header.textSize)
@@ -231,11 +205,11 @@ class MainFragment : Fragment(), CardAdapter.ItemListener {
} }
} }
} }
(activity as MainActivity).fragmentReady("MainFragment") (activity as MainActivity).fragmentReady(TAG)
} }
} }
fun changeStyle() { fun changeMenu() {
if (SP.grid) { if (SP.grid) {
for (i in rowList) { for (i in rowList) {
if (i is RecyclerView) { if (i is RecyclerView) {
@@ -278,7 +252,7 @@ class MainFragment : Fragment(), CardAdapter.ItemListener {
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).focusable = false ((i as RecyclerView).adapter as CardAdapter).focusable = false
((i as RecyclerView).adapter as CardAdapter).clear() (i.adapter as CardAdapter).clear()
} else { } else {
((i as RecyclerView).adapter as CardAdapter).focusable = true ((i as RecyclerView).adapter as CardAdapter).focusable = true
} }
@@ -435,13 +409,6 @@ class MainFragment : Fragment(), CardAdapter.ItemListener {
super.onResume() super.onResume()
} }
override fun onStop() {
Log.i(TAG, "onStop")
super.onStop()
SP.itemPosition = itemPosition
Log.i(TAG, "$POSITION $itemPosition saved")
}
override fun onDestroy() { override fun onDestroy() {
Log.i(TAG, "onDestroy") Log.i(TAG, "onDestroy")
super.onDestroy() super.onDestroy()
@@ -12,8 +12,12 @@ class MyTvApplication : Application() {
private lateinit var displayMetrics: DisplayMetrics private lateinit var displayMetrics: DisplayMetrics
private lateinit var realDisplayMetrics: DisplayMetrics private lateinit var realDisplayMetrics: DisplayMetrics
private lateinit var windowManager: WindowManager
private var width = 0 private var width = 0
private var height = 0 private var height = 0
private var shouldWidth = 0
private var shouldHeight = 0
private var deviation = 0 private var deviation = 0
private var ratio = 1.0 private var ratio = 1.0
private var density = 2.0f private var density = 2.0f
@@ -24,7 +28,7 @@ class MyTvApplication : Application() {
displayMetrics = DisplayMetrics() displayMetrics = DisplayMetrics()
realDisplayMetrics = DisplayMetrics() realDisplayMetrics = DisplayMetrics()
val windowManager = getSystemService(Context.WINDOW_SERVICE) as WindowManager windowManager = getSystemService(Context.WINDOW_SERVICE) as WindowManager
windowManager.defaultDisplay.getMetrics(displayMetrics) windowManager.defaultDisplay.getMetrics(displayMetrics)
windowManager.defaultDisplay.getRealMetrics(realDisplayMetrics) windowManager.defaultDisplay.getRealMetrics(realDisplayMetrics)
@@ -44,6 +48,16 @@ class MyTvApplication : Application() {
height * 2 / 1080.0 / density height * 2 / 1080.0 / density
} }
if ((width.toDouble() / height) < (16.0 / 9.0)) {
ratio = width * 2 / 1920.0 / density
shouldWidth = width
shouldHeight = (width * 9.0 / 16.0).toInt()
} else {
ratio = height * 2 / 1080.0 / density
shouldHeight = height
shouldWidth = (height * 16.0 / 9.0).toInt()
}
deviation = width - Resources.getSystem().displayMetrics.widthPixels deviation = width - Resources.getSystem().displayMetrics.widthPixels
scale = Resources.getSystem().displayMetrics.scaledDensity scale = Resources.getSystem().displayMetrics.scaledDensity
} }
@@ -56,18 +70,26 @@ class MyTvApplication : Application() {
return realDisplayMetrics return realDisplayMetrics
} }
fun shouldWidthPx(): Int {
return shouldWidth
}
fun shouldHeightPx(): Int {
return shouldHeight
}
fun getWidth(): Int { fun getWidth(): Int {
return width return width
} }
fun getDeviation(): Int {
return deviation
}
fun getHeight(): Int { fun getHeight(): Int {
return height return height
} }
fun getDeviation(): Int {
return deviation
}
fun getRatio(): Double { fun getRatio(): Double {
return ratio return ratio
} }
@@ -93,7 +93,7 @@ class PlayerFragment : Fragment(), SurfaceHolder.Callback {
}) })
} }
}) })
(activity as MainActivity).fragmentReady("PlayerFragment") (activity as MainActivity).fragmentReady(TAG)
return _binding!!.root return _binding!!.root
} }
@@ -154,7 +154,7 @@ class PlayerFragment : Fragment(), SurfaceHolder.Callback {
} }
companion object { companion object {
private const val TAG = "PlaybackVideoFragment" private const val TAG = "PlayerFragment"
} }
override fun surfaceCreated(holder: SurfaceHolder) { override fun surfaceCreated(holder: SurfaceHolder) {
@@ -101,9 +101,9 @@ class SettingFragment : DialogFragment() {
) )
binding.name.textSize = application.px2PxFont(binding.name.textSize) binding.name.textSize = application.px2PxFont(binding.name.textSize)
binding.version.textSize = application.px2PxFont(binding.version.textSize) binding.version.textSize = application.px2PxFont(binding.version.textSize)
val layoutParamsDesc = binding.version.layoutParams as ViewGroup.MarginLayoutParams val layoutParamsVersion = binding.version.layoutParams as ViewGroup.MarginLayoutParams
layoutParamsDesc.topMargin = application.px2Px(binding.version.marginTop) layoutParamsVersion.topMargin = application.px2Px(binding.version.marginTop)
binding.version.layoutParams = layoutParamsDesc binding.version.layoutParams = layoutParamsVersion
binding.checkVersion.textSize = application.px2PxFont(binding.checkVersion.textSize) binding.checkVersion.textSize = application.px2PxFont(binding.checkVersion.textSize)
val layoutParamsCheckVersion = val layoutParamsCheckVersion =
@@ -6,7 +6,7 @@ import android.os.Handler
import android.view.LayoutInflater import android.view.LayoutInflater
import android.view.View import android.view.View
import android.view.ViewGroup import android.view.ViewGroup
import androidx.core.view.marginRight import androidx.core.view.marginEnd
import androidx.core.view.marginTop import androidx.core.view.marginTop
import androidx.fragment.app.Fragment import androidx.fragment.app.Fragment
import com.lizongying.mytv.Utils.getDateFormat import com.lizongying.mytv.Utils.getDateFormat
@@ -27,52 +27,33 @@ class TimeFragment : Fragment() {
val application = requireActivity().applicationContext as MyTvApplication val application = requireActivity().applicationContext as MyTvApplication
val width = application.getWidth()
val height = application.getHeight()
val ratio = 16f / 9f
if (width.toFloat() / height > ratio) {
val x =
((Resources.getSystem().displayMetrics.widthPixels - height * ratio) / 2).toInt()
val originalLayoutParams = binding.time.layoutParams as ViewGroup.MarginLayoutParams
originalLayoutParams.rightMargin += x
binding.time.layoutParams = originalLayoutParams
}
if (width.toFloat() / height < ratio) {
val y =
((height - Resources.getSystem().displayMetrics.widthPixels / ratio) / 2).toInt()
val originalLayoutParams = binding.time.layoutParams as ViewGroup.MarginLayoutParams
originalLayoutParams.topMargin += y
binding.time.layoutParams = originalLayoutParams
}
binding.time.layoutParams.width = application.px2Px(binding.time.layoutParams.width) binding.time.layoutParams.width = application.px2Px(binding.time.layoutParams.width)
binding.time.layoutParams.height = application.px2Px(binding.time.layoutParams.height) binding.time.layoutParams.height = application.px2Px(binding.time.layoutParams.height)
val layoutParams = binding.time.layoutParams as ViewGroup.MarginLayoutParams val layoutParams = binding.time.layoutParams as ViewGroup.MarginLayoutParams
layoutParams.topMargin = application.px2Px(binding.time.marginTop) layoutParams.topMargin = application.px2Px(binding.time.marginTop)
layoutParams.rightMargin = application.px2Px(binding.time.marginRight) layoutParams.marginEnd = application.px2Px(binding.time.marginEnd)
binding.time.layoutParams = layoutParams binding.time.layoutParams = layoutParams
binding.content.textSize = application.px2PxFont(binding.content.textSize) binding.content.textSize = application.px2PxFont(binding.content.textSize)
(activity as MainActivity).fragmentReady("TimeFragment") binding.main.layoutParams.width = application.shouldWidthPx()
binding.main.layoutParams.height = application.shouldHeightPx()
(activity as MainActivity).fragmentReady(TAG)
return binding.root return binding.root
} }
override fun onResume() { override fun onHiddenChanged(hidden: Boolean) {
super.onResume() super.onHiddenChanged(hidden)
if (view?.visibility == View.VISIBLE) { if (!hidden) {
handler.removeCallbacks(showRunnable) handler.removeCallbacks(showRunnable)
handler.postDelayed(showRunnable, 0) handler.postDelayed(showRunnable, 0)
} else {
handler.removeCallbacks(showRunnable)
} }
} }
override fun onPause() {
super.onPause()
handler.removeCallbacks(showRunnable)
}
private val showRunnable: Runnable = Runnable { private val showRunnable: Runnable = Runnable {
run { run {
if (_binding == null) { if (_binding == null) {
@@ -83,17 +64,6 @@ class TimeFragment : Fragment() {
} }
} }
fun show() {
view?.visibility = View.VISIBLE
handler.removeCallbacks(showRunnable)
handler.postDelayed(showRunnable, 0)
}
fun hide() {
view?.visibility = View.GONE
handler.removeCallbacks(showRunnable)
}
override fun onDestroyView() { override fun onDestroyView() {
handler.removeCallbacks(showRunnable) handler.removeCallbacks(showRunnable)
super.onDestroyView() super.onDestroyView()
@@ -3,6 +3,7 @@ package com.lizongying.mytv.models
import androidx.lifecycle.LiveData import androidx.lifecycle.LiveData
import androidx.lifecycle.MutableLiveData import androidx.lifecycle.MutableLiveData
import androidx.lifecycle.ViewModel import androidx.lifecycle.ViewModel
import com.lizongying.mytv.SP
class TVListViewModel : ViewModel() { class TVListViewModel : ViewModel() {
@@ -30,6 +31,7 @@ class TVListViewModel : ViewModel() {
fun setItemPosition(position: Int) { fun setItemPosition(position: Int) {
_itemPosition.value = position _itemPosition.value = position
SP.itemPosition = position
} }
fun size(): Int { fun size(): Int {
@@ -16,6 +16,8 @@ class TVViewModel(private var tv: TV) : ViewModel() {
var retryTimes = 0 var retryTimes = 0
var retryMaxTimes = 8 var retryMaxTimes = 8
var authYSPRetryTimes = 0
var authYSPRetryMaxTimes = 3
var tokenYSPRetryTimes = 0 var tokenYSPRetryTimes = 0
var tokenYSPRetryMaxTimes = 0 var tokenYSPRetryMaxTimes = 0
var tokenFHRetryTimes = 0 var tokenFHRetryTimes = 0
@@ -64,6 +66,10 @@ class TVViewModel(private var tv: TV) : ViewModel() {
} }
fun changed(from: String) { fun changed(from: String) {
retryTimes = 0
authYSPRetryTimes = 0
tokenYSPRetryTimes = 0
tokenFHRetryTimes = 0
_change.value = from _change.value = from
} }
@@ -119,7 +119,9 @@ object Request {
if (!tvModel.getTV().mustToken) { if (!tvModel.getTV().mustToken) {
fetchAuth(tvModel, cookie) fetchAuth(tvModel, cookie)
} else { } else {
// TODO val err = "错误"
Log.e(TAG, "$title $err")
tvModel.setErrInfo(err)
} }
} }
} else { } else {
@@ -144,7 +146,9 @@ object Request {
if (!tvModel.getTV().mustToken) { if (!tvModel.getTV().mustToken) {
fetchAuth(tvModel, cookie) fetchAuth(tvModel, cookie)
} else { } else {
// TODO val err = "错误"
Log.e(TAG, "$title $err")
tvModel.setErrInfo(err)
} }
} }
} else { } else {
@@ -171,7 +175,9 @@ object Request {
if (!tvModel.getTV().mustToken) { if (!tvModel.getTV().mustToken) {
fetchAuth(tvModel, cookie) fetchAuth(tvModel, cookie)
} else { } else {
// TODO val err = "错误"
Log.e(TAG, "$title $err")
tvModel.setErrInfo(err)
} }
} }
} else { } else {
@@ -241,19 +247,30 @@ object Request {
if (needToken && tvModel.tokenYSPRetryTimes < tvModel.tokenYSPRetryMaxTimes) { if (needToken && tvModel.tokenYSPRetryTimes < tvModel.tokenYSPRetryMaxTimes) {
tvModel.tokenYSPRetryTimes++ tvModel.tokenYSPRetryTimes++
tvModel.needGetToken = true tvModel.needGetToken = true
fetchVideo(tvModel) if (needAuth) {
// fetchAuth(tvModel) fetchAuth(tvModel)
} else {
fetchVideo(tvModel)
}
} else { } else {
if (!tvModel.getTV().mustToken) { if (!tvModel.getTV().mustToken) {
fetchVideo(tvModel, cookie) if (needAuth) {
// fetchAuth(tvModel, cookie) fetchAuth(tvModel, cookie)
} else {
fetchVideo(tvModel, cookie)
}
} else { } else {
// TODO val err = "错误"
Log.e(TAG, "$title $err")
tvModel.setErrInfo(err)
} }
} }
} else { } else {
fetchVideo(tvModel, cookie) if (needAuth) {
// fetchAuth(tvModel, cookie) fetchAuth(tvModel, cookie)
} else {
fetchVideo(tvModel, cookie)
}
} }
} else { } else {
val err = "结果错误" val err = "结果错误"
@@ -274,19 +291,30 @@ object Request {
if (needToken && tvModel.tokenYSPRetryTimes < tvModel.tokenYSPRetryMaxTimes) { if (needToken && tvModel.tokenYSPRetryTimes < tvModel.tokenYSPRetryMaxTimes) {
tvModel.tokenYSPRetryTimes++ tvModel.tokenYSPRetryTimes++
tvModel.needGetToken = true tvModel.needGetToken = true
fetchVideo(tvModel) if (needAuth) {
// fetchAuth(tvModel) fetchAuth(tvModel)
} else {
fetchVideo(tvModel)
}
} else { } else {
if (!tvModel.getTV().mustToken) { if (!tvModel.getTV().mustToken) {
fetchVideo(tvModel, cookie) if (needAuth) {
// fetchAuth(tvModel, cookie) fetchAuth(tvModel, cookie)
} else {
fetchVideo(tvModel, cookie)
}
} else { } else {
// TODO val err = "错误"
Log.e(TAG, "$title $err")
tvModel.setErrInfo(err)
} }
} }
} else { } else {
fetchVideo(tvModel, cookie) if (needAuth) {
// fetchAuth(tvModel, cookie) fetchAuth(tvModel, cookie)
} else {
fetchVideo(tvModel, cookie)
}
} }
} else { } else {
val err = "其他错误" val err = "其他错误"
@@ -303,19 +331,30 @@ object Request {
if (needToken && tvModel.tokenYSPRetryTimes < tvModel.tokenYSPRetryMaxTimes) { if (needToken && tvModel.tokenYSPRetryTimes < tvModel.tokenYSPRetryMaxTimes) {
tvModel.tokenYSPRetryTimes++ tvModel.tokenYSPRetryTimes++
tvModel.needGetToken = true tvModel.needGetToken = true
fetchVideo(tvModel) if (needAuth) {
// fetchAuth(tvModel) fetchAuth(tvModel, cookie)
} else {
fetchVideo(tvModel, cookie)
}
} else { } else {
if (!tvModel.getTV().mustToken) { if (!tvModel.getTV().mustToken) {
fetchVideo(tvModel, cookie) if (needAuth) {
// fetchAuth(tvModel, cookie) fetchAuth(tvModel, cookie)
} else {
fetchVideo(tvModel, cookie)
}
} else { } else {
// TODO val err = "错误"
Log.e(TAG, "$title $err")
tvModel.setErrInfo(err)
} }
} }
} else { } else {
fetchVideo(tvModel, cookie) if (needAuth) {
// fetchAuth(tvModel, cookie) fetchAuth(tvModel, cookie)
} else {
fetchVideo(tvModel, cookie)
}
} }
} else { } else {
val err = "状态错误" val err = "状态错误"
+1 -1
View File
@@ -1,4 +1,4 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android" xmlns:aapt="http://schemas.android.com/aapt" <vector xmlns:android="http://schemas.android.com/apk/res/android"
android:viewportWidth="50" android:viewportWidth="50"
android:viewportHeight="50" android:viewportHeight="50"
android:width="62.5dp" android:width="62.5dp"
+29 -16
View File
@@ -1,18 +1,31 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android" <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/channel" android:layout_width="match_parent"
android:layout_width="90dp" android:layout_height="match_parent"
android:layout_height="60dp" android:gravity="center"
android:layout_gravity="end|top" >
android:layout_marginTop="20dp" <FrameLayout
android:layout_marginEnd="170dp"> android:id="@+id/main"
android:layout_width="match_parent"
android:layout_height="match_parent"
>
<TextView <FrameLayout
android:id="@+id/content" android:id="@+id/channel"
android:layout_width="wrap_content" android:layout_width="90dp"
android:layout_height="wrap_content" android:layout_height="60dp"
android:layout_gravity="end" android:layout_gravity="end|top"
android:textColor="#FFEEEEEE" android:layout_marginTop="20dp"
android:textStyle="bold" android:layout_marginEnd="170dp">
android:textSize="40sp" />
</FrameLayout> <TextView
android:id="@+id/content"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="end"
android:textColor="@color/white"
android:textStyle="bold"
android:textSize="40sp" />
</FrameLayout>
</FrameLayout>
</LinearLayout>
+3 -3
View File
@@ -2,14 +2,14 @@
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android" <FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/error" android:id="@+id/error"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent" > android:layout_height="match_parent"
android:background="@color/black" >
<LinearLayout <LinearLayout
android:id="@+id/main" android:id="@+id/main"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent" android:layout_height="match_parent"
android:layout_gravity="center_horizontal" android:gravity="center"
android:gravity="center_vertical|center_horizontal"
android:orientation="vertical" > android:orientation="vertical" >
<ImageView <ImageView
+55 -41
View File
@@ -1,46 +1,60 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android" <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/info" android:layout_width="match_parent"
android:layout_width="400dp" android:layout_height="match_parent"
android:layout_height="80dp" android:gravity="center"
android:layout_gravity="center_horizontal|bottom" >
android:layout_marginBottom="20dp"> <FrameLayout
android:id="@+id/container"
<ImageView android:layout_width="match_parent"
android:id="@+id/logo"
android:layout_width="100dp"
android:layout_height="match_parent" android:layout_height="match_parent"
android:background="@drawable/rounded_white_left" >
android:padding="10dp" />
<LinearLayout <LinearLayout
android:id="@+id/main" android:id="@+id/info"
android:layout_width="300dp" android:layout_width="400dp"
android:layout_height="match_parent" android:layout_height="80dp"
android:layout_marginStart="100dp" android:layout_gravity="center_horizontal|bottom"
android:background="@drawable/rounded_dark_right" android:layout_marginBottom="20dp"
android:gravity="start|center_vertical" android:orientation="horizontal">
android:orientation="vertical"
android:padding="7dp">
<TextView <ImageView
android:id="@+id/title" android:id="@+id/logo"
android:layout_width="wrap_content" android:layout_width="100dp"
android:layout_height="wrap_content" android:layout_height="match_parent"
android:layout_gravity="start" android:background="@drawable/rounded_white_left"
android:gravity="start" android:padding="10dp" />
android:textColor="#FFEEEEEE"
android:textSize="20sp" />
<TextView <LinearLayout
android:id="@+id/desc" android:id="@+id/main"
android:layout_width="wrap_content" android:layout_width="300dp"
android:layout_height="wrap_content" android:layout_height="match_parent"
android:layout_gravity="start" android:layout_marginStart="0dp"
android:layout_marginTop="8dp" android:background="@drawable/rounded_dark_right"
android:gravity="start" android:gravity="start|center_vertical"
android:singleLine="true" android:orientation="vertical"
android:textColor="#B3EEEEEE" android:padding="7dp">
android:textSize="14sp" />
</LinearLayout> <TextView
</FrameLayout> android:id="@+id/title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="start"
android:gravity="start"
android:textColor="#FFEEEEEE"
android:textSize="20sp" />
<TextView
android:id="@+id/desc"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="start"
android:layout_marginTop="8dp"
android:gravity="start"
android:singleLine="true"
android:textColor="#B3EEEEEE"
android:textSize="14sp" />
</LinearLayout>
</LinearLayout>
</FrameLayout>
</LinearLayout>
+21
View File
@@ -0,0 +1,21 @@
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/loading"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/black"
>
<LinearLayout
android:id="@+id/main"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center" >
<ProgressBar
android:id="@+id/bar"
android:layout_width="50dp"
android:layout_height="50dp"
android:indeterminateTint="@color/white"/>
</LinearLayout>
</FrameLayout>
+25 -14
View File
@@ -1,21 +1,32 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android" <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/menu" android:id="@+id/container"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent" android:layout_height="match_parent"
android:background="@android:color/transparent" android:background="@android:color/transparent"
android:clickable="true" android:clickable="true"
android:focusable="false" android:focusable="false"
> android:gravity="center"
<ScrollView >
android:id="@+id/scroll"
<FrameLayout
android:id="@+id/menu"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent"> android:layout_height="match_parent"
<LinearLayout >
android:id="@+id/content"
android:layout_width="match_parent" <ScrollView
android:layout_height="wrap_content" android:id="@+id/scroll"
android:orientation="vertical"> android:layout_width="wrap_content"
</LinearLayout> android:layout_height="wrap_content"
</ScrollView> >
</FrameLayout> <LinearLayout
android:id="@+id/content"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical">
</LinearLayout>
</ScrollView>
</FrameLayout>
</LinearLayout>
+2 -2
View File
@@ -13,8 +13,8 @@
android:layout_height="match_parent" android:layout_height="match_parent"
android:orientation="vertical" android:orientation="vertical"
android:paddingTop="20dp" android:paddingTop="20dp"
android:paddingLeft="7dp" android:paddingLeft="10dp"
android:paddingRight="7dp" android:paddingRight="10dp"
android:background="@drawable/rounded_dark_left" android:background="@drawable/rounded_dark_left"
> >
<TextView <TextView
+30 -16
View File
@@ -1,18 +1,32 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android" <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/time" android:layout_width="match_parent"
android:layout_width="100dp" android:layout_height="match_parent"
android:layout_height="40dp" android:gravity="center"
android:layout_gravity="end|top" >
android:layout_marginTop="25dp" <FrameLayout
android:layout_marginEnd="50dp"> android:id="@+id/main"
android:layout_width="match_parent"
android:layout_height="match_parent"
>
<TextView <FrameLayout
android:id="@+id/content" android:id="@+id/time"
android:layout_width="wrap_content" android:layout_width="100dp"
android:layout_height="wrap_content" android:layout_height="40dp"
android:layout_gravity="end" android:layout_gravity="end|top"
android:textColor="#FFEEEEEE" android:layout_marginTop="25dp"
android:textStyle="bold" android:layout_marginEnd="50dp">
android:textSize="32sp" />
</FrameLayout> <TextView
android:id="@+id/content"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="end"
android:textColor="@color/white"
android:textStyle="bold"
android:textSize="32sp" />
</FrameLayout>
</FrameLayout>
</LinearLayout>
+1
View File
@@ -1,5 +1,6 @@
<resources> <resources>
<style name="Theme.MyTV" parent="@style/Theme.Leanback"> <style name="Theme.MyTV" parent="@style/Theme.Leanback">
<item name="android:fitsSystemWindows">false</item>
</style> </style>
</resources> </resources>