diff --git a/app/src/main/java/com/lizongying/mytv/MainActivity.kt b/app/src/main/java/com/lizongying/mytv/MainActivity.kt index 0684c1a..a7c6d39 100644 --- a/app/src/main/java/com/lizongying/mytv/MainActivity.kt +++ b/app/src/main/java/com/lizongying/mytv/MainActivity.kt @@ -10,7 +10,9 @@ import android.os.Bundle import android.os.Handler import android.os.Looper import android.util.Log +import android.view.GestureDetector import android.view.KeyEvent +import android.view.MotionEvent import android.view.WindowManager import android.widget.ImageView import android.widget.LinearLayout @@ -30,11 +32,14 @@ class MainActivity : FragmentActivity() { private var doubleBackToExitPressedOnce = false + private lateinit var gestureDetector: GestureDetector + override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) setContentView(R.layout.activity_main) - window.addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON); + window.addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON) + window.addFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN) if (savedInstanceState == null) { supportFragmentManager.beginTransaction() @@ -44,6 +49,7 @@ class MainActivity : FragmentActivity() { .hide(infoFragment) .commit() } + gestureDetector = GestureDetector(this, GestureListener()) } fun switchInfoFragment(tv: TV) { @@ -117,6 +123,85 @@ class MainActivity : FragmentActivity() { } } + override fun onTouchEvent(event: MotionEvent?): Boolean { + // 在触摸事件中将事件传递给 GestureDetector 处理手势 + if (event != null) { + gestureDetector.onTouchEvent(event) + } + return super.onTouchEvent(event) + } + + private inner class GestureListener : GestureDetector.SimpleOnGestureListener() { + + override fun onSingleTapConfirmed(e: MotionEvent): Boolean { + // 处理单击事件 + val versionName = getPackageInfo().versionName + + val textView = TextView(this@MainActivity) + textView.text = + "当前版本: $versionName\n获取最新: https://github.com/lizongying/my-tv/releases/" + + val imageView = ImageView(this@MainActivity) + val drawable = ContextCompat.getDrawable(this@MainActivity, R.drawable.appreciate) + imageView.setImageDrawable(drawable) + + val linearLayout = LinearLayout(this@MainActivity) + linearLayout.orientation = LinearLayout.VERTICAL + linearLayout.addView(textView) + linearLayout.addView(imageView) + + val layoutParams = LinearLayout.LayoutParams( + LinearLayout.LayoutParams.MATCH_PARENT, + LinearLayout.LayoutParams.WRAP_CONTENT + ) + imageView.layoutParams = layoutParams + textView.layoutParams = layoutParams + + val builder: AlertDialog.Builder = AlertDialog.Builder(this@MainActivity) + builder + .setView(linearLayout) + + val dialog: AlertDialog = builder.create() + dialog.show() + return true + } + + override fun onFling( + e1: MotionEvent, + e2: MotionEvent, + velocityX: Float, + velocityY: Float + ): Boolean { + // 如果 Y 方向的速度为负值,表示向上滑动 + if (velocityY < 0) { + // 在这里执行上滑时的操作 + if (mainFragment.isHidden) { + prev() + } else { + if (mainFragment.selectedPosition == 0) { + mainFragment.setSelectedPosition( + mainFragment.tvListViewModel.maxNum.size - 1, + false + ) + } + } + } + if (velocityY > 0) { + // 在这里执行上滑时的操作 + if (mainFragment.isHidden) { + next() + } else { + if (mainFragment.selectedPosition == mainFragment.tvListViewModel.maxNum.size - 1) { +// mainFragment.setSelectedPosition(0, false) + hideMainFragment() + return false + } + } + } + return super.onFling(e1, e2, velocityX, velocityY) + } + } + override fun onKeyDown(keyCode: Int, event: KeyEvent?): Boolean { when (keyCode) { KeyEvent.KEYCODE_BACK -> { @@ -173,6 +258,9 @@ class MainActivity : FragmentActivity() { KeyEvent.KEYCODE_DPAD_CENTER -> { Log.i(TAG, "KEYCODE_DPAD_CENTER") +// if (mainFragment.isHidden) { +// mainFragment.checkProgram() +// } switchMainFragment() } diff --git a/app/src/main/java/com/lizongying/mytv/MainFragment.kt b/app/src/main/java/com/lizongying/mytv/MainFragment.kt index 4875693..db074f1 100644 --- a/app/src/main/java/com/lizongying/mytv/MainFragment.kt +++ b/app/src/main/java/com/lizongying/mytv/MainFragment.kt @@ -5,7 +5,6 @@ import android.content.SharedPreferences import android.os.Bundle import android.util.Log import android.widget.Toast -import androidx.core.content.ContextCompat import androidx.leanback.app.BrowseSupportFragment import androidx.leanback.widget.ArrayObjectAdapter import androidx.leanback.widget.HeaderItem @@ -44,7 +43,6 @@ class MainFragment : BrowseSupportFragment() { sharedPref = activity?.getPreferences(Context.MODE_PRIVATE) - setupUIElements() request = activity?.let { Request(it) } loadRows() setupEventListeners() @@ -88,7 +86,7 @@ class MainFragment : BrowseSupportFragment() { } } tvViewModel.program.observe(viewLifecycleOwner) { _ -> - if (tvViewModel.program.value == null || tvViewModel.program.value?.size!! < 3) { + if (tvViewModel.program.value!!.isEmpty()) { if (tvViewModel.programId.value != null) { Log.i(TAG, "get program ${tvViewModel.title.value}") request?.fetchProgram(tvViewModel) @@ -98,6 +96,17 @@ class MainFragment : BrowseSupportFragment() { } } + fun checkProgram() { + tvListViewModel.getTVListViewModel().value?.forEach { tvViewModel -> + if (tvViewModel.program.value!!.isEmpty()) { + if (tvViewModel.programId.value != null) { + Log.i(TAG, "get program ${tvViewModel.title.value}") + request?.fetchProgram(tvViewModel) + } + } + } + } + fun toLastPosition() { setSelectedPosition( selectedPosition, false, @@ -113,42 +122,8 @@ class MainFragment : BrowseSupportFragment() { } override fun startHeadersTransition(withHeaders: Boolean) { -// check(mCanShowHeaders) { "Cannot start headers transition" } -// if (isInHeadersTransition || mShowingHeaders == withHeaders) { -// return -// } -// startHeadersTransitionInternal(withHeaders) } - private fun setupUIElements() { - brandColor = ContextCompat.getColor(context!!, R.color.fastlane_background) -// var headers = headersSupportFragment -// headers.setMenuVisibility(false) -// Log.i(TAG, "headers $headers") - -// setHeadersState(HEADERS_DISABLED); -// -// setHeaderPresenterSelector(object : PresenterSelector() { -// override fun getPresenter(o: Any): Presenter { -// return IconHeaderItemPresenter() -// } -// }) -// showHeaders(true) - } - -// private fun updateRows(tv: TV) { -//// 获取适配器中的数据 -// val dataList = rowsAdapter?.replace(tv.id, tv) -//// -////// 修改数据 -////// 这里假设 dataList 是一个可变的列表 -//// dataList[position] = updatedData -//// -////// 刷新适配器 -//// rowsAdapter.notifyItemChanged(position) -//// rowsAdapter.notifyItemRangeChanged() -// } - private fun loadRows() { rowsAdapter = ArrayObjectAdapter(ListRowPresenter()) @@ -243,14 +218,13 @@ class MainFragment : BrowseSupportFragment() { view?.post { val tvViewModel = tvListViewModel.getTVViewModel(itemPosition) if (tvViewModel != null) { - tvViewModel.changed() -// if (tvViewModel.videoUrl.value!!.size > 1) { -// val videoIndex = tvViewModel.videoIndex.value?.plus(1) -// if (videoIndex == tvViewModel.videoUrl.value!!.size) { -// tvViewModel.setVideoIndex(0) -// } -// tvViewModel.changed() -// } + if (tvViewModel.videoUrl.value!!.size > 1) { + val videoIndex = tvViewModel.videoIndex.value?.plus(1) + if (videoIndex == tvViewModel.videoUrl.value!!.size) { + tvViewModel.setVideoIndex(0) + } + tvViewModel.changed() + } } } } diff --git a/app/src/main/java/com/lizongying/mytv/Request.kt b/app/src/main/java/com/lizongying/mytv/Request.kt index dc91729..d0906bf 100644 --- a/app/src/main/java/com/lizongying/mytv/Request.kt +++ b/app/src/main/java/com/lizongying/mytv/Request.kt @@ -30,7 +30,7 @@ class Request(var context: Context) { private var yspProtoService: YSPProtoService? = null private var mapping = mapOf( - "CCTV4K" to "CCTV4K", + "CCTV4K" to "CCTV4K 超高清", "CCTV1" to "CCTV1 综合", "CCTV2" to "CCTV2 财经", "CCTV4" to "CCTV4 中文国际", diff --git a/app/src/main/java/com/lizongying/mytv/TVList.kt b/app/src/main/java/com/lizongying/mytv/TVList.kt index 6dcbcd1..17a8b49 100644 --- a/app/src/main/java/com/lizongying/mytv/TVList.kt +++ b/app/src/main/java/com/lizongying/mytv/TVList.kt @@ -10,7 +10,7 @@ object TVList { private fun setupTV(): Map> { val tvs = """ 央视频道 -CCTV4K,,https://resources.yangshipin.cn/assets/oms/image/202306/3e9d06fd7244d950df5838750f1c6ac3456e172b51caca2c16d2282125b111e8.png?imageMogr2/format/webp,600002264,2000266303 +CCTV4K 超高清,,https://resources.yangshipin.cn/assets/oms/image/202306/3e9d06fd7244d950df5838750f1c6ac3456e172b51caca2c16d2282125b111e8.png?imageMogr2/format/webp,600002264,2000266303 CCTV1 综合,http://tvpull.dxhmt.cn/tv/11481-4.m3u8,https://resources.yangshipin.cn/assets/oms/image/202306/d57905b93540bd15f0c48230dbbbff7ee0d645ff539e38866e2d15c8b9f7dfcd.png?imageMogr2/format/webp,600001859,2000210103 CCTV2 财经,http://dbiptv.sn.chinamobile.com/PLTV/88888890/224/3221226195/index.m3u8,https://resources.yangshipin.cn/assets/oms/image/202306/20115388de0207131af17eac86c33049b95d69eaff064e55653a1b941810a006.png?imageMogr2/format/webp,600001800,2000203603 CCTV3 综艺,http://dbiptv.sn.chinamobile.com/PLTV/88888890/224/3221226397/index.m3u8 @@ -40,36 +40,36 @@ CGTN 阿拉伯语频道,http://livear.cgtn.com/1000a/prog_index.m3u8,https://res 地方频道 东方卫视,http://dbiptv.sn.chinamobile.com/PLTV/88888890/224/3221226217/index.m3u8,https://resources.yangshipin.cn/assets/oms/image/202306/9bd372ca292a82ce3aa08772b07efc4af1f85c21d1f268ea33440c49e9a0a488.png?imageMogr2/format/webp,600002483,2000292403 -内蒙古卫视,http://ottrrs.hl.chinamobile.com/PLTV/88888888/224/3221226389/index.m3u8 湖南卫视,http://ottrrs.hl.chinamobile.com/PLTV/88888888/224/3221226307/index.m3u8,https://resources.yangshipin.cn/assets/oms/image/202306/4120e89d3079d08aa17d382f69a2308ec70839b278367763c34a34666c75cb88.png?imageMogr2/format/webp,600002475,2000296203 湖北卫视,http://ottrrs.hl.chinamobile.com/PLTV/88888888/224/3221226477/index.m3u8,https://resources.yangshipin.cn/assets/oms/image/202306/7a6be5a2bb1dc53a945c016ff1f525dc4a84c51db371c15c89aa55404b0ba784.png?imageMogr2/format/webp,600002508,2000294503 辽宁卫视,http://ottrrs.hl.chinamobile.com/PLTV/88888888/224/3221226546/index.m3u8,https://resources.yangshipin.cn/assets/oms/image/202306/ac4ed6058a87c101ae7147ebc38905d0cae047fb73fd277ee5049b84f52bda36.png?imageMogr2/format/webp,600002505,2000281303 江苏卫视,http://39.134.24.166/dbiptv.sn.chinamobile.com/PLTV/88888890/224/3221226200/index.m3u8,https://resources.yangshipin.cn/assets/oms/image/202306/380ad685c0c1d5b2c902246b8d2df6d3f9b45e2837abcfe493075bbded597a31.png?imageMogr2/format/webp,600002521,2000295603 江西卫视,http://ottrrs.hl.chinamobile.com/PLTV/88888888/224/3221226344/index.m3u8,https://resources.yangshipin.cn/assets/oms/image/202306/3c760d0d00463855890e8a1864ea4a6b6dd66b90c29b4ac714a4b17c16519871.png?imageMogr2/format/webp,600002503,2000294103 -西藏卫视,http://39.134.24.161/dbiptv.sn.chinamobile.com/PLTV/88888890/224/3221226212/index.m3u8 山东卫视,http://dbiptv.sn.chinamobile.com/PLTV/88888890/224/3221226209/index.m3u8,https://resources.yangshipin.cn/assets/oms/image/202306/22d403f07a7cf5410b3ad3ddb65a11aa229a32475fac213f5344c9f0ec330ca1.png?imageMogr2/format/webp,600002513,2000294803 -山西卫视,http://39.134.24.161/dbiptv.sn.chinamobile.com/PLTV/88888890/224/3221225763/index.m3u8 广东卫视,http://dbiptv.sn.chinamobile.com/PLTV/88888890/224/3221226216/index.m3u8,https://resources.yangshipin.cn/assets/oms/image/202306/28886880a4dc0f06fb7e0a528a1def0591d61a65870e29176ede0cc92033bbfd.png?imageMogr2/format/webp,600002485,2000292703 广西卫视,http://live.gxrb.com.cn/tv/gxtvlive03/index.m3u8,https://resources.yangshipin.cn/assets/oms/image/202306/54b7e97cb816bb223fe05f3fc44da2c7820eb66e8550c19d23100f2c414ecc38.png?imageMogr2/format/webp,600002509,2000294203 重庆卫视,http://ottrrs.hl.chinamobile.com/PLTV/88888888/224/3221226409/index.m3u8,https://resources.yangshipin.cn/assets/oms/image/202306/657651f411de2673d1770d9a78b44c1265704f7468cc41d4be7f51d630768494.png?imageMogr2/format/webp,600002531,2000297803 -甘肃卫视,http://ottrrs.hl.chinamobile.com/PLTV/88888888/224/3221225633/index.m3u8 -青海卫视,http://stream.qhbtv.com/qhws/sd/live.m3u8 -陕西卫视,http://ottrrs.hl.chinamobile.com/PLTV/88888888/224/3221226457/index.m3u8 河南卫视,http://ottrrs.hl.chinamobile.com/PLTV/88888888/224/3221226480/index.m3u8,https://resources.yangshipin.cn/assets/oms/image/202306/74925962148a6d31c85808b6cd4e444c2a54bab393d2c5fc85e960b50e22fa86.png?imageMogr2/format/webp,600002525,2000296103 河北卫视,http://ottrrs.hl.chinamobile.com/PLTV/88888888/224/3221226406/index.m3u8,https://resources.yangshipin.cn/assets/oms/image/202306/d545becdc81c60197b08c7f47380705e4665ed3fe55efc8b855e486f6e655378.png?imageMogr2/format/webp,600002493,2000293403 -云南卫视,http://ottrrs.hl.chinamobile.com/PLTV/88888888/224/3221226444/index.m3u8 贵州卫视,http://ottrrs.hl.chinamobile.com/PLTV/88888888/224/3221226474/index.m3u8,https://resources.yangshipin.cn/assets/oms/image/202306/4eb45f4781d33d872af027dc01c941559aab55667dd99cc5c22bef7037807b13.png?imageMogr2/format/webp,600002490,2000293303 -新疆卫视,http://ottrrs.hl.chinamobile.com/PLTV/88888888/224/3221226460/index.m3u8 北京卫视,http://ottrrs.hl.chinamobile.com/PLTV/88888888/224/3221225728/index.m3u8,https://resources.yangshipin.cn/assets/oms/image/202306/f4f23633c578beea49a3841d88d3490100f029ee349059fa532869db889872c5.png?imageMogr2/format/webp,600002309,2000272103 -天津卫视,http://ottrrs.hl.chinamobile.com/PLTV/88888888/224/3221225740/index.m3u8 黑龙江卫视,http://ottrrs.hl.chinamobile.com/PLTV/88888888/224/3221226327/index.m3u8,https://resources.yangshipin.cn/assets/oms/image/202306/d8273ae9be698ce2db21f5b886ecac95a73429593f93713c60ed8c12c38bf0d3.png?imageMogr2/format/webp,600002498,2000293903 -吉林卫视,http://ottrrs.hl.chinamobile.com/PLTV/88888888/224/3221226397/index.m3u8 浙江卫视,http://hw-m-l.cztv.com/channels/lantian/channel01/1080p.m3u8,https://resources.yangshipin.cn/assets/oms/image/202306/a66c836bd98ba3e41a2e9a570d4b9c50dedc6839e9de333e2e78212ad505f37e.png?imageMogr2/format/webp,600002520,2000295503 安徽卫视,http://ottrrs.hl.chinamobile.com/PLTV/88888888/224/3221226391/index.m3u8,https://resources.yangshipin.cn/assets/oms/image/202306/f35fa04b51b1ee4984b03578b65403570868ebca03c6c01e11b097f999a58d9b.png?imageMogr2/format/webp,600002532,2000298003 深圳卫视,http://39.134.24.166/dbiptv.sn.chinamobile.com/PLTV/88888890/224/3221226205/index.m3u8,https://resources.yangshipin.cn/assets/oms/image/202306/d59fec04c902e3581c617136d02d4b9b8c4cbe64272781ddd3525e80c823edb7.png?imageMogr2/format/webp,600002481,2000292203 四川卫视,http://39.134.24.166/dbiptv.sn.chinamobile.com/PLTV/88888890/224/3221225768/index.m3u8,https://resources.yangshipin.cn/assets/oms/image/202306/3276a414ae0eaa0f116f2045cd913367967d0c7c1e978e8621ac3879436c6ed7.png?imageMogr2/format/webp,600002516,2000295003 东南卫视,http://ottrrs.hl.chinamobile.com/PLTV/88888888/224/3221226341/index.m3u8,https://resources.yangshipin.cn/assets/oms/image/202306/3208fe6564a293c21b711333fb3edb05bb5b406cff840573c9a8d839680a1579.png?imageMogr2/format/webp,600002484,2000292503 海南卫视,http://ottrrs.hl.chinamobile.com/PLTV/88888888/224/3221226465/index.m3u8,https://resources.yangshipin.cn/assets/oms/image/202306/6e060391fde0469801fc3d84dbf204b4f8d650d251f17d7595a6964c0bb99e81.png?imageMogr2/format/webp,600002506,2000291503 +天津卫视,http://ottrrs.hl.chinamobile.com/PLTV/88888888/224/3221225740/index.m3u8 +吉林卫视,http://ottrrs.hl.chinamobile.com/PLTV/88888888/224/3221226397/index.m3u8 +云南卫视,http://ottrrs.hl.chinamobile.com/PLTV/88888888/224/3221226444/index.m3u8 +内蒙古卫视,http://ottrrs.hl.chinamobile.com/PLTV/88888888/224/3221226389/index.m3u8 +新疆卫视,http://ottrrs.hl.chinamobile.com/PLTV/88888888/224/3221226460/index.m3u8 +甘肃卫视,http://ottrrs.hl.chinamobile.com/PLTV/88888888/224/3221225633/index.m3u8 +青海卫视,http://stream.qhbtv.com/qhws/sd/live.m3u8 +陕西卫视,http://ottrrs.hl.chinamobile.com/PLTV/88888888/224/3221226457/index.m3u8 +西藏卫视,http://39.134.24.161/dbiptv.sn.chinamobile.com/PLTV/88888890/224/3221226212/index.m3u8 +山西卫视,http://39.134.24.161/dbiptv.sn.chinamobile.com/PLTV/88888890/224/3221225763/index.m3u8 宁夏卫视,http://dbiptv.sn.chinamobile.com/PLTV/88888890/224/3221225748/index.m3u8 安多卫视,http://stream.qhbtv.com/adws/sd/live.m3u8 三沙卫视,https://pullsstv90080111.ssws.tv/live/SSTV20220729.m3u8 diff --git a/app/src/main/java/com/lizongying/mytv/api/YSP.kt b/app/src/main/java/com/lizongying/mytv/api/YSP.kt index 85a63e2..430ffb8 100644 --- a/app/src/main/java/com/lizongying/mytv/api/YSP.kt +++ b/app/src/main/java/com/lizongying/mytv/api/YSP.kt @@ -68,7 +68,6 @@ class YSP(var context: Context) { cnlid = tvModel.sid.value!! defn = "fhd" -// guid = getGuid() randStr = getRand() timeStr = getTimeStr() 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 95146af..90aacba 100644 --- a/app/src/main/java/com/lizongying/mytv/models/TVViewModel.kt +++ b/app/src/main/java/com/lizongying/mytv/models/TVViewModel.kt @@ -10,7 +10,7 @@ import java.util.Date class TVViewModel(private var tv: TV) : ViewModel() { private var mapping = mapOf( - "CCTV4K" to "CCTV4K", + "CCTV4K" to "CCTV4K 超高清", "CCTV1" to "CCTV1 综合", "CCTV2" to "CCTV2 财经", "CCTV4" to "CCTV4 中文国际", @@ -58,12 +58,13 @@ class TVViewModel(private var tv: TV) : ViewModel() { private var mappingLogo = mapOf( "CCTV4K" to "https://resources.yangshipin.cn/assets/oms/image/202306/3e9d06fd7244d950df5838750f1c6ac3456e172b51caca2c16d2282125b111e8.png?imageMogr2/format/webp", + "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", + "CCTV3" to "https://resources.yangshipin.cn/assets/oms/image/202306/7b7a65c712450da3deb6ca66fbacf4f9aee00d3f20bd80eafb5ada01ec63eb3a.png?imageMogr2/format/webp", + "CCTV3 综艺" to "https://resources.yangshipin.cn/assets/oms/image/202306/7b7a65c712450da3deb6ca66fbacf4f9aee00d3f20bd80eafb5ada01ec63eb3a.png?imageMogr2/format/webp", "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", @@ -126,12 +127,13 @@ class TVViewModel(private var tv: TV) : ViewModel() { private var mappingEPG = mapOf( "CCTV4K" to "600002264", + "CCTV4K 超高清" to "600002264", "CCTV1" to "600001859", "CCTV1 综合" to "600001859", "CCTV2" to "600001800", "CCTV2 财经" to "600001800", -// "CCTV3" to "", -// "CCTV3 综艺" to "", + "CCTV3" to "600001801", + "CCTV3 综艺" to "600001801", "CCTV4" to "600001814", "CCTV4 中文国际" to "600001814", "CCTV5" to "600001818", @@ -343,7 +345,7 @@ class TVViewModel(private var tv: TV) : ViewModel() { fun getProgramOne(): Program? { val programNew = (_program.value?.filter { it.et > (Date().time / 1000) })?.toMutableList() - if (_program.value != programNew) { + if (programNew != null && _program.value != programNew) { _program.value = programNew } if (_program.value!!.isEmpty()) { @@ -353,11 +355,18 @@ class TVViewModel(private var tv: TV) : ViewModel() { } fun addProgram(p: MutableList) { - if (_program.value == null) { - _program.value = p + val p1 = (p.filter { it.et > (Date().time / 1000) }).toMutableList() + if (p1.isEmpty() || _program.value == p1) { + return + } + + if (_program.value!!.isEmpty()) { + _program.value = p1 } else { _program.value = - ((_program.value?.filter { it.st < p.first().st })?.plus(p))?.toMutableList() + ((_program.value?.filter { it.et > (Date().time / 1000) && it.st < p1.first().st })?.plus( + p1 + ))?.toMutableList() } }