Skip to content

Commit 8a37200

Browse files
committed
update mannager
1 parent e778043 commit 8a37200

File tree

18 files changed

+486
-36
lines changed

18 files changed

+486
-36
lines changed

app/src/main/java/com/lizongying/mytv/CardPresenter.kt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,11 @@ class CardPresenter(
4747
.centerInside()
4848
.into(cardView.mainImageView)
4949

50+
"兵团卫视" -> Glide.with(viewHolder.view.context)
51+
.load(R.drawable.bingtuan)
52+
.centerInside()
53+
.into(cardView.mainImageView)
54+
5055
else -> Glide.with(viewHolder.view.context)
5156
.load(tvViewModel.logo.value)
5257
.centerInside()
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
package com.lizongying.mytv
2+
3+
import android.app.AlertDialog
4+
import android.app.Dialog
5+
import android.os.Bundle
6+
import androidx.fragment.app.DialogFragment
7+
8+
class ConfirmationDialogFragment(private val listener: ConfirmationDialogListener) :
9+
DialogFragment() {
10+
11+
override fun onCreateDialog(savedInstanceState: Bundle?): Dialog {
12+
return activity?.let {
13+
val builder = AlertDialog.Builder(it)
14+
builder.setTitle("确认")
15+
.setMessage("确认更新吗?")
16+
.setPositiveButton(
17+
"确定"
18+
) { _, _ ->
19+
listener.onConfirm()
20+
}
21+
.setNegativeButton(
22+
"取消"
23+
) { _, _ ->
24+
listener.onCancel()
25+
}
26+
// 创建并返回 AlertDialog 对象
27+
builder.create()
28+
} ?: throw IllegalStateException("Activity cannot be null")
29+
}
30+
31+
interface ConfirmationDialogListener {
32+
fun onConfirm()
33+
fun onCancel()
34+
}
35+
}
36+

app/src/main/java/com/lizongying/mytv/Encryptor.kt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ class Encryptor {
99

1010
external fun hash(data: ByteArray): ByteArray?
1111

12+
external fun hash2(data: ByteArray): ByteArray?
13+
1214
companion object {
1315
init {
1416
System.loadLibrary("native")

app/src/main/java/com/lizongying/mytv/MainActivity.kt

Lines changed: 21 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -29,10 +29,11 @@ import java.security.MessageDigest
2929

3030
class MainActivity : FragmentActivity() {
3131

32-
var playerFragment = PlayerFragment()
33-
private val mainFragment = MainFragment()
34-
private val infoFragment = InfoFragment()
35-
private val channelFragment = ChannelFragment()
32+
private var ready = 0
33+
private var playerFragment = PlayerFragment()
34+
private var mainFragment = MainFragment()
35+
private var infoFragment = InfoFragment()
36+
private var channelFragment = ChannelFragment()
3637
private lateinit var settingFragment: SettingFragment
3738

3839
private var doubleBackToExitPressedOnce = false
@@ -85,8 +86,15 @@ class MainActivity : FragmentActivity() {
8586
channelNum = sharedPref.getBoolean(CHANNEL_NUM, channelNum)
8687
bootStartup = sharedPref.getBoolean(BOOT_STARTUP, bootStartup)
8788

88-
versionName = getPackageInfo().versionName
89-
settingFragment = SettingFragment(versionName, channelReversal, channelNum, bootStartup)
89+
val packageInfo = getPackageInfo()
90+
versionName = packageInfo.versionName
91+
val versionCode = if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) {
92+
packageInfo.longVersionCode
93+
} else {
94+
packageInfo.versionCode.toLong()
95+
}
96+
settingFragment =
97+
SettingFragment(versionName, versionCode, channelReversal, channelNum, bootStartup)
9098
}
9199

92100
fun showInfoFragment(tvViewModel: TVViewModel) {
@@ -172,7 +180,11 @@ class MainActivity : FragmentActivity() {
172180
}
173181

174182
fun fragmentReady() {
175-
mainFragment.fragmentReady()
183+
ready++
184+
Log.i(TAG, "ready $ready")
185+
if (ready == 4) {
186+
mainFragment.fragmentReady()
187+
}
176188
}
177189

178190
override fun onTouchEvent(event: MotionEvent?): Boolean {
@@ -520,7 +532,7 @@ class MainActivity : FragmentActivity() {
520532
override fun onResume() {
521533
Log.i(TAG, "onResume")
522534
super.onResume()
523-
if (!mainFragment.isHidden){
535+
if (!mainFragment.isHidden) {
524536
handler.postDelayed(hideMain, delayHideMain)
525537
}
526538
}
@@ -537,4 +549,4 @@ class MainActivity : FragmentActivity() {
537549
private const val CHANNEL_NUM = "channel_num"
538550
const val BOOT_STARTUP = "boot_startup"
539551
}
540-
}
552+
}

app/src/main/java/com/lizongying/mytv/MainFragment.kt

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,6 @@ class MainFragment : BrowseSupportFragment() {
4141
private val handler = Handler(Looper.getMainLooper())
4242
private lateinit var mUpdateProgramRunnable: UpdateProgramRunnable
4343

44-
private var ready = 0
45-
4644
override fun onCreate(savedInstanceState: Bundle?) {
4745
Log.i(TAG, "onCreate")
4846
super.onCreate(savedInstanceState)
@@ -89,6 +87,7 @@ class MainFragment : BrowseSupportFragment() {
8987
tvViewModel.change.observe(viewLifecycleOwner) { _ ->
9088
if (tvViewModel.change.value != null) {
9189
val title = tvViewModel.title.value
90+
Log.i(TAG, "switch $title")
9291
if (tvViewModel.pid.value != "") {
9392
Log.i(TAG, "request $title")
9493
lifecycleScope.launch(Dispatchers.IO) {
@@ -113,7 +112,7 @@ class MainFragment : BrowseSupportFragment() {
113112
}
114113
}
115114

116-
fragmentReady()
115+
(activity as MainActivity).fragmentReady()
117116
}
118117

119118
fun toLastPosition() {
@@ -245,12 +244,8 @@ class MainFragment : BrowseSupportFragment() {
245244
}
246245

247246
fun fragmentReady() {
248-
ready++
249-
Log.i(TAG, "ready $ready")
250-
if (ready == 4) {
251247
// request.fetchPage()
252-
tvListViewModel.getTVViewModel(itemPosition)?.changed()
253-
}
248+
tvListViewModel.getTVViewModel(itemPosition)?.changed()
254249
}
255250

256251
fun play(itemPosition: Int) {
@@ -332,7 +327,9 @@ class MainFragment : BrowseSupportFragment() {
332327
override fun onDestroy() {
333328
Log.i(TAG, "onDestroy")
334329
super.onDestroy()
335-
handler.removeCallbacks(mUpdateProgramRunnable)
330+
if (::mUpdateProgramRunnable.isInitialized) {
331+
handler.removeCallbacks(mUpdateProgramRunnable)
332+
}
336333
}
337334

338335
companion object {

app/src/main/java/com/lizongying/mytv/PlayerFragment.kt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,7 @@ class PlayerFragment : Fragment(), SurfaceHolder.Callback {
8080
super.onPlayerError(error)
8181

8282
Log.e(TAG, "PlaybackException $error")
83+
tvViewModel?.changed()
8384
}
8485
})
8586
}
@@ -107,10 +108,12 @@ class PlayerFragment : Fragment(), SurfaceHolder.Callback {
107108
if (playerView != null && playerView!!.player?.isPlaying == false) {
108109
Log.i(TAG, "replay")
109110
playerView!!.player?.prepare()
111+
playerView!!.player?.play()
110112
}
111113
if (exoPlayer?.isPlaying == false) {
112114
Log.i(TAG, "replay")
113115
exoPlayer?.prepare()
116+
exoPlayer?.play()
114117
}
115118
}
116119

app/src/main/java/com/lizongying/mytv/SettingFragment.kt

Lines changed: 28 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,16 +8,20 @@ import androidx.fragment.app.DialogFragment
88
import com.lizongying.mytv.databinding.DialogBinding
99

1010

11-
class SettingFragment(private val versionName: String,
12-
private val channelReversal: Boolean,
13-
private val channelNum: Boolean,
14-
private val bootStartup: Boolean,
15-
) :
11+
class SettingFragment(
12+
private val versionName: String,
13+
private val versionCode: Long,
14+
private val channelReversal: Boolean,
15+
private val channelNum: Boolean,
16+
private val bootStartup: Boolean,
17+
) :
1618
DialogFragment() {
1719

1820
private var _binding: DialogBinding? = null
1921
private val binding get() = _binding!!
2022

23+
private lateinit var updateManager: UpdateManager
24+
2125
override fun onCreate(savedInstanceState: Bundle?) {
2226
super.onCreate(savedInstanceState)
2327
setStyle(STYLE_NO_TITLE, 0)
@@ -50,14 +54,33 @@ class SettingFragment(private val versionName: String,
5054
(activity as MainActivity).saveBootStartup(isChecked)
5155
}
5256

57+
updateManager = UpdateManager(context, this, versionCode)
58+
_binding?.checkVersion?.setOnClickListener(OnClickListenerCheckVersion(updateManager))
59+
5360
return binding.root
5461
}
5562

63+
fun setVersionName(versionName: String) {
64+
binding.versionName.text = versionName
65+
}
66+
67+
internal class OnClickListenerCheckVersion(private val updateManager: UpdateManager) :
68+
View.OnClickListener {
69+
override fun onClick(view: View?) {
70+
updateManager.checkAndUpdate()
71+
}
72+
}
73+
5674
override fun onDestroyView() {
5775
super.onDestroyView()
5876
_binding = null
5977
}
6078

79+
override fun onDestroy() {
80+
super.onDestroy()
81+
// updateManager.destroy()
82+
}
83+
6184
companion object {
6285
const val TAG = "SettingFragment"
6386
}

app/src/main/java/com/lizongying/mytv/TVList.kt

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -859,10 +859,24 @@ object TVList {
859859
true,
860860
mustToken = false
861861
),
862+
TV(
863+
56,
864+
"兵团卫视",
865+
"兵团卫视",
866+
listOf(),
867+
0,
868+
"地方频道",
869+
"",
870+
"600170344",
871+
"2022606701",
872+
"",
873+
true,
874+
mustToken = false
875+
),
862876
),
863877
"国际频道" to listOf(
864878
TV(
865-
56,
879+
57,
866880
"CGTN",
867881
"CGTN",
868882
listOf("http://live.cgtn.com/1000/prog_index.m3u8"),
@@ -876,7 +890,7 @@ object TVList {
876890
mustToken = false
877891
),
878892
TV(
879-
57,
893+
58,
880894
"CGTN 法语频道",
881895
"CGTN法语频道",
882896
listOf("https://livefr.cgtn.com/1000f/prog_index.m3u8"),
@@ -890,7 +904,7 @@ object TVList {
890904
mustToken = false
891905
),
892906
TV(
893-
58,
907+
59,
894908
"CGTN 俄语频道",
895909
"CGTN俄语频道",
896910
listOf("http://liveru.cgtn.com/1000r/prog_index.m3u8"),
@@ -904,7 +918,7 @@ object TVList {
904918
mustToken = false
905919
),
906920
TV(
907-
59,
921+
60,
908922
"CGTN 阿拉伯语频道",
909923
"CGTN阿拉伯语频道",
910924
listOf("http://livear.cgtn.com/1000a/prog_index.m3u8"),
@@ -918,7 +932,7 @@ object TVList {
918932
mustToken = false
919933
),
920934
TV(
921-
60,
935+
61,
922936
"CGTN 西班牙语频道",
923937
"CGTN西班牙语频道",
924938
listOf(
@@ -935,7 +949,7 @@ object TVList {
935949
mustToken = false
936950
),
937951
TV(
938-
61,
952+
62,
939953
"CGTN 纪录频道",
940954
"CGTN外语纪录频道",
941955
listOf("https://livedoc.cgtn.com/500d/prog_index.m3u8"),

0 commit comments

Comments
 (0)