From 248a3ae3293b3a2bc560e4941572b41dc566f42a Mon Sep 17 00:00:00 2001 From: SkyD666 Date: Mon, 25 Nov 2024 20:06:50 +0800 Subject: [PATCH] [fix|build] Fix the height issue of article item image; update dependencies --- app/build.gradle.kts | 2 +- .../model/bean/{VideoBean.kt => MediaBean.kt} | 2 +- .../anivu/model/repository/MediaRepository.kt | 30 +++++++++---------- .../anivu/ui/screen/article/Article1Item.kt | 16 ++++++++-- .../skyd/anivu/ui/screen/media/MediaIntent.kt | 4 +-- .../anivu/ui/screen/media/MediaViewModel.kt | 10 +++---- .../anivu/ui/screen/media/list/Media1Item.kt | 12 ++++---- .../anivu/ui/screen/media/list/MediaList.kt | 14 ++++----- .../media/list/MediaListPartialStateChange.kt | 4 +-- .../ui/screen/media/list/MediaListState.kt | 4 +-- .../screen/media/list/MediaListViewModel.kt | 2 +- gradle/libs.versions.toml | 6 ++-- 12 files changed, 58 insertions(+), 48 deletions(-) rename app/src/main/java/com/skyd/anivu/model/bean/{VideoBean.kt => MediaBean.kt} (96%) diff --git a/app/build.gradle.kts b/app/build.gradle.kts index 5e1af6aa..ea2f4554 100644 --- a/app/build.gradle.kts +++ b/app/build.gradle.kts @@ -22,7 +22,7 @@ android { minSdk = 24 targetSdk = 35 versionCode = 24 - versionName = "2.1-beta09" + versionName = "2.1-beta10" testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner" diff --git a/app/src/main/java/com/skyd/anivu/model/bean/VideoBean.kt b/app/src/main/java/com/skyd/anivu/model/bean/MediaBean.kt similarity index 96% rename from app/src/main/java/com/skyd/anivu/model/bean/VideoBean.kt rename to app/src/main/java/com/skyd/anivu/model/bean/MediaBean.kt index 3ff4ab13..28152585 100644 --- a/app/src/main/java/com/skyd/anivu/model/bean/VideoBean.kt +++ b/app/src/main/java/com/skyd/anivu/model/bean/MediaBean.kt @@ -5,7 +5,7 @@ import com.skyd.anivu.ext.getMimeType import com.skyd.anivu.util.fileicon.getFileIcon import java.io.File -data class VideoBean( +data class MediaBean( val displayName: String? = null, val file: File, ) : BaseBean { diff --git a/app/src/main/java/com/skyd/anivu/model/repository/MediaRepository.kt b/app/src/main/java/com/skyd/anivu/model/repository/MediaRepository.kt index 2a6b0b49..b5a4d709 100644 --- a/app/src/main/java/com/skyd/anivu/model/repository/MediaRepository.kt +++ b/app/src/main/java/com/skyd/anivu/model/repository/MediaRepository.kt @@ -4,7 +4,7 @@ import androidx.compose.ui.util.fastFirstOrNull import com.skyd.anivu.base.BaseRepository import com.skyd.anivu.model.bean.MediaGroupBean import com.skyd.anivu.model.bean.MediaGroupBean.Companion.isDefaultGroup -import com.skyd.anivu.model.bean.VideoBean +import com.skyd.anivu.model.bean.MediaBean import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.flow.Flow import kotlinx.coroutines.flow.flow @@ -37,7 +37,7 @@ class MediaRepository @Inject constructor( }.flowOn(Dispatchers.IO) } - fun requestFiles(uriPath: String, group: MediaGroupBean?): Flow> { + fun requestFiles(uriPath: String, group: MediaGroupBean?): Flow> { return flow { val groupJsonFile = File(uriPath, GROUP_JSON_NAME) val mediaGroupJson = parseGroupJson(groupJsonFile) @@ -46,7 +46,7 @@ class MediaRepository @Inject constructor( File(uriPath).listFiles().orEmpty().toMutableList().filter { it.exists() } val videoList = if (group == null) { allFiles.map { - VideoBean( + MediaBean( displayName = null, // TODO file = it, ) @@ -56,7 +56,7 @@ class MediaRepository @Inject constructor( allFiles.filter { file -> filesInGroup.fastFirstOrNull { it.fileName == file.name } == null }.map { file -> - VideoBean( + MediaBean( displayName = null, // TODO file = file, ) @@ -65,7 +65,7 @@ class MediaRepository @Inject constructor( filesInGroup.filter { it.groupName == group.name }.mapNotNull { val file = File(uriPath, it.fileName) if (file.exists()) { - VideoBean( + MediaBean( displayName = null, // TODO file = file, ) @@ -81,13 +81,13 @@ class MediaRepository @Inject constructor( }.flowOn(Dispatchers.IO) } - fun requestDelete(file: File): Flow { + fun deleteFile(file: File): Flow { return flow { emit(file.deleteRecursively()) }.flowOn(Dispatchers.IO) } - fun requestCreateGroup(uriPath: String, group: MediaGroupBean): Flow = flow { + fun createGroup(uriPath: String, group: MediaGroupBean): Flow = flow { if (group.isDefaultGroup()) { emit(Unit) return@flow @@ -103,7 +103,7 @@ class MediaRepository @Inject constructor( emit(Unit) }.flowOn(Dispatchers.IO) - fun requestDeleteGroup(uriPath: String, group: MediaGroupBean): Flow = flow { + fun deleteGroup(uriPath: String, group: MediaGroupBean): Flow = flow { if (group.isDefaultGroup()) { emit(0) return@flow @@ -128,7 +128,7 @@ class MediaRepository @Inject constructor( emit(newFileToGroups.count() - fileToGroups.count()) }.flowOn(Dispatchers.IO) - fun requestRenameGroup( + fun renameGroup( uriPath: String, group: MediaGroupBean, newName: String, @@ -162,15 +162,15 @@ class MediaRepository @Inject constructor( emit(MediaGroupBean(name = newName)) }.flowOn(Dispatchers.IO) - fun requestChangeMediaGroup( + fun changeMediaGroup( uriPath: String, - videoBean: VideoBean, + mediaBean: MediaBean, group: MediaGroupBean, ): Flow = flow { val groupJsonFile = File(uriPath, GROUP_JSON_NAME) val mediaGroupJson = parseGroupJson(groupJsonFile)!! val fileToGroups = mediaGroupJson.files.toSet() - val file = fileToGroups.firstOrNull { it.fileName == videoBean.file.name } + val file = fileToGroups.firstOrNull { it.fileName == mediaBean.file.name } val newFileToGroups = (if (file != null) fileToGroups - file else fileToGroups) .toMutableList() @@ -178,9 +178,9 @@ class MediaRepository @Inject constructor( if (!group.isDefaultGroup()) { add( FileToGroup( - fileName = videoBean.file.name, + fileName = mediaBean.file.name, groupName = group.name, - isFile = videoBean.file.isFile, + isFile = mediaBean.file.isFile, ) ) } @@ -190,7 +190,7 @@ class MediaRepository @Inject constructor( emit(Unit) }.flowOn(Dispatchers.IO) - fun requestMoveFilesToGroup( + fun moveFilesToGroup( path: String, from: MediaGroupBean, to: MediaGroupBean diff --git a/app/src/main/java/com/skyd/anivu/ui/screen/article/Article1Item.kt b/app/src/main/java/com/skyd/anivu/ui/screen/article/Article1Item.kt index aadcbef0..6c22779f 100644 --- a/app/src/main/java/com/skyd/anivu/ui/screen/article/Article1Item.kt +++ b/app/src/main/java/com/skyd/anivu/ui/screen/article/Article1Item.kt @@ -9,7 +9,6 @@ import androidx.compose.foundation.layout.Column import androidx.compose.foundation.layout.IntrinsicSize import androidx.compose.foundation.layout.Row import androidx.compose.foundation.layout.Spacer -import androidx.compose.foundation.layout.fillMaxHeight import androidx.compose.foundation.layout.fillMaxSize import androidx.compose.foundation.layout.fillMaxWidth import androidx.compose.foundation.layout.height @@ -54,9 +53,11 @@ import androidx.compose.ui.Modifier import androidx.compose.ui.draw.clip import androidx.compose.ui.graphics.vector.rememberVectorPainter import androidx.compose.ui.layout.ContentScale +import androidx.compose.ui.layout.layout import androidx.compose.ui.platform.LocalContext import androidx.compose.ui.res.stringResource import androidx.compose.ui.text.style.TextOverflow +import androidx.compose.ui.unit.Constraints import androidx.compose.ui.unit.Dp import androidx.compose.ui.unit.dp import androidx.navigation.NavController @@ -301,8 +302,17 @@ private fun Article1ItemContent( AniVuImage( modifier = Modifier .width(100.dp) - .fillMaxHeight() - .heightIn(min = 70.dp, max = 120.dp), + .heightIn(min = 70.dp, max = 120.dp) + .layout { measurable, constraints -> + if (constraints.maxHeight == Constraints.Infinity) { + layout(0, 0) {} + } else { + val placeable = measurable.measure(constraints) + layout(placeable.width, placeable.height) { + placeable.place(0, 0) + } + } + }, model = article.image, contentScale = ContentScale.Crop, ) diff --git a/app/src/main/java/com/skyd/anivu/ui/screen/media/MediaIntent.kt b/app/src/main/java/com/skyd/anivu/ui/screen/media/MediaIntent.kt index b9ff7f88..71fc36ca 100644 --- a/app/src/main/java/com/skyd/anivu/ui/screen/media/MediaIntent.kt +++ b/app/src/main/java/com/skyd/anivu/ui/screen/media/MediaIntent.kt @@ -2,14 +2,14 @@ package com.skyd.anivu.ui.screen.media import com.skyd.anivu.base.mvi.MviIntent import com.skyd.anivu.model.bean.MediaGroupBean -import com.skyd.anivu.model.bean.VideoBean +import com.skyd.anivu.model.bean.MediaBean sealed interface MediaIntent : MviIntent { data class Init(val path: String?) : MediaIntent data class Refresh(val path: String?) : MediaIntent data class ChangeMediaGroup( val path: String?, - val videoBean: VideoBean, + val mediaBean: MediaBean, val group: MediaGroupBean ) : MediaIntent diff --git a/app/src/main/java/com/skyd/anivu/ui/screen/media/MediaViewModel.kt b/app/src/main/java/com/skyd/anivu/ui/screen/media/MediaViewModel.kt index 6b157157..6045fe1d 100644 --- a/app/src/main/java/com/skyd/anivu/ui/screen/media/MediaViewModel.kt +++ b/app/src/main/java/com/skyd/anivu/ui/screen/media/MediaViewModel.kt @@ -94,7 +94,7 @@ class MediaViewModel @Inject constructor( filterIsInstance().filterNot { it.path.isNullOrBlank() }.flatMapConcat { intent -> - mediaRepo.requestChangeMediaGroup(intent.path!!, intent.videoBean, intent.group) + mediaRepo.changeMediaGroup(intent.path!!, intent.mediaBean, intent.group) .map { MediaPartialStateChange.ChangeMediaGroup.Success }.startWith(MediaPartialStateChange.LoadingDialog.Show) @@ -103,7 +103,7 @@ class MediaViewModel @Inject constructor( filterIsInstance().filterNot { it.path.isNullOrBlank() }.flatMapConcat { intent -> - mediaRepo.requestDeleteGroup(intent.path!!, intent.group).map { + mediaRepo.deleteGroup(intent.path!!, intent.group).map { MediaPartialStateChange.DeleteGroup.Success(intent.group) }.startWith(MediaPartialStateChange.LoadingDialog.Show) .catchMap { MediaPartialStateChange.DeleteGroup.Failed(it.message.toString()) } @@ -111,7 +111,7 @@ class MediaViewModel @Inject constructor( filterIsInstance().filterNot { it.path.isNullOrBlank() }.flatMapConcat { intent -> - mediaRepo.requestCreateGroup(intent.path!!, intent.group).map { + mediaRepo.createGroup(intent.path!!, intent.group).map { MediaPartialStateChange.CreateGroup.Success }.startWith(MediaPartialStateChange.LoadingDialog.Show) .catchMap { MediaPartialStateChange.CreateGroup.Failed(it.message.toString()) } @@ -119,7 +119,7 @@ class MediaViewModel @Inject constructor( filterIsInstance().filterNot { it.path.isNullOrBlank() }.flatMapConcat { intent -> - mediaRepo.requestMoveFilesToGroup(intent.path!!, intent.from, intent.to).map { + mediaRepo.moveFilesToGroup(intent.path!!, intent.from, intent.to).map { MediaPartialStateChange.MoveFilesToGroup.Success }.startWith(MediaPartialStateChange.LoadingDialog.Show) .catchMap { MediaPartialStateChange.MoveFilesToGroup.Failed(it.message.toString()) } @@ -127,7 +127,7 @@ class MediaViewModel @Inject constructor( filterIsInstance().filterNot { it.path.isNullOrBlank() }.flatMapConcat { intent -> - mediaRepo.requestRenameGroup(intent.path!!, intent.group, intent.newName).map { + mediaRepo.renameGroup(intent.path!!, intent.group, intent.newName).map { MediaPartialStateChange.EditGroup.Success(it) }.startWith(MediaPartialStateChange.LoadingDialog.Show) .catchMap { MediaPartialStateChange.EditGroup.Failed(it.message.toString()) } diff --git a/app/src/main/java/com/skyd/anivu/ui/screen/media/list/Media1Item.kt b/app/src/main/java/com/skyd/anivu/ui/screen/media/list/Media1Item.kt index e8ebbb8d..8d7a8ab0 100644 --- a/app/src/main/java/com/skyd/anivu/ui/screen/media/list/Media1Item.kt +++ b/app/src/main/java/com/skyd/anivu/ui/screen/media/list/Media1Item.kt @@ -49,7 +49,7 @@ import com.skyd.anivu.ext.openWith import com.skyd.anivu.ext.share import com.skyd.anivu.ext.toDateTimeString import com.skyd.anivu.ext.toUri -import com.skyd.anivu.model.bean.VideoBean +import com.skyd.anivu.model.bean.MediaBean import com.skyd.anivu.ui.component.AniVuImage import com.skyd.anivu.ui.component.rememberAniVuImageLoader import com.skyd.anivu.ui.local.LocalMediaShowThumbnail @@ -57,11 +57,11 @@ import java.util.Locale @Composable fun Media1Item( - data: VideoBean, - onPlay: (VideoBean) -> Unit, - onOpenDir: (VideoBean) -> Unit, - onRemove: (VideoBean) -> Unit, - onLongClick: ((VideoBean) -> Unit)? = null, + data: MediaBean, + onPlay: (MediaBean) -> Unit, + onOpenDir: (MediaBean) -> Unit, + onRemove: (MediaBean) -> Unit, + onLongClick: ((MediaBean) -> Unit)? = null, ) { val context = LocalContext.current var expandMenu by rememberSaveable { mutableStateOf(false) } diff --git a/app/src/main/java/com/skyd/anivu/ui/screen/media/list/MediaList.kt b/app/src/main/java/com/skyd/anivu/ui/screen/media/list/MediaList.kt index 26178f3d..bae9e06f 100644 --- a/app/src/main/java/com/skyd/anivu/ui/screen/media/list/MediaList.kt +++ b/app/src/main/java/com/skyd/anivu/ui/screen/media/list/MediaList.kt @@ -36,7 +36,7 @@ import com.skyd.anivu.ext.activity import com.skyd.anivu.ext.plus import com.skyd.anivu.ext.toUri import com.skyd.anivu.model.bean.MediaGroupBean -import com.skyd.anivu.model.bean.VideoBean +import com.skyd.anivu.model.bean.MediaBean import com.skyd.anivu.ui.activity.PlayActivity import com.skyd.anivu.ui.component.CircularProgressPlaceholder import com.skyd.anivu.ui.component.EmptyPlaceholder @@ -48,7 +48,7 @@ class GroupInfo( val group: MediaGroupBean, val version: Long, // For update, if version changed, MediaList will refresh media list val onCreateGroup: (MediaGroupBean) -> Unit, - val onMoveFileToGroup: (VideoBean, MediaGroupBean) -> Unit, + val onMoveFileToGroup: (MediaBean, MediaGroupBean) -> Unit, ) @Composable @@ -147,16 +147,16 @@ internal fun MediaList( @Composable private fun MediaList( modifier: Modifier = Modifier, - list: List, + list: List, groups: List, groupInfo: GroupInfo?, - onPlay: (VideoBean) -> Unit, - onOpenDir: (VideoBean) -> Unit, - onRemove: (VideoBean) -> Unit, + onPlay: (MediaBean) -> Unit, + onOpenDir: (MediaBean) -> Unit, + onRemove: (MediaBean) -> Unit, contentPadding: PaddingValues = PaddingValues(0.dp), ) { var openEditMediaDialog by rememberSaveable { - mutableStateOf(null, policy = referentialEqualityPolicy()) + mutableStateOf(null, policy = referentialEqualityPolicy()) } var openCreateGroupDialog by rememberSaveable { mutableStateOf(false) } var createGroupDialogGroup by rememberSaveable { mutableStateOf("") } diff --git a/app/src/main/java/com/skyd/anivu/ui/screen/media/list/MediaListPartialStateChange.kt b/app/src/main/java/com/skyd/anivu/ui/screen/media/list/MediaListPartialStateChange.kt index 4321b834..4dac41e6 100644 --- a/app/src/main/java/com/skyd/anivu/ui/screen/media/list/MediaListPartialStateChange.kt +++ b/app/src/main/java/com/skyd/anivu/ui/screen/media/list/MediaListPartialStateChange.kt @@ -2,7 +2,7 @@ package com.skyd.anivu.ui.screen.media.list import androidx.compose.ui.util.fastFirstOrNull import com.skyd.anivu.model.bean.MediaGroupBean -import com.skyd.anivu.model.bean.VideoBean +import com.skyd.anivu.model.bean.MediaBean import java.io.File @@ -42,7 +42,7 @@ internal sealed interface MediaListPartialStateChange { } } - data class Success(val list: List, val groups: List) : + data class Success(val list: List, val groups: List) : MediaListResult data class Failed(val msg: String) : MediaListResult diff --git a/app/src/main/java/com/skyd/anivu/ui/screen/media/list/MediaListState.kt b/app/src/main/java/com/skyd/anivu/ui/screen/media/list/MediaListState.kt index 5e375338..de0b36ea 100644 --- a/app/src/main/java/com/skyd/anivu/ui/screen/media/list/MediaListState.kt +++ b/app/src/main/java/com/skyd/anivu/ui/screen/media/list/MediaListState.kt @@ -2,7 +2,7 @@ package com.skyd.anivu.ui.screen.media.list import com.skyd.anivu.base.mvi.MviViewState import com.skyd.anivu.model.bean.MediaGroupBean -import com.skyd.anivu.model.bean.VideoBean +import com.skyd.anivu.model.bean.MediaBean data class MediaListState( val listState: ListState, @@ -19,7 +19,7 @@ data class MediaListState( } sealed class ListState(open val loading: Boolean) { - data class Success(val list: List, override val loading: Boolean = false) : + data class Success(val list: List, override val loading: Boolean = false) : ListState(loading) data class Init(override val loading: Boolean = false) : ListState(loading) diff --git a/app/src/main/java/com/skyd/anivu/ui/screen/media/list/MediaListViewModel.kt b/app/src/main/java/com/skyd/anivu/ui/screen/media/list/MediaListViewModel.kt index b646d467..cbf61db7 100644 --- a/app/src/main/java/com/skyd/anivu/ui/screen/media/list/MediaListViewModel.kt +++ b/app/src/main/java/com/skyd/anivu/ui/screen/media/list/MediaListViewModel.kt @@ -77,7 +77,7 @@ class MediaListViewModel @Inject constructor( .catchMap { MediaListPartialStateChange.MediaListResult.Failed(it.message.toString()) } }, filterIsInstance().flatMapConcat { intent -> - mediaRepo.requestDelete(intent.file).map { + mediaRepo.deleteFile(intent.file).map { MediaListPartialStateChange.DeleteFileResult.Success(file = intent.file) }.startWith(MediaListPartialStateChange.LoadingDialog.Show) .catchMap { MediaListPartialStateChange.DeleteFileResult.Failed(it.message.toString()) } diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml index 19711296..fb7f3c87 100644 --- a/gradle/libs.versions.toml +++ b/gradle/libs.versions.toml @@ -1,8 +1,8 @@ [versions] adaptive = "1.0.0" -coil = "3.0.2" +coil = "3.0.3" hilt = "2.52" -libtorrent4j = "2.1.0-31" +libtorrent4j = "2.1.0-35" composeMaterial = "1.7.5" composeMaterial3 = "1.4.0-alpha04" okhttp3 = "4.12.0" @@ -70,7 +70,7 @@ ceau-opmlparser = { module = "be.ceau:opml-parser", version = "3.1.0" } readability4j = { module = "net.dankito.readability4j:readability4j", version = "1.0.8" } -reorderable = { module = "sh.calvin.reorderable:reorderable", version = "2.3.3" } +reorderable = { module = "sh.calvin.reorderable:reorderable", version = "2.4.0" } libtorrent4j-arm64 = { module = "org.libtorrent4j:libtorrent4j-android-arm64", version.ref = "libtorrent4j" } libtorrent4j-arm = { module = "org.libtorrent4j:libtorrent4j-android-arm", version.ref = "libtorrent4j" }