This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
data class Volume(val id: String, val volumeInfo: VolumeInfo) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
data class VolumeInfo( | |
val title: String, | |
val authors: List<String>, | |
val imageUrl: String? | |
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
interface BooksRepository { | |
suspend fun getRemoteBooks(author: String): Result<List<Volume>> | |
suspend fun getBookmarks(): Flow<List<Volume>> | |
suspend fun bookmark(book: Volume) | |
suspend fun unbookmark(book: Volume) | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class GetBooksUseCase(private val booksRepository: BooksRepository) { | |
suspend operator fun invoke(author: String) = booksRepository.getRemoteBooks(author) | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class BooksRepositoryImpl( | |
private val localDataSource: BooksLocalDataSource, | |
private val remoteDataSource: BooksRemoteDataSource | |
) : BooksRepository { | |
override suspend fun getRemoteBooks(author: String): Result<List<Volume>> { | |
return remoteDataSource.getBooks(author) | |
} | |
override suspend fun getBookmarks(): Flow<List<Volume>> { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class BookEntityMapper { | |
fun toBookEntity(volume: Volume): BookEntity { | |
return BookEntity( | |
id = volume.id, | |
title = volume.volumeInfo.title, | |
authors = volume.volumeInfo.authors, | |
imageUrl = volume.volumeInfo.imageUrl | |
) | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@Entity(tableName = "book") | |
data class BookEntity( | |
@PrimaryKey | |
val id: String, | |
val title: String, | |
val authors: List<String>, | |
val imageUrl: String? | |
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class BooksViewModel( | |
private val getBooksUseCase: GetBooksUseCase, | |
private val getBookmarksUseCase: GetBookmarksUseCase, | |
private val bookmarkBookUseCase: BookmarkBookUseCase, | |
private val unbookmarkBookUseCase: UnbookmarkBookUseCase, | |
private val mapper: BookWithStatusMapper | |
) : ViewModel() { | |
private val _dataLoading = MutableLiveData(true) | |
val dataLoading: LiveData<Boolean> = _dataLoading |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
override fun onCreate(savedInstanceState: Bundle?) { | |
super.onCreate(savedInstanceState) | |
booksAdapter = BookAdapter(requireContext(), object : BookAdapter.ActionClickListener { | |
override fun bookmark(book: BookWithStatus) { | |
booksViewModel.bookmark(book) | |
} | |
override fun unbookmark(book: BookWithStatus) { | |
booksViewModel.unbookmark(book) | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
private fun printInvoiceSheet(invoice: Invoice) { | |
printInvoiceHeader(invoice) | |
val fullName = getFullName(invoice) | |
binding.tvInvoicePreview.append(fullName) | |
val address = getAddress(invoice) | |
binding.tvInvoicePreview.append(address) | |
} | |
private fun getFullName(invoice: Invoice): String { | |
val fullName = |
OlderNewer