mirror of
https://github.com/lizongying/my-tv.git
synced 2026-11-26 05:16:29 +08:00
backup source
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
package com.lizongying.mytv.models
|
||||
|
||||
import android.util.Log
|
||||
import androidx.lifecycle.LiveData
|
||||
import androidx.lifecycle.MutableLiveData
|
||||
import androidx.lifecycle.ViewModel
|
||||
@@ -8,7 +9,7 @@ import com.lizongying.mytv.TV
|
||||
class TVViewModel(private var tv: TV) : ViewModel() {
|
||||
private var mapping = mapOf(
|
||||
"CCTV4K" to "CCTV4K",
|
||||
// "CCTV1" to "CCTV1 综合",
|
||||
"CCTV1" to "CCTV1 综合",
|
||||
"CCTV2" to "CCTV2 财经",
|
||||
"CCTV4" to "CCTV4 中文国际",
|
||||
"CCTV5" to "CCTV5 体育",
|
||||
@@ -18,17 +19,17 @@ class TVViewModel(private var tv: TV) : ViewModel() {
|
||||
"CCTV10" to "CCTV10 科教",
|
||||
"CCTV11" to "CCTV11 戏曲",
|
||||
"CCTV12" to "CCTV12 社会与法",
|
||||
// "CCTV13" to "CCTV13",
|
||||
"CCTV13" to "CCTV13 新闻",
|
||||
"CCTV14" to "CCTV14 少儿",
|
||||
"CCTV15" to "CCTV15 音乐",
|
||||
"CCTV16-HD" to "CCTV16 奥林匹克",
|
||||
"CCTV17" to "CCTV17 农业农村",
|
||||
"CGTN" to "CGTN",
|
||||
"CGTN外语纪录频道" to "CGTN 纪录频道",
|
||||
"CGTN法语频道" to "CGTN 法语频道",
|
||||
"CGTN俄语频道" to "CGTN 俄语频道",
|
||||
"CGTN阿拉伯语频道" to "CGTN 阿拉伯语频道",
|
||||
"CGTN西班牙语频道" to "CGTN 西班牙语频道",
|
||||
// "CGTN外语纪录频道" to "CGTN外语纪录频道",
|
||||
|
||||
"东方卫视" to "东方卫视",
|
||||
"湖南卫视" to "湖南卫视",
|
||||
@@ -53,12 +54,24 @@ class TVViewModel(private var tv: TV) : ViewModel() {
|
||||
"海南卫视" to "海南卫视",
|
||||
).entries.associate { (key, value) -> value to key }
|
||||
|
||||
private var updateByYSP = false
|
||||
private var isFirstTime = true
|
||||
|
||||
private val _id = MutableLiveData<Int>()
|
||||
val id: LiveData<Int>
|
||||
get() = _id
|
||||
|
||||
private val _title = MutableLiveData<String>()
|
||||
val title: LiveData<String>
|
||||
get() = _title
|
||||
|
||||
private val _videoUrl = MutableLiveData<List<String>>()
|
||||
val videoUrl: LiveData<List<String>>
|
||||
get() = _videoUrl
|
||||
|
||||
private val _videoIndex = MutableLiveData<Int>()
|
||||
val videoIndex: LiveData<Int>
|
||||
get() = _videoIndex
|
||||
|
||||
private val _pid = MutableLiveData<String>()
|
||||
val pid: LiveData<String>
|
||||
get() = _pid
|
||||
@@ -79,25 +92,37 @@ class TVViewModel(private var tv: TV) : ViewModel() {
|
||||
_backgroundImage.value = url
|
||||
}
|
||||
|
||||
private fun updateVideoUrl(url: String) {
|
||||
tv.videoUrl = listOf(url)
|
||||
tv.videoIndex = 0
|
||||
_videoUrl.value = listOf(url)
|
||||
fun addVideoUrl(url: String) {
|
||||
tv.videoUrl = tv.videoUrl + listOf(url)
|
||||
tv.videoIndex = tv.videoUrl.lastIndex
|
||||
_videoUrl.value = tv.videoUrl
|
||||
_videoIndex.value = tv.videoIndex
|
||||
}
|
||||
|
||||
fun updateVideoUrlByYSP(url: String) {
|
||||
updateByYSP = true
|
||||
updateVideoUrl(url)
|
||||
fun firstSource() {
|
||||
if (tv.videoUrl.isNotEmpty()) {
|
||||
tv.videoIndex = 0
|
||||
_videoIndex.value = 0
|
||||
} else {
|
||||
Log.e(TAG, "no first")
|
||||
}
|
||||
}
|
||||
|
||||
init {
|
||||
_id.value = tv.id
|
||||
_title.value = tv.title
|
||||
_videoUrl.value = tv.videoUrl
|
||||
_videoIndex.value = tv.videoIndex
|
||||
_pid.value = tv.pid
|
||||
_sid.value = tv.sid
|
||||
}
|
||||
|
||||
fun updateByYSP(): Boolean {
|
||||
return updateByYSP
|
||||
fun getIsFirstTime(): Boolean {
|
||||
return isFirstTime
|
||||
}
|
||||
|
||||
fun isFirstTime(firstTime: Boolean) {
|
||||
isFirstTime = firstTime
|
||||
}
|
||||
|
||||
fun update(t: TV) {
|
||||
@@ -114,4 +139,8 @@ class TVViewModel(private var tv: TV) : ViewModel() {
|
||||
}
|
||||
return mapping[tv.title]
|
||||
}
|
||||
|
||||
companion object {
|
||||
private const val TAG = "TVViewModel"
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user