Skip to content

Commit

Permalink
replay
Browse files Browse the repository at this point in the history
  • Loading branch information
lizongying committed Feb 1, 2024
1 parent cc2514a commit 73239a6
Show file tree
Hide file tree
Showing 7 changed files with 76 additions and 29 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# 我的电视

安卓电视直播软件,内置直播源
电视直播软件,安装即可使用

## 使用

Expand Down
8 changes: 5 additions & 3 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -9,17 +9,19 @@
<uses-permission android:name="android.permission.INTERNET" />
<application
android:allowBackup="true"
android:largeHeap="true"
android:icon="@drawable/logo"
android:logo="@drawable/logo"
android:banner="@drawable/banner"
android:label="@string/app_name"
android:supportsRtl="true"
android:networkSecurityConfig="@xml/network"
android:usesCleartextTraffic="true"
android:theme="@style/Theme.MyTV">
<activity
android:keepScreenOn="true"
android:name=".MainActivity"
android:banner="@drawable/banner"
android:exported="true"
android:icon="@drawable/logo"
android:logo="@drawable/logo"
android:screenOrientation="landscape">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
Expand Down
51 changes: 36 additions & 15 deletions app/src/main/java/com/lizongying/mytv/MainActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@ class MainActivity : FragmentActivity() {
private lateinit var gestureDetector: GestureDetector

private val handler = Handler()
private val delay: Long = 4000
private val delayHideHelp: Long = 10000
private val delayHideMain: Long = 5000
private val delayHideSetting: Long = 10000

lateinit var sharedPref: SharedPreferences
private var channelReversal = false
Expand All @@ -45,6 +45,7 @@ class MainActivity : FragmentActivity() {
private var versionName = ""

override fun onCreate(savedInstanceState: Bundle?) {
Log.i(TAG, "onCreate")
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)

Expand All @@ -53,13 +54,17 @@ class MainActivity : FragmentActivity() {
window.decorView.systemUiVisibility = SYSTEM_UI_FLAG_HIDE_NAVIGATION

if (savedInstanceState == null) {
Log.i(TAG, "beginTransaction begin")
supportFragmentManager.beginTransaction()
.add(R.id.main_browse_fragment, playerFragment)
.add(R.id.main_browse_fragment, infoFragment)
.add(R.id.main_browse_fragment, channelFragment)
.add(R.id.main_browse_fragment, mainFragment)
.hide(mainFragment)
.commit()
Log.i(TAG, "beginTransaction end")
} else {
Log.i(TAG, "savedInstanceState $savedInstanceState")
}
gestureDetector = GestureDetector(this, GestureListener())

Expand Down Expand Up @@ -131,11 +136,11 @@ class MainActivity : FragmentActivity() {
}

fun keepRunnable() {
handler.removeCallbacks(hideRunnable)
handler.postDelayed(hideRunnable, delay)
handler.removeCallbacks(hideMain)
handler.postDelayed(hideMain, delayHideMain)
}

private val hideRunnable = Runnable {
private val hideMain = Runnable {
if (!mainFragment.isHidden) {
supportFragmentManager.beginTransaction().hide(mainFragment).commit()
}
Expand Down Expand Up @@ -221,23 +226,23 @@ class MainActivity : FragmentActivity() {
this.channelNum = channelNum
}

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

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

private val hideHelp = Runnable {
private val hideSetting = Runnable {
if (settingFragment.isVisible) {
settingFragment.dismiss()
}
Expand Down Expand Up @@ -358,27 +363,27 @@ class MainActivity : FragmentActivity() {
}

KeyEvent.KEYCODE_BOOKMARK -> {
showHelp()
showSetting()
return true
}

KeyEvent.KEYCODE_UNKNOWN -> {
showHelp()
showSetting()
return true
}

KeyEvent.KEYCODE_HELP -> {
showHelp()
showSetting()
return true
}

KeyEvent.KEYCODE_SETTINGS -> {
showHelp()
showSetting()
return true
}

KeyEvent.KEYCODE_MENU -> {
showHelp()
showSetting()
return true
}

Expand Down Expand Up @@ -486,6 +491,22 @@ class MainActivity : FragmentActivity() {
}
}

override fun onStart() {
Log.i(TAG, "onStart")
super.onStart()
}

override fun onResume() {
Log.i(TAG, "onResume")
super.onResume()
}

override fun onPause() {
Log.i(TAG, "onPause")
super.onPause()
handler.removeCallbacks(hideMain)
}

companion object {
private const val TAG = "MainActivity"
private const val CHANNEL_REVERSAL = "channel_reversal"
Expand Down
18 changes: 12 additions & 6 deletions app/src/main/java/com/lizongying/mytv/MainFragment.kt
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,16 @@ class MainFragment : BrowseSupportFragment() {
private var ready = 0

override fun onCreate(savedInstanceState: Bundle?) {
Log.i(TAG, "onCreate")
super.onCreate(savedInstanceState)
headersState = HEADERS_DISABLED
}

override fun onStart() {
Log.i(TAG, "onStart")
super.onStart()
}

override fun onActivityCreated(savedInstanceState: Bundle?) {
super.onActivityCreated(savedInstanceState)

Expand Down Expand Up @@ -308,14 +314,19 @@ class MainFragment : BrowseSupportFragment() {
}
}

override fun onResume() {
Log.i(TAG, "onResume")
super.onResume()
}

override fun onStop() {
Log.i(TAG, "onStop")
super.onStop()
with(sharedPref.edit()) {
putInt(POSITION, itemPosition)
apply()
}
Log.i(TAG, "POSITION saved")
Log.i(TAG, "$POSITION saved")
}

override fun onDestroy() {
Expand All @@ -324,11 +335,6 @@ class MainFragment : BrowseSupportFragment() {
handler.removeCallbacks(mUpdateProgramRunnable)
}

override fun onResume() {
super.onResume()
view?.post { view?.requestFocus() }
}

companion object {
private const val TAG = "MainFragment"
private const val POSITION = "position"
Expand Down
15 changes: 12 additions & 3 deletions app/src/main/java/com/lizongying/mytv/PlayerFragment.kt
Original file line number Diff line number Diff line change
Expand Up @@ -81,14 +81,23 @@ class PlayerFragment : Fragment() {
}

override fun onStart() {
Log.i(TAG, "onStart")
super.onStart()
if (playerView != null && playerView!!.player?.isPlaying == false) {
playerView!!.player?.play()
Log.i(TAG, "replay")
playerView!!.player?.prepare()
} else {
Log.i(TAG, "playing")
}
}

override fun onStop() {
super.onStop()
override fun onResume() {
Log.i(TAG, "onResume")
super.onResume()
}

override fun onPause() {
super.onPause()
if (playerView != null && playerView!!.player?.isPlaying == true) {
playerView!!.player?.stop()
}
Expand Down
2 changes: 1 addition & 1 deletion app/src/main/java/com/lizongying/mytv/Request.kt
Original file line number Diff line number Diff line change
Expand Up @@ -361,7 +361,7 @@ class Request {
val program = response.body()
if (program != null) {
tvViewModel.addProgram(program.dataListList)
Log.i(TAG, "$title program ${program.dataListList.size}")
Log.d(TAG, "$title program ${program.dataListList.size}")
}
} else {
Log.w(TAG, "$title program error")
Expand Down
9 changes: 9 additions & 0 deletions app/src/main/res/xml/network.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<?xml version="1.0" encoding="utf-8"?>
<network-security-config>
<base-config cleartextTrafficPermitted="true">
<trust-anchors>
<certificates src="system" />
<certificates src="user" />
</trust-anchors>
</base-config>
</network-security-config>

0 comments on commit 73239a6

Please sign in to comment.