From f6496e485d3d4c7e0a75215e04fa782142846fe5 Mon Sep 17 00:00:00 2001 From: Thomas Andres Gomez Date: Thu, 6 Apr 2023 10:35:10 +0200 Subject: [PATCH] Small refactor and add FireBase Crashlitycs. --- app/build.gradle | 8 ++- app/src/google-services.json | 68 +++++++++++++++++++ .../home/common/item/LargeBookThumbnail.kt | 38 +++++------ .../home/common/item/SmallBookThumbnail.kt | 11 +-- .../home/detail/DetailScreenSendOption.kt | 47 ++++++++----- .../biblib/utils/extention/ContextEx.kt | 27 -------- .../pixelized/biblib/utils/extention/IntEx.kt | 2 +- .../utils/extention/LazyPagingItemsEx.kt | 14 ---- build.gradle | 4 +- 9 files changed, 131 insertions(+), 88 deletions(-) create mode 100644 app/src/google-services.json delete mode 100644 app/src/main/java/com/pixelized/biblib/utils/extention/ContextEx.kt delete mode 100644 app/src/main/java/com/pixelized/biblib/utils/extention/LazyPagingItemsEx.kt diff --git a/app/build.gradle b/app/build.gradle index a67d90b..fbd1f08 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -2,6 +2,8 @@ plugins { id 'com.android.application' id 'kotlin-android' id 'kotlin-kapt' + id 'com.google.gms.google-services' + id 'com.google.firebase.crashlytics' id 'dagger.hilt.android.plugin' id 'org.jetbrains.kotlin.android' } @@ -130,7 +132,7 @@ dependencies { implementation "com.github.skydoves:landscapist-glide:1.5.2" kapt 'com.github.bumptech.glide:compiler:4.13.2' // this have to be align with landscapist-glide - // Reorder element in laylist + // Reorder element in lazylist implementation "org.burnoutcrew.composereorderable:reorderable:0.9.6" // Navigation @@ -142,6 +144,10 @@ dependencies { // Google sign in. implementation "com.google.android.gms:play-services-auth:20.4.1" + // Firebase + implementation platform('com.google.firebase:firebase-bom:31.3.0') + implementation 'com.google.firebase:firebase-crashlytics' + // RetroFit & Gson for webservice call implementation 'com.squareup.retrofit2:retrofit:2.9.0' implementation 'com.squareup.retrofit2:converter-gson:2.9.0' diff --git a/app/src/google-services.json b/app/src/google-services.json new file mode 100644 index 0000000..326f9b5 --- /dev/null +++ b/app/src/google-services.json @@ -0,0 +1,68 @@ +{ + "project_info": { + "project_number": "837508873287", + "project_id": "biblib-2b8e6", + "storage_bucket": "biblib-2b8e6.appspot.com" + }, + "client": [ + { + "client_info": { + "mobilesdk_app_id": "1:837508873287:android:52368b2f6ecf2304c90562", + "android_client_info": { + "package_name": "com.pixelized.biblib" + } + }, + "oauth_client": [ + { + "client_id": "837508873287-kar6b3a5phks9n5f4ieoib48cfb3r437.apps.googleusercontent.com", + "client_type": 3 + } + ], + "api_key": [ + { + "current_key": "AIzaSyAU-JemDic4WFaIq6nTp48uf_P1-pxgARo" + } + ], + "services": { + "appinvite_service": { + "other_platform_oauth_client": [ + { + "client_id": "837508873287-kar6b3a5phks9n5f4ieoib48cfb3r437.apps.googleusercontent.com", + "client_type": 3 + } + ] + } + } + }, + { + "client_info": { + "mobilesdk_app_id": "1:837508873287:android:200c71bdf4129685c90562", + "android_client_info": { + "package_name": "com.pixelized.biblib.debug" + } + }, + "oauth_client": [ + { + "client_id": "837508873287-kar6b3a5phks9n5f4ieoib48cfb3r437.apps.googleusercontent.com", + "client_type": 3 + } + ], + "api_key": [ + { + "current_key": "AIzaSyAU-JemDic4WFaIq6nTp48uf_P1-pxgARo" + } + ], + "services": { + "appinvite_service": { + "other_platform_oauth_client": [ + { + "client_id": "837508873287-kar6b3a5phks9n5f4ieoib48cfb3r437.apps.googleusercontent.com", + "client_type": 3 + } + ] + } + } + } + ], + "configuration_version": "1" +} \ No newline at end of file diff --git a/app/src/main/java/com/pixelized/biblib/ui/screen/home/common/item/LargeBookThumbnail.kt b/app/src/main/java/com/pixelized/biblib/ui/screen/home/common/item/LargeBookThumbnail.kt index 45a7e45..507cdd8 100644 --- a/app/src/main/java/com/pixelized/biblib/ui/screen/home/common/item/LargeBookThumbnail.kt +++ b/app/src/main/java/com/pixelized/biblib/ui/screen/home/common/item/LargeBookThumbnail.kt @@ -2,7 +2,6 @@ package com.pixelized.biblib.ui.screen.home.common.item import android.annotation.SuppressLint import android.content.res.Configuration -import androidx.compose.foundation.background import androidx.compose.foundation.clickable import androidx.compose.foundation.layout.* import androidx.compose.material.Card @@ -16,11 +15,12 @@ import androidx.compose.ui.graphics.Color import androidx.compose.ui.res.stringResource import androidx.compose.ui.text.TextStyle import androidx.compose.ui.tooling.preview.Preview +import androidx.compose.ui.tooling.preview.PreviewParameter +import androidx.compose.ui.tooling.preview.PreviewParameterProvider import androidx.compose.ui.unit.dp import com.pixelized.biblib.R import com.pixelized.biblib.ui.theme.BibLibTheme import com.pixelized.biblib.utils.extention.bibLib -import com.pixelized.biblib.utils.extention.default import com.pixelized.biblib.utils.extention.modifier.drawDiagonalLabel import com.pixelized.biblib.utils.extention.placeholder import com.skydoves.landscapist.glide.GlideImage @@ -36,7 +36,7 @@ data class LargeBookThumbnailUio( fun LargeBookThumbnail( modifier: Modifier = Modifier, thumbnail: LargeBookThumbnailUio?, - onClick: (LargeBookThumbnailUio) -> Unit = default(), + onClick: (LargeBookThumbnailUio) -> Unit, ) { Card( modifier = modifier @@ -62,7 +62,7 @@ fun LargeBookThumbnail( private fun LargeBookThumbnailContent( modifier: Modifier = Modifier, thumbnail: LargeBookThumbnailUio, - onClick: (LargeBookThumbnailUio) -> Unit = default(), + onClick: (LargeBookThumbnailUio) -> Unit, ) { GlideImage( modifier = Modifier @@ -115,27 +115,25 @@ private fun Modifier.isNew( @Composable @Preview(showBackground = true, uiMode = Configuration.UI_MODE_NIGHT_NO) @Preview(showBackground = true, uiMode = Configuration.UI_MODE_NIGHT_YES) -private fun LargeBookThumbnailPreview() { +private fun LargeBookThumbnailPreview( + @PreviewParameter(LargeBookThumbnailPreviewProvider::class) preview: LargeBookThumbnailUio?, +) { BibLibTheme { LargeBookThumbnail( modifier = Modifier.width(168.dp), - thumbnail = LargeBookThumbnailUio( - id = 0, - isNew = true, - cover = "", - ), + thumbnail = preview, + onClick = { }, ) } } -@Composable -@Preview(showBackground = true, uiMode = Configuration.UI_MODE_NIGHT_NO) -@Preview(showBackground = true, uiMode = Configuration.UI_MODE_NIGHT_YES) -private fun LargeBookThumbnailEmptyPreview() { - BibLibTheme { - LargeBookThumbnail( - modifier = Modifier.width(168.dp), - thumbnail = null, - ) - } +private class LargeBookThumbnailPreviewProvider : PreviewParameterProvider { + override val values: Sequence = sequenceOf( + LargeBookThumbnailUio( + id = 0, + isNew = true, + cover = "", + ), + null + ) } \ No newline at end of file diff --git a/app/src/main/java/com/pixelized/biblib/ui/screen/home/common/item/SmallBookThumbnail.kt b/app/src/main/java/com/pixelized/biblib/ui/screen/home/common/item/SmallBookThumbnail.kt index f03e692..2fe4d60 100644 --- a/app/src/main/java/com/pixelized/biblib/ui/screen/home/common/item/SmallBookThumbnail.kt +++ b/app/src/main/java/com/pixelized/biblib/ui/screen/home/common/item/SmallBookThumbnail.kt @@ -23,7 +23,6 @@ import androidx.constraintlayout.compose.Dimension import com.pixelized.biblib.R import com.pixelized.biblib.ui.theme.BibLibTheme import com.pixelized.biblib.utils.extention.bibLib -import com.pixelized.biblib.utils.extention.default import com.pixelized.biblib.utils.extention.modifier.drawDiagonalLabel import com.pixelized.biblib.utils.extention.placeholder import com.skydoves.landscapist.glide.GlideImage @@ -43,7 +42,7 @@ data class SmallBookThumbnailUio( fun SmallBookThumbnail( modifier: Modifier = Modifier, thumbnail: SmallBookThumbnailUio?, - onClick: (SmallBookThumbnailUio) -> Unit = default(), + onClick: (SmallBookThumbnailUio) -> Unit, ) { if (thumbnail != null) { SmallBookThumbnailContent( @@ -62,7 +61,7 @@ fun SmallBookThumbnail( private fun SmallBookThumbnailContent( modifier: Modifier = Modifier, thumbnail: SmallBookThumbnailUio, - onClick: (SmallBookThumbnailUio) -> Unit = default(), + onClick: (SmallBookThumbnailUio) -> Unit, ) { Card( modifier = modifier @@ -248,13 +247,14 @@ private fun SmallBookThumbnailPreview() { SmallBookThumbnail( thumbnail = SmallBookThumbnailUio( id = 0, - genre = "Sci-Fi", title = "Foundation", + genre = "Sci-Fi", author = "Asimov", date = "1951", isNew = true, cover = "", - ) + ), + onClick = { }, ) } } @@ -266,6 +266,7 @@ private fun SmallBookThumbnailEmptyPreview() { BibLibTheme { SmallBookThumbnail( thumbnail = null, + onClick = { }, ) } } \ No newline at end of file diff --git a/app/src/main/java/com/pixelized/biblib/ui/screen/home/detail/DetailScreenSendOption.kt b/app/src/main/java/com/pixelized/biblib/ui/screen/home/detail/DetailScreenSendOption.kt index b7f3269..4d81c39 100644 --- a/app/src/main/java/com/pixelized/biblib/ui/screen/home/detail/DetailScreenSendOption.kt +++ b/app/src/main/java/com/pixelized/biblib/ui/screen/home/detail/DetailScreenSendOption.kt @@ -13,10 +13,7 @@ import androidx.compose.material.Button import androidx.compose.material.MaterialTheme import androidx.compose.material.RadioButton import androidx.compose.material.Text -import androidx.compose.runtime.Composable -import androidx.compose.runtime.Immutable -import androidx.compose.runtime.LaunchedEffect -import androidx.compose.runtime.Stable +import androidx.compose.runtime.* import androidx.compose.ui.Alignment import androidx.compose.ui.Modifier import androidx.compose.ui.res.stringResource @@ -52,8 +49,8 @@ fun DetailScreenSendOption( modifier: Modifier = Modifier, optionViewModel: BookOptionViewModel = hiltViewModel(), emails: List, - onHelp: (url: String) -> Unit = default(), - onSend: (email: String, format: String) -> Unit = { _, _ -> }, + onHelp: (url: String) -> Unit, + onSend: (email: String, format: String) -> Unit, ) { LaunchedEffect(key1 = emails) { optionViewModel.updateEmails(amazonEmails = emails) @@ -74,10 +71,10 @@ fun DetailScreenSendOption( modifier: Modifier = Modifier, emails: List, formats: List, - onHelp: (url: String) -> Unit = default(), - onEmail: (OptionUio) -> Unit = { }, - onFormat: (OptionUio) -> Unit = { }, - onSend: (email: String, format: String) -> Unit = { _, _ -> }, + onHelp: (url: String) -> Unit, + onEmail: (OptionUio) -> Unit, + onFormat: (OptionUio) -> Unit, + onSend: (email: String, format: String) -> Unit, ) { val amazonHelpUri = stringResource(R.string.detail_send_confirm_help_url) @@ -221,15 +218,29 @@ private fun rememberDescription( @Preview(showBackground = true, uiMode = Configuration.UI_MODE_NIGHT_YES) private fun DetailScreenEmailListPreview() { BibLibTheme { + val emails by remember { + mutableStateOf( + listOf( + OptionUio("R.Giskard.Reventlov.Kindle@gmail.com", selected = true), + OptionUio("R.Daneel.Olivaw.Kindle@gmail.com"), + ) + ) + } + val formats by remember { + mutableStateOf( + listOf( + OptionUio(Format.EPUB.capitalize(), selected = true), + OptionUio(Format.MOBI.capitalize()), + ) + ) + } DetailScreenSendOption( - emails = listOf( - OptionUio("R.Giskard.Reventlov.Kindle@gmail.com", selected = true), - OptionUio("R.Daneel.Olivaw.Kindle@gmail.com"), - ), - formats = listOf( - OptionUio(Format.EPUB.capitalize(), selected = true), - OptionUio(Format.MOBI.capitalize()), - ), + emails = emails, + formats = formats, + onHelp = { }, + onEmail = { }, + onFormat = { }, + onSend = { _, _ -> }, ) } } \ No newline at end of file diff --git a/app/src/main/java/com/pixelized/biblib/utils/extention/ContextEx.kt b/app/src/main/java/com/pixelized/biblib/utils/extention/ContextEx.kt deleted file mode 100644 index c6de2a6..0000000 --- a/app/src/main/java/com/pixelized/biblib/utils/extention/ContextEx.kt +++ /dev/null @@ -1,27 +0,0 @@ -package com.pixelized.biblib.utils.extention - -import android.content.Context -import android.widget.Toast -import androidx.compose.runtime.Composable -import androidx.compose.ui.platform.LocalContext - -fun Context.showToast(message: String, duration: Int = Toast.LENGTH_SHORT) = - Toast.makeText(this, message, duration).show() - -fun Context.notImplemented() { - showToast("Not implemented yet") -} - -@Deprecated("") -@Composable -fun default(): () -> Unit { - val context = LocalContext.current - return { context.notImplemented() } -} - -@Deprecated("") -@Composable -fun default(): (T) -> Unit { - val context = LocalContext.current - return { context.notImplemented() } -} \ No newline at end of file diff --git a/app/src/main/java/com/pixelized/biblib/utils/extention/IntEx.kt b/app/src/main/java/com/pixelized/biblib/utils/extention/IntEx.kt index 6af1595..35b9638 100644 --- a/app/src/main/java/com/pixelized/biblib/utils/extention/IntEx.kt +++ b/app/src/main/java/com/pixelized/biblib/utils/extention/IntEx.kt @@ -2,4 +2,4 @@ package com.pixelized.biblib.utils.extention fun Int.toBoolean(): Boolean = this != 0 -fun Int?.toBoolean(): Boolean? = if (this == null) null else this != 0 \ No newline at end of file +fun Int?.toBoolean(): Boolean? = this?.toBoolean() \ No newline at end of file diff --git a/app/src/main/java/com/pixelized/biblib/utils/extention/LazyPagingItemsEx.kt b/app/src/main/java/com/pixelized/biblib/utils/extention/LazyPagingItemsEx.kt deleted file mode 100644 index f996106..0000000 --- a/app/src/main/java/com/pixelized/biblib/utils/extention/LazyPagingItemsEx.kt +++ /dev/null @@ -1,14 +0,0 @@ -package com.pixelized.biblib.utils.extention - -import androidx.compose.runtime.derivedStateOf -import androidx.compose.runtime.getValue -import androidx.paging.LoadState -import androidx.paging.compose.LazyPagingItems - -val LazyPagingItems<*>.isLoading: Boolean - get() { - val isLoading by derivedStateOf { - loadState.refresh is LoadState.Loading || loadState.append is LoadState.Loading - } - return isLoading - } \ No newline at end of file diff --git a/build.gradle b/build.gradle index 4874899..976caea 100644 --- a/build.gradle +++ b/build.gradle @@ -1,15 +1,15 @@ // Top-level build file where you can add configuration options common to all sub-projects/modules. buildscript { - repositories { google() mavenCentral() } - dependencies { classpath 'com.android.tools.build:gradle:7.4.2' classpath 'org.jetbrains.kotlin:kotlin-gradle-plugin:1.8.10' classpath "com.google.dagger:hilt-android-gradle-plugin:2.43.2" + classpath 'com.google.gms:google-services:4.3.15' + classpath 'com.google.firebase:firebase-crashlytics-gradle:2.9.4' } }