Skip to content

Commit

Permalink
Feat: Migrated FAQ Module to KMP
Browse files Browse the repository at this point in the history
  • Loading branch information
niyajali committed Oct 11, 2024
1 parent 79954e0 commit 6ebdb9b
Show file tree
Hide file tree
Showing 19 changed files with 351 additions and 250 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@ class CMPFeatureConventionPlugin : Plugin<Project> {
add("commonMainImplementation", project(":core:designsystem"))
add("commonMainImplementation", project(":core:data"))

add("commonMainImplementation", libs.findLibrary("koin.compose").get())
add("commonMainImplementation", libs.findLibrary("koin.compose.viewmodel").get())

add("commonMainImplementation", libs.findLibrary("jb.composeRuntime").get())
add("commonMainImplementation", libs.findLibrary("jb.composeViewmodel").get())
add("commonMainImplementation", libs.findLibrary("jb.lifecycleViewmodel").get())
Expand Down

This file was deleted.

16 changes: 13 additions & 3 deletions feature/faq/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,22 @@
* See https://github.com/openMF/mobile-wallet/blob/master/LICENSE.md
*/
plugins {
alias(libs.plugins.mifospay.android.feature)
alias(libs.plugins.mifospay.android.library.compose)
alias(libs.plugins.mifospay.cmp.feature)
alias(libs.plugins.kotlin.parcelize)
}

android {
namespace = "org.mifospay.feature.faq"
}

dependencies { }
kotlin {
sourceSets {
commonMain.dependencies {
implementation(compose.ui)
implementation(compose.foundation)
implementation(compose.material3)
implementation(compose.components.resources)
implementation(compose.components.uiToolingPreview)
}
}
}
Empty file removed feature/faq/consumer-rules.pro
Empty file.
21 changes: 0 additions & 21 deletions feature/faq/proguard-rules.pro

This file was deleted.

File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,5 @@
<string name="feature_faq_answer2">Navigate to Payments section. You will find your payment history under the History tab.</string>
<string name="feature_faq_answer3">To make a transfer, navigate to Payments section.Under the Send tab, from there you can choose the type of transfer, add the amount and submit.</string>
<string name="feature_faq_answer4">Navigate to Finance section. Click on Add Card under the Cards tab.</string>
<string name="feature_faq_frequently_asked_questions">Frequently Asked Question</string>
<string name="feature_faq">FAQ's</string>
</resources>
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,10 @@
*/
package org.mifospay.feature.faq

import org.jetbrains.compose.resources.StringResource

internal data class FAQ(
var question: Int,
var answer: Int? = null,
val faqId: Int,
val question: StringResource,
val answer: StringResource,
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
/*
* 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-wallet/blob/master/LICENSE.md
*/
package org.mifospay.feature.faq

import kotlinx.coroutines.flow.update
import mobile_wallet.feature.faq.generated.resources.Res
import mobile_wallet.feature.faq.generated.resources.feature_faq_answer1
import mobile_wallet.feature.faq.generated.resources.feature_faq_answer2
import mobile_wallet.feature.faq.generated.resources.feature_faq_answer3
import mobile_wallet.feature.faq.generated.resources.feature_faq_answer4
import mobile_wallet.feature.faq.generated.resources.feature_faq_question1
import mobile_wallet.feature.faq.generated.resources.feature_faq_question2
import mobile_wallet.feature.faq.generated.resources.feature_faq_question3
import mobile_wallet.feature.faq.generated.resources.feature_faq_question4
import org.mifospay.core.ui.utils.BaseViewModel

internal class FAQViewModel : BaseViewModel<FaqState, FaqEvent, FaqAction>(
initialState = FaqState(sampleFaqList),
) {
override fun handleAction(action: FaqAction) {
when (action) {
is FaqAction.ExpandFaq -> {
mutableStateFlow.update {
if (it.expandedFaq == action.faqId) {
it.copy(expandedFaq = null)
} else {
it.copy(expandedFaq = action.faqId)
}
}
}

is FaqAction.NavigateBack -> {
sendEvent(FaqEvent.OnNavigateBack)
}
}
}
}

internal data class FaqState(
val faqList: List<FAQ>,
val expandedFaq: Int? = null,
)

internal sealed interface FaqEvent {
data object OnNavigateBack : FaqEvent
}

internal sealed interface FaqAction {
data class ExpandFaq(val faqId: Int) : FaqAction
data object NavigateBack : FaqAction
}

/**
* Retrieves a list of Frequently Asked Questions (FAQs).
*
* Currently, the FAQs are statically defined within this function. This is a temporary
* implementation for demonstration or testing purposes. In the future, this method will
* be updated to fetch the FAQ data from a backend service once the backend functionality
* is implemented. This will allow for dynamic and up-to-date FAQ content.
*
* @return A list of [FAQ] objects containing the questions and answers.
*/
internal val sampleFaqList = listOf(
FAQ(1, Res.string.feature_faq_question1, Res.string.feature_faq_answer1),
FAQ(2, Res.string.feature_faq_question2, Res.string.feature_faq_answer2),
FAQ(3, Res.string.feature_faq_question3, Res.string.feature_faq_answer3),
FAQ(4, Res.string.feature_faq_question4, Res.string.feature_faq_answer4),
)
Loading

0 comments on commit 6ebdb9b

Please sign in to comment.