rename to setting
This commit is contained in:
parent
33d3da97e5
commit
c17d62c698
|
@ -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
|
||||
}
|
||||
|
@ -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
|
||||
|
|
|
@ -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 超高清") {
|
||||
|
@ -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)
|
||||
}
|
||||
|
||||
|
|
|
@ -28,6 +28,7 @@ class MainActivity : FragmentActivity() {
|
|||
private val mainFragment = MainFragment()
|
||||
private val infoFragment = InfoFragment()
|
||||
private val channelFragment = ChannelFragment()
|
||||
private lateinit var settingFragment: SettingFragment
|
||||
|
||||
private var doubleBackToExitPressedOnce = false
|
||||
|
||||
|
@ -42,7 +43,6 @@ class MainActivity : FragmentActivity() {
|
|||
private var channelNum = true
|
||||
|
||||
private var versionName = ""
|
||||
private lateinit var dialogFragment: MyDialogFragment
|
||||
|
||||
override fun onCreate(savedInstanceState: Bundle?) {
|
||||
super.onCreate(savedInstanceState)
|
||||
|
@ -58,8 +58,7 @@ 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()
|
||||
}
|
||||
|
@ -70,7 +69,7 @@ class MainActivity : FragmentActivity() {
|
|||
channelNum = sharedPref.getBoolean(CHANNEL_NUM, channelNum)
|
||||
|
||||
versionName = getPackageInfo().versionName
|
||||
dialogFragment = MyDialogFragment(versionName, channelReversal, channelNum)
|
||||
settingFragment = SettingFragment(versionName, channelReversal, channelNum)
|
||||
}
|
||||
|
||||
fun showInfoFragment(tvViewModel: TVViewModel) {
|
||||
|
@ -80,6 +79,20 @@ class MainActivity : FragmentActivity() {
|
|||
}
|
||||
}
|
||||
|
||||
private fun showChannel(channel: String) {
|
||||
if (!mainFragment.isHidden) {
|
||||
return
|
||||
}
|
||||
|
||||
if (settingFragment.isVisible) {
|
||||
return
|
||||
}
|
||||
|
||||
if (channelNum) {
|
||||
channelFragment.show(channel)
|
||||
}
|
||||
}
|
||||
|
||||
fun play(tvViewModel: TVViewModel) {
|
||||
playerFragment.play(tvViewModel)
|
||||
mainFragment.view?.requestFocus()
|
||||
|
@ -214,20 +227,20 @@ class MainActivity : FragmentActivity() {
|
|||
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()
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -283,20 +296,6 @@ class MainActivity : FragmentActivity() {
|
|||
}, 2000)
|
||||
}
|
||||
|
||||
private fun showChannel(channel: String) {
|
||||
if (!mainFragment.isHidden) {
|
||||
return
|
||||
}
|
||||
|
||||
if (dialogFragment.isVisible) {
|
||||
return
|
||||
}
|
||||
|
||||
if (channelNum) {
|
||||
channelFragment.show(channel)
|
||||
}
|
||||
}
|
||||
|
||||
override fun onKeyDown(keyCode: Int, event: KeyEvent?): Boolean {
|
||||
when (keyCode) {
|
||||
KeyEvent.KEYCODE_0 -> {
|
||||
|
|
|
@ -53,7 +53,6 @@ class MainFragment : BrowseSupportFragment() {
|
|||
super.onActivityCreated(savedInstanceState)
|
||||
|
||||
activity?.let { request.initYSP(it) }
|
||||
|
||||
sharedPref = activity?.getPreferences(Context.MODE_PRIVATE)
|
||||
|
||||
loadRows()
|
||||
|
@ -100,7 +99,6 @@ class MainFragment : BrowseSupportFragment() {
|
|||
if (check(tvViewModel)) {
|
||||
(activity as? MainActivity)?.play(tvViewModel)
|
||||
(activity as? MainActivity)?.showInfoFragment(tvViewModel)
|
||||
|
||||
setSelectedPosition(
|
||||
tvViewModel.getRowPosition(), true,
|
||||
SelectItemViewHolderTask(tvViewModel.getItemPosition())
|
||||
|
@ -114,58 +112,6 @@ class MainFragment : BrowseSupportFragment() {
|
|||
fragmentReady()
|
||||
}
|
||||
|
||||
override fun onDestroy() {
|
||||
super.onDestroy()
|
||||
handler.removeCallbacks(mUpdateProgramRunnable)
|
||||
with(sharedPref!!.edit()) {
|
||||
putInt("position", itemPosition)
|
||||
apply()
|
||||
}
|
||||
}
|
||||
|
||||
fun updateProgram(tvViewModel: TVViewModel) {
|
||||
val timestamp = getDateTimestamp()
|
||||
if (timestamp - tvViewModel.programUpdateTime > 60) {
|
||||
if (tvViewModel.program.value!!.isEmpty()) {
|
||||
tvViewModel.programUpdateTime = timestamp
|
||||
request.fetchProgram(tvViewModel)
|
||||
} else {
|
||||
if (timestamp - tvViewModel.program.value!!.last().et < 600) {
|
||||
tvViewModel.programUpdateTime = timestamp
|
||||
request.fetchProgram(tvViewModel)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
inner class UpdateProgramRunnable : Runnable {
|
||||
override fun run() {
|
||||
tvListViewModel.getTVListViewModel().value?.filter { it.programId.value != null }
|
||||
?.forEach { tvViewModel ->
|
||||
updateProgram(
|
||||
tvViewModel
|
||||
)
|
||||
}
|
||||
handler.postDelayed(this, 60000)
|
||||
}
|
||||
}
|
||||
|
||||
fun check(tvViewModel: TVViewModel): Boolean {
|
||||
val title = tvViewModel.title.value
|
||||
val videoUrl = tvViewModel.videoIndex.value?.let { tvViewModel.videoUrl.value?.get(it) }
|
||||
if (videoUrl == null || videoUrl == "") {
|
||||
Log.e(TAG, "$title videoUrl is empty")
|
||||
return false
|
||||
}
|
||||
|
||||
if (videoUrl == lastVideoUrl) {
|
||||
Log.e(TAG, "$title videoUrl is duplication")
|
||||
return false
|
||||
}
|
||||
|
||||
return true
|
||||
}
|
||||
|
||||
fun toLastPosition() {
|
||||
setSelectedPosition(
|
||||
selectedPosition, false,
|
||||
|
@ -206,22 +152,35 @@ class MainFragment : BrowseSupportFragment() {
|
|||
|
||||
adapter = rowsAdapter
|
||||
|
||||
itemPosition = sharedPref?.getInt("position", 0)!!
|
||||
itemPosition = sharedPref?.getInt(POSITION, 0)!!
|
||||
if (itemPosition >= tvListViewModel.size()) {
|
||||
itemPosition = 0
|
||||
}
|
||||
tvListViewModel.setItemPosition(itemPosition)
|
||||
}
|
||||
|
||||
fun check(tvViewModel: TVViewModel): Boolean {
|
||||
val title = tvViewModel.title.value
|
||||
val videoUrl = tvViewModel.videoIndex.value?.let { tvViewModel.videoUrl.value?.get(it) }
|
||||
if (videoUrl == null || videoUrl == "") {
|
||||
Log.e(TAG, "$title videoUrl is empty")
|
||||
return false
|
||||
}
|
||||
|
||||
if (videoUrl == lastVideoUrl) {
|
||||
Log.e(TAG, "$title videoUrl is duplication")
|
||||
return false
|
||||
}
|
||||
|
||||
return true
|
||||
}
|
||||
|
||||
fun fragmentReady() {
|
||||
ready++
|
||||
Log.i(TAG, "ready $ready")
|
||||
if (ready == 4) {
|
||||
// request.fetchPage()
|
||||
val tvViewModel = tvListViewModel.getTVViewModel(itemPosition)
|
||||
tvViewModel?.changed()
|
||||
|
||||
(activity as? MainActivity)?.switchMainFragment()
|
||||
tvListViewModel.getTVViewModel(itemPosition)?.changed()
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -322,12 +281,56 @@ class MainFragment : BrowseSupportFragment() {
|
|||
}
|
||||
}
|
||||
|
||||
fun updateProgram(tvViewModel: TVViewModel) {
|
||||
val timestamp = getDateTimestamp()
|
||||
if (timestamp - tvViewModel.programUpdateTime > 60) {
|
||||
if (tvViewModel.program.value!!.isEmpty()) {
|
||||
tvViewModel.programUpdateTime = timestamp
|
||||
request.fetchProgram(tvViewModel)
|
||||
} else {
|
||||
if (timestamp - tvViewModel.program.value!!.last().et < 600) {
|
||||
tvViewModel.programUpdateTime = timestamp
|
||||
request.fetchProgram(tvViewModel)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
inner class UpdateProgramRunnable : Runnable {
|
||||
override fun run() {
|
||||
tvListViewModel.getTVListViewModel().value?.filter { it.programId.value != null }
|
||||
?.forEach { tvViewModel ->
|
||||
updateProgram(
|
||||
tvViewModel
|
||||
)
|
||||
}
|
||||
handler.postDelayed(this, 60000)
|
||||
}
|
||||
}
|
||||
|
||||
override fun onStop() {
|
||||
Log.i(TAG, "onStop")
|
||||
super.onStop()
|
||||
with(sharedPref!!.edit()) {
|
||||
putInt(POSITION, itemPosition)
|
||||
apply()
|
||||
}
|
||||
Log.i(TAG, "POSITION saved")
|
||||
}
|
||||
|
||||
override fun onDestroy() {
|
||||
Log.i(TAG, "onDestroy")
|
||||
super.onDestroy()
|
||||
handler.removeCallbacks(mUpdateProgramRunnable)
|
||||
}
|
||||
|
||||
override fun onResume() {
|
||||
super.onResume()
|
||||
view!!.requestFocus()
|
||||
view?.post { view?.requestFocus() }
|
||||
}
|
||||
|
||||
companion object {
|
||||
private const val TAG = "MainFragment"
|
||||
private const val POSITION = "position"
|
||||
}
|
||||
}
|
|
@ -8,9 +8,9 @@ import androidx.fragment.app.DialogFragment
|
|||
import com.lizongying.mytv.databinding.DialogBinding
|
||||
|
||||
|
||||
class MyDialogFragment(private val versionName: String,
|
||||
private val channelReversal: Boolean,
|
||||
private val channelNum: Boolean,
|
||||
class SettingFragment(private val versionName: String,
|
||||
private val channelReversal: Boolean,
|
||||
private val channelNum: Boolean,
|
||||
) :
|
||||
DialogFragment() {
|
||||
|
||||
|
@ -52,7 +52,7 @@ class MyDialogFragment(private val versionName: String,
|
|||
}
|
||||
|
||||
companion object {
|
||||
const val TAG = "MyDialogFragment"
|
||||
const val TAG = "SettingFragment"
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue