diff --git a/app/src/main/java/com/lizongying/mytv/CardPresenter.kt b/app/src/main/java/com/lizongying/mytv/CardPresenter.kt index 843d816..94171fe 100644 --- a/app/src/main/java/com/lizongying/mytv/CardPresenter.kt +++ b/app/src/main/java/com/lizongying/mytv/CardPresenter.kt @@ -1,47 +1,22 @@ package com.lizongying.mytv -import android.content.Context -import android.graphics.Bitmap -import android.media.MediaMetadataRetriever -import android.util.Log +import android.graphics.Color import android.view.ContextThemeWrapper import android.view.ViewGroup +import android.widget.ImageView import androidx.leanback.widget.ImageCardView import androidx.leanback.widget.Presenter -import androidx.lifecycle.LifecycleCoroutineScope import androidx.lifecycle.LifecycleOwner import com.bumptech.glide.Glide import com.lizongying.mytv.models.TVViewModel -import kotlinx.coroutines.Dispatchers -import kotlinx.coroutines.delay -import kotlinx.coroutines.launch -import kotlinx.coroutines.withContext class CardPresenter( - private val lifecycleScope: LifecycleCoroutineScope, -// private val owner: LifecycleOwner + private val owner: LifecycleOwner, ) : Presenter() { - private var tvViewModel: TVViewModel? = null - fun bindData(viewModel: TVViewModel, fragment: Context?, viewHolder: ViewHolder) { - } - - fun setViewModel(model: TVViewModel) { - tvViewModel = model - } - - fun unbind() { -// viewModel?.backgroundImage?.removeObservers(fragment) - } - override fun onCreateViewHolder(parent: ViewGroup): ViewHolder { val cardView = object : - ImageCardView(ContextThemeWrapper(parent.context, R.style.CustomImageCardTheme)) { - override fun setSelected(selected: Boolean) { - updateCardBackgroundColor(this) - super.setSelected(selected) - } - } + ImageCardView(ContextThemeWrapper(parent.context, R.style.CustomImageCardTheme)) {} cardView.isFocusable = true cardView.isFocusableInTouchMode = true @@ -56,63 +31,32 @@ class CardPresenter( cardView.setMainImageDimensions(CARD_WIDTH, CARD_HEIGHT) cardView.tag = tvViewModel.videoUrl.value -// lifecycleScope.launch(Dispatchers.IO) { -// val videoThumbnail = tv.videoUrl?.let { getVideoThumbnail(it) } -// -// withContext(Dispatchers.Main) { -// cardView.mainImageView.setImageBitmap(videoThumbnail) -// } -// } + if (tvViewModel.logo.value != null) { + Glide.with(viewHolder.view.context) + .load(tvViewModel.logo.value) + .centerInside() + .into(cardView.mainImageView) -// tvViewModel?.update(tv) -// tvViewModel?.backgroundImage?.observe(owner) { imageUrl -> -// if (imageUrl != "") { -// Glide.with(viewHolder.view.context) -// .load(imageUrl) -// .centerCrop() -// .into(cardView.mainImageView) -// } -// } + cardView.setBackgroundColor(Color.WHITE) + cardView.setMainImageScaleType(ImageView.ScaleType.CENTER_INSIDE) + } + + tvViewModel.program.observe(owner) { _ -> + val program = tvViewModel.getProgramOne() + if (program != null) { + cardView.contentText = program.name + } + } } override fun onUnbindViewHolder(viewHolder: ViewHolder) { val cardView = viewHolder.view as ImageCardView - cardView.badgeImage = null cardView.mainImage = null } - private fun updateCardBackgroundColor(view: ImageCardView) { - val currentTag = view.tag -// lifecycleScope.launch(Dispatchers.IO) { -// delay(1000) -// if (view.isSelected && view.tag != null && currentTag == view.tag) { -// val videoThumbnail = view.tag.toString().let { getVideoThumbnail(it) } -// withContext(Dispatchers.Main) { -// if (view.isSelected && currentTag == view.tag) { -// view.mainImageView.setImageBitmap(videoThumbnail) -// } -// } -// } -// } - } - - private fun getVideoThumbnail(url: String): Bitmap? { - val mediaMetadataRetriever = MediaMetadataRetriever() - try { - val map = HashMap() - mediaMetadataRetriever.setDataSource(url, map) - return mediaMetadataRetriever.frameAtTime - } catch (e: Exception) { - e.printStackTrace() - } finally { - mediaMetadataRetriever.release() - } - return null - } - companion object { private const val TAG = "CardPresenter" private const val CARD_WIDTH = 300 - private const val CARD_HEIGHT = 169 + private const val CARD_HEIGHT = 101 } } \ No newline at end of file diff --git a/app/src/main/java/com/lizongying/mytv/MainFragment.kt b/app/src/main/java/com/lizongying/mytv/MainFragment.kt index 17c3f64..4875693 100644 --- a/app/src/main/java/com/lizongying/mytv/MainFragment.kt +++ b/app/src/main/java/com/lizongying/mytv/MainFragment.kt @@ -51,6 +51,7 @@ class MainFragment : BrowseSupportFragment() { view?.post { // request?.fetchPage() +// tvListViewModel.getTVViewModel(0)?.let { request?.fetchProgram(it) } } tvListViewModel.getTVListViewModel().value?.forEach { tvViewModel -> @@ -86,6 +87,14 @@ class MainFragment : BrowseSupportFragment() { ).show() } } + tvViewModel.program.observe(viewLifecycleOwner) { _ -> + if (tvViewModel.program.value == null || tvViewModel.program.value?.size!! < 3) { + if (tvViewModel.programId.value != null) { + Log.i(TAG, "get program ${tvViewModel.title.value}") + request?.fetchProgram(tvViewModel) + } + } + } } } @@ -143,7 +152,7 @@ class MainFragment : BrowseSupportFragment() { private fun loadRows() { rowsAdapter = ArrayObjectAdapter(ListRowPresenter()) - val cardPresenter = CardPresenter(lifecycleScope) + val cardPresenter = CardPresenter(viewLifecycleOwner) var idx: Long = 0 for ((k, v) in TVList.list) { diff --git a/app/src/main/java/com/lizongying/mytv/Request.kt b/app/src/main/java/com/lizongying/mytv/Request.kt index 34a8fa5..dc91729 100644 --- a/app/src/main/java/com/lizongying/mytv/Request.kt +++ b/app/src/main/java/com/lizongying/mytv/Request.kt @@ -12,9 +12,13 @@ import com.lizongying.mytv.api.YSPApiService import com.lizongying.mytv.api.YSPProtoService import com.lizongying.mytv.models.TVViewModel import com.lizongying.mytv.proto.Ysp.cn.yangshipin.oms.common.proto.pageModel +import com.lizongying.mytv.proto.Ysp.cn.yangshipin.omstv.common.proto.epgProgramModel import retrofit2.Call import retrofit2.Callback import retrofit2.Response +import java.text.SimpleDateFormat +import java.util.Date +import java.util.Locale import javax.crypto.Cipher import javax.crypto.spec.IvParameterSpec import javax.crypto.spec.SecretKeySpec @@ -174,18 +178,31 @@ class Request(var context: Context) { }) } - fun fetchProgram(tvModel: TVViewModel) { - yspProtoService?.getProgram("", "")?.enqueue(object : Callback { - override fun onResponse(call: Call, response: Response) { - if (response.isSuccessful) { - val liveInfo = response.body() - Log.i(TAG, "${liveInfo?.data?.playurl}") - } - } + private fun getCurrentDate(): String { + val currentDate = Date() + val formatter = SimpleDateFormat("yyyyMMdd", Locale.CHINA) + return formatter.format(currentDate) + } - override fun onFailure(call: Call, t: Throwable) { - } - }) + fun fetchProgram(tvModel: TVViewModel) { + yspProtoService?.getProgram(tvModel.programId.value!!, getCurrentDate()) + ?.enqueue(object : Callback { + override fun onResponse( + call: Call, + response: Response + ) { + if (response.isSuccessful) { + val program = response.body() + if (program != null) { + tvModel.addProgram(program.dataListList) + } + } + } + + override fun onFailure(call: Call, t: Throwable) { + Log.e(TAG, "Program request failed", t) + } + }) } private fun encryptTripleDES(key: ByteArray, iv: ByteArray): String { diff --git a/app/src/main/java/com/lizongying/mytv/api/Page.kt b/app/src/main/java/com/lizongying/mytv/api/Page.kt deleted file mode 100644 index 8b61a3b..0000000 --- a/app/src/main/java/com/lizongying/mytv/api/Page.kt +++ /dev/null @@ -1,24 +0,0 @@ -package com.lizongying.mytv.api - -import okhttp3.MediaType -import okhttp3.RequestBody -import okio.BufferedSink -import java.io.IOException - -data class Page( - val code: Int, - val msg: String, - val data: Data, -) - -data class Data( - val feedModuleList: List -) - -data class Module( - val dataTvChannelList: List -) - -data class TvChannelListData( - val dataTvChannelList: List -) \ No newline at end of file diff --git a/app/src/main/java/com/lizongying/mytv/api/YSPProtoService.kt b/app/src/main/java/com/lizongying/mytv/api/YSPProtoService.kt index 59a65eb..1d67fbc 100644 --- a/app/src/main/java/com/lizongying/mytv/api/YSPProtoService.kt +++ b/app/src/main/java/com/lizongying/mytv/api/YSPProtoService.kt @@ -1,6 +1,7 @@ package com.lizongying.mytv.api import com.lizongying.mytv.proto.Ysp.cn.yangshipin.oms.common.proto.pageModel +import com.lizongying.mytv.proto.Ysp.cn.yangshipin.omstv.common.proto.epgProgramModel import retrofit2.Call import retrofit2.http.GET import retrofit2.http.Headers @@ -15,13 +16,13 @@ interface YSPProtoService { fun getPage( ): Call - @GET("api/yspepg/program/{livepid}/{cnlid}") + @GET("api/yspepg/program/{livepid}/{date}") @Headers( "yspappid: 519748109", "platform: 109", ) fun getProgram( @Path("livepid") livepid: String, - @Path("cnlid") cnlid: String, - ): Call + @Path("date") date: String, + ): Call } \ No newline at end of file diff --git a/app/src/main/java/com/lizongying/mytv/models/TVViewModel.kt b/app/src/main/java/com/lizongying/mytv/models/TVViewModel.kt index 655f99c..95146af 100644 --- a/app/src/main/java/com/lizongying/mytv/models/TVViewModel.kt +++ b/app/src/main/java/com/lizongying/mytv/models/TVViewModel.kt @@ -5,6 +5,8 @@ import androidx.lifecycle.LiveData import androidx.lifecycle.MutableLiveData import androidx.lifecycle.ViewModel import com.lizongying.mytv.TV +import com.lizongying.mytv.proto.Ysp.cn.yangshipin.omstv.common.proto.programModel.Program +import java.util.Date class TVViewModel(private var tv: TV) : ViewModel() { private var mapping = mapOf( @@ -54,11 +56,154 @@ class TVViewModel(private var tv: TV) : ViewModel() { "海南卫视" to "海南卫视", ).entries.associate { (key, value) -> value to key } + private var mappingLogo = mapOf( + "CCTV4K" to "https://resources.yangshipin.cn/assets/oms/image/202306/3e9d06fd7244d950df5838750f1c6ac3456e172b51caca2c16d2282125b111e8.png?imageMogr2/format/webp", + "CCTV1" to "https://resources.yangshipin.cn/assets/oms/image/202306/d57905b93540bd15f0c48230dbbbff7ee0d645ff539e38866e2d15c8b9f7dfcd.png?imageMogr2/format/webp", + "CCTV1 综合" to "https://resources.yangshipin.cn/assets/oms/image/202306/d57905b93540bd15f0c48230dbbbff7ee0d645ff539e38866e2d15c8b9f7dfcd.png?imageMogr2/format/webp", + "CCTV2" to "https://resources.yangshipin.cn/assets/oms/image/202306/20115388de0207131af17eac86c33049b95d69eaff064e55653a1b941810a006.png?imageMogr2/format/webp", + "CCTV2 财经" to "https://resources.yangshipin.cn/assets/oms/image/202306/20115388de0207131af17eac86c33049b95d69eaff064e55653a1b941810a006.png?imageMogr2/format/webp", + "CCTV3" to "https://p2.img.cctvpic.com/photoAlbum/page/performance/img/2021/8/16/1629103576424_839.png", + "CCTV3 综艺" to "https://p2.img.cctvpic.com/photoAlbum/page/performance/img/2021/8/16/1629103576424_839.png", + "CCTV4" to "https://resources.yangshipin.cn/assets/oms/image/202306/f357e58fdbcc076a3d65e1f958c942b2e14f14342c60736ceed98b092d35356a.png?imageMogr2/format/webp", + "CCTV4 中文国际" to "https://resources.yangshipin.cn/assets/oms/image/202306/f357e58fdbcc076a3d65e1f958c942b2e14f14342c60736ceed98b092d35356a.png?imageMogr2/format/webp", + "CCTV5" to "https://resources.yangshipin.cn/assets/oms/image/202306/0a6a7138952675983a3d854df7688557b286d59aa06166edae51506f9204d655.png?imageMogr2/format/webp", + "CCTV5 体育" to "https://resources.yangshipin.cn/assets/oms/image/202306/0a6a7138952675983a3d854df7688557b286d59aa06166edae51506f9204d655.png?imageMogr2/format/webp", + "CCTV5+" to "https://resources.yangshipin.cn/assets/oms/image/202306/649ad76a90bfef55b05db9fe52e006487280f619089099d5dc971e387fc6eff0.png?imageMogr2/format/webp", + "CCTV5+ 体育赛事" to "https://resources.yangshipin.cn/assets/oms/image/202306/649ad76a90bfef55b05db9fe52e006487280f619089099d5dc971e387fc6eff0.png?imageMogr2/format/webp", + "CCTV6" to "https://resources.yangshipin.cn/assets/oms/image/202306/741515efda91f03f455df8a7da4ee11fa9329139c276435cf0a9e2af398d5bf2.png?imageMogr2/format/webp", + "CCTV6 电影" to "https://resources.yangshipin.cn/assets/oms/image/202306/741515efda91f03f455df8a7da4ee11fa9329139c276435cf0a9e2af398d5bf2.png?imageMogr2/format/webp", + "CCTV7" to "https://resources.yangshipin.cn/assets/oms/image/202306/b29af94e295ebdf646cefb68122c429b9cd921f498ca20d2d8070252536f9ff9.png?imageMogr2/format/webp", + "CCTV7 国防军事" to "https://resources.yangshipin.cn/assets/oms/image/202306/b29af94e295ebdf646cefb68122c429b9cd921f498ca20d2d8070252536f9ff9.png?imageMogr2/format/webp", + "CCTV8" to "https://resources.yangshipin.cn/assets/oms/image/202306/ad51de94426a0ba039e6dd6a8534ea98ecc813a6176bde87b4f18cc34d6d7590.png?imageMogr2/format/webp", + "CCTV8 电视剧" to "https://resources.yangshipin.cn/assets/oms/image/202306/ad51de94426a0ba039e6dd6a8534ea98ecc813a6176bde87b4f18cc34d6d7590.png?imageMogr2/format/webp", + "CCTV9" to "https://resources.yangshipin.cn/assets/oms/image/202306/2ed1b4deeca179d5db806bb941790f82eb92a1b7299c1c38fe027f95a5caee5e.png?imageMogr2/format/webp", + "CCTV9 记录" to "https://resources.yangshipin.cn/assets/oms/image/202306/2ed1b4deeca179d5db806bb941790f82eb92a1b7299c1c38fe027f95a5caee5e.png?imageMogr2/format/webp", + "CCTV10" to "https://resources.yangshipin.cn/assets/oms/image/202306/aa6157ec65188cd41826e5a2f088c3d6d153205f5f6428258d12c59999e221aa.png?imageMogr2/format/webp", + "CCTV10 科教" to "https://resources.yangshipin.cn/assets/oms/image/202306/aa6157ec65188cd41826e5a2f088c3d6d153205f5f6428258d12c59999e221aa.png?imageMogr2/format/webp", + "CCTV11" to "https://resources.yangshipin.cn/assets/oms/image/202306/ed12ed7c7a1034dae4350011fe039284c5d5a836506b28c9e32e3c75299625c0.png?imageMogr2/format/webp", + "CCTV11 戏曲" to "https://resources.yangshipin.cn/assets/oms/image/202306/ed12ed7c7a1034dae4350011fe039284c5d5a836506b28c9e32e3c75299625c0.png?imageMogr2/format/webp", + "CCTV12" to "https://resources.yangshipin.cn/assets/oms/image/202306/484083cffaa40df7e659565e8cb4d1cc740158a185512114167aa21fa0c59240.png?imageMogr2/format/webp", + "CCTV12 社会与法" to "https://resources.yangshipin.cn/assets/oms/image/202306/484083cffaa40df7e659565e8cb4d1cc740158a185512114167aa21fa0c59240.png?imageMogr2/format/webp", + "CCTV13" to "https://resources.yangshipin.cn/assets/oms/image/202306/266da7b43c03e2312186b4a999e0f060e8f15b10d2cc2c9aa32171819254cf1a.png?imageMogr2/format/webp", + "CCTV13 新闻" to "https://resources.yangshipin.cn/assets/oms/image/202306/266da7b43c03e2312186b4a999e0f060e8f15b10d2cc2c9aa32171819254cf1a.png?imageMogr2/format/webp", + "CCTV14" to "https://resources.yangshipin.cn/assets/oms/image/202306/af6b603896938dc346fbb16abfc63c12cba54b0ec9d18770a15d347d115f12d5.png?imageMogr2/format/webp", + "CCTV14 少儿" to "https://resources.yangshipin.cn/assets/oms/image/202306/af6b603896938dc346fbb16abfc63c12cba54b0ec9d18770a15d347d115f12d5.png?imageMogr2/format/webp", + "CCTV15" to "https://resources.yangshipin.cn/assets/oms/image/202306/2ceee92188ef684efe0d8b90839c4f3ad450d179dc64d59beff417059453af47.png?imageMogr2/format/webp", + "CCTV15 音乐" to "https://resources.yangshipin.cn/assets/oms/image/202306/2ceee92188ef684efe0d8b90839c4f3ad450d179dc64d59beff417059453af47.png?imageMogr2/format/webp", + "CCTV16" to "https://resources.yangshipin.cn/assets/oms/image/202306/53793fa7bacd3a93ff6dc5d2758418985e1f952a316c335d663b572d8bdcd74d.png?imageMogr2/format/webp", + "CCTV16 奥林匹克" to "https://resources.yangshipin.cn/assets/oms/image/202306/53793fa7bacd3a93ff6dc5d2758418985e1f952a316c335d663b572d8bdcd74d.png?imageMogr2/format/webp", + "CCTV17" to "https://resources.yangshipin.cn/assets/oms/image/202306/ddef563072f8bad2bea5b9e52674cb7b4ed50efb20c26e61994dfbdf05c1e3c0.png?imageMogr2/format/webp", + "CCTV17 农业农村" to "https://resources.yangshipin.cn/assets/oms/image/202306/ddef563072f8bad2bea5b9e52674cb7b4ed50efb20c26e61994dfbdf05c1e3c0.png?imageMogr2/format/webp", + "CGTN" to "https://resources.yangshipin.cn/assets/oms/image/202306/a72dff758ca1c17cd0ecc8cedc11b893d208f409d5e6302faa0e9d298848abc3.png?imageMogr2/format/webp", + "CGTN 记录频道" to "https://resources.yangshipin.cn/assets/oms/image/202309/74d3ac436a7e374879578de1d87a941fbf566d39d5632b027c5097891ed32bd5.png?imageMogr2/format/webp", + "CGTN 法语频道" to "https://resources.yangshipin.cn/assets/oms/image/202306/a8d0046a47433d952bf6ed17062deb8bd2184ba9aec0f7781df6bf9487a3ffcf.png?imageMogr2/format/webp", + "CGTN 俄语频道" to "https://resources.yangshipin.cn/assets/oms/image/202306/bf0a820893cbaf20dd0333e27042e1ef9c8806e5b602b6a8c95af399db0bc77a.png?imageMogr2/format/webp", + "CGTN 西班牙语频道" to "https://resources.yangshipin.cn/assets/oms/image/202309/7c337e3dbe64402ec7e4678a619a4a6d95144e42f35161181ff78e143b7cf67a.png?imageMogr2/format/webp", + "CGTN 阿拉伯语频道" to "https://resources.yangshipin.cn/assets/oms/image/202306/2e44e2aa3e7a1cedf07fd0ae59fe69e86a60a2632660a006e3e9e7397b2d107e.png?imageMogr2/format/webp", + + "东方卫视" to "https://resources.yangshipin.cn/assets/oms/image/202306/9bd372ca292a82ce3aa08772b07efc4af1f85c21d1f268ea33440c49e9a0a488.png?imageMogr2/format/webp", + "湖南卫视" to "https://resources.yangshipin.cn/assets/oms/image/202306/4120e89d3079d08aa17d382f69a2308ec70839b278367763c34a34666c75cb88.png?imageMogr2/format/webp", + "湖北卫视" to "https://resources.yangshipin.cn/assets/oms/image/202306/7a6be5a2bb1dc53a945c016ff1f525dc4a84c51db371c15c89aa55404b0ba784.png?imageMogr2/format/webp", + "辽宁卫视" to "https://resources.yangshipin.cn/assets/oms/image/202306/ac4ed6058a87c101ae7147ebc38905d0cae047fb73fd277ee5049b84f52bda36.png?imageMogr2/format/webp", + "江苏卫视" to "https://resources.yangshipin.cn/assets/oms/image/202306/380ad685c0c1d5b2c902246b8d2df6d3f9b45e2837abcfe493075bbded597a31.png?imageMogr2/format/webp", + "江西卫视" to "https://resources.yangshipin.cn/assets/oms/image/202306/3c760d0d00463855890e8a1864ea4a6b6dd66b90c29b4ac714a4b17c16519871.png?imageMogr2/format/webp", + "山东卫视" to "https://resources.yangshipin.cn/assets/oms/image/202306/22d403f07a7cf5410b3ad3ddb65a11aa229a32475fac213f5344c9f0ec330ca1.png?imageMogr2/format/webp", + "广东卫视" to "https://resources.yangshipin.cn/assets/oms/image/202306/28886880a4dc0f06fb7e0a528a1def0591d61a65870e29176ede0cc92033bbfd.png?imageMogr2/format/webp", + "广西卫视" to "https://resources.yangshipin.cn/assets/oms/image/202306/54b7e97cb816bb223fe05f3fc44da2c7820eb66e8550c19d23100f2c414ecc38.png?imageMogr2/format/webp", + "重庆卫视" to "https://resources.yangshipin.cn/assets/oms/image/202306/657651f411de2673d1770d9a78b44c1265704f7468cc41d4be7f51d630768494.png?imageMogr2/format/webp", + "河南卫视" to "https://resources.yangshipin.cn/assets/oms/image/202306/74925962148a6d31c85808b6cd4e444c2a54bab393d2c5fc85e960b50e22fa86.png?imageMogr2/format/webp", + "河北卫视" to "https://resources.yangshipin.cn/assets/oms/image/202306/d545becdc81c60197b08c7f47380705e4665ed3fe55efc8b855e486f6e655378.png?imageMogr2/format/webp", + "贵州卫视" to "https://resources.yangshipin.cn/assets/oms/image/202306/4eb45f4781d33d872af027dc01c941559aab55667dd99cc5c22bef7037807b13.png?imageMogr2/format/webp", + "北京卫视" to "https://resources.yangshipin.cn/assets/oms/image/202306/f4f23633c578beea49a3841d88d3490100f029ee349059fa532869db889872c5.png?imageMogr2/format/webp", + "黑龙江卫视" to "https://resources.yangshipin.cn/assets/oms/image/202306/d8273ae9be698ce2db21f5b886ecac95a73429593f93713c60ed8c12c38bf0d3.png?imageMogr2/format/webp", + "浙江卫视" to "https://resources.yangshipin.cn/assets/oms/image/202306/a66c836bd98ba3e41a2e9a570d4b9c50dedc6839e9de333e2e78212ad505f37e.png?imageMogr2/format/webp", + "安徽卫视" to "https://resources.yangshipin.cn/assets/oms/image/202306/f35fa04b51b1ee4984b03578b65403570868ebca03c6c01e11b097f999a58d9b.png?imageMogr2/format/webp", + "深圳卫视" to "https://resources.yangshipin.cn/assets/oms/image/202306/d59fec04c902e3581c617136d02d4b9b8c4cbe64272781ddd3525e80c823edb7.png?imageMogr2/format/webp", + "四川卫视" to "https://resources.yangshipin.cn/assets/oms/image/202306/3276a414ae0eaa0f116f2045cd913367967d0c7c1e978e8621ac3879436c6ed7.png?imageMogr2/format/webp", + "东南卫视" to "https://resources.yangshipin.cn/assets/oms/image/202306/3208fe6564a293c21b711333fb3edb05bb5b406cff840573c9a8d839680a1579.png?imageMogr2/format/webp", + "海南卫视" to "https://resources.yangshipin.cn/assets/oms/image/202306/6e060391fde0469801fc3d84dbf204b4f8d650d251f17d7595a6964c0bb99e81.png?imageMogr2/format/webp", + ) + + private var mappingEPG = mapOf( + "CCTV4K" to "600002264", + "CCTV1" to "600001859", + "CCTV1 综合" to "600001859", + "CCTV2" to "600001800", + "CCTV2 财经" to "600001800", +// "CCTV3" to "", +// "CCTV3 综艺" to "", + "CCTV4" to "600001814", + "CCTV4 中文国际" to "600001814", + "CCTV5" to "600001818", + "CCTV5 体育" to "600001818", + "CCTV5+" to "600001817", + "CCTV5+ 体育赛事" to "600001817", + "CCTV6" to "600001802", + "CCTV6 电影" to "600001802", + "CCTV7" to "600004092", + "CCTV7 国防军事" to "600004092", + "CCTV8" to "600001803", + "CCTV8 电视剧" to "600001803", + "CCTV9" to "600004078", + "CCTV9 记录" to "600004078", + "CCTV10" to "600001805", + "CCTV10 科教" to "600001805", + "CCTV11" to "600001806", + "CCTV11 戏曲" to "600001806", + "CCTV12" to "600001807", + "CCTV12 社会与法" to "600001807", + "CCTV13" to "600001811", + "CCTV13 新闻" to "600001811", + "CCTV14" to "600001809", + "CCTV14 少儿" to "600001809", + "CCTV15" to "600001815", + "CCTV15 音乐" to "600001815", + "CCTV16" to "600098637", + "CCTV16 奥林匹克" to "600098637", + "CCTV17" to "600001810", + "CCTV17 农业农村" to "600001810", + "CGTN" to "600014550", + "CGTN 法语频道" to "600084704", + "CGTN 俄语频道" to "600084758", + "CGTN 西班牙语频道" to "600084744", + "CGTN 阿拉伯语频道" to "600084782", + + "东方卫视" to "600002483", + "湖南卫视" to "600002475", + "湖北卫视" to "600002508", + "辽宁卫视" to "600002505", + "江苏卫视" to "600002521", + "江西卫视" to "600002503", + "山东卫视" to "600002513", + "广东卫视" to "600002485", + "广西卫视" to "600002509", + "重庆卫视" to "600002531", + "河南卫视" to "600002525", + "河北卫视" to "600002493", + "贵州卫视" to "600002490", + "北京卫视" to "600002309", + "黑龙江卫视" to "600002498", + "浙江卫视" to "600002520", + "安徽卫视" to "600002532", + "深圳卫视" to "600002481", + "四川卫视" to "600002516", + "东南卫视" to "600002484", + "海南卫视" to "600002506", + ) + private var isFirstTime = true private var rowPosition: Int = 0 private var itemPosition: Int = 0 + private val _programId = MutableLiveData() + val programId: LiveData + get() = _programId + + private var _program = MutableLiveData>() + val program: LiveData> + get() = _program + private val _id = MutableLiveData() val id: LiveData get() = _id @@ -140,8 +285,16 @@ class TVViewModel(private var tv: TV) : ViewModel() { _title.value = tv.title _videoUrl.value = tv.videoUrl _videoIndex.value = tv.videoIndex + if (mappingLogo[tv.title] != null) { + _logo.value = mappingLogo[tv.title] + } _pid.value = tv.pid _sid.value = tv.sid + _program.value = mutableListOf() + + if (mappingEPG[tv.title] != null) { + _programId.value = mappingEPG[tv.title] + } } fun getIsFirstTime(): Boolean { @@ -183,6 +336,31 @@ class TVViewModel(private var tv: TV) : ViewModel() { return mapping[tv.title] } + fun getProgram(): MutableList? { + _program.value = (_program.value?.filter { it.et > (Date().time / 1000) })?.toMutableList() + return _program.value?.subList(0, 2) + } + + fun getProgramOne(): Program? { + val programNew = (_program.value?.filter { it.et > (Date().time / 1000) })?.toMutableList() + if (_program.value != programNew) { + _program.value = programNew + } + if (_program.value!!.isEmpty()) { + return null + } + return _program.value?.first() + } + + fun addProgram(p: MutableList) { + if (_program.value == null) { + _program.value = p + } else { + _program.value = + ((_program.value?.filter { it.st < p.first().st })?.plus(p))?.toMutableList() + } + } + companion object { private const val TAG = "TVViewModel" } diff --git a/app/src/main/res/values/styles.xml b/app/src/main/res/values/styles.xml index 51bdee8..5157486 100644 --- a/app/src/main/res/values/styles.xml +++ b/app/src/main/res/values/styles.xml @@ -2,7 +2,8 @@ \ No newline at end of file diff --git a/screenshots/img.png b/screenshots/img.png index 0fdd973..30dad63 100644 Binary files a/screenshots/img.png and b/screenshots/img.png differ