Skip to content

Commit

Permalink
channel num setting
Browse files Browse the repository at this point in the history
  • Loading branch information
lizongying committed Jan 19, 2024
1 parent 4631103 commit 9feb0dc
Show file tree
Hide file tree
Showing 10 changed files with 255 additions and 558 deletions.
2 changes: 1 addition & 1 deletion app/src/main/java/com/lizongying/mytv/ChannelFragment.kt
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ class ChannelFragment : Fragment() {
savedInstanceState: Bundle?
): View {
_binding = ChannelBinding.inflate(inflater, container, false)
_binding!!.root.visibility = View.GONE
(activity as MainActivity).fragmentReady()
return binding.root
}
Expand All @@ -41,7 +42,6 @@ class ChannelFragment : Fragment() {
handler.postDelayed(removeRunnable, delay)
} else {
val ch = "${binding.channelContent.text}$channel".toInt()
Log.i(TAG, "channel $ch")
(activity as MainActivity).play(ch)
binding.channelContent.text = ""
view?.visibility = View.GONE
Expand Down
15 changes: 6 additions & 9 deletions app/src/main/java/com/lizongying/mytv/InfoFragment.kt
Original file line number Diff line number Diff line change
Expand Up @@ -23,17 +23,11 @@ class InfoFragment : Fragment() {
savedInstanceState: Bundle?
): View {
_binding = InfoBinding.inflate(inflater, container, false)
_binding!!.root.visibility = View.GONE
(activity as MainActivity).fragmentReady()
return binding.root
}

override fun onResume() {
super.onResume()

// Use a Handler to delay the fragment transaction
handler.postDelayed(removeRunnable, delay)
}

fun show(tvViewModel: TVViewModel) {
binding.textView.text = tvViewModel.title.value
if (tvViewModel.title.value == "CCTV8K 超高清") {
Expand All @@ -56,10 +50,13 @@ class InfoFragment : Fragment() {
handler.postDelayed(removeRunnable, delay)
}

override fun onResume() {
super.onResume()
handler.postDelayed(removeRunnable, delay)
}

override fun onPause() {
super.onPause()
Log.i(TAG, "onPause")
// Cancel the delayed task when the fragment is paused
handler.removeCallbacks(removeRunnable)
}

Expand Down
63 changes: 38 additions & 25 deletions app/src/main/java/com/lizongying/mytv/MainActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,10 @@ import java.security.MessageDigest
class MainActivity : FragmentActivity() {

var playerFragment = PlayerFragment()
private val mainFragment = MainFragment2()
private val mainFragment = MainFragment()
private val infoFragment = InfoFragment()
private val channelFragment = ChannelFragment()
private lateinit var settingFragment: SettingFragment

private var doubleBackToExitPressedOnce = false

Expand All @@ -39,9 +40,9 @@ class MainActivity : FragmentActivity() {

private lateinit var sharedPref: SharedPreferences
private var channelReversal = false
private var channelNum = true

private var versionName = ""
private lateinit var dialogFragment: MyDialogFragment

override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
Expand All @@ -57,24 +58,39 @@ class MainActivity : FragmentActivity() {
.add(R.id.main_browse_fragment, infoFragment)
.add(R.id.main_browse_fragment, channelFragment)
.add(R.id.main_browse_fragment, mainFragment)
.hide(infoFragment)
.hide(channelFragment)
.hide(mainFragment)
.commit()
mainFragment.view?.requestFocus()
}
gestureDetector = GestureDetector(this, GestureListener())

sharedPref = getPreferences(Context.MODE_PRIVATE)
channelReversal = sharedPref.getBoolean(CHANNEL_REVERSAL, false)
channelReversal = sharedPref.getBoolean(CHANNEL_REVERSAL, channelReversal)
channelNum = sharedPref.getBoolean(CHANNEL_NUM, channelNum)

versionName = getPackageInfo().versionName
dialogFragment = MyDialogFragment(versionName, channelReversal)
settingFragment = SettingFragment(versionName, channelReversal, channelNum)
}

fun showInfoFragment(tvViewModel: TVViewModel) {
infoFragment.show(tvViewModel)
channelFragment.show(tvViewModel)
if (channelNum) {
channelFragment.show(tvViewModel)
}
}

private fun showChannel(channel: String) {
if (!mainFragment.isHidden) {
return
}

if (settingFragment.isVisible) {
return
}

if (channelNum) {
channelFragment.show(channel)
}
}

fun play(tvViewModel: TVViewModel) {
Expand Down Expand Up @@ -199,25 +215,33 @@ class MainActivity : FragmentActivity() {
this.channelReversal = channelReversal
}

fun saveChannelNum(channelNum: Boolean) {
with(sharedPref.edit()) {
putBoolean(CHANNEL_NUM, channelNum)
apply()
}
this.channelNum = channelNum
}

private fun showHelp() {
if (!mainFragment.isHidden) {
return
}

Log.i(TAG, "dialogFragment ${dialogFragment.isVisible}")
if (!dialogFragment.isVisible) {
dialogFragment.show(supportFragmentManager, "settings_dialog")
Log.i(TAG, "settingFragment ${settingFragment.isVisible}")
if (!settingFragment.isVisible) {
settingFragment.show(supportFragmentManager, "setting")
handler.removeCallbacks(hideHelp)
handler.postDelayed(hideHelp, delayHideHelp)
} else {
handler.removeCallbacks(hideHelp)
dialogFragment.dismiss()
settingFragment.dismiss()
}
}

private val hideHelp = Runnable {
if (dialogFragment.isVisible) {
dialogFragment.dismiss()
if (settingFragment.isVisible) {
settingFragment.dismiss()
}
}

Expand Down Expand Up @@ -273,18 +297,6 @@ class MainActivity : FragmentActivity() {
}, 2000)
}

private fun showChannel(channel: String) {
if (!mainFragment.isHidden) {
return
}

if (dialogFragment.isVisible) {
return
}

channelFragment.show(channel)
}

override fun onKeyDown(keyCode: Int, event: KeyEvent?): Boolean {
when (keyCode) {
KeyEvent.KEYCODE_0 -> {
Expand Down Expand Up @@ -479,5 +491,6 @@ class MainActivity : FragmentActivity() {
companion object {
private const val TAG = "MainActivity"
private const val CHANNEL_REVERSAL = "channel_reversal"
private const val CHANNEL_NUM = "channel_num"
}
}
Loading

0 comments on commit 9feb0dc

Please sign in to comment.