Skip to content

Commit

Permalink
[optimize|build] Optimize code; update dependencies
Browse files Browse the repository at this point in the history
  • Loading branch information
SkyD666 committed May 7, 2024
1 parent 3db7360 commit fd94466
Show file tree
Hide file tree
Showing 12 changed files with 48 additions and 69 deletions.
7 changes: 0 additions & 7 deletions .github/workflows/pre_release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,6 @@ on:
- '**.md'
- 'doc/**'
- 'image/**'
pull_request:
branches:
- 'master'
paths-ignore:
- '**.md'
- 'doc/**'
- 'image/**'

jobs:
build:
Expand Down
16 changes: 8 additions & 8 deletions app/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ android {
minSdk = 24
targetSdk = 34
versionCode = 65
versionName = "2.2-rc04"
versionName = "2.2-rc05"

testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"
vectorDrawables {
Expand Down Expand Up @@ -150,14 +150,14 @@ dependencies {
val accompanistVersion: String by rootProject.extra
val mlkitRecognitionVersion: String by rootProject.extra
val roomVersion: String by rootProject.extra
implementation("androidx.core:core-ktx:1.13.0")
implementation("androidx.core:core-ktx:1.13.1")
implementation("androidx.compose.ui:ui:$composeVersion")
implementation("androidx.compose.material3:material3:$md3Version")
implementation("androidx.compose.material3:material3-window-size-class:$md3Version")
implementation("androidx.compose.material:material:1.6.6")
implementation("androidx.compose.material:material-icons-extended:1.6.6")
implementation("androidx.compose.material:material:1.6.7")
implementation("androidx.compose.material:material-icons-extended:1.6.7")
implementation("androidx.compose.ui:ui-tooling-preview:$md3Version")
implementation("com.google.android.material:material:1.11.0")
implementation("com.google.android.material:material:1.12.0")
implementation("androidx.lifecycle:lifecycle-runtime-compose:2.7.0")
implementation("androidx.lifecycle:lifecycle-runtime-ktx:2.7.0")
implementation("androidx.activity:activity-compose:1.9.0")
Expand All @@ -178,7 +178,7 @@ dependencies {
implementation("com.github.thegrizzlylabs:sardine-android:0.8")
implementation("org.jetbrains.kotlinx:kotlinx-serialization-json:1.6.3")
implementation("com.materialkolor:material-kolor:1.4.4")
implementation("androidx.datastore:datastore-preferences:1.1.0")
implementation("androidx.datastore:datastore-preferences:1.1.1")
implementation("com.airbnb.android:lottie-compose:6.3.0")

implementation("com.squareup.retrofit2:retrofit:2.10.0")
Expand All @@ -198,6 +198,6 @@ dependencies {

implementation("com.github.penfeizhou.android.animation:apng:2.28.0")

debugImplementation("androidx.compose.ui:ui-tooling:1.6.6")
debugImplementation("androidx.compose.ui:ui-test-manifest:1.6.6")
debugImplementation("androidx.compose.ui:ui-tooling:1.6.7")
debugImplementation("androidx.compose.ui:ui-test-manifest:1.6.7")
}
7 changes: 7 additions & 0 deletions app/src/main/java/com/skyd/rays/ext/DateExt.kt
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,10 @@ fun Date.toDateTimeString(
): String = SimpleDateFormat
.getDateTimeInstance(dateStyle, timeStyle, locale)
.format(this)

fun Long.toDateTimeString(pattern: String): String = Date(this).toDateTimeString(pattern)

fun Date.toDateTimeString(pattern: String): String = runCatching {
SimpleDateFormat(pattern, Locale.getDefault())
.format(this)
}.getOrDefault("")
5 changes: 1 addition & 4 deletions app/src/main/java/com/skyd/rays/ext/IOExt.kt
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,7 @@ fun Uri.copyTo(target: File): File {
}

fun InputStream.saveTo(target: File): File {
val parentFile = target.parentFile
if (parentFile?.exists() == false) {
parentFile.mkdirs()
}
target.parentFile?.takeIf { !it.exists() }?.mkdirs()
if (!target.exists()) {
target.createNewFile()
}
Expand Down
8 changes: 4 additions & 4 deletions app/src/main/java/com/skyd/rays/ext/ImageExt.kt
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,10 @@ fun Bitmap.cropTransparency(): Bitmap? {
val alpha = getPixel(x, y) shr 24 and 255
// pixel is not 100% transparent
if (alpha > 0) {
if (x < minX) minX = x
if (x > maxX) maxX = x
if (y < minY) minY = y
if (y > maxY) maxY = y
minX = minOf(minX, x)
maxX = maxOf(maxX, x)
minY = minOf(minY, y)
maxY = maxOf(maxY, y)
}
}
}
Expand Down
14 changes: 0 additions & 14 deletions app/src/main/java/com/skyd/rays/ext/TimeExt.kt

This file was deleted.

27 changes: 9 additions & 18 deletions app/src/main/java/com/skyd/rays/model/db/AppDatabase.kt
Original file line number Diff line number Diff line change
Expand Up @@ -64,25 +64,16 @@ abstract class AppDatabase : RoomDatabase() {
)

fun getInstance(context: Context): AppDatabase {
return if (instance == null) {
synchronized(this) {
if (instance == null) {
Room.databaseBuilder(
context.applicationContext,
AppDatabase::class.java,
APP_DATA_BASE_FILE_NAME
)
.addMigrations(*migrations)
.build()
.apply { instance = this }
} else {
instance as AppDatabase
}
}
} else {
instance as AppDatabase
return instance ?: synchronized(this) {
instance ?: Room.databaseBuilder(
context.applicationContext,
AppDatabase::class.java,
APP_DATA_BASE_FILE_NAME
)
.addMigrations(*migrations)
.build()
.apply { instance = this }
}

}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -143,11 +143,10 @@ class StickerProvider : DocumentsProvider() {
}

private fun getDisplayMap(stickerUuids: List<String>): MutableMap<String, String> {
val titles = entryPoint.stickerDao().getStickerTitles(stickerUuids)
.toMutableMap()
val titles = entryPoint.stickerDao().getStickerTitles(stickerUuids).toMutableMap()

entryPoint.tagDao().getTagStringMap(
titles.filter { it.value.isBlank() }.map { it.key }
titles.filterValues { it.isBlank() }.map { it.key }
).forEach { (t, u) ->
titles[t] = u.ifBlank { t }
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import com.skyd.rays.appContext
import com.skyd.rays.base.BaseRepository
import com.skyd.rays.config.EXPORT_FILES_DIR
import com.skyd.rays.config.IMPORT_FILES_DIR
import com.skyd.rays.ext.dateTime
import com.skyd.rays.ext.toDateTimeString
import com.skyd.rays.model.bean.ImportExportInfo
import com.skyd.rays.model.bean.ImportExportResultInfo
import com.skyd.rays.model.bean.ImportExportWaitingInfo
Expand Down Expand Up @@ -132,7 +132,12 @@ class ImportExportFilesRepository @Inject constructor(
if (excludeModifyTime) it.sticker.modifyTime = 0L
stickerWithTagsToJsonFile(it)
stickerUuidToFile(it.sticker.uuid)
.copyTo(File("${appContext.EXPORT_FILES_DIR}/$BACKUP_STICKER_DIR", it.sticker.uuid))
.copyTo(
File(
"${appContext.EXPORT_FILES_DIR}/$BACKUP_STICKER_DIR",
it.sticker.uuid
)
)
emitProgressData(
current = ++currentCount,
total = totalCount,
Expand All @@ -141,7 +146,7 @@ class ImportExportFilesRepository @Inject constructor(
}
val documentFile = DocumentFile.fromTreeUri(appContext, dirUri)!!
val currentDate =
dateTime(timestamp = System.currentTimeMillis(), pattern = "yyyyMMdd-HHmmss")
System.currentTimeMillis().toDateTimeString(pattern = "yyyyMMdd-HHmmss")
val zipFileUri: Uri = documentFile.createFile(
"application/zip",
"Rays_Backup_${currentDate}_${Random.nextInt(0, Int.MAX_VALUE)}"
Expand Down Expand Up @@ -180,7 +185,8 @@ class ImportExportFilesRepository @Inject constructor(
}

private fun stickerWithTagsToJsonFile(stickerWithTags: StickerWithTags): File {
val file = File("${appContext.EXPORT_FILES_DIR}/$BACKUP_DATA_DIR", stickerWithTags.sticker.uuid)
val file =
File("${appContext.EXPORT_FILES_DIR}/$BACKUP_DATA_DIR", stickerWithTags.sticker.uuid)
if (!file.exists()) {
if (file.parentFile?.exists() == false) {
file.parentFile?.mkdirs()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ class WebDavRepository @Inject constructor(
return flowOnIo {
val sardine: Sardine = initWebDav(website, username, password)
val backupInfoMap: List<BackupInfo> = getMd5UuidKeyBackupInfoMap(sardine, website)
.filter { it.value.isDeleted }.values.toList()
.filterValues { it.isDeleted }.values.toList()
emit(backupInfoMap)
}
}
Expand Down Expand Up @@ -91,7 +91,7 @@ class WebDavRepository @Inject constructor(
return flowOnIo {
val sardine: Sardine = initWebDav(website, username, password)
val (willBeDeletedMap, othersMap) = getMd5UuidKeyBackupInfoMap(sardine, website).run {
filter { it.value.isDeleted } to filter { !it.value.isDeleted }
filterValues { it.isDeleted } to filterValues { !it.isDeleted }
}
updateBackupInfo(sardine, website, othersMap.values.toList())
willBeDeletedMap.forEach { (_, u) ->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,12 +68,12 @@ import androidx.lifecycle.compose.collectAsStateWithLifecycle
import androidx.navigation.NavHostController
import com.skyd.rays.R
import com.skyd.rays.base.mvi.getDispatcher
import com.skyd.rays.ext.dateTime
import com.skyd.rays.ext.isCompact
import com.skyd.rays.ext.navigate
import com.skyd.rays.ext.popBackStackWithLifecycle
import com.skyd.rays.ext.showSnackbar
import com.skyd.rays.ext.showSnackbarWithLaunchedEffect
import com.skyd.rays.ext.toDateTimeString
import com.skyd.rays.model.bean.StickerWithTags
import com.skyd.rays.model.bean.UriWithStickerUuidBean
import com.skyd.rays.model.preference.StickerScalePreference
Expand Down Expand Up @@ -457,12 +457,12 @@ fun StickerDetailInfo(modifier: Modifier = Modifier, stickerWithTags: StickerWit
DetailInfoItem(
icon = Icons.Default.AddCircle,
title = stringResource(id = R.string.sticker_create_time),
text = dateTime(sticker.createTime)
text = sticker.createTime.toDateTimeString()
)
DetailInfoItem(
icon = Icons.Default.Edit,
title = stringResource(id = R.string.detail_screen_sticker_info_last_modified_time),
text = sticker.modifyTime?.let { dateTime(it) } ?: dateTime(sticker.createTime)
text = (sticker.modifyTime ?: sticker.createTime).toDateTimeString()
)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,10 +50,10 @@ import androidx.hilt.navigation.compose.hiltViewModel
import androidx.lifecycle.compose.collectAsStateWithLifecycle
import com.skyd.rays.R
import com.skyd.rays.base.mvi.getDispatcher
import com.skyd.rays.ext.dateTime
import com.skyd.rays.ext.editor
import com.skyd.rays.ext.secretSharedPreferences
import com.skyd.rays.ext.showSnackbarWithLaunchedEffect
import com.skyd.rays.ext.toDateTimeString
import com.skyd.rays.model.bean.BackupInfo
import com.skyd.rays.model.bean.WebDavWaitingInfo
import com.skyd.rays.model.preference.WebDavServerPreference
Expand Down Expand Up @@ -409,7 +409,7 @@ private fun RecycleBinBottomSheet(
Text(
text = stringResource(
R.string.webdav_screen_last_modified_time,
dateTime(list[it].modifiedTime)
list[it].modifiedTime.toDateTimeString()
)
)
},
Expand Down

0 comments on commit fd94466

Please sign in to comment.