fixed app not updating when clicking the version nr in the settings

This commit is contained in:
deniscerri 2023-05-01 17:37:51 +02:00
parent 5edfe4be38
commit 167b35a077
No known key found for this signature in database
GPG key ID: 95C43D517D830350
5 changed files with 20 additions and 16 deletions

View file

@ -122,9 +122,9 @@ android {
dependencies { dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar']) implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation "com.github.JunkFood02.youtubedl-android:library:$youtubedlAndroidVer" implementation "com.github.yausername.youtubedl-android:library:$youtubedlAndroidVer"
implementation "com.github.JunkFood02.youtubedl-android:ffmpeg:$youtubedlAndroidVer" implementation "com.github.yausername.youtubedl-android:ffmpeg:$youtubedlAndroidVer"
implementation "com.github.JunkFood02.youtubedl-android:aria2c:$youtubedlAndroidVer" implementation "com.github.yausername.youtubedl-android:aria2c:$youtubedlAndroidVer"
implementation "androidx.appcompat:appcompat:$appCompatVer" implementation "androidx.appcompat:appcompat:$appCompatVer"
implementation "androidx.constraintlayout:constraintlayout:2.1.4" implementation "androidx.constraintlayout:constraintlayout:2.1.4"

View file

@ -260,7 +260,7 @@ class MainActivity : BaseActivity() {
if (preferences.getBoolean("update_app", false)) { if (preferences.getBoolean("update_app", false)) {
val updateUtil = UpdateUtil(this) val updateUtil = UpdateUtil(this)
lifecycleScope.launch(Dispatchers.IO){ lifecycleScope.launch(Dispatchers.IO){
updateUtil.updateApp() updateUtil.updateApp{}
} }
} }
} }

View file

@ -28,6 +28,7 @@ import com.deniscerri.ytdlnis.util.ThemeUtil
import com.deniscerri.ytdlnis.util.UpdateUtil import com.deniscerri.ytdlnis.util.UpdateUtil
import com.google.android.material.dialog.MaterialAlertDialogBuilder import com.google.android.material.dialog.MaterialAlertDialogBuilder
import com.yausername.youtubedl_android.YoutubeDL import com.yausername.youtubedl_android.YoutubeDL
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.launch import kotlinx.coroutines.launch
import kotlinx.serialization.json.Json import kotlinx.serialization.json.Json
import java.io.File import java.io.File
@ -697,9 +698,10 @@ class SettingsFragment : PreferenceFragmentCompat() {
// } // }
version!!.onPreferenceClickListener = version!!.onPreferenceClickListener =
Preference.OnPreferenceClickListener { Preference.OnPreferenceClickListener {
if (!updateUtil!!.updateApp()) { lifecycleScope.launch(Dispatchers.IO){
Toast.makeText(context, R.string.you_are_in_latest_version, Toast.LENGTH_SHORT) updateUtil!!.updateApp(){ msg ->
.show() Toast.makeText(context, msg, Toast.LENGTH_SHORT).show()
}
} }
true true
} }

View file

@ -30,7 +30,7 @@ class UpdateUtil(var context: Context) {
private val downloadManager: DownloadManager = context.getSystemService(Context.DOWNLOAD_SERVICE) as DownloadManager private val downloadManager: DownloadManager = context.getSystemService(Context.DOWNLOAD_SERVICE) as DownloadManager
private val ytdlpNightly = "https://api.github.com/repos/yt-dlp/yt-dlp-nightly-builds/releases/latest" private val ytdlpNightly = "https://api.github.com/repos/yt-dlp/yt-dlp-nightly-builds/releases/latest"
fun updateApp(): Boolean { fun updateApp(result: (result: String) -> Unit) {
try { try {
if (updatingApp) { if (updatingApp) {
Toast.makeText( Toast.makeText(
@ -38,7 +38,6 @@ class UpdateUtil(var context: Context) {
context.getString(R.string.ytdl_already_updating), context.getString(R.string.ytdl_already_updating),
Toast.LENGTH_LONG Toast.LENGTH_LONG
).show() ).show()
return true
} }
val res = checkForAppUpdate() val res = checkForAppUpdate()
val version: String val version: String
@ -46,13 +45,15 @@ class UpdateUtil(var context: Context) {
try { try {
version = res.getString("tag_name") version = res.getString("tag_name")
body = res.getString("body") body = res.getString("body")
} catch (ignored: JSONException) { } catch (e: JSONException) {
return false result(e.message.toString())
return
} }
val versionNameInt = version.split("v")[1].replace(".","").toInt() val versionNameInt = version.split("v")[1].replace(".","").toInt()
val currentVersionNameInt = BuildConfig.VERSION_NAME.replace(".","").toInt() val currentVersionNameInt = BuildConfig.VERSION_NAME.replace(".","").toInt()
if (currentVersionNameInt >= versionNameInt) { if (currentVersionNameInt >= versionNameInt) {
return false result(context.getString(R.string.you_are_in_latest_version))
return
} }
Handler(Looper.getMainLooper()).post { Handler(Looper.getMainLooper()).post {
val updateDialog = MaterialAlertDialogBuilder(context) val updateDialog = MaterialAlertDialogBuilder(context)
@ -67,10 +68,11 @@ class UpdateUtil(var context: Context) {
} }
updateDialog.show() updateDialog.show()
} }
return true return
}catch (e: Exception){ }catch (e: Exception){
e.printStackTrace() e.printStackTrace()
return false result(e.message.toString())
return
} }
} }
@ -167,7 +169,7 @@ class UpdateUtil(var context: Context) {
try { try {
YoutubeDL.getInstance().updateYoutubeDL( YoutubeDL.getInstance().updateYoutubeDL(
context, if (sharedPreferences.getBoolean("nightly_ytdl", false) ) ytdlpNightly else null context, if (sharedPreferences.getBoolean("nightly_ytdl", false) ) YoutubeDL.UpdateChannel._NIGHTLY else YoutubeDL.UpdateChannel._STABLE
).apply { ).apply {
updatingYTDL = false updatingYTDL = false
} }

View file

@ -21,7 +21,7 @@ buildscript {
commonsIoVer = '2.5' commonsIoVer = '2.5'
// supports java 1.6 // supports java 1.6
commonsCompressVer = '1.12' commonsCompressVer = '1.12'
youtubedlAndroidVer = "7222fe9637" youtubedlAndroidVer = "23b26d55f8"
workVer = "2.8.1" workVer = "2.8.1"
composeVer = '1.4.2' composeVer = '1.4.2'
kotlinVer = "1.7.21" kotlinVer = "1.7.21"