remove left headers

This commit is contained in:
Li ZongYing
2023-12-20 14:55:39 +08:00
parent e6fa9a50db
commit 0285f1b3b1
15 changed files with 341 additions and 238 deletions
@@ -1,47 +1,61 @@
package com.lizongying.mytv.models
import android.content.SharedPreferences
import androidx.lifecycle.LiveData
import androidx.lifecycle.MutableLiveData
import androidx.lifecycle.ViewModel
import com.lizongying.mytv.TV
class TVListViewModel : ViewModel() {
private val tvListLiveData = MutableLiveData<MutableList<TV>>()
private val tvModelListLiveData = MutableLiveData<MutableList<TVViewModel>>()
var maxNum = mutableListOf<Int>()
fun getListLiveData(): MutableLiveData<MutableList<TVViewModel>> {
return tvModelListLiveData
private var sharedPref: SharedPreferences? = null
private val tvListViewModel = MutableLiveData<MutableList<TVViewModel>>()
private val _itemPosition = MutableLiveData<Int>()
val itemPosition: LiveData<Int>
get() = _itemPosition
private val _itemPositionCurrent = MutableLiveData<Int>()
val itemPositionCurrent: LiveData<Int>
get() = _itemPositionCurrent
fun getTVListViewModel(): MutableLiveData<MutableList<TVViewModel>> {
return tvListViewModel
}
fun addTV(tv: TV) {
val currentList = tvListLiveData.value ?: mutableListOf()
currentList.add(tv)
tvListLiveData.value = currentList
val currentModelList = tvModelListLiveData.value ?: mutableListOf()
currentModelList.add(TVViewModel(tv))
tvModelListLiveData.value = currentModelList
fun addTVViewModel(tvViewModel: TVViewModel) {
val currentTVModelList = tvListViewModel.value ?: mutableListOf()
currentTVModelList.add(tvViewModel)
tvListViewModel.value = currentTVModelList
}
fun updateTV(tv: TV) {
val currentList = tvListLiveData.value ?: mutableListOf()
currentList[tv.id] = tv
tvListLiveData.value = currentList
val currentModelList = tvModelListLiveData.value ?: mutableListOf()
currentModelList[tv.id].update(tv)
tvModelListLiveData.value = currentModelList
fun getTVViewModel(id: Int): TVViewModel? {
return tvListViewModel.value?.get(id)
}
fun getTV(id: Int): TV? {
return tvListLiveData.value?.get(id)
fun getTVViewModelCurrent(): TVViewModel? {
return _itemPositionCurrent.value?.let { tvListViewModel.value?.get(it) }
}
fun getTVModel(id: Int): TVViewModel? {
return tvModelListLiveData.value?.get(id)
fun setItemPosition(position: Int) {
_itemPosition.value = position
_itemPositionCurrent.value = position
}
fun setItemPositionCurrent(position: Int) {
_itemPositionCurrent.value = position
}
fun savePosition(position: Int) {
with(sharedPref!!.edit()) {
putInt("position", position)
apply()
}
}
fun size(): Int {
return tvListLiveData.value!!.size
return tvListViewModel.value!!.size
}
}
@@ -56,6 +56,9 @@ class TVViewModel(private var tv: TV) : ViewModel() {
private var isFirstTime = true
private var rowPosition: Int = 0
private var itemPosition: Int = 0
private val _id = MutableLiveData<Int>()
val id: LiveData<Int>
get() = _id
@@ -72,6 +75,10 @@ class TVViewModel(private var tv: TV) : ViewModel() {
val videoIndex: LiveData<Int>
get() = _videoIndex
private val _logo = MutableLiveData<String>()
val logo: LiveData<String>
get() = _logo
private val _pid = MutableLiveData<String>()
val pid: LiveData<String>
get() = _pid
@@ -80,34 +87,54 @@ class TVViewModel(private var tv: TV) : ViewModel() {
val sid: LiveData<String>
get() = _sid
private val _backgroundImage = MutableLiveData<String>()
val backgroundImage: LiveData<String>
get() = _backgroundImage
private val _change = MutableLiveData<Boolean>()
val change: LiveData<Boolean>
get() = _change
fun getBackgroundImage(): String {
return tv.logo ?: ""
}
fun updateBackgroundImage(url: String) {
_backgroundImage.value = url
}
private val _ready = MutableLiveData<Boolean>()
val ready: LiveData<Boolean>
get() = _ready
fun addVideoUrl(url: String) {
tv.videoUrl = tv.videoUrl + listOf(url)
if (_videoUrl.value?.isNotEmpty() == true) {
if (_videoUrl.value!!.last().contains("cctv.cn")) {
tv.videoUrl = tv.videoUrl.subList(0, tv.videoUrl.lastIndex) + listOf(url)
} else {
tv.videoUrl = tv.videoUrl + listOf(url)
}
} else {
tv.videoUrl = tv.videoUrl + listOf(url)
}
tv.videoIndex = tv.videoUrl.lastIndex
_videoUrl.value = tv.videoUrl
_videoIndex.value = tv.videoIndex
}
fun firstSource() {
if (tv.videoUrl.isNotEmpty()) {
tv.videoIndex = 0
_videoIndex.value = 0
if (_videoUrl.value!!.isNotEmpty()) {
setVideoIndex(0)
allReady()
} else {
Log.e(TAG, "no first")
}
}
fun changed() {
_change.value = true
}
fun allReady() {
_ready.value = true
}
fun setVideoIndex(videoIndex: Int) {
_videoIndex.value = videoIndex
}
fun setLogo(url: String) {
_logo.value = url
}
init {
_id.value = tv.id
_title.value = tv.title
@@ -125,6 +152,22 @@ class TVViewModel(private var tv: TV) : ViewModel() {
isFirstTime = firstTime
}
fun getRowPosition(): Int {
return rowPosition
}
fun getItemPosition(): Int {
return itemPosition
}
fun setRowPosition(position: Int) {
rowPosition = position
}
fun setItemPosition(position: Int) {
itemPosition = position
}
fun update(t: TV) {
tv = t
}