Skip to content

Commit 72e893b

Browse files
committed
show info
1 parent e6530b4 commit 72e893b

File tree

10 files changed

+103
-45
lines changed

10 files changed

+103
-45
lines changed

app/src/main/java/com/lizongying/mytv/InfoFragment.kt

Lines changed: 42 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,23 @@
11
package com.lizongying.mytv
22

33
import android.os.Bundle
4+
import android.os.Handler
5+
import android.util.Log
46
import android.view.LayoutInflater
57
import android.view.View
68
import android.view.ViewGroup
79
import androidx.fragment.app.Fragment
10+
import com.bumptech.glide.Glide
811
import com.lizongying.mytv.databinding.InfoBinding
12+
import com.lizongying.mytv.models.TVViewModel
913

1014
class InfoFragment : Fragment() {
1115
private var _binding: InfoBinding? = null
1216
private val binding get() = _binding!!
1317

18+
private val handler = Handler()
19+
private val delay: Long = 3000
20+
1421
override fun onCreateView(
1522
inflater: LayoutInflater, container: ViewGroup?,
1623
savedInstanceState: Bundle?
@@ -19,8 +26,41 @@ class InfoFragment : Fragment() {
1926
return binding.root
2027
}
2128

22-
fun setInfo(info: TV) {
23-
binding.textView.text = info.title
29+
override fun onResume() {
30+
super.onResume()
31+
32+
// Use a Handler to delay the fragment transaction
33+
handler.postDelayed(removeRunnable, delay)
34+
}
35+
36+
fun show() {
37+
Log.i("", "show")
38+
handler.removeCallbacks(removeRunnable)
39+
view?.visibility = View.VISIBLE
40+
handler.postDelayed(removeRunnable, delay)
41+
}
42+
43+
override fun onPause() {
44+
super.onPause()
45+
Log.i("", "onPause")
46+
// Cancel the delayed task when the fragment is paused
47+
handler.removeCallbacks(removeRunnable)
48+
}
49+
50+
private val removeRunnable = Runnable {
51+
Log.i("", "hide")
52+
view?.visibility = View.GONE
53+
}
54+
55+
fun setInfo(tvViewModel: TVViewModel) {
56+
binding.textView.text = tvViewModel.title.value
57+
Glide.with(this)
58+
.load(tvViewModel.logo.value)
59+
.into(binding.infoLogo)
60+
val program = tvViewModel.getProgramOne()
61+
if (program != null) {
62+
binding.infoDesc.text = program.name
63+
}
2464
}
2565

2666
override fun onDestroyView() {

app/src/main/java/com/lizongying/mytv/MainActivity.kt

Lines changed: 3 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -55,25 +55,9 @@ class MainActivity : FragmentActivity() {
5555
gestureDetector = GestureDetector(this, GestureListener())
5656
}
5757

58-
fun switchInfoFragment(tv: TV) {
59-
infoFragment.setInfo(tv)
60-
61-
if (infoFragment.isHidden) {
62-
supportFragmentManager.beginTransaction().show(infoFragment).commit()
63-
}
64-
}
65-
66-
fun showInfoFragment(tv: TV) {
67-
infoFragment.setInfo(tv)
68-
supportFragmentManager.beginTransaction()
69-
.show(infoFragment)
70-
.commit()
71-
}
72-
73-
fun hideInfoFragment() {
74-
supportFragmentManager.beginTransaction()
75-
.hide(infoFragment)
76-
.commit()
58+
fun showInfoFragment(tvViewModel: TVViewModel) {
59+
infoFragment.setInfo(tvViewModel)
60+
infoFragment.show()
7761
}
7862

7963
fun play(tvViewModel: TVViewModel) {

app/src/main/java/com/lizongying/mytv/MainFragment.kt

Lines changed: 2 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ import android.content.Context
44
import android.content.SharedPreferences
55
import android.os.Bundle
66
import android.util.Log
7-
import android.widget.Toast
87
import androidx.leanback.app.BrowseSupportFragment
98
import androidx.leanback.widget.ArrayObjectAdapter
109
import androidx.leanback.widget.HeaderItem
@@ -64,7 +63,6 @@ class MainFragment : BrowseSupportFragment() {
6463
) {
6564
Log.i(TAG, "ready ${tvViewModel.title.value}")
6665
(activity as? MainActivity)?.play(tvViewModel)
67-
// (activity as? MainActivity)?.switchInfoFragment(item)
6866
}
6967
}
7068
tvViewModel.change.observe(viewLifecycleOwner) { _ ->
@@ -76,29 +74,20 @@ class MainFragment : BrowseSupportFragment() {
7674
lifecycleScope.launch(Dispatchers.IO) {
7775
tvViewModel.let { request?.fetchData(it) }
7876
}
77+
(activity as? MainActivity)?.showInfoFragment(tvViewModel)
7978
setSelectedPosition(
8079
tvViewModel.getRowPosition(), true,
8180
SelectItemViewHolderTask(tvViewModel.getItemPosition())
8281
)
83-
Toast.makeText(
84-
activity,
85-
title,
86-
Toast.LENGTH_SHORT
87-
).show()
8882
} else {
8983
if (check(tvViewModel)) {
9084
(activity as? MainActivity)?.play(tvViewModel)
91-
// (activity as? MainActivity)?.switchInfoFragment(item)
85+
(activity as? MainActivity)?.showInfoFragment(tvViewModel)
9286

9387
setSelectedPosition(
9488
tvViewModel.getRowPosition(), true,
9589
SelectItemViewHolderTask(tvViewModel.getItemPosition())
9690
)
97-
Toast.makeText(
98-
activity,
99-
title,
100-
Toast.LENGTH_SHORT
101-
).show()
10291
}
10392
}
10493
}

app/src/main/java/com/lizongying/mytv/TVList.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,10 +69,10 @@ CGTN 纪录频道,https://livedoc.cgtn.com/500d/prog_index.m3u8,https://resource
6969
四川卫视,http://39.134.24.166/dbiptv.sn.chinamobile.com/PLTV/88888890/224/3221225768/index.m3u8;http://dbiptv.sn.chinamobile.com/PLTV/88888890/224/3221225768/index.m3u8,https://resources.yangshipin.cn/assets/oms/image/202306/3276a414ae0eaa0f116f2045cd913367967d0c7c1e978e8621ac3879436c6ed7.png?imageMogr2/format/webp,600002516,2000295003
7070
东南卫视,http://ottrrs.hl.chinamobile.com/PLTV/88888888/224/3221226341/index.m3u8;http://dbiptv.sn.chinamobile.com/PLTV/88888890/224/3221225766/index.m3u8,https://resources.yangshipin.cn/assets/oms/image/202306/3208fe6564a293c21b711333fb3edb05bb5b406cff840573c9a8d839680a1579.png?imageMogr2/format/webp,600002484,2000292503
7171
海南卫视,http://ottrrs.hl.chinamobile.com/PLTV/88888888/224/3221226465/index.m3u8;http://dbiptv.sn.chinamobile.com/PLTV/88888890/224/3221225769/index.m3u8,https://resources.yangshipin.cn/assets/oms/image/202306/6e060391fde0469801fc3d84dbf204b4f8d650d251f17d7595a6964c0bb99e81.png?imageMogr2/format/webp,600002506,2000291503
72-
三沙卫视,https://pullsstv90080111.ssws.tv/live/SSTV20220729.m3u8
7372
7473
移动专区
7574
75+
三沙卫视,https://pullsstv90080111.ssws.tv/live/SSTV20220729.m3u8
7676
7777
天津卫视,http://ottrrs.hl.chinamobile.com/PLTV/88888888/224/3221225740/index.m3u8;http://dbiptv.sn.chinamobile.com/PLTV/88888890/224/3221226204/index.m3u8
7878
吉林卫视,http://ottrrs.hl.chinamobile.com/PLTV/88888888/224/3221226397/index.m3u8;http://dbiptv.sn.chinamobile.com/PLTV/88888890/224/3221225792/index.m3u8

app/src/main/java/com/lizongying/mytv/models/TVViewModel.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -324,7 +324,7 @@ class TVViewModel(private var tv: TV) : ViewModel() {
324324
_title.value = tv.title
325325
_videoUrl.value = tv.videoUrl
326326
_videoIndex.value = tv.videoIndex
327-
Log.i(TAG, "tv.title ${tv.title} ${mappingLogo[tv.title]}")
327+
Log.d(TAG, "${tv.title} ${mappingLogo[tv.title]}")
328328
if (mappingLogo[tv.title] != null) {
329329
_logo.value = mappingLogo[tv.title]
330330
}
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
<shape xmlns:android="http://schemas.android.com/apk/res/android">
2+
<solid android:color="@color/white" />
3+
<corners android:radius="4dp" /> <!-- Adjust the radius as needed -->
4+
</shape>
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
<shape xmlns:android="http://schemas.android.com/apk/res/android">
2+
<solid android:color="#FF263238" />
3+
<corners android:radius="4dp" /> <!-- Adjust the radius as needed -->
4+
</shape>

app/src/main/res/layout/info.xml

Lines changed: 44 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,50 @@
55
android:layout_height="80dp"
66
android:layout_gravity="center_horizontal|bottom"
77
android:layout_marginBottom="20dp"
8-
android:background="@color/fastlane_background"
9-
>
8+
android:background="@drawable/rounded_background">
109

11-
<TextView
12-
android:id="@+id/textView"
13-
android:layout_width="wrap_content"
10+
<ImageView
11+
android:id="@+id/info_logo"
12+
android:layout_width="100dp"
1413
android:layout_height="wrap_content"
15-
android:layout_gravity="center_horizontal|top"
16-
android:layout_marginTop="10dp"
17-
android:textSize="40sp"
18-
/>
14+
android:layout_marginTop="8dp"
15+
android:contentDescription="@string/logo"
16+
android:padding="10dp" />
17+
18+
<LinearLayout
19+
android:layout_width="216dp"
20+
android:layout_height="match_parent"
21+
android:layout_marginStart="100dp"
22+
android:background="#FF263238"
23+
android:gravity="start|center_vertical"
24+
android:orientation="vertical"
25+
android:padding="7dp">
26+
27+
<TextView
28+
android:id="@+id/textView"
29+
android:layout_width="wrap_content"
30+
android:layout_height="wrap_content"
31+
android:layout_gravity="start"
32+
android:layout_marginTop="0dp"
33+
android:gravity="start"
34+
android:textColor="#FFEEEEEE"
35+
android:textSize="20sp" />
36+
37+
<TextView
38+
android:id="@+id/info_desc"
39+
android:layout_width="wrap_content"
40+
android:layout_height="wrap_content"
41+
android:layout_gravity="start"
42+
android:layout_marginTop="10dp"
43+
android:gravity="start"
44+
android:singleLine="true"
45+
android:textColor="#B3EEEEEE"
46+
android:textSize="16sp" />
47+
</LinearLayout>
48+
49+
<View
50+
android:layout_width="8dp"
51+
android:layout_height="wrap_content"
52+
android:layout_gravity="end"
53+
android:background="@drawable/rounded_background2" />
1954
</FrameLayout>

app/src/main/res/values/colors.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
<resources>
22
<color name="fastlane_background">#30000000</color>
33
<color name="black">#000</color>
4+
<color name="white">#FFF</color>
45
</resources>
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
<resources>
22
<string name="app_name">我的电视</string>
3+
<string name="logo">logo</string>
34
</resources>

0 commit comments

Comments
 (0)