diff --git a/HISTORY.md b/HISTORY.md index 1f315a69..c900e660 100644 --- a/HISTORY.md +++ b/HISTORY.md @@ -1,5 +1,9 @@ ## 更新日誌 +### v2.1.2 + +* + ### v2.1.1 * 平衡聲音 diff --git a/app/src/main/cpp/arm64-v8a/libnative.so b/app/src/main/cpp/arm64-v8a/libnative.so index bd74dae2..5ffdfed7 100755 Binary files a/app/src/main/cpp/arm64-v8a/libnative.so and b/app/src/main/cpp/arm64-v8a/libnative.so differ diff --git a/app/src/main/cpp/armeabi-v7a/libnative.so b/app/src/main/cpp/armeabi-v7a/libnative.so index 25d7f928..75740082 100755 Binary files a/app/src/main/cpp/armeabi-v7a/libnative.so and b/app/src/main/cpp/armeabi-v7a/libnative.so differ diff --git a/app/src/main/java/com/lizongying/mytv/ConfirmationFragment.kt b/app/src/main/java/com/lizongying/mytv/ConfirmationFragment.kt index 5d929e53..6d6705a9 100644 --- a/app/src/main/java/com/lizongying/mytv/ConfirmationFragment.kt +++ b/app/src/main/java/com/lizongying/mytv/ConfirmationFragment.kt @@ -3,13 +3,37 @@ package com.lizongying.mytv import android.app.AlertDialog import android.app.Dialog import android.os.Bundle +import android.view.LayoutInflater +import android.view.View +import android.view.ViewGroup import androidx.fragment.app.DialogFragment +import com.lizongying.mytv.databinding.ConfirmationBinding class ConfirmationFragment( private val listener: ConfirmationListener, private val message: String, private val update: Boolean ) : DialogFragment() { +// +// private var _binding: ConfirmationBinding? = null +// private val binding get() = _binding!! +// +// override fun onCreateView( +// inflater: LayoutInflater, container: ViewGroup?, +// savedInstanceState: Bundle? +// ): View { +// _binding = ConfirmationBinding.inflate(inflater, container, false) +// return binding.root +// } +// +// fun updateProgress(progress: Int) { +// binding.progressBar.progress = progress +// } +// +// override fun onDestroyView() { +// super.onDestroyView() +// _binding = null +// } override fun onCreateDialog(savedInstanceState: Bundle?): Dialog { return activity?.let { diff --git a/app/src/main/java/com/lizongying/mytv/MyTVApplication.kt b/app/src/main/java/com/lizongying/mytv/MyTVApplication.kt index 4e82181b..9a8ecee0 100644 --- a/app/src/main/java/com/lizongying/mytv/MyTVApplication.kt +++ b/app/src/main/java/com/lizongying/mytv/MyTVApplication.kt @@ -5,7 +5,10 @@ import android.content.Context import android.content.res.Resources import android.util.DisplayMetrics import android.view.WindowManager +import androidx.lifecycle.ViewModelProvider +import androidx.lifecycle.ViewModelStore import androidx.multidex.MultiDex +import com.lizongying.mytv.models.MyViewModel class MyTVApplication : Application() { @@ -23,6 +26,8 @@ class MyTVApplication : Application() { private var density = 2.0f private var scale = 1.0f + lateinit var myViewModel: MyViewModel + override fun onCreate() { super.onCreate() @@ -60,6 +65,11 @@ class MyTVApplication : Application() { deviation = width - Resources.getSystem().displayMetrics.widthPixels scale = Resources.getSystem().displayMetrics.scaledDensity + + myViewModel = ViewModelProvider( + ViewModelStore(), + ViewModelProvider.NewInstanceFactory() + )[MyViewModel::class.java] } fun getDisplayMetrics(): DisplayMetrics { diff --git a/app/src/main/java/com/lizongying/mytv/SettingFragment.kt b/app/src/main/java/com/lizongying/mytv/SettingFragment.kt index 99618f97..61b715f5 100644 --- a/app/src/main/java/com/lizongying/mytv/SettingFragment.kt +++ b/app/src/main/java/com/lizongying/mytv/SettingFragment.kt @@ -6,11 +6,14 @@ import android.os.Build import android.os.Bundle import android.view.LayoutInflater import android.view.View +import android.view.View.GONE +import android.view.View.VISIBLE import android.view.ViewGroup import android.view.WindowManager import android.widget.Toast import androidx.core.app.ActivityCompat import androidx.core.content.ContextCompat +import androidx.core.view.isVisible import androidx.core.view.marginEnd import androidx.core.view.marginTop import androidx.fragment.app.DialogFragment @@ -159,6 +162,21 @@ class SettingFragment : DialogFragment() { requireActivity().finishAffinity() } +// val myViewModel = application.myViewModel +// application.myViewModel.downloadProgress.observe(viewLifecycleOwner) { _ -> +// val downloadProgress = myViewModel.downloadProgress.value +// if (downloadProgress != null) { +// if (downloadProgress == 100) { +// binding.progressBar.visibility = GONE +// } else { +// if (!binding.progressBar.isVisible) { +// binding.progressBar.visibility = VISIBLE +// } +// binding.progressBar.progress = downloadProgress +// } +// } +// } + updateManager = UpdateManager(context, context.appVersionCode) return binding.root diff --git a/app/src/main/java/com/lizongying/mytv/UpdateManager.kt b/app/src/main/java/com/lizongying/mytv/UpdateManager.kt index 77f3ede2..3d268627 100644 --- a/app/src/main/java/com/lizongying/mytv/UpdateManager.kt +++ b/app/src/main/java/com/lizongying/mytv/UpdateManager.kt @@ -31,7 +31,7 @@ class UpdateManager( release = releaseRequest.getRelease() val code = release?.version_code if (code != null) { - if (code.toLong() > versionCode) { + if (code.toLong() >= versionCode) { text = "最新版本:${release?.version_name}" update = true } else { diff --git a/app/src/main/java/com/lizongying/mytv/UpdateWorker.kt b/app/src/main/java/com/lizongying/mytv/UpdateWorker.kt index 72221ad9..4e3b5057 100644 --- a/app/src/main/java/com/lizongying/mytv/UpdateWorker.kt +++ b/app/src/main/java/com/lizongying/mytv/UpdateWorker.kt @@ -13,6 +13,7 @@ import androidx.core.app.NotificationCompat import androidx.core.content.FileProvider import androidx.work.CoroutineWorker import androidx.work.WorkerParameters +import com.lizongying.mytv.models.MyViewModel import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.withContext import java.io.File @@ -22,6 +23,8 @@ class UpdateWorker(context: Context, params: WorkerParameters) : CoroutineWorker private lateinit var notificationManager: NotificationManager private lateinit var notificationBuilder: NotificationCompat.Builder + private lateinit var myViewModel: MyViewModel + override suspend fun doWork(): Result { val downloadUrl = inputData.getString("DOWNLOAD_URL") ?: return Result.failure() val apkFileName = inputData.getString("APK_FILENAME") ?: return Result.failure() @@ -29,6 +32,9 @@ class UpdateWorker(context: Context, params: WorkerParameters) : CoroutineWorker showNotification(applicationContext) + val app = applicationContext as MyTVApplication + myViewModel = app.myViewModel + return withContext(Dispatchers.IO) { try { downloadAndInstall(applicationContext, downloadUrl, apkFileName, versionName) @@ -96,6 +102,8 @@ class UpdateWorker(context: Context, params: WorkerParameters) : CoroutineWorker if (bytesTotal > 0) { val progress = (bytesDownloaded * 100L / bytesTotal).toInt() + Log.i(TAG, "progress $progress") +// myViewModel.setDownloadProgress(progress) notificationBuilder.setProgress(100, progress, false) notificationManager.notify(1, notificationBuilder.build()) } diff --git a/app/src/main/java/com/lizongying/mytv/api/ApiClient.kt b/app/src/main/java/com/lizongying/mytv/api/ApiClient.kt index 4b196ea3..ec58f850 100644 --- a/app/src/main/java/com/lizongying/mytv/api/ApiClient.kt +++ b/app/src/main/java/com/lizongying/mytv/api/ApiClient.kt @@ -12,6 +12,8 @@ import okhttp3.TlsVersion import retrofit2.Retrofit import retrofit2.converter.gson.GsonConverterFactory import retrofit2.converter.protobuf.ProtoConverterFactory +import java.net.InetSocketAddress +import java.net.Proxy import javax.net.ssl.SSLContext import javax.net.ssl.TrustManager import javax.net.ssl.X509TrustManager @@ -166,7 +168,7 @@ class ApiClient { val sslContext = SSLContext.getInstance("SSL") sslContext.init(null, trustAllCerts, java.security.SecureRandom()) -// val proxy = Proxy(Proxy.Type.HTTP, InetSocketAddress("10.0.2.2", 8888)) + val proxy = Proxy(Proxy.Type.HTTP, InetSocketAddress("10.0.2.2", 8888)) val builder = OkHttpClient.Builder() .sslSocketFactory(sslContext.socketFactory, trustAllCerts[0] as X509TrustManager) diff --git a/app/src/main/java/com/lizongying/mytv/models/MyViewModel.kt b/app/src/main/java/com/lizongying/mytv/models/MyViewModel.kt new file mode 100644 index 00000000..168ac845 --- /dev/null +++ b/app/src/main/java/com/lizongying/mytv/models/MyViewModel.kt @@ -0,0 +1,19 @@ +package com.lizongying.mytv.models + +import androidx.lifecycle.LiveData +import androidx.lifecycle.MutableLiveData +import androidx.lifecycle.ViewModel + +class MyViewModel : ViewModel() { + private var _downloadProgress = MutableLiveData() + val downloadProgress: LiveData + get() = _downloadProgress + + fun setDownloadProgress(progress: Int) { + _downloadProgress.value = progress + } + + init { + _downloadProgress.value = 0 + } +} \ No newline at end of file diff --git a/app/src/main/res/layout/confirmation.xml b/app/src/main/res/layout/confirmation.xml new file mode 100644 index 00000000..f8cb67a0 --- /dev/null +++ b/app/src/main/res/layout/confirmation.xml @@ -0,0 +1,24 @@ + + + + + + diff --git a/app/src/main/res/layout/setting.xml b/app/src/main/res/layout/setting.xml index 2146a899..277da58e 100644 --- a/app/src/main/res/layout/setting.xml +++ b/app/src/main/res/layout/setting.xml @@ -59,6 +59,15 @@ android:layout_width="wrap_content" android:layout_height="wrap_content" /> + + + + + + + + +