@@ -3,6 +3,7 @@ package com.lizongying.mytv0
33import MainViewModel
44import android.os.Bundle
55import android.os.Handler
6+ import android.os.Looper
67import android.util.Log
78import android.view.LayoutInflater
89import android.view.View
@@ -18,7 +19,7 @@ class ChannelFragment : Fragment() {
1819 private var _binding : ChannelBinding ? = null
1920 private val binding get() = _binding !!
2021
21- private val handler = Handler ()
22+ private val handler = Handler (Looper .getMainLooper() )
2223 private val delay: Long = 5000
2324 private var channel = 0
2425 private var channelCount = 0
@@ -57,19 +58,23 @@ class ChannelFragment : Fragment() {
5758 viewModel = ViewModelProvider (context)[MainViewModel ::class .java]
5859 }
5960
60- fun show (tvViewModel : TVModel ) {
61+ fun show (tvModel : TVModel ) {
62+ val tv = tvModel.tv
63+ Log .i(TAG , " show $tv " )
6164 handler.removeCallbacks(hideRunnable)
6265 handler.removeCallbacks(playRunnable)
6366 if (_binding != null ) {
6467 binding.content.text =
65- if (tvViewModel. tv.number == - 1 ) (tvViewModel. tv.id.plus(1 )).toString() else tvViewModel. tv.number.toString()
68+ if (tv.number == - 1 ) (tv.id.plus(1 )).toString() else tv.number.toString()
6669 }
6770 view?.visibility = View .VISIBLE
71+ channel = 0
72+ channelCount = 0
6873 handler.postDelayed(hideRunnable, delay)
6974 }
7075
71- fun show (channel : String ) {
72- Log .d (TAG , " input $channel " )
76+ fun show (channel : Int ) {
77+ Log .i (TAG , " input $channel ${ this .channel} " )
7378 val tv = viewModel.groupModel.getCurrent()!! .tv
7479 if (tv.id > 10 && tv.id == this .channel - 1 ) {
7580 this .channel = 0
@@ -83,15 +88,19 @@ class ChannelFragment : Fragment() {
8388 handler.removeCallbacks(hideRunnable)
8489 handler.removeCallbacks(playRunnable)
8590 Log .d(TAG , " channelCount $channelCount " )
86- binding.content.text = this .channel.toString()
91+ binding.content.text = " ${ this .channel} "
8792 view?.visibility = View .VISIBLE
8893 if (channelCount < 3 ) {
8994 handler.postDelayed(playRunnable, delay)
9095 } else {
91- handler.postDelayed(playRunnable, 0 )
96+ playNow( )
9297 }
9398 }
9499
100+ fun playNow () {
101+ handler.postDelayed(playRunnable, 0 )
102+ }
103+
95104 override fun onResume () {
96105 super .onResume()
97106 if (view?.visibility == View .VISIBLE ) {
@@ -111,11 +120,11 @@ class ChannelFragment : Fragment() {
111120 }
112121
113122 view?.visibility = View .GONE
114- channel = 0
115- channelCount = 0
116123 }
117124
118125 fun hideSelf () {
126+ channel = 0
127+ channelCount = 0
119128 handler.postDelayed(hideRunnable, 0 )
120129 }
121130
@@ -124,8 +133,13 @@ class ChannelFragment : Fragment() {
124133 viewModel.listModel.find { it.tv.number == channel }?.let {
125134 c = it.tv.id
126135 }
127- (activity as MainActivity ).play(c)
128- handler.postDelayed(hideRunnable, delay)
136+ if ((activity as MainActivity ).play(c)) {
137+ channel = 0
138+ channelCount = 0
139+ handler.postDelayed(hideRunnable, delay)
140+ } else {
141+ hideSelf()
142+ }
129143 }
130144
131145 override fun onDestroyView () {
0 commit comments