Skip to content

Commit

Permalink
Merge pull request #215 from JunkFood02/dev
Browse files Browse the repository at this point in the history
Merged with v1.3.0-beta.2
  • Loading branch information
JunkFood02 authored Sep 12, 2022
2 parents cf09c27 + 314adc9 commit 5ea546c
Show file tree
Hide file tree
Showing 17 changed files with 134 additions and 80 deletions.
2 changes: 0 additions & 2 deletions .github/workflows/android.yml
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
name: Android CI

on:
pull_request:
branches: [ "main" ]
workflow_dispatch:

jobs:
Expand Down
15 changes: 8 additions & 7 deletions app/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,10 @@ plugins {
apply(plugin = "dagger.hilt.android.plugin")

val versionMajor = 1
val versionMinor = 2
val versionPatch = 1
val versionBuild = 0
val isStable = true
val versionMinor = 3
val versionPatch = 0
val versionBuild = 2
val isStable = false

val composeVersion = "1.2.1"
val lifecycleVersion = "2.6.0-alpha01"
Expand All @@ -25,7 +25,7 @@ val kotlinVersion = "1.6.21"
val hiltVersion = "2.43.2"
val composeMd3Version = "1.0.0-beta01"
val coilVersion = "2.2.0"
val youtubedlAndroidVersion = "add_aria2-SNAPSHOT"
val youtubedlAndroidVersion = "68e633ff07"
val okhttpVersion = "5.0.0-alpha.10"

val keystorePropertiesFile = rootProject.file("keystore.properties")
Expand Down Expand Up @@ -179,8 +179,9 @@ dependencies {
implementation("com.github.yausername.youtubedl-android:ffmpeg:$youtubedlAndroidVersion")
implementation("com.github.yausername.youtubedl-android:aria2c:$youtubedlAndroidVersion")

// implementation ("com.github.xibr.youtubedl-android:library:set-ffmpeg-location-SNAPSHOT")
// implementation ("com.github.xibr.youtubedl-android:ffmpeg:set-ffmpeg-location-SNAPSHOT")
// implementation ("com.github.xibr.youtubedl-android:library:$youtubedlAndroidVersion")
// implementation ("com.github.xibr.youtubedl-android:ffmpeg:$youtubedlAndroidVersion")
// implementation ("com.github.xibr.youtubedl-android:aria2c:$youtubedlAndroidVersion")

// implementation("com.github.JunkFood02.youtubedl-android:ffmpeg:-SNAPSHOT")
// implementation("com.github.JunkFood02.youtubedl-android:library:-SNAPSHOT")
Expand Down
2 changes: 2 additions & 0 deletions app/src/main/java/com/junkfood/seal/BaseApplication.kt
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import com.junkfood.seal.util.PreferenceUtil.AUDIO_DIRECTORY
import com.junkfood.seal.util.PreferenceUtil.TEMPLATE_INDEX
import com.junkfood.seal.util.PreferenceUtil.VIDEO_DIRECTORY
import com.tencent.mmkv.MMKV
import com.yausername.aria2c.Aria2c
import com.yausername.ffmpeg.FFmpeg
import com.yausername.youtubedl_android.YoutubeDL
import com.yausername.youtubedl_android.YoutubeDLException
Expand Down Expand Up @@ -51,6 +52,7 @@ class BaseApplication : Application() {
try {
YoutubeDL.getInstance().init(this@BaseApplication)
FFmpeg.getInstance().init(this@BaseApplication)
Aria2c.getInstance().init(this@BaseApplication)
} catch (e: YoutubeDLException) {
e.printStackTrace()
Toast.makeText(this@BaseApplication, e.message, Toast.LENGTH_LONG).show()
Expand Down
18 changes: 10 additions & 8 deletions app/src/main/java/com/junkfood/seal/MainActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -65,20 +65,21 @@ class MainActivity : AppCompatActivity() {
handleShareIntent(intent)
}

override fun onNewIntent(intent: Intent?) {
intent?.let { handleShareIntent(it) }
override fun onNewIntent(intent: Intent) {
handleShareIntent(intent)
super.onNewIntent(intent)
}

private fun handleShareIntent(intent: Intent) {
Log.d(TAG, "handleShareIntent: $intent")
if (Intent.ACTION_SEND == intent.action)
intent.getStringExtra(Intent.EXTRA_TEXT)
?.let { it ->
TextUtil.matchUrlFromSharedText(it)
?.let { it1 ->
if (sharedUrl != it1) {
sharedUrl = it1
?.let { sharedContent ->
intent.removeExtra(Intent.EXTRA_TEXT)
TextUtil.matchUrlFromSharedText(sharedContent)
.let { matchedUrl ->
if (sharedUrl != matchedUrl) {
sharedUrl = matchedUrl
downloadViewModel.updateUrl(sharedUrl)
}
}
Expand All @@ -101,7 +102,8 @@ class MainActivity : AppCompatActivity() {

fun startService() {
if (isServiceRunning) return
Intent(context, DownloadService::class.java).also { intent ->
isServiceRunning = true
Intent(context.applicationContext, DownloadService::class.java).also { intent ->
context.applicationContext.bindService(intent, connection, Context.BIND_AUTO_CREATE)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ fun DrawerSheetSubtitle(
text = text,
modifier = modifier
.fillMaxWidth()
.padding(start = 6.dp, top = 16.dp, bottom = 8.dp),
.padding(start = 4.dp, top = 16.dp, bottom = 8.dp),
color = color,
style = MaterialTheme.typography.labelLarge
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ fun DownloadPage(
keyboardController?.hide()
}, pasteCallback = {
TextUtil.matchUrlFromClipboard(clipboardManager.getText().toString())
?.let { downloadViewModel.updateUrl(it) }
.let { downloadViewModel.updateUrl(it) }
}
)
}) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,17 +59,23 @@ fun DownloadSettingDialog(

val templateList = DatabaseUtil.getTemplateFlow().collectAsState(ArrayList()).value

val downloadButtonCallback = {
val updatePreferences = {
PreferenceUtil.updateValue(EXTRACT_AUDIO, audio)
PreferenceUtil.updateValue(THUMBNAIL, thumbnail)
PreferenceUtil.updateValue(CUSTOM_COMMAND, customCommand)
PreferenceUtil.updateValue(PLAYLIST, playlist)
PreferenceUtil.updateValue(SUBTITLE, subtitle)
PreferenceUtil.updateInt(TEMPLATE_INDEX, selectedTemplateIndex)
}

val downloadButtonCallback = {
updatePreferences()
hide()
confirm()
}



val sheetContent: @Composable () -> Unit = {
Column {
Text(
Expand All @@ -83,33 +89,48 @@ fun DownloadSettingDialog(
FilterChip(
selected = audio,
enabled = !customCommand,
onClick = { audio = !audio },
onClick = {
audio = !audio
updatePreferences()
},
label = stringResource(R.string.extract_audio)
)
FilterChip(
selected = playlist,
enabled = !customCommand,
onClick = { playlist = !playlist },
onClick = {
playlist = !playlist
updatePreferences()
},
label = stringResource(R.string.download_playlist)
)
FilterChip(
selected = subtitle,
enabled = !customCommand && !audio,
onClick = { subtitle = !subtitle },
onClick = {
subtitle = !subtitle
updatePreferences()
},
label = stringResource(id = R.string.embed_subtitles)
)
FilterChip(
selected = thumbnail,
enabled = !customCommand,
onClick = { thumbnail = !thumbnail },
onClick = {
thumbnail = !thumbnail
updatePreferences()
},
label = stringResource(R.string.create_thumbnail)
)
}
DrawerSheetSubtitle(text = stringResource(id = R.string.advanced_settings))
Row(modifier = Modifier.horizontalScroll(rememberScrollState())) {
FilterChip(
selected = customCommand,
onClick = { customCommand = !customCommand },
onClick = {
customCommand = !customCommand
updatePreferences()
},
label = stringResource(R.string.custom_command)
)
ButtonChip(
Expand Down Expand Up @@ -157,7 +178,10 @@ fun DownloadSettingDialog(
itemsIndexed(templateList) { index, item ->
FilterChipWithIcons(
selected = index == selectedTemplateIndex,
onClick = { selectedTemplateIndex = index },
onClick = {
selectedTemplateIndex = index
updatePreferences()
},
label = item.name
)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import com.junkfood.seal.R
import com.junkfood.seal.util.*
import com.junkfood.seal.util.FileUtil.getConfigFile
import com.junkfood.seal.util.FileUtil.getCookiesFile
import com.junkfood.seal.util.FileUtil.getTempDir
import com.junkfood.seal.util.FileUtil.openFile
import com.junkfood.seal.util.PreferenceUtil.COOKIES
import com.yausername.youtubedl_android.YoutubeDL
Expand Down Expand Up @@ -103,10 +104,6 @@ class DownloadViewModel @Inject constructor() : ViewModel() {
notificationId: Int? = null
) {
if (stateFlow.value.isCancelled) return
if (e.message.isNullOrEmpty()) {
finishProcessing()
return
}
viewModelScope.launch {
e.printStackTrace()
if (PreferenceUtil.getValue(PreferenceUtil.DEBUG) || stateFlow.value.isInCustomCommandMode)
Expand Down Expand Up @@ -315,23 +312,20 @@ class DownloadViewModel @Inject constructor() : ViewModel() {
downloadResultTemp = DownloadUtil.Result.failure()

viewModelScope.launch(Dispatchers.IO) {
if (urlList.size > 1) return@launch
try {
if (stateFlow.value.url.isNotEmpty())
with(DownloadUtil.fetchVideoInfo(stateFlow.value.url)) {
if (!title.isNullOrEmpty() and !thumbnail.isNullOrEmpty())
mutableStateFlow.update {
it.copy(
videoTitle = title,
videoThumbnailUrl = TextUtil.urlHttpToHttps(thumbnail),
videoAuthor = uploader ?: "null",
showVideoCard = true
)
}
if (urlList.size != 1) return@launch
kotlin.runCatching {
with(DownloadUtil.fetchVideoInfo(urlList[0])) {
mutableStateFlow.update {
it.copy(
videoTitle = title.toString(),
videoThumbnailUrl = TextUtil.urlHttpToHttps(thumbnail),
videoAuthor = uploader.toString(),
showVideoCard = true
)
}
} catch (e: Exception) {
e.printStackTrace()
}
}

}
val notificationId = stateFlow.value.url.hashCode()

Expand All @@ -344,7 +338,8 @@ class DownloadViewModel @Inject constructor() : ViewModel() {
try {
with(mutableStateFlow) {
val request = YoutubeDLRequest(urlList)
request.addOption("-P", "${BaseApplication.videoDownloadDir}/")
request.addOption("-P", BaseApplication.videoDownloadDir)
request.addOption("-P", "temp:" + context.getTempDir())
FileUtil.writeContentToFile(
PreferenceUtil.getTemplate(),
context.getConfigFile()
Expand All @@ -370,21 +365,24 @@ class DownloadViewModel @Inject constructor() : ViewModel() {
)
}
finishProcessing()
NotificationUtil.finishNotification(
notificationId,
title = context.getString(R.string.download_success_msg),
text = null,
intent = null
)
}
} catch (e: Exception) {
manageDownloadError(e, false, notificationId)
return@launch
if (!e.message.isNullOrEmpty()) {
manageDownloadError(e, false, notificationId)
return@launch
}
finishProcessing()
}
NotificationUtil.finishNotification(
notificationId,
title = context.getString(R.string.download_success_msg),
text = null,
intent = null
)
}
}

private suspend fun checkStateBeforeDownload(): Boolean {
private fun checkStateBeforeDownload(): Boolean {
with(mutableStateFlow) {
if (value.isProcessRunning || value.isFetchingInfo) {
TextUtil.makeToastSuspend(context.getString(R.string.task_running))
Expand Down Expand Up @@ -432,7 +430,7 @@ class DownloadViewModel @Inject constructor() : ViewModel() {
}
}

private suspend fun showErrorMessage(s: String) {
private fun showErrorMessage(s: String) {
TextUtil.makeToastSuspend(s)
mutableStateFlow.update {
it.copy(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,12 @@ import android.os.Build
import android.provider.Settings
import androidx.activity.compose.rememberLauncherForActivityResult
import androidx.activity.result.contract.ActivityResultContracts
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.lazy.LazyColumn
import androidx.compose.foundation.rememberScrollState
import androidx.compose.foundation.verticalScroll
import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.outlined.*
import androidx.compose.material3.*
Expand Down Expand Up @@ -243,7 +246,11 @@ fun UpdateDialog(
) {
AlertDialog(
onDismissRequest = {},
title = { Text(title) },
title = {
Column(Modifier.verticalScroll(rememberScrollState())) {
Text(title)
}
},
icon = { Icon(Icons.Outlined.NewReleases, null) }, confirmButton = {
TextButton(onClick = { if (downloadStatus !is UpdateUtil.DownloadStatus.Progress) onConfirmUpdate() }) {
when (downloadStatus) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,6 @@ fun AppearancePreferences(
) {
if (DynamicColors.isDynamicColorAvailable()) {
ColorButton(color = dynamicDarkColorScheme(LocalContext.current).primary)
ColorButton(color = dynamicDarkColorScheme(LocalContext.current).tertiary)
}
ColorButton(color = Color(ColorScheme.DEFAULT_SEED_COLOR))
ColorButton(color = Color.Yellow)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ import com.junkfood.seal.R
import com.junkfood.seal.ui.component.*
import com.junkfood.seal.ui.component.LargeTopAppBar
import com.junkfood.seal.util.FileUtil
import com.junkfood.seal.util.FileUtil.getTempDir
import com.junkfood.seal.util.PreferenceUtil
import com.junkfood.seal.util.PreferenceUtil.CUSTOM_PATH
import com.junkfood.seal.util.PreferenceUtil.OUTPUT_PATH_TEMPLATE
Expand Down Expand Up @@ -206,9 +207,7 @@ fun DownloadDirectoryPreferences(onBackPressed: () -> Unit) {
showClearTempDialog = false
scope.launch(Dispatchers.IO) {
val count =
FileUtil.clearTempFiles(audioDirectoryText) + FileUtil.clearTempFiles(
videoDirectoryText
)
FileUtil.clearTempFiles(context.getTempDir())
withContext(Dispatchers.Main) {
snackbarHostState.showSnackbar(
context.getString(R.string.clear_temp_files_count).format(count)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import com.junkfood.seal.BaseApplication
import com.junkfood.seal.R
import com.junkfood.seal.ui.component.*
import com.junkfood.seal.util.DownloadUtil
import com.junkfood.seal.util.NotificationUtil
import com.junkfood.seal.util.PreferenceUtil
import com.junkfood.seal.util.PreferenceUtil.ARIA2C
import com.junkfood.seal.util.PreferenceUtil.COOKIES
Expand Down Expand Up @@ -148,6 +149,8 @@ fun DownloadPreferences(
onClick = {
notificationPermission?.launchPermissionRequest()
if (checkNotificationPermission()) {
if (downloadNotification)
NotificationUtil.cancelAllNotifications()
downloadNotification = !downloadNotification
PreferenceUtil.updateValue(
NOTIFICATION, downloadNotification
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,8 +102,7 @@ fun VideoListPage(

Scaffold(
modifier = Modifier
.nestedScroll(scrollBehavior.nestedScrollConnection)
.navigationBarsPadding(),
.nestedScroll(scrollBehavior.nestedScrollConnection),
topBar = {
LargeTopAppBar(
title = {
Expand Down
Loading

0 comments on commit 5ea546c

Please sign in to comment.