Skip to content

Commit

Permalink
feat: Compose View for Help Screen
Browse files Browse the repository at this point in the history
  • Loading branch information
AvneetSingh2001 committed Jan 23, 2024
1 parent dbfcd8c commit efa7119
Show file tree
Hide file tree
Showing 16 changed files with 705 additions and 259 deletions.
2 changes: 1 addition & 1 deletion app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@
android:windowSoftInputMode="adjustResize" />

<activity
android:name="org.mifos.mobile.ui.activities.HelpActivity"
android:name="org.mifos.mobile.ui.help.HelpActivity"
android:windowSoftInputMode="adjustResize" />

<activity
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ import org.mifos.mobile.ui.enums.AccountType
import org.mifos.mobile.ui.enums.ChargeType
import org.mifos.mobile.ui.fragments.*
import org.mifos.mobile.ui.getThemeAttributeColor
import org.mifos.mobile.ui.help.HelpActivity
import org.mifos.mobile.ui.login.LoginActivity
import org.mifos.mobile.utils.Constants
import org.mifos.mobile.utils.TextDrawable
Expand Down
212 changes: 0 additions & 212 deletions app/src/main/java/org/mifos/mobile/ui/fragments/HelpFragment.kt

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
package org.mifos.mobile.ui.activities
package org.mifos.mobile.ui.help

import android.os.Bundle
import android.view.View
import org.mifos.mobile.R
import org.mifos.mobile.databinding.ActivityContainerBinding
import org.mifos.mobile.ui.activities.base.BaseActivity
import org.mifos.mobile.ui.fragments.HelpFragment
import org.mifos.mobile.ui.help.HelpFragment

/**
* @author Rajan Maurya
Expand All @@ -17,8 +18,7 @@ class HelpActivity : BaseActivity() {
super.onCreate(savedInstanceState)
binding = ActivityContainerBinding.inflate(layoutInflater)
setContentView(binding.root)
setToolbarTitle(getString(R.string.help))
showBackButton()
toolbar?.visibility = View.GONE
replaceFragment(HelpFragment.newInstance(), false, R.id.container)
}
}
130 changes: 130 additions & 0 deletions app/src/main/java/org/mifos/mobile/ui/help/HelpFragment.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,130 @@
package org.mifos.mobile.ui.help

import android.content.Intent
import android.net.Uri
import android.os.Bundle
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.ui.theme.MifosMobileTheme
import org.mifos.mobile.models.FAQ
import org.mifos.mobile.ui.activities.base.BaseActivity
import org.mifos.mobile.ui.fragments.LocationsFragment
import org.mifos.mobile.ui.fragments.base.BaseFragment
import org.mifos.mobile.utils.HelpUiState

/*
~This project is licensed under the open source MPL V2.
~See https://github.com/openMF/self-service-app/blob/master/LICENSE.md
*/
@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 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() {
val intent = Intent(Intent.ACTION_DIAL)
intent.data = Uri.parse("tel:" + getString(R.string.help_line_number))
startActivity(intent)
}

private fun findLocations() {
(activity as BaseActivity?)?.replaceFragment(
LocationsFragment.newInstance(),
true,
R.id.container,
)
}

private fun mailHelpline() {
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()
}
}

companion object {
@JvmStatic
fun newInstance(): HelpFragment {
val fragment = HelpFragment()
val args = Bundle()
fragment.arguments = args
return fragment
}
}
}
Loading

0 comments on commit efa7119

Please sign in to comment.