Skip to content

Commit 029473b

Browse files
committed
optimize channel number
1 parent 7a144ad commit 029473b

File tree

13 files changed

+87
-114
lines changed

13 files changed

+87
-114
lines changed

HISTORY.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
### v1.3.9.8
44

5-
*
5+
* 優化頻道號
66

77
### v1.3.9.7-kitkat
88

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,4 @@ gen-version:
88

99
#make gen v=1.2.3
1010
gen:
11-
echo $(v) | sed 's/v/ /g' | sed 's/\./ /g' | sed 's/-/ /g' | awk '{print "{\"version_code\": " ($$1*16777216)+($$2*65536)+($$3*256)+$$4 ", \"version_name\": \"" "v$(v)" "\", \"apk_name\": \"" "my-tv-0_$(v).apk" "\", \"apk_url\": \"" "https://mirror.ghproxy.com/github.com/lizongying/my-tv-0/releases/download/v$(v)/my-tv-0_$(v).apk" "\"}"}' > version.json
11+
echo $(v) | sed 's/v/ /g' | sed 's/\./ /g' | sed 's/-/ /g' | awk '{print "{\"version_code\": " ($$1*16777216)+($$2*65536)+($$3*256)+$$4 ", \"version_name\": \"" "v$(v)" "\", \"apk_name\": \"" "my-tv-0_$(v).apk" "\", \"apk_url\": \"" "https://www.gitlink.org.cn/lizongying/my-tv-0/releases/download/v$(v)/my-tv-0_$(v).apk" "\"}"}' > version.json

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
* 遇到問題可以先考慮重啟/恢復默認/清除數據/重新安裝等方式自助解決
2121
* 視頻源可以設置為本地文件,格式如:file:///mnt/sdcard/tmp/channels.m3u
2222
/channels.m3u
23+
* 為了使用方便,只支持設置3位頻道號
2324
* 目前設置代理後,需要重啟生效。代理屬於全局代理,也就是視頻請求及其他請求都會使用代理。
2425

2526
目前支持的配置格式:

app/build.gradle.kts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,6 @@ android {
3232
}
3333
compileOptions {
3434
// Flag to enable support for the new language APIs
35-
3635
// For AGP 4.1+
3736
isCoreLibraryDesugaringEnabled = true
3837

app/src/main/java/com/lizongying/mytv0/ChannelFragment.kt

Lines changed: 25 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package com.lizongying.mytv0
33
import MainViewModel
44
import android.os.Bundle
55
import android.os.Handler
6+
import android.os.Looper
67
import android.util.Log
78
import android.view.LayoutInflater
89
import android.view.View
@@ -18,7 +19,7 @@ class ChannelFragment : Fragment() {
1819
private var _binding: ChannelBinding? = null
1920
private val binding get() = _binding!!
2021

21-
private val handler = Handler()
22+
private val handler = Handler(Looper.getMainLooper())
2223
private val delay: Long = 5000
2324
private var channel = 0
2425
private var channelCount = 0
@@ -57,19 +58,23 @@ class ChannelFragment : Fragment() {
5758
viewModel = ViewModelProvider(context)[MainViewModel::class.java]
5859
}
5960

60-
fun show(tvViewModel: TVModel) {
61+
fun show(tvModel: TVModel) {
62+
val tv = tvModel.tv
63+
Log.i(TAG, "show $tv")
6164
handler.removeCallbacks(hideRunnable)
6265
handler.removeCallbacks(playRunnable)
6366
if (_binding != null) {
6467
binding.content.text =
65-
if (tvViewModel.tv.number == -1) (tvViewModel.tv.id.plus(1)).toString() else tvViewModel.tv.number.toString()
68+
if (tv.number == -1) (tv.id.plus(1)).toString() else tv.number.toString()
6669
}
6770
view?.visibility = View.VISIBLE
71+
channel = 0
72+
channelCount = 0
6873
handler.postDelayed(hideRunnable, delay)
6974
}
7075

71-
fun show(channel: String) {
72-
Log.d(TAG, "input $channel")
76+
fun show(channel: Int) {
77+
Log.i(TAG, "input $channel ${this.channel}")
7378
val tv = viewModel.groupModel.getCurrent()!!.tv
7479
if (tv.id > 10 && tv.id == this.channel - 1) {
7580
this.channel = 0
@@ -83,15 +88,19 @@ class ChannelFragment : Fragment() {
8388
handler.removeCallbacks(hideRunnable)
8489
handler.removeCallbacks(playRunnable)
8590
Log.d(TAG, "channelCount $channelCount")
86-
binding.content.text = this.channel.toString()
91+
binding.content.text = "${this.channel}"
8792
view?.visibility = View.VISIBLE
8893
if (channelCount < 3) {
8994
handler.postDelayed(playRunnable, delay)
9095
} else {
91-
handler.postDelayed(playRunnable, 0)
96+
playNow()
9297
}
9398
}
9499

100+
fun playNow() {
101+
handler.postDelayed(playRunnable, 0)
102+
}
103+
95104
override fun onResume() {
96105
super.onResume()
97106
if (view?.visibility == View.VISIBLE) {
@@ -111,11 +120,11 @@ class ChannelFragment : Fragment() {
111120
}
112121

113122
view?.visibility = View.GONE
114-
channel = 0
115-
channelCount = 0
116123
}
117124

118125
fun hideSelf() {
126+
channel = 0
127+
channelCount = 0
119128
handler.postDelayed(hideRunnable, 0)
120129
}
121130

@@ -124,8 +133,13 @@ class ChannelFragment : Fragment() {
124133
viewModel.listModel.find { it.tv.number == channel }?.let {
125134
c = it.tv.id
126135
}
127-
(activity as MainActivity).play(c)
128-
handler.postDelayed(hideRunnable, delay)
136+
if ((activity as MainActivity).play(c)) {
137+
channel = 0
138+
channelCount = 0
139+
handler.postDelayed(hideRunnable, delay)
140+
} else {
141+
hideSelf()
142+
}
129143
}
130144

131145
override fun onDestroyView() {

app/src/main/java/com/lizongying/mytv0/ImageHelper.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ class ImageHelper(private val context: Context) {
7979
) {
8080
val file = files[key]
8181
if (file != null) {
82-
Log.i(TAG, "$key image exists ${file.absolutePath}")
82+
Log.d(TAG, "image exists ${file.absolutePath}")
8383
Glide.with(context)
8484
.load(file)
8585
.fitCenter()

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

Lines changed: 27 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -433,8 +433,8 @@ class MainActivity : AppCompatActivity() {
433433
}
434434
}
435435

436-
fun play(position: Int) {
437-
if (position > -1 && position < viewModel.groupModel.getAllList()!!.size()) {
436+
fun play(position: Int): Boolean {
437+
return if (position > -1 && position < viewModel.groupModel.getAllList()!!.size()) {
438438
val prevGroup = viewModel.groupModel.positionValue
439439
val tvModel = viewModel.groupModel.getPosition(position)
440440

@@ -446,8 +446,10 @@ class MainActivity : AppCompatActivity() {
446446
if (currentGroup != prevGroup) {
447447
menuFragment.updateList(currentGroup)
448448
}
449+
true
449450
} else {
450451
R.string.channel_not_exist.showToast()
452+
false
451453
}
452454
}
453455

@@ -567,7 +569,7 @@ class MainActivity : AppCompatActivity() {
567569
}
568570
}
569571

570-
private fun showChannel(channel: String) {
572+
private fun showChannel(channel: Int) {
571573
if (!menuFragment.isHidden) {
572574
return
573575
}
@@ -721,53 +723,18 @@ class MainActivity : AppCompatActivity() {
721723
fun onKey(keyCode: Int): Boolean {
722724
Log.d(TAG, "keyCode $keyCode")
723725
when (keyCode) {
724-
KeyEvent.KEYCODE_0 -> {
725-
showChannel("0")
726-
return true
727-
}
728-
729-
KeyEvent.KEYCODE_1 -> {
730-
showChannel("1")
731-
return true
732-
}
733-
734-
KeyEvent.KEYCODE_2 -> {
735-
showChannel("2")
736-
return true
737-
}
738-
739-
KeyEvent.KEYCODE_3 -> {
740-
showChannel("3")
741-
return true
742-
}
743-
744-
KeyEvent.KEYCODE_4 -> {
745-
showChannel("4")
746-
return true
747-
}
748-
749-
KeyEvent.KEYCODE_5 -> {
750-
showChannel("5")
751-
return true
752-
}
753-
754-
KeyEvent.KEYCODE_6 -> {
755-
showChannel("6")
756-
return true
757-
}
758-
759-
KeyEvent.KEYCODE_7 -> {
760-
showChannel("7")
761-
return true
762-
}
763-
764-
KeyEvent.KEYCODE_8 -> {
765-
showChannel("8")
766-
return true
767-
}
768-
769-
KeyEvent.KEYCODE_9 -> {
770-
showChannel("9")
726+
KeyEvent.KEYCODE_0,
727+
KeyEvent.KEYCODE_1,
728+
KeyEvent.KEYCODE_2,
729+
KeyEvent.KEYCODE_3,
730+
KeyEvent.KEYCODE_4,
731+
KeyEvent.KEYCODE_5,
732+
KeyEvent.KEYCODE_6,
733+
KeyEvent.KEYCODE_7,
734+
KeyEvent.KEYCODE_8,
735+
KeyEvent.KEYCODE_9,
736+
-> {
737+
showChannel(keyCode - 7)
771738
return true
772739
}
773740

@@ -807,10 +774,20 @@ class MainActivity : AppCompatActivity() {
807774
}
808775

809776
KeyEvent.KEYCODE_ENTER -> {
777+
if (channelFragment.isAdded && channelFragment.isVisible) {
778+
channelFragment.playNow()
779+
return true
780+
}
781+
810782
showFragment(menuFragment)
811783
}
812784

813785
KeyEvent.KEYCODE_DPAD_CENTER -> {
786+
if (channelFragment.isAdded && channelFragment.isVisible) {
787+
channelFragment.playNow()
788+
return true
789+
}
790+
814791
showFragment(menuFragment)
815792
}
816793

app/src/main/java/com/lizongying/mytv0/SimpleServer.kt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -104,11 +104,11 @@ class SimpleServer(private val context: Context, private val viewModel: MainView
104104

105105
var sources = ""
106106
var success = false
107-
for (a in urls) {
108-
Log.i(TAG, "request $a")
107+
for (u in urls) {
108+
Log.i(TAG, "request $u")
109109
withContext(Dispatchers.IO) {
110110
try {
111-
val request = okhttp3.Request.Builder().url(a).build()
111+
val request = okhttp3.Request.Builder().url(u).build()
112112
val response = HttpClient.okHttpClient.newCall(request).execute()
113113

114114
if (response.isSuccessful) {

app/src/main/java/com/lizongying/mytv0/UpdateManager.kt

Lines changed: 26 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import android.os.Handler
1414
import android.os.Looper
1515
import android.util.Log
1616
import androidx.fragment.app.FragmentActivity
17+
import com.lizongying.mytv0.Utils.getUrls
1718
import com.lizongying.mytv0.data.Global.gson
1819
import com.lizongying.mytv0.data.ReleaseResponse
1920
import com.lizongying.mytv0.requests.HttpClient
@@ -31,28 +32,36 @@ class UpdateManager(
3132
ConfirmationFragment.ConfirmationListener {
3233

3334
private var downloadReceiver: DownloadReceiver? = null
34-
private var release: ReleaseResponse? = null
35+
var release: ReleaseResponse? = null
3536

3637
private suspend fun getRelease(): ReleaseResponse? {
37-
return withContext(Dispatchers.IO) {
38-
try {
39-
val request = okhttp3.Request.Builder()
40-
.url(VERSION_URL)
41-
.build()
42-
43-
HttpClient.okHttpClient.newCall(request).execute().use { response ->
44-
if (!response.isSuccessful) return@withContext null
45-
46-
response.bodyAlias()?.let {
47-
return@withContext gson.fromJson(it.string(), ReleaseResponse::class.java)
38+
val urls = getUrls(VERSION_URL)
39+
40+
for (u in urls) {
41+
Log.i(TAG, "request $u")
42+
withContext(Dispatchers.IO) {
43+
try {
44+
val request = okhttp3.Request.Builder().url(u).build()
45+
val response = HttpClient.okHttpClient.newCall(request).execute()
46+
47+
if (response.isSuccessful) {
48+
response.bodyAlias()?.let {
49+
return@withContext gson.fromJson(
50+
it.string(),
51+
ReleaseResponse::class.java
52+
)
53+
}
54+
} else {
55+
Log.e(TAG, "getRelease $u ${response.codeAlias()}")
4856
}
49-
null
57+
} catch (e: Exception) {
58+
// Log.e(TAG, "getRelease $u error", e)
59+
Log.e(TAG, "getRelease $u error")
5060
}
51-
} catch (e: Exception) {
52-
Log.e(TAG, "getRelease", e)
53-
null
5461
}
5562
}
63+
64+
return null
5665
}
5766

5867
fun checkAndUpdate() {
@@ -246,7 +255,7 @@ class UpdateManager(
246255
private const val TAG = "UpdateManager"
247256
private const val BUFFER_SIZE = 8192
248257
private const val VERSION_URL =
249-
"https://mirror.ghproxy.com/raw.githubusercontent.com/lizongying/my-tv-0/main/version.json"
258+
"https://raw.githubusercontent.com/lizongying/my-tv-0/main/version.json"
250259
}
251260

252261
override fun onConfirm() {

app/src/main/java/com/lizongying/mytv0/Utils.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -177,6 +177,7 @@ object Utils {
177177
"https://www.ghproxy.cc/",
178178
"https://cf.ghproxy.cc/",
179179
"https://ghp.ci/",
180+
"https://ghfast.top"
180181
).map {
181182
"$it$url"
182183
}

0 commit comments

Comments
 (0)