Skip to content

Commit

Permalink
fix time
Browse files Browse the repository at this point in the history
  • Loading branch information
lizongying committed May 7, 2024
1 parent 2b172ae commit b157f1e
Show file tree
Hide file tree
Showing 10 changed files with 107 additions and 39 deletions.
10 changes: 10 additions & 0 deletions HISTORY.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,15 @@
## 更新日志

### v1.9.4(通用)

* 修复默认时间不显示问题
* 设置页居中
* 频道号和时间对齐

### v1.9.2(通用)

* 修复一个重试的错误

### v1.9.0(通用)

* 减少视频播放失败情况
Expand Down
1 change: 1 addition & 0 deletions app/src/main/java/com/lizongying/mytv/ChannelFragment.kt
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ class ChannelFragment : Fragment() {
binding.channel.layoutParams = layoutParams

binding.content.textSize = application.px2PxFont(binding.content.textSize)
binding.time.textSize = application.px2PxFont(binding.time.textSize)

binding.main.layoutParams.width = application.shouldWidthPx()
binding.main.layoutParams.height = application.shouldHeightPx()
Expand Down
59 changes: 39 additions & 20 deletions app/src/main/java/com/lizongying/mytv/MainActivity.kt
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
package com.lizongying.mytv

import android.content.Context
import android.net.ConnectivityManager
import android.net.Network
import android.os.Build
import android.os.Bundle
import android.os.Handler
Expand Down Expand Up @@ -34,7 +31,7 @@ class MainActivity : FragmentActivity(), Request.RequestListener {
private val playerFragment = PlayerFragment()
private val errorFragment = ErrorFragment()

// private val loadingFragment = LoadingFragment()
private val loadingFragment = LoadingFragment()
private val mainFragment = MainFragment()
private val infoFragment = InfoFragment()
private val channelFragment = ChannelFragment()
Expand Down Expand Up @@ -86,7 +83,7 @@ class MainActivity : FragmentActivity(), Request.RequestListener {
// }

if (savedInstanceState == null) {
supportFragmentManager.beginTransaction()
val transaction = supportFragmentManager.beginTransaction()
.add(R.id.main_browse_fragment, playerFragment)
.add(R.id.main_browse_fragment, errorFragment)
// .add(R.id.main_browse_fragment, loadingFragment)
Expand All @@ -96,9 +93,14 @@ class MainActivity : FragmentActivity(), Request.RequestListener {
.add(R.id.main_browse_fragment, mainFragment)
.hide(mainFragment)
.hide(errorFragment)
// .hide(loadingFragment)
.hide(timeFragment)
.commit()

if (!SP.time) {
transaction.hide(timeFragment)
} else {
transaction.show(timeFragment)
}

transaction.commitNow()
}
gestureDetector = GestureDetector(this, GestureListener())

Expand All @@ -120,9 +122,6 @@ class MainActivity : FragmentActivity(), Request.RequestListener {
// Log.i(TAG, "net ${Build.VERSION.SDK_INT}")
// ready++
// }

showTime()
mainFragment.changeMenu()
}

fun showInfoFragment(tvViewModel: TVViewModel) {
Expand Down Expand Up @@ -152,6 +151,14 @@ class MainActivity : FragmentActivity(), Request.RequestListener {
.commit()
}

fun showLoadingFragment() {
showFragment(loadingFragment)
}

fun hideLoadingFragment() {
hideFragment(loadingFragment)
}

fun showPlayerFragment() {
if (playerFragment.isVisible) {
return
Expand Down Expand Up @@ -222,8 +229,6 @@ class MainActivity : FragmentActivity(), Request.RequestListener {
fun settingDelayHide() {
handler.removeCallbacks(hideSetting)
handler.postDelayed(hideSetting, delayHideSetting)
showTime()
mainFragment.changeMenu()
}

fun settingNeverHide() {
Expand Down Expand Up @@ -342,14 +347,12 @@ class MainActivity : FragmentActivity(), Request.RequestListener {
return
}

Log.i(TAG, "settingFragment ${settingFragment.isVisible}")
if (!settingFragment.isVisible) {
settingFragment.show(supportFragmentManager, "setting")
settingDelayHide()
} else {
handler.removeCallbacks(hideSetting)
settingFragment.dismiss()
if (settingFragment.isVisible) {
return
}

settingFragment.show(supportFragmentManager, TAG)
settingDelayHide()
}

private val hideSetting = Runnable {
Expand Down Expand Up @@ -421,6 +424,11 @@ class MainActivity : FragmentActivity(), Request.RequestListener {
}, 2000)
}

private fun active() {
if (settingFragment.isVisible) {
settingDelayHide()
}
}

fun onKey(keyCode: Int): Boolean {
Log.i(TAG, "keyCode $keyCode")
Expand Down Expand Up @@ -511,6 +519,7 @@ class MainActivity : FragmentActivity(), Request.RequestListener {
}

KeyEvent.KEYCODE_ENTER -> {
active()
switchMainFragment()
}

Expand All @@ -519,6 +528,7 @@ class MainActivity : FragmentActivity(), Request.RequestListener {
}

KeyEvent.KEYCODE_DPAD_UP -> {
active()
channelUp()
}

Expand All @@ -527,6 +537,7 @@ class MainActivity : FragmentActivity(), Request.RequestListener {
}

KeyEvent.KEYCODE_DPAD_DOWN -> {
active()
channelDown()
}

Expand All @@ -535,13 +546,15 @@ class MainActivity : FragmentActivity(), Request.RequestListener {
}

KeyEvent.KEYCODE_DPAD_LEFT -> {
active()
if (mainFragment.isHidden && !settingFragment.isVisible) {
switchMainFragment()
return true
}
}

KeyEvent.KEYCODE_DPAD_RIGHT -> {
active()
if (mainFragment.isHidden && !settingFragment.isVisible) {
showSetting()
return true
Expand Down Expand Up @@ -570,6 +583,12 @@ class MainActivity : FragmentActivity(), Request.RequestListener {
override fun onResume() {
Log.i(TAG, "onResume")
super.onResume()
}

override fun onResumeFragments() {
super.onResumeFragments()
mainFragment.changeMenu()

if (!mainFragment.isHidden) {
handler.postDelayed(hideMain, delayHideMain)
}
Expand Down
4 changes: 2 additions & 2 deletions app/src/main/java/com/lizongying/mytv/MainFragment.kt
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
package com.lizongying.mytv

import android.content.res.Resources
import android.graphics.Color
import android.os.Bundle
import android.util.Log
import android.view.KeyEvent
Expand Down Expand Up @@ -162,8 +160,10 @@ class MainFragment : Fragment(), CardAdapter.ItemListener {
if (tvViewModel.errInfo.value == "") {
(activity as? MainActivity)?.showPlayerFragment()
(activity as? MainActivity)?.hideErrorFragment()
(activity as? MainActivity)?.hideLoadingFragment()
} else {
(activity as? MainActivity)?.hidePlayerFragment()
(activity as? MainActivity)?.hideLoadingFragment()
(activity as? MainActivity)?.showErrorFragment(tvViewModel.errInfo.value.toString())
}
}
Expand Down
6 changes: 6 additions & 0 deletions app/src/main/java/com/lizongying/mytv/SettingFragment.kt
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.lizongying.mytv

import android.os.Build
import android.os.Bundle
import android.view.LayoutInflater
import android.view.View
Expand All @@ -23,6 +24,11 @@ class SettingFragment : DialogFragment() {
dialog?.window?.apply {
addFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN)
decorView.systemUiVisibility = View.SYSTEM_UI_FLAG_HIDE_NAVIGATION
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) {
attributes.layoutInDisplayCutoutMode =
WindowManager.LayoutParams.LAYOUT_IN_DISPLAY_CUTOUT_MODE_SHORT_EDGES
setAttributes(attributes)
}
}
}

Expand Down
9 changes: 8 additions & 1 deletion app/src/main/java/com/lizongying/mytv/TimeFragment.kt
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package com.lizongying.mytv

import android.content.res.Resources
import android.os.Bundle
import android.os.Handler
import android.view.LayoutInflater
Expand Down Expand Up @@ -36,10 +35,18 @@ class TimeFragment : Fragment() {
binding.time.layoutParams = layoutParams

binding.content.textSize = application.px2PxFont(binding.content.textSize)
binding.channel.textSize = application.px2PxFont(binding.channel.textSize)

binding.main.layoutParams.width = application.shouldWidthPx()
binding.main.layoutParams.height = application.shouldHeightPx()

if (SP.time) {
handler.removeCallbacks(showRunnable)
handler.postDelayed(showRunnable, 0)
} else {
handler.removeCallbacks(showRunnable)
}

(activity as MainActivity).fragmentReady(TAG)
return binding.root
}
Expand Down
25 changes: 19 additions & 6 deletions app/src/main/res/layout/channel.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center"
Expand All @@ -10,22 +11,34 @@
android:layout_height="match_parent"
>

<FrameLayout
<RelativeLayout
android:id="@+id/channel"
android:layout_width="90dp"
android:layout_height="60dp"
android:layout_gravity="end|top"
android:layout_marginTop="20dp"
android:layout_marginEnd="170dp">
android:layout_marginTop="15dp"
android:layout_marginEnd="170dp"
android:gravity="end|bottom" >

<TextView
android:id="@+id/content"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="end"
android:layout_gravity="end|bottom"
android:textColor="@color/white"
android:textStyle="bold"
android:textSize="40sp" />
</FrameLayout>
android:textSize="40sp"
tools:text="99"
android:layout_alignBaseline="@+id/time"/>
<TextView
android:id="@+id/time"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="end|bottom"
android:textColor="@color/white"
android:textStyle="bold"
android:textSize="32sp"
tools:text="12:34" />
</RelativeLayout>
</FrameLayout>
</LinearLayout>
1 change: 0 additions & 1 deletion app/src/main/res/layout/setting.xml
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@
android:id="@+id/check_version"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginEnd="10dp"
android:textSize="14sp"
android:text="@string/check_version"
/>
Expand Down
29 changes: 21 additions & 8 deletions app/src/main/res/layout/time.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center"
Expand All @@ -10,23 +11,35 @@
android:layout_height="match_parent"
>

<FrameLayout
<RelativeLayout
android:id="@+id/time"
android:layout_width="100dp"
android:layout_height="40dp"
android:layout_width="120dp"
android:layout_height="60dp"
android:layout_gravity="end|top"
android:layout_marginTop="25dp"
android:layout_marginEnd="50dp">
android:layout_marginTop="15dp"
android:layout_marginEnd="50dp"
android:gravity="end|bottom" >

<TextView
android:id="@+id/channel"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="end|bottom"
android:textColor="@color/white"
android:textStyle="bold"
android:textSize="40sp"
tools:text="99"
android:layout_alignBaseline="@+id/content"/>
<TextView
android:id="@+id/content"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="end"
android:layout_gravity="end|bottom"
android:textColor="@color/white"
android:textStyle="bold"
android:textSize="32sp" />
</FrameLayout>
android:textSize="32sp"
tools:text="12:34" />
</RelativeLayout>

</FrameLayout>
</LinearLayout>
2 changes: 1 addition & 1 deletion app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,5 @@
<string name="title_boot_startup">开机自启</string>
<string name="title_grid">频道列表采用网格样式</string>
<string name="title_time">显示时间</string>
<string name="exit">退出</string>
<string name="exit">退出应用</string>
</resources>

1 comment on commit b157f1e

@yulo126
Copy link

@yulo126 yulo126 commented on b157f1e May 7, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

你好,要是能完善央视(3.6.8等套)就更好了,感谢作者的无私付出!

Please sign in to comment.