Skip to content

Commit 962c9b6

Browse files
authored
Gallery Image visibility toggle (#355)
* Gallery Image visibility toggle * Fix txt2img, img2img software keyboard state Set toggle input to false by default
1 parent f898885 commit 962c9b6

File tree

37 files changed

+516
-21
lines changed

37 files changed

+516
-21
lines changed

data/src/main/java/com/shifthackz/aisdv1/data/mappers/AiGenerationResultMappers.kt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ fun AiGenerationResult.mapDomainToEntity(): GenerationResultEntity = with(this)
2626
subSeed = subSeed,
2727
subSeedStrength = subSeedStrength,
2828
denoisingStrength = denoisingStrength,
29+
hidden = hidden,
2930
)
3031
}
3132
//endregion
@@ -53,6 +54,7 @@ fun GenerationResultEntity.mapEntityToDomain(): AiGenerationResult = with(this)
5354
subSeed = subSeed,
5455
subSeedStrength = subSeedStrength,
5556
denoisingStrength = denoisingStrength,
57+
hidden = hidden,
5658
)
5759
}
5860
//endregion

data/src/main/java/com/shifthackz/aisdv1/data/mappers/ImageToImagePayloadMappers.kt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,7 @@ fun Pair<ImageToImagePayload, SdGenerationResponse>.mapToAiGenResult(): AiGenera
142142
subSeed = if (payload.subSeed.trim().isNotEmpty()) payload.subSeed
143143
else mapSubSeedFromRemote(response.info),
144144
subSeedStrength = payload.subSeedStrength,
145+
hidden = false,
145146
)
146147
}
147148

@@ -165,6 +166,7 @@ fun Pair<ImageToImagePayload, String>.mapCloudToAiGenResult(): AiGenerationResul
165166
seed = payload.seed,
166167
subSeed = payload.subSeed,
167168
subSeedStrength = payload.subSeedStrength,
169+
hidden = false,
168170
)
169171
}
170172
//endregion

data/src/main/java/com/shifthackz/aisdv1/data/mappers/TextToImagePayloadMappers.kt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,7 @@ fun Pair<TextToImagePayload, SdGenerationResponse>.mapToAiGenResult(): AiGenerat
143143
subSeed = if (payload.subSeed.trim().isNotEmpty()) payload.subSeed
144144
else mapSubSeedFromRemote(response.info),
145145
subSeedStrength = payload.subSeedStrength,
146+
hidden = false,
146147
)
147148
}
148149

@@ -166,6 +167,7 @@ fun Pair<TextToImagePayload, String>.mapCloudToAiGenResult(): AiGenerationResult
166167
seed = payload.seed,
167168
subSeed = payload.subSeed,
168169
subSeedStrength = payload.subSeedStrength,
170+
hidden = false,
169171
)
170172
}
171173

@@ -189,6 +191,7 @@ fun Pair<TextToImagePayload, String>.mapLocalDiffusionToAiGenResult(): AiGenerat
189191
seed = payload.seed,
190192
subSeed = payload.subSeed,
191193
subSeedStrength = payload.subSeedStrength,
194+
hidden = false,
192195
)
193196
}
194197
//endregion

data/src/main/java/com/shifthackz/aisdv1/data/preference/PreferenceManagerImpl.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ class PreferenceManagerImpl(
107107

108108
override var formPromptTaggedInput: Boolean by preferences.delegates.boolean(
109109
key = KEY_FORM_PROMPT_TAGGED_INPUT,
110-
default = true,
110+
default = false,
111111
onChanged = ::onPreferencesChanged,
112112
)
113113

@@ -274,7 +274,7 @@ class PreferenceManagerImpl(
274274
const val KEY_AI_AUTO_SAVE = "key_ai_auto_save"
275275
const val KEY_SAVE_TO_MEDIA_STORE = "key_save_to_media_store"
276276
const val KEY_FORM_ALWAYS_SHOW_ADVANCED_OPTIONS = "key_always_show_advanced_options"
277-
const val KEY_FORM_PROMPT_TAGGED_INPUT = "key_prompt_tagged_input"
277+
const val KEY_FORM_PROMPT_TAGGED_INPUT = "key_prompt_tagged_input_kb"
278278
const val KEY_SERVER_SOURCE = "key_server_source"
279279
const val KEY_SD_MODEL = "key_sd_model"
280280
const val KEY_HORDE_API_KEY = "key_horde_api_key"

data/src/main/java/com/shifthackz/aisdv1/data/repository/GenerationResultRepositoryImpl.kt

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,4 +39,11 @@ internal class GenerationResultRepositoryImpl(
3939
override fun deleteByIdList(idList: List<Long>) = localDataSource.deleteByIdList(idList)
4040

4141
override fun deleteAll() = localDataSource.deleteAll()
42+
43+
override fun toggleVisibility(id: Long): Single<Boolean> = localDataSource
44+
.queryById(id)
45+
.map { it.copy(hidden = !it.hidden) }
46+
.flatMap(localDataSource::insert)
47+
.flatMap { localDataSource.queryById(id) }
48+
.map(AiGenerationResult::hidden)
4249
}

data/src/test/java/com/shifthackz/aisdv1/data/mocks/AiGenerationResultMocks.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ val mockAiGenerationResult = AiGenerationResult(
2121
subSeed = "1504",
2222
subSeedStrength = 5598f,
2323
denoisingStrength = 1504f,
24+
hidden = false,
2425
)
2526

2627
val mockAiGenerationResults = listOf(mockAiGenerationResult)

data/src/test/java/com/shifthackz/aisdv1/data/mocks/GenerationResultEntityMocks.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ val mockGenerationResultEntity = GenerationResultEntity(
2222
subSeed = "1504",
2323
subSeedStrength = 5598f,
2424
denoisingStrength = 1504f,
25+
hidden = false,
2526
)
2627

2728
val mockGenerationResultEntities = listOf(mockGenerationResultEntity)

data/src/test/java/com/shifthackz/aisdv1/data/repository/GenerationResultRepositoryImplTest.kt

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -299,4 +299,40 @@ class GenerationResultRepositoryImplTest {
299299
.await()
300300
.assertNotComplete()
301301
}
302+
303+
@Test
304+
fun `given attempt to toggle image visibility, process succeeds, expected boolean value`() {
305+
every {
306+
stubLocalDataSource.queryById(any())
307+
} returns Single.just(mockAiGenerationResult)
308+
309+
every {
310+
stubLocalDataSource.insert(any())
311+
} returns Single.just(5598L)
312+
313+
repository
314+
.toggleVisibility(5598L)
315+
.test()
316+
.await()
317+
.assertComplete()
318+
}
319+
320+
@Test
321+
fun `given attempt to toggle image visibility, error occurs, expected boolean value`() {
322+
every {
323+
stubLocalDataSource.queryById(any())
324+
} returns Single.just(mockAiGenerationResult)
325+
326+
every {
327+
stubLocalDataSource.insert(any())
328+
} returns Single.error(stubException)
329+
330+
repository
331+
.toggleVisibility(5598L)
332+
.test()
333+
.assertError(stubException)
334+
.assertNoValues()
335+
.await()
336+
.assertNotComplete()
337+
}
302338
}

demo/src/main/java/com/shifthackz/aisdv1/demo/ImageToImageDemoImpl.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ internal class ImageToImageDemoImpl(
2929
subSeed = timeProvider.currentTimeMillis().toString(),
3030
subSeedStrength = 0f,
3131
denoisingStrength = 0f,
32+
hidden = false,
3233
)
3334

3435
override fun getDemoBase64(payload: ImageToImagePayload) = execute(payload)

demo/src/main/java/com/shifthackz/aisdv1/demo/TextToImageDemoImpl.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ internal class TextToImageDemoImpl(
2929
subSeed = timeProvider.currentTimeMillis().toString(),
3030
subSeedStrength = 0f,
3131
denoisingStrength = 0f,
32+
hidden = false,
3233
)
3334

3435
override fun getDemoBase64(payload: TextToImagePayload) = execute(payload)

0 commit comments

Comments
 (0)