diff --git a/core/designsystem/src/main/java/com/mifos/core/designsystem/component/MifosBottomSheet.kt b/core/designsystem/src/main/java/com/mifos/core/designsystem/component/MifosBottomSheet.kt new file mode 100644 index 00000000000..cac4f8d15aa --- /dev/null +++ b/core/designsystem/src/main/java/com/mifos/core/designsystem/component/MifosBottomSheet.kt @@ -0,0 +1,69 @@ +@file:OptIn(ExperimentalMaterial3Api::class) + +package com.mifos.core.designsystem.component + +import androidx.activity.compose.BackHandler +import androidx.compose.animation.AnimatedVisibility +import androidx.compose.foundation.layout.Box +import androidx.compose.foundation.layout.height +import androidx.compose.material3.ExperimentalMaterial3Api +import androidx.compose.material3.ModalBottomSheet +import androidx.compose.material3.rememberModalBottomSheetState +import androidx.compose.runtime.Composable +import androidx.compose.runtime.getValue +import androidx.compose.runtime.mutableStateOf +import androidx.compose.runtime.remember +import androidx.compose.runtime.rememberCoroutineScope +import androidx.compose.runtime.setValue +import androidx.compose.ui.Modifier +import androidx.compose.ui.graphics.Color +import androidx.compose.ui.tooling.preview.Preview +import androidx.compose.ui.unit.dp +import kotlinx.coroutines.launch + +@Composable +fun MifosBottomSheet( + content: @Composable () -> Unit, + onDismiss: () -> Unit +) { + val coroutineScope = rememberCoroutineScope() + val modalSheetState = rememberModalBottomSheetState(skipPartiallyExpanded = true) + var showBottomSheet by remember { mutableStateOf(true) } + + + fun dismissSheet() { + coroutineScope.launch { modalSheetState.hide() }.invokeOnCompletion { + if (!modalSheetState.isVisible) { + showBottomSheet = false + } + } + onDismiss.invoke() + } + + BackHandler(modalSheetState.isVisible) { + dismissSheet() + } + + AnimatedVisibility(visible = showBottomSheet) { + ModalBottomSheet( + containerColor = Color.White, + onDismissRequest = { + showBottomSheet = false + dismissSheet() + }, + sheetState = modalSheetState + ) { + content() + } + } +} + +@Preview +@Composable +fun MifosBottomSheetPreview() { + MifosBottomSheet({ + Box { + Modifier.height(100.dp) + } + }, {}) +} \ No newline at end of file diff --git a/core/designsystem/src/main/java/com/mifos/core/designsystem/component/MifosScaffold.kt b/core/designsystem/src/main/java/com/mifos/core/designsystem/component/MifosScaffold.kt index 268a4a34a62..b1329146e2b 100644 --- a/core/designsystem/src/main/java/com/mifos/core/designsystem/component/MifosScaffold.kt +++ b/core/designsystem/src/main/java/com/mifos/core/designsystem/component/MifosScaffold.kt @@ -14,7 +14,7 @@ import com.mifos.core.designsystem.theme.White fun MifosScaffold( topBar: @Composable () -> Unit, snackbarHostState: SnackbarHostState?, - bottomBar: @Composable () -> Unit, + bottomBar: @Composable () -> Unit = {}, content: @Composable (PaddingValues) -> Unit ) { diff --git a/core/designsystem/src/main/java/com/mifos/core/designsystem/component/MifosTabRow.kt b/core/designsystem/src/main/java/com/mifos/core/designsystem/component/MifosTabRow.kt new file mode 100644 index 00000000000..a173bb67995 --- /dev/null +++ b/core/designsystem/src/main/java/com/mifos/core/designsystem/component/MifosTabRow.kt @@ -0,0 +1,57 @@ +@file:OptIn(ExperimentalFoundationApi::class) + +package com.mifos.core.designsystem.component + +import androidx.compose.foundation.ExperimentalFoundationApi +import androidx.compose.foundation.pager.HorizontalPager +import androidx.compose.foundation.pager.PagerState +import androidx.compose.material3.Tab +import androidx.compose.material3.TabRow +import androidx.compose.material3.Text +import androidx.compose.runtime.Composable +import androidx.compose.runtime.rememberCoroutineScope +import androidx.compose.ui.Modifier +import androidx.compose.ui.graphics.Color +import com.mifos.core.designsystem.theme.BluePrimary +import com.mifos.core.designsystem.utility.TabContent +import kotlinx.coroutines.launch + +@Composable +fun MifosTabRow( + tabContents: List, + pagerState: PagerState, + modifier: Modifier = Modifier, + containerColor: Color = Color.White, + selectedContentColor: Color = BluePrimary, + unselectedContentColor: Color = Color.LightGray +) { + val scope = rememberCoroutineScope() + + TabRow( + containerColor = containerColor, + selectedTabIndex = pagerState.currentPage, + indicator = {}, + divider = {}, + ) { + tabContents.forEachIndexed { index, currentTab -> + Tab( + text = { Text(text = currentTab.tabName) }, + selected = pagerState.currentPage == index, + selectedContentColor = selectedContentColor, + unselectedContentColor = unselectedContentColor, + onClick = { + scope.launch { + pagerState.animateScrollToPage(index) + } + } + ) + } + } + + HorizontalPager( + state = pagerState, + modifier = modifier + ) { page -> + tabContents.getOrNull(page)?.content?.invoke() ?: Text("Page $page") + } +} \ No newline at end of file diff --git a/core/designsystem/src/main/java/com/mifos/core/designsystem/utility/TabContent.kt b/core/designsystem/src/main/java/com/mifos/core/designsystem/utility/TabContent.kt new file mode 100644 index 00000000000..b97e1a0bd39 --- /dev/null +++ b/core/designsystem/src/main/java/com/mifos/core/designsystem/utility/TabContent.kt @@ -0,0 +1,10 @@ +package com.mifos.core.designsystem.utility + +import androidx.compose.runtime.Composable + +data class TabContent( + + val tabName: String, + + val content: @Composable () -> Unit +) diff --git a/feature/collection-sheet/src/main/java/com/mifos/feature/individual_collection_sheet/individual_collection_sheet/ui/IndividualCollectionSheetScreen.kt b/feature/collection-sheet/src/main/java/com/mifos/feature/individual_collection_sheet/individual_collection_sheet/ui/IndividualCollectionSheetScreen.kt new file mode 100644 index 00000000000..5dc8fcadb23 --- /dev/null +++ b/feature/collection-sheet/src/main/java/com/mifos/feature/individual_collection_sheet/individual_collection_sheet/ui/IndividualCollectionSheetScreen.kt @@ -0,0 +1,110 @@ +@file:OptIn(ExperimentalFoundationApi::class, ExperimentalMaterial3Api::class) + +package com.mifos.feature.individual_collection_sheet.individual_collection_sheet.ui + +import androidx.compose.foundation.ExperimentalFoundationApi +import androidx.compose.foundation.layout.Column +import androidx.compose.foundation.layout.padding +import androidx.compose.foundation.pager.rememberPagerState +import androidx.compose.material.icons.Icons +import androidx.compose.material.icons.rounded.ArrowBackIosNew +import androidx.compose.material3.ExperimentalMaterial3Api +import androidx.compose.material3.Icon +import androidx.compose.material3.IconButton +import androidx.compose.material3.SnackbarHostState +import androidx.compose.material3.Text +import androidx.compose.material3.TopAppBar +import androidx.compose.material3.TopAppBarDefaults +import androidx.compose.runtime.Composable +import androidx.compose.runtime.remember +import androidx.compose.ui.Modifier +import androidx.compose.ui.res.stringResource +import androidx.compose.ui.text.TextStyle +import androidx.compose.ui.text.font.FontStyle +import androidx.compose.ui.text.font.FontWeight +import androidx.compose.ui.text.style.TextAlign +import androidx.compose.ui.tooling.preview.Preview +import androidx.compose.ui.unit.sp +import com.mifos.core.designsystem.component.MifosScaffold +import com.mifos.core.designsystem.component.MifosTabRow +import com.mifos.core.designsystem.theme.Black +import com.mifos.core.designsystem.theme.White +import com.mifos.core.designsystem.utility.TabContent +import com.mifos.core.objects.collectionsheet.IndividualCollectionSheet +import com.mifos.feature.collection_sheet.R +import com.mifos.feature.individual_collection_sheet.new_individual_collection_sheet.ui.NewIndividualCollectionSheetScreen +import com.mifos.feature.individual_collection_sheet.saved_individual_collection_sheet.ui.SavedIndividualCollectionSheetCompose + +@Composable +fun IndividualCollectionSheetScreen( + onBackPressed: () -> Unit, + onDetail: (String, IndividualCollectionSheet) -> Unit, +) { + + val snackbarHostState = remember { SnackbarHostState() } + + val pagerState = rememberPagerState( + pageCount = { IndividualCollectionSheetScreenContents.entries.size } + ) + + val tabContents = listOf( + TabContent(IndividualCollectionSheetScreenContents.NEW.name) { + NewIndividualCollectionSheetScreen(onDetail = onDetail) + }, + TabContent(IndividualCollectionSheetScreenContents.SAVED.name) { + SavedIndividualCollectionSheetCompose() + } + ) + + MifosScaffold( + topBar = { + TopAppBar( + colors = TopAppBarDefaults.mediumTopAppBarColors(containerColor = White), + navigationIcon = { + IconButton( + onClick = { onBackPressed() }, + ) { + Icon( + imageVector = Icons.Rounded.ArrowBackIosNew, + contentDescription = null, + tint = Black, + ) + } + + }, + title = { + Text( + text = stringResource(id = R.string.feature_collection_sheet_individual_collection_sheet), + style = TextStyle( + fontSize = 24.sp, + fontWeight = FontWeight.Medium, + fontStyle = FontStyle.Normal + ), + color = Black, + textAlign = TextAlign.Start + ) + + } + ) + }, + snackbarHostState = snackbarHostState, + bottomBar = { } + ) { paddingValues -> + Column( + modifier = Modifier.padding(paddingValues) + ) { + MifosTabRow(tabContents = tabContents, pagerState = pagerState) + } + } +} + +enum class IndividualCollectionSheetScreenContents { + NEW, + SAVED +} + +@Preview(showBackground = true) +@Composable +private fun IndividualCollectionSheetScreenPreview() { + IndividualCollectionSheetScreen(onBackPressed = {}, onDetail = { _, _ -> }) +} \ No newline at end of file diff --git a/feature/collection-sheet/src/main/java/com/mifos/feature/individual_collection_sheet/new_individual_collection_sheet/ui/NewIndividualCollectionSheetScreen.kt b/feature/collection-sheet/src/main/java/com/mifos/feature/individual_collection_sheet/new_individual_collection_sheet/ui/NewIndividualCollectionSheetScreen.kt index 47524248c6c..a9b1df3c83d 100644 --- a/feature/collection-sheet/src/main/java/com/mifos/feature/individual_collection_sheet/new_individual_collection_sheet/ui/NewIndividualCollectionSheetScreen.kt +++ b/feature/collection-sheet/src/main/java/com/mifos/feature/individual_collection_sheet/new_individual_collection_sheet/ui/NewIndividualCollectionSheetScreen.kt @@ -12,6 +12,7 @@ import androidx.compose.foundation.layout.fillMaxSize import androidx.compose.foundation.layout.fillMaxWidth import androidx.compose.foundation.layout.height import androidx.compose.foundation.layout.padding +import androidx.compose.foundation.layout.width import androidx.compose.material3.Button import androidx.compose.material3.ButtonDefaults import androidx.compose.material3.DatePicker @@ -31,11 +32,13 @@ import androidx.compose.runtime.mutableStateOf import androidx.compose.runtime.remember import androidx.compose.runtime.saveable.rememberSaveable import androidx.compose.runtime.setValue +import androidx.compose.ui.Alignment import androidx.compose.ui.Modifier import androidx.compose.ui.graphics.Color import androidx.compose.ui.platform.LocalSoftwareKeyboardController import androidx.compose.ui.res.stringResource import androidx.compose.ui.text.TextStyle +import androidx.compose.ui.text.font.FontWeight import androidx.compose.ui.tooling.preview.Preview import androidx.compose.ui.tooling.preview.PreviewParameter import androidx.compose.ui.tooling.preview.PreviewParameterProvider @@ -43,6 +46,7 @@ import androidx.compose.ui.unit.dp import androidx.compose.ui.unit.sp import androidx.hilt.navigation.compose.hiltViewModel import androidx.lifecycle.compose.collectAsStateWithLifecycle +import com.mifos.core.designsystem.component.MifosBottomSheet import com.mifos.core.designsystem.component.MifosCircularProgress import com.mifos.core.designsystem.component.MifosDatePickerTextField import com.mifos.core.designsystem.component.MifosScaffold @@ -60,10 +64,10 @@ import java.util.Locale @Composable fun NewIndividualCollectionSheetScreen( viewModel: NewIndividualCollectionSheetViewModel = hiltViewModel(), - popupDialog: (IndividualCollectionSheet) -> Unit, - repaymentDate: (String) -> Unit + onDetail: (String, IndividualCollectionSheet) -> Unit ) { val state = viewModel.newIndividualCollectionSheetUiState.collectAsStateWithLifecycle().value + NewIndividualCollectionSheetScreen( state = state, getStaffList = { @@ -75,9 +79,8 @@ fun NewIndividualCollectionSheetScreen( transactionDate = _repaymentDate staffId = _staffId }) - repaymentDate(_repaymentDate) }, - popupDialog = popupDialog + onDetail = onDetail ) } @@ -87,7 +90,7 @@ fun NewIndividualCollectionSheetScreen( state: NewIndividualCollectionSheetUiState, getStaffList: (Int) -> Unit, generateCollection: (Int, Int, String) -> Unit, - popupDialog: (IndividualCollectionSheet) -> Unit + onDetail: (String, IndividualCollectionSheet) -> Unit ) { val keyboardController = LocalSoftwareKeyboardController.current @@ -98,6 +101,7 @@ fun NewIndividualCollectionSheetScreen( var staffId by rememberSaveable { mutableIntStateOf(0) } val snackbarHostState = remember { SnackbarHostState() } + var showCollectionSheetDialog by rememberSaveable { mutableStateOf(false) } var showDatePicker by rememberSaveable { mutableStateOf(false) } var repaymentDate by rememberSaveable { mutableLongStateOf(System.currentTimeMillis()) } @@ -109,6 +113,11 @@ fun NewIndividualCollectionSheetScreen( } } ) + var individualCollectionSheet by rememberSaveable { + mutableStateOf( + null + ) + } LaunchedEffect(key1 = state.error) { state.error?.let { snackbarHostState.showSnackbar(it) } @@ -116,14 +125,14 @@ fun NewIndividualCollectionSheetScreen( LaunchedEffect(key1 = state.individualCollectionSheet) { state.individualCollectionSheet?.let { - popupDialog(it) + individualCollectionSheet = it + showCollectionSheetDialog = true } } MifosScaffold( topBar = { }, - snackbarHostState = snackbarHostState, - bottomBar = { } + snackbarHostState = snackbarHostState ) { paddingValues -> if (showDatePicker) { DatePickerDialog( @@ -152,7 +161,33 @@ fun NewIndividualCollectionSheetScreen( DatePicker(state = datePickerState) } } - + if (showCollectionSheetDialog) { + MifosBottomSheet( + content = { + CollectionSheetDialogContent( + date = SimpleDateFormat("dd MMMM yyyy", Locale.getDefault()).format( + repaymentDate + ), + member = individualCollectionSheet?.clients?.size.toString(), + fillNow = { + showCollectionSheetDialog = false + individualCollectionSheet?.let { + onDetail( + SimpleDateFormat("dd MMMM yyyy", Locale.getDefault()).format( + repaymentDate + ), + it + ) + } + }, + onDismiss = { + showCollectionSheetDialog = false + }) + }, + onDismiss = { + showCollectionSheetDialog = false + }) + } if (state.isLoading) { MifosCircularProgress() } else { @@ -254,6 +289,7 @@ fun NewIndividualCollectionSheetScreen( selectedOffice = "" repaymentDate = System.currentTimeMillis() selectedStaff = "" + individualCollectionSheet = null }, modifier = Modifier .weight(1f) @@ -274,6 +310,101 @@ fun NewIndividualCollectionSheetScreen( } } +@Composable +fun CollectionSheetDialogContent( + date: String, + member: String, + fillNow: () -> Unit, + onDismiss: () -> Unit +) { + MifosBottomSheet(content = { + Column( + modifier = Modifier + .fillMaxWidth() + .padding(start = 15.dp, end = 16.dp, bottom = 16.dp) + ) { + Text( + modifier = Modifier + .fillMaxWidth() + .align(Alignment.CenterHorizontally), + text = stringResource(id = R.string.feature_collection_sheet_found_sheet), + style = TextStyle( + fontSize = 24.sp + ) + ) + Spacer(modifier = Modifier.height(16.dp)) + Text( + text = stringResource(id = R.string.feature_collection_sheet_fill_collection_sheet_message), + style = TextStyle( + fontSize = 16.sp + ) + ) + Spacer(modifier = Modifier.height(16.dp)) + Row { + Text( + text = stringResource(id = R.string.feature_collection_sheet_date), + style = TextStyle( + fontSize = 16.sp, + fontWeight = FontWeight.Bold + ) + ) + Spacer(modifier = Modifier.width(16.dp)) + Text( + text = date, + style = TextStyle( + fontSize = 16.sp, + fontWeight = FontWeight.Normal + ) + ) + } + + Row { + Text( + text = stringResource(id = R.string.feature_collection_sheet_member), + style = TextStyle( + fontSize = 16.sp, + fontWeight = FontWeight.Bold + ) + ) + Spacer(modifier = Modifier.width(16.dp)) + Text( + text = member, + style = TextStyle( + fontSize = 16.sp, + fontWeight = FontWeight.Normal + ) + ) + } + Spacer(modifier = Modifier.height(16.dp)) + Row(modifier = Modifier.fillMaxWidth(), horizontalArrangement = Arrangement.End) { + Button( + onClick = fillNow, + colors = ButtonDefaults.buttonColors( + containerColor = if (isSystemInDarkTheme()) BluePrimaryDark else BluePrimary + ) + ) { + Text( + text = stringResource(id = R.string.feature_collection_sheet_fill_now), + fontSize = 16.sp + ) + } + Spacer(modifier = Modifier.width(16.dp)) + Button( + onClick = onDismiss, + colors = ButtonDefaults.buttonColors( + containerColor = if (isSystemInDarkTheme()) BluePrimaryDark else BluePrimary + ) + ) { + Text( + text = stringResource(id = R.string.feature_collection_sheet_cancel), + fontSize = 16.sp + ) + } + } + } + }, onDismiss = onDismiss) +} + class NewIndividualCollectionSheetUiStateProvider : PreviewParameterProvider { @@ -297,7 +428,7 @@ private fun NewIndividualCollectionSheetPreview( getStaffList = {}, generateCollection = { _, _, _ -> }, - popupDialog = {} + onDetail = { _, _ -> } ) } @@ -307,4 +438,10 @@ val sampleStaffList = List(10) { val sampleOfficeList = List(10) { Office(name = "Name") +} + +@Preview +@Composable +private fun CollectionSheetDialogContentPreview() { + CollectionSheetDialogContent(date = "19 June 2024", member = "5", fillNow = {}, onDismiss = {}) } \ No newline at end of file diff --git a/feature/collection-sheet/src/main/res/values/strings.xml b/feature/collection-sheet/src/main/res/values/strings.xml index 37669aea858..40bf42371be 100644 --- a/feature/collection-sheet/src/main/res/values/strings.xml +++ b/feature/collection-sheet/src/main/res/values/strings.xml @@ -12,5 +12,11 @@ Cancel Please Select a Office Please Select a Staff + Individual Collection Sheet + Found Collection Sheet + You Can Save this Collection Sheet for Offline Use also. + Date: + Member: + Fill Now \ No newline at end of file diff --git a/mifosng-android/src/main/java/com/mifos/mifosxdroid/dialogfragments/collectionsheetdialog/CollectionSheetDialogFragment.kt b/mifosng-android/src/main/java/com/mifos/mifosxdroid/dialogfragments/collectionsheetdialog/CollectionSheetDialogFragment.kt deleted file mode 100644 index 523c02c2720..00000000000 --- a/mifosng-android/src/main/java/com/mifos/mifosxdroid/dialogfragments/collectionsheetdialog/CollectionSheetDialogFragment.kt +++ /dev/null @@ -1,74 +0,0 @@ -package com.mifos.mifosxdroid.dialogfragments.collectionsheetdialog - -import android.os.Bundle -import android.view.LayoutInflater -import android.view.View -import android.view.ViewGroup -import com.google.android.material.bottomsheet.BottomSheetDialogFragment -import com.mifos.mifosxdroid.databinding.FragmentCollectionSheetDialogBinding -import com.mifos.mifosxdroid.online.collectionsheetindividual.NewIndividualCollectionSheetFragment -import com.mifos.utils.Constants -import dagger.hilt.android.AndroidEntryPoint - -/** - * Created by aksh on 2/7/18. - */ -@AndroidEntryPoint -class CollectionSheetDialogFragment : BottomSheetDialogFragment() { - - private lateinit var binding: FragmentCollectionSheetDialogBinding - - private var date: String? = null - private var members = 0 - override fun onCreate(savedInstanceState: Bundle?) { - date = - requireArguments().getString(Constants.REPAYMENT_DATE) - members = requireArguments().getInt(Constants.MEMBERS) - super.onCreate(savedInstanceState) - } - - override fun onCreateView( - inflater: LayoutInflater, - container: ViewGroup?, - savedInstanceState: Bundle? - ): View { - binding = FragmentCollectionSheetDialogBinding.inflate(inflater, container, false) - return binding.root - } - - override fun onViewCreated(view: View, savedInstanceState: Bundle?) { - super.onViewCreated(view, savedInstanceState) - binding.btnFillnow.setOnClickListener { - setBtnFillNow() - } - binding.btnCancel.setOnClickListener { - setBtnCancel() - } - } - - override fun onActivityCreated(savedInstanceState: Bundle?) { - super.onActivityCreated(savedInstanceState) - binding.tvDueDate.text = date - binding.tvMembers.text = Integer.toString(members) - } - - private fun setBtnFillNow() { - (targetFragment as NewIndividualCollectionSheetFragment).getResponse(Constants.FILLNOW) - } - - - private fun setBtnCancel() { - dialog?.dismiss() - } - - companion object { - fun newInstance(date: String?, members: Int): CollectionSheetDialogFragment { - val collectionSheetDialogFragment = CollectionSheetDialogFragment() - val args = Bundle() - args.putString(Constants.REPAYMENT_DATE, date) - args.putInt(Constants.MEMBERS, members) - collectionSheetDialogFragment.arguments = args - return collectionSheetDialogFragment - } - } -} \ No newline at end of file diff --git a/mifosng-android/src/main/java/com/mifos/mifosxdroid/online/collectionsheetindividual/IndividualCollectionSheetFragment.kt b/mifosng-android/src/main/java/com/mifos/mifosxdroid/online/collectionsheetindividual/IndividualCollectionSheetFragment.kt index 694993e70ae..132205a0625 100644 --- a/mifosng-android/src/main/java/com/mifos/mifosxdroid/online/collectionsheetindividual/IndividualCollectionSheetFragment.kt +++ b/mifosng-android/src/main/java/com/mifos/mifosxdroid/online/collectionsheetindividual/IndividualCollectionSheetFragment.kt @@ -4,61 +4,49 @@ import android.os.Bundle import android.view.LayoutInflater import android.view.View import android.view.ViewGroup -import androidx.fragment.app.Fragment -import androidx.fragment.app.FragmentManager -import androidx.fragment.app.FragmentPagerAdapter -import androidx.viewpager.widget.ViewPager -import com.mifos.core.common.utils.Constants -import com.mifos.mifosxdroid.R +import androidx.compose.ui.platform.ComposeView +import androidx.compose.ui.platform.ViewCompositionStrategy +import androidx.navigation.fragment.findNavController +import com.mifos.core.objects.collectionsheet.IndividualCollectionSheet +import com.mifos.feature.individual_collection_sheet.individual_collection_sheet.ui.IndividualCollectionSheetScreen import com.mifos.mifosxdroid.core.MifosBaseFragment -import com.mifos.mifosxdroid.databinding.FragmentIndividualRecyclerBinding -import com.mifos.mifosxdroid.online.savedcollectionsheetindividual.SavedIndividualCollectionSheetFragment +import java.text.SimpleDateFormat +import java.util.Locale /** * Created by Tarun on 05-07-2017. */ class IndividualCollectionSheetFragment : MifosBaseFragment() { - private lateinit var binding: FragmentIndividualRecyclerBinding override fun onCreateView( inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle? ): View { - binding = FragmentIndividualRecyclerBinding.inflate(inflater, container, false) - setToolbarTitle(getStringMessage(R.string.individual_collection_sheet)) - setupViewPager(binding.viewpager) - binding.tabs.setupWithViewPager(binding.viewpager) - return binding.root - } - - private fun setupViewPager(viewPager: ViewPager?) { - val adapter = ViewPagerAdapter(requireActivity().supportFragmentManager) - adapter.addFragment(NewIndividualCollectionSheetFragment(), Constants.NEW) - adapter.addFragment(SavedIndividualCollectionSheetFragment(), Constants.SAVED) - viewPager?.adapter = adapter - } - - internal inner class ViewPagerAdapter(manager: FragmentManager?) : - FragmentPagerAdapter(manager!!) { - private val mFragmentList: MutableList = ArrayList() - private val mFragmentTitleList: MutableList = ArrayList() - override fun getItem(position: Int): Fragment { - return mFragmentList[position] - } - - override fun getCount(): Int { - return mFragmentList.size - } - - fun addFragment(fragment: Fragment, title: String) { - mFragmentList.add(fragment) - mFragmentTitleList.add(title) - } - - override fun getPageTitle(position: Int): CharSequence { - return mFragmentTitleList[position] + toolbar?.visibility = View.GONE + return ComposeView(requireContext()).apply { + setViewCompositionStrategy(ViewCompositionStrategy.DisposeOnViewTreeLifecycleDestroyed) + setContent { + IndividualCollectionSheetScreen(onBackPressed = { + requireActivity().onBackPressed() + }, onDetail = { repaymentDate, individualCollectionSheet -> + getIndividualCollectionSheetDetails(repaymentDate, individualCollectionSheet) + }) + } } } + private fun getIndividualCollectionSheetDetails( + repaymentDate: String, + individualCollectionSheet: IndividualCollectionSheet + ) { + val action = + IndividualCollectionSheetFragmentDirections.actionIndividualCollectionSheetFragmentToIndividualCollectionSheetDetailsFragment( + individualCollectionSheet, SimpleDateFormat( + "dd MMMM yyyy", + Locale.getDefault() + ).format(System.currentTimeMillis()), repaymentDate + ) + findNavController().navigate(action) + } } \ No newline at end of file diff --git a/mifosng-android/src/main/java/com/mifos/mifosxdroid/online/collectionsheetindividual/NewIndividualCollectionSheetFragment.kt b/mifosng-android/src/main/java/com/mifos/mifosxdroid/online/collectionsheetindividual/NewIndividualCollectionSheetFragment.kt deleted file mode 100644 index d5e104e6c34..00000000000 --- a/mifosng-android/src/main/java/com/mifos/mifosxdroid/online/collectionsheetindividual/NewIndividualCollectionSheetFragment.kt +++ /dev/null @@ -1,92 +0,0 @@ -package com.mifos.mifosxdroid.online.collectionsheetindividual - -import android.os.Bundle -import android.view.LayoutInflater -import android.view.View -import android.view.ViewGroup -import androidx.compose.ui.platform.ComposeView -import androidx.compose.ui.platform.ViewCompositionStrategy -import androidx.navigation.fragment.findNavController -import com.mifos.core.common.utils.Constants -import com.mifos.core.objects.collectionsheet.IndividualCollectionSheet -import com.mifos.feature.individual_collection_sheet.new_individual_collection_sheet.ui.NewIndividualCollectionSheetScreen -import com.mifos.mifosxdroid.core.MifosBaseFragment -import com.mifos.mifosxdroid.dialogfragments.collectionsheetdialog.CollectionSheetDialogFragment -import com.mifos.utils.FragmentConstants -import dagger.hilt.android.AndroidEntryPoint -import java.text.SimpleDateFormat -import java.util.Locale - - -/** - * Created by aksh on 18/6/18. - */ -@AndroidEntryPoint -class NewIndividualCollectionSheetFragment : MifosBaseFragment() { - - private var sheet: IndividualCollectionSheet? = null - private lateinit var repaymentDate: String - - override fun onCreate(savedInstanceState: Bundle?) { - super.onCreate(savedInstanceState) - if (savedInstanceState != null) { - sheet = - savedInstanceState[Constants.EXTRA_COLLECTION_INDIVIDUAL] as IndividualCollectionSheet - } - } - - override fun onCreateView( - inflater: LayoutInflater, container: ViewGroup?, - savedInstanceState: Bundle? - ): View { - return ComposeView(requireContext()).apply { - setViewCompositionStrategy( - ViewCompositionStrategy.DisposeOnViewTreeLifecycleDestroyed - ) - setContent { - NewIndividualCollectionSheetScreen(popupDialog = { - popupDialog(it) - }, repaymentDate = { - repaymentDate = it - }) - } - } - } - - private fun popupDialog(individualCollectionSheet: IndividualCollectionSheet) { - sheet = individualCollectionSheet - val collectionSheetDialogFragment = CollectionSheetDialogFragment.newInstance( - repaymentDate, - sheet?.clients?.size ?: 0 - ) - collectionSheetDialogFragment.setTargetFragment(this, 1) - val fragmentTransaction = requireActivity().supportFragmentManager - .beginTransaction() - fragmentTransaction.addToBackStack(FragmentConstants.FRAG_DOCUMENT_LIST) - collectionSheetDialogFragment.show(fragmentTransaction, "Identifier Dialog Fragment") - } - - fun getResponse(response: String) { - when (response) { - Constants.FILLNOW -> { - val action = sheet?.let { - NewIndividualCollectionSheetFragmentDirections.actionNewIndividualCollectionSheetFragmentToIndividualCollectionSheetDetailsFragment( - it, SimpleDateFormat( - "dd MMMM yyyy", - Locale.getDefault() - ).format(System.currentTimeMillis()), repaymentDate - ) - } - action?.let { findNavController().navigate(it) } - } - } - } - - override fun onSaveInstanceState(outState: Bundle) { - super.onSaveInstanceState(outState) - outState.putParcelable( - Constants.EXTRA_COLLECTION_INDIVIDUAL, - sheet - ) - } -} \ No newline at end of file diff --git a/mifosng-android/src/main/res/navigation/nav_graph.xml b/mifosng-android/src/main/res/navigation/nav_graph.xml index 15a077e45fc..07f09b463d3 100644 --- a/mifosng-android/src/main/res/navigation/nav_graph.xml +++ b/mifosng-android/src/main/res/navigation/nav_graph.xml @@ -407,7 +407,13 @@ + android:label="IndividualCollectionSheetFragment"> + + + + + android:label="GroupDetailsFragment"> @@ -492,7 +498,7 @@ + android:label="GroupLoanAccountFragment"> @@ -500,7 +506,7 @@ + android:label="ClientListFragment"> @@ -514,7 +520,7 @@ + android:label="CreateNewClientFragment"> @@ -522,7 +528,7 @@ + android:label="CenterDetailsFragment"> @@ -537,7 +543,7 @@ android:id="@+id/groupListFragment" android:name="com.mifos.mifosxdroid.online.grouplist.GroupListFragment" android:label="fragment_group_list" - tools:layout="@layout/fragment_group_list" > + tools:layout="@layout/fragment_group_list"> @@ -548,7 +554,7 @@ + android:label="ClientActivity"> @@ -556,7 +562,7 @@ + android:label="IndividualCollectionSheetDetailsFragment"> @@ -570,18 +576,10 @@ android:id="@+id/action_individualCollectionSheetDetailsFragment_to_paymentDetailsFragment" app:destination="@id/paymentDetailsFragment" /> - - - + android:label="PaymentDetailsFragment">