Skip to content

Commit

Permalink
Process Id exist error when preference dialog unabled
Browse files Browse the repository at this point in the history
  • Loading branch information
JunkFood02 committed Jan 10, 2023
1 parent 275601e commit 2627b06
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 19 deletions.
23 changes: 15 additions & 8 deletions app/src/main/java/com/junkfood/seal/QuickDownloadActivity.kt
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.junkfood.seal

import android.content.Intent
import android.graphics.drawable.ColorDrawable
import android.os.Bundle
import android.util.Log
import android.view.WindowManager
Expand Down Expand Up @@ -74,11 +75,22 @@ class QuickDownloadActivity : ComponentActivity() {
v.setPadding(0, 0, 0, 0)
insets
}
window.setBackgroundDrawable(ColorDrawable(0))
window.setLayout(
WindowManager.LayoutParams.MATCH_PARENT,
WindowManager.LayoutParams.MATCH_PARENT
)
handleShareIntent(intent)
val isDialogEnabled = PreferenceUtil.getValue(PreferenceUtil.CONFIGURE, true)

if (url.isEmpty()) {
finish()
}

if (!isDialogEnabled) {
onDownloadStarted(PreferenceUtil.getValue(PreferenceUtil.CUSTOM_COMMAND))
this.finish()
}

setContent {
val scope = rememberCoroutineScope()
Expand All @@ -91,12 +103,7 @@ class QuickDownloadActivity : ComponentActivity() {
seedColor = LocalSeedColor.current,
isDynamicColorEnabled = LocalDynamicColorSwitch.current,
) {
val isDialogEnabled = PreferenceUtil.getValue(PreferenceUtil.CONFIGURE, true)
if (!isDialogEnabled) {
onDownloadStarted(PreferenceUtil.getValue(PreferenceUtil.CUSTOM_COMMAND))
this.finish()
return@SealTheme
}


var showDialog by remember { mutableStateOf(true) }
val drawerState =
Expand All @@ -105,8 +112,8 @@ class QuickDownloadActivity : ComponentActivity() {
skipHalfExpanded = true
)

LaunchedEffect(drawerState.targetValue, showDialog) {
if (drawerState.targetValue == ModalBottomSheetValue.Hidden || !showDialog)
LaunchedEffect(drawerState.currentValue, showDialog) {
if (drawerState.currentValue == ModalBottomSheetValue.Hidden || !showDialog)
this@QuickDownloadActivity.finish()
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
import androidx.compose.runtime.rememberCoroutineScope
import androidx.compose.runtime.setValue
import androidx.compose.ui.Alignment
import androidx.compose.ui.ExperimentalComposeUiApi
import androidx.compose.ui.Modifier
Expand Down Expand Up @@ -88,6 +89,7 @@ import com.junkfood.seal.ui.component.NavigationBarSpacer
import com.junkfood.seal.ui.component.VideoCard
import com.junkfood.seal.ui.theme.PreviewThemeLight
import com.junkfood.seal.util.PreferenceUtil
import com.junkfood.seal.util.PreferenceUtil.DEBUG
import com.junkfood.seal.util.PreferenceUtil.WELCOME_DIALOG
import com.junkfood.seal.util.TextUtil
import kotlinx.coroutines.launch
Expand All @@ -96,7 +98,6 @@ import kotlinx.coroutines.launch
@OptIn(
ExperimentalPermissionsApi::class,
ExperimentalMaterialApi::class,
ExperimentalMaterial3Api::class,
ExperimentalComposeUiApi::class,
ExperimentalLifecycleComposeApi::class
)
Expand Down Expand Up @@ -154,7 +155,12 @@ fun DownloadPage(
}
onDispose { downloadViewModel.hideFormatPage() }
}

var showOutput by remember {
mutableStateOf(PreferenceUtil.getValue(DEBUG))
}
LaunchedEffect(downloaderState) {
showOutput = PreferenceUtil.getValue(DEBUG) && downloaderState !is Downloader.State.Idle
}
if (viewState.isUrlSharingTriggered) {
downloadViewModel.onShareIntentConsumed()
downloadCallback()
Expand Down Expand Up @@ -184,6 +190,7 @@ fun DownloadPage(
navigateToSettings = navigateToSettings,
navigateToDownloads = navigateToDownloads,
showVideoCard = showVideoCard,
showOutput = showOutput,
showDownloadProgress = taskState.taskId.isNotEmpty(),
pasteCallback = {
TextUtil.matchUrlFromClipboard(clipboardManager.getText().toString())
Expand All @@ -209,7 +216,7 @@ fun DownloadPage(
}

@OptIn(
ExperimentalMaterialApi::class, ExperimentalMaterial3Api::class, ExperimentalComposeUiApi::class
ExperimentalMaterial3Api::class
)
@Composable
fun DownloadPageImpl(
Expand All @@ -218,6 +225,7 @@ fun DownloadPageImpl(
viewState: DownloadViewModel.ViewState,
errorState: Downloader.ErrorState,
showVideoCard: Boolean = false,
showOutput: Boolean = false,
showDownloadProgress: Boolean = false,
downloadCallback: () -> Unit = {},
navigateToSettings: () -> Unit = {},
Expand Down Expand Up @@ -306,7 +314,7 @@ fun DownloadPageImpl(
AnimatedVisibility(
enter = expandVertically() + fadeIn(),
exit = shrinkVertically() + fadeOut(),
visible = viewState.isInDebugMode && progressText.isNotEmpty()
visible = progressText.isNotEmpty() && showOutput
) {
Text(
modifier = Modifier.padding(bottom = 12.dp),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,6 @@ class DownloadViewModel @Inject constructor() : ViewModel() {
val showDownloadSettingDialog: Boolean = false,
val showFormatSelectionPage: Boolean = false,
val isUrlSharingTriggered: Boolean = false,
val isInDebugMode: Boolean = PreferenceUtil.getValue(DEBUG)
)

fun updateUrl(url: String, isUrlSharingTriggered: Boolean = false) =
Expand All @@ -77,12 +76,6 @@ class DownloadViewModel @Inject constructor() : ViewModel() {
fun startDownloadVideo() {
val url = viewStateFlow.value.url
Downloader.clearErrorState()
mutableViewStateFlow.update {
it.copy(
isInDebugMode =
PreferenceUtil.getValue(DEBUG, true)
)
}
if (!PreferenceUtil.isNetworkAvailableForDownload()) {
showErrorMessage(R.string.download_disabled_with_cellular)
return
Expand Down

0 comments on commit 2627b06

Please sign in to comment.