mirror of
https://github.com/lizongying/my-tv.git
synced 2026-10-26 14:16:29 +08:00
optimize time
This commit is contained in:
+7
-2
@@ -1,5 +1,10 @@
|
|||||||
## 更新日志
|
## 更新日志
|
||||||
|
|
||||||
|
### v1.9.8(通用)
|
||||||
|
|
||||||
|
* 优化在线升级
|
||||||
|
* 优化可能状态错误的问题
|
||||||
|
|
||||||
### v1.9.6(通用)
|
### v1.9.6(通用)
|
||||||
|
|
||||||
* 优化在线升级
|
* 优化在线升级
|
||||||
@@ -41,6 +46,8 @@
|
|||||||
|
|
||||||
* 修复无法播放问题
|
* 修复无法播放问题
|
||||||
|
|
||||||
|
### 以下已不可用
|
||||||
|
|
||||||
### v1.8.0(通用)
|
### v1.8.0(通用)
|
||||||
|
|
||||||
* 修复返回键无法退出问题
|
* 修复返回键无法退出问题
|
||||||
@@ -176,8 +183,6 @@
|
|||||||
|
|
||||||
* 修复播放失败的问题
|
* 修复播放失败的问题
|
||||||
|
|
||||||
### 以下已不可用
|
|
||||||
|
|
||||||
### v1.5.3(安卓5及以上专用)
|
### v1.5.3(安卓5及以上专用)
|
||||||
|
|
||||||
* 修复部分情况下APP切换后无法继续播放的问题
|
* 修复部分情况下APP切换后无法继续播放的问题
|
||||||
|
|||||||
@@ -1,11 +1,16 @@
|
|||||||
package com.lizongying.mytv
|
package com.lizongying.mytv
|
||||||
|
|
||||||
|
import android.Manifest
|
||||||
|
import android.content.pm.PackageManager
|
||||||
import android.os.Build
|
import android.os.Build
|
||||||
import android.os.Bundle
|
import android.os.Bundle
|
||||||
import android.view.LayoutInflater
|
import android.view.LayoutInflater
|
||||||
import android.view.View
|
import android.view.View
|
||||||
import android.view.ViewGroup
|
import android.view.ViewGroup
|
||||||
import android.view.WindowManager
|
import android.view.WindowManager
|
||||||
|
import android.widget.Toast
|
||||||
|
import androidx.core.app.ActivityCompat
|
||||||
|
import androidx.core.content.ContextCompat
|
||||||
import androidx.core.view.marginEnd
|
import androidx.core.view.marginEnd
|
||||||
import androidx.core.view.marginTop
|
import androidx.core.view.marginTop
|
||||||
import androidx.fragment.app.DialogFragment
|
import androidx.fragment.app.DialogFragment
|
||||||
@@ -87,13 +92,10 @@ class SettingFragment : DialogFragment() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
updateManager = UpdateManager(context, context.appVersionCode)
|
binding.checkVersion.setOnClickListener {
|
||||||
binding.checkVersion.setOnClickListener(
|
(activity as MainActivity).settingDelayHide()
|
||||||
OnClickListenerCheckVersion(
|
requestInstallPermissions()
|
||||||
activity as MainActivity,
|
}
|
||||||
updateManager
|
|
||||||
)
|
|
||||||
)
|
|
||||||
|
|
||||||
val application = requireActivity().applicationContext as MyTvApplication
|
val application = requireActivity().applicationContext as MyTvApplication
|
||||||
|
|
||||||
@@ -162,20 +164,63 @@ class SettingFragment : DialogFragment() {
|
|||||||
return binding.root
|
return binding.root
|
||||||
}
|
}
|
||||||
|
|
||||||
fun setVersionName(versionName: String) {
|
private fun requestInstallPermissions() {
|
||||||
if (_binding != null) {
|
val context = requireContext()
|
||||||
binding.versionName.text = versionName
|
val permissionsList: MutableList<String> = ArrayList()
|
||||||
|
|
||||||
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O && !context.packageManager.canRequestPackageInstalls()) {
|
||||||
|
permissionsList.add(Manifest.permission.REQUEST_INSTALL_PACKAGES)
|
||||||
|
}
|
||||||
|
|
||||||
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M &&
|
||||||
|
ContextCompat.checkSelfPermission(
|
||||||
|
context,
|
||||||
|
Manifest.permission.READ_EXTERNAL_STORAGE
|
||||||
|
) != PackageManager.PERMISSION_GRANTED
|
||||||
|
) {
|
||||||
|
permissionsList.add(Manifest.permission.READ_EXTERNAL_STORAGE)
|
||||||
|
}
|
||||||
|
|
||||||
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M &&
|
||||||
|
ContextCompat.checkSelfPermission(
|
||||||
|
context,
|
||||||
|
Manifest.permission.WRITE_EXTERNAL_STORAGE
|
||||||
|
) != PackageManager.PERMISSION_GRANTED
|
||||||
|
) {
|
||||||
|
permissionsList.add(Manifest.permission.WRITE_EXTERNAL_STORAGE)
|
||||||
|
}
|
||||||
|
|
||||||
|
if (permissionsList.isNotEmpty()) {
|
||||||
|
ActivityCompat.requestPermissions(
|
||||||
|
requireActivity(),
|
||||||
|
permissionsList.toTypedArray<String>(),
|
||||||
|
PERMISSIONS_REQUEST_CODE
|
||||||
|
)
|
||||||
|
} else {
|
||||||
|
UpdateManager(context, context.appVersionCode).checkAndUpdate()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
internal class OnClickListenerCheckVersion(
|
override fun onRequestPermissionsResult(
|
||||||
private val mainActivity: MainActivity,
|
requestCode: Int,
|
||||||
private val updateManager: UpdateManager
|
permissions: Array<out String>,
|
||||||
) :
|
grantResults: IntArray
|
||||||
View.OnClickListener {
|
) {
|
||||||
override fun onClick(view: View?) {
|
super.onRequestPermissionsResult(requestCode, permissions, grantResults)
|
||||||
mainActivity.settingDelayHide()
|
if (requestCode == PERMISSIONS_REQUEST_CODE) {
|
||||||
updateManager.checkAndUpdate()
|
var allPermissionsGranted = true
|
||||||
|
for (result in grantResults) {
|
||||||
|
if (result != PackageManager.PERMISSION_GRANTED) {
|
||||||
|
allPermissionsGranted = false
|
||||||
|
break
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (allPermissionsGranted) {
|
||||||
|
val context = requireContext()
|
||||||
|
UpdateManager(context, context.appVersionCode).checkAndUpdate()
|
||||||
|
} else {
|
||||||
|
Toast.makeText(context, "权限授权失败", Toast.LENGTH_LONG).show()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -186,6 +231,7 @@ class SettingFragment : DialogFragment() {
|
|||||||
|
|
||||||
companion object {
|
companion object {
|
||||||
const val TAG = "SettingFragment"
|
const val TAG = "SettingFragment"
|
||||||
|
const val PERMISSIONS_REQUEST_CODE = 1
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,6 +1,5 @@
|
|||||||
package com.lizongying.mytv
|
package com.lizongying.mytv
|
||||||
|
|
||||||
import android.app.Activity
|
|
||||||
import android.app.DownloadManager
|
import android.app.DownloadManager
|
||||||
import android.app.DownloadManager.Request
|
import android.app.DownloadManager.Request
|
||||||
import android.content.BroadcastReceiver
|
import android.content.BroadcastReceiver
|
||||||
@@ -14,9 +13,6 @@ import android.os.Environment
|
|||||||
import android.os.Handler
|
import android.os.Handler
|
||||||
import android.os.Looper
|
import android.os.Looper
|
||||||
import android.util.Log
|
import android.util.Log
|
||||||
import androidx.core.app.ActivityCompat
|
|
||||||
import androidx.core.content.PermissionChecker
|
|
||||||
import androidx.core.content.PermissionChecker.checkSelfPermission
|
|
||||||
import androidx.fragment.app.FragmentActivity
|
import androidx.fragment.app.FragmentActivity
|
||||||
import com.lizongying.mytv.api.ApiClient
|
import com.lizongying.mytv.api.ApiClient
|
||||||
import com.lizongying.mytv.requests.ReleaseRequest
|
import com.lizongying.mytv.requests.ReleaseRequest
|
||||||
@@ -39,9 +35,6 @@ class UpdateManager(
|
|||||||
private var downloadReceiver: DownloadReceiver? = null
|
private var downloadReceiver: DownloadReceiver? = null
|
||||||
|
|
||||||
fun checkAndUpdate() {
|
fun checkAndUpdate() {
|
||||||
if (!haveStoragePermission()) {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
CoroutineScope(Dispatchers.Main).launch {
|
CoroutineScope(Dispatchers.Main).launch {
|
||||||
var text = "版本获取失败"
|
var text = "版本获取失败"
|
||||||
var update = false
|
var update = false
|
||||||
@@ -68,36 +61,7 @@ class UpdateManager(
|
|||||||
dialog.show((context as FragmentActivity).supportFragmentManager, TAG)
|
dialog.show((context as FragmentActivity).supportFragmentManager, TAG)
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun haveStoragePermission(): Boolean {
|
|
||||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
|
|
||||||
if (checkSelfPermission(context, android.Manifest.permission.WRITE_EXTERNAL_STORAGE)
|
|
||||||
=== PermissionChecker.PERMISSION_GRANTED
|
|
||||||
) {
|
|
||||||
Log.e("Permission error", "You have permission")
|
|
||||||
return true
|
|
||||||
} else {
|
|
||||||
Log.e("Permission error", "You have asked for permission")
|
|
||||||
ActivityCompat.requestPermissions(
|
|
||||||
context as Activity, arrayOf(
|
|
||||||
android.Manifest.permission.WRITE_EXTERNAL_STORAGE
|
|
||||||
), 1
|
|
||||||
)
|
|
||||||
return false
|
|
||||||
}
|
|
||||||
} else { //you don't need to worry about these stuff below api level 23
|
|
||||||
Log.e("Permission error", "You already have the permission")
|
|
||||||
return true
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
private fun startDownload(release: ReleaseResponse) {
|
private fun startDownload(release: ReleaseResponse) {
|
||||||
val packageInstaller = context.packageManager
|
|
||||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
|
|
||||||
if (!packageInstaller.canRequestPackageInstalls()) {
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
val apkName = "my-tv"
|
val apkName = "my-tv"
|
||||||
val apkFileName = "$apkName-${release.version_name}.apk"
|
val apkFileName = "$apkName-${release.version_name}.apk"
|
||||||
Log.i(TAG, "apkFileName $apkFileName")
|
Log.i(TAG, "apkFileName $apkFileName")
|
||||||
|
|||||||
@@ -2,7 +2,6 @@ package com.lizongying.mytv
|
|||||||
|
|
||||||
import android.content.res.Resources
|
import android.content.res.Resources
|
||||||
import android.os.Build
|
import android.os.Build
|
||||||
import android.util.Log
|
|
||||||
import android.util.TypedValue
|
import android.util.TypedValue
|
||||||
import com.google.gson.Gson
|
import com.google.gson.Gson
|
||||||
import com.lizongying.mytv.api.TimeResponse
|
import com.lizongying.mytv.api.TimeResponse
|
||||||
@@ -37,13 +36,14 @@ object Utils {
|
|||||||
}
|
}
|
||||||
|
|
||||||
suspend fun init() {
|
suspend fun init() {
|
||||||
var currentTimeMillis: Long = 0
|
|
||||||
try {
|
try {
|
||||||
currentTimeMillis = getTimestampFromServer()
|
val currentTimeMillis = getTimestampFromServer()
|
||||||
|
if (currentTimeMillis > 0) {
|
||||||
|
between = System.currentTimeMillis() - currentTimeMillis
|
||||||
|
}
|
||||||
} catch (e: Exception) {
|
} catch (e: Exception) {
|
||||||
println("Failed to retrieve timestamp from server: ${e.message}")
|
println("Failed to retrieve timestamp from server: ${e.message}")
|
||||||
}
|
}
|
||||||
between = System.currentTimeMillis() - currentTimeMillis
|
|
||||||
|
|
||||||
withContext(Dispatchers.Main) {
|
withContext(Dispatchers.Main) {
|
||||||
listener?.onRequestFinished(null)
|
listener?.onRequestFinished(null)
|
||||||
@@ -71,8 +71,6 @@ object Utils {
|
|||||||
private suspend fun getTimestampFromServer(): Long {
|
private suspend fun getTimestampFromServer(): Long {
|
||||||
return withContext(Dispatchers.IO) {
|
return withContext(Dispatchers.IO) {
|
||||||
val client = okhttp3.OkHttpClient.Builder()
|
val client = okhttp3.OkHttpClient.Builder()
|
||||||
.connectTimeout(500, java.util.concurrent.TimeUnit.MILLISECONDS)
|
|
||||||
.readTimeout(1, java.util.concurrent.TimeUnit.SECONDS)
|
|
||||||
.addInterceptor(RetryInterceptor(3))
|
.addInterceptor(RetryInterceptor(3))
|
||||||
.build()
|
.build()
|
||||||
val request = okhttp3.Request.Builder()
|
val request = okhttp3.Request.Builder()
|
||||||
@@ -85,7 +83,6 @@ object Utils {
|
|||||||
Gson().fromJson(string, TimeResponse::class.java).data.t.toLong()
|
Gson().fromJson(string, TimeResponse::class.java).data.t.toLong()
|
||||||
}
|
}
|
||||||
} catch (e: IOException) {
|
} catch (e: IOException) {
|
||||||
// Handle network errors
|
|
||||||
throw IOException("Error during network request", e)
|
throw IOException("Error during network request", e)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+1
-1
@@ -1 +1 @@
|
|||||||
{"version_code": 17368576, "version_name": "v1.9.6"}
|
{"version_code": 17369088, "version_name": "v1.9.8"}
|
||||||
|
|||||||
Reference in New Issue
Block a user