mirror of
https://github.com/lizongying/my-tv.git
synced 2026-10-26 14:16:29 +08:00
show info
This commit is contained in:
@@ -1,16 +1,23 @@
|
||||
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
|
||||
import androidx.fragment.app.Fragment
|
||||
import com.bumptech.glide.Glide
|
||||
import com.lizongying.mytv.databinding.InfoBinding
|
||||
import com.lizongying.mytv.models.TVViewModel
|
||||
|
||||
class InfoFragment : Fragment() {
|
||||
private var _binding: InfoBinding? = null
|
||||
private val binding get() = _binding!!
|
||||
|
||||
private val handler = Handler()
|
||||
private val delay: Long = 3000
|
||||
|
||||
override fun onCreateView(
|
||||
inflater: LayoutInflater, container: ViewGroup?,
|
||||
savedInstanceState: Bundle?
|
||||
@@ -19,8 +26,41 @@ class InfoFragment : Fragment() {
|
||||
return binding.root
|
||||
}
|
||||
|
||||
fun setInfo(info: TV) {
|
||||
binding.textView.text = info.title
|
||||
override fun onResume() {
|
||||
super.onResume()
|
||||
|
||||
// Use a Handler to delay the fragment transaction
|
||||
handler.postDelayed(removeRunnable, delay)
|
||||
}
|
||||
|
||||
fun show() {
|
||||
Log.i("", "show")
|
||||
handler.removeCallbacks(removeRunnable)
|
||||
view?.visibility = View.VISIBLE
|
||||
handler.postDelayed(removeRunnable, delay)
|
||||
}
|
||||
|
||||
override fun onPause() {
|
||||
super.onPause()
|
||||
Log.i("", "onPause")
|
||||
// Cancel the delayed task when the fragment is paused
|
||||
handler.removeCallbacks(removeRunnable)
|
||||
}
|
||||
|
||||
private val removeRunnable = Runnable {
|
||||
Log.i("", "hide")
|
||||
view?.visibility = View.GONE
|
||||
}
|
||||
|
||||
fun setInfo(tvViewModel: TVViewModel) {
|
||||
binding.textView.text = tvViewModel.title.value
|
||||
Glide.with(this)
|
||||
.load(tvViewModel.logo.value)
|
||||
.into(binding.infoLogo)
|
||||
val program = tvViewModel.getProgramOne()
|
||||
if (program != null) {
|
||||
binding.infoDesc.text = program.name
|
||||
}
|
||||
}
|
||||
|
||||
override fun onDestroyView() {
|
||||
|
||||
Reference in New Issue
Block a user