Skip to content

Commit

Permalink
Merge pull request #2411 from SekhGulamMainuddin/fixHelpFAQForgottenS…
Browse files Browse the repository at this point in the history
…tate

Fix: #1742 Fixed FAQS forgotten state
  • Loading branch information
therajanmaurya authored Jan 28, 2024
2 parents c647a15 + 415d79f commit 0b91c36
Show file tree
Hide file tree
Showing 3 changed files with 67 additions and 58 deletions.
33 changes: 14 additions & 19 deletions app/src/main/java/org/mifos/mobile/ui/adapters/FAQAdapter.kt
Original file line number Diff line number Diff line change
@@ -1,34 +1,31 @@
package org.mifos.mobile.ui.adapters

import android.content.Context
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.core.view.isVisible
import androidx.recyclerview.widget.DiffUtil
import androidx.recyclerview.widget.RecyclerView
import org.mifos.mobile.R
import org.mifos.mobile.databinding.RowFaqBinding
import dagger.hilt.android.qualifiers.ActivityContext


import org.mifos.mobile.models.FAQ
import org.mifos.mobile.utils.FaqDiffUtil
import javax.inject.Inject

/**
* Created by dilpreet on 12/8/17.
*/
class FAQAdapter @Inject constructor(@ActivityContext context: Context) :
class FAQAdapter(val onFAQClicked: (Int) -> Unit) :
RecyclerView.Adapter<RecyclerView.ViewHolder>() {

private var faqArrayList: ArrayList<FAQ?>?
private var alreadySelectedPosition = 0
private val context: Context
private lateinit var binding: RowFaqBinding

init {
faqArrayList = ArrayList()
this.context = context
}

fun updateAlreadySelectedPosition(selectedPosition: Int) {
alreadySelectedPosition = selectedPosition
}

fun setFaqArrayList(faqArrayList: ArrayList<FAQ?>?) {
Expand Down Expand Up @@ -76,22 +73,20 @@ class FAQAdapter @Inject constructor(@ActivityContext context: Context) :
RecyclerView.ViewHolder(binding.root) {

fun bind(question: String?, answer: String?, isSelected: Boolean) {
binding.tvQs.text = question
binding.tvAns.text = answer
binding.apply {
tvQs.text = question
tvAns.text = answer

if (isSelected) {
binding.tvAns.visibility = View.VISIBLE
binding.ivArrow.setImageResource(R.drawable.ic_arrow_up)
} else {
binding.tvAns.visibility = View.GONE
binding.ivArrow.setImageResource(R.drawable.ic_arrow_drop_down)
tvAns.isVisible = isSelected
ivArrow.setImageResource(if (isSelected) R.drawable.ic_arrow_up else R.drawable.ic_arrow_drop_down)
}
}

init {
binding.llFaq.setOnClickListener {
updateView(adapterPosition)
updateView(bindingAdapterPosition)
onFAQClicked(bindingAdapterPosition)
}
}
}
}
}
89 changes: 50 additions & 39 deletions app/src/main/java/org/mifos/mobile/ui/fragments/HelpFragment.kt
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ import org.mifos.mobile.utils.Constants
import org.mifos.mobile.utils.DividerItemDecoration
import org.mifos.mobile.utils.HelpUiState
import org.mifos.mobile.viewModels.HelpViewModel
import javax.inject.Inject

/*
~This project is licensed under the open source MPL V2.
Expand All @@ -42,9 +41,7 @@ class HelpFragment : BaseFragment() {
private var _binding: FragmentHelpBinding? = null
private val binding get() = _binding!!

@JvmField
@Inject
var faqAdapter: FAQAdapter? = null
private lateinit var faqAdapter: FAQAdapter

private val viewModel: HelpViewModel by viewModels()

Expand Down Expand Up @@ -73,6 +70,9 @@ class HelpFragment : BaseFragment() {

override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)
faqAdapter = FAQAdapter {
viewModel.alreadySelectedPosition = it
}

viewLifecycleOwner.lifecycleScope.launch {
repeatOnLifecycle(Lifecycle.State.STARTED) {
Expand All @@ -92,7 +92,10 @@ class HelpFragment : BaseFragment() {

override fun onSaveInstanceState(outState: Bundle) {
super.onSaveInstanceState(outState)
outState.putParcelableArrayList(Constants.HELP, ArrayList<Parcelable?>(faqArrayList))
outState.putParcelableArrayList(
Constants.HELP,
faqArrayList?.let { ArrayList<Parcelable?>(it) },
)
}

override fun onActivityCreated(savedInstanceState: Bundle?) {
Expand All @@ -104,43 +107,50 @@ class HelpFragment : BaseFragment() {
}
}

override fun onResume() {
super.onResume()
faqAdapter.updateAlreadySelectedPosition(viewModel.alreadySelectedPosition)
}

private fun showUserInterface() {
val layoutManager = LinearLayoutManager(activity)
layoutManager.orientation = LinearLayoutManager.VERTICAL
binding.rvFaq.layoutManager = layoutManager
binding.rvFaq.addItemDecoration(
DividerItemDecoration(
activity,
layoutManager.orientation,
),
)
binding.callButton.setOnClickListener {
val intent = Intent(Intent.ACTION_DIAL)
intent.data = Uri.parse("tel:" + getString(R.string.help_line_number))
startActivity(intent)
}
binding.mailButton.setOnClickListener {
val intent = Intent(Intent.ACTION_SENDTO).apply {
data = Uri.parse("mailto:")
putExtra(Intent.EXTRA_EMAIL, arrayOf(getString(R.string.contact_email)))
putExtra(Intent.EXTRA_SUBJECT, getString(R.string.user_query))
}
try {
binding.apply {
rvFaq.layoutManager = layoutManager
rvFaq.addItemDecoration(
DividerItemDecoration(
activity,
layoutManager.orientation,
),
)
callButton.setOnClickListener {
val intent = Intent(Intent.ACTION_DIAL)
intent.data = Uri.parse("tel:" + getString(R.string.help_line_number))
startActivity(intent)
} catch (e: Exception) {
Toast.makeText(
requireContext(),
getString(R.string.no_app_to_support_action),
Toast.LENGTH_SHORT,
).show()
}
}
binding.locationsButton.setOnClickListener {
(activity as BaseActivity?)?.replaceFragment(
LocationsFragment.newInstance(),
true,
R.id.container,
)
mailButton.setOnClickListener {
val intent = Intent(Intent.ACTION_SENDTO).apply {
data = Uri.parse("mailto:")
putExtra(Intent.EXTRA_EMAIL, arrayOf(getString(R.string.contact_email)))
putExtra(Intent.EXTRA_SUBJECT, getString(R.string.user_query))
}
try {
startActivity(intent)
} catch (e: Exception) {
Toast.makeText(
requireContext(),
getString(R.string.no_app_to_support_action),
Toast.LENGTH_SHORT,
).show()
}
}
locationsButton.setOnClickListener {
(activity as BaseActivity?)?.replaceFragment(
LocationsFragment.newInstance(),
true,
R.id.container,
)
}
}
}

Expand Down Expand Up @@ -168,7 +178,8 @@ class HelpFragment : BaseFragment() {
binding.rvFaq,
binding.layoutError.clErrorLayout,
)
faqAdapter?.updateList(it)
faqAdapter.updateList(it)
viewModel.alreadySelectedPosition = -1
} else {
showEmptyFAQUI()
}
Expand Down Expand Up @@ -209,4 +220,4 @@ class HelpFragment : BaseFragment() {
_binding = null
super.onDestroyView()
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -38,4 +38,7 @@ class HelpViewModel @Inject constructor() : ViewModel() {
}
return filteredList
}

var alreadySelectedPosition = -1

}

0 comments on commit 0b91c36

Please sign in to comment.