@@ -27,16 +27,22 @@ class MainActivity : FragmentActivity() {
2727 var playerFragment = PlayerFragment ()
2828 private val mainFragment = MainFragment ()
2929 private val infoFragment = InfoFragment ()
30+ private val channelFragment = ChannelFragment ()
3031
3132 private var doubleBackToExitPressedOnce = false
3233
3334 private lateinit var gestureDetector: GestureDetector
3435
3536 private val handler = Handler ()
3637 private val delay: Long = 4000
38+ private val delayHideHelp: Long = 10000
3739
3840 private lateinit var sharedPref: SharedPreferences
3941 private var channelReversal = false
42+ private var channelNum = true
43+
44+ private var versionName = " "
45+ private lateinit var dialogFragment: MyDialogFragment
4046
4147 override fun onCreate (savedInstanceState : Bundle ? ) {
4248 super .onCreate(savedInstanceState)
@@ -50,26 +56,39 @@ class MainActivity : FragmentActivity() {
5056 supportFragmentManager.beginTransaction()
5157 .add(R .id.main_browse_fragment, playerFragment)
5258 .add(R .id.main_browse_fragment, infoFragment)
59+ .add(R .id.main_browse_fragment, channelFragment)
5360 .add(R .id.main_browse_fragment, mainFragment)
5461 .hide(infoFragment)
62+ .hide(channelFragment)
5563 .commit()
5664 mainFragment.view?.requestFocus()
5765 }
5866 gestureDetector = GestureDetector (this , GestureListener ())
5967
6068 sharedPref = getPreferences(Context .MODE_PRIVATE )
61- channelReversal = sharedPref.getBoolean(CHANNEL_REVERSAL , false )
69+ channelReversal = sharedPref.getBoolean(CHANNEL_REVERSAL , channelReversal)
70+ channelNum = sharedPref.getBoolean(CHANNEL_NUM , channelNum)
71+
72+ versionName = getPackageInfo().versionName
73+ dialogFragment = MyDialogFragment (versionName, channelReversal, channelNum)
6274 }
6375
6476 fun showInfoFragment (tvViewModel : TVViewModel ) {
6577 infoFragment.show(tvViewModel)
78+ if (channelNum) {
79+ channelFragment.show(tvViewModel)
80+ }
6681 }
6782
6883 fun play (tvViewModel : TVViewModel ) {
6984 playerFragment.play(tvViewModel)
7085 mainFragment.view?.requestFocus()
7186 }
7287
88+ fun play (itemPosition : Int ) {
89+ mainFragment.play(itemPosition)
90+ }
91+
7392 fun prev () {
7493 mainFragment.prev()
7594 }
@@ -79,11 +98,11 @@ class MainActivity : FragmentActivity() {
7998 }
8099
81100 private fun prevSource () {
82- mainFragment.prevSource()
101+ // mainFragment.prevSource()
83102 }
84103
85104 private fun nextSource () {
86- mainFragment.nextSource()
105+ // mainFragment.nextSource()
87106 }
88107
89108 fun switchMainFragment () {
@@ -182,14 +201,34 @@ class MainActivity : FragmentActivity() {
182201 this .channelReversal = channelReversal
183202 }
184203
204+ fun saveChannelNum (channelNum : Boolean ) {
205+ with (sharedPref.edit()) {
206+ putBoolean(CHANNEL_NUM , channelNum)
207+ apply ()
208+ }
209+ this .channelNum = channelNum
210+ }
211+
185212 private fun showHelp () {
186213 if (! mainFragment.isHidden) {
187214 return
188215 }
189216
190- val versionName = getPackageInfo().versionName
191- val dialogFragment = MyDialogFragment (versionName, channelReversal)
192- dialogFragment.show(supportFragmentManager, " settings_dialog" )
217+ Log .i(TAG , " dialogFragment ${dialogFragment.isVisible} " )
218+ if (! dialogFragment.isVisible) {
219+ dialogFragment.show(supportFragmentManager, " settings_dialog" )
220+ handler.removeCallbacks(hideHelp)
221+ handler.postDelayed(hideHelp, delayHideHelp)
222+ } else {
223+ handler.removeCallbacks(hideHelp)
224+ dialogFragment.dismiss()
225+ }
226+ }
227+
228+ private val hideHelp = Runnable {
229+ if (dialogFragment.isVisible) {
230+ dialogFragment.dismiss()
231+ }
193232 }
194233
195234 private fun channelUp () {
@@ -244,8 +283,72 @@ class MainActivity : FragmentActivity() {
244283 }, 2000 )
245284 }
246285
286+ private fun showChannel (channel : String ) {
287+ if (! mainFragment.isHidden) {
288+ return
289+ }
290+
291+ if (dialogFragment.isVisible) {
292+ return
293+ }
294+
295+ if (channelNum) {
296+ channelFragment.show(channel)
297+ }
298+ }
299+
247300 override fun onKeyDown (keyCode : Int , event : KeyEvent ? ): Boolean {
248301 when (keyCode) {
302+ KeyEvent .KEYCODE_0 -> {
303+ showChannel(" 0" )
304+ return true
305+ }
306+
307+ KeyEvent .KEYCODE_1 -> {
308+ showChannel(" 1" )
309+ return true
310+ }
311+
312+ KeyEvent .KEYCODE_2 -> {
313+ showChannel(" 2" )
314+ return true
315+ }
316+
317+ KeyEvent .KEYCODE_3 -> {
318+ showChannel(" 3" )
319+ return true
320+ }
321+
322+ KeyEvent .KEYCODE_4 -> {
323+ showChannel(" 4" )
324+ return true
325+ }
326+
327+ KeyEvent .KEYCODE_5 -> {
328+ showChannel(" 5" )
329+ return true
330+ }
331+
332+ KeyEvent .KEYCODE_6 -> {
333+ showChannel(" 6" )
334+ return true
335+ }
336+
337+ KeyEvent .KEYCODE_7 -> {
338+ showChannel(" 7" )
339+ return true
340+ }
341+
342+ KeyEvent .KEYCODE_8 -> {
343+ showChannel(" 8" )
344+ return true
345+ }
346+
347+ KeyEvent .KEYCODE_9 -> {
348+ showChannel(" 9" )
349+ return true
350+ }
351+
249352 KeyEvent .KEYCODE_ESCAPE -> {
250353 back()
251354 return true
@@ -388,5 +491,6 @@ class MainActivity : FragmentActivity() {
388491 companion object {
389492 private const val TAG = " MainActivity"
390493 private const val CHANNEL_REVERSAL = " channel_reversal"
494+ private const val CHANNEL_NUM = " channel_num"
391495 }
392496}
0 commit comments