Skip to content

Commit

Permalink
fix time always visible
Browse files Browse the repository at this point in the history
  • Loading branch information
lizongying committed Apr 29, 2024
1 parent b1bef58 commit 013b819
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 26 deletions.
40 changes: 33 additions & 7 deletions app/src/main/java/com/lizongying/mytv0/MainActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ class MainActivity : FragmentActivity() {
.hide(settingFragment)
.hide(errorFragment)
.hide(loadingFragment)
.hide(timeFragment)
.commitNow()
}

Expand Down Expand Up @@ -285,9 +286,9 @@ class MainActivity : FragmentActivity() {

fun showTime() {
if (SP.time) {
timeFragment.show()
showTimeFragment()
} else {
timeFragment.hide()
hideTimeFragment()
}
}

Expand Down Expand Up @@ -404,7 +405,7 @@ class MainActivity : FragmentActivity() {

private fun showErrorFragment(msg: String) {
errorFragment.show(msg)
if (errorFragment.isVisible) {
if (!errorFragment.isHidden) {
return
}

Expand All @@ -425,7 +426,7 @@ class MainActivity : FragmentActivity() {
}

private fun showLoadingFragment() {
if (loadingFragment.isVisible) {
if (!loadingFragment.isHidden) {
return
}

Expand All @@ -435,7 +436,7 @@ class MainActivity : FragmentActivity() {
}

private fun hideLoadingFragment() {
if (!loadingFragment.isVisible) {
if (loadingFragment.isHidden) {
return
}

Expand All @@ -444,8 +445,28 @@ class MainActivity : FragmentActivity() {
.commitNow()
}

private fun showTimeFragment() {
if (!timeFragment.isHidden) {
return
}

supportFragmentManager.beginTransaction()
.show(timeFragment)
.commitNow()
}

private fun hideTimeFragment() {
if (timeFragment.isHidden) {
return
}

supportFragmentManager.beginTransaction()
.hide(timeFragment)
.commitNow()
}

private fun showPlayerFragment() {
if (playerFragment.isVisible) {
if (!playerFragment.isHidden) {
return
}

Expand All @@ -455,7 +476,7 @@ class MainActivity : FragmentActivity() {
}

private fun hidePlayerFragment() {
if (!playerFragment.isVisible) {
if (playerFragment.isHidden) {
return
}

Expand Down Expand Up @@ -597,6 +618,11 @@ class MainActivity : FragmentActivity() {
return super.onKeyDown(keyCode, event)
}

override fun onResume() {
super.onResume()
showTime()
}

override fun onStop() {
super.onStop()
}
Expand Down
24 changes: 5 additions & 19 deletions app/src/main/java/com/lizongying/mytv0/TimeFragment.kt
Original file line number Diff line number Diff line change
Expand Up @@ -42,19 +42,16 @@ class TimeFragment : Fragment() {
return binding.root
}

override fun onResume() {
super.onResume()
if (view?.visibility == View.VISIBLE) {
override fun onHiddenChanged(hidden: Boolean) {
super.onHiddenChanged(hidden)
if (!hidden) {
handler.removeCallbacks(showRunnable)
handler.postDelayed(showRunnable, 0)
} else {
handler.removeCallbacks(showRunnable)
}
}

override fun onPause() {
super.onPause()
handler.removeCallbacks(showRunnable)
}

private val showRunnable: Runnable = Runnable {
run {
if (_binding == null) {
Expand All @@ -65,17 +62,6 @@ class TimeFragment : Fragment() {
}
}

fun show() {
view?.visibility = View.VISIBLE
handler.removeCallbacks(showRunnable)
handler.postDelayed(showRunnable, 0)
}

fun hide() {
view?.visibility = View.GONE
handler.removeCallbacks(showRunnable)
}

override fun onDestroyView() {
super.onDestroyView()
_binding = null
Expand Down

0 comments on commit 013b819

Please sign in to comment.