Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: help module #2645

Merged
merged 1 commit into from
Jul 5, 2024
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
1 change: 1 addition & 0 deletions app/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ dependencies {
implementation(projects.feature.clientCharge)
implementation(projects.feature.recentTransaction)
implementation(projects.feature.thirdPartyTransfer)
implementation(projects.feature.help)


implementation("androidx.legacy:legacy-support-v4:1.0.0")
Expand Down
63 changes: 9 additions & 54 deletions app/src/main/java/org/mifos/mobile/ui/help/HelpFragment.kt
Original file line number Diff line number Diff line change
Expand Up @@ -7,23 +7,18 @@ import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.Toast
import androidx.compose.runtime.MutableState
import androidx.compose.runtime.mutableStateOf
import androidx.compose.ui.platform.ComposeView
import androidx.compose.ui.platform.ViewCompositionStrategy
import androidx.fragment.app.viewModels
import androidx.lifecycle.Lifecycle
import androidx.lifecycle.lifecycleScope
import androidx.lifecycle.repeatOnLifecycle
import dagger.hilt.android.AndroidEntryPoint
import kotlinx.coroutines.launch
import org.mifos.mobile.R
import org.mifos.mobile.core.model.entity.FAQ
import org.mifos.mobile.core.ui.component.mifosComposeView
import org.mifos.mobile.core.ui.theme.MifosMobileTheme
import org.mifos.mobile.feature.help.HelpScreen
import org.mifos.mobile.feature.help.HelpViewModel
import org.mifos.mobile.ui.activities.base.BaseActivity
import org.mifos.mobile.ui.fragments.base.BaseFragment
import org.mifos.mobile.ui.location.LocationsFragment
import org.mifos.mobile.utils.HelpUiState

/*
~This project is licensed under the open source MPL V2.
Expand All @@ -32,59 +27,19 @@ import org.mifos.mobile.utils.HelpUiState
@AndroidEntryPoint
class HelpFragment : BaseFragment() {

private val viewModel: HelpViewModel by viewModels()
private var faqArrayList: MutableState<List<FAQ?>> = mutableStateOf(arrayListOf())
private var selectedFaqPosition: MutableState<Int> = mutableStateOf(-1)
override fun onCreateView(
inflater: LayoutInflater,
container: ViewGroup?,
savedInstanceState: Bundle?,
): View {
if (savedInstanceState == null) {
viewModel.loadFaq(
context?.resources?.getStringArray(R.array.faq_qs),
context?.resources?.getStringArray(R.array.faq_ans)
return mifosComposeView(requireContext()) {
HelpScreen(
callNow = { callHelpline() },
leaveEmail = { mailHelpline() },
findLocations = { findLocations() },
navigateBack = { activity?.finish() },
)
}
return ComposeView(requireContext()).apply {
setViewCompositionStrategy(ViewCompositionStrategy.DisposeOnViewTreeLifecycleDestroyed)
setContent {
MifosMobileTheme {
HelpScreen(
faqArrayList = faqArrayList.value,
callNow = { callHelpline() },
leaveEmail = { mailHelpline() },
findLocations = { findLocations() },
navigateBack = { activity?.finish() },
onSearchDismiss = { viewModel.loadFaq(qs = null, ans = null) },
searchQuery = { viewModel.filterList(it) },
selectedFaqPosition = selectedFaqPosition.value,
updateFaqPosition = { viewModel.updateSelectedFaqPosition(it) }
)
}
}
}
}


override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)

viewLifecycleOwner.lifecycleScope.launch {
repeatOnLifecycle(Lifecycle.State.STARTED) {
viewModel.helpUiState.collect() {
when (it) {

is HelpUiState.ShowFaq -> {
faqArrayList.value = it.faqArrayList
selectedFaqPosition.value = it.selectedFaqPosition
}

HelpUiState.Initial -> {}
}
}
}
}
}

private fun callHelpline() {
Expand Down
7 changes: 0 additions & 7 deletions app/src/main/java/org/mifos/mobile/utils/HelpUiState.kt
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,3 @@ package org.mifos.mobile.utils

import org.mifos.mobile.core.model.entity.FAQ

sealed class HelpUiState {
object Initial : HelpUiState()
data class ShowFaq(
val faqArrayList: ArrayList<FAQ?>,
val selectedFaqPosition: Int = -1
) : HelpUiState()
}
34 changes: 0 additions & 34 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -513,40 +513,6 @@
<string name="scan_your_fingerprint">Scan your fingerprint</string>


<string-array name="faq_qs">
<item>How do I apply for new loan account?</item>
<item>Where can I view my profile information?</item>
<item>Where can I see my Savings Accounts Transactions?</item>
<item>What is the use of QR Code?</item>
<item>How to create a beneficiary using QR Code?</item>
<item>How to make a payment for a Loan Account?</item>
</string-array>

<string-array name="faq_ans">
<item>To apply for loan account, click on \"Apply for Loan\" given on the Home Screen.
</item>
<item>You can view your profile information by clicking on the User Image present on Home
Screen.
</item>
<item>To view your savings account transactions, navigate to the Accounts Sections, click on
the required savings account, click on three dots present on top right and select
Transactions option.
</item>
<item>QrCode for any loan or savings accounts can be shared with other users which will
allow them to create a beneficiary.
</item>
<item>In order to create a Beneficiary, goto Beneficiary option from Home Screen then click
on the circular button present on bottom right, choose the option to Scan which opens
your device camera, scan the QR Code of other person for which you want to create a
beneficiary, after filling in the other required detail you will be able to create a
Beneficiary using QR Code.
</item>
<item>To make a payment for a loan account, navigate to the Accounts Sections, choose LOAN
then open your required Loan Account and click on Make Payment option.
</item>

</string-array>

<string name="language_type" translatable="false">language_type</string>
<string name="default_system_language" translatable="false">default_system_language</string>
<string name="theme_type" translatable="false">theme_type</string>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package org.mifos.mobile.viewModels

import androidx.arch.core.executor.testing.InstantTaskExecutorRule
import androidx.lifecycle.Observer
import app.cash.turbine.test
import junit.framework.Assert.assertEquals
import kotlinx.coroutines.test.advanceUntilIdle
Expand All @@ -11,7 +10,6 @@ import org.junit.Rule
import org.junit.Test
import org.junit.runner.RunWith
import org.mifos.mobile.models.FAQ
import org.mifos.mobile.ui.help.HelpViewModel
import org.mifos.mobile.utils.HelpUiState
import org.mockito.Mock
import org.mockito.Mockito.*
Expand Down
1 change: 1 addition & 0 deletions feature/help/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/build
19 changes: 19 additions & 0 deletions feature/help/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
plugins {
alias(libs.plugins.mifos.android.feature)
alias(libs.plugins.mifos.android.library.compose)
}

android {
namespace = "org.mifos.mobile.feature.help"
}

dependencies {
implementation(projects.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)
}
Empty file added feature/help/consumer-rules.pro
Empty file.
21 changes: 21 additions & 0 deletions feature/help/proguard-rules.pro
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# Add project specific ProGuard rules here.
# You can control the set of applied configuration files using the
# proguardFiles setting in build.gradle.
#
# For more details, see
# http://developer.android.com/guide/developing/tools/proguard.html

# If your project uses WebView with JS, uncomment the following
# and specify the fully qualified class name to the JavaScript interface
# class:
#-keepclassmembers class fqcn.of.javascript.interface.for.webview {
# public *;
#}

# Uncomment this to preserve the line number information for
# debugging stack traces.
#-keepattributes SourceFile,LineNumberTable

# If you keep the line number information, uncomment this to
# hide the original source file name.
#-renamesourcefileattribute SourceFile
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package org.mifos.mobile.feature.help

import androidx.test.platform.app.InstrumentationRegistry
import androidx.test.ext.junit.runners.AndroidJUnit4

import org.junit.Test
import org.junit.runner.RunWith

import org.junit.Assert.*

/**
* Instrumented test, which will execute on an Android device.
*
* See [testing documentation](http://d.android.com/tools/testing).
*/
@RunWith(AndroidJUnit4::class)
class ExampleInstrumentedTest {
@Test
fun useAppContext() {
// Context of the app under test.
val appContext = InstrumentationRegistry.getInstrumentation().targetContext
assertEquals("org.mifos.mobile.feature.help.test", appContext.packageName)
}
}
4 changes: 4 additions & 0 deletions feature/help/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android">

</manifest>
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package org.mifos.mobile.ui.help
package org.mifos.mobile.feature.help

import androidx.compose.foundation.isSystemInDarkTheme
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.fillMaxSize
Expand All @@ -15,23 +15,58 @@ import androidx.compose.material.icons.outlined.Mail
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.runtime.LaunchedEffect
import androidx.compose.runtime.getValue
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.platform.LocalContext
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.unit.dp
import org.mifos.mobile.R
import androidx.hilt.navigation.compose.hiltViewModel
import androidx.lifecycle.compose.collectAsStateWithLifecycle
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.MFScaffold
import org.mifos.mobile.core.ui.component.MifosTextButtonWithTopDrawable
import org.mifos.mobile.core.ui.component.MifosTitleSearchCard
import org.mifos.mobile.core.ui.component.MifosTopBar



@Composable
fun HelpScreen(
faqArrayList: List<FAQ?>?,
selectedFaqPosition: Int = -1,
viewModel: HelpViewModel = hiltViewModel(),
callNow: () -> Unit,
leaveEmail: () -> Unit,
findLocations: () -> Unit,
navigateBack: () -> Unit,
) {

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)
)
}

HelpScreen(
uiState = uiState,
callNow = callNow,
leaveEmail = leaveEmail,
findLocations = findLocations,
navigateBack = navigateBack,
searchQuery = { viewModel.filterList(it) },
onSearchDismiss = { viewModel.loadFaq(qs = null, ans = null) },
updateFaqPosition = { viewModel.updateSelectedFaqPosition(it) }
)
}

@Composable
fun HelpScreen(
uiState: HelpUiState,
callNow: () -> Unit,
leaveEmail: () -> Unit,
findLocations: () -> Unit,
Expand All @@ -40,21 +75,55 @@ fun HelpScreen(
onSearchDismiss: () -> Unit,
updateFaqPosition: (Int) -> Unit,
) {

MFScaffold(
topBar = {
MifosTopBar(
navigateBack = navigateBack,
title = {
MifosTitleSearchCard(
searchQuery = searchQuery,
titleResourceId = R.string.help,
onSearchDismiss = onSearchDismiss
)
}
)
},
scaffoldContent = { paddingValues ->
Box(modifier = Modifier.padding(paddingValues)) {
when(uiState) {
is HelpUiState.Initial -> Unit
is HelpUiState.ShowFaq -> {
HelpContent(
faqArrayList = uiState.faqArrayList.toList().filterNotNull(),
selectedFaqPosition = uiState.selectedFaqPosition,
callNow = callNow,
leaveEmail = leaveEmail,
findLocations = findLocations,
updateFaqPosition = updateFaqPosition
)
}
}
}
}
)

}


@Composable
fun HelpContent(
faqArrayList: List<FAQ>,
selectedFaqPosition: Int,
callNow: () -> Unit,
leaveEmail: () -> Unit,
findLocations: () -> Unit,
updateFaqPosition: (Int) -> Unit,
) {
Column(
modifier = Modifier
.fillMaxSize()
) {
MifosTopBar(
navigateBack = navigateBack,
title = {
MifosTitleSearchCard(
searchQuery = searchQuery,
titleResourceId = R.string.help,
onSearchDismiss = onSearchDismiss
)
}
)

Text(
text = stringResource(id = R.string.faq),
modifier = Modifier
Expand Down Expand Up @@ -116,11 +185,8 @@ fun HelpScreen(
} else {
EmptyDataView(
modifier = Modifier.fillMaxSize(),
icon = R.drawable.ic_help_black_24dp,
error = R.string.no_questions_found
)
}

}
}

Loading
Loading