Skip to content

Commit 7371b8f

Browse files
authored
Merge pull request #13 from JunkFood02/dev
Update yt-dlp when initialize app
2 parents 0536ff0 + e453225 commit 7371b8f

File tree

5 files changed

+11
-10
lines changed

5 files changed

+11
-10
lines changed

app/build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ android {
2323

2424
buildTypes {
2525
release {
26-
minifyEnabled true
26+
minifyEnabled false
2727
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
2828
}
2929
}

app/src/main/java/com/junkfood/seal/BaseApplication.kt

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import android.content.Context
77
import android.os.Environment
88
import android.util.Log
99
import com.google.android.material.color.DynamicColors
10+
import com.junkfood.seal.util.DownloadUtil
1011
import com.junkfood.seal.util.PreferenceUtil
1112
import com.tencent.mmkv.MMKV
1213
import com.yausername.ffmpeg.FFmpeg
@@ -22,13 +23,15 @@ class BaseApplication : Application() {
2223
MMKV.initialize(this)
2324
DynamicColors.applyToActivitiesIfAvailable(this)
2425
clipboard = getSystemService(Context.CLIPBOARD_SERVICE) as ClipboardManager
25-
2626
CoroutineScope(Job()).launch {
2727
withContext(Dispatchers.IO) {
2828
try {
2929
Log.d(TAG, "onCreate: Init")
3030
YoutubeDL.getInstance().init(this@BaseApplication)
3131
FFmpeg.getInstance().init(this@BaseApplication)
32+
if (PreferenceUtil.getString("yt-dlp_init").isNullOrEmpty()) {
33+
DownloadUtil.updateYtDlp()
34+
}
3235
Log.d(TAG, "onCreate: Init Finish")
3336
} catch (e: YoutubeDLException) {
3437
Log.e(TAG, "failed to initialize youtubedl-android", e)
@@ -67,7 +70,6 @@ class BaseApplication : Application() {
6770
}
6871

6972

70-
7173
@SuppressLint("StaticFieldLeak")
7274
lateinit var context: Context
7375
}

app/src/main/java/com/junkfood/seal/ui/viewmodel/DownloadViewModel.kt

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -29,10 +29,6 @@ class DownloadViewModel : ViewModel() {
2929
val url: MutableLiveData<String> = MutableLiveData<String>().apply { value = "" }
3030
val videoTitle: MutableLiveData<String> = MutableLiveData<String>().apply { value = "" }
3131

32-
fun updateProgress(progressNum: Float) {
33-
_progress.postValue(progressNum)
34-
}
35-
3632
fun startDownloadVideo() {
3733
with(url.value) {
3834
if (isNullOrBlank()) TextUtil.makeToast(context.getString(R.string.url_empty))
@@ -46,7 +42,7 @@ class DownloadViewModel : ViewModel() {
4642
videoTitle.value = videoInfo.title
4743
}
4844
val downloadResult = DownloadUtil.downloadVideo(this@with, videoInfo)
49-
{ fl: Float, _: Long, _: String -> updateProgress(fl) }
45+
{ fl: Float, _: Long, _: String -> _progress.postValue(fl) }
5046
isDownloading.postValue(false)
5147
if (downloadResult.resultCode != DownloadUtil.ResultCode.EXCEPTION)
5248
withContext(Dispatchers.Main) {

app/src/main/java/com/junkfood/seal/util/DownloadUtil.kt

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,10 @@ object DownloadUtil {
132132
toast(R.string.yt_dlp_update_fail)
133133
}
134134
}
135-
YoutubeDL.getInstance().version(context)?.let { BaseApplication.ytdlpVersion = it }
135+
YoutubeDL.getInstance().version(context)?.let {
136+
BaseApplication.ytdlpVersion = it
137+
PreferenceUtil.updateString("yt-dlp_init", it)
138+
}
136139
return BaseApplication.ytdlpVersion
137140
}
138141

app/src/main/java/com/junkfood/seal/util/PreferenceUtil.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ object PreferenceUtil {
88
private val kv = MMKV.defaultMMKV()
99

1010
fun updateValue(key: String, b: Boolean) = kv.encode(key, b)
11-
fun getValue(key: String): Boolean = kv.decodeBool(key, true)
11+
fun getValue(key: String): Boolean = kv.decodeBool(key, false)
1212
fun getString(key: String): String? = kv.decodeString(key)
1313
fun updateString(key: String, string: String) = kv.encode(key, string)
1414
}

0 commit comments

Comments
 (0)