-
-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[feature] Support #43, merge multiple stickers
- Loading branch information
Showing
20 changed files
with
762 additions
and
24 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
47 changes: 47 additions & 0 deletions
47
app/src/main/java/com/skyd/rays/model/respository/MergeStickersRepository.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
package com.skyd.rays.model.respository | ||
|
||
import com.skyd.rays.base.BaseRepository | ||
import com.skyd.rays.model.bean.StickerWithTags | ||
import com.skyd.rays.model.db.dao.sticker.StickerDao | ||
import com.skyd.rays.util.stickerUuidToFile | ||
import com.skyd.rays.util.stickerUuidToUri | ||
import kotlinx.coroutines.Dispatchers | ||
import kotlinx.coroutines.flow.Flow | ||
import kotlinx.coroutines.flow.collect | ||
import kotlinx.coroutines.flow.flow | ||
import kotlinx.coroutines.flow.flowOn | ||
import java.util.UUID | ||
import javax.inject.Inject | ||
|
||
class MergeStickersRepository @Inject constructor( | ||
private val stickerDao: StickerDao, | ||
private val addRepo: AddRepository, | ||
private val searchRepo: SearchRepository, | ||
) : BaseRepository() { | ||
fun requestStickers(stickerUuids: List<String>): Flow<List<StickerWithTags>> = flow { | ||
emit(stickerDao.getAllStickerWithTagsList(stickerUuids)) | ||
}.flowOn(Dispatchers.IO) | ||
|
||
fun requestMerge( | ||
oldStickerUuid: String, | ||
sticker: StickerWithTags, | ||
deleteUuids: List<String>, | ||
): Flow<Unit> { | ||
return flow { | ||
val stickerFile = stickerUuidToFile(oldStickerUuid) | ||
check(stickerFile.exists()) | ||
if (sticker.sticker.uuid == oldStickerUuid) { | ||
sticker.sticker.uuid = UUID.randomUUID().toString() | ||
} | ||
val newStickerFile = stickerUuidToFile(sticker.sticker.uuid) | ||
stickerFile.copyTo(newStickerFile) | ||
check(newStickerFile.exists()) | ||
|
||
searchRepo.requestDeleteStickerWithTagsDetail(deleteUuids).collect() | ||
addRepo.requestAddStickerWithTags(sticker, stickerUuidToUri(sticker.sticker.uuid)) | ||
.collect() | ||
|
||
emit(Unit) | ||
}.flowOn(Dispatchers.IO) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
10 changes: 10 additions & 0 deletions
10
app/src/main/java/com/skyd/rays/ui/screen/mergestickers/MergeStickersEvent.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
package com.skyd.rays.ui.screen.mergestickers | ||
|
||
import com.skyd.rays.base.mvi.MviSingleEvent | ||
|
||
sealed interface MergeStickersEvent : MviSingleEvent { | ||
sealed interface MergeResult : MergeStickersEvent { | ||
data object Success : MergeResult | ||
data class Failed(val msg: String) : MergeResult | ||
} | ||
} |
16 changes: 16 additions & 0 deletions
16
app/src/main/java/com/skyd/rays/ui/screen/mergestickers/MergeStickersIntent.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
package com.skyd.rays.ui.screen.mergestickers | ||
|
||
import com.skyd.rays.base.mvi.MviIntent | ||
import com.skyd.rays.model.bean.StickerWithTags | ||
|
||
sealed interface MergeStickersIntent : MviIntent { | ||
data class Init(val stickers: List<String>) : MergeStickersIntent | ||
data class Merge( | ||
val oldStickerUuid: String, | ||
val sticker: StickerWithTags, | ||
val deleteUuids: List<String>, | ||
) : MergeStickersIntent | ||
data class RemoveSelectedTag(val tag: String) : MergeStickersIntent | ||
data class AddSelectedTag(val tag: String) : MergeStickersIntent | ||
data class ReplaceAllSelectedTags(val tags: List<String>) : MergeStickersIntent | ||
} |
61 changes: 61 additions & 0 deletions
61
app/src/main/java/com/skyd/rays/ui/screen/mergestickers/MergeStickersPartialStateChange.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
package com.skyd.rays.ui.screen.mergestickers | ||
|
||
import com.skyd.rays.model.bean.StickerWithTags | ||
|
||
internal sealed interface MergeStickersPartialStateChange { | ||
fun reduce(oldState: MergeStickersState): MergeStickersState | ||
|
||
data object LoadingDialog : MergeStickersPartialStateChange { | ||
override fun reduce(oldState: MergeStickersState) = oldState.copy(loadingDialog = true) | ||
} | ||
|
||
sealed interface Init : MergeStickersPartialStateChange { | ||
override fun reduce(oldState: MergeStickersState): MergeStickersState { | ||
return when (this) { | ||
is Success -> oldState.copy( | ||
stickersState = StickersState.Success(stickersList), | ||
selectedTags = stickersList.map { sticker -> | ||
sticker.tags.map { it.tag } | ||
}.flatten().distinct(), | ||
loadingDialog = false, | ||
) | ||
|
||
is Failed -> oldState.copy( | ||
stickersState = StickersState.Failed(msg), | ||
loadingDialog = false, | ||
) | ||
} | ||
} | ||
|
||
data class Success(val stickersList: List<StickerWithTags>) : Init | ||
data class Failed(val msg: String) : Init | ||
} | ||
|
||
sealed interface Merge : MergeStickersPartialStateChange { | ||
override fun reduce(oldState: MergeStickersState): MergeStickersState = | ||
oldState.copy(loadingDialog = false) | ||
|
||
data object Success : Merge | ||
data class Failed(val msg: String) : Merge | ||
} | ||
|
||
data class RemoveSelectedTag(val tag: String) : MergeStickersPartialStateChange { | ||
override fun reduce(oldState: MergeStickersState) = oldState.copy( | ||
selectedTags = oldState.selectedTags.toMutableList().apply { remove(tag) } | ||
) | ||
} | ||
|
||
data class AddSelectedTag(val tag: String) : MergeStickersPartialStateChange { | ||
override fun reduce(oldState: MergeStickersState) = oldState.copy( | ||
selectedTags = oldState.selectedTags.toMutableList().apply { | ||
if (tag !in this) add(tag) | ||
} | ||
) | ||
} | ||
|
||
data class ReplaceAllSelectedTags(val tags: List<String>) : MergeStickersPartialStateChange { | ||
override fun reduce(oldState: MergeStickersState) = oldState.copy( | ||
selectedTags = tags | ||
) | ||
} | ||
} |
Oops, something went wrong.