Skip to content

Commit

Permalink
fix update manager
Browse files Browse the repository at this point in the history
  • Loading branch information
lizongying committed Mar 18, 2024
1 parent 06b8df5 commit 7b0e144
Show file tree
Hide file tree
Showing 21 changed files with 275 additions and 236 deletions.
12 changes: 12 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,17 @@

## 更新日志

### v1.6.6(通用)

* 更新重庆卫视图标
* 凤凰卫视增强画质
* 凤凰卫视增加EPG

### v1.6.5(安卓5及以上专用)

* 增加CETV1图标
* 稳定性提升

### v1.6.4(通用)

* 增加CETV1
Expand Down Expand Up @@ -222,6 +233,7 @@ adb install my-tv.apk
* 节目增加预告
* 频道列表优化
* 自动更新
* 時間

## 赞赏

Expand Down
13 changes: 9 additions & 4 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ android {
}

kotlinOptions {
jvmTarget=17
jvmTarget = 17
}

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

static def VersionCode() {
try {
def process = 'git rev-list --count HEAD'.execute()
def p = "git describe --tags --always"
def process = p.execute()
process.waitFor()
return process.text.toInteger()
def replace = [v: "", ".": " ", "-": " "]
def arr = (process.text.trim().replace(replace) + " 0").split(" ")
def versionCode = arr[0].toInteger() * 16777216 + arr[1].toInteger() * 65536 + arr[2].toInteger() * 256 + arr[3].toInteger()
println("VersionCode $versionCode")
return versionCode
} catch (ignored) {
return 0
}
}

static def VersionName() {
try {
def process = 'git describe --tags --always'.execute()
def process = "git describe --tags --always".execute()
process.waitFor()
return process.text.trim() - "v"
} catch (ignored) {
Expand Down
1 change: 1 addition & 0 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
android:name="android.software.leanback"
android:required="true" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
<application
android:allowBackup="true"
Expand Down
Binary file modified app/src/main/cpp/arm64-v8a/libnative.so
Binary file not shown.
Binary file modified app/src/main/cpp/armeabi-v7a/libnative.so
Binary file not shown.
12 changes: 6 additions & 6 deletions app/src/main/java/com/lizongying/mytv/MainActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,7 @@ import android.view.View.SYSTEM_UI_FLAG_HIDE_NAVIGATION
import android.view.WindowManager
import android.widget.Toast
import androidx.fragment.app.FragmentActivity
import androidx.lifecycle.lifecycleScope
import com.lizongying.mytv.models.TVViewModel
import kotlinx.coroutines.CoroutineStart
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.async
import kotlinx.coroutines.launch


class MainActivity : FragmentActivity(), Request.RequestListener {
Expand All @@ -39,6 +34,7 @@ class MainActivity : FragmentActivity(), Request.RequestListener {
override fun onCreate(savedInstanceState: Bundle?) {
Log.i(TAG, "onCreate")
super.onCreate(savedInstanceState)

setContentView(R.layout.activity_main)

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

override fun onSingleTapConfirmed(e: MotionEvent): Boolean {
Log.i(TAG, "onSingleTapConfirmed")
switchMainFragment()
return true
}

override fun onDoubleTap(e: MotionEvent): Boolean {
showSetting()
return true
}

override fun onFling(
e1: MotionEvent?,
e2: MotionEvent,
Expand Down
75 changes: 45 additions & 30 deletions app/src/main/java/com/lizongying/mytv/Request.kt
Original file line number Diff line number Diff line change
Expand Up @@ -72,14 +72,14 @@ object Request {
private var call: Call<LiveInfo>? = null
private var callAuth: Call<Auth>? = null
private var callInfo: Call<Info>? = null
private var fAuth: Call<FAuth>? = null
private var callFAuth: Call<FAuth>? = null
private var callPage: Call<pageModel.Response>? = null

private fun cancelCall() {
call?.cancel()
callAuth?.cancel()
callInfo?.cancel()
fAuth?.cancel()
callFAuth?.cancel()
callPage?.cancel()
}

Expand All @@ -91,7 +91,6 @@ object Request {
val data = YSP.getAuthData(tvModel)
val request = AuthRequest(data)
callAuth = request.let { yspApiService.getAuth("guid=${YSP.getGuid()}; $cookie", it) }

callAuth?.enqueue(object : Callback<Auth> {
override fun onResponse(call: Call<Auth>, response: Response<Auth>) {
if (response.isSuccessful) {
Expand All @@ -106,12 +105,12 @@ object Request {
if (tvModel.retryTimes < tvModel.retryMaxTimes) {
tvModel.retryTimes++
if (tvModel.getTV().needToken) {
if (tvModel.tokenRetryTimes == tvModel.tokenRetryMaxTimes) {
if (tvModel.tokenYSPRetryTimes == tvModel.tokenYSPRetryMaxTimes) {
if (!tvModel.getTV().mustToken) {
fetchAuth(tvModel, cookie)
}
} else {
token = ""
tvModel.needGetToken = true
fetchAuth(tvModel)
}
} else {
Expand All @@ -124,12 +123,12 @@ object Request {
if (tvModel.retryTimes < tvModel.retryMaxTimes) {
tvModel.retryTimes++
if (tvModel.getTV().needToken) {
if (tvModel.tokenRetryTimes == tvModel.tokenRetryMaxTimes) {
if (tvModel.tokenYSPRetryTimes == tvModel.tokenYSPRetryMaxTimes) {
if (!tvModel.getTV().mustToken) {
fetchAuth(tvModel, cookie)
}
} else {
token = ""
tvModel.needGetToken = true
fetchAuth(tvModel)
}
} else {
Expand All @@ -144,12 +143,12 @@ object Request {
if (tvModel.retryTimes < tvModel.retryMaxTimes) {
tvModel.retryTimes++
if (tvModel.getTV().needToken) {
if (tvModel.tokenRetryTimes == tvModel.tokenRetryMaxTimes) {
if (tvModel.tokenYSPRetryTimes == tvModel.tokenYSPRetryMaxTimes) {
if (!tvModel.getTV().mustToken) {
fetchAuth(tvModel, cookie)
}
} else {
token = ""
tvModel.needGetToken = true
fetchAuth(tvModel)
}
} else {
Expand Down Expand Up @@ -212,13 +211,13 @@ object Request {
if (tvModel.retryTimes < tvModel.retryMaxTimes) {
tvModel.retryTimes++
if (tvModel.getTV().needToken) {
if (tvModel.tokenRetryTimes == tvModel.tokenRetryMaxTimes) {
if (tvModel.tokenYSPRetryTimes == tvModel.tokenYSPRetryMaxTimes) {
if (!tvModel.getTV().mustToken) {
fetchVideo(tvModel, cookie)
// fetchAuth(tvModel, cookie)
}
} else {
token = ""
tvModel.needGetToken = true
fetchVideo(tvModel)
// fetchAuth(tvModel)
}
Expand All @@ -237,13 +236,13 @@ object Request {
if (tvModel.retryTimes < tvModel.retryMaxTimes) {
tvModel.retryTimes++
if (tvModel.getTV().needToken) {
if (tvModel.tokenRetryTimes == tvModel.tokenRetryMaxTimes) {
if (tvModel.tokenYSPRetryTimes == tvModel.tokenYSPRetryMaxTimes) {
if (!tvModel.getTV().mustToken) {
fetchVideo(tvModel, cookie)
// fetchAuth(tvModel, cookie)
}
} else {
token = ""
tvModel.needGetToken = true
fetchVideo(tvModel)
// fetchAuth(tvModel)
}
Expand All @@ -259,13 +258,13 @@ object Request {
if (tvModel.retryTimes < tvModel.retryMaxTimes) {
tvModel.retryTimes++
if (tvModel.getTV().needToken) {
if (tvModel.tokenRetryTimes == tvModel.tokenRetryMaxTimes) {
if (tvModel.tokenYSPRetryTimes == tvModel.tokenYSPRetryMaxTimes) {
if (!tvModel.getTV().mustToken) {
fetchVideo(tvModel, cookie)
// fetchAuth(tvModel, cookie)
}
} else {
token = ""
tvModel.needGetToken = true
fetchVideo(tvModel)
// fetchAuth(tvModel)
}
Expand All @@ -282,12 +281,12 @@ object Request {
if (tvModel.retryTimes < tvModel.retryMaxTimes) {
tvModel.retryTimes++
if (tvModel.getTV().needToken) {
if (tvModel.tokenRetryTimes == tvModel.tokenRetryMaxTimes) {
if (tvModel.tokenYSPRetryTimes == tvModel.tokenYSPRetryMaxTimes) {
if (!tvModel.getTV().mustToken) {
fetchVideo(tvModel, cookie)
}
} else {
token = ""
tvModel.needGetToken = true
fetchVideo(tvModel)
}
} else {
Expand All @@ -300,20 +299,28 @@ object Request {

private fun fetchAuth(tvModel: TVViewModel) {
cancelCall()
if (token == "") {
if (tvModel.needGetToken) {
callInfo = yspTokenService.getInfo("")
callInfo?.enqueue(object : Callback<Info> {
override fun onResponse(call: Call<Info>, response: Response<Info>) {
if (response.isSuccessful) {
if (response.isSuccessful && response.body()?.data?.token != null) {
token = response.body()?.data?.token!!
Log.i(TAG, "info success $token")
tvModel.needGetToken = false
tvModel.tokenYSPRetryTimes = 0
val cookie =
"versionName=99.99.99; versionCode=999999; vplatform=109; platformVersion=Chrome; deviceModel=120; appid=1400421205; yspappid=519748109;yspopenid=vu0-8lgGV2LW9QjDeuBFsX8yMnzs37Q3_HZF6XyVDpGR_I; vusession=$token"
fetchAuth(tvModel, cookie)
} else if (response.code() == 304) {
tvModel.needGetToken = false
tvModel.tokenYSPRetryTimes = 0
val cookie =
"versionName=99.99.99; versionCode=999999; vplatform=109; platformVersion=Chrome; deviceModel=120; appid=1400421205; yspappid=519748109; yspopenid=vu0-8lgGV2LW9QjDeuBFsX8yMnzs37Q3_HZF6XyVDpGR_I; vusession=$token"
fetchVideo(tvModel, cookie)
} else {
Log.e(TAG, "info status error")
if (tvModel.tokenRetryTimes < tvModel.tokenRetryMaxTimes) {
tvModel.tokenRetryTimes++
if (tvModel.tokenYSPRetryTimes < tvModel.tokenYSPRetryMaxTimes) {
tvModel.tokenYSPRetryTimes++
fetchAuth(tvModel)
} else {
if (!tvModel.getTV().mustToken) {
Expand All @@ -327,8 +334,8 @@ object Request {

override fun onFailure(call: Call<Info>, t: Throwable) {
Log.e(TAG, "info request error $t")
if (tvModel.tokenRetryTimes < tvModel.tokenRetryMaxTimes) {
tvModel.tokenRetryTimes++
if (tvModel.tokenYSPRetryTimes < tvModel.tokenYSPRetryMaxTimes) {
tvModel.tokenYSPRetryTimes++
fetchVideo(tvModel)
} else {
if (!tvModel.getTV().mustToken) {
Expand All @@ -349,20 +356,28 @@ object Request {
private fun fetchVideo(tvModel: TVViewModel) {
cancelCall()
Log.d(TAG, "fetchVideo")
if (token == "") {
if (tvModel.needGetToken) {
callInfo = yspTokenService.getInfo("")
callInfo?.enqueue(object : Callback<Info> {
override fun onResponse(call: Call<Info>, response: Response<Info>) {
if (response.isSuccessful && response.body()?.data?.token != null) {
token = response.body()?.data?.token!!
Log.i(TAG, "info success $token")
tvModel.needGetToken = false
tvModel.tokenYSPRetryTimes = 0
val cookie =
"versionName=99.99.99; versionCode=999999; vplatform=109; platformVersion=Chrome; deviceModel=120; appid=1400421205; yspappid=519748109; yspopenid=vu0-8lgGV2LW9QjDeuBFsX8yMnzs37Q3_HZF6XyVDpGR_I; vusession=$token"
fetchVideo(tvModel, cookie)
} else if (response.code() == 304) {
tvModel.needGetToken = false
tvModel.tokenYSPRetryTimes = 0
val cookie =
"versionName=99.99.99; versionCode=999999; vplatform=109; platformVersion=Chrome; deviceModel=120; appid=1400421205; yspappid=519748109; yspopenid=vu0-8lgGV2LW9QjDeuBFsX8yMnzs37Q3_HZF6XyVDpGR_I; vusession=$token"
fetchVideo(tvModel, cookie)
} else {
Log.e(TAG, "info status error")
if (tvModel.tokenRetryTimes < tvModel.tokenRetryMaxTimes) {
tvModel.tokenRetryTimes++
if (tvModel.tokenYSPRetryTimes < tvModel.tokenYSPRetryMaxTimes) {
tvModel.tokenYSPRetryTimes++
fetchVideo(tvModel)
} else {
if (!tvModel.getTV().mustToken) {
Expand All @@ -376,8 +391,8 @@ object Request {

override fun onFailure(call: Call<Info>, t: Throwable) {
Log.e(TAG, "info request error $t")
if (tvModel.tokenRetryTimes < tvModel.tokenRetryMaxTimes) {
tvModel.tokenRetryTimes++
if (tvModel.tokenYSPRetryTimes < tvModel.tokenYSPRetryMaxTimes) {
tvModel.tokenYSPRetryTimes++
fetchVideo(tvModel)
} else {
if (!tvModel.getTV().mustToken) {
Expand Down Expand Up @@ -405,8 +420,8 @@ object Request {
qa = "FHD"
}

fAuth = fAuthService.getAuth(tokenFH, tvModel.getTV().pid, qa)
fAuth?.enqueue(object : Callback<FAuth> {
callFAuth = fAuthService.getAuth(tokenFH, tvModel.getTV().pid, qa)
callFAuth?.enqueue(object : Callback<FAuth> {
override fun onResponse(call: Call<FAuth>, response: Response<FAuth>) {
if (response.isSuccessful && response.body()?.data?.live_url != null) {
val url = response.body()?.data?.live_url!!
Expand Down
7 changes: 6 additions & 1 deletion app/src/main/java/com/lizongying/mytv/SP.kt
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,19 @@ import android.content.SharedPreferences
object SP {
// Name of the sp file TODO Should use a meaningful name and do migrations
private const val SP_FILE_NAME = "MainActivity"

// If Change channel with up and down in reversed order or not
private const val KEY_CHANNEL_REVERSAL = "channel_reversal"

// If use channel num to select channel or not
private const val KEY_CHANNEL_NUM = "channel_num"

// If start app on device boot or not
private const val KEY_BOOT_STARTUP = "boot_startup"

// Position in list of the selected channel item
private const val KEY_POSITION = "position"

// guid
private const val KEY_GUID = "guid"

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

var guid: String
get() = sp.getString(KEY_GUID, "") ?: ""
get() = sp.getString(KEY_GUID, "") ?: ""
set(value) = sp.edit().putString(KEY_GUID, value).apply()
}
4 changes: 2 additions & 2 deletions app/src/main/java/com/lizongying/mytv/SettingFragment.kt
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@ class SettingFragment : DialogFragment() {
): View {
val context = requireContext() // It‘s safe to get context here.
_binding = DialogBinding.inflate(inflater, container, false)
binding.version.text =
"当前版本: ${context.appVersionName}\n获取最新: https://github.com/lizongying/my-tv/releases/"
binding.versionName.text = "当前版本: v${context.appVersionName}"
binding.version.text = "https://github.com/lizongying/my-tv"

binding.switchChannelReversal.run {
isChecked = SP.channelReversal
Expand Down
2 changes: 0 additions & 2 deletions app/src/main/java/com/lizongying/mytv/TV.kt
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ data class TV(
var title: String,
var alias: String = "",
var videoUrl: List<String>,
var videoIndex: Int = 0,
var channel: String = "",
var logo: Any = "",
var pid: String = "",
Expand All @@ -23,7 +22,6 @@ data class TV(
"id=" + id +
", title='" + title + '\'' +
", videoUrl='" + videoUrl + '\'' +
", videoIndex='" + videoIndex + '\'' +
", logo='" + logo + '\'' +
", pid='" + pid + '\'' +
", sid='" + sid + '\'' +
Expand Down
Loading

0 comments on commit 7b0e144

Please sign in to comment.