-
Notifications
You must be signed in to change notification settings - Fork 494
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
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
89 changes: 89 additions & 0 deletions
89
...tem/src/main/java/org/mifos/mobilewallet/mifospay/designsystem/component/FaqItemScreen.kt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() | ||
} | ||
} |
20 changes: 20 additions & 0 deletions
20
mifospay/src/main/java/org/mifos/mobilewallet/mifospay/faq/presenter/FAQViewModel.kt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
) | ||
} | ||
} |
6 changes: 6 additions & 0 deletions
6
mifospay/src/main/java/org/mifos/mobilewallet/mifospay/faq/ui/FAQ.kt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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, | ||
) |
111 changes: 12 additions & 99 deletions
111
mifospay/src/main/java/org/mifos/mobilewallet/mifospay/faq/ui/FAQActivity.kt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() } | ||
) | ||
} | ||
} | ||
} | ||
} |
61 changes: 61 additions & 0 deletions
61
mifospay/src/main/java/org/mifos/mobilewallet/mifospay/faq/ui/FaqScreen.kt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) } | ||
) | ||
} | ||
} | ||
} | ||
} | ||
|
||
therajanmaurya marked this conversation as resolved.
Show resolved
Hide resolved
|
||
@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) | ||
) | ||
) | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.