Skip to content

Commit 957c6e8

Browse files
committed
Code cleanup
1 parent 460efcb commit 957c6e8

File tree

9 files changed

+35
-57
lines changed

9 files changed

+35
-57
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ class BaseApplication : Application() {
3737
DynamicColors.applyToActivitiesIfAvailable(this)
3838
clipboard = getSystemService(Context.CLIPBOARD_SERVICE) as ClipboardManager
3939
applicationScope.launch((Dispatchers.IO)) {
40-
if (!PreferenceUtil.containsKey(PreferenceUtil.TEMPLATE_INDEX)) {
40+
if (!PreferenceUtil.containsKey(TEMPLATE_INDEX)) {
4141
PreferenceUtil.updateInt(TEMPLATE_INDEX, 0)
4242
DatabaseUtil.insertTemplate(
4343
CommandTemplate(

app/src/main/java/com/junkfood/seal/ui/component/DownloadTaskItem.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ fun DownloadTaskItem(
7676
onClick = { isExpanded = !isExpanded },
7777
shape = MaterialTheme.shapes.small
7878
) {
79-
Box() {
79+
Box {
8080
Row(
8181
modifier = Modifier
8282
.fillMaxWidth()
@@ -289,7 +289,7 @@ fun CardPreview() {
289289
)
290290
}
291291
}
292-
Column() {
292+
Column {
293293
DownloadTaskItem(expanded = false, status = DownloadTaskItemStatus.ENQUEUED)
294294
DownloadTaskItem(expanded = false, status = DownloadTaskItemStatus.FETCHING_INFO)
295295
DownloadTaskItem(expanded = false, progress = 1f, status = DownloadTaskItemStatus.COMPLETED)

app/src/main/java/com/junkfood/seal/ui/page/HomeEntry.kt

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -137,9 +137,7 @@ fun HomeEntry(
137137
launch(Dispatchers.IO) {
138138
try {
139139
val temp = UpdateUtil.checkForUpdate()
140-
if (temp == null) {
141-
TextUtil.makeToastSuspend(context.getString(R.string.app_up_to_date))
142-
} else {
140+
if (temp != null) {
143141
latestRelease = temp
144142
showUpdateDialog = true
145143
}

app/src/main/java/com/junkfood/seal/ui/page/settings/appearance/AppearancePreferences.kt

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ import com.junkfood.seal.ui.common.LocalSeedColor
3333
import com.junkfood.seal.ui.common.Route
3434
import com.junkfood.seal.ui.component.*
3535
import com.junkfood.seal.ui.component.LargeTopAppBar
36+
import com.junkfood.seal.ui.page.download.VideoCard
3637
import com.junkfood.seal.ui.theme.ColorScheme
3738
import com.junkfood.seal.util.PreferenceUtil
3839
import com.junkfood.seal.util.PreferenceUtil.DarkThemePreference.Companion.FOLLOW_SYSTEM
@@ -77,8 +78,8 @@ fun AppearancePreferences(
7778
.padding(it)
7879
.verticalScroll(rememberScrollState())
7980
) {
80-
// VideoCard(modifier = Modifier.padding(18.dp))
81-
CardPreview()
81+
VideoCard(modifier = Modifier.padding(18.dp))
82+
// CardPreview()
8283
Column {
8384
Row(
8485
modifier = Modifier
@@ -128,7 +129,7 @@ fun AppearancePreferences(
128129
}
129130
}, icon = { Icon(Icons.Outlined.DarkMode, null) },
130131
title = { Text(stringResource(R.string.dark_theme)) }, text = {
131-
Column() {
132+
Column {
132133
SingleChoiceItem(
133134
text = stringResource(R.string.follow_system),
134135
selected = darkThemeValue == FOLLOW_SYSTEM

app/src/main/java/com/junkfood/seal/ui/page/settings/download/AdvancedSettingDialogs.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,7 @@ fun SponsorBlockDialog(onDismissRequest: () -> Unit) {
169169
AlertDialog(onDismissRequest = onDismissRequest, icon = {
170170
Icon(Icons.Outlined.MoneyOff, null)
171171
}, title = { Text(stringResource(R.string.sponsorblock)) }, text = {
172-
Column() {
172+
Column {
173173
Text(
174174
stringResource(R.string.sponsorblock_categories_desc),
175175
style = MaterialTheme.typography.bodyLarge
@@ -204,7 +204,7 @@ fun CookiesDialog(onDismissRequest: () -> Unit) {
204204
AlertDialog(onDismissRequest = onDismissRequest, icon = {
205205
Icon(Icons.Outlined.Cookie, null)
206206
}, title = { Text(stringResource(R.string.cookies)) }, text = {
207-
Column() {
207+
Column {
208208
Text(
209209
stringResource(R.string.cookies_desc),
210210
style = MaterialTheme.typography.bodyLarge

app/src/main/java/com/junkfood/seal/ui/page/settings/download/DownloadPreferences.kt

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ import com.google.accompanist.permissions.rememberPermissionState
2020
import com.junkfood.seal.BaseApplication
2121
import com.junkfood.seal.R
2222
import com.junkfood.seal.ui.component.*
23-
import com.junkfood.seal.util.DownloadUtil
2423
import com.junkfood.seal.util.NotificationUtil
2524
import com.junkfood.seal.util.PreferenceUtil
2625
import com.junkfood.seal.util.PreferenceUtil.ARIA2C
@@ -37,8 +36,7 @@ import com.junkfood.seal.util.PreferenceUtil.getAudioFormatDesc
3736
import com.junkfood.seal.util.PreferenceUtil.getVideoFormatDesc
3837
import com.junkfood.seal.util.PreferenceUtil.getVideoResolutionDesc
3938
import com.junkfood.seal.util.TextUtil
40-
import kotlinx.coroutines.CoroutineScope
41-
import kotlinx.coroutines.Job
39+
import com.junkfood.seal.util.UpdateUtil
4240
import kotlinx.coroutines.launch
4341

4442
@OptIn(
@@ -51,7 +49,7 @@ fun DownloadPreferences(
5149
navigateToTemplate: () -> Unit
5250
) {
5351
val context = LocalContext.current
54-
52+
val scope = rememberCoroutineScope()
5553
var showAudioFormatEditDialog by remember { mutableStateOf(false) }
5654
var showVideoQualityDialog by remember { mutableStateOf(false) }
5755
var showVideoFormatDialog by remember { mutableStateOf(false) }
@@ -131,8 +129,8 @@ fun DownloadPreferences(
131129
description = ytdlpVersion,
132130
icon = Icons.Outlined.Update
133131
) {
134-
CoroutineScope(Job()).launch {
135-
ytdlpVersion = DownloadUtil.updateYtDlp()
132+
scope.launch {
133+
ytdlpVersion = UpdateUtil.updateYtDlp()
136134
}
137135
}
138136
}

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

Lines changed: 4 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
package com.junkfood.seal.util
22

33
import android.util.Log
4-
import com.junkfood.seal.BaseApplication
54
import com.junkfood.seal.BaseApplication.Companion.audioDownloadDir
65
import com.junkfood.seal.BaseApplication.Companion.context
76
import com.junkfood.seal.BaseApplication.Companion.videoDownloadDir
@@ -22,8 +21,6 @@ import com.yausername.youtubedl_android.YoutubeDL
2221
import com.yausername.youtubedl_android.YoutubeDLRequest
2322
import com.yausername.youtubedl_android.YoutubeDLResponse
2423
import com.yausername.youtubedl_android.mapper.VideoInfo
25-
import kotlinx.coroutines.Dispatchers
26-
import kotlinx.coroutines.withContext
2724
import org.json.JSONObject
2825
import kotlin.math.roundToInt
2926

@@ -134,8 +131,8 @@ object DownloadUtil {
134131
if (extractAudio) {
135132
pathBuilder.append(audioDownloadDir)
136133
if (aria2c) {
137-
addOption("--downloader", "libaria2c.so");
138-
addOption("--external-downloader-args", "aria2c:\"--summary-interval=1\"");
134+
addOption("--downloader", "libaria2c.so")
135+
addOption("--external-downloader-args", "aria2c:\"--summary-interval=1\"")
139136
}
140137
addOption("-x")
141138
when (PreferenceUtil.getAudioFormat()) {
@@ -185,8 +182,8 @@ object DownloadUtil {
185182
if (sorter.isNotEmpty())
186183
addOption("-S", sorter.toString())
187184
if (aria2c) {
188-
addOption("--downloader", "libaria2c.so");
189-
addOption("--external-downloader-args", "aria2c:\"--summary-interval=1\"");
185+
addOption("--downloader", "libaria2c.so")
186+
addOption("--external-downloader-args", "aria2c:\"--summary-interval=1\"")
190187
} else if (concurrentFragments > 0f) {
191188
addOption("--concurrent-fragments", (concurrentFragments * 16).roundToInt())
192189
}
@@ -244,21 +241,6 @@ object DownloadUtil {
244241
return Result.success(filePaths)
245242
}
246243

247-
suspend fun updateYtDlp(): String {
248-
withContext(Dispatchers.IO) {
249-
try {
250-
YoutubeDL.getInstance().updateYoutubeDL(context)
251-
TextUtil.makeToastSuspend(context.getString(R.string.yt_dlp_up_to_date))
252-
} catch (e: Exception) {
253-
TextUtil.makeToastSuspend(context.getString(R.string.yt_dlp_update_fail))
254-
}
255-
}
256-
YoutubeDL.getInstance().version(context)?.let {
257-
BaseApplication.ytdlpVersion = it
258-
PreferenceUtil.updateString(PreferenceUtil.YT_DLP, it)
259-
}
260-
return BaseApplication.ytdlpVersion
261-
}
262244

263245

264246
}

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

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -9,30 +9,12 @@ import androidx.core.content.FileProvider
99
import com.junkfood.seal.BaseApplication.Companion.context
1010
import java.io.File
1111

12-
/**
13-
* Sorry for ugly codes for filename control
14-
*/
1512
object FileUtil {
1613
fun openFile(downloadResult: DownloadUtil.Result) {
1714
if (downloadResult.resultCode == DownloadUtil.ResultCode.EXCEPTION) return
1815
openFileInURI(downloadResult.filePath?.get(0) ?: return)
1916
}
2017

21-
fun openFile(path: String) {
22-
context.startActivity(Intent().apply {
23-
action = (Intent.ACTION_VIEW)
24-
addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION or Intent.FLAG_ACTIVITY_NEW_TASK)
25-
setDataAndType(
26-
FileProvider.getUriForFile(
27-
context,
28-
context.packageName + ".provider",
29-
File(path)
30-
),
31-
if (path.contains(Regex("\\.mp3|\\.m4a|\\.opus"))) "audio/*" else "video/*"
32-
)
33-
})
34-
}
35-
3618
fun openFileInURI(path: String) {
3719
MediaScannerConnection.scanFile(context, arrayOf(path), null) { _, uri ->
3820
context.startActivity(Intent().apply {

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

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import android.util.Log
88
import androidx.core.content.FileProvider
99
import com.junkfood.seal.BaseApplication
1010
import com.junkfood.seal.R
11+
import com.yausername.youtubedl_android.YoutubeDL
1112
import kotlinx.coroutines.Dispatchers
1213
import kotlinx.coroutines.flow.*
1314
import kotlinx.coroutines.withContext
@@ -37,6 +38,22 @@ object UpdateUtil {
3738
.build()
3839
private val jsonFormat = Json { ignoreUnknownKeys = true }
3940

41+
suspend fun updateYtDlp(): String {
42+
withContext(Dispatchers.IO) {
43+
try {
44+
YoutubeDL.getInstance().updateYoutubeDL(BaseApplication.context)
45+
TextUtil.makeToastSuspend(BaseApplication.context.getString(R.string.yt_dlp_up_to_date))
46+
} catch (e: Exception) {
47+
TextUtil.makeToastSuspend(BaseApplication.context.getString(R.string.yt_dlp_update_fail))
48+
}
49+
}
50+
YoutubeDL.getInstance().version(BaseApplication.context)?.let {
51+
BaseApplication.ytdlpVersion = it
52+
PreferenceUtil.updateString(PreferenceUtil.YT_DLP, it)
53+
}
54+
return BaseApplication.ytdlpVersion
55+
}
56+
4057
private suspend fun getLatestRelease(): LatestRelease {
4158
return suspendCoroutine { continuation ->
4259
client.newCall(requestForLatestRelease).enqueue(object : Callback {

0 commit comments

Comments
 (0)