Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -170,8 +170,11 @@ internal fun RecordRegisterResponse.toModel(): RecordRegisterModel {

internal fun ReadingRecordsResponse.toModel(): ReadingRecordsModel {
return ReadingRecordsModel(
content = content.map { it.toModel() },
page = page.toModel(),
lastPage = lastPage,
totalResults = totalResults,
startIndex = startIndex,
itemsPerPage = itemsPerPage,
readingRecords = readingRecords.map { it.toModel() },
)
}

Expand All @@ -188,6 +191,7 @@ internal fun ReadingRecord.toModel(): ReadingRecordModel {
bookTitle = bookTitle,
bookPublisher = bookPublisher,
bookCoverImageUrl = bookCoverImageUrl,
author = author,
)
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
package com.ninecraft.booket.core.model

data class ReadingRecordsModel(
val content: List<ReadingRecordModel> = emptyList(),
val page: PageInfoModel = PageInfoModel(),
val lastPage: Boolean = true,
val totalResults: Int = 0,
val startIndex: Int = 0,
val itemsPerPage: Int = 0,
val readingRecords: List<ReadingRecordModel> = emptyList(),
)

data class ReadingRecordModel(
Expand All @@ -17,4 +20,5 @@ data class ReadingRecordModel(
val bookTitle: String = "",
val bookPublisher: String = "",
val bookCoverImageUrl: String = "",
val author: String = "",
)
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,16 @@ import kotlinx.serialization.Serializable

@Serializable
data class ReadingRecordsResponse(
@SerialName("content")
val content: List<ReadingRecord>,
@SerialName("page")
val page: PageInfo,
@SerialName("lastPage")
val lastPage: Boolean,
@SerialName("totalResults")
val totalResults: Int,
@SerialName("startIndex")
val startIndex: Int,
@SerialName("itemsPerPage")
val itemsPerPage: Int,
@SerialName("readingRecords")
val readingRecords: List<ReadingRecord>,
)

@Serializable
Expand All @@ -35,4 +41,6 @@ data class ReadingRecord(
val bookPublisher: String,
@SerialName("bookCoverImageUrl")
val bookCoverImageUrl: String,
@SerialName("author")
val author: String,
)
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ import com.ninecraft.booket.core.data.api.repository.BookRepository
import com.ninecraft.booket.core.data.api.repository.RecordRepository
import com.ninecraft.booket.core.model.BookDetailModel
import com.ninecraft.booket.core.model.EmotionModel
import com.ninecraft.booket.core.model.PageInfoModel
import com.ninecraft.booket.core.model.ReadingRecordModel
import com.ninecraft.booket.core.ui.component.FooterState
import com.ninecraft.booket.feature.screens.BookDetailScreen
Expand All @@ -36,6 +35,7 @@ import kotlinx.collections.immutable.persistentListOf
import kotlinx.collections.immutable.toImmutableList
import kotlinx.collections.immutable.toPersistentList
import kotlinx.coroutines.async
import kotlinx.coroutines.coroutineScope
import kotlinx.coroutines.launch
import java.time.LocalDateTime

Expand Down Expand Up @@ -65,7 +65,7 @@ class BookDetailPresenter @AssistedInject constructor(
var bookDetail by rememberRetained { mutableStateOf(BookDetailModel()) }
var seedsStates by rememberRetained { mutableStateOf<ImmutableList<EmotionModel>>(persistentListOf()) }
var readingRecords by rememberRetained { mutableStateOf(persistentListOf<ReadingRecordModel>()) }
var readingRecordsPageInfo by rememberRetained { mutableStateOf(PageInfoModel()) }
var readingRecordsTotalCount by rememberRetained { mutableIntStateOf(0) }
var currentStartIndex by rememberRetained { mutableIntStateOf(START_INDEX) }
var isLastPage by rememberRetained { mutableStateOf(false) }
var currentBookStatus by rememberRetained { mutableStateOf(BookStatus.READING) }
Expand All @@ -76,11 +76,11 @@ class BookDetailPresenter @AssistedInject constructor(
var sideEffect by rememberRetained { mutableStateOf<BookDetailSideEffect?>(null) }

@Suppress("TooGenericExceptionCaught")
fun initialLoad() {
suspend fun initialLoad() {
uiState = UiState.Loading

try {
scope.launch {
coroutineScope {
val bookDetailDef = async { bookRepository.getBookDetail(screen.isbn13).getOrThrow() }
val seedsDef = async { bookRepository.getSeedsStats(screen.userBookId).getOrThrow() }
val readingRecordsDef = async {
Expand All @@ -99,10 +99,10 @@ class BookDetailPresenter @AssistedInject constructor(
currentBookStatus = BookStatus.fromValue(detail.userBookStatus) ?: BookStatus.BEFORE_READING
selectedBookStatus = currentBookStatus
seedsStates = seeds.categories.toImmutableList()
readingRecords = records.content.toPersistentList()
readingRecordsPageInfo = records.page
readingRecords = records.readingRecords.toPersistentList()
readingRecordsTotalCount = records.totalResults

isLastPage = records.content.size < PAGE_SIZE
isLastPage = records.lastPage
currentStartIndex = START_INDEX

uiState = UiState.Success
Expand Down Expand Up @@ -170,9 +170,9 @@ class BookDetailPresenter @AssistedInject constructor(
page = startIndex,
size = PAGE_SIZE,
).onSuccess { result ->
readingRecords = (readingRecords + result.content).toPersistentList()
readingRecords = (readingRecords + result.readingRecords).toPersistentList()
currentStartIndex = startIndex
isLastPage = result.content.size < PAGE_SIZE
isLastPage = result.lastPage
footerState = if (isLastPage) FooterState.End else FooterState.Idle
}.onFailure { exception ->
Logger.d(exception)
Expand Down Expand Up @@ -254,7 +254,7 @@ class BookDetailPresenter @AssistedInject constructor(
bookDetail = bookDetail,
seedsStats = seedsStates,
readingRecords = readingRecords,
readingRecordsPageInfo = readingRecordsPageInfo,
readingRecordsTotalCount = readingRecordsTotalCount,
isBookUpdateBottomSheetVisible = isBookUpdateBottomSheetVisible,
isRecordSortBottomSheetVisible = isRecordSortBottomSheetVisible,
currentBookStatus = currentBookStatus,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,7 @@ internal fun BookDetailContent(
) {
Spacer(modifier = Modifier.height(ReedTheme.spacing.spacing6))
ReadingRecordsHeader(
pageInfo = state.readingRecordsPageInfo,
totalCount = state.readingRecordsTotalCount,
currentRecordSort = state.currentRecordSort,
onReadingRecordClick = {
state.eventSink(BookDetailUiEvent.OnRecordSortButtonClick)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import com.ninecraft.booket.core.common.R
import com.ninecraft.booket.core.common.constants.BookStatus
import com.ninecraft.booket.core.model.BookDetailModel
import com.ninecraft.booket.core.model.EmotionModel
import com.ninecraft.booket.core.model.PageInfoModel
import com.ninecraft.booket.core.model.ReadingRecordModel
import com.ninecraft.booket.core.ui.component.FooterState
import com.slack.circuit.runtime.CircuitUiEvent
Expand All @@ -28,7 +27,7 @@ data class BookDetailUiState(
val bookDetail: BookDetailModel = BookDetailModel(),
val seedsStats: ImmutableList<EmotionModel> = persistentListOf(),
val readingRecords: ImmutableList<ReadingRecordModel> = persistentListOf(),
val readingRecordsPageInfo: PageInfoModel = PageInfoModel(),
val readingRecordsTotalCount: Int = 0,
val currentStartIndex: Int = 1,
val isLastPage: Boolean = false,
val currentBookStatus: BookStatus = BookStatus.BEFORE_READING,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,13 @@ import androidx.compose.ui.graphics.vector.ImageVector
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.res.vectorResource
import com.ninecraft.booket.core.designsystem.theme.ReedTheme
import com.ninecraft.booket.core.model.PageInfoModel
import com.ninecraft.booket.feature.detail.R
import com.ninecraft.booket.feature.detail.book.RecordSort
import com.ninecraft.booket.core.designsystem.R as designR

@Composable
internal fun ReadingRecordsHeader(
pageInfo: PageInfoModel,
totalCount: Int,
currentRecordSort: RecordSort,
onReadingRecordClick: () -> Unit,
modifier: Modifier = Modifier,
Expand All @@ -40,7 +39,7 @@ internal fun ReadingRecordsHeader(
)
Spacer(modifier = Modifier.width(ReedTheme.spacing.spacing1))
Text(
text = "${pageInfo.totalElements}",
text = "$totalCount",
color = ReedTheme.colors.contentBrand,
style = ReedTheme.typography.headline2SemiBold,
)
Expand Down
Loading