Skip to content

Commit 641f8a9

Browse files
committed
add time
1 parent 74b6287 commit 641f8a9

27 files changed

+680
-179
lines changed

HISTORY.md

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,27 @@
11
## 更新日志
22

3+
### v1.7.8(通用)
4+
5+
* 修复播放过程中的卡顿问题
6+
* 增加时间显示
7+
* 频道号优化
8+
* 遥控器左键打开频道列表
9+
* 遥控器右键打开设置菜单
10+
* 频道列表空白处点击隐藏频道列表
11+
312
### v1.7.6(通用)
413

514
* 临时去掉部分频道,提高频道的可用性
615
* 部分频道增加节目单
716

17+
### v1.7.5(安卓5及以上专用)
18+
19+
* 修复播放过程中的卡顿问题
20+
* 增加时间显示
21+
* 频道号优化
22+
* 设置中增加退出按钮
23+
*
24+
825
### v1.7.4(通用)
926

1027
* 修复368

README.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,10 @@ adb install my-tv.apk
3838
* 显示时间
3939
* 软解
4040
* 不同分辨率
41+
* “比如:我输了3跳转到3号频道后数字没有消失时,这时我发现按错了频道,然后我想马上换到6频道输到6就变成36了”
42+
43+
無法自啟的設備:
44+
斐讯N1盒子,[Phicomm] Phicomm p230 (Android 7.1.2)
4145

4246
## 赞赏
4347

app/build.gradle

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ android {
1313

1414
defaultConfig {
1515
applicationId "com.lizongying.mytv"
16-
minSdk 17
16+
minSdk 21
1717
targetSdk 33
1818
versionCode VersionCode()
1919
versionName VersionName()
@@ -95,7 +95,7 @@ static def VersionName() {
9595
}
9696

9797
dependencies {
98-
def media3_version = "1.2.1"
98+
def media3_version = "1.3.1"
9999

100100
implementation "androidx.media3:media3-ui:$media3_version"
101101

@@ -105,18 +105,22 @@ dependencies {
105105
// For HLS playback support with ExoPlayer
106106
implementation "androidx.media3:media3-exoplayer-hls:$media3_version"
107107

108-
// 21:2.9.0 17:2.6.4
109-
def retrofit2_version = "2.9.0"
108+
// 21:2.11.0 17:2.6.4
109+
def retrofit2_version = "2.11.0"
110110

111111
implementation 'com.google.protobuf:protobuf-kotlin:3.25.1'
112112
implementation "com.squareup.retrofit2:converter-gson:$retrofit2_version"
113113
implementation "com.squareup.retrofit2:converter-protobuf:$retrofit2_version"
114114
implementation "com.squareup.retrofit2:retrofit:$retrofit2_version"
115-
implementation "org.jetbrains.kotlinx:kotlinx-serialization-json:1.6.2"
116-
implementation 'androidx.core:core-ktx:1.11.0-beta02'
117-
implementation 'androidx.leanback:leanback:1.2.0-alpha02'
115+
116+
implementation 'androidx.leanback:leanback:1.2.0-alpha04'
117+
118118
implementation 'com.github.bumptech.glide:glide:4.11.0'
119-
implementation "androidx.lifecycle:lifecycle-runtime-ktx:2.6.2"
119+
120+
implementation 'androidx.core:core-ktx:1.13.0'
121+
implementation "androidx.lifecycle:lifecycle-runtime-ktx:2.7.0"
122+
123+
implementation "org.jetbrains.kotlinx:kotlinx-serialization-json:1.6.2"
120124
implementation("org.jetbrains.kotlinx:kotlinx-coroutines-android:1.8.0-RC")
121125

122126
implementation 'com.google.android.exoplayer:exoplayer-ui:2.13.3'

app/src/main/AndroidManifest.xml

Lines changed: 18 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,37 +1,43 @@
11
<?xml version="1.0" encoding="utf-8"?>
22
<manifest xmlns:android="http://schemas.android.com/apk/res/android">
3+
34
<uses-feature
45
android:name="android.hardware.touchscreen"
56
android:required="false" />
67
<uses-feature
78
android:name="android.software.leanback"
89
android:required="true" />
10+
911
<uses-permission android:name="android.permission.INTERNET" />
1012
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
11-
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
13+
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
1214
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
15+
1316
<application
17+
android:name=".MyApplication"
1418
android:allowBackup="true"
15-
android:largeHeap="true"
16-
android:icon="@drawable/logo"
17-
android:logo="@drawable/logo"
1819
android:banner="@drawable/banner"
20+
android:icon="@drawable/logo"
1921
android:label="@string/app_name"
20-
android:supportsRtl="true"
22+
android:largeHeap="true"
23+
android:logo="@drawable/logo"
2124
android:networkSecurityConfig="@xml/network"
22-
android:usesCleartextTraffic="true"
23-
android:theme="@style/Theme.MyTV">
25+
android:supportsRtl="true"
26+
android:theme="@style/Theme.MyTV"
27+
android:usesCleartextTraffic="true">
2428
<activity
25-
android:keepScreenOn="true"
2629
android:name=".MainActivity"
2730
android:exported="true"
31+
android:keepScreenOn="true"
2832
android:screenOrientation="landscape">
2933
<intent-filter>
3034
<action android:name="android.intent.action.MAIN" />
35+
3136
<category android:name="android.intent.category.LEANBACK_LAUNCHER" />
3237
<category android:name="android.intent.category.LAUNCHER" />
3338
</intent-filter>
3439
</activity>
40+
3541
<receiver
3642
android:name=".BootReceiver"
3743
android:exported="true">
@@ -40,15 +46,17 @@
4046
<category android:name="android.intent.category.DEFAULT" />
4147
</intent-filter>
4248
</receiver>
43-
<receiver android:name=".NetworkChangeReceiver"
49+
<receiver
50+
android:name=".NetworkChangeReceiver"
4451
android:exported="true">
4552
<intent-filter>
4653
<action android:name="android.net.conn.CONNECTIVITY_CHANGE" />
4754
</intent-filter>
4855
</receiver>
56+
4957
<provider
5058
android:name=".InitializerProvider"
5159
android:authorities="${applicationId}.InitializerProvider"
52-
android:exported="false"/>
60+
android:exported="false" />
5361
</application>
5462
</manifest>
0 Bytes
Binary file not shown.

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

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,18 +23,20 @@ class CardPresenter(
2323
return ViewHolder(cardView)
2424
}
2525

26-
override fun onBindViewHolder(viewHolder: ViewHolder, item: Any) {
26+
override fun onBindViewHolder(viewHolder: ViewHolder, item: Any?) {
2727
val tvViewModel = item as TVViewModel
2828
val cardView = viewHolder.view as ImageCardView
2929

3030
cardView.titleText = tvViewModel.getTV().title
3131
cardView.setMainImageDimensions(CARD_WIDTH, CARD_HEIGHT)
3232
cardView.tag = tvViewModel.videoUrl.value
3333

34-
Glide.with(viewHolder.view.context)
35-
.load(tvViewModel.getTV().logo)
36-
.centerInside()
37-
.into(cardView.mainImageView)
34+
cardView.mainImageView?.let {
35+
Glide.with(viewHolder.view.context)
36+
.load(tvViewModel.getTV().logo)
37+
.centerInside()
38+
.into(it)
39+
}
3840

3941
cardView.setBackgroundColor(Color.WHITE)
4042
cardView.setMainImageScaleType(ImageView.ScaleType.CENTER_INSIDE)

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

Lines changed: 50 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package com.lizongying.mytv
22

33
import android.os.Bundle
44
import android.os.Handler
5+
import android.util.Log
56
import android.view.LayoutInflater
67
import android.view.View
78
import android.view.ViewGroup
@@ -16,14 +17,47 @@ class ChannelFragment : Fragment() {
1617
private val handler = Handler()
1718
private val delay: Long = 3000
1819
private var channel = 0
20+
private var channelCount = 0
1921

2022
override fun onCreateView(
2123
inflater: LayoutInflater, container: ViewGroup?,
2224
savedInstanceState: Bundle?
2325
): View {
2426
_binding = ChannelBinding.inflate(inflater, container, false)
2527
_binding!!.root.visibility = View.GONE
26-
(activity as MainActivity).fragmentReady()
28+
29+
val activity = requireActivity()
30+
val application = activity.applicationContext as MyApplication
31+
val displayMetrics = application.getDisplayMetrics()
32+
33+
displayMetrics.density
34+
35+
var screenWidth = displayMetrics.widthPixels
36+
var screenHeight = displayMetrics.heightPixels
37+
if (screenHeight > screenWidth) {
38+
screenWidth = displayMetrics.heightPixels
39+
screenHeight = displayMetrics.widthPixels
40+
}
41+
42+
val ratio = 16f / 9f
43+
44+
if (screenWidth / screenHeight > ratio) {
45+
val x = ((screenWidth - screenHeight * ratio) / 2).toInt()
46+
val originalLayoutParams =
47+
binding.channelFragment.layoutParams as ViewGroup.MarginLayoutParams
48+
originalLayoutParams.rightMargin += x
49+
binding.channelFragment.layoutParams = originalLayoutParams
50+
}
51+
52+
if (screenWidth / screenHeight < ratio) {
53+
val y = ((screenHeight - screenWidth / ratio) / 2).toInt()
54+
val originalLayoutParams =
55+
binding.channelFragment.layoutParams as ViewGroup.MarginLayoutParams
56+
originalLayoutParams.topMargin += y
57+
binding.channelFragment.layoutParams = originalLayoutParams
58+
}
59+
60+
(activity as MainActivity).fragmentReady("ChannelFragment")
2761
return binding.root
2862
}
2963

@@ -36,11 +70,17 @@ class ChannelFragment : Fragment() {
3670
}
3771

3872
fun show(channel: String) {
39-
this.channel = "${binding.channelContent.text}$channel".toInt()
73+
if (channelCount > 1) {
74+
return
75+
}
76+
channelCount++
77+
Log.i(TAG, "channelCount ${channelCount}")
78+
this.channel = "${this.channel}$channel".toInt()
79+
Log.i(TAG, "this.channel ${this.channel}")
4080
handler.removeCallbacks(hideRunnable)
4181
handler.removeCallbacks(playRunnable)
42-
if (binding.channelContent.text == "") {
43-
binding.channelContent.text = channel
82+
if (channelCount < 2) {
83+
binding.channelContent.text = "${this.channel}"
4484
view?.visibility = View.VISIBLE
4585
handler.postDelayed(playRunnable, delay)
4686
} else {
@@ -64,12 +104,18 @@ class ChannelFragment : Fragment() {
64104
private val hideRunnable = Runnable {
65105
binding.channelContent.text = ""
66106
view?.visibility = View.GONE
107+
channel = 0
108+
channelCount = 0
109+
Log.i(TAG, "hideRunnable")
67110
}
68111

69112
private val playRunnable = Runnable {
70113
(activity as MainActivity).play(channel - 1)
71114
binding.channelContent.text = ""
72115
view?.visibility = View.GONE
116+
channel = 0
117+
channelCount = 0
118+
Log.i(TAG, "playRunnable")
73119
}
74120

75121
override fun onDestroyView() {

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ class InfoFragment : Fragment() {
2424
): View {
2525
_binding = InfoBinding.inflate(inflater, container, false)
2626
_binding!!.root.visibility = View.GONE
27-
(activity as MainActivity).fragmentReady()
27+
(activity as MainActivity).fragmentReady("InfoFragment")
2828
return binding.root
2929
}
3030

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

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ class MainActivity : FragmentActivity(), Request.RequestListener {
3131
private val mainFragment = MainFragment()
3232
private val infoFragment = InfoFragment()
3333
private val channelFragment = ChannelFragment()
34+
private var timeFragment = TimeFragment()
3435
private val settingFragment = SettingFragment()
3536
private val errorFragment = ErrorFragment()
3637

@@ -67,6 +68,7 @@ class MainActivity : FragmentActivity(), Request.RequestListener {
6768
if (savedInstanceState == null) {
6869
supportFragmentManager.beginTransaction()
6970
.add(R.id.main_browse_fragment, playerFragment)
71+
.add(R.id.main_browse_fragment, timeFragment)
7072
.add(R.id.main_browse_fragment, infoFragment)
7173
.add(R.id.main_browse_fragment, channelFragment)
7274
.add(R.id.main_browse_fragment, mainFragment)
@@ -169,6 +171,7 @@ class MainActivity : FragmentActivity(), Request.RequestListener {
169171
fun settingDelayHide() {
170172
handler.removeCallbacks(hideSetting)
171173
handler.postDelayed(hideSetting, delayHideSetting)
174+
showTime()
172175
}
173176

174177
fun settingHideNow() {
@@ -198,11 +201,21 @@ class MainActivity : FragmentActivity(), Request.RequestListener {
198201
}
199202
}
200203

201-
fun fragmentReady() {
204+
fun fragmentReady(tag: String) {
202205
ready++
203-
Log.i(TAG, "ready $ready")
204-
if (ready == 5) {
206+
Log.i(TAG, "ready $tag $ready ")
207+
if (ready == 6) {
205208
mainFragment.fragmentReady()
209+
showTime()
210+
}
211+
}
212+
213+
private fun showTime() {
214+
Log.i(TAG, "showTime ${SP.time}")
215+
if (SP.time) {
216+
timeFragment.show()
217+
} else {
218+
timeFragment.hide()
206219
}
207220
}
208221

@@ -502,7 +515,7 @@ class MainActivity : FragmentActivity(), Request.RequestListener {
502515
.commitNow()
503516
errorFragment.setErrorContent(message)
504517
}
505-
fragmentReady()
518+
fragmentReady("Request")
506519
}
507520

508521
private companion object {

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ class MainFragment : BrowseSupportFragment() {
125125
}
126126
}
127127

128-
(activity as MainActivity).fragmentReady()
128+
(activity as MainActivity).fragmentReady("MainFragment")
129129
}
130130

131131
fun toLastPosition() {

0 commit comments

Comments
 (0)