Skip to content

Commit

Permalink
[optimize|fix]加入更多Lottie动画;修复WebDAV推送时的bug;修复WebDAV下载时Json.decodeFrom…
Browse files Browse the repository at this point in the history
…Stream未关闭流导致内存泄漏的问题
  • Loading branch information
SkyD666 committed Mar 31, 2023
1 parent e42c102 commit 9374d6c
Show file tree
Hide file tree
Showing 20 changed files with 94 additions and 66 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,12 +52,12 @@
11. ......

## 🤩应用截图
![ic_main_screen](image/ic_main_screen.jpg) ![ic_main_screen_search](image/ic_main_screen_search.jpg)
![ic_home_screen](image/ic_home_screen.jpg) ![ic_main_screen_search](image/ic_main_screen_search.jpg)
![ic_add_screen_edit](image/ic_add_screen_edit.jpg) ![ic_search_config_screen](image/ic_search_config_screen.jpg)
![ic_process_text_menu](image/ic_process_text_menu.jpg) ![ic_auto_fill_menu](image/ic_auto_fill_menu.jpg)
![ic_import_export_screen](image/ic_import_export_screen.jpg) ![ic_easy_usage_screen](image/ic_easy_usage_screen.jpg)
![ic_appearance_screen](image/ic_appearance_screen.jpg) ![ic_webdav_screen](image/ic_webdav_screen.jpg)
![ic_abstract_emoji_screen](image/ic_abstract_emoji_screen.jpg) ![ic_about_screen](image/ic_about_screen.jpg)
![ic_abstract_emoji_screen](image/ic_abstract_emoji_screen.jpg) ![ic_more_screen](image/ic_more_screen.jpg)

## 🔍搜索示例

Expand Down
4 changes: 2 additions & 2 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ android {
applicationId "com.skyd.raca"
minSdk 24
targetSdk 33
versionCode 5
versionName "1.4"
versionCode 6
versionName "1.5"
flavorDimensions "versionName"

testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import com.thegrizzlylabs.sardineandroid.impl.OkHttpSardine
import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.FlowCollector
import kotlinx.coroutines.flow.flow
import kotlinx.serialization.decodeFromString
import kotlinx.serialization.encodeToString
import kotlinx.serialization.json.Json
import kotlinx.serialization.json.decodeFromStream
Expand Down Expand Up @@ -125,9 +124,9 @@ class WebDavRepository @Inject constructor(private val articleDao: ArticleDao) :
emitProgressData(current = ++currentCount, total = totalCount)
}
excludedMap.forEach { entry ->
waitToAddList += Json.decodeFromStream<ArticleWithTags>(
sardine.get(website + APP_DIR + BACKUP_DIR + entry.value.uuid)
)
sardine.get(website + APP_DIR + BACKUP_DIR + entry.value.uuid).use { inputStream ->
waitToAddList += Json.decodeFromStream<ArticleWithTags>(inputStream)
}
emitProgressData(current = ++currentCount, total = totalCount)
}
articleDao.webDavImportData(waitToAddList)
Expand All @@ -150,29 +149,34 @@ class WebDavRepository @Inject constructor(private val articleDao: ArticleDao) :
val startTime = System.currentTimeMillis()
val allArticleWithTagsList = articleDao.getAllArticleWithTagsList()
val sardine: Sardine = initWebDav(website, username, password)
val backupInfoMap: MutableMap<String, BackupInfo> =
var backupInfoMap: MutableMap<String, BackupInfo> =
getMd5UuidKeyBackupInfoMap(sardine, website).toMutableMap()
val (excludedList, willBeDeletedMap) = excludeLocalUnchanged(
backupInfoMap,
backupInfoMap, // 这里需要md5+uuid map
allArticleWithTagsList
)
backupInfoMap = backupInfoMap.values.associateBy { it.uuid }.toMutableMap()
val totalCount = excludedList.size + willBeDeletedMap.size
var currentCount = 0
willBeDeletedMap.forEach { (_, u) ->
backupInfoMap[u.contentMd5 + u.uuid]?.isDeleted = true
backupInfoMap[/*u.contentMd5 + */u.uuid]?.isDeleted = true
emitProgressData(current = ++currentCount, total = totalCount)
}
excludedList.forEach {
val file = toFile(it)
sardine.put(website + APP_DIR + BACKUP_DIR + file.name, file, "text/*")
file.deleteRecursively()
val md5 = it.md5()
val uuid = it.article.uuid
backupInfoMap[md5 + uuid] = BackupInfo(
backupInfoMap[uuid] = BackupInfo(
uuid = uuid,
contentMd5 = md5,
modifiedTime = System.currentTimeMillis(),
isDeleted = false
)
emitProgressData(current = ++currentCount, total = totalCount)
}
updateBackupInfo(sardine, website, backupInfoMap)
updateBackupInfo(sardine, website, backupInfoMap.values.toList())
emitBaseData(BaseData<WebDavInfo>().apply {
code = 0
data = WebDavResultInfo(
Expand Down Expand Up @@ -232,20 +236,14 @@ class WebDavRepository @Inject constructor(private val articleDao: ArticleDao) :
website: String,
): Map<String, BackupInfo> {
return if (sardine.exists(website + APP_DIR + BACKUP_INFO_FILE)) {
val inputAsString = sardine.get(website + APP_DIR + BACKUP_INFO_FILE)
.bufferedReader().use { it.readText() }
Json.decodeFromString<List<BackupInfo>>(inputAsString)
.distinctBy { it.uuid } // 保证uuid唯一
.associateBy { it.contentMd5 + it.uuid }
sardine.get(website + APP_DIR + BACKUP_INFO_FILE).use { inputStream ->
Json.decodeFromStream<List<BackupInfo>>(inputStream)
.distinctBy { it.uuid } // 保证uuid唯一
.associateBy { it.contentMd5 + it.uuid }
}
} else mapOf()
}

private fun updateBackupInfo(
sardine: Sardine,
website: String,
backupInfoMap: Map<String, BackupInfo>
) = updateBackupInfo(sardine, website, backupInfoMap.values.toList())

private fun updateBackupInfo(
sardine: Sardine,
website: String,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,29 +7,21 @@ import androidx.compose.foundation.layout.padding
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.runtime.getValue
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.text.style.TextAlign
import androidx.compose.ui.unit.dp
import com.airbnb.lottie.compose.*

@Composable
fun AnimatedPlaceholder(@androidx.annotation.RawRes resId: Int, tip: String) {
val lottieComposition by rememberLottieComposition(LottieCompositionSpec.RawRes(resId))
val lottieProgress by animateLottieCompositionAsState(
composition = lottieComposition,
iterations = LottieConstants.IterateForever
)
Box(modifier = Modifier.fillMaxSize(), contentAlignment = Alignment.Center) {
Column(
modifier = Modifier.fillMaxSize(fraction = 0.5f),
horizontalAlignment = Alignment.CenterHorizontally
) {
LottieAnimation(
RacaLottieAnimation(
modifier = Modifier.weight(1f),
composition = lottieComposition,
progress = { lottieProgress },
resId = resId,
)
Text(
modifier = Modifier.padding(top = 5.dp),
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package com.skyd.raca.ui.component

import androidx.compose.runtime.Composable
import androidx.compose.runtime.getValue
import androidx.compose.ui.Modifier
import com.airbnb.lottie.compose.*

@Composable
fun RacaLottieAnimation(modifier: Modifier = Modifier, @androidx.annotation.RawRes resId: Int) {
val lottieComposition by rememberLottieComposition(LottieCompositionSpec.RawRes(resId))
val lottieProgress by animateLottieCompositionAsState(
composition = lottieComposition,
iterations = LottieConstants.IterateForever
)
LottieAnimation(
modifier = modifier,
composition = lottieComposition,
progress = { lottieProgress },
)
}
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
package com.skyd.raca.ui.component.dialog

import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.filled.Warning
import androidx.compose.material3.Icon
import androidx.compose.foundation.layout.size
import androidx.compose.material3.Text
import androidx.compose.material3.TextButton
import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.unit.dp
import com.skyd.raca.R
import com.skyd.raca.ui.component.dialog.RacaDialog
import com.skyd.raca.ui.component.RacaLottieAnimation

@Composable
fun DeleteWarningDialog(
Expand All @@ -21,7 +21,10 @@ fun DeleteWarningDialog(
visible = visible,
onDismissRequest = onDismissRequest,
icon = {
Icon(imageVector = Icons.Default.Warning, contentDescription = null)
RacaLottieAnimation(
modifier = Modifier.size(48.dp),
resId = R.raw.lottie_genshin_impact_qiqi_1
)
},
title = {
Text(text = stringResource(R.string.dialog_warning))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,27 @@
*/
package com.skyd.raca.ui.component.dialog

import androidx.compose.foundation.layout.size
import androidx.compose.material3.AlertDialog
import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier
import androidx.compose.ui.unit.dp
import androidx.compose.ui.window.DialogProperties
import com.skyd.raca.R
import com.skyd.raca.ui.component.RacaLottieAnimation

@Composable
fun RacaDialog(
modifier: Modifier = Modifier,
visible: Boolean,
properties: DialogProperties = DialogProperties(),
onDismissRequest: () -> Unit = {},
icon: @Composable (() -> Unit)? = null,
icon: @Composable (() -> Unit)? = {
RacaLottieAnimation(
modifier = Modifier.size(48.dp),
resId = R.raw.lottie_genshin_impact_venti_1
)
},
title: @Composable (() -> Unit)? = null,
text: @Composable (() -> Unit)? = null,
confirmButton: @Composable () -> Unit,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,21 +7,21 @@
*/
package com.skyd.raca.ui.component.dialog

import androidx.compose.material3.Icon
import androidx.compose.foundation.layout.size
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.Text
import androidx.compose.material3.TextButton
import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.graphics.vector.ImageVector
import androidx.compose.ui.platform.LocalFocusManager
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.text.input.ImeAction
import androidx.compose.ui.text.style.TextOverflow
import androidx.compose.ui.window.DialogProperties
import androidx.compose.ui.unit.dp
import com.skyd.raca.R
import com.skyd.raca.ui.component.ClipboardTextField
import com.skyd.raca.ui.component.RacaLottieAnimation

@Composable
fun TextFieldDialog(
Expand All @@ -30,7 +30,12 @@ fun TextFieldDialog(
readOnly: Boolean = false,
maxLines: Int = Int.MAX_VALUE,
title: String = "",
icon: ImageVector? = null,
icon: @Composable (() -> Unit)? = {
RacaLottieAnimation(
modifier = Modifier.size(48.dp),
resId = R.raw.lottie_genshin_impact_venti_1
)
},
value: String = "",
placeholder: String = "",
isPassword: Boolean = false,
Expand All @@ -48,14 +53,7 @@ fun TextFieldDialog(
modifier = modifier,
visible = visible,
onDismissRequest = onDismissRequest,
icon = {
icon?.let {
Icon(
imageVector = icon,
contentDescription = title,
)
}
},
icon = icon,
title = {
Text(text = title, maxLines = 2, overflow = TextOverflow.Ellipsis)
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,10 @@ package com.skyd.raca.ui.component.dialog

import androidx.compose.animation.core.animateFloatAsState
import androidx.compose.foundation.layout.*
import androidx.compose.material3.*
import androidx.compose.material3.LinearProgressIndicator
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.ProgressIndicatorDefaults
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.runtime.getValue
import androidx.compose.ui.Alignment
Expand All @@ -11,6 +14,7 @@ import androidx.compose.ui.res.stringResource
import androidx.compose.ui.semantics.semantics
import androidx.compose.ui.unit.dp
import com.skyd.raca.R
import com.skyd.raca.ui.component.RacaLottieAnimation

@Composable
fun WaitingDialog(
Expand Down Expand Up @@ -57,7 +61,10 @@ fun WaitingDialog(
visible = visible,
onDismissRequest = { },
icon = {
CircularProgressIndicator()
RacaLottieAnimation(
modifier = Modifier.size(48.dp),
resId = R.raw.lottie_genshin_impact_klee_3
)
},
title = {
Text(text = title)
Expand Down
2 changes: 0 additions & 2 deletions app/src/main/java/com/skyd/raca/ui/screen/add/AddScreen.kt
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import androidx.compose.foundation.text.KeyboardOptions
import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.filled.Close
import androidx.compose.material.icons.filled.Done
import androidx.compose.material.icons.filled.Info
import androidx.compose.material3.*
import androidx.compose.runtime.*
import androidx.compose.runtime.saveable.rememberSaveable
Expand Down Expand Up @@ -174,7 +173,6 @@ fun AddScreen(articleUuid: String, article: String, viewModel: AddViewModel = hi

RacaDialog(
visible = openDialog,
icon = { Icon(imageVector = Icons.Default.Info, contentDescription = null) },
title = { Text(text = stringResource(R.string.dialog_tip)) },
text = { Text(text = stringResource(R.string.add_screen_success)) },
onDismissRequest = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,6 @@ fun Palettes(
TextFieldDialog(
visible = addDialogVisible,
title = stringResource(R.string.primary_color),
icon = Icons.Outlined.Palette,
value = customColorValue,
onValueChange = {
customColorValue = it
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,7 @@ import com.skyd.raca.model.bean.BackupInfo
import com.skyd.raca.model.bean.WebDavResultInfo
import com.skyd.raca.model.bean.WebDavWaitingInfo
import com.skyd.raca.model.preference.WebDavServerPreference
import com.skyd.raca.ui.component.BaseSettingsItem
import com.skyd.raca.ui.component.CategorySettingsItem
import com.skyd.raca.ui.component.RacaTopBar
import com.skyd.raca.ui.component.RacaTopBarStyle
import com.skyd.raca.ui.component.*
import com.skyd.raca.ui.component.dialog.DeleteWarningDialog
import com.skyd.raca.ui.component.dialog.TextFieldDialog
import com.skyd.raca.ui.component.dialog.WaitingDialog
Expand Down Expand Up @@ -266,7 +263,6 @@ fun WebDavScreen(viewModel: WebDavViewModel = hiltViewModel()) {
)
TextFieldDialog(
visible = openInputDialog,
icon = Icons.Default.Input,
title = inputDialogInfo.first,
value = inputDialogInfo.second,
maxLines = 1,
Expand Down Expand Up @@ -383,7 +379,10 @@ private fun RecycleBinBottomSheet(
verticalAlignment = Alignment.CenterVertically,
horizontalArrangement = Arrangement.Center
) {
Icon(imageVector = Icons.Default.Lightbulb, contentDescription = null)
RacaLottieAnimation(
modifier = Modifier.size(48.dp),
resId = R.raw.lottie_genshin_impact_paimon_1
)
Text(
modifier = Modifier.padding(start = 10.dp),
textAlign = TextAlign.Center,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,15 +34,15 @@ class RacaAutofillService : AutofillService() {
) {
val structure = request.fillContexts.lastOrNull()?.structure
?: run {
callback.onSuccess(null)
callback.onFailure(null)
return
}
val viewNode = traverseStructure(structure) ?: run {
callback.onSuccess(null)
callback.onFailure(null)
return
}
val autofillId = viewNode.autofillId ?: run {
callback.onSuccess(null)
callback.onFailure(null)
return
}

Expand Down
1 change: 1 addition & 0 deletions app/src/main/res/raw/lottie_genshin_impact_diona_1.json

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions app/src/main/res/raw/lottie_genshin_impact_klee_3.json

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions app/src/main/res/raw/lottie_genshin_impact_paimon_1.json

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions app/src/main/res/raw/lottie_genshin_impact_qiqi_1.json

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions app/src/main/res/raw/lottie_genshin_impact_venti_1.json

Large diffs are not rendered by default.

Binary file added image/ic_home_screen.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file removed image/ic_main_screen.jpg
Binary file not shown.

0 comments on commit 9374d6c

Please sign in to comment.