diff --git a/feature/single-edit/src/main/java/ru/tech/imageresizershrinker/feature/single_edit/presentation/SingeEditScreen.kt b/feature/single-edit/src/main/java/ru/tech/imageresizershrinker/feature/single_edit/presentation/SingeEditScreen.kt index e35f91608c..9c295980d3 100644 --- a/feature/single-edit/src/main/java/ru/tech/imageresizershrinker/feature/single_edit/presentation/SingeEditScreen.kt +++ b/feature/single-edit/src/main/java/ru/tech/imageresizershrinker/feature/single_edit/presentation/SingeEditScreen.kt @@ -497,7 +497,9 @@ fun SingleEditContent( drawPathMode = viewModel.drawPathMode, onUpdateDrawPathMode = viewModel::updateDrawPathMode, drawLineStyle = viewModel.drawLineStyle, - onUpdateDrawLineStyle = viewModel::updateDrawLineStyle + onUpdateDrawLineStyle = viewModel::updateDrawLineStyle, + helperGridParams = viewModel.helperGridParams, + onUpdateHelperGridParams = viewModel::updateHelperGridParams ) EraseBackgroundEditOption( diff --git a/feature/single-edit/src/main/java/ru/tech/imageresizershrinker/feature/single_edit/presentation/components/DrawEditOption.kt b/feature/single-edit/src/main/java/ru/tech/imageresizershrinker/feature/single_edit/presentation/components/DrawEditOption.kt index db4d0a6e9f..067c8db4a4 100644 --- a/feature/single-edit/src/main/java/ru/tech/imageresizershrinker/feature/single_edit/presentation/components/DrawEditOption.kt +++ b/feature/single-edit/src/main/java/ru/tech/imageresizershrinker/feature/single_edit/presentation/components/DrawEditOption.kt @@ -82,6 +82,8 @@ import ru.tech.imageresizershrinker.core.ui.widget.buttons.EnhancedIconButton import ru.tech.imageresizershrinker.core.ui.widget.buttons.EraseModeButton import ru.tech.imageresizershrinker.core.ui.widget.buttons.PanModeButton import ru.tech.imageresizershrinker.core.ui.widget.controls.selection.AlphaSelector +import ru.tech.imageresizershrinker.core.ui.widget.controls.selection.HelperGridParamsSelector +import ru.tech.imageresizershrinker.core.ui.widget.modifier.HelperGridParams import ru.tech.imageresizershrinker.core.ui.widget.modifier.container import ru.tech.imageresizershrinker.core.ui.widget.other.DrawLockScreenOrientation import ru.tech.imageresizershrinker.core.ui.widget.other.EnhancedTopAppBar @@ -125,6 +127,8 @@ fun DrawEditOption( lastPaths: List, undonePaths: List, addPath: (UiPathPaint) -> Unit, + helperGridParams: HelperGridParams, + onUpdateHelperGridParams: (HelperGridParams) -> Unit, ) { bitmap?.let { var panEnabled by rememberSaveable { mutableStateOf(false) } @@ -355,6 +359,11 @@ fun DrawEditOption( value = drawLineStyle, onValueChange = onUpdateDrawLineStyle ) + HelperGridParamsSelector( + value = helperGridParams, + onValueChange = onUpdateHelperGridParams, + modifier = Modifier.padding(horizontal = 16.dp) + ) val settingsInteractor = LocalSimpleSettingsInteractor.current val scope = rememberCoroutineScope() PreferenceRowSwitch( @@ -448,7 +457,8 @@ fun DrawEditOption( }, drawPathMode = drawPathMode, backgroundColor = Color.Transparent, - drawLineStyle = drawLineStyle + drawLineStyle = drawLineStyle, + helperGridParams = helperGridParams ) } } diff --git a/feature/single-edit/src/main/java/ru/tech/imageresizershrinker/feature/single_edit/presentation/viewModel/SingleEditViewModel.kt b/feature/single-edit/src/main/java/ru/tech/imageresizershrinker/feature/single_edit/presentation/viewModel/SingleEditViewModel.kt index d346175ad4..f70ed444bd 100644 --- a/feature/single-edit/src/main/java/ru/tech/imageresizershrinker/feature/single_edit/presentation/viewModel/SingleEditViewModel.kt +++ b/feature/single-edit/src/main/java/ru/tech/imageresizershrinker/feature/single_edit/presentation/viewModel/SingleEditViewModel.kt @@ -64,6 +64,7 @@ import ru.tech.imageresizershrinker.core.settings.domain.SettingsProvider import ru.tech.imageresizershrinker.core.ui.utils.BaseViewModel import ru.tech.imageresizershrinker.core.ui.utils.helper.ImageUtils.safeAspectRatio import ru.tech.imageresizershrinker.core.ui.utils.state.update +import ru.tech.imageresizershrinker.core.ui.widget.modifier.HelperGridParams import ru.tech.imageresizershrinker.feature.draw.domain.DrawLineStyle import ru.tech.imageresizershrinker.feature.draw.domain.DrawMode import ru.tech.imageresizershrinker.feature.draw.domain.DrawPathMode @@ -83,7 +84,7 @@ class SingleEditViewModel @Inject constructor( private val shareProvider: ShareProvider, private val filterProvider: FilterProvider, private val settingsProvider: SettingsProvider, - dispatchersHolder: DispatchersHolder + dispatchersHolder: DispatchersHolder, ) : BaseViewModel(dispatchersHolder) { private val _originalSize: MutableState = mutableStateOf(null) @@ -172,6 +173,10 @@ class SingleEditViewModel @Inject constructor( private val _drawLineStyle: MutableState = mutableStateOf(DrawLineStyle.None) val drawLineStyle: DrawLineStyle by _drawLineStyle + private val _helperGridParams: MutableState = + mutableStateOf(HelperGridParams()) + val helperGridParams: HelperGridParams by _helperGridParams + init { viewModelScope.launch { val settingsState = settingsProvider.getSettingsState() @@ -180,6 +185,13 @@ class SingleEditViewModel @Inject constructor( it.copy(resizeType = settingsState.defaultResizeType) } } + viewModelScope.launch { + val params = fileController.restoreObject( + "helperGridParams", + HelperGridParams::class + ) ?: HelperGridParams() + _helperGridParams.update { params } + } } private var job: Job? by smartJob { @@ -233,7 +245,7 @@ class SingleEditViewModel @Inject constructor( } private suspend fun updatePreview( - bitmap: Bitmap + bitmap: Bitmap, ): Bitmap? = withContext(defaultDispatcher) { return@withContext imageInfo.run { _showWarning.update { @@ -281,7 +293,7 @@ class SingleEditViewModel @Inject constructor( fun updateBitmapAfterEditing( bitmap: Bitmap?, - saveOriginalSize: Boolean = false + saveOriginalSize: Boolean = false, ) { viewModelScope.launch { if (!saveOriginalSize) { @@ -424,7 +436,7 @@ class SingleEditViewModel @Inject constructor( fun decodeBitmapByUri( uri: Uri, - onError: (Throwable) -> Unit + onError: (Throwable) -> Unit, ) { _isImageLoading.update { true } _imageInfo.update { @@ -541,7 +553,7 @@ class SingleEditViewModel @Inject constructor( fun updateExifByTag( tag: MetadataTag, - value: String + value: String, ) { val exifInterface = _exif.value exifInterface?.setAttribute(tag.key, value) @@ -550,7 +562,7 @@ class SingleEditViewModel @Inject constructor( fun setCropAspectRatio( domainAspectRatio: DomainAspectRatio, - aspectRatio: AspectRatio + aspectRatio: AspectRatio, ) { _cropProperties.update { properties -> properties.copy( @@ -577,7 +589,7 @@ class SingleEditViewModel @Inject constructor( fun updateFilter( value: T, index: Int, - showError: (Throwable) -> Unit + showError: (Throwable) -> Unit, ) { val list = _filterList.value.toMutableList() runCatching { @@ -705,14 +717,14 @@ class SingleEditViewModel @Inject constructor( suspend fun filter( bitmap: Bitmap, - filters: List> + filters: List>, ): Bitmap? = imageTransformer.transform( image = bitmap, transformations = mapFilters(filters) ) fun mapFilters( - filters: List> + filters: List>, ): List> = filters.map { filterProvider.filterToTransformation(it) } fun updateDrawMode(drawMode: DrawMode) { @@ -733,4 +745,18 @@ class SingleEditViewModel @Inject constructor( _drawLineStyle.update { style } } + private var smartSavingJob: Job? by smartJob() + + fun updateHelperGridParams(params: HelperGridParams) { + _helperGridParams.update { params } + + smartSavingJob = viewModelScope.launch { + delay(200) + fileController.saveObject( + key = "helperGridParams", + value = params + ) + } + } + }