feat(posts): add post creator, refactoring

This commit is contained in:
Diego Beraldin 2023-07-27 13:58:05 +02:00
parent 74cda9afcd
commit f645e9e81f
27 changed files with 352 additions and 222 deletions

View File

@ -1,4 +1,4 @@
package com.github.diegoberaldin.raccoonforlemmy.core_api
package com.github.diegoberaldin.raccoonforlemmy.core_api.di
import com.github.diegoberaldin.raccoonforlemmy.core_api.provider.DefaultServiceProvider
import com.github.diegoberaldin.raccoonforlemmy.core_api.provider.ServiceProvider

View File

@ -8,5 +8,5 @@ data class PostModel(
val comments: Int = 0,
val thumbnailUrl: String? = null,
val community: CommunityModel? = null,
val author: UserModel? = null,
val creator: UserModel? = null,
)

View File

@ -1,6 +1,8 @@
package com.github.diegoberaldin.raccoonforlemmy.data
data class UserModel(
val id: Int = 0,
val name: String = "",
val instance: String = "",
val avatar: String? = null,
val host: String = "",
)

View File

@ -3,6 +3,7 @@ package com.github.diegoberaldin.raccoonforlemmy.domain_post.repository
import com.github.diegoberaldin.raccoonforlemmy.core_api.dto.CommunityView
import com.github.diegoberaldin.raccoonforlemmy.core_api.service.CommunityService
import com.github.diegoberaldin.raccoonforlemmy.data.CommunityModel
import com.github.diegoberaldin.raccoonforlemmy.domain_post.repository.utils.toModel
class CommunityRepository(
private val communityService: CommunityService,
@ -14,8 +15,4 @@ class CommunityRepository(
}
}
private fun CommunityView.toModel() = CommunityModel(
name = community.name,
icon = community.icon,
host = extractHost(community.actorId),
)
private fun CommunityView.toModel() = community.toModel()

View File

@ -2,12 +2,11 @@ package com.github.diegoberaldin.raccoonforlemmy.domain_post.repository
import com.github.diegoberaldin.raccoonforlemmy.core_api.dto.PostView
import com.github.diegoberaldin.raccoonforlemmy.core_api.service.PostService
import com.github.diegoberaldin.raccoonforlemmy.data.CommunityModel
import com.github.diegoberaldin.raccoonforlemmy.data.ListingType
import com.github.diegoberaldin.raccoonforlemmy.data.PostModel
import com.github.diegoberaldin.raccoonforlemmy.data.SortType
import com.github.diegoberaldin.raccoonforlemmy.core_api.dto.ListingType as DtoListingType
import com.github.diegoberaldin.raccoonforlemmy.core_api.dto.SortType as DtoSortType
import com.github.diegoberaldin.raccoonforlemmy.domain_post.repository.utils.toDto
import com.github.diegoberaldin.raccoonforlemmy.domain_post.repository.utils.toModel
class PostsRepository(
private val postService: PostService,
@ -41,26 +40,6 @@ private fun PostView.toModel() = PostModel(
score = counts.score,
comments = counts.comments,
thumbnailUrl = post.thumbnailUrl.orEmpty(),
community = CommunityModel(id = post.communityId)
)
private fun ListingType.toDto() = when (this) {
ListingType.All -> DtoListingType.All
ListingType.Subscribed -> DtoListingType.Subscribed
ListingType.Local -> DtoListingType.Local
}
private fun SortType.toDto() = when (this) {
SortType.Hot -> DtoSortType.Hot
SortType.MostComments -> DtoSortType.MostComments
SortType.New -> DtoSortType.New
SortType.NewComments -> DtoSortType.NewComments
SortType.Top.Day -> DtoSortType.TopDay
SortType.Top.Month -> DtoSortType.TopMonth
SortType.Top.Past12Hours -> DtoSortType.TopTwelveHour
SortType.Top.Past6Hours -> DtoSortType.TopSixHour
SortType.Top.PastHour -> DtoSortType.TopHour
SortType.Top.Week -> DtoSortType.TopWeek
SortType.Top.Year -> DtoSortType.TopYear
else -> DtoSortType.Active
}
community = community.toModel(),
creator = creator.toModel(),
)

View File

@ -1,10 +0,0 @@
package com.github.diegoberaldin.raccoonforlemmy.domain_post.repository
import org.koin.core.module.dsl.singleOf
import org.koin.dsl.module
val postsRepositoryModule = module {
singleOf(::ApiConfigurationRepository)
singleOf(::PostsRepository)
singleOf(::CommunityRepository)
}

View File

@ -1,6 +0,0 @@
package com.github.diegoberaldin.raccoonforlemmy.domain_post.repository
internal fun extractHost(value: String) = value.replace("https://", "").let {
val i = it.indexOf("/")
it.substring(0, i)
}

View File

@ -0,0 +1,13 @@
package com.github.diegoberaldin.raccoonforlemmy.domain_post.repository.di
import com.github.diegoberaldin.raccoonforlemmy.domain_post.repository.ApiConfigurationRepository
import com.github.diegoberaldin.raccoonforlemmy.domain_post.repository.CommunityRepository
import com.github.diegoberaldin.raccoonforlemmy.domain_post.repository.PostsRepository
import org.koin.core.module.dsl.singleOf
import org.koin.dsl.module
val postsRepositoryModule = module {
singleOf(::ApiConfigurationRepository)
singleOf(::PostsRepository)
singleOf(::CommunityRepository)
}

View File

@ -0,0 +1,62 @@
package com.github.diegoberaldin.raccoonforlemmy.domain_post.repository.utils
import com.github.diegoberaldin.raccoonforlemmy.core_api.dto.Community
import com.github.diegoberaldin.raccoonforlemmy.core_api.dto.ListingType.All
import com.github.diegoberaldin.raccoonforlemmy.core_api.dto.ListingType.Local
import com.github.diegoberaldin.raccoonforlemmy.core_api.dto.ListingType.Subscribed
import com.github.diegoberaldin.raccoonforlemmy.core_api.dto.Person
import com.github.diegoberaldin.raccoonforlemmy.core_api.dto.SortType.Active
import com.github.diegoberaldin.raccoonforlemmy.core_api.dto.SortType.Hot
import com.github.diegoberaldin.raccoonforlemmy.core_api.dto.SortType.MostComments
import com.github.diegoberaldin.raccoonforlemmy.core_api.dto.SortType.New
import com.github.diegoberaldin.raccoonforlemmy.core_api.dto.SortType.NewComments
import com.github.diegoberaldin.raccoonforlemmy.core_api.dto.SortType.TopDay
import com.github.diegoberaldin.raccoonforlemmy.core_api.dto.SortType.TopHour
import com.github.diegoberaldin.raccoonforlemmy.core_api.dto.SortType.TopMonth
import com.github.diegoberaldin.raccoonforlemmy.core_api.dto.SortType.TopSixHour
import com.github.diegoberaldin.raccoonforlemmy.core_api.dto.SortType.TopTwelveHour
import com.github.diegoberaldin.raccoonforlemmy.core_api.dto.SortType.TopWeek
import com.github.diegoberaldin.raccoonforlemmy.core_api.dto.SortType.TopYear
import com.github.diegoberaldin.raccoonforlemmy.data.CommunityModel
import com.github.diegoberaldin.raccoonforlemmy.data.ListingType
import com.github.diegoberaldin.raccoonforlemmy.data.SortType
import com.github.diegoberaldin.raccoonforlemmy.data.UserModel
internal fun ListingType.toDto() = when (this) {
ListingType.All -> All
ListingType.Subscribed -> Subscribed
ListingType.Local -> Local
}
internal fun SortType.toDto() = when (this) {
SortType.Hot -> Hot
SortType.MostComments -> MostComments
SortType.New -> New
SortType.NewComments -> NewComments
SortType.Top.Day -> TopDay
SortType.Top.Month -> TopMonth
SortType.Top.Past12Hours -> TopTwelveHour
SortType.Top.Past6Hours -> TopSixHour
SortType.Top.PastHour -> TopHour
SortType.Top.Week -> TopWeek
SortType.Top.Year -> TopYear
else -> Active
}
internal fun Community.toModel() = CommunityModel(
name = name,
icon = icon,
host = extractHost(actorId),
)
internal fun Person.toModel() = UserModel(
name = name,
avatar = avatar,
host = extractHost(actorId)
)
internal fun extractHost(value: String) = value.replace("https://", "").let {
val i = it.indexOf("/")
it.substring(0, i)
}

View File

@ -1,7 +1,9 @@
package com.github.diegoberaldin.raccoonforlemmy.feature_home
package com.github.diegoberaldin.raccoonforlemmy.feature_home.di
import com.github.diegoberaldin.raccoonforlemmy.core_architecture.DefaultMviModel
import com.github.diegoberaldin.raccoonforlemmy.domain_post.repository.postsRepositoryModule
import com.github.diegoberaldin.raccoonforlemmy.domain_post.repository.di.postsRepositoryModule
import com.github.diegoberaldin.raccoonforlemmy.feature_home.viewmodel.HomeScreenModel
import com.github.diegoberaldin.raccoonforlemmy.feature_home.viewmodel.HomeScreenMviModel
import org.koin.dsl.module
import org.koin.java.KoinJavaComponent.inject
@ -11,7 +13,6 @@ actual val homeTabModule = module {
HomeScreenModel(
mvi = DefaultMviModel(HomeScreenMviModel.UiState()),
postsRepository = get(),
communityRepository = get(),
apiConfigRepository = get(),
)
}

View File

@ -1,7 +0,0 @@
package com.github.diegoberaldin.raccoonforlemmy.feature_home
import org.koin.core.module.Module
expect val homeTabModule: Module
expect fun getHomeScreenModel(): HomeScreenModel

View File

@ -1,135 +0,0 @@
package com.github.diegoberaldin.raccoonforlemmy.feature_home
import androidx.compose.foundation.Image
import androidx.compose.foundation.background
import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.Spacer
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.size
import androidx.compose.foundation.shape.RoundedCornerShape
import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.filled.ArrowDropDown
import androidx.compose.material.icons.filled.ArrowDropUp
import androidx.compose.material.icons.filled.Chat
import androidx.compose.material3.Card
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.draw.clip
import androidx.compose.ui.graphics.ColorFilter
import androidx.compose.ui.layout.ContentScale
import androidx.compose.ui.unit.dp
import com.github.diegoberaldin.raccoonforlemmy.core_appearance.theme.CornerSize
import com.github.diegoberaldin.raccoonforlemmy.core_appearance.theme.Spacing
import com.github.diegoberaldin.raccoonforlemmy.core_md.compose.Markdown
import com.github.diegoberaldin.raccoonforlemmy.data.PostModel
import com.seiko.imageloader.rememberImagePainter
@Composable
fun PostCard(
post: PostModel,
) {
Card(
modifier = Modifier
.fillMaxWidth()
.background(
color = MaterialTheme.colorScheme.surfaceVariant,
shape = RoundedCornerShape(CornerSize.m)
).padding(
vertical = Spacing.lHalf,
horizontal = Spacing.s,
)
) {
Column(
verticalArrangement = Arrangement.spacedBy(Spacing.s)
) {
Text(
text = post.title,
style = MaterialTheme.typography.titleMedium,
)
val communityName = post.community?.name.orEmpty()
val communityIcon = post.community?.icon.orEmpty()
val communityHost = post.community?.host.orEmpty()
val iconSize = 20.dp
if (communityName.isNotEmpty()) {
Row(
verticalAlignment = Alignment.CenterVertically,
horizontalArrangement = Arrangement.spacedBy(Spacing.s),
) {
if (communityIcon.isNotEmpty()) {
val painter = rememberImagePainter(communityIcon)
Image(
modifier = Modifier.size(iconSize)
.clip(RoundedCornerShape(iconSize / 2)),
painter = painter,
contentDescription = null,
contentScale = ContentScale.FillBounds,
)
}
Text(
text = buildString {
append(communityName)
if (communityHost.isNotEmpty()) {
append("@$communityHost")
}
},
style = MaterialTheme.typography.titleSmall,
)
}
}
val imageUrl = post.thumbnailUrl
if (!imageUrl.isNullOrEmpty()) {
val painter = rememberImagePainter(imageUrl)
Image(
modifier = Modifier.fillMaxWidth(),
painter = painter,
contentDescription = null,
contentScale = ContentScale.FillWidth,
)
}
val body = post.text
if (body.isNotEmpty()) {
Markdown(content = body)
}
Row(
verticalAlignment = Alignment.CenterVertically,
horizontalArrangement = Arrangement.spacedBy(Spacing.xxs),
) {
val buttonModifier = Modifier.size(42.dp)
Image(
modifier = buttonModifier,
imageVector = Icons.Default.ArrowDropUp,
contentDescription = null,
colorFilter = ColorFilter.tint(color = MaterialTheme.colorScheme.onSurface)
)
Text(
text = "${post.score}"
)
Image(
modifier = buttonModifier,
imageVector = Icons.Default.ArrowDropDown,
contentDescription = null,
colorFilter = ColorFilter.tint(color = MaterialTheme.colorScheme.onSurface)
)
Spacer(modifier = Modifier.weight(1f))
Image(
modifier = buttonModifier.padding(10.dp),
imageVector = Icons.Default.Chat,
contentDescription = null,
colorFilter = ColorFilter.tint(color = MaterialTheme.colorScheme.onSurface)
)
Text(
modifier = Modifier.padding(end = Spacing.s),
text = "${post.comments}"
)
}
}
}
}

View File

@ -0,0 +1,8 @@
package com.github.diegoberaldin.raccoonforlemmy.feature_home.di
import com.github.diegoberaldin.raccoonforlemmy.feature_home.viewmodel.HomeScreenModel
import org.koin.core.module.Module
expect val homeTabModule: Module
expect fun getHomeScreenModel(): HomeScreenModel

View File

@ -1,4 +1,4 @@
package com.github.diegoberaldin.raccoonforlemmy.feature_home
package com.github.diegoberaldin.raccoonforlemmy.feature_home.ui
import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Box
@ -31,6 +31,8 @@ import cafe.adriel.voyager.navigator.tab.Tab
import cafe.adriel.voyager.navigator.tab.TabOptions
import com.github.diegoberaldin.raccoonforlemmy.core_appearance.theme.Spacing
import com.github.diegoberaldin.raccoonforlemmy.core_architecture.bindToLifecycle
import com.github.diegoberaldin.raccoonforlemmy.feature_home.viewmodel.HomeScreenMviModel
import com.github.diegoberaldin.raccoonforlemmy.feature_home.di.getHomeScreenModel
import com.github.diegoberaldin.raccoonforlemmy.feature_home.modals.ListingTypeBottomSheet
import com.github.diegoberaldin.raccoonforlemmy.feature_home.modals.SortBottomSheet
import com.github.diegoberaldin.raccoonforlemmy.resources.MR

View File

@ -0,0 +1,42 @@
package com.github.diegoberaldin.raccoonforlemmy.feature_home.ui
import androidx.compose.foundation.background
import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.shape.RoundedCornerShape
import androidx.compose.material3.Card
import androidx.compose.material3.MaterialTheme
import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier
import com.github.diegoberaldin.raccoonforlemmy.core_appearance.theme.CornerSize
import com.github.diegoberaldin.raccoonforlemmy.core_appearance.theme.Spacing
import com.github.diegoberaldin.raccoonforlemmy.data.PostModel
@Composable
fun PostCard(
post: PostModel,
) {
Card(
modifier = Modifier
.fillMaxWidth()
.background(
color = MaterialTheme.colorScheme.surfaceVariant,
shape = RoundedCornerShape(CornerSize.m)
).padding(
vertical = Spacing.lHalf,
horizontal = Spacing.s,
)
) {
Column(
verticalArrangement = Arrangement.spacedBy(Spacing.s)
) {
PostCardTitle(post)
PostCardSubtitle(post)
PostCardImage(post)
PostCardBody(post)
PostCardFooter(post)
}
}
}

View File

@ -0,0 +1,13 @@
package com.github.diegoberaldin.raccoonforlemmy.feature_home.ui
import androidx.compose.runtime.Composable
import com.github.diegoberaldin.raccoonforlemmy.core_md.compose.Markdown
import com.github.diegoberaldin.raccoonforlemmy.data.PostModel
@Composable
internal fun PostCardBody(post: PostModel) {
val body = post.text
if (body.isNotEmpty()) {
Markdown(content = body)
}
}

View File

@ -0,0 +1,57 @@
package com.github.diegoberaldin.raccoonforlemmy.feature_home.ui
import androidx.compose.foundation.Image
import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.Spacer
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.size
import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.filled.ArrowDropDown
import androidx.compose.material.icons.filled.ArrowDropUp
import androidx.compose.material.icons.filled.Chat
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.ColorFilter
import androidx.compose.ui.unit.dp
import com.github.diegoberaldin.raccoonforlemmy.core_appearance.theme.Spacing
import com.github.diegoberaldin.raccoonforlemmy.data.PostModel
@Composable
internal fun PostCardFooter(post: PostModel) {
Row(
verticalAlignment = Alignment.CenterVertically,
horizontalArrangement = Arrangement.spacedBy(Spacing.xxs),
) {
val buttonModifier = Modifier.size(42.dp)
Image(
modifier = buttonModifier,
imageVector = Icons.Default.ArrowDropUp,
contentDescription = null,
colorFilter = ColorFilter.tint(color = MaterialTheme.colorScheme.onSurface)
)
Text(
text = "${post.score}"
)
Image(
modifier = buttonModifier,
imageVector = Icons.Default.ArrowDropDown,
contentDescription = null,
colorFilter = ColorFilter.tint(color = MaterialTheme.colorScheme.onSurface)
)
Spacer(modifier = Modifier.weight(1f))
Image(
modifier = buttonModifier.padding(10.dp),
imageVector = Icons.Default.Chat,
contentDescription = null,
colorFilter = ColorFilter.tint(color = MaterialTheme.colorScheme.onSurface)
)
Text(
modifier = Modifier.padding(end = Spacing.s),
text = "${post.comments}"
)
}
}

View File

@ -0,0 +1,25 @@
package com.github.diegoberaldin.raccoonforlemmy.feature_home.ui
import androidx.compose.foundation.Image
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.heightIn
import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier
import androidx.compose.ui.layout.ContentScale
import androidx.compose.ui.unit.dp
import com.github.diegoberaldin.raccoonforlemmy.data.PostModel
import com.seiko.imageloader.rememberImagePainter
@Composable
internal fun PostCardImage(post: PostModel) {
val imageUrl = post.thumbnailUrl
if (!imageUrl.isNullOrEmpty()) {
val painter = rememberImagePainter(imageUrl)
Image(
modifier = Modifier.fillMaxWidth().heightIn(min = 200.dp),
painter = painter,
contentDescription = null,
contentScale = ContentScale.FillWidth,
)
}
}

View File

@ -0,0 +1,84 @@
package com.github.diegoberaldin.raccoonforlemmy.feature_home.ui
import androidx.compose.foundation.Image
import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.size
import androidx.compose.foundation.shape.RoundedCornerShape
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.draw.clip
import androidx.compose.ui.layout.ContentScale
import androidx.compose.ui.unit.dp
import com.github.diegoberaldin.raccoonforlemmy.core_appearance.theme.Spacing
import com.github.diegoberaldin.raccoonforlemmy.data.PostModel
import com.seiko.imageloader.rememberImagePainter
@Composable
internal fun PostCardSubtitle(post: PostModel) {
val communityName = post.community?.name.orEmpty()
val communityIcon = post.community?.icon.orEmpty()
val communityHost = post.community?.host.orEmpty()
val creatorName = post.creator?.name.orEmpty()
val creatorAvatar = post.creator?.avatar.orEmpty()
val creatorHost = post.creator?.host.orEmpty()
val iconSize = 16.dp
if (communityName.isNotEmpty() || creatorName.isNotEmpty()) {
Row(
verticalAlignment = Alignment.CenterVertically,
horizontalArrangement = Arrangement.spacedBy(Spacing.xxs),
) {
if (communityName.isNotEmpty()) {
if (communityIcon.isNotEmpty()) {
val painter = rememberImagePainter(communityIcon)
Image(
modifier = Modifier.size(iconSize)
.clip(RoundedCornerShape(iconSize / 2)),
painter = painter,
contentDescription = null,
contentScale = ContentScale.FillBounds,
)
}
Text(
text = buildString {
append(communityName)
if (communityHost.isNotEmpty()) {
append("@$communityHost")
}
},
style = MaterialTheme.typography.bodySmall,
)
}
if (creatorName.isNotEmpty()) {
if (communityName.isNotEmpty()) {
Text(
text = "",
style = MaterialTheme.typography.bodySmall,
)
}
if (creatorAvatar.isNotEmpty()) {
val painter = rememberImagePainter(creatorAvatar)
Image(
modifier = Modifier.size(iconSize)
.clip(RoundedCornerShape(iconSize / 2)),
painter = painter,
contentDescription = null,
contentScale = ContentScale.FillBounds,
)
}
Text(
text = buildString {
append(creatorName)
if (creatorHost.isNotEmpty() && communityHost != creatorHost) {
append("@$creatorHost")
}
},
style = MaterialTheme.typography.bodySmall,
)
}
}
}
}

View File

@ -0,0 +1,14 @@
package com.github.diegoberaldin.raccoonforlemmy.feature_home.ui
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import com.github.diegoberaldin.raccoonforlemmy.data.PostModel
@Composable
internal fun PostCardTitle(post: PostModel) {
Text(
text = post.title,
style = MaterialTheme.typography.titleMedium,
)
}

View File

@ -1,4 +1,4 @@
package com.github.diegoberaldin.raccoonforlemmy.feature_home
package com.github.diegoberaldin.raccoonforlemmy.feature_home.ui
import androidx.compose.foundation.Image
import androidx.compose.foundation.layout.Arrangement
@ -18,6 +18,8 @@ import com.github.diegoberaldin.racconforlemmy.core_utils.onClick
import com.github.diegoberaldin.raccoonforlemmy.core_appearance.theme.Spacing
import com.github.diegoberaldin.raccoonforlemmy.data.ListingType
import com.github.diegoberaldin.raccoonforlemmy.data.SortType
import com.github.diegoberaldin.raccoonforlemmy.feature_home.toIcon
import com.github.diegoberaldin.raccoonforlemmy.feature_home.toReadableName
import com.github.diegoberaldin.raccoonforlemmy.resources.MR
import dev.icerock.moko.resources.compose.stringResource

View File

@ -1,4 +1,4 @@
package com.github.diegoberaldin.raccoonforlemmy.feature_home
package com.github.diegoberaldin.raccoonforlemmy.feature_home.viewmodel
import cafe.adriel.voyager.core.model.ScreenModel
import com.github.diegoberaldin.raccoonforlemmy.core_architecture.DefaultMviModel
@ -6,7 +6,6 @@ import com.github.diegoberaldin.raccoonforlemmy.core_architecture.MviModel
import com.github.diegoberaldin.raccoonforlemmy.data.ListingType
import com.github.diegoberaldin.raccoonforlemmy.data.SortType
import com.github.diegoberaldin.raccoonforlemmy.domain_post.repository.ApiConfigurationRepository
import com.github.diegoberaldin.raccoonforlemmy.domain_post.repository.CommunityRepository
import com.github.diegoberaldin.raccoonforlemmy.domain_post.repository.PostsRepository
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.IO
@ -15,7 +14,6 @@ import kotlinx.coroutines.launch
class HomeScreenModel(
private val mvi: DefaultMviModel<HomeScreenMviModel.Intent, HomeScreenMviModel.UiState, HomeScreenMviModel.Effect>,
private val postsRepository: PostsRepository,
private val communityRepository: CommunityRepository,
private val apiConfigRepository: ApiConfigurationRepository,
) : ScreenModel,
MviModel<HomeScreenMviModel.Intent, HomeScreenMviModel.UiState, HomeScreenMviModel.Effect> by mvi {
@ -58,21 +56,7 @@ class HomeScreenModel(
page = currentPage,
type = type,
sort = sort,
).map {
val community = it.community
if (community?.id != null) {
val remoteCommunity = communityRepository.getCommunity(community.id)
it.copy(
community = it.community?.copy(
name = remoteCommunity?.name.orEmpty(),
icon = remoteCommunity?.icon,
host = remoteCommunity?.host.orEmpty(),
)
)
} else {
it
}
}
)
currentPage++
val canFetchMore = postList.size >= PostsRepository.DEFAULT_PAGE_SIZE
mvi.updateState {

View File

@ -1,4 +1,4 @@
package com.github.diegoberaldin.raccoonforlemmy.feature_home
package com.github.diegoberaldin.raccoonforlemmy.feature_home.viewmodel
import com.github.diegoberaldin.raccoonforlemmy.core_architecture.MviModel
import com.github.diegoberaldin.raccoonforlemmy.data.ListingType

View File

@ -1,7 +1,9 @@
package com.github.diegoberaldin.raccoonforlemmy.feature_home
package com.github.diegoberaldin.raccoonforlemmy.feature_home.di
import com.github.diegoberaldin.raccoonforlemmy.core_architecture.DefaultMviModel
import com.github.diegoberaldin.raccoonforlemmy.domain_post.repository.postsRepositoryModule
import com.github.diegoberaldin.raccoonforlemmy.feature_home.viewmodel.HomeScreenModel
import com.github.diegoberaldin.raccoonforlemmy.feature_home.viewmodel.HomeScreenMviModel
import org.koin.core.component.KoinComponent
import org.koin.core.component.inject
import org.koin.dsl.module
@ -12,6 +14,7 @@ actual val homeTabModule = module {
HomeScreenModel(
mvi = DefaultMviModel(HomeScreenMviModel.UiState()),
postsRepository = get(),
apiConfigRepository = get(),
)
}
}

View File

@ -1,12 +1,12 @@
package com.github.diegoberaldin.raccoonforlemmy
import com.github.diegoberaldin.raccoonforlemmy.core_api.coreApiModule
import com.github.diegoberaldin.raccoonforlemmy.core_api.di.coreApiModule
import com.github.diegoberaldin.raccoonforlemmy.core_appearance.di.coreAppearanceModule
import com.github.diegoberaldin.raccoonforlemmy.core_preferences.di.corePreferencesModule
import com.github.diegoberaldin.raccoonforlemmy.feature_inbox.inboxTabModule
import com.github.diegoberaldin.raccoonforlemmy.feature_profile.profileTabModule
import com.github.diegoberaldin.raccoonforlemmy.feature_search.searchTabModule
import com.github.diegoberaldin.raccoonforlemmy.feature_home.homeTabModule
import com.github.diegoberaldin.raccoonforlemmy.feature_home.di.homeTabModule
import com.github.diegoberaldin.raccoonforlemmy.feature_settings.settingsTabModule
import com.github.diegoberaldin.raccoonforlemmy.resources.localizationModule
import org.koin.dsl.module

View File

@ -20,7 +20,7 @@ import cafe.adriel.voyager.navigator.tab.TabNavigator
import com.github.diegoberaldin.raccoonforlemmy.core_appearance.theme.AppTheme
import com.github.diegoberaldin.raccoonforlemmy.core_preferences.KeyStoreKeys
import com.github.diegoberaldin.raccoonforlemmy.core_preferences.di.getTemporaryKeyStore
import com.github.diegoberaldin.raccoonforlemmy.feature_home.HomeTab
import com.github.diegoberaldin.raccoonforlemmy.feature_home.ui.HomeTab
import com.github.diegoberaldin.raccoonforlemmy.feature_inbox.InboxTab
import com.github.diegoberaldin.raccoonforlemmy.feature_profile.ProfileTab
import com.github.diegoberaldin.raccoonforlemmy.feature_search.SearchTab

View File

@ -1,12 +1,12 @@
package com.github.diegoberaldin.raccoonforlemmy
import com.github.diegoberaldin.raccoonforlemmy.core_api.coreApiModule
import com.github.diegoberaldin.raccoonforlemmy.core_api.di.coreApiModule
import com.github.diegoberaldin.raccoonforlemmy.core_appearance.di.coreAppearanceModule
import com.github.diegoberaldin.raccoonforlemmy.core_preferences.di.corePreferencesModule
import com.github.diegoberaldin.raccoonforlemmy.feature_home.di.homeTabModule
import com.github.diegoberaldin.raccoonforlemmy.feature_inbox.inboxTabModule
import com.github.diegoberaldin.raccoonforlemmy.feature_profile.profileTabModule
import com.github.diegoberaldin.raccoonforlemmy.feature_search.searchTabModule
import com.github.diegoberaldin.raccoonforlemmy.feature_home.homeTabModule
import com.github.diegoberaldin.raccoonforlemmy.feature_settings.settingsTabModule
import com.github.diegoberaldin.raccoonforlemmy.resources.localizationModule
import org.koin.core.context.startKoin