mirror of
https://github.com/lizongying/my-tv.git
synced 2026-10-26 22:26:29 +08:00
optimize style
This commit is contained in:
@@ -119,6 +119,7 @@ dependencies {
|
||||
implementation 'androidx.multidex:multidex:2.0.1'
|
||||
implementation 'androidx.leanback:leanback:1.2.0-alpha02'
|
||||
implementation "androidx.lifecycle:lifecycle-runtime-ktx:2.6.2"
|
||||
implementation("androidx.constraintlayout:constraintlayout:2.1.4")
|
||||
|
||||
implementation "org.jetbrains.kotlinx:kotlinx-serialization-json:1.6.2"
|
||||
implementation("org.jetbrains.kotlinx:kotlinx-coroutines-android:1.8.0-RC")
|
||||
|
||||
@@ -14,7 +14,7 @@
|
||||
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
|
||||
|
||||
<application
|
||||
android:name=".MyApplication"
|
||||
android:name=".MyTvApplication"
|
||||
android:allowBackup="true"
|
||||
android:banner="@drawable/banner"
|
||||
android:icon="@drawable/logo"
|
||||
|
||||
@@ -1,16 +1,15 @@
|
||||
package com.lizongying.mytv
|
||||
|
||||
import android.graphics.Color
|
||||
import android.view.ContextThemeWrapper
|
||||
import android.view.KeyEvent
|
||||
import android.view.LayoutInflater
|
||||
import android.view.View
|
||||
import android.view.ViewGroup
|
||||
import android.view.animation.ScaleAnimation
|
||||
import android.widget.ImageView
|
||||
import androidx.core.view.updatePadding
|
||||
import androidx.leanback.widget.ImageCardView
|
||||
import androidx.core.view.marginTop
|
||||
import androidx.core.view.setPadding
|
||||
import androidx.recyclerview.widget.RecyclerView
|
||||
import com.bumptech.glide.Glide
|
||||
import com.lizongying.mytv.databinding.CardBinding
|
||||
import com.lizongying.mytv.models.TVListViewModel
|
||||
import com.lizongying.mytv.models.TVViewModel
|
||||
|
||||
@@ -25,15 +24,30 @@ class CardAdapter(
|
||||
private var listener: ItemListener? = null
|
||||
private var focused: View? = null
|
||||
|
||||
var visiable = false
|
||||
var focusable = false
|
||||
|
||||
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ViewHolder {
|
||||
val cardView = object :
|
||||
ImageCardView(ContextThemeWrapper(parent.context, R.style.CustomImageCardTheme)) {}
|
||||
val inflater = LayoutInflater.from(parent.context)
|
||||
val binding = CardBinding.inflate(inflater, parent, false)
|
||||
|
||||
val application = mainFragment.requireActivity().applicationContext as MyTvApplication
|
||||
|
||||
binding.card.layoutParams.width = application.px2Px(binding.card.layoutParams.width)
|
||||
binding.card.layoutParams.height = application.px2Px(binding.card.layoutParams.height)
|
||||
binding.icon.layoutParams.height = application.px2Px(binding.icon.layoutParams.height)
|
||||
binding.icon.setPadding(application.px2Px(binding.icon.paddingTop))
|
||||
binding.main.layoutParams.height = application.px2Px(binding.main.layoutParams.height)
|
||||
binding.main.setPadding(application.px2Px(binding.main.paddingTop))
|
||||
binding.title.textSize = application.px2PxFont(binding.title.textSize)
|
||||
binding.desc.textSize = application.px2PxFont(binding.desc.textSize)
|
||||
val layoutParams = binding.desc.layoutParams as ViewGroup.MarginLayoutParams
|
||||
layoutParams.topMargin = application.px2Px(binding.desc.marginTop)
|
||||
binding.desc.layoutParams = layoutParams
|
||||
|
||||
val cardView = binding.root
|
||||
cardView.isFocusable = true
|
||||
cardView.isFocusableInTouchMode = true
|
||||
cardView.updatePadding(1, 0, 1, 0)
|
||||
return ViewHolder(cardView)
|
||||
return ViewHolder(cardView, binding)
|
||||
}
|
||||
|
||||
fun clear() {
|
||||
@@ -57,7 +71,7 @@ class CardAdapter(
|
||||
val item = tvListViewModel.getTVViewModel(position)
|
||||
|
||||
val tvViewModel = item as TVViewModel
|
||||
val cardView = viewHolder.view as ImageCardView
|
||||
val cardView = viewHolder.view
|
||||
cardView.tag = tvViewModel
|
||||
|
||||
val onFocusChangeListener = View.OnFocusChangeListener { view, hasFocus ->
|
||||
@@ -65,16 +79,12 @@ class CardAdapter(
|
||||
listener?.onItemHasFocus(item)
|
||||
focused = cardView
|
||||
|
||||
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
|
||||
// }
|
||||
if (focusable) {
|
||||
startScaleAnimation(cardView, 0.9f, 1.0f, 200)
|
||||
viewHolder.focus(true)
|
||||
}
|
||||
} else {
|
||||
viewHolder.focus(false)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -91,30 +101,35 @@ class CardAdapter(
|
||||
false
|
||||
}
|
||||
|
||||
cardView.titleText = tvViewModel.getTV().title
|
||||
viewHolder.binding.title.text = tvViewModel.getTV().title
|
||||
|
||||
cardView.mainImageView?.let {
|
||||
viewHolder.binding.icon.let {
|
||||
Glide.with(viewHolder.view.context)
|
||||
.load(tvViewModel.getTV().logo)
|
||||
.centerInside()
|
||||
.into(it)
|
||||
}
|
||||
|
||||
cardView.mainImageView?.setBackgroundColor(Color.WHITE)
|
||||
cardView.setMainImageScaleType(ImageView.ScaleType.CENTER_INSIDE)
|
||||
|
||||
val epg = tvViewModel.epg.value?.filter { it.beginTime < Utils.getDateTimestamp() }
|
||||
if (!epg.isNullOrEmpty()) {
|
||||
cardView.contentText = epg.last().title
|
||||
viewHolder.binding.desc.text = epg.last().title
|
||||
} else {
|
||||
cardView.contentText = ""
|
||||
viewHolder.binding.desc.text = ""
|
||||
}
|
||||
}
|
||||
|
||||
override fun getItemCount() = tvListViewModel.size()
|
||||
|
||||
class ViewHolder(itemView: View) : RecyclerView.ViewHolder(itemView) {
|
||||
class ViewHolder(itemView: View, var binding: CardBinding) : RecyclerView.ViewHolder(itemView) {
|
||||
val view = itemView
|
||||
|
||||
fun focus(hasFocus: Boolean) {
|
||||
if (hasFocus) {
|
||||
binding.main.setBackgroundResource(R.drawable.rounded_light_bottom)
|
||||
} else {
|
||||
binding.main.setBackgroundResource(R.drawable.rounded_dark_bottom)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fun toPosition(position: Int) {
|
||||
|
||||
@@ -1,10 +1,13 @@
|
||||
package com.lizongying.mytv
|
||||
|
||||
import android.content.res.Resources
|
||||
import android.os.Bundle
|
||||
import android.os.Handler
|
||||
import android.view.LayoutInflater
|
||||
import android.view.View
|
||||
import android.view.ViewGroup
|
||||
import androidx.core.view.marginRight
|
||||
import androidx.core.view.marginTop
|
||||
import androidx.fragment.app.Fragment
|
||||
import com.lizongying.mytv.databinding.ChannelBinding
|
||||
import com.lizongying.mytv.models.TVViewModel
|
||||
@@ -14,7 +17,7 @@ class ChannelFragment : Fragment() {
|
||||
private val binding get() = _binding!!
|
||||
|
||||
private val handler = Handler()
|
||||
private val delay: Long = 3000
|
||||
private val delay: Long = 5000
|
||||
private var channel = 0
|
||||
private var channelCount = 0
|
||||
|
||||
@@ -25,37 +28,39 @@ class ChannelFragment : Fragment() {
|
||||
_binding = ChannelBinding.inflate(inflater, container, false)
|
||||
_binding!!.root.visibility = View.GONE
|
||||
|
||||
val activity = requireActivity()
|
||||
val application = activity.applicationContext as MyApplication
|
||||
val displayMetrics = application.getDisplayMetrics()
|
||||
val application = requireActivity().applicationContext as MyTvApplication
|
||||
|
||||
displayMetrics.density
|
||||
|
||||
var screenWidth = displayMetrics.widthPixels
|
||||
var screenHeight = displayMetrics.heightPixels
|
||||
if (screenHeight > screenWidth) {
|
||||
screenWidth = displayMetrics.heightPixels
|
||||
screenHeight = displayMetrics.widthPixels
|
||||
}
|
||||
val width = application.getWidth()
|
||||
val height = application.getHeight()
|
||||
|
||||
val ratio = 16f / 9f
|
||||
|
||||
if (screenWidth / screenHeight > ratio) {
|
||||
val x = ((screenWidth - screenHeight * ratio) / 2).toInt()
|
||||
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 (screenWidth / screenHeight < ratio) {
|
||||
val y = ((screenHeight - screenWidth / ratio) / 2).toInt()
|
||||
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.height = application.px2Px(binding.channel.layoutParams.height)
|
||||
val layoutParams = binding.channel.layoutParams as ViewGroup.MarginLayoutParams
|
||||
layoutParams.topMargin = application.px2Px(binding.channel.marginTop)
|
||||
layoutParams.rightMargin = application.px2Px(binding.channel.marginRight)
|
||||
binding.channel.layoutParams = layoutParams
|
||||
binding.content.textSize = application.px2PxFont(binding.content.textSize)
|
||||
|
||||
(activity as MainActivity).fragmentReady("ChannelFragment")
|
||||
return binding.root
|
||||
}
|
||||
|
||||
@@ -1,54 +0,0 @@
|
||||
package com.lizongying.mytv
|
||||
|
||||
import android.content.Context
|
||||
import android.graphics.Canvas
|
||||
import android.graphics.Paint
|
||||
import android.graphics.Rect
|
||||
import android.view.View
|
||||
import androidx.core.content.ContextCompat
|
||||
import androidx.leanback.widget.ImageCardView
|
||||
import androidx.recyclerview.widget.RecyclerView
|
||||
|
||||
class GrayOverlayItemDecoration(private val context: Context) : RecyclerView.ItemDecoration() {
|
||||
|
||||
private val grayOverlayPaint = Paint().apply {
|
||||
color = ContextCompat.getColor(context, R.color.gray_overlay)
|
||||
style = Paint.Style.FILL
|
||||
}
|
||||
|
||||
override fun onDrawOver(c: Canvas, parent: RecyclerView, state: RecyclerView.State) {
|
||||
super.onDrawOver(c, parent, state)
|
||||
|
||||
val childCount = parent.childCount
|
||||
for (i in 0 until childCount) {
|
||||
val child = parent.getChildAt(i)
|
||||
if (!child.hasFocus()) {
|
||||
(child as ImageCardView).setInfoAreaBackgroundColor(ContextCompat.getColor(context, R.color.blur))
|
||||
// child.alpha = 0.5f
|
||||
// 计算遮罩层的大小
|
||||
// val overlayRect = Rect(
|
||||
// child.left,
|
||||
// child.top,
|
||||
// child.right,
|
||||
// child.bottom
|
||||
// )
|
||||
// // 绘制灰色遮罩层
|
||||
// c.drawRect(overlayRect, grayOverlayPaint)
|
||||
} else {
|
||||
(child as ImageCardView).setInfoAreaBackgroundColor(ContextCompat.getColor(context, R.color.focus))
|
||||
// child.alpha = 1f
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
override fun getItemOffsets(
|
||||
outRect: Rect,
|
||||
view: View,
|
||||
parent: RecyclerView,
|
||||
state: RecyclerView.State
|
||||
) {
|
||||
super.getItemOffsets(outRect, view, parent, state)
|
||||
// 在此处设置偏移量为0,以防止遮罩层影响项的布局
|
||||
outRect.setEmpty()
|
||||
}
|
||||
}
|
||||
@@ -1,11 +1,16 @@
|
||||
package com.lizongying.mytv
|
||||
|
||||
import android.content.res.Resources
|
||||
import android.os.Bundle
|
||||
import android.os.Handler
|
||||
import android.util.Log
|
||||
import android.view.LayoutInflater
|
||||
import android.view.View
|
||||
import android.view.ViewGroup
|
||||
import androidx.core.view.marginBottom
|
||||
import androidx.core.view.marginLeft
|
||||
import androidx.core.view.marginTop
|
||||
import androidx.core.view.setPadding
|
||||
import androidx.fragment.app.Fragment
|
||||
import com.bumptech.glide.Glide
|
||||
import com.lizongying.mytv.databinding.InfoBinding
|
||||
@@ -16,7 +21,7 @@ class InfoFragment : Fragment() {
|
||||
private val binding get() = _binding!!
|
||||
|
||||
private val handler = Handler()
|
||||
private val delay: Long = 3000
|
||||
private val delay: Long = 5000
|
||||
|
||||
override fun onCreateView(
|
||||
inflater: LayoutInflater, container: ViewGroup?,
|
||||
@@ -24,28 +29,39 @@ class InfoFragment : Fragment() {
|
||||
): View {
|
||||
_binding = InfoBinding.inflate(inflater, container, false)
|
||||
|
||||
val activity = requireActivity()
|
||||
val application = activity.applicationContext as MyApplication
|
||||
val displayMetrics = application.getDisplayMetrics()
|
||||
|
||||
displayMetrics.density
|
||||
|
||||
var screenWidth = displayMetrics.widthPixels
|
||||
var screenHeight = displayMetrics.heightPixels
|
||||
if (screenHeight > screenWidth) {
|
||||
screenWidth = displayMetrics.heightPixels
|
||||
screenHeight = displayMetrics.widthPixels
|
||||
}
|
||||
val application = requireActivity().applicationContext as MyTvApplication
|
||||
val width = application.getWidth()
|
||||
val height = application.getHeight()
|
||||
|
||||
val ratio = 16f / 9f
|
||||
|
||||
if (screenWidth / screenHeight < ratio) {
|
||||
val y = ((screenHeight - screenWidth / ratio) / 2).toInt()
|
||||
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.height = application.px2Px(binding.info.layoutParams.height)
|
||||
val layoutParams = binding.info.layoutParams as ViewGroup.MarginLayoutParams
|
||||
layoutParams.bottomMargin = application.px2Px(binding.info.marginBottom)
|
||||
binding.info.layoutParams = layoutParams
|
||||
binding.logo.layoutParams.width = application.px2Px(binding.logo.layoutParams.width)
|
||||
binding.logo.setPadding(application.px2Px(binding.logo.paddingTop))
|
||||
binding.main.layoutParams.width = application.px2Px(binding.main.layoutParams.width)
|
||||
binding.main.setPadding(application.px2Px(binding.main.paddingTop))
|
||||
val layoutParamsMain = binding.main.layoutParams as ViewGroup.MarginLayoutParams
|
||||
layoutParamsMain.leftMargin = application.px2Px(binding.main.marginLeft)
|
||||
binding.main.layoutParams = layoutParamsMain
|
||||
|
||||
val layoutParamsDesc = binding.desc.layoutParams as ViewGroup.MarginLayoutParams
|
||||
layoutParamsDesc.topMargin = application.px2Px(binding.desc.marginTop)
|
||||
binding.desc.layoutParams = layoutParamsDesc
|
||||
binding.title.textSize = application.px2PxFont(binding.title.textSize)
|
||||
binding.desc.textSize = application.px2PxFont(binding.desc.textSize)
|
||||
|
||||
_binding!!.root.visibility = View.GONE
|
||||
|
||||
(activity as MainActivity).fragmentReady("InfoFragment")
|
||||
@@ -53,18 +69,18 @@ class InfoFragment : Fragment() {
|
||||
}
|
||||
|
||||
fun show(tvViewModel: TVViewModel) {
|
||||
binding.textView.text = tvViewModel.getTV().title
|
||||
binding.title.text = tvViewModel.getTV().title
|
||||
|
||||
Glide.with(this)
|
||||
.load(tvViewModel.getTV().logo)
|
||||
.into(binding.infoLogo)
|
||||
.into(binding.logo)
|
||||
|
||||
Log.i(TAG, "${tvViewModel.getTV().title} ${tvViewModel.epg.value}")
|
||||
val epg = tvViewModel.epg.value?.filter { it.beginTime < Utils.getDateTimestamp() }
|
||||
if (!epg.isNullOrEmpty()) {
|
||||
binding.infoDesc.text = epg.last().title
|
||||
binding.desc.text = epg.last().title
|
||||
} else {
|
||||
binding.infoDesc.text = ""
|
||||
binding.desc.text = ""
|
||||
}
|
||||
|
||||
handler.removeCallbacks(removeRunnable)
|
||||
|
||||
@@ -0,0 +1,29 @@
|
||||
package com.lizongying.mytv
|
||||
|
||||
import android.content.Context
|
||||
import android.graphics.Rect
|
||||
import android.view.View
|
||||
import androidx.recyclerview.widget.RecyclerView
|
||||
|
||||
class ItemDecoration(context: Context) : RecyclerView.ItemDecoration() {
|
||||
|
||||
private var application: MyTvApplication
|
||||
|
||||
init {
|
||||
application = context.applicationContext as MyTvApplication
|
||||
}
|
||||
|
||||
override fun getItemOffsets(
|
||||
outRect: Rect,
|
||||
view: View,
|
||||
parent: RecyclerView,
|
||||
state: RecyclerView.State
|
||||
) {
|
||||
super.getItemOffsets(outRect, view, parent, state)
|
||||
val space = application.dp2Px(5)
|
||||
outRect.top = space
|
||||
outRect.bottom = space
|
||||
outRect.left = space
|
||||
outRect.right = space
|
||||
}
|
||||
}
|
||||
@@ -42,12 +42,13 @@ class MainActivity : FragmentActivity(), Request.RequestListener {
|
||||
private val delayHideSetting: Long = 10000
|
||||
|
||||
init {
|
||||
Utils.setRequestListener(this)
|
||||
}
|
||||
|
||||
private fun syncTime() {
|
||||
lifecycleScope.launch(Dispatchers.IO) {
|
||||
val utilsJob = async(start = CoroutineStart.LAZY) { Utils.init() }
|
||||
|
||||
utilsJob.start()
|
||||
|
||||
// utilsJob.await()
|
||||
}
|
||||
}
|
||||
|
||||
@@ -93,7 +94,6 @@ class MainActivity : FragmentActivity(), Request.RequestListener {
|
||||
Log.i(TAG, "net ${Build.VERSION.SDK_INT}")
|
||||
ready++
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
fun showInfoFragment(tvViewModel: TVViewModel) {
|
||||
@@ -119,7 +119,6 @@ class MainActivity : FragmentActivity(), Request.RequestListener {
|
||||
|
||||
fun play(tvViewModel: TVViewModel) {
|
||||
playerFragment.play(tvViewModel)
|
||||
mainFragment.view?.requestFocus()
|
||||
}
|
||||
|
||||
fun play(itemPosition: Int) {
|
||||
@@ -134,14 +133,6 @@ class MainActivity : FragmentActivity(), Request.RequestListener {
|
||||
mainFragment.next()
|
||||
}
|
||||
|
||||
private fun prevSource() {
|
||||
// mainFragment.prevSource()
|
||||
}
|
||||
|
||||
private fun nextSource() {
|
||||
// mainFragment.nextSource()
|
||||
}
|
||||
|
||||
fun switchMainFragment() {
|
||||
val transaction = supportFragmentManager.beginTransaction()
|
||||
|
||||
@@ -192,7 +183,7 @@ class MainActivity : FragmentActivity(), Request.RequestListener {
|
||||
fun fragmentReady(tag: String) {
|
||||
ready++
|
||||
Log.i(TAG, "ready $tag $ready ")
|
||||
if (ready == 6) {
|
||||
if (ready == 7) {
|
||||
mainFragment.fragmentReady()
|
||||
showTime()
|
||||
}
|
||||
@@ -205,6 +196,7 @@ class MainActivity : FragmentActivity(), Request.RequestListener {
|
||||
} else {
|
||||
timeFragment.hide()
|
||||
}
|
||||
mainFragment.changeStyle()
|
||||
}
|
||||
|
||||
override fun onTouchEvent(event: MotionEvent?): Boolean {
|
||||
@@ -484,7 +476,8 @@ class MainActivity : FragmentActivity(), Request.RequestListener {
|
||||
private fun getAppSignature() = this.appSignature
|
||||
|
||||
override fun onStart() {
|
||||
Log.i(TAG, "onStart")
|
||||
Log.i(TAG, "onStart MainActivity")
|
||||
syncTime()
|
||||
super.onStart()
|
||||
}
|
||||
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
package com.lizongying.mytv
|
||||
|
||||
import android.content.res.Resources
|
||||
import android.os.Bundle
|
||||
import android.util.Log
|
||||
import android.view.KeyEvent
|
||||
@@ -7,12 +8,14 @@ import android.view.LayoutInflater
|
||||
import android.view.View
|
||||
import android.view.ViewGroup
|
||||
import android.widget.Toast
|
||||
import androidx.core.view.marginBottom
|
||||
import androidx.core.view.marginLeft
|
||||
import androidx.core.view.marginTop
|
||||
import androidx.fragment.app.Fragment
|
||||
import androidx.lifecycle.lifecycleScope
|
||||
import androidx.recyclerview.widget.GridLayoutManager
|
||||
import androidx.recyclerview.widget.LinearLayoutManager
|
||||
import androidx.recyclerview.widget.RecyclerView
|
||||
import com.lizongying.mytv.Utils.dpToPx
|
||||
import com.lizongying.mytv.api.YSP
|
||||
import com.lizongying.mytv.databinding.MenuBinding
|
||||
import com.lizongying.mytv.databinding.RowBinding
|
||||
@@ -36,38 +39,39 @@ class MainFragment : Fragment(), CardAdapter.ItemListener {
|
||||
|
||||
private var lastVideoUrl = ""
|
||||
|
||||
private lateinit var application: MyTvApplication
|
||||
|
||||
override fun onCreateView(
|
||||
inflater: LayoutInflater, container: ViewGroup?,
|
||||
savedInstanceState: Bundle?
|
||||
): View {
|
||||
_binding = MenuBinding.inflate(inflater, container, false)
|
||||
|
||||
val activity = requireActivity()
|
||||
val application = activity.applicationContext as MyApplication
|
||||
val displayMetrics = application.getDisplayMetrics()
|
||||
application = requireActivity().applicationContext as MyTvApplication
|
||||
|
||||
displayMetrics.density
|
||||
|
||||
var screenWidth = displayMetrics.widthPixels
|
||||
var screenHeight = displayMetrics.heightPixels
|
||||
if (screenHeight > screenWidth) {
|
||||
screenWidth = displayMetrics.heightPixels
|
||||
screenHeight = displayMetrics.widthPixels
|
||||
}
|
||||
val width = application.getWidth()
|
||||
val height = application.getHeight()
|
||||
|
||||
val ratio = 16f / 9f
|
||||
|
||||
if (screenWidth / screenHeight > ratio) {
|
||||
val x = ((screenWidth - screenHeight * ratio) / 2).toInt()
|
||||
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 (screenWidth / screenHeight < ratio) {
|
||||
val y = ((screenHeight - screenWidth / ratio) / 2).toInt()
|
||||
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
|
||||
@@ -115,46 +119,55 @@ class MainFragment : Fragment(), CardAdapter.ItemListener {
|
||||
|
||||
val adapter =
|
||||
CardAdapter(
|
||||
itemBinding.rowItems,
|
||||
itemBinding.items,
|
||||
this,
|
||||
tvListViewModelCurrent,
|
||||
)
|
||||
rowList.add(itemBinding.rowItems)
|
||||
rowList.add(itemBinding.items)
|
||||
|
||||
adapter.setItemListener(this)
|
||||
|
||||
itemBinding.rowHeader.text = k
|
||||
itemBinding.rowItems.tag = idx.toInt()
|
||||
itemBinding.rowItems.adapter = adapter
|
||||
itemBinding.header.text = k
|
||||
itemBinding.items.tag = idx.toInt()
|
||||
itemBinding.items.adapter = adapter
|
||||
|
||||
itemBinding.rowItems.addOnScrollListener(object : RecyclerView.OnScrollListener() {
|
||||
itemBinding.items.addOnScrollListener(object : RecyclerView.OnScrollListener() {
|
||||
override fun onScrolled(recyclerView: RecyclerView, dx: Int, dy: Int) {
|
||||
super.onScrolled(recyclerView, dx, dy)
|
||||
(activity as MainActivity).mainActive()
|
||||
}
|
||||
})
|
||||
|
||||
val itemDecoration = context?.let { GrayOverlayItemDecoration(it) }
|
||||
val itemDecoration = context?.let { ItemDecoration(it) }
|
||||
if (itemDecoration != null) {
|
||||
itemBinding.rowItems.addItemDecoration(itemDecoration)
|
||||
itemBinding.items.addItemDecoration(itemDecoration)
|
||||
}
|
||||
|
||||
if (SP.grid) {
|
||||
itemBinding.rowItems.layoutManager =
|
||||
itemBinding.items.layoutManager =
|
||||
GridLayoutManager(context, 6)
|
||||
itemBinding.rowItems.layoutParams.height =
|
||||
dpToPx(92 * ((tvListViewModelCurrent.size() + 6 - 1) / 6))
|
||||
itemBinding.items.layoutParams.height =
|
||||
application.dp2Px(110 * ((tvListViewModelCurrent.size() + 6 - 1) / 6) + 5)
|
||||
} else {
|
||||
itemBinding.rowItems.layoutManager =
|
||||
itemBinding.items.layoutManager =
|
||||
LinearLayoutManager(context, LinearLayoutManager.HORIZONTAL, false)
|
||||
}
|
||||
|
||||
val layoutParams = itemBinding.row.layoutParams as ViewGroup.MarginLayoutParams
|
||||
layoutParams.topMargin = dpToPx(11F)
|
||||
layoutParams.topMargin = application.dp2Px(11)
|
||||
itemBinding.row.layoutParams = layoutParams
|
||||
itemBinding.row.setOnClickListener {
|
||||
hideSelf()
|
||||
}
|
||||
|
||||
val layoutParamsHeader =
|
||||
itemBinding.header.layoutParams as ViewGroup.MarginLayoutParams
|
||||
layoutParamsHeader.topMargin = application.px2Px(itemBinding.header.marginTop)
|
||||
layoutParamsHeader.bottomMargin = application.px2Px(itemBinding.header.marginBottom)
|
||||
layoutParamsHeader.leftMargin = application.px2Px(itemBinding.header.marginLeft)
|
||||
itemBinding.header.layoutParams = layoutParamsHeader
|
||||
itemBinding.header.textSize = application.px2PxFont(itemBinding.header.textSize)
|
||||
|
||||
content.addView(itemBinding.row)
|
||||
|
||||
idx++
|
||||
@@ -215,8 +228,24 @@ class MainFragment : Fragment(), CardAdapter.ItemListener {
|
||||
}
|
||||
}
|
||||
|
||||
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
|
||||
super.onViewCreated(view, savedInstanceState)
|
||||
fun changeStyle() {
|
||||
if (SP.grid) {
|
||||
for (i in rowList) {
|
||||
if (i is RecyclerView) {
|
||||
i.layoutManager = GridLayoutManager(context, 6)
|
||||
i.layoutParams.height =
|
||||
application.dp2Px(110 * (((i.adapter as CardAdapter).getItemCount() + 6 - 1) / 6) + 5)
|
||||
}
|
||||
}
|
||||
} else {
|
||||
for (i in rowList) {
|
||||
if (i is RecyclerView) {
|
||||
i.layoutManager =
|
||||
LinearLayoutManager(context, LinearLayoutManager.HORIZONTAL, false)
|
||||
i.layoutParams.height = application.dp2Px(110 + 5)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
override fun onKey(keyCode: Int): Boolean {
|
||||
@@ -243,7 +272,10 @@ class MainFragment : Fragment(), CardAdapter.ItemListener {
|
||||
|
||||
for (i in rowList) {
|
||||
if (i.tag as Int != row) {
|
||||
((i as RecyclerView).adapter as CardAdapter).focusable = false
|
||||
((i as RecyclerView).adapter as CardAdapter).clear()
|
||||
} else {
|
||||
((i as RecyclerView).adapter as CardAdapter).focusable = true
|
||||
}
|
||||
}
|
||||
|
||||
@@ -260,7 +292,7 @@ class MainFragment : Fragment(), CardAdapter.ItemListener {
|
||||
if (itemPosition != tvViewModel.getTV().id) {
|
||||
itemPosition = tvViewModel.getTV().id
|
||||
tvListViewModel.setItemPosition(itemPosition)
|
||||
tvListViewModel.getTVViewModel(itemPosition)?.changed()
|
||||
tvListViewModel.getTVViewModel(itemPosition)?.changed("menu")
|
||||
}
|
||||
(activity as? MainActivity)?.switchMainFragment()
|
||||
}
|
||||
@@ -307,8 +339,7 @@ class MainFragment : Fragment(), CardAdapter.ItemListener {
|
||||
}
|
||||
|
||||
fun fragmentReady() {
|
||||
// request.fetchPage()
|
||||
tvListViewModel.getTVViewModel(itemPosition)?.changed()
|
||||
tvListViewModel.getTVViewModel(itemPosition)?.changed("init")
|
||||
|
||||
tvListViewModel.tvListViewModel.value?.forEach { tvViewModel ->
|
||||
updateEPG(tvViewModel)
|
||||
@@ -320,7 +351,7 @@ class MainFragment : Fragment(), CardAdapter.ItemListener {
|
||||
if (itemPosition > -1 && itemPosition < tvListViewModel.size()) {
|
||||
this.itemPosition = itemPosition
|
||||
tvListViewModel.setItemPosition(itemPosition)
|
||||
tvListViewModel.getTVViewModel(itemPosition)?.changed()
|
||||
tvListViewModel.getTVViewModel(itemPosition)?.changed("num")
|
||||
} else {
|
||||
Toast.makeText(context, "频道不存在", Toast.LENGTH_SHORT).show()
|
||||
}
|
||||
@@ -334,7 +365,7 @@ class MainFragment : Fragment(), CardAdapter.ItemListener {
|
||||
itemPosition = tvListViewModel.size() - 1
|
||||
}
|
||||
tvListViewModel.setItemPosition(itemPosition)
|
||||
tvListViewModel.getTVViewModel(itemPosition)?.changed()
|
||||
tvListViewModel.getTVViewModel(itemPosition)?.changed("prev")
|
||||
}
|
||||
}
|
||||
|
||||
@@ -345,7 +376,7 @@ class MainFragment : Fragment(), CardAdapter.ItemListener {
|
||||
itemPosition = 0
|
||||
}
|
||||
tvListViewModel.setItemPosition(itemPosition)
|
||||
tvListViewModel.getTVViewModel(itemPosition)?.changed()
|
||||
tvListViewModel.getTVViewModel(itemPosition)?.changed("next")
|
||||
}
|
||||
}
|
||||
|
||||
@@ -370,6 +401,7 @@ class MainFragment : Fragment(), CardAdapter.ItemListener {
|
||||
}
|
||||
|
||||
override fun onHiddenChanged(hidden: Boolean) {
|
||||
Log.i(TAG, "onHiddenChanged $hidden")
|
||||
super.onHiddenChanged(hidden)
|
||||
if (!hidden) {
|
||||
val tvModel = tvListViewModel.getTVViewModel(itemPosition)
|
||||
@@ -378,15 +410,16 @@ class MainFragment : Fragment(), CardAdapter.ItemListener {
|
||||
Log.i(TAG, "toPosition $rowPosition $itemPosition")
|
||||
for (i in rowList) {
|
||||
if (i.tag as Int == rowPosition) {
|
||||
((i as RecyclerView).adapter as CardAdapter).focusable = true
|
||||
((i as RecyclerView).adapter as CardAdapter).toPosition(itemPosition!!)
|
||||
break
|
||||
}
|
||||
}
|
||||
} else {
|
||||
view?.post {
|
||||
// for (i in rowList) {
|
||||
// ((i as RecyclerView).adapter as CardAdapter).visiable = false
|
||||
// }
|
||||
for (i in rowList) {
|
||||
((i as RecyclerView).adapter as CardAdapter).focusable = false
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,30 +0,0 @@
|
||||
package com.lizongying.mytv
|
||||
|
||||
import android.app.Application
|
||||
import android.content.Context
|
||||
import android.util.DisplayMetrics
|
||||
import android.view.WindowManager
|
||||
import androidx.multidex.MultiDex
|
||||
|
||||
|
||||
class MyApplication : Application() {
|
||||
private lateinit var displayMetrics: DisplayMetrics
|
||||
|
||||
override fun onCreate() {
|
||||
super.onCreate()
|
||||
|
||||
displayMetrics = DisplayMetrics()
|
||||
val windowManager = getSystemService(Context.WINDOW_SERVICE) as WindowManager
|
||||
// windowManager.defaultDisplay.getRealMetrics(displayMetrics)
|
||||
windowManager.defaultDisplay.getMetrics(displayMetrics)
|
||||
}
|
||||
|
||||
fun getDisplayMetrics(): DisplayMetrics {
|
||||
return displayMetrics
|
||||
}
|
||||
|
||||
override fun attachBaseContext(base: Context?) {
|
||||
super.attachBaseContext(base)
|
||||
MultiDex.install(base)
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,95 @@
|
||||
package com.lizongying.mytv
|
||||
|
||||
import android.app.Application
|
||||
import android.content.Context
|
||||
import android.content.res.Resources
|
||||
import android.util.DisplayMetrics
|
||||
import android.view.WindowManager
|
||||
import androidx.multidex.MultiDex
|
||||
|
||||
|
||||
class MyTvApplication : Application() {
|
||||
private lateinit var displayMetrics: DisplayMetrics
|
||||
private lateinit var realDisplayMetrics: DisplayMetrics
|
||||
|
||||
private var width = 0
|
||||
private var height = 0
|
||||
private var deviation = 0
|
||||
private var ratio = 1.0
|
||||
private var density = 2.0f
|
||||
private var scale = 1.0f
|
||||
|
||||
override fun onCreate() {
|
||||
super.onCreate()
|
||||
|
||||
displayMetrics = DisplayMetrics()
|
||||
realDisplayMetrics = DisplayMetrics()
|
||||
val windowManager = getSystemService(Context.WINDOW_SERVICE) as WindowManager
|
||||
windowManager.defaultDisplay.getMetrics(displayMetrics)
|
||||
windowManager.defaultDisplay.getRealMetrics(realDisplayMetrics)
|
||||
|
||||
if (realDisplayMetrics.heightPixels > realDisplayMetrics.widthPixels) {
|
||||
width = realDisplayMetrics.heightPixels
|
||||
height = realDisplayMetrics.widthPixels
|
||||
} else {
|
||||
width = realDisplayMetrics.widthPixels
|
||||
height = realDisplayMetrics.heightPixels
|
||||
}
|
||||
|
||||
density = displayMetrics.density
|
||||
|
||||
ratio = if ((width.toDouble() / height) < (16.0 / 9)) {
|
||||
width * 2 / 1920.0 / density
|
||||
} else {
|
||||
height * 2 / 1080.0 / density
|
||||
}
|
||||
|
||||
deviation = width - Resources.getSystem().displayMetrics.widthPixels
|
||||
scale = Resources.getSystem().displayMetrics.scaledDensity
|
||||
}
|
||||
|
||||
fun getDisplayMetrics(): DisplayMetrics {
|
||||
return displayMetrics
|
||||
}
|
||||
|
||||
fun getRealDisplayMetrics(): DisplayMetrics {
|
||||
return realDisplayMetrics
|
||||
}
|
||||
|
||||
fun getWidth(): Int {
|
||||
return width
|
||||
}
|
||||
|
||||
fun getDeviation(): Int {
|
||||
return deviation
|
||||
}
|
||||
|
||||
fun getHeight(): Int {
|
||||
return height
|
||||
}
|
||||
|
||||
fun getRatio(): Double {
|
||||
return ratio
|
||||
}
|
||||
|
||||
fun dp2Px(dp: Int): Int {
|
||||
return (dp * ratio * density + 0.5f).toInt()
|
||||
}
|
||||
|
||||
fun px2Px(px: Int): Int {
|
||||
return (px * ratio + 0.5f).toInt()
|
||||
}
|
||||
|
||||
fun px2PxFont(px: Float): Float {
|
||||
return (px * ratio / scale).toFloat()
|
||||
}
|
||||
|
||||
fun sp2Px(sp: Float): Float {
|
||||
return (sp * ratio * scale).toFloat()
|
||||
}
|
||||
|
||||
override fun attachBaseContext(base: Context?) {
|
||||
super.attachBaseContext(base)
|
||||
MultiDex.install(base)
|
||||
}
|
||||
}
|
||||
@@ -80,7 +80,7 @@ class PlayerFragment : Fragment(), SurfaceHolder.Callback {
|
||||
super.onPlayerError(error)
|
||||
|
||||
Log.e(TAG, "PlaybackException $error")
|
||||
tvViewModel?.changed()
|
||||
tvViewModel?.changed("retry")
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
@@ -5,6 +5,8 @@ import android.view.LayoutInflater
|
||||
import android.view.View
|
||||
import android.view.ViewGroup
|
||||
import android.view.WindowManager
|
||||
import androidx.core.view.marginEnd
|
||||
import androidx.core.view.marginTop
|
||||
import androidx.fragment.app.DialogFragment
|
||||
import com.lizongying.mytv.databinding.SettingBinding
|
||||
|
||||
@@ -87,7 +89,67 @@ class SettingFragment : DialogFragment() {
|
||||
)
|
||||
)
|
||||
|
||||
binding.exit.setOnClickListener{
|
||||
val application = requireActivity().applicationContext as MyTvApplication
|
||||
|
||||
binding.content.layoutParams.width =
|
||||
application.px2Px(binding.content.layoutParams.width)
|
||||
binding.content.setPadding(
|
||||
application.px2Px(binding.content.paddingLeft),
|
||||
application.px2Px(binding.content.paddingTop),
|
||||
application.px2Px(binding.content.paddingRight),
|
||||
application.px2Px(binding.content.paddingBottom)
|
||||
)
|
||||
binding.name.textSize = application.px2PxFont(binding.name.textSize)
|
||||
binding.version.textSize = application.px2PxFont(binding.version.textSize)
|
||||
val layoutParamsDesc = binding.version.layoutParams as ViewGroup.MarginLayoutParams
|
||||
layoutParamsDesc.topMargin = application.px2Px(binding.version.marginTop)
|
||||
binding.version.layoutParams = layoutParamsDesc
|
||||
|
||||
binding.checkVersion.textSize = application.px2PxFont(binding.checkVersion.textSize)
|
||||
val layoutParamsCheckVersion =
|
||||
binding.checkVersion.layoutParams as ViewGroup.MarginLayoutParams
|
||||
layoutParamsCheckVersion.marginEnd = application.px2Px(binding.checkVersion.marginEnd)
|
||||
binding.checkVersion.layoutParams = layoutParamsCheckVersion
|
||||
|
||||
binding.versionName.textSize = application.px2PxFont(binding.versionName.textSize)
|
||||
|
||||
binding.exit.textSize = application.px2PxFont(binding.exit.textSize)
|
||||
|
||||
binding.switchChannelReversal.textSize =
|
||||
application.px2PxFont(binding.switchChannelReversal.textSize)
|
||||
val layoutParamsChannelReversal =
|
||||
binding.switchChannelReversal.layoutParams as ViewGroup.MarginLayoutParams
|
||||
layoutParamsChannelReversal.topMargin =
|
||||
application.px2Px(binding.switchChannelReversal.marginTop)
|
||||
binding.switchChannelReversal.layoutParams = layoutParamsChannelReversal
|
||||
|
||||
binding.switchChannelNum.textSize = application.px2PxFont(binding.switchChannelNum.textSize)
|
||||
val layoutParamsChannelNum =
|
||||
binding.switchChannelNum.layoutParams as ViewGroup.MarginLayoutParams
|
||||
layoutParamsChannelNum.topMargin = application.px2Px(binding.switchChannelNum.marginTop)
|
||||
binding.switchChannelNum.layoutParams = layoutParamsChannelNum
|
||||
|
||||
binding.switchTime.textSize = application.px2PxFont(binding.switchTime.textSize)
|
||||
val layoutParamsTime = binding.switchTime.layoutParams as ViewGroup.MarginLayoutParams
|
||||
layoutParamsTime.topMargin = application.px2Px(binding.switchTime.marginTop)
|
||||
binding.switchTime.layoutParams = layoutParamsTime
|
||||
|
||||
binding.switchBootStartup.textSize =
|
||||
application.px2PxFont(binding.switchBootStartup.textSize)
|
||||
val layoutParamsBootStartup =
|
||||
binding.switchBootStartup.layoutParams as ViewGroup.MarginLayoutParams
|
||||
layoutParamsBootStartup.topMargin = application.px2Px(binding.switchBootStartup.marginTop)
|
||||
binding.switchBootStartup.layoutParams = layoutParamsBootStartup
|
||||
|
||||
binding.switchGrid.textSize = application.px2PxFont(binding.switchGrid.textSize)
|
||||
val layoutParamsGrid = binding.switchGrid.layoutParams as ViewGroup.MarginLayoutParams
|
||||
layoutParamsGrid.topMargin = application.px2Px(binding.switchGrid.marginTop)
|
||||
binding.switchGrid.layoutParams = layoutParamsGrid
|
||||
|
||||
binding.appreciate.layoutParams.width =
|
||||
application.px2Px(binding.appreciate.layoutParams.width)
|
||||
|
||||
binding.exit.setOnClickListener {
|
||||
requireActivity().finishAffinity()
|
||||
}
|
||||
|
||||
|
||||
@@ -15,14 +15,15 @@ data class TV(
|
||||
var programType: ProgramType,
|
||||
var needToken: Boolean = false,
|
||||
var mustToken: Boolean = false,
|
||||
|
||||
) : Serializable {
|
||||
) : Serializable {
|
||||
|
||||
override fun toString(): String {
|
||||
return "TV{" +
|
||||
"id=" + id +
|
||||
", title='" + title + '\'' +
|
||||
", alias='" + alias + '\'' +
|
||||
", videoUrl='" + videoUrl + '\'' +
|
||||
", channel='" + channel + '\'' +
|
||||
", logo='" + logo + '\'' +
|
||||
", pid='" + pid + '\'' +
|
||||
", sid='" + sid + '\'' +
|
||||
|
||||
@@ -1,11 +1,13 @@
|
||||
package com.lizongying.mytv
|
||||
|
||||
import android.content.res.Resources
|
||||
import android.os.Bundle
|
||||
import android.os.Handler
|
||||
import android.util.Log
|
||||
import android.view.LayoutInflater
|
||||
import android.view.View
|
||||
import android.view.ViewGroup
|
||||
import androidx.core.view.marginRight
|
||||
import androidx.core.view.marginTop
|
||||
import androidx.fragment.app.Fragment
|
||||
import com.lizongying.mytv.Utils.getDateFormat
|
||||
import com.lizongying.mytv.databinding.TimeBinding
|
||||
@@ -21,38 +23,39 @@ class TimeFragment : Fragment() {
|
||||
inflater: LayoutInflater, container: ViewGroup?,
|
||||
savedInstanceState: Bundle?
|
||||
): View {
|
||||
Log.i(TAG, "onCreateView")
|
||||
_binding = TimeBinding.inflate(inflater, container, false)
|
||||
|
||||
val activity = requireActivity()
|
||||
val application = activity.applicationContext as MyApplication
|
||||
val displayMetrics = application.getDisplayMetrics()
|
||||
val application = requireActivity().applicationContext as MyTvApplication
|
||||
|
||||
displayMetrics.density
|
||||
|
||||
var screenWidth = displayMetrics.widthPixels
|
||||
var screenHeight = displayMetrics.heightPixels
|
||||
if (screenHeight > screenWidth) {
|
||||
screenWidth = displayMetrics.heightPixels
|
||||
screenHeight = displayMetrics.widthPixels
|
||||
}
|
||||
val width = application.getWidth()
|
||||
val height = application.getHeight()
|
||||
|
||||
val ratio = 16f / 9f
|
||||
|
||||
if (screenWidth / screenHeight > ratio) {
|
||||
val x = ((screenWidth - screenHeight * ratio) / 2).toInt()
|
||||
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 (screenWidth / screenHeight < ratio) {
|
||||
val y = ((screenHeight - screenWidth / ratio) / 2).toInt()
|
||||
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.height = application.px2Px(binding.time.layoutParams.height)
|
||||
val layoutParams = binding.time.layoutParams as ViewGroup.MarginLayoutParams
|
||||
layoutParams.topMargin = application.px2Px(binding.time.marginTop)
|
||||
layoutParams.rightMargin = application.px2Px(binding.time.marginRight)
|
||||
binding.time.layoutParams = layoutParams
|
||||
binding.content.textSize = application.px2PxFont(binding.content.textSize)
|
||||
|
||||
(activity as MainActivity).fragmentReady("TimeFragment")
|
||||
return binding.root
|
||||
}
|
||||
@@ -72,6 +75,9 @@ class TimeFragment : Fragment() {
|
||||
|
||||
private val showRunnable: Runnable = Runnable {
|
||||
run {
|
||||
if (_binding == null) {
|
||||
return@Runnable
|
||||
}
|
||||
binding.content.text = getDateFormat("HH:mm")
|
||||
handler.postDelayed(showRunnable, delay)
|
||||
}
|
||||
@@ -89,6 +95,7 @@ class TimeFragment : Fragment() {
|
||||
}
|
||||
|
||||
override fun onDestroyView() {
|
||||
handler.removeCallbacks(showRunnable)
|
||||
super.onDestroyView()
|
||||
_binding = null
|
||||
}
|
||||
|
||||
@@ -62,7 +62,7 @@ class UpdateManager(
|
||||
|
||||
private fun updateUI(text: String) {
|
||||
val dialog = ConfirmationFragment(this@UpdateManager, text)
|
||||
dialog.show(settingFragment.fragmentManager, TAG)
|
||||
settingFragment.fragmentManager?.let { dialog.show(it, TAG) }
|
||||
}
|
||||
|
||||
private fun haveStoragePermission(): Boolean {
|
||||
|
||||
@@ -15,6 +15,8 @@ import java.util.Locale
|
||||
object Utils {
|
||||
private var between: Long = 0
|
||||
|
||||
private var listener: Request.RequestListener? = null
|
||||
|
||||
fun getDateFormat(format: String): String {
|
||||
return SimpleDateFormat(
|
||||
format,
|
||||
@@ -38,6 +40,10 @@ object Utils {
|
||||
println("Failed to retrieve timestamp from server: ${e.message}")
|
||||
}
|
||||
between = System.currentTimeMillis() - currentTimeMillis
|
||||
|
||||
withContext(Dispatchers.Main) {
|
||||
listener?.onRequestFinished(null)
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -72,6 +78,8 @@ object Utils {
|
||||
}
|
||||
|
||||
fun dpToPx(dp: Int): Int {
|
||||
// val density = Resources.getSystem().displayMetrics.density
|
||||
// return (dp * density + 0.5f).toInt()
|
||||
return TypedValue.applyDimension(
|
||||
TypedValue.COMPLEX_UNIT_DIP, dp.toFloat(), Resources.getSystem().displayMetrics
|
||||
).toInt()
|
||||
@@ -88,4 +96,8 @@ object Utils {
|
||||
}
|
||||
|
||||
fun isTmallDevice() = Build.MANUFACTURER.equals("Tmall", ignoreCase = true)
|
||||
|
||||
fun setRequestListener(listener: Request.RequestListener) {
|
||||
this.listener = listener
|
||||
}
|
||||
}
|
||||
@@ -41,8 +41,8 @@ class TVViewModel(private var tv: TV) : ViewModel() {
|
||||
val videoIndex: LiveData<Int>
|
||||
get() = _videoIndex
|
||||
|
||||
private val _change = MutableLiveData<Boolean>()
|
||||
val change: LiveData<Boolean>
|
||||
private val _change = MutableLiveData<String>()
|
||||
val change: LiveData<String>
|
||||
get() = _change
|
||||
|
||||
private val _ready = MutableLiveData<Boolean>()
|
||||
@@ -74,8 +74,8 @@ class TVViewModel(private var tv: TV) : ViewModel() {
|
||||
}
|
||||
}
|
||||
|
||||
fun changed() {
|
||||
_change.value = true
|
||||
fun changed(from: String) {
|
||||
_change.value = from
|
||||
}
|
||||
|
||||
fun allReady() {
|
||||
|
||||
@@ -1,4 +0,0 @@
|
||||
<shape xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
<solid android:color="#FF263238" />
|
||||
<corners android:radius="4dp" /> <!-- Adjust the radius as needed -->
|
||||
</shape>
|
||||
@@ -0,0 +1,6 @@
|
||||
<shape xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
<solid android:color="@color/blur" />
|
||||
<corners
|
||||
android:bottomLeftRadius="4dp"
|
||||
android:bottomRightRadius="4dp" />
|
||||
</shape>
|
||||
@@ -0,0 +1,6 @@
|
||||
<shape xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
<solid android:color="@color/blur" />
|
||||
<corners
|
||||
android:topLeftRadius="4dp"
|
||||
android:bottomLeftRadius="4dp" />
|
||||
</shape>
|
||||
@@ -0,0 +1,6 @@
|
||||
<shape xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
<solid android:color="@color/blur" />
|
||||
<corners
|
||||
android:topRightRadius="4dp"
|
||||
android:bottomRightRadius="4dp" />
|
||||
</shape>
|
||||
@@ -0,0 +1,6 @@
|
||||
<shape xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
<solid android:color="@color/focus" />
|
||||
<corners
|
||||
android:bottomLeftRadius="4dp"
|
||||
android:bottomRightRadius="4dp" />
|
||||
</shape>
|
||||
@@ -0,0 +1,6 @@
|
||||
<shape xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
<solid android:color="@color/white" />
|
||||
<corners
|
||||
android:topLeftRadius="4dp"
|
||||
android:bottomLeftRadius="4dp" />
|
||||
</shape>
|
||||
@@ -0,0 +1,6 @@
|
||||
<shape xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
<solid android:color="@color/white" />
|
||||
<corners
|
||||
android:topRightRadius="4dp"
|
||||
android:bottomRightRadius="4dp" />
|
||||
</shape>
|
||||
+3
-1
@@ -1,4 +1,6 @@
|
||||
<shape xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
<solid android:color="@color/white" />
|
||||
<corners android:radius="4dp" /> <!-- Adjust the radius as needed -->
|
||||
<corners
|
||||
android:topLeftRadius="4dp"
|
||||
android:topRightRadius="4dp" />
|
||||
</shape>
|
||||
@@ -0,0 +1,60 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||
android:id="@+id/card"
|
||||
android:layout_width="150dp"
|
||||
android:layout_height="100dp"
|
||||
android:orientation="vertical"
|
||||
android:layout_gravity="center_vertical"
|
||||
>
|
||||
<ImageView
|
||||
android:id="@+id/icon"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="40dp"
|
||||
android:background="@drawable/rounded_white_top"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintTop_toTopOf="parent"
|
||||
android:padding="5dp" />
|
||||
|
||||
<LinearLayout
|
||||
android:id="@+id/main"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="60dp"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintTop_toBottomOf="@id/icon"
|
||||
android:background="@drawable/rounded_dark_bottom"
|
||||
android:orientation="vertical"
|
||||
android:padding="7dp">
|
||||
|
||||
<TextView
|
||||
android:id="@+id/title"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintTop_toTopOf="parent"
|
||||
android:gravity="start"
|
||||
android:text="Title"
|
||||
android:maxLines="1"
|
||||
android:ellipsize="end"
|
||||
android:textColor="#FFEEEEEE"
|
||||
android:textSize="14sp" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/desc"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintTop_toBottomOf="@id/title"
|
||||
android:layout_marginTop="8dp"
|
||||
android:gravity="start"
|
||||
android:maxLines="1"
|
||||
android:ellipsize="end"
|
||||
android:text="Description"
|
||||
android:textColor="#B3EEEEEE"
|
||||
android:textSize="12sp" />
|
||||
</LinearLayout>
|
||||
</androidx.constraintlayout.widget.ConstraintLayout>
|
||||
@@ -12,7 +12,6 @@
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_gravity="end"
|
||||
android:layout_marginTop="0dp"
|
||||
android:textColor="#FFEEEEEE"
|
||||
android:textStyle="bold"
|
||||
android:textSize="40sp" />
|
||||
|
||||
@@ -1,40 +1,39 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:id="@+id/info"
|
||||
android:layout_width="320dp"
|
||||
android:layout_width="400dp"
|
||||
android:layout_height="80dp"
|
||||
android:layout_gravity="center_horizontal|bottom"
|
||||
android:layout_marginBottom="20dp"
|
||||
android:background="@drawable/rounded_background">
|
||||
android:layout_marginBottom="20dp">
|
||||
|
||||
<ImageView
|
||||
android:id="@+id/info_logo"
|
||||
android:id="@+id/logo"
|
||||
android:layout_width="100dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginTop="8dp"
|
||||
android:layout_height="match_parent"
|
||||
android:background="@drawable/rounded_white_left"
|
||||
android:padding="10dp" />
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="216dp"
|
||||
android:id="@+id/main"
|
||||
android:layout_width="300dp"
|
||||
android:layout_height="match_parent"
|
||||
android:layout_marginStart="100dp"
|
||||
android:background="#FF263238"
|
||||
android:background="@drawable/rounded_dark_right"
|
||||
android:gravity="start|center_vertical"
|
||||
android:orientation="vertical"
|
||||
android:padding="7dp">
|
||||
|
||||
<TextView
|
||||
android:id="@+id/textView"
|
||||
android:id="@+id/title"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_gravity="start"
|
||||
android:layout_marginTop="0dp"
|
||||
android:gravity="start"
|
||||
android:textColor="#FFEEEEEE"
|
||||
android:textSize="22sp" />
|
||||
android:textSize="20sp" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/info_desc"
|
||||
android:id="@+id/desc"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_gravity="start"
|
||||
@@ -42,12 +41,6 @@
|
||||
android:gravity="start"
|
||||
android:singleLine="true"
|
||||
android:textColor="#B3EEEEEE"
|
||||
android:textSize="16sp" />
|
||||
android:textSize="14sp" />
|
||||
</LinearLayout>
|
||||
|
||||
<View
|
||||
android:layout_width="8dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_gravity="end"
|
||||
android:background="@drawable/rounded_background2" />
|
||||
</FrameLayout>
|
||||
@@ -10,7 +10,7 @@
|
||||
>
|
||||
|
||||
<TextView
|
||||
android:id="@+id/row_header"
|
||||
android:id="@+id/header"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_gravity="start"
|
||||
@@ -22,7 +22,7 @@
|
||||
android:textSize="22sp" />
|
||||
|
||||
<androidx.recyclerview.widget.RecyclerView
|
||||
android:id="@+id/row_items"
|
||||
android:id="@+id/items"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content">
|
||||
</androidx.recyclerview.widget.RecyclerView>
|
||||
|
||||
@@ -8,15 +8,17 @@
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content">
|
||||
<LinearLayout
|
||||
android:id="@+id/content"
|
||||
android:layout_width="300dp"
|
||||
android:layout_height="match_parent"
|
||||
android:orientation="vertical"
|
||||
android:paddingTop="20dp"
|
||||
android:paddingLeft="7dp"
|
||||
android:paddingRight="7dp"
|
||||
android:background="#FF263238"
|
||||
android:background="@drawable/rounded_dark_left"
|
||||
>
|
||||
<TextView
|
||||
android:id="@+id/name"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="@string/app_name"
|
||||
@@ -27,9 +29,10 @@
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginTop="10dp"
|
||||
android:text="当前版本: $versionName\n获取最新: https://github.com/lizongying/my-tv/releases/"
|
||||
android:textSize="14sp"
|
||||
/>
|
||||
<LinearLayout
|
||||
android:layout_width="300dp"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:orientation="horizontal"
|
||||
>
|
||||
@@ -38,6 +41,7 @@
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginEnd="10dp"
|
||||
android:textSize="14sp"
|
||||
android:text="@string/check_version"
|
||||
/>
|
||||
<ProgressBar
|
||||
@@ -48,6 +52,7 @@
|
||||
<TextView
|
||||
android:id="@+id/version_name"
|
||||
android:text=""
|
||||
android:textSize="14sp"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content" />
|
||||
</LinearLayout>
|
||||
@@ -55,44 +60,50 @@
|
||||
android:id="@+id/exit"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginEnd="10dp"
|
||||
android:textSize="14sp"
|
||||
android:text="@string/exit"
|
||||
/>
|
||||
<Switch
|
||||
android:id="@+id/switch_channel_reversal"
|
||||
android:text="@string/title_channel_reversal"
|
||||
android:textSize="14sp"
|
||||
android:layout_marginTop="5dp"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content" />
|
||||
<Switch
|
||||
android:id="@+id/switch_channel_num"
|
||||
android:text="@string/title_channel_num"
|
||||
android:textSize="14sp"
|
||||
android:layout_marginTop="5dp"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content" />
|
||||
<Switch
|
||||
android:id="@+id/switch_time"
|
||||
android:text="@string/title_time"
|
||||
android:textSize="14sp"
|
||||
android:layout_marginTop="5dp"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content" />
|
||||
<Switch
|
||||
android:id="@+id/switch_boot_startup"
|
||||
android:text="@string/title_boot_startup"
|
||||
android:textSize="14sp"
|
||||
android:layout_marginTop="5dp"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content" />
|
||||
<Switch
|
||||
android:id="@+id/switch_grid"
|
||||
android:text="@string/title_grid"
|
||||
android:textSize="14sp"
|
||||
android:layout_marginTop="5dp"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content" />
|
||||
</LinearLayout>
|
||||
<ImageView
|
||||
android:id="@+id/appreciate"
|
||||
android:layout_width="300dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:src="@drawable/appreciate"
|
||||
android:background="@color/white" />
|
||||
android:background="@drawable/rounded_white_right" />
|
||||
</LinearLayout>
|
||||
</FrameLayout>
|
||||
@@ -12,7 +12,6 @@
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_gravity="end"
|
||||
android:layout_marginTop="0dp"
|
||||
android:textColor="#FFEEEEEE"
|
||||
android:textStyle="bold"
|
||||
android:textSize="32sp" />
|
||||
|
||||
@@ -1,8 +1,6 @@
|
||||
<resources>
|
||||
<color name="fastlane_background">#30000000</color>
|
||||
<color name="black">#000</color>
|
||||
<color name="white">#FFF</color>
|
||||
<color name="gray_overlay">#7F000000</color>
|
||||
<color name="focus">#0096a6</color>
|
||||
<color name="blur">#FF263238</color>
|
||||
</resources>
|
||||
@@ -10,11 +10,11 @@
|
||||
</style>
|
||||
|
||||
<style name="CustomImageCardViewImageStyle" parent="Widget.Leanback.ImageCardView.ImageStyle">
|
||||
<item name="android:layout_width">160dp</item>
|
||||
<item name="android:layout_width">150dp</item>
|
||||
<item name="android:layout_height">40dp</item>
|
||||
<item name="android:adjustViewBounds">true</item>
|
||||
<item name="android:contentDescription">@null</item>
|
||||
<item name="android:scaleType">centerCrop</item>
|
||||
<item name="android:scaleType">centerInside</item>
|
||||
<item name="layout_viewType">main</item>
|
||||
</style>
|
||||
|
||||
|
||||
Reference in New Issue
Block a user