Skip to content

Commit

Permalink
add time
Browse files Browse the repository at this point in the history
  • Loading branch information
lizongying committed Apr 19, 2024
1 parent 74b6287 commit 641f8a9
Show file tree
Hide file tree
Showing 27 changed files with 680 additions and 179 deletions.
17 changes: 17 additions & 0 deletions HISTORY.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,27 @@
## 更新日志

### v1.7.8(通用)

* 修复播放过程中的卡顿问题
* 增加时间显示
* 频道号优化
* 遥控器左键打开频道列表
* 遥控器右键打开设置菜单
* 频道列表空白处点击隐藏频道列表

### v1.7.6(通用)

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

### v1.7.5(安卓5及以上专用)

* 修复播放过程中的卡顿问题
* 增加时间显示
* 频道号优化
* 设置中增加退出按钮
*

### v1.7.4(通用)

* 修复368
Expand Down
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,10 @@ adb install my-tv.apk
* 显示时间
* 软解
* 不同分辨率
* “比如:我输了3跳转到3号频道后数字没有消失时,这时我发现按错了频道,然后我想马上换到6频道输到6就变成36了”

無法自啟的設備:
斐讯N1盒子,[Phicomm] Phicomm p230 (Android 7.1.2)

## 赞赏

Expand Down
20 changes: 12 additions & 8 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ android {

defaultConfig {
applicationId "com.lizongying.mytv"
minSdk 17
minSdk 21
targetSdk 33
versionCode VersionCode()
versionName VersionName()
Expand Down Expand Up @@ -95,7 +95,7 @@ static def VersionName() {
}

dependencies {
def media3_version = "1.2.1"
def media3_version = "1.3.1"

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

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

// 21:2.9.0 17:2.6.4
def retrofit2_version = "2.9.0"
// 21:2.11.0 17:2.6.4
def retrofit2_version = "2.11.0"

implementation 'com.google.protobuf:protobuf-kotlin:3.25.1'
implementation "com.squareup.retrofit2:converter-gson:$retrofit2_version"
implementation "com.squareup.retrofit2:converter-protobuf:$retrofit2_version"
implementation "com.squareup.retrofit2:retrofit:$retrofit2_version"
implementation "org.jetbrains.kotlinx:kotlinx-serialization-json:1.6.2"
implementation 'androidx.core:core-ktx:1.11.0-beta02'
implementation 'androidx.leanback:leanback:1.2.0-alpha02'

implementation 'androidx.leanback:leanback:1.2.0-alpha04'

implementation 'com.github.bumptech.glide:glide:4.11.0'
implementation "androidx.lifecycle:lifecycle-runtime-ktx:2.6.2"

implementation 'androidx.core:core-ktx:1.13.0'
implementation "androidx.lifecycle:lifecycle-runtime-ktx:2.7.0"

implementation "org.jetbrains.kotlinx:kotlinx-serialization-json:1.6.2"
implementation("org.jetbrains.kotlinx:kotlinx-coroutines-android:1.8.0-RC")

implementation 'com.google.android.exoplayer:exoplayer-ui:2.13.3'
Expand Down
28 changes: 18 additions & 10 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -1,37 +1,43 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android">

<uses-feature
android:name="android.hardware.touchscreen"
android:required="false" />
<uses-feature
android:name="android.software.leanback"
android:required="true" />

<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />

<application
android:name=".MyApplication"
android:allowBackup="true"
android:largeHeap="true"
android:icon="@drawable/logo"
android:logo="@drawable/logo"
android:banner="@drawable/banner"
android:icon="@drawable/logo"
android:label="@string/app_name"
android:supportsRtl="true"
android:largeHeap="true"
android:logo="@drawable/logo"
android:networkSecurityConfig="@xml/network"
android:usesCleartextTraffic="true"
android:theme="@style/Theme.MyTV">
android:supportsRtl="true"
android:theme="@style/Theme.MyTV"
android:usesCleartextTraffic="true">
<activity
android:keepScreenOn="true"
android:name=".MainActivity"
android:exported="true"
android:keepScreenOn="true"
android:screenOrientation="landscape">
<intent-filter>
<action android:name="android.intent.action.MAIN" />

<category android:name="android.intent.category.LEANBACK_LAUNCHER" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>

<receiver
android:name=".BootReceiver"
android:exported="true">
Expand All @@ -40,15 +46,17 @@
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</receiver>
<receiver android:name=".NetworkChangeReceiver"
<receiver
android:name=".NetworkChangeReceiver"
android:exported="true">
<intent-filter>
<action android:name="android.net.conn.CONNECTIVITY_CHANGE" />
</intent-filter>
</receiver>

<provider
android:name=".InitializerProvider"
android:authorities="${applicationId}.InitializerProvider"
android:exported="false"/>
android:exported="false" />
</application>
</manifest>
Binary file modified app/src/main/cpp/arm64-v8a/libnative.so
Binary file not shown.
12 changes: 7 additions & 5 deletions app/src/main/java/com/lizongying/mytv/CardPresenter.kt
Original file line number Diff line number Diff line change
Expand Up @@ -23,18 +23,20 @@ class CardPresenter(
return ViewHolder(cardView)
}

override fun onBindViewHolder(viewHolder: ViewHolder, item: Any) {
override fun onBindViewHolder(viewHolder: ViewHolder, item: Any?) {
val tvViewModel = item as TVViewModel
val cardView = viewHolder.view as ImageCardView

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

Glide.with(viewHolder.view.context)
.load(tvViewModel.getTV().logo)
.centerInside()
.into(cardView.mainImageView)
cardView.mainImageView?.let {
Glide.with(viewHolder.view.context)
.load(tvViewModel.getTV().logo)
.centerInside()
.into(it)
}

cardView.setBackgroundColor(Color.WHITE)
cardView.setMainImageScaleType(ImageView.ScaleType.CENTER_INSIDE)
Expand Down
54 changes: 50 additions & 4 deletions app/src/main/java/com/lizongying/mytv/ChannelFragment.kt
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ 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,14 +17,47 @@ class ChannelFragment : Fragment() {
private val handler = Handler()
private val delay: Long = 3000
private var channel = 0
private var channelCount = 0

override fun onCreateView(
inflater: LayoutInflater, container: ViewGroup?,
savedInstanceState: Bundle?
): View {
_binding = ChannelBinding.inflate(inflater, container, false)
_binding!!.root.visibility = View.GONE
(activity as MainActivity).fragmentReady()

val activity = requireActivity()
val application = activity.applicationContext as MyApplication
val displayMetrics = application.getDisplayMetrics()

displayMetrics.density

var screenWidth = displayMetrics.widthPixels
var screenHeight = displayMetrics.heightPixels
if (screenHeight > screenWidth) {
screenWidth = displayMetrics.heightPixels
screenHeight = displayMetrics.widthPixels
}

val ratio = 16f / 9f

if (screenWidth / screenHeight > ratio) {
val x = ((screenWidth - screenHeight * ratio) / 2).toInt()
val originalLayoutParams =
binding.channelFragment.layoutParams as ViewGroup.MarginLayoutParams
originalLayoutParams.rightMargin += x
binding.channelFragment.layoutParams = originalLayoutParams
}

if (screenWidth / screenHeight < ratio) {
val y = ((screenHeight - screenWidth / ratio) / 2).toInt()
val originalLayoutParams =
binding.channelFragment.layoutParams as ViewGroup.MarginLayoutParams
originalLayoutParams.topMargin += y
binding.channelFragment.layoutParams = originalLayoutParams
}

(activity as MainActivity).fragmentReady("ChannelFragment")
return binding.root
}

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

fun show(channel: String) {
this.channel = "${binding.channelContent.text}$channel".toInt()
if (channelCount > 1) {
return
}
channelCount++
Log.i(TAG, "channelCount ${channelCount}")
this.channel = "${this.channel}$channel".toInt()
Log.i(TAG, "this.channel ${this.channel}")
handler.removeCallbacks(hideRunnable)
handler.removeCallbacks(playRunnable)
if (binding.channelContent.text == "") {
binding.channelContent.text = channel
if (channelCount < 2) {
binding.channelContent.text = "${this.channel}"
view?.visibility = View.VISIBLE
handler.postDelayed(playRunnable, delay)
} else {
Expand All @@ -64,12 +104,18 @@ class ChannelFragment : Fragment() {
private val hideRunnable = Runnable {
binding.channelContent.text = ""
view?.visibility = View.GONE
channel = 0
channelCount = 0
Log.i(TAG, "hideRunnable")
}

private val playRunnable = Runnable {
(activity as MainActivity).play(channel - 1)
binding.channelContent.text = ""
view?.visibility = View.GONE
channel = 0
channelCount = 0
Log.i(TAG, "playRunnable")
}

override fun onDestroyView() {
Expand Down
2 changes: 1 addition & 1 deletion app/src/main/java/com/lizongying/mytv/InfoFragment.kt
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ class InfoFragment : Fragment() {
): View {
_binding = InfoBinding.inflate(inflater, container, false)
_binding!!.root.visibility = View.GONE
(activity as MainActivity).fragmentReady()
(activity as MainActivity).fragmentReady("InfoFragment")
return binding.root
}

Expand Down
21 changes: 17 additions & 4 deletions app/src/main/java/com/lizongying/mytv/MainActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ class MainActivity : FragmentActivity(), Request.RequestListener {
private val mainFragment = MainFragment()
private val infoFragment = InfoFragment()
private val channelFragment = ChannelFragment()
private var timeFragment = TimeFragment()
private val settingFragment = SettingFragment()
private val errorFragment = ErrorFragment()

Expand Down Expand Up @@ -67,6 +68,7 @@ class MainActivity : FragmentActivity(), Request.RequestListener {
if (savedInstanceState == null) {
supportFragmentManager.beginTransaction()
.add(R.id.main_browse_fragment, playerFragment)
.add(R.id.main_browse_fragment, timeFragment)
.add(R.id.main_browse_fragment, infoFragment)
.add(R.id.main_browse_fragment, channelFragment)
.add(R.id.main_browse_fragment, mainFragment)
Expand Down Expand Up @@ -169,6 +171,7 @@ class MainActivity : FragmentActivity(), Request.RequestListener {
fun settingDelayHide() {
handler.removeCallbacks(hideSetting)
handler.postDelayed(hideSetting, delayHideSetting)
showTime()
}

fun settingHideNow() {
Expand Down Expand Up @@ -198,11 +201,21 @@ class MainActivity : FragmentActivity(), Request.RequestListener {
}
}

fun fragmentReady() {
fun fragmentReady(tag: String) {
ready++
Log.i(TAG, "ready $ready")
if (ready == 5) {
Log.i(TAG, "ready $tag $ready ")
if (ready == 6) {
mainFragment.fragmentReady()
showTime()
}
}

private fun showTime() {
Log.i(TAG, "showTime ${SP.time}")
if (SP.time) {
timeFragment.show()
} else {
timeFragment.hide()
}
}

Expand Down Expand Up @@ -502,7 +515,7 @@ class MainActivity : FragmentActivity(), Request.RequestListener {
.commitNow()
errorFragment.setErrorContent(message)
}
fragmentReady()
fragmentReady("Request")
}

private companion object {
Expand Down
2 changes: 1 addition & 1 deletion app/src/main/java/com/lizongying/mytv/MainFragment.kt
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ class MainFragment : BrowseSupportFragment() {
}
}

(activity as MainActivity).fragmentReady()
(activity as MainActivity).fragmentReady("MainFragment")
}

fun toLastPosition() {
Expand Down
23 changes: 23 additions & 0 deletions app/src/main/java/com/lizongying/mytv/MyApplication.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package com.lizongying.mytv

import android.app.Application
import android.content.Context
import android.util.DisplayMetrics
import android.view.WindowManager

class MyApplication : Application() {
private lateinit var displayMetrics: DisplayMetrics

override fun onCreate() {
super.onCreate()

displayMetrics = DisplayMetrics()
val windowManager = getSystemService(Context.WINDOW_SERVICE) as WindowManager
// windowManager.defaultDisplay.getRealMetrics(displayMetrics)
windowManager.defaultDisplay.getMetrics(displayMetrics)
}

fun getDisplayMetrics(): DisplayMetrics {
return displayMetrics
}
}
2 changes: 1 addition & 1 deletion app/src/main/java/com/lizongying/mytv/PlayerFragment.kt
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ class PlayerFragment : Fragment(), SurfaceHolder.Callback {
})
}
})
(activity as MainActivity).fragmentReady()
(activity as MainActivity).fragmentReady("PlayerFragment")
return _binding!!.root
}

Expand Down
Loading

0 comments on commit 641f8a9

Please sign in to comment.