Skip to content

Commit

Permalink
Refactor- [:feature:help] Apply & Fix Detekt, Ktlint Rules (#2681)
Browse files Browse the repository at this point in the history
  • Loading branch information
niyajali authored Aug 31, 2024
1 parent 6c1d871 commit c704433
Show file tree
Hide file tree
Showing 11 changed files with 126 additions and 116 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,16 +20,22 @@ import androidx.compose.material.icons.filled.FilterList
import androidx.compose.material.icons.filled.FlashOff
import androidx.compose.material.icons.filled.FlashOn
import androidx.compose.material.icons.filled.Info
import androidx.compose.material.icons.filled.LocationOn
import androidx.compose.material.icons.filled.Menu
import androidx.compose.material.icons.filled.MoreVert
import androidx.compose.material.icons.filled.Notifications
import androidx.compose.material.icons.filled.Phone
import androidx.compose.material.icons.filled.Search
import androidx.compose.material.icons.filled.Visibility
import androidx.compose.material.icons.filled.VisibilityOff
import androidx.compose.material.icons.filled.WifiOff
import androidx.compose.material.icons.outlined.Mail
import androidx.compose.ui.graphics.vector.ImageVector

object MifosIcons {
val Mail: ImageVector = Icons.Outlined.Mail
val LocationOn: ImageVector = Icons.Filled.LocationOn
val Phone: ImageVector= Icons.Default.Phone
val MoreVert: ImageVector = Icons.Filled.MoreVert
val VisibilityOff: ImageVector = Icons.Filled.VisibilityOff
val Visibility: ImageVector = Icons.Filled.Visibility
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,9 @@ import org.mifos.mobile.core.ui.component.MifosErrorComponent
import org.mifos.mobile.core.ui.component.MifosProgressIndicator
import org.mifos.mobile.core.ui.component.MifosTextTitleDescSingleLine
import org.mifos.mobile.core.ui.utils.DevicePreviews
import org.mifos.mobile.feature.charge.R
import org.mifos.mobile.feature.charge.utils.ClientChargeState
import org.mifos.mobile.feature.charge.viewmodel.ClientChargeViewModel
import org.mifos.mobile.feature.client_charge.R

@Composable
internal fun ClientChargeScreen(
Expand Down
20 changes: 10 additions & 10 deletions feature/help/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,3 +1,12 @@
/*
* Copyright 2024 Mifos Initiative
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at https://mozilla.org/MPL/2.0/.
*
* See https://github.com/openMF/mobile-mobile/blob/master/LICENSE.md
*/
plugins {
alias(libs.plugins.mifos.android.feature)
alias(libs.plugins.mifos.android.library.compose)
Expand All @@ -7,13 +16,4 @@ android {
namespace = "org.mifos.mobile.feature.help"
}

dependencies {
implementation(projects.core.ui)
implementation(projects.core.common)
implementation(projects.core.model)
implementation(projects.core.data)

testImplementation(libs.junit)
androidTestImplementation(libs.androidx.test.ext.junit)
androidTestImplementation(libs.espresso.core)
}
dependencies { }

This file was deleted.

9 changes: 9 additions & 0 deletions feature/help/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -1,4 +1,13 @@
<?xml version="1.0" encoding="utf-8"?>
<!--
Copyright 2024 Mifos Initiative
This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0.
If a copy of the MPL was not distributed with this file,
You can obtain one at https://mozilla.org/MPL/2.0/.
See https://github.com/openMF/mobile-mobile/blob/master/LICENSE.md
-->
<manifest xmlns:android="http://schemas.android.com/apk/res/android">

</manifest>
106 changes: 57 additions & 49 deletions feature/help/src/main/java/org/mifos/mobile/feature/help/HelpScreen.kt
Original file line number Diff line number Diff line change
@@ -1,3 +1,12 @@
/*
* Copyright 2024 Mifos Initiative
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at https://mozilla.org/MPL/2.0/.
*
* See https://github.com/openMF/mobile-mobile/blob/master/LICENSE.md
*/
package org.mifos.mobile.feature.help

import androidx.compose.foundation.layout.Box
Expand All @@ -8,10 +17,6 @@ import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.lazy.LazyColumn
import androidx.compose.foundation.lazy.itemsIndexed
import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.filled.LocationOn
import androidx.compose.material.icons.filled.Phone
import androidx.compose.material.icons.outlined.Mail
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
Expand All @@ -20,37 +25,38 @@ import androidx.compose.runtime.getValue
import androidx.compose.ui.Modifier
import androidx.compose.ui.platform.LocalContext
import androidx.compose.ui.res.stringResource
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 androidx.hilt.navigation.compose.hiltViewModel
import androidx.lifecycle.compose.collectAsStateWithLifecycle
import org.mifos.mobile.core.designsystem.components.MifosScaffold
import org.mifos.mobile.core.designsystem.components.MifosTopBar
import org.mifos.mobile.core.designsystem.icons.MifosIcons
import org.mifos.mobile.core.designsystem.theme.MifosMobileTheme
import org.mifos.mobile.core.model.entity.FAQ
import org.mifos.mobile.core.ui.component.EmptyDataView
import org.mifos.mobile.core.ui.component.FaqItemHolder
import org.mifos.mobile.core.ui.component.MifosTextButtonWithTopDrawable
import org.mifos.mobile.core.ui.component.MifosTitleSearchCard
import org.mifos.mobile.core.ui.utils.DevicePreviews

@Composable
fun HelpScreen(
viewModel: HelpViewModel = hiltViewModel(),
internal fun HelpScreen(
callNow: () -> Unit,
leaveEmail: () -> Unit,
findLocations: () -> Unit,
navigateBack: () -> Unit,
modifier: Modifier = Modifier,
viewModel: HelpViewModel = hiltViewModel(),
) {

val context = LocalContext.current
val uiState by viewModel.helpUiState.collectAsStateWithLifecycle()

LaunchedEffect(key1 = Unit) {
viewModel.loadFaq(
context.resources?.getStringArray(R.array.faq_qs),
context.resources?.getStringArray(R.array.faq_ans)
context.resources?.getStringArray(R.array.faq_ans),
)
}

Expand All @@ -60,14 +66,15 @@ fun HelpScreen(
leaveEmail = leaveEmail,
findLocations = findLocations,
navigateBack = navigateBack,
searchQuery = { viewModel.filterList(it) },
searchQuery = viewModel::filterList,
modifier = modifier,
onSearchDismiss = { viewModel.loadFaq(qs = null, ans = null) },
updateFaqPosition = { viewModel.updateSelectedFaqPosition(it) }
updateFaqPosition = viewModel::updateSelectedFaqPosition,
)
}

@Composable
fun HelpScreen(
private fun HelpScreen(
uiState: HelpUiState,
callNow: () -> Unit,
leaveEmail: () -> Unit,
Expand All @@ -76,8 +83,8 @@ fun HelpScreen(
searchQuery: (String) -> Unit,
onSearchDismiss: () -> Unit,
updateFaqPosition: (Int) -> Unit,
modifier: Modifier = Modifier,
) {

MifosScaffold(
topBar = {
MifosTopBar(
Expand All @@ -86,14 +93,14 @@ fun HelpScreen(
MifosTitleSearchCard(
searchQuery = searchQuery,
titleResourceId = R.string.help,
onSearchDismiss = onSearchDismiss
onSearchDismiss = onSearchDismiss,
)
}
},
)
},
content = { paddingValues ->
Box(modifier = Modifier.padding(paddingValues)) {
when(uiState) {
when (uiState) {
is HelpUiState.Initial -> Unit
is HelpUiState.ShowFaq -> {
HelpContent(
Expand All @@ -102,120 +109,121 @@ fun HelpScreen(
callNow = callNow,
leaveEmail = leaveEmail,
findLocations = findLocations,
updateFaqPosition = updateFaqPosition
updateFaqPosition = updateFaqPosition,
)
}
}
}
}
},
modifier = modifier,
)

}


@Composable
fun HelpContent(
private fun HelpContent(
faqArrayList: List<FAQ>,
selectedFaqPosition: Int,
callNow: () -> Unit,
leaveEmail: () -> Unit,
findLocations: () -> Unit,
updateFaqPosition: (Int) -> Unit,
modifier: Modifier = Modifier,
) {
Column(
modifier = Modifier
.fillMaxSize()
modifier = modifier
.fillMaxSize(),
) {
Text(
text = stringResource(id = R.string.faq),
modifier = Modifier
.fillMaxWidth()
.padding(start = 16.dp, end = 16.dp, top = 12.dp, bottom = 8.dp),
style = MaterialTheme.typography.titleMedium,
color = MaterialTheme.colorScheme.onSurface
color = MaterialTheme.colorScheme.onSurface,
)

if (!faqArrayList.isNullOrEmpty()) {
if (faqArrayList.isNotEmpty()) {
LazyColumn(
modifier = Modifier
.weight(1f)
.fillMaxWidth()
.fillMaxWidth(),
) {
itemsIndexed(items = faqArrayList) { index, faqItem ->
FaqItemHolder(
index = index,
isSelected = selectedFaqPosition == index,
onItemSelected = { updateFaqPosition(it) },
question = faqItem?.question,
answer = faqItem?.answer
question = faqItem.question,
answer = faqItem.answer,
)
}
}

Row(
modifier = Modifier
.fillMaxWidth()
.padding(vertical = 4.dp)
.padding(vertical = 4.dp),
) {
MifosTextButtonWithTopDrawable(
modifier = Modifier
.weight(1f),
onClick = callNow,
textResourceId = R.string.call_now,
icon = Icons.Default.Phone,
contentDescription = "Phone Icon"
icon = MifosIcons.Phone,
contentDescription = "Phone Icon",
)
MifosTextButtonWithTopDrawable(
modifier = Modifier
.fillMaxWidth()
.weight(1f),
onClick = leaveEmail,
textResourceId = R.string.leave_email,
icon = Icons.Outlined.Mail,
contentDescription = "Mail Icon"
icon = MifosIcons.Mail,
contentDescription = "Mail Icon",
)
MifosTextButtonWithTopDrawable(
modifier = Modifier
.fillMaxWidth()
.weight(1f),
onClick = findLocations,
textResourceId = R.string.find_locations,
icon = Icons.Default.LocationOn,
contentDescription = "Location Icon"
icon = MifosIcons.LocationOn,
contentDescription = "Location Icon",
)
}
} else {
EmptyDataView(
modifier = Modifier.fillMaxSize(),
error = R.string.no_questions_found
error = R.string.no_questions_found,
)
}
}
}

class HelpScreenPreviewProvider : PreviewParameterProvider<HelpUiState> {
internal class HelpScreenPreviewProvider : PreviewParameterProvider<HelpUiState> {
override val values: Sequence<HelpUiState>
get() = sequenceOf(
HelpUiState.Initial,
HelpUiState.ShowFaq(arrayListOf())
HelpUiState.ShowFaq(arrayListOf()),
)
}

@Preview(showSystemUi = true, showBackground = true)
@DevicePreviews
@Composable
private fun HelpScreenPreview(
@PreviewParameter( HelpScreenPreviewProvider::class) helpUiState: HelpUiState
@PreviewParameter(HelpScreenPreviewProvider::class)
helpUiState: HelpUiState,
) {
MifosMobileTheme {
HelpScreen(
uiState= helpUiState,
callNow = { },
leaveEmail= { },
findLocations= {},
updateFaqPosition= { _-> },
navigateBack= {},
searchQuery= {_ -> },
onSearchDismiss= { },
uiState = helpUiState,
callNow = { },
leaveEmail = { },
findLocations = {},
updateFaqPosition = { _ -> },
navigateBack = {},
searchQuery = { _ -> },
onSearchDismiss = { },
)
}
}
}
Loading

0 comments on commit c704433

Please sign in to comment.