Skip to content

Commit

Permalink
[fix|build] Fix the height issue of article item image; update depend…
Browse files Browse the repository at this point in the history
…encies
  • Loading branch information
SkyD666 committed Nov 25, 2024
1 parent aa6337c commit 248a3ae
Show file tree
Hide file tree
Showing 12 changed files with 58 additions and 48 deletions.
2 changes: 1 addition & 1 deletion app/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ android {
minSdk = 24
targetSdk = 35
versionCode = 24
versionName = "2.1-beta09"
versionName = "2.1-beta10"

testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -37,7 +37,7 @@ class MediaRepository @Inject constructor(
}.flowOn(Dispatchers.IO)
}

fun requestFiles(uriPath: String, group: MediaGroupBean?): Flow<List<VideoBean>> {
fun requestFiles(uriPath: String, group: MediaGroupBean?): Flow<List<MediaBean>> {
return flow {
val groupJsonFile = File(uriPath, GROUP_JSON_NAME)
val mediaGroupJson = parseGroupJson(groupJsonFile)
Expand All @@ -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,
)
Expand All @@ -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,
)
Expand All @@ -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,
)
Expand All @@ -81,13 +81,13 @@ class MediaRepository @Inject constructor(
}.flowOn(Dispatchers.IO)
}

fun requestDelete(file: File): Flow<Boolean> {
fun deleteFile(file: File): Flow<Boolean> {
return flow {
emit(file.deleteRecursively())
}.flowOn(Dispatchers.IO)
}

fun requestCreateGroup(uriPath: String, group: MediaGroupBean): Flow<Unit> = flow {
fun createGroup(uriPath: String, group: MediaGroupBean): Flow<Unit> = flow {
if (group.isDefaultGroup()) {
emit(Unit)
return@flow
Expand All @@ -103,7 +103,7 @@ class MediaRepository @Inject constructor(
emit(Unit)
}.flowOn(Dispatchers.IO)

fun requestDeleteGroup(uriPath: String, group: MediaGroupBean): Flow<Int> = flow {
fun deleteGroup(uriPath: String, group: MediaGroupBean): Flow<Int> = flow {
if (group.isDefaultGroup()) {
emit(0)
return@flow
Expand All @@ -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,
Expand Down Expand Up @@ -162,25 +162,25 @@ class MediaRepository @Inject constructor(
emit(MediaGroupBean(name = newName))
}.flowOn(Dispatchers.IO)

fun requestChangeMediaGroup(
fun changeMediaGroup(
uriPath: String,
videoBean: VideoBean,
mediaBean: MediaBean,
group: MediaGroupBean,
): Flow<Unit> = 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()
.apply {
if (!group.isDefaultGroup()) {
add(
FileToGroup(
fileName = videoBean.file.name,
fileName = mediaBean.file.name,
groupName = group.name,
isFile = videoBean.file.isFile,
isFile = mediaBean.file.isFile,
)
)
}
Expand All @@ -190,7 +190,7 @@ class MediaRepository @Inject constructor(
emit(Unit)
}.flowOn(Dispatchers.IO)

fun requestMoveFilesToGroup(
fun moveFilesToGroup(
path: String,
from: MediaGroupBean,
to: MediaGroupBean
Expand Down
16 changes: 13 additions & 3 deletions app/src/main/java/com/skyd/anivu/ui/screen/article/Article1Item.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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,
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ class MediaViewModel @Inject constructor(
filterIsInstance<MediaIntent.ChangeMediaGroup>().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)
Expand All @@ -103,31 +103,31 @@ class MediaViewModel @Inject constructor(
filterIsInstance<MediaIntent.DeleteGroup>().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()) }
},
filterIsInstance<MediaIntent.CreateGroup>().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()) }
},
filterIsInstance<MediaIntent.MoveFilesToGroup>().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()) }
},
filterIsInstance<MediaIntent.RenameGroup>().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()) }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,19 +49,19 @@ 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
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) }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -147,16 +147,16 @@ internal fun MediaList(
@Composable
private fun MediaList(
modifier: Modifier = Modifier,
list: List<VideoBean>,
list: List<MediaBean>,
groups: List<MediaGroupBean>,
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<VideoBean?>(null, policy = referentialEqualityPolicy())
mutableStateOf<MediaBean?>(null, policy = referentialEqualityPolicy())
}
var openCreateGroupDialog by rememberSaveable { mutableStateOf(false) }
var createGroupDialogGroup by rememberSaveable { mutableStateOf("") }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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


Expand Down Expand Up @@ -42,7 +42,7 @@ internal sealed interface MediaListPartialStateChange {
}
}

data class Success(val list: List<VideoBean>, val groups: List<MediaGroupBean>) :
data class Success(val list: List<MediaBean>, val groups: List<MediaGroupBean>) :
MediaListResult

data class Failed(val msg: String) : MediaListResult
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -19,7 +19,7 @@ data class MediaListState(
}

sealed class ListState(open val loading: Boolean) {
data class Success(val list: List<VideoBean>, override val loading: Boolean = false) :
data class Success(val list: List<MediaBean>, override val loading: Boolean = false) :
ListState(loading)

data class Init(override val loading: Boolean = false) : ListState(loading)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ class MediaListViewModel @Inject constructor(
.catchMap { MediaListPartialStateChange.MediaListResult.Failed(it.message.toString()) }
},
filterIsInstance<MediaListIntent.DeleteFile>().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()) }
Expand Down
6 changes: 3 additions & 3 deletions gradle/libs.versions.toml
Original file line number Diff line number Diff line change
@@ -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"
Expand Down Expand Up @@ -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" }
Expand Down

0 comments on commit 248a3ae

Please sign in to comment.