Skip to content

Commit 7b0e144

Browse files
committed
fix update manager
1 parent 06b8df5 commit 7b0e144

File tree

21 files changed

+275
-236
lines changed

21 files changed

+275
-236
lines changed

README.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,17 @@
1414

1515
## 更新日志
1616

17+
### v1.6.6(通用)
18+
19+
* 更新重庆卫视图标
20+
* 凤凰卫视增强画质
21+
* 凤凰卫视增加EPG
22+
23+
### v1.6.5(安卓5及以上专用)
24+
25+
* 增加CETV1图标
26+
* 稳定性提升
27+
1728
### v1.6.4(通用)
1829

1930
* 增加CETV1
@@ -222,6 +233,7 @@ adb install my-tv.apk
222233
* 节目增加预告
223234
* 频道列表优化
224235
* 自动更新
236+
* 時間
225237

226238
## 赞赏
227239

app/build.gradle

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ android {
5454
}
5555

5656
kotlinOptions {
57-
jvmTarget=17
57+
jvmTarget = 17
5858
}
5959

6060
// Encapsulates your external native build configurations.
@@ -71,17 +71,22 @@ android {
7171

7272
static def VersionCode() {
7373
try {
74-
def process = 'git rev-list --count HEAD'.execute()
74+
def p = "git describe --tags --always"
75+
def process = p.execute()
7576
process.waitFor()
76-
return process.text.toInteger()
77+
def replace = [v: "", ".": " ", "-": " "]
78+
def arr = (process.text.trim().replace(replace) + " 0").split(" ")
79+
def versionCode = arr[0].toInteger() * 16777216 + arr[1].toInteger() * 65536 + arr[2].toInteger() * 256 + arr[3].toInteger()
80+
println("VersionCode $versionCode")
81+
return versionCode
7782
} catch (ignored) {
7883
return 0
7984
}
8085
}
8186

8287
static def VersionName() {
8388
try {
84-
def process = 'git describe --tags --always'.execute()
89+
def process = "git describe --tags --always".execute()
8590
process.waitFor()
8691
return process.text.trim() - "v"
8792
} catch (ignored) {

app/src/main/AndroidManifest.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
android:name="android.software.leanback"
88
android:required="true" />
99
<uses-permission android:name="android.permission.INTERNET" />
10+
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
1011
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
1112
<application
1213
android:allowBackup="true"
2.01 KB
Binary file not shown.
284 Bytes
Binary file not shown.

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

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,7 @@ import android.view.View.SYSTEM_UI_FLAG_HIDE_NAVIGATION
1111
import android.view.WindowManager
1212
import android.widget.Toast
1313
import androidx.fragment.app.FragmentActivity
14-
import androidx.lifecycle.lifecycleScope
1514
import com.lizongying.mytv.models.TVViewModel
16-
import kotlinx.coroutines.CoroutineStart
17-
import kotlinx.coroutines.Dispatchers
18-
import kotlinx.coroutines.async
19-
import kotlinx.coroutines.launch
2015

2116

2217
class MainActivity : FragmentActivity(), Request.RequestListener {
@@ -39,6 +34,7 @@ class MainActivity : FragmentActivity(), Request.RequestListener {
3934
override fun onCreate(savedInstanceState: Bundle?) {
4035
Log.i(TAG, "onCreate")
4136
super.onCreate(savedInstanceState)
37+
4238
setContentView(R.layout.activity_main)
4339

4440
Request.onCreate()
@@ -165,11 +161,15 @@ class MainActivity : FragmentActivity(), Request.RequestListener {
165161
private inner class GestureListener : GestureDetector.SimpleOnGestureListener() {
166162

167163
override fun onSingleTapConfirmed(e: MotionEvent): Boolean {
168-
Log.i(TAG, "onSingleTapConfirmed")
169164
switchMainFragment()
170165
return true
171166
}
172167

168+
override fun onDoubleTap(e: MotionEvent): Boolean {
169+
showSetting()
170+
return true
171+
}
172+
173173
override fun onFling(
174174
e1: MotionEvent?,
175175
e2: MotionEvent,

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

Lines changed: 45 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -72,14 +72,14 @@ object Request {
7272
private var call: Call<LiveInfo>? = null
7373
private var callAuth: Call<Auth>? = null
7474
private var callInfo: Call<Info>? = null
75-
private var fAuth: Call<FAuth>? = null
75+
private var callFAuth: Call<FAuth>? = null
7676
private var callPage: Call<pageModel.Response>? = null
7777

7878
private fun cancelCall() {
7979
call?.cancel()
8080
callAuth?.cancel()
8181
callInfo?.cancel()
82-
fAuth?.cancel()
82+
callFAuth?.cancel()
8383
callPage?.cancel()
8484
}
8585

@@ -91,7 +91,6 @@ object Request {
9191
val data = YSP.getAuthData(tvModel)
9292
val request = AuthRequest(data)
9393
callAuth = request.let { yspApiService.getAuth("guid=${YSP.getGuid()}; $cookie", it) }
94-
9594
callAuth?.enqueue(object : Callback<Auth> {
9695
override fun onResponse(call: Call<Auth>, response: Response<Auth>) {
9796
if (response.isSuccessful) {
@@ -106,12 +105,12 @@ object Request {
106105
if (tvModel.retryTimes < tvModel.retryMaxTimes) {
107106
tvModel.retryTimes++
108107
if (tvModel.getTV().needToken) {
109-
if (tvModel.tokenRetryTimes == tvModel.tokenRetryMaxTimes) {
108+
if (tvModel.tokenYSPRetryTimes == tvModel.tokenYSPRetryMaxTimes) {
110109
if (!tvModel.getTV().mustToken) {
111110
fetchAuth(tvModel, cookie)
112111
}
113112
} else {
114-
token = ""
113+
tvModel.needGetToken = true
115114
fetchAuth(tvModel)
116115
}
117116
} else {
@@ -124,12 +123,12 @@ object Request {
124123
if (tvModel.retryTimes < tvModel.retryMaxTimes) {
125124
tvModel.retryTimes++
126125
if (tvModel.getTV().needToken) {
127-
if (tvModel.tokenRetryTimes == tvModel.tokenRetryMaxTimes) {
126+
if (tvModel.tokenYSPRetryTimes == tvModel.tokenYSPRetryMaxTimes) {
128127
if (!tvModel.getTV().mustToken) {
129128
fetchAuth(tvModel, cookie)
130129
}
131130
} else {
132-
token = ""
131+
tvModel.needGetToken = true
133132
fetchAuth(tvModel)
134133
}
135134
} else {
@@ -144,12 +143,12 @@ object Request {
144143
if (tvModel.retryTimes < tvModel.retryMaxTimes) {
145144
tvModel.retryTimes++
146145
if (tvModel.getTV().needToken) {
147-
if (tvModel.tokenRetryTimes == tvModel.tokenRetryMaxTimes) {
146+
if (tvModel.tokenYSPRetryTimes == tvModel.tokenYSPRetryMaxTimes) {
148147
if (!tvModel.getTV().mustToken) {
149148
fetchAuth(tvModel, cookie)
150149
}
151150
} else {
152-
token = ""
151+
tvModel.needGetToken = true
153152
fetchAuth(tvModel)
154153
}
155154
} else {
@@ -212,13 +211,13 @@ object Request {
212211
if (tvModel.retryTimes < tvModel.retryMaxTimes) {
213212
tvModel.retryTimes++
214213
if (tvModel.getTV().needToken) {
215-
if (tvModel.tokenRetryTimes == tvModel.tokenRetryMaxTimes) {
214+
if (tvModel.tokenYSPRetryTimes == tvModel.tokenYSPRetryMaxTimes) {
216215
if (!tvModel.getTV().mustToken) {
217216
fetchVideo(tvModel, cookie)
218217
// fetchAuth(tvModel, cookie)
219218
}
220219
} else {
221-
token = ""
220+
tvModel.needGetToken = true
222221
fetchVideo(tvModel)
223222
// fetchAuth(tvModel)
224223
}
@@ -237,13 +236,13 @@ object Request {
237236
if (tvModel.retryTimes < tvModel.retryMaxTimes) {
238237
tvModel.retryTimes++
239238
if (tvModel.getTV().needToken) {
240-
if (tvModel.tokenRetryTimes == tvModel.tokenRetryMaxTimes) {
239+
if (tvModel.tokenYSPRetryTimes == tvModel.tokenYSPRetryMaxTimes) {
241240
if (!tvModel.getTV().mustToken) {
242241
fetchVideo(tvModel, cookie)
243242
// fetchAuth(tvModel, cookie)
244243
}
245244
} else {
246-
token = ""
245+
tvModel.needGetToken = true
247246
fetchVideo(tvModel)
248247
// fetchAuth(tvModel)
249248
}
@@ -259,13 +258,13 @@ object Request {
259258
if (tvModel.retryTimes < tvModel.retryMaxTimes) {
260259
tvModel.retryTimes++
261260
if (tvModel.getTV().needToken) {
262-
if (tvModel.tokenRetryTimes == tvModel.tokenRetryMaxTimes) {
261+
if (tvModel.tokenYSPRetryTimes == tvModel.tokenYSPRetryMaxTimes) {
263262
if (!tvModel.getTV().mustToken) {
264263
fetchVideo(tvModel, cookie)
265264
// fetchAuth(tvModel, cookie)
266265
}
267266
} else {
268-
token = ""
267+
tvModel.needGetToken = true
269268
fetchVideo(tvModel)
270269
// fetchAuth(tvModel)
271270
}
@@ -282,12 +281,12 @@ object Request {
282281
if (tvModel.retryTimes < tvModel.retryMaxTimes) {
283282
tvModel.retryTimes++
284283
if (tvModel.getTV().needToken) {
285-
if (tvModel.tokenRetryTimes == tvModel.tokenRetryMaxTimes) {
284+
if (tvModel.tokenYSPRetryTimes == tvModel.tokenYSPRetryMaxTimes) {
286285
if (!tvModel.getTV().mustToken) {
287286
fetchVideo(tvModel, cookie)
288287
}
289288
} else {
290-
token = ""
289+
tvModel.needGetToken = true
291290
fetchVideo(tvModel)
292291
}
293292
} else {
@@ -300,20 +299,28 @@ object Request {
300299

301300
private fun fetchAuth(tvModel: TVViewModel) {
302301
cancelCall()
303-
if (token == "") {
302+
if (tvModel.needGetToken) {
304303
callInfo = yspTokenService.getInfo("")
305304
callInfo?.enqueue(object : Callback<Info> {
306305
override fun onResponse(call: Call<Info>, response: Response<Info>) {
307-
if (response.isSuccessful) {
306+
if (response.isSuccessful && response.body()?.data?.token != null) {
308307
token = response.body()?.data?.token!!
309308
Log.i(TAG, "info success $token")
309+
tvModel.needGetToken = false
310+
tvModel.tokenYSPRetryTimes = 0
310311
val cookie =
311312
"versionName=99.99.99; versionCode=999999; vplatform=109; platformVersion=Chrome; deviceModel=120; appid=1400421205; yspappid=519748109;yspopenid=vu0-8lgGV2LW9QjDeuBFsX8yMnzs37Q3_HZF6XyVDpGR_I; vusession=$token"
312313
fetchAuth(tvModel, cookie)
314+
} else if (response.code() == 304) {
315+
tvModel.needGetToken = false
316+
tvModel.tokenYSPRetryTimes = 0
317+
val cookie =
318+
"versionName=99.99.99; versionCode=999999; vplatform=109; platformVersion=Chrome; deviceModel=120; appid=1400421205; yspappid=519748109; yspopenid=vu0-8lgGV2LW9QjDeuBFsX8yMnzs37Q3_HZF6XyVDpGR_I; vusession=$token"
319+
fetchVideo(tvModel, cookie)
313320
} else {
314321
Log.e(TAG, "info status error")
315-
if (tvModel.tokenRetryTimes < tvModel.tokenRetryMaxTimes) {
316-
tvModel.tokenRetryTimes++
322+
if (tvModel.tokenYSPRetryTimes < tvModel.tokenYSPRetryMaxTimes) {
323+
tvModel.tokenYSPRetryTimes++
317324
fetchAuth(tvModel)
318325
} else {
319326
if (!tvModel.getTV().mustToken) {
@@ -327,8 +334,8 @@ object Request {
327334

328335
override fun onFailure(call: Call<Info>, t: Throwable) {
329336
Log.e(TAG, "info request error $t")
330-
if (tvModel.tokenRetryTimes < tvModel.tokenRetryMaxTimes) {
331-
tvModel.tokenRetryTimes++
337+
if (tvModel.tokenYSPRetryTimes < tvModel.tokenYSPRetryMaxTimes) {
338+
tvModel.tokenYSPRetryTimes++
332339
fetchVideo(tvModel)
333340
} else {
334341
if (!tvModel.getTV().mustToken) {
@@ -349,20 +356,28 @@ object Request {
349356
private fun fetchVideo(tvModel: TVViewModel) {
350357
cancelCall()
351358
Log.d(TAG, "fetchVideo")
352-
if (token == "") {
359+
if (tvModel.needGetToken) {
353360
callInfo = yspTokenService.getInfo("")
354361
callInfo?.enqueue(object : Callback<Info> {
355362
override fun onResponse(call: Call<Info>, response: Response<Info>) {
356363
if (response.isSuccessful && response.body()?.data?.token != null) {
357364
token = response.body()?.data?.token!!
358365
Log.i(TAG, "info success $token")
366+
tvModel.needGetToken = false
367+
tvModel.tokenYSPRetryTimes = 0
368+
val cookie =
369+
"versionName=99.99.99; versionCode=999999; vplatform=109; platformVersion=Chrome; deviceModel=120; appid=1400421205; yspappid=519748109; yspopenid=vu0-8lgGV2LW9QjDeuBFsX8yMnzs37Q3_HZF6XyVDpGR_I; vusession=$token"
370+
fetchVideo(tvModel, cookie)
371+
} else if (response.code() == 304) {
372+
tvModel.needGetToken = false
373+
tvModel.tokenYSPRetryTimes = 0
359374
val cookie =
360375
"versionName=99.99.99; versionCode=999999; vplatform=109; platformVersion=Chrome; deviceModel=120; appid=1400421205; yspappid=519748109; yspopenid=vu0-8lgGV2LW9QjDeuBFsX8yMnzs37Q3_HZF6XyVDpGR_I; vusession=$token"
361376
fetchVideo(tvModel, cookie)
362377
} else {
363378
Log.e(TAG, "info status error")
364-
if (tvModel.tokenRetryTimes < tvModel.tokenRetryMaxTimes) {
365-
tvModel.tokenRetryTimes++
379+
if (tvModel.tokenYSPRetryTimes < tvModel.tokenYSPRetryMaxTimes) {
380+
tvModel.tokenYSPRetryTimes++
366381
fetchVideo(tvModel)
367382
} else {
368383
if (!tvModel.getTV().mustToken) {
@@ -376,8 +391,8 @@ object Request {
376391

377392
override fun onFailure(call: Call<Info>, t: Throwable) {
378393
Log.e(TAG, "info request error $t")
379-
if (tvModel.tokenRetryTimes < tvModel.tokenRetryMaxTimes) {
380-
tvModel.tokenRetryTimes++
394+
if (tvModel.tokenYSPRetryTimes < tvModel.tokenYSPRetryMaxTimes) {
395+
tvModel.tokenYSPRetryTimes++
381396
fetchVideo(tvModel)
382397
} else {
383398
if (!tvModel.getTV().mustToken) {
@@ -405,8 +420,8 @@ object Request {
405420
qa = "FHD"
406421
}
407422

408-
fAuth = fAuthService.getAuth(tokenFH, tvModel.getTV().pid, qa)
409-
fAuth?.enqueue(object : Callback<FAuth> {
423+
callFAuth = fAuthService.getAuth(tokenFH, tvModel.getTV().pid, qa)
424+
callFAuth?.enqueue(object : Callback<FAuth> {
410425
override fun onResponse(call: Call<FAuth>, response: Response<FAuth>) {
411426
if (response.isSuccessful && response.body()?.data?.live_url != null) {
412427
val url = response.body()?.data?.live_url!!

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

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,19 @@ import android.content.SharedPreferences
66
object SP {
77
// Name of the sp file TODO Should use a meaningful name and do migrations
88
private const val SP_FILE_NAME = "MainActivity"
9+
910
// If Change channel with up and down in reversed order or not
1011
private const val KEY_CHANNEL_REVERSAL = "channel_reversal"
12+
1113
// If use channel num to select channel or not
1214
private const val KEY_CHANNEL_NUM = "channel_num"
15+
1316
// If start app on device boot or not
1417
private const val KEY_BOOT_STARTUP = "boot_startup"
18+
1519
// Position in list of the selected channel item
1620
private const val KEY_POSITION = "position"
21+
1722
// guid
1823
private const val KEY_GUID = "guid"
1924

@@ -43,6 +48,6 @@ object SP {
4348
set(value) = sp.edit().putInt(KEY_POSITION, value).apply()
4449

4550
var guid: String
46-
get() = sp.getString(KEY_GUID, "") ?: ""
51+
get() = sp.getString(KEY_GUID, "") ?: ""
4752
set(value) = sp.edit().putString(KEY_GUID, value).apply()
4853
}

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,8 @@ class SettingFragment : DialogFragment() {
2727
): View {
2828
val context = requireContext() // It‘s safe to get context here.
2929
_binding = DialogBinding.inflate(inflater, container, false)
30-
binding.version.text =
31-
"当前版本: ${context.appVersionName}\n获取最新: https://github.com/lizongying/my-tv/releases/"
30+
binding.versionName.text = "当前版本: v${context.appVersionName}"
31+
binding.version.text = "https://github.com/lizongying/my-tv"
3232

3333
binding.switchChannelReversal.run {
3434
isChecked = SP.channelReversal

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

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ data class TV(
77
var title: String,
88
var alias: String = "",
99
var videoUrl: List<String>,
10-
var videoIndex: Int = 0,
1110
var channel: String = "",
1211
var logo: Any = "",
1312
var pid: String = "",
@@ -23,7 +22,6 @@ data class TV(
2322
"id=" + id +
2423
", title='" + title + '\'' +
2524
", videoUrl='" + videoUrl + '\'' +
26-
", videoIndex='" + videoIndex + '\'' +
2725
", logo='" + logo + '\'' +
2826
", pid='" + pid + '\'' +
2927
", sid='" + sid + '\'' +

0 commit comments

Comments
 (0)