Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,16 @@
<!-- </intent-filter>-->
<!-- </receiver>-->

<service
android:name=".util.StashDreamService"
android:exported="false"
android:label="@string/app_name"
android:permission="android.permission.BIND_DREAM_SERVICE">
<intent-filter>
<action android:name="android.service.dreams.DreamService" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</service>
</application>

</manifest>
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ class CreateFilterViewModel : ViewModel() {
this.filterName.value = initialFilter?.name

// Fetch all of the labels for any existing IDs in the initial object filter
viewModelScope.launch(StashCoroutineExceptionHandler()) {
viewModelScope.launch(StashCoroutineExceptionHandler(autoToast = true)) {
getIdsByDataType(dataType, objectFilter.value!!).entries.forEach {
val dt = it.key
val ids = it.value
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ fun BasicFilterSettings(
findFilterInteractionSource: MutableInteractionSource,
objectFilterInteractionSource: MutableInteractionSource,
onSubmit: (Boolean) -> Unit,
saveEnabled: Boolean,
modifier: Modifier = Modifier,
) {
val context = LocalContext.current
Expand All @@ -45,14 +46,16 @@ fun BasicFilterSettings(
.focusRestorer(focusRequester),
verticalArrangement = Arrangement.spacedBy(0.dp),
) {
item {
SimpleListItem(
title = stringResource(R.string.stashapp_filter_name),
subtitle = name,
showArrow = false,
onClick = onFilterNameClick,
modifier = Modifier.focusRequester(focusRequester),
)
if (saveEnabled) {
item {
SimpleListItem(
title = stringResource(R.string.stashapp_filter_name),
subtitle = name,
showArrow = false,
onClick = onFilterNameClick,
modifier = Modifier.focusRequester(focusRequester),
)
}
}
item {
SimpleListItem(
Expand Down Expand Up @@ -82,7 +85,14 @@ fun BasicFilterSettings(
}
item {
SimpleListItem(
title = stringResource(R.string.submit_without_saving),
title =
if (saveEnabled) {
stringResource(R.string.submit_without_saving)
} else {
stringResource(
R.string.stashapp_actions_submit,
)
},
subtitle =
if (resultCount >= 0) {
resultCount.toString() + " " + stringResource(R.string.results)
Expand All @@ -93,19 +103,21 @@ fun BasicFilterSettings(
onClick = { onSubmit.invoke(false) },
)
}
item {
SimpleListItem(
enabled = name.isNotNullOrBlank(),
title = stringResource(R.string.save_and_submit),
subtitle =
if (name.isNotNullOrBlank()) {
null
} else {
stringResource(R.string.save_and_submit_no_name_desc)
},
showArrow = false,
onClick = { onSubmit.invoke(true) },
)
if (saveEnabled) {
item {
SimpleListItem(
enabled = name.isNotNullOrBlank(),
title = stringResource(R.string.save_and_submit),
subtitle =
if (name.isNotNullOrBlank()) {
null
} else {
stringResource(R.string.save_and_submit_no_name_desc)
},
showArrow = false,
onClick = { onSubmit.invoke(true) },
)
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -81,9 +81,49 @@ fun CreateFilterScreen(
onUpdateTitle: ((AnnotatedString) -> Unit)? = null,
viewModel: CreateFilterViewModel = viewModel(),
) {
val context = LocalContext.current
val server = LocalGlobalContext.current.server
val scope = rememberCoroutineScope()
CreateFilterContent(
uiConfig = uiConfig,
dataType = dataType,
initialFilter = initialFilter,
saveEnabled = true,
onSubmit = { save, filterArgs ->
if (save) {
scope.launch(
LoggingCoroutineExceptionHandler(
server,
scope,
toastMessage = "Error saving filter",
),
) {
viewModel.saveFilter()
navigationManager.goBack()
navigationManager.navigate(Destination.Filter(filterArgs))
}
} else {
navigationManager.goBack()
navigationManager.navigate(Destination.Filter(filterArgs))
}
},
modifier = modifier,
onUpdateTitle = onUpdateTitle,
viewModel = viewModel,
)
}

@Composable
fun CreateFilterContent(
uiConfig: ComposeUiConfig,
dataType: DataType,
initialFilter: FilterArgs?,
saveEnabled: Boolean,
onSubmit: (save: Boolean, filter: FilterArgs) -> Unit,
modifier: Modifier = Modifier,
onUpdateTitle: ((AnnotatedString) -> Unit)? = null,
viewModel: CreateFilterViewModel = viewModel(),
) {
val context = LocalContext.current

val ready by viewModel.ready.observeAsState(false)
val name by viewModel.filterName.observeAsState()
Expand Down Expand Up @@ -133,23 +173,9 @@ fun CreateFilterScreen(
},
idLookup = viewModel::lookupIds,
idStore = viewModel::store,
saveEnabled = saveEnabled,
onSubmit = { save ->
if (save) {
scope.launch(
LoggingCoroutineExceptionHandler(
server,
scope,
toastMessage = "Error saving filter",
),
) {
viewModel.saveFilter()
navigationManager.goBack()
navigationManager.navigate(Destination.Filter(viewModel.createFilterArgs()))
}
} else {
navigationManager.goBack()
navigationManager.navigate(Destination.Filter(viewModel.createFilterArgs()))
}
onSubmit.invoke(save, viewModel.createFilterArgs())
},
modifier =
Modifier
Expand All @@ -175,6 +201,7 @@ fun CreateFilterColumns(
idLookup: (DataType, List<String>) -> Map<String, CreateFilterViewModel.NameDescription?>,
idStore: (DataType, StashData) -> Unit,
onSubmit: (Boolean) -> Unit,
saveEnabled: Boolean,
modifier: Modifier = Modifier,
) {
val findFilterInteractionSource = remember { MutableInteractionSource() }
Expand Down Expand Up @@ -318,6 +345,7 @@ fun CreateFilterColumns(
findFilterInteractionSource = findFilterInteractionSource,
objectFilterInteractionSource = objectFilterInteractionSource,
onSubmit = onSubmit,
saveEnabled = saveEnabled,
modifier =
Modifier
.width(listWidth)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,8 @@ import com.github.damontecres.stashapp.R
import com.github.damontecres.stashapp.RootActivity
import com.github.damontecres.stashapp.navigation.Destination
import com.github.damontecres.stashapp.navigation.NavigationManager
import com.github.damontecres.stashapp.proto.StashPreferences
import com.github.damontecres.stashapp.ui.ComposeUiConfig
import com.github.damontecres.stashapp.ui.components.screensaver.ChooseScreensaverFilterDialog
import com.github.damontecres.stashapp.ui.tryRequestFocus
import com.github.damontecres.stashapp.ui.util.ifElse
import com.github.damontecres.stashapp.ui.util.playOnClickSound
Expand Down Expand Up @@ -166,6 +167,13 @@ val advancedPreferences =
StashPreference.DirectPlayFormat,
),
),
PreferenceGroup(
R.string.screensaver,
listOf(
StashPreference.ScreensaverEnable,
StashPreference.ScreensaverFilter,
),
),
PreferenceGroup(
R.string.effects_filters,
listOf(
Expand Down Expand Up @@ -223,7 +231,7 @@ val advancedPreferences =
fun PreferencesContent(
server: StashServer,
navigationManager: NavigationManager,
initialPreferences: StashPreferences,
uiConfig: ComposeUiConfig,
preferenceScreenOption: PreferenceScreenOption,
modifier: Modifier = Modifier,
onUpdateTitle: ((AnnotatedString) -> Unit)? = null,
Expand All @@ -234,7 +242,7 @@ fun PreferencesContent(
val focusRequester = remember { FocusRequester() }
var focusedIndex by rememberSaveable { mutableStateOf(Pair(0, 0)) }
val state = rememberLazyListState()
var preferences by remember { mutableStateOf(initialPreferences) }
var preferences by remember { mutableStateOf(uiConfig.preferences) }
val sharedPrefs = remember { PreferenceManager.getDefaultSharedPreferences(context) }
LaunchedEffect(Unit) {
context.preferences.data.collect {
Expand Down Expand Up @@ -282,6 +290,8 @@ fun PreferencesContent(
visible = true
}

var showScreensaverFilterDialog by remember { mutableStateOf(false) }

AnimatedVisibility(
visible = visible,
enter = fadeIn() + slideInHorizontally { it / 2 },
Expand Down Expand Up @@ -439,6 +449,22 @@ fun PreferencesContent(
)
}

StashPreference.ScreensaverFilter -> {
ClickPreference(
title = stringResource(pref.title),
onClick = {
showScreensaverFilterDialog = true
},
interactionSource = interactionSource,
modifier =
Modifier
.ifElse(
groupIndex == focusedIndex.first && prefIndex == focusedIndex.second,
Modifier.focusRequester(focusRequester),
),
)
}

else -> {
val value = pref.getter.invoke(preferences)
ComposablePreference(
Expand Down Expand Up @@ -527,6 +553,12 @@ fun PreferencesContent(
}
}
}
if (showScreensaverFilterDialog) {
ChooseScreensaverFilterDialog(
uiConfig = uiConfig,
onDismissRequest = { showScreensaverFilterDialog = false },
)
}
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
package com.github.damontecres.stashapp.ui.components.prefs

import android.content.ComponentName
import android.content.Context
import android.content.SharedPreferences
import android.content.pm.PackageManager
import android.util.Log
import androidx.annotation.ArrayRes
import androidx.annotation.StringRes
Expand All @@ -19,13 +21,15 @@ import com.github.damontecres.stashapp.proto.StashPreferences
import com.github.damontecres.stashapp.proto.StreamChoice
import com.github.damontecres.stashapp.proto.TabType
import com.github.damontecres.stashapp.proto.ThemeStyle
import com.github.damontecres.stashapp.util.StashDreamService
import com.github.damontecres.stashapp.util.cacheDurationPrefToDuration
import com.github.damontecres.stashapp.util.isNotNullOrBlank
import com.github.damontecres.stashapp.util.updateAdvancedPreferences
import com.github.damontecres.stashapp.util.updateCachePreferences
import com.github.damontecres.stashapp.util.updateInterfacePreferences
import com.github.damontecres.stashapp.util.updatePinPreferences
import com.github.damontecres.stashapp.util.updatePlaybackPreferences
import com.github.damontecres.stashapp.util.updateScreensaverPreferences
import com.github.damontecres.stashapp.util.updateSearchPreferences
import com.github.damontecres.stashapp.util.updateTabPreferences
import com.github.damontecres.stashapp.util.updateUpdatePreferences
Expand Down Expand Up @@ -1424,6 +1428,37 @@ sealed interface StashPreference<T> {
title = R.string.migrate_preferences,
summary = R.string.migrate_preferences_summary,
)

// Screensaver
val ScreensaverEnable =
StashSwitchPreference(
title = R.string.enable_screensaver,
prefKey = R.string.pref_key_screensaver_enabled,
defaultValue = false,
getter = { it.screensaverPreferences.enabled },
setter = { prefs, value ->
val pm: PackageManager = StashApplication.getApplication().packageManager
val componentName =
ComponentName(
StashApplication.getApplication(),
StashDreamService::class.java,
)
val newState =
if (value) PackageManager.COMPONENT_ENABLED_STATE_ENABLED else PackageManager.COMPONENT_ENABLED_STATE_DISABLED
pm.setComponentEnabledSetting(
componentName,
newState,
PackageManager.DONT_KILL_APP,
)
prefs.updateScreensaverPreferences { enabled = value }
},
summaryOn = R.string.stashapp_actions_enable,
summaryOff = R.string.transcode_options_disabled,
)
val ScreensaverFilter =
StashClickablePreference(
title = R.string.screensaver_filter,
)
}
}

Expand Down
Loading
Loading