Skip to content

refactor #1537: migrated faq screen to compose #1538

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

Merged
merged 2 commits into from
Feb 20, 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
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
package org.mifos.mobilewallet.mifospay.designsystem.component

import androidx.compose.animation.AnimatedVisibility
import androidx.compose.animation.core.Spring
import androidx.compose.animation.core.spring
import androidx.compose.animation.expandVertically
import androidx.compose.animation.fadeIn
import androidx.compose.foundation.clickable
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.padding
import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.filled.ArrowDropDown
import androidx.compose.material3.Divider
import androidx.compose.material3.Icon
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
import androidx.compose.runtime.setValue
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.draw.scale
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.text.font.FontWeight
import androidx.compose.ui.unit.dp

@Composable
fun FaqItemScreen(
question: String?,
answer: String?,
) {
var isSelected by remember { mutableStateOf(false) }

Column(
modifier = Modifier
.fillMaxWidth()
.padding(horizontal = 16.dp)
) {
Row(
modifier = Modifier
.clickable {
isSelected = !isSelected
}
.padding(vertical = 8.dp),
verticalAlignment = Alignment.CenterVertically
) {
Text(
text = question.orEmpty(),
style = MaterialTheme.typography.bodyMedium.copy(fontWeight = FontWeight.Bold),
color = Color.Black,
modifier = Modifier
.fillMaxWidth()
.weight(1f),
)

Icon(
imageVector = Icons.Default.ArrowDropDown,
contentDescription = "drop down",
tint = Color.Black,
modifier = Modifier
.scale(1f, if (isSelected) -1f else 1f)
)
}

AnimatedVisibility(
visible = isSelected,
enter = fadeIn() + expandVertically(
animationSpec = spring(
stiffness = Spring.StiffnessMedium
)
)
) {
Text(
text = answer.orEmpty(),
style = MaterialTheme.typography.bodyMedium,
color = Color.Black,
modifier = Modifier
.fillMaxWidth()
.padding(bottom = 8.dp)
)
}

Divider()
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package org.mifos.mobilewallet.mifospay.faq.presenter

import androidx.lifecycle.ViewModel
import dagger.hilt.android.lifecycle.HiltViewModel
import org.mifos.mobilewallet.mifospay.R
import org.mifos.mobilewallet.mifospay.faq.ui.FAQ
import javax.inject.Inject

@HiltViewModel
class FAQViewModel @Inject constructor() : ViewModel() {

fun getFAQ(): List<FAQ> {
return listOf(
FAQ(R.string.question1, R.string.answer1),
FAQ(R.string.question2, R.string.answer2),
FAQ(R.string.question3, R.string.answer3),
FAQ(R.string.question4, R.string.answer4)
)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package org.mifos.mobilewallet.mifospay.faq.ui

data class FAQ(
var question: Int,
var answer: Int? = null,
)
Original file line number Diff line number Diff line change
@@ -1,114 +1,27 @@
package org.mifos.mobilewallet.mifospay.faq.ui

import android.os.Bundle
import android.widget.ExpandableListView
import org.mifos.mobilewallet.mifospay.R
import androidx.activity.compose.setContent
import org.mifos.mobilewallet.mifospay.base.BaseActivity
import org.mifos.mobilewallet.mifospay.faq.FAQContract
import org.mifos.mobilewallet.mifospay.faq.FAQContract.FAQView
import org.mifos.mobilewallet.mifospay.faq.FAQListAdapter
import org.mifos.mobilewallet.mifospay.faq.presenter.FAQPresenter
import org.mifos.mobilewallet.mifospay.utils.Constants
import javax.inject.Inject
import org.mifos.mobilewallet.mifospay.theme.MifosTheme

/**
* This class is the UI component of the Architecture.
*
* @author ankur
* @since 11/July/2018
*/
class FAQActivity : BaseActivity(), FAQView {
@JvmField
@Inject
var mPresenter: FAQPresenter? = null
private var mFAQPresenter: FAQContract.FAQPresenter? = null
private var expandableListView: ExpandableListView? = null
private var faqListAdapter: FAQListAdapter? = null
private var listDataGroup: MutableList<String>? = null
private var listDataChild: HashMap<String, List<String>>? = null
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_faq)
showColoredBackButton(Constants.BLACK_BACK_BUTTON)
setToolbarTitle(Constants.FAQ)

// initializing the views
initViews()

// initializing the objects
initObjects()

// preparing list data
initListData()
}

override fun setPresenter(presenter: FAQContract.FAQPresenter?) {
mFAQPresenter = presenter
}

/**
* Method to initialize the views
*/
override fun initViews() {
expandableListView = findViewById(R.id.faq_list)
}

/**
* Method to initialize the objects
*/
override fun initObjects() {

// initializing the list of groups
listDataGroup = ArrayList()
class FAQActivity : BaseActivity() {

// initializing the list of child
listDataChild = HashMap()

// initializing the adapter object
faqListAdapter = FAQListAdapter(this, listDataGroup as ArrayList<String>, listDataChild!!)

// setting list adapter
expandableListView?.setAdapter(faqListAdapter)
}

/**
* Preparing the list data
* Dummy Items
*/
override fun initListData() {


// Adding group data
listDataGroup?.add(getString(R.string.question1))
listDataGroup?.add(getString(R.string.question2))
listDataGroup?.add(getString(R.string.question3))
listDataGroup?.add(getString(R.string.question4))

// list of alcohol
val question1List: MutableList<String> = ArrayList()
question1List.add(getString(R.string.answer1))

// list of coffee
val question2List: MutableList<String> = ArrayList()
question2List.add(getString(R.string.answer2))

// list of pasta
val question3List: MutableList<String> = ArrayList()
question3List.add(getString(R.string.answer3))


// list of cold drinks
val question4List: MutableList<String> = ArrayList()
question4List.add(getString(R.string.answer4))


// Adding child data
listDataChild!![listDataGroup!![0]] = question1List
listDataChild!![listDataGroup!![1]] = question2List
listDataChild!![listDataGroup!![2]] = question3List
listDataChild!![listDataGroup!![3]] = question4List

// notify the adapter
faqListAdapter?.notifyDataSetChanged()
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContent {
MifosTheme {
FaqScreen(
navigateBack = { onBackPressedDispatcher.onBackPressed() }
)
}
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
package org.mifos.mobilewallet.mifospay.faq.ui

import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.lazy.LazyColumn
import androidx.compose.foundation.lazy.itemsIndexed
import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.tooling.preview.Preview
import androidx.hilt.navigation.compose.hiltViewModel
import org.mifos.mobilewallet.mifospay.R
import org.mifos.mobilewallet.mifospay.designsystem.component.FaqItemScreen
import org.mifos.mobilewallet.mifospay.designsystem.component.MifosTopBar
import org.mifos.mobilewallet.mifospay.faq.presenter.FAQViewModel

@Composable
fun FaqScreen(
navigateBack: () -> Unit,
faqViewModel: FAQViewModel = hiltViewModel()
) {
FaqScreen(navigateBack = { navigateBack.invoke() }, faqViewModel.getFAQ())
}

@Composable
fun FaqScreen(
navigateBack: () -> Unit,
faqList: List<FAQ>
) {
Column(modifier = Modifier.fillMaxSize()) {
MifosTopBar(
topBarTitle = R.string.frequently_asked_questions,
backPress = { navigateBack.invoke() })
LazyColumn(
modifier = Modifier
.weight(1f)
.fillMaxWidth()
) {
itemsIndexed(items = faqList) { _, faqItem ->
FaqItemScreen(
question = stringResource(id = faqItem.question),
answer = faqItem.answer?.let { stringResource(id = it) }
)
}
}
}
}

@Preview(showSystemUi = true)
@Composable
fun FaqScreenPreview() {
FaqScreen(
{}, listOf(
FAQ(R.string.question1, R.string.answer1),
FAQ(R.string.question2, R.string.answer2),
FAQ(R.string.question3, R.string.answer3),
FAQ(R.string.question4, R.string.answer4)
)
)
}
1 change: 1 addition & 0 deletions mifospay/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,7 @@
<string name="type">Type</string>
<string name="edit_profile">Edit Profile</string>
<string name="faq">FAQ</string>
<string name="frequently_asked_questions">Frequently Asked Question</string>
<string name="settings">Settings</string>
<string name="mobile_number">Mobile Number</string>
<string name="passcode_title">Passcode will be reset, are you sure?</string>
Expand Down