-
-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
28 changed files
with
1,139 additions
and
23 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
23 changes: 23 additions & 0 deletions
23
app/src/main/java/com/skyd/rays/model/bean/ImportExportInfo.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,23 @@ | ||
package com.skyd.rays.model.bean | ||
|
||
import android.net.Uri | ||
import android.os.Parcelable | ||
import androidx.annotation.Keep | ||
import kotlinx.parcelize.Parcelize | ||
|
||
@Keep | ||
sealed interface ImportExportInfo : BaseBean | ||
|
||
@Parcelize | ||
data class ImportExportResultInfo( | ||
var time: Long, | ||
var count: Int, | ||
var backupFile: Uri, | ||
) : ImportExportInfo, Parcelable | ||
|
||
@Parcelize | ||
data class ImportExportWaitingInfo( | ||
var current: Int?, | ||
var total: Int?, | ||
var msg: String, | ||
) : ImportExportInfo, Parcelable |
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
88 changes: 88 additions & 0 deletions
88
app/src/main/java/com/skyd/rays/model/db/dao/sticker/HandleTagsProxy.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,88 @@ | ||
package com.skyd.rays.model.db.dao.sticker | ||
|
||
import android.os.Parcelable | ||
import com.skyd.rays.R | ||
import com.skyd.rays.appContext | ||
import com.skyd.rays.config.STICKER_DIR | ||
import com.skyd.rays.model.bean.StickerWithTags | ||
import com.skyd.rays.model.db.dao.TagDao | ||
import kotlinx.parcelize.Parcelize | ||
import java.io.File | ||
import java.util.UUID | ||
|
||
|
||
@Parcelize | ||
sealed interface HandleImportedStickerProxy : Parcelable { | ||
fun handle( | ||
stickerDao: StickerDao, | ||
tagDao: TagDao, | ||
importedStickerWithTags: StickerWithTags, | ||
stickerFile: File, | ||
): Boolean | ||
|
||
fun checkStickerWithTagsFormat(stickerWithTags: StickerWithTags) { | ||
check(stickerWithTags.sticker.stickerMd5.isNotBlank()) { "sticker's md5 is blank!" } | ||
UUID.fromString(stickerWithTags.sticker.uuid) | ||
} | ||
|
||
fun moveFile(stickerFile: File) { | ||
val destStickerFile = File(File(STICKER_DIR), stickerFile.name) | ||
stickerFile.renameTo(destStickerFile) | ||
} | ||
|
||
val displayName: String | ||
|
||
// 冲突则跳过 | ||
@Parcelize | ||
object SkipProxy : HandleImportedStickerProxy { | ||
override fun handle( | ||
stickerDao: StickerDao, | ||
tagDao: TagDao, | ||
importedStickerWithTags: StickerWithTags, | ||
stickerFile: File, | ||
): Boolean { | ||
checkStickerWithTagsFormat(importedStickerWithTags) | ||
val stickerUuid = importedStickerWithTags.sticker.uuid | ||
// 冲突跳过 | ||
if (stickerDao.containsByUuid(stickerUuid) != 0) { | ||
return false | ||
} | ||
moveFile(stickerFile) | ||
stickerDao.innerAddSticker(importedStickerWithTags.sticker) | ||
importedStickerWithTags.tags.forEach { | ||
it.stickerUuid = stickerUuid | ||
} | ||
tagDao.deleteTags(stickerUuid) | ||
tagDao.addTags(importedStickerWithTags.tags) | ||
return true | ||
} | ||
|
||
override val displayName: String | ||
get() = appContext.getString(R.string.handle_imported_sticker_proxy_skip) | ||
} | ||
|
||
// 冲突则覆盖 | ||
@Parcelize | ||
object ReplaceProxy : HandleImportedStickerProxy { | ||
override fun handle( | ||
stickerDao: StickerDao, | ||
tagDao: TagDao, | ||
importedStickerWithTags: StickerWithTags, | ||
stickerFile: File, | ||
): Boolean { | ||
checkStickerWithTagsFormat(importedStickerWithTags) | ||
val stickerUuid = importedStickerWithTags.sticker.uuid | ||
moveFile(stickerFile) | ||
stickerDao.innerAddSticker(importedStickerWithTags.sticker) | ||
importedStickerWithTags.tags.forEach { | ||
it.stickerUuid = stickerUuid | ||
} | ||
tagDao.deleteTags(stickerUuid) | ||
tagDao.addTags(importedStickerWithTags.tags) | ||
return true | ||
} | ||
|
||
override val displayName: String | ||
get() = appContext.getString(R.string.handle_imported_sticker_proxy_replace) | ||
} | ||
} |
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
Oops, something went wrong.