Skip to content

Commit 9f495f8

Browse files
ComicSASShiftHackZ
andauthored
Export input image to gallery (#215)
* Added option to save input image to gallery from detail when generating via img2img * Hiding export button on Detail Info tab * Apply fade in/out to export icon --------- Co-authored-by: ShiftHackZ <[email protected]>
1 parent b414a13 commit 9f495f8

File tree

2 files changed

+31
-13
lines changed

2 files changed

+31
-13
lines changed

presentation/src/main/java/com/shifthackz/aisdv1/presentation/screen/gallery/detail/GalleryDetailScreen.kt

Lines changed: 20 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@
22

33
package com.shifthackz.aisdv1.presentation.screen.gallery.detail
44

5+
import androidx.compose.animation.AnimatedVisibility
6+
import androidx.compose.animation.fadeIn
7+
import androidx.compose.animation.fadeOut
58
import androidx.compose.foundation.Image
69
import androidx.compose.foundation.background
710
import androidx.compose.foundation.layout.Arrangement
@@ -126,17 +129,23 @@ private fun ScreenContent(
126129
)
127130
},
128131
actions = {
129-
IconButton(
130-
onClick = { processIntent(GalleryDetailIntent.Export.Image) },
131-
content = {
132-
Image(
133-
modifier = Modifier.size(24.dp),
134-
painter = painterResource(id = R.drawable.ic_share),
135-
contentDescription = "Export",
136-
colorFilter = ColorFilter.tint(LocalContentColor.current),
137-
)
138-
},
139-
)
132+
AnimatedVisibility(
133+
visible = state.selectedTab != GalleryDetailState.Tab.INFO,
134+
enter = fadeIn(),
135+
exit = fadeOut(),
136+
) {
137+
IconButton(
138+
onClick = { processIntent(GalleryDetailIntent.Export.Image) },
139+
content = {
140+
Image(
141+
modifier = Modifier.size(24.dp),
142+
painter = painterResource(id = R.drawable.ic_share),
143+
contentDescription = "Export",
144+
colorFilter = ColorFilter.tint(LocalContentColor.current),
145+
)
146+
},
147+
)
148+
}
140149
}
141150
)
142151
},

presentation/src/main/java/com/shifthackz/aisdv1/presentation/screen/gallery/detail/GalleryDetailViewModel.kt

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -79,8 +79,17 @@ class GalleryDetailViewModel(
7979
}
8080

8181
private fun share() {
82-
if (currentState !is GalleryDetailState.Content) return
83-
!galleryDetailBitmapExporter((currentState as GalleryDetailState.Content).bitmap)
82+
val state = currentState as? GalleryDetailState.Content ?: return
83+
val bitmap = if (
84+
state.generationType == AiGenerationResult.Type.IMAGE_TO_IMAGE
85+
&& state.inputBitmap != null
86+
&& state.selectedTab == GalleryDetailState.Tab.ORIGINAL
87+
) {
88+
state.inputBitmap
89+
} else {
90+
state.bitmap
91+
}
92+
!galleryDetailBitmapExporter(bitmap)
8493
.subscribeOnMainThread(schedulersProvider)
8594
.subscribeBy(::errorLog) { file ->
8695
emitEffect(GalleryDetailEffect.ShareImageFile(file))

0 commit comments

Comments
 (0)