Skip to content

Commit

Permalink
optimize channel switch
Browse files Browse the repository at this point in the history
  • Loading branch information
lizongying committed Jan 25, 2024
1 parent 1eb2f25 commit cda1999
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 20 deletions.
15 changes: 14 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,20 @@

## 更新日志

### v1.4.4(安卓4专用)
### v1.4.7(高版本专用)

* 修复部分用户cctv13播放过程中卡住的问题
* 调整cctv的频道顺序

### v1.4.6(通用版)

* 10以下频道不再需要先按0

### v1.4.5(高版本专用)

* 数字选台配置

### v1.4.4(通用版)

* 优化图标显示
* 增加换台反转
Expand Down
34 changes: 18 additions & 16 deletions app/src/main/java/com/lizongying/mytv/ChannelFragment.kt
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package com.lizongying.mytv

import android.os.Bundle
import android.os.Handler
import android.util.Log
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
Expand All @@ -16,6 +15,7 @@ class ChannelFragment : Fragment() {

private val handler = Handler()
private val delay: Long = 3000
private var channel = 0

override fun onCreateView(
inflater: LayoutInflater, container: ViewGroup?,
Expand All @@ -28,37 +28,39 @@ class ChannelFragment : Fragment() {
}

fun show(tvViewModel: TVViewModel) {
handler.removeCallbacks(hideRunnable)
handler.removeCallbacks(playRunnable)
binding.channelContent.text = tvViewModel.id.value.toString()
handler.removeCallbacks(removeRunnable)
view?.visibility = View.VISIBLE
handler.postDelayed(removeRunnable, delay)
handler.postDelayed(hideRunnable, delay)
}

fun show(channel: String) {
this.channel = "${binding.channelContent.text}$channel".toInt()
handler.removeCallbacks(hideRunnable)
handler.removeCallbacks(playRunnable)
if (binding.channelContent.text == "") {
binding.channelContent.text = channel
handler.removeCallbacks(removeRunnable)
view?.visibility = View.VISIBLE
handler.postDelayed(removeRunnable, delay)
handler.postDelayed(playRunnable, delay)
} else {
val ch = "${binding.channelContent.text}$channel".toInt()
(activity as MainActivity).play(ch)
binding.channelContent.text = ""
view?.visibility = View.GONE
handler.postDelayed(playRunnable, 0)
}
}

override fun onResume() {
super.onResume()
handler.postDelayed(removeRunnable, delay)
}

override fun onPause() {
super.onPause()
handler.removeCallbacks(removeRunnable)
handler.removeCallbacks(hideRunnable)
handler.removeCallbacks(playRunnable)
}

private val hideRunnable = Runnable {
binding.channelContent.text = ""
view?.visibility = View.GONE
}

private val removeRunnable = Runnable {
private val playRunnable = Runnable {
(activity as MainActivity).play(channel)
binding.channelContent.text = ""
view?.visibility = View.GONE
}
Expand Down
9 changes: 6 additions & 3 deletions app/src/main/java/com/lizongying/mytv/MainFragment.kt
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import androidx.lifecycle.lifecycleScope
import androidx.recyclerview.widget.LinearLayoutManager
import androidx.recyclerview.widget.RecyclerView
import com.lizongying.mytv.Utils.dpToPx
import com.lizongying.mytv.Utils.getDateTimestamp
import com.lizongying.mytv.databinding.RowBinding
import com.lizongying.mytv.databinding.ShowBinding
import com.lizongying.mytv.models.TVListViewModel
Expand All @@ -31,13 +32,13 @@ class MainFragment : Fragment(), CardAdapter.ItemListener {
private var _binding: ShowBinding? = null
private val binding get() = _binding!!

private var request: Request = Request()
private var request = Request()

var tvListViewModel = TVListViewModel()

private var sharedPref: SharedPreferences? = null

private var lastVideoUrl: String = ""
private var lastVideoUrl = ""

private val handler = Handler(Looper.getMainLooper())
private lateinit var mUpdateProgramRunnable: UpdateProgramRunnable
Expand Down Expand Up @@ -226,6 +227,8 @@ class MainFragment : Fragment(), CardAdapter.ItemListener {
this.itemPosition = itemPosition
tvListViewModel.setItemPosition(itemPosition)
tvListViewModel.getTVViewModel(itemPosition)?.changed()
} else {
Toast.makeText(context, "频道不存在", Toast.LENGTH_SHORT).show()
}
}
}
Expand Down Expand Up @@ -253,7 +256,7 @@ class MainFragment : Fragment(), CardAdapter.ItemListener {
}

fun updateProgram(tvViewModel: TVViewModel) {
val timestamp = Utils.getDateTimestamp()
val timestamp = getDateTimestamp()
if (timestamp - tvViewModel.programUpdateTime > 60) {
if (tvViewModel.program.value!!.isEmpty()) {
tvViewModel.programUpdateTime = timestamp
Expand Down

0 comments on commit cda1999

Please sign in to comment.