From 0446a0ce49097e87ec92ba34c6a2acdfda6afdfb Mon Sep 17 00:00:00 2001 From: Aleksandar Ilic Date: Mon, 11 Mar 2024 16:34:36 +0100 Subject: [PATCH] Fix detekt issues in ZapBottomSheet --- app/detekt-baseline.xml | 10 +- .../core/compose/feed/zaps/ZapBottomSheet.kt | 108 ++++++++++-------- 2 files changed, 66 insertions(+), 52 deletions(-) diff --git a/app/detekt-baseline.xml b/app/detekt-baseline.xml index c9e279dc..7cf295e8 100644 --- a/app/detekt-baseline.xml +++ b/app/detekt-baseline.xml @@ -7,7 +7,6 @@ CyclomaticComplexMethod:CreateTransactionScreen.kt$@ExperimentalComposeUiApi @ExperimentalMaterial3Api @Composable fun CreateTransactionScreen( state: CreateTransactionContract.UiState, eventPublisher: (CreateTransactionContract.UiEvent) -> Unit, onClose: () -> Unit, ) CyclomaticComplexMethod:FeedLazyColumn.kt$@ExperimentalMaterial3Api @ExperimentalFoundationApi @Composable fun FeedLazyColumn( pagingItems: LazyPagingItems<FeedPostUi>, contentPadding: PaddingValues, listState: LazyListState, zappingState: ZappingState, onPostClick: (String) -> Unit, onProfileClick: (String) -> Unit, onPostLikeClick: (FeedPostUi) -> Unit, onRepostClick: (FeedPostUi) -> Unit, onZapClick: (FeedPostUi, ULong?, String?) -> Unit, onPostReplyClick: (String) -> Unit, onPostQuoteClick: (FeedPostUi) -> Unit, onHashtagClick: (String) -> Unit, onMediaClick: (String, String) -> Unit, onGoToWallet: () -> Unit, onMuteClick: ((String) -> Unit)? = null, shouldShowLoadingState: Boolean = true, shouldShowNoContentState: Boolean = true, showReplyTo: Boolean = true, header: @Composable (LazyItemScope.() -> Unit)? = null, stickyHeader: @Composable (LazyItemScope.() -> Unit)? = null, ) CyclomaticComplexMethod:FeedRemoteMediator.kt$FeedRemoteMediator$override suspend fun load(loadType: LoadType, state: PagingState<Int, FeedPost>): MediatorResult - CyclomaticComplexMethod:LoginScreen.kt$@OptIn(ExperimentalComposeUiApi::class) @Composable fun LoginContent( state: LoginContract.UiState, paddingValues: PaddingValues, onLogin: (String) -> Unit, ) CyclomaticComplexMethod:MessagesRemoteMediator.kt$MessagesRemoteMediator$override suspend fun load(loadType: LoadType, state: PagingState<Int, DirectMessage>): MediatorResult CyclomaticComplexMethod:NoteEditorScreen.kt$@OptIn(ExperimentalMaterial3Api::class) @Composable fun NoteEditorScreen( state: NoteEditorContract.UiState, onClose: () -> Unit, eventPublisher: (UiEvent) -> Unit, ) CyclomaticComplexMethod:NotificationEvents.kt$private fun ContentPrimalNotification.parseActionPostId(type: NotificationType): String? @@ -41,7 +40,6 @@ LongMethod:FeedScreen.kt$@OptIn(ExperimentalMaterial3Api::class) @Composable fun FeedScreen( state: FeedContract.UiState, eventPublisher: (FeedContract.UiEvent) -> Unit, onFeedsClick: () -> Unit, onNewPostClick: (String?) -> Unit, onPostClick: (String) -> Unit, onPostReplyClick: (String) -> Unit, onProfileClick: (String) -> Unit, onHashtagClick: (String) -> Unit, onMediaClick: (String, String) -> Unit, onGoToWallet: () -> Unit, onPrimaryDestinationChanged: (PrimalTopLevelDestination) -> Unit, onDrawerDestinationClick: (DrawerScreenDestination) -> Unit, ) LongMethod:FeedsSettingsScreen.kt$@OptIn(ExperimentalMaterial3Api::class) @Composable fun FeedsSettingsScreen( state: FeedsSettingsContract.UiState, eventPublisher: (FeedsSettingsContract.UiEvent) -> Unit, onClose: () -> Unit, ) LongMethod:FollowRecommendedAccountsStep.kt$@OptIn(ExperimentalFoundationApi::class) @Composable fun FollowRecommendedAccountsStep( state: CreateAccountContract.UiState, eventPublisher: (CreateAccountContract.UiEvent) -> Unit, ) - LongMethod:LoginScreen.kt$@OptIn(ExperimentalComposeUiApi::class) @Composable fun LoginContent( state: LoginContract.UiState, paddingValues: PaddingValues, onLogin: (String) -> Unit, ) LongMethod:MessageConversationListScreen.kt$@Composable private fun MessagesTabs( relation: ConversationRelation, onFollowsTabClick: () -> Unit, onOtherTabClick: () -> Unit, onMarkAllRead: () -> Unit, ) LongMethod:NoteDropdownMenu.kt$@Composable fun NoteDropdownMenuIcon( modifier: Modifier, noteId: String, noteContent: String, noteRawData: String, authorId: String, onMuteUserClick: () -> Unit, ) LongMethod:NoteEditorScreen.kt$@OptIn(ExperimentalMaterial3Api::class) @Composable fun NoteEditorScreen( state: NoteEditorContract.UiState, onClose: () -> Unit, eventPublisher: (UiEvent) -> Unit, ) @@ -64,12 +62,12 @@ LongMethod:ThreadScreen.kt$@OptIn(ExperimentalMaterial3Api::class) @Composable fun ThreadScreen( state: ThreadContract.UiState, onClose: () -> Unit, onPostClick: (String) -> Unit, onPostReplyClick: (String) -> Unit, onPostQuoteClick: (String) -> Unit, onProfileClick: (String) -> Unit, onHashtagClick: (String) -> Unit, onMediaClick: (String, String) -> Unit, onGoToWallet: () -> Unit, onReplyInNoteEditor: (String, Uri?, String) -> Unit, eventPublisher: (ThreadContract.UiEvent) -> Unit, ) LongMethod:TransactionEditor.kt$@Composable private fun TransactionHeaderColumn( modifier: Modifier, uiMode: UiDensityMode, state: CreateTransactionContract.UiState, keyboardVisible: Boolean, onAmountClick: () -> Unit, ) LongMethod:TransactionEditor.kt$@ExperimentalMaterial3Api @ExperimentalComposeUiApi @Composable fun TransactionEditor( modifier: Modifier, state: CreateTransactionContract.UiState, paddingValues: PaddingValues, eventPublisher: (CreateTransactionContract.UiEvent) -> Unit, onCancelClick: () -> Unit, ) - LongMethod:WalletActivationScreen.kt$@ExperimentalComposeUiApi @Composable private fun WalletCodeActivationInput( working: Boolean, error: Throwable?, email: String, onCodeChanged: () -> Unit, onCodeConfirmation: (String) -> Unit, isKeyboardVisible: Boolean, ) - LongMethod:WalletActivationScreen.kt$@Suppress("MagicNumber") @OptIn(ExperimentalMaterial3Api::class) @ExperimentalComposeUiApi @Composable private fun WalletActivationDataInput( data: WalletActivationData, working: Boolean, error: Throwable?, onErrorDismiss: () -> Unit, onDataChanged: (WalletActivationData) -> Unit, onActivationCodeRequest: (WalletActivationData) -> Unit, ) + LongMethod:WalletActivationScreen.kt$@ExperimentalComposeUiApi @Composable private fun WalletCodeActivationInput( modifier: Modifier = Modifier, working: Boolean, error: Throwable?, email: String, onCodeChanged: () -> Unit, onCodeConfirmation: (String) -> Unit, isKeyboardVisible: Boolean, ) + LongMethod:WalletActivationScreen.kt$@ExperimentalMaterial3Api @ExperimentalComposeUiApi @Composable fun WalletActivationScreen( uiState: WalletActivationContract.UiState, eventPublisher: (UiEvent) -> Unit, onClose: () -> Unit, ) + LongMethod:WalletActivationScreen.kt$@Suppress("MagicNumber") @OptIn(ExperimentalMaterial3Api::class) @ExperimentalComposeUiApi @Composable private fun WalletActivationDataInput( modifier: Modifier = Modifier, data: WalletActivationData, working: Boolean, error: Throwable?, onErrorDismiss: () -> Unit, onDataChanged: (WalletActivationData) -> Unit, onActivationCodeRequest: (WalletActivationData) -> Unit, ) LongMethod:WalletDashboardScreen.kt$@OptIn(ExperimentalMaterial3Api::class, ExperimentalFoundationApi::class) @Composable fun WalletDashboardScreen( state: WalletDashboardContract.UiState, onPrimaryDestinationChanged: (PrimalTopLevelDestination) -> Unit, onDrawerDestinationClick: (DrawerScreenDestination) -> Unit, onWalletActivateClick: () -> Unit, onProfileClick: (String) -> Unit, onTransactionClick: (String) -> Unit, onSendClick: () -> Unit, onScanClick: () -> Unit, onReceiveClick: () -> Unit, eventPublisher: (UiEvent) -> Unit, ) LongMethod:WalletSettingsScreen.kt$@OptIn(ExperimentalMaterial3Api::class) @Composable fun WalletSettingsScreen( state: WalletSettingsContract.UiState, onClose: () -> Unit, onEditProfileClick: () -> Unit, eventPublisher: (UiEvent) -> Unit, ) LongMethod:WelcomeScreen.kt$@Composable fun WelcomeScreen(onSignInClick: () -> Unit, onCreateAccountClick: () -> Unit) - LongMethod:ZapBottomSheet.kt$@OptIn(ExperimentalMaterial3Api::class, ExperimentalComposeUiApi::class) @Composable fun ZapBottomSheet( receiverName: String, zappingState: ZappingState, onDismissRequest: () -> Unit, onZap: (Long, String?) -> Unit, ) LongMethod:ZapSettingsScreen.kt$@OptIn(ExperimentalMaterial3Api::class) @Composable fun ZapSettingsScreen( uiState: ZapSettingsContract.UiState, onClose: () -> Unit, eventPublisher: (ZapSettingsContract.UiEvent) -> Unit, ) LongParameterList:CreateAccountViewModel.kt$CreateAccountViewModel$( private val dispatcherProvider: CoroutineDispatcherProvider, private val authRepository: AuthRepository, private val settingsRepository: SettingsRepository, private val profileRepository: ProfileRepository, private val userRepository: UserRepository, private val recommendedFollowsApi: RecommendedFollowsApi, private val relayRepository: RelayRepository, ) LongParameterList:ExploreFeedViewModel.kt$ExploreFeedViewModel$( savedStateHandle: SavedStateHandle, private val dispatcherProvider: CoroutineDispatcherProvider, private val activeAccountStore: ActiveAccountStore, private val feedRepository: FeedRepository, private val postRepository: PostRepository, private val profileRepository: ProfileRepository, private val zapHandler: ZapHandler, private val settingsRepository: SettingsRepository, private val mutedUserRepository: MutedUserRepository, ) @@ -100,7 +98,6 @@ MagicNumber:FeedNoteList.kt$30 MagicNumber:FeedNoteList.kt$5 MagicNumber:FeedViewModel.kt$FeedViewModel$3 - MagicNumber:Insets.kt$0.5f MagicNumber:IntUtils.kt$10 MagicNumber:IntUtils.kt$1000 MagicNumber:IntUtils.kt$1000.0 @@ -131,7 +128,6 @@ MagicNumber:Timestamps.kt$7 MagicNumber:ValidationUtils.kt$32 MagicNumber:WalletDashboardScreen.kt$0.42f - MagicNumber:ZapBottomSheet.kt$3 MatchingDeclarationName:__PrimalIcons.kt$PrimalIcons NestedBlockDepth:FeedRemoteMediator.kt$FeedRemoteMediator$override suspend fun load(loadType: LoadType, state: PagingState<Int, FeedPost>): MediatorResult ReturnCount:FeedRemoteMediator.kt$FeedRemoteMediator$override suspend fun load(loadType: LoadType, state: PagingState<Int, FeedPost>): MediatorResult diff --git a/app/src/main/kotlin/net/primal/android/core/compose/feed/zaps/ZapBottomSheet.kt b/app/src/main/kotlin/net/primal/android/core/compose/feed/zaps/ZapBottomSheet.kt index a0c58345..54a08f15 100644 --- a/app/src/main/kotlin/net/primal/android/core/compose/feed/zaps/ZapBottomSheet.kt +++ b/app/src/main/kotlin/net/primal/android/core/compose/feed/zaps/ZapBottomSheet.kt @@ -107,16 +107,7 @@ fun ZapBottomSheet( }?.message ?: selectedZapComment }, ) - OutlinedTextField( - modifier = Modifier - .fillMaxWidth() - .padding(horizontal = 24.dp), - singleLine = true, - colors = PrimalDefaults.outlinedTextFieldColors( - unfocusedBorderColor = Color.Transparent, - focusedBorderColor = Color.Transparent, - ), - shape = RoundedCornerShape(8.dp), + ZapCustomAmountOutlinedTextField( value = customZapAmount, onValueChange = { when { @@ -125,44 +116,11 @@ fun ZapBottomSheet( } selectedZapAmount = customZapAmount.toLongOrNull() ?: zapConfig.first().amount }, - textStyle = AppTheme.typography.bodyMedium, - keyboardOptions = KeyboardOptions( - keyboardType = KeyboardType.Number, - imeAction = ImeAction.Done, - ), - placeholder = { - Text( - modifier = Modifier.fillMaxWidth(), - text = stringResource(id = R.string.zap_bottom_sheet_custom_amount_placeholder), - textAlign = TextAlign.Left, - style = AppTheme.typography.bodyMedium, - color = AppTheme.extraColorScheme.onSurfaceVariantAlt4, - ) - }, ) Spacer(modifier = Modifier.height(16.dp)) - OutlinedTextField( - modifier = Modifier - .fillMaxWidth() - .padding(horizontal = 24.dp), - singleLine = true, - colors = PrimalDefaults.outlinedTextFieldColors( - unfocusedBorderColor = Color.Transparent, - focusedBorderColor = Color.Transparent, - ), - shape = RoundedCornerShape(8.dp), + ZapCommentOutlinedTextField( value = selectedZapComment, onValueChange = { selectedZapComment = it }, - textStyle = AppTheme.typography.bodyMedium, - placeholder = { - Text( - modifier = Modifier.fillMaxWidth(), - text = stringResource(id = R.string.zap_bottom_sheet_comment_placeholder), - textAlign = TextAlign.Left, - style = AppTheme.typography.bodyMedium, - color = AppTheme.extraColorScheme.onSurfaceVariantAlt4, - ) - }, ) Spacer(modifier = Modifier.height(16.dp)) if (!keyboardVisible) { @@ -183,6 +141,66 @@ fun ZapBottomSheet( } } +@Composable +private fun ZapCommentOutlinedTextField(value: String, onValueChange: (String) -> Unit) { + OutlinedTextField( + modifier = Modifier + .fillMaxWidth() + .padding(horizontal = 24.dp), + singleLine = true, + colors = PrimalDefaults.outlinedTextFieldColors( + unfocusedBorderColor = Color.Transparent, + focusedBorderColor = Color.Transparent, + ), + shape = RoundedCornerShape(8.dp), + value = value, + onValueChange = onValueChange, + textStyle = AppTheme.typography.bodyMedium, + placeholder = { + Text( + modifier = Modifier.fillMaxWidth(), + text = stringResource(id = R.string.zap_bottom_sheet_comment_placeholder), + textAlign = TextAlign.Left, + style = AppTheme.typography.bodyMedium, + color = AppTheme.extraColorScheme.onSurfaceVariantAlt4, + ) + }, + ) +} + +@Composable +private fun ZapCustomAmountOutlinedTextField(value: String, onValueChange: (String) -> Unit) { + OutlinedTextField( + modifier = Modifier + .fillMaxWidth() + .padding(horizontal = 24.dp), + singleLine = true, + colors = PrimalDefaults.outlinedTextFieldColors( + unfocusedBorderColor = Color.Transparent, + focusedBorderColor = Color.Transparent, + ), + shape = RoundedCornerShape(8.dp), + value = value, + onValueChange = onValueChange, + textStyle = AppTheme.typography.bodyMedium, + keyboardOptions = KeyboardOptions( + keyboardType = KeyboardType.Number, + imeAction = ImeAction.Done, + ), + placeholder = { + Text( + modifier = Modifier.fillMaxWidth(), + text = stringResource(id = R.string.zap_bottom_sheet_custom_amount_placeholder), + textAlign = TextAlign.Left, + style = AppTheme.typography.bodyMedium, + color = AppTheme.extraColorScheme.onSurfaceVariantAlt4, + ) + }, + ) +} + +private const val ZAP_OPTIONS_COLUMNS_COUNT = 3 + @Composable private fun ZapOptions( zapConfig: List, @@ -190,7 +208,7 @@ private fun ZapOptions( onSelectedZapAmountChange: (Long) -> Unit, ) { LazyVerticalGrid( - columns = GridCells.Fixed(3), + columns = GridCells.Fixed(ZAP_OPTIONS_COLUMNS_COUNT), contentPadding = PaddingValues(12.dp), ) { items(zapConfig) {