fixed app not updating when clicking the version nr in the settings
This commit is contained in:
parent
5edfe4be38
commit
167b35a077
5 changed files with 20 additions and 16 deletions
|
|
@ -122,9 +122,9 @@ android {
|
|||
dependencies {
|
||||
implementation fileTree(dir: 'libs', include: ['*.jar'])
|
||||
|
||||
implementation "com.github.JunkFood02.youtubedl-android:library:$youtubedlAndroidVer"
|
||||
implementation "com.github.JunkFood02.youtubedl-android:ffmpeg:$youtubedlAndroidVer"
|
||||
implementation "com.github.JunkFood02.youtubedl-android:aria2c:$youtubedlAndroidVer"
|
||||
implementation "com.github.yausername.youtubedl-android:library:$youtubedlAndroidVer"
|
||||
implementation "com.github.yausername.youtubedl-android:ffmpeg:$youtubedlAndroidVer"
|
||||
implementation "com.github.yausername.youtubedl-android:aria2c:$youtubedlAndroidVer"
|
||||
|
||||
implementation "androidx.appcompat:appcompat:$appCompatVer"
|
||||
implementation "androidx.constraintlayout:constraintlayout:2.1.4"
|
||||
|
|
|
|||
|
|
@ -260,7 +260,7 @@ class MainActivity : BaseActivity() {
|
|||
if (preferences.getBoolean("update_app", false)) {
|
||||
val updateUtil = UpdateUtil(this)
|
||||
lifecycleScope.launch(Dispatchers.IO){
|
||||
updateUtil.updateApp()
|
||||
updateUtil.updateApp{}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -28,6 +28,7 @@ import com.deniscerri.ytdlnis.util.ThemeUtil
|
|||
import com.deniscerri.ytdlnis.util.UpdateUtil
|
||||
import com.google.android.material.dialog.MaterialAlertDialogBuilder
|
||||
import com.yausername.youtubedl_android.YoutubeDL
|
||||
import kotlinx.coroutines.Dispatchers
|
||||
import kotlinx.coroutines.launch
|
||||
import kotlinx.serialization.json.Json
|
||||
import java.io.File
|
||||
|
|
@ -697,9 +698,10 @@ class SettingsFragment : PreferenceFragmentCompat() {
|
|||
// }
|
||||
version!!.onPreferenceClickListener =
|
||||
Preference.OnPreferenceClickListener {
|
||||
if (!updateUtil!!.updateApp()) {
|
||||
Toast.makeText(context, R.string.you_are_in_latest_version, Toast.LENGTH_SHORT)
|
||||
.show()
|
||||
lifecycleScope.launch(Dispatchers.IO){
|
||||
updateUtil!!.updateApp(){ msg ->
|
||||
Toast.makeText(context, msg, Toast.LENGTH_SHORT).show()
|
||||
}
|
||||
}
|
||||
true
|
||||
}
|
||||
|
|
|
|||
|
|
@ -30,7 +30,7 @@ class UpdateUtil(var context: Context) {
|
|||
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"
|
||||
|
||||
fun updateApp(): Boolean {
|
||||
fun updateApp(result: (result: String) -> Unit) {
|
||||
try {
|
||||
if (updatingApp) {
|
||||
Toast.makeText(
|
||||
|
|
@ -38,7 +38,6 @@ class UpdateUtil(var context: Context) {
|
|||
context.getString(R.string.ytdl_already_updating),
|
||||
Toast.LENGTH_LONG
|
||||
).show()
|
||||
return true
|
||||
}
|
||||
val res = checkForAppUpdate()
|
||||
val version: String
|
||||
|
|
@ -46,13 +45,15 @@ class UpdateUtil(var context: Context) {
|
|||
try {
|
||||
version = res.getString("tag_name")
|
||||
body = res.getString("body")
|
||||
} catch (ignored: JSONException) {
|
||||
return false
|
||||
} catch (e: JSONException) {
|
||||
result(e.message.toString())
|
||||
return
|
||||
}
|
||||
val versionNameInt = version.split("v")[1].replace(".","").toInt()
|
||||
val currentVersionNameInt = BuildConfig.VERSION_NAME.replace(".","").toInt()
|
||||
if (currentVersionNameInt >= versionNameInt) {
|
||||
return false
|
||||
result(context.getString(R.string.you_are_in_latest_version))
|
||||
return
|
||||
}
|
||||
Handler(Looper.getMainLooper()).post {
|
||||
val updateDialog = MaterialAlertDialogBuilder(context)
|
||||
|
|
@ -67,10 +68,11 @@ class UpdateUtil(var context: Context) {
|
|||
}
|
||||
updateDialog.show()
|
||||
}
|
||||
return true
|
||||
return
|
||||
}catch (e: Exception){
|
||||
e.printStackTrace()
|
||||
return false
|
||||
result(e.message.toString())
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -167,7 +169,7 @@ class UpdateUtil(var context: Context) {
|
|||
|
||||
try {
|
||||
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 {
|
||||
updatingYTDL = false
|
||||
}
|
||||
|
|
|
|||
|
|
@ -21,7 +21,7 @@ buildscript {
|
|||
commonsIoVer = '2.5'
|
||||
// supports java 1.6
|
||||
commonsCompressVer = '1.12'
|
||||
youtubedlAndroidVer = "7222fe9637"
|
||||
youtubedlAndroidVer = "23b26d55f8"
|
||||
workVer = "2.8.1"
|
||||
composeVer = '1.4.2'
|
||||
kotlinVer = "1.7.21"
|
||||
|
|
|
|||
Loading…
Reference in a new issue