Skip to content
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

fix: Improve clarity and correctness in showFilterDialog #2465

Closed
wants to merge 1 commit into from
Closed
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
Expand Up @@ -27,6 +27,7 @@ import dagger.hilt.android.AndroidEntryPoint
import kotlinx.coroutines.launch
import org.mifos.mobile.R
import org.mifos.mobile.databinding.FragmentSavingAccountTransactionsBinding
import org.mifos.mobile.databinding.LayoutFilterDialogBinding
import org.mifos.mobile.models.CheckboxStatus
import org.mifos.mobile.models.accounts.savings.SavingsWithAssociations
import org.mifos.mobile.models.accounts.savings.Transactions
Expand Down Expand Up @@ -298,84 +299,70 @@ class SavingAccountsTransactionFragment : BaseFragment() {
/**
* Shows a filter dialog
*/
private lateinit var filterBinding: LayoutFilterDialogBinding
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

make this global and change the name of variable to layoutFilterDialogBinding

Copy link
Author

@ghost ghost Jan 2, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okay...needed to change the first letter to Lowercase..?

private fun showFilterDialog() {
val inflater = activity?.layoutInflater
val dialogView = inflater?.inflate(R.layout.layout_filter_dialog, null, false)
val checkBoxPeriod: AppCompatCheckBox? = dialogView?.findViewById(R.id.cb_select)
val radioGroupFilter = dialogView?.findViewById<RadioGroup>(R.id.rg_date_filter)
tvStartDate = dialogView?.findViewById(R.id.tv_start_date)
tvEndDate = dialogView?.findViewById(R.id.tv_end_date)
filterBinding = LayoutFilterDialogBinding.inflate(layoutInflater)
val dialogView = filterBinding.root

val checkBoxPeriod: AppCompatCheckBox? = filterBinding.cbSelect
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

do we need to explicitly declare AppCompatCheckBox ?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nope ig...should i remove it..?

val radioGroupFilter = filterBinding.rgDateFilter
tvStartDate = filterBinding.tvStartDate
tvEndDate = filterBinding.tvEndDate
tvStartDate?.isEnabled = false
tvEndDate?.isEnabled = false

tvStartDate?.text = DateHelper.getDateAsStringFromLong(startDate)
tvEndDate?.text = DateHelper.getDateAsStringFromLong(endDate)
// setup listeners

tvStartDate?.setOnClickListener { startDatePick() }
tvEndDate?.setOnClickListener { endDatePick() }
checkBoxPeriod?.setOnClickListener {
checkBoxPeriod.isChecked = (!checkBoxPeriod.isChecked)
}

checkBoxPeriod?.setOnCheckedChangeListener { _, isChecked ->
isCheckBoxPeriod = isChecked
tvStartDate?.isEnabled = isChecked
tvEndDate?.isEnabled = false

if (!isChecked) {
isReady = false
radioGroupFilter?.clearCheck()
filterBinding.rgDateFilter.clearCheck()
selectedRadioButtonId = -1
} else {
if (selectedRadioButtonId == -1) {
val btn = dialogView.findViewById<RadioButton>(R.id.rb_date)
val btn = filterBinding.rbDate
btn.isChecked = true
}
}
}
radioGroupFilter?.setOnCheckedChangeListener { radioGroup, _ ->
radioGroupFilter?.setOnCheckedChangeListener { _, checkedId ->
isCheckBoxPeriod = true
selectedRadioButtonId = radioGroup.checkedRadioButtonId
when (radioGroup.checkedRadioButtonId) {
R.id.rb_four_weeks -> {
tvStartDate?.isEnabled = false
tvEndDate?.isEnabled = false
startDate = DateHelper.subtractWeeks(4)
endDate = System.currentTimeMillis()
isReady = true
}

R.id.rb_three_months -> {
selectedRadioButtonId = checkedId
when (checkedId) {
R.id.rb_four_weeks, R.id.rb_three_months, R.id.rb_six_months -> {
tvStartDate?.isEnabled = false
tvEndDate?.isEnabled = false
startDate = DateHelper.subtractMonths(3)
endDate = System.currentTimeMillis()
isReady = true
}

R.id.rb_six_months -> {
tvStartDate?.isEnabled = false
tvEndDate?.isEnabled = false
startDate = DateHelper.subtractMonths(6)
startDate = when (checkedId) {
R.id.rb_four_weeks -> DateHelper.subtractWeeks(4)
R.id.rb_three_months -> DateHelper.subtractMonths(3)
R.id.rb_six_months -> DateHelper.subtractMonths(6)
else -> startDate
}
endDate = System.currentTimeMillis()
isReady = true
}

R.id.rb_date -> {
tvStartDate?.isEnabled = true
tvEndDate?.isEnabled = false
}
}
}

// restore prev state
checkBoxPeriod?.isChecked = isCheckBoxPeriod
if (selectedRadioButtonId != -1) {
val btn = dialogView?.findViewById<RadioButton>(selectedRadioButtonId)
btn?.isChecked = true
}
val checkBoxRecyclerView: RecyclerView? = dialogView?.findViewById(R.id.recycler_view)
val layoutManager = LinearLayoutManager(activity)
val checkBoxRecyclerView: RecyclerView? = filterBinding.recyclerView
val layoutManager = LinearLayoutManager(requireContext())
layoutManager.orientation = LinearLayoutManager.VERTICAL
checkBoxRecyclerView?.layoutManager = layoutManager
checkBoxRecyclerView?.adapter = checkBoxAdapter
checkBoxAdapter?.statusList = statusList

MaterialAlertDialogBuilder(requireContext())
.setTitle(R.string.select_you_want)
.setView(dialogView)
Expand Down
55 changes: 32 additions & 23 deletions app/src/main/res/layout/fragment_saving_account_transactions.xml
Original file line number Diff line number Diff line change
Expand Up @@ -8,37 +8,46 @@
android:id="@+id/ll_account"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:visibility="visible">
android:orientation="vertical">

<androidx.recyclerview.widget.RecyclerView
android:id="@+id/rv_saving_accounts_transaction"
android:layout_width="match_parent"
android:layout_height="@dimen/height_0dp"
android:layout_height="0dp"
android:layout_weight="1" />

<LinearLayout
<TextView
android:id="@+id/tvEmptyView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:padding="@dimen/Mifos.DesignSystem.Spacing.CardInnerPadding">

<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/need_help" />

<TextView
android:id="@+id/tv_help_line_number"
style="@style/Mifos.DesignSystem.TextStyle.Link"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="@dimen/Mifos.DesignSystem.Spacing.marginWords"
android:clickable="true"
android:focusable="true"
android:text="@string/help_line_number" />

</LinearLayout>
android:gravity="center"
android:text="@string/no_transaction"
android:visibility="gone" />

</LinearLayout>

<LinearLayout
android:id="@+id/ll_contact_us"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:orientation="horizontal"
android:padding="@dimen/Mifos.DesignSystem.Spacing.CardInnerPadding">

<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/need_help" />

<TextView
android:id="@+id/tv_help_line_number"
style="@style/Mifos.DesignSystem.TextStyle.Link"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="@dimen/Mifos.DesignSystem.Spacing.marginWords"
android:clickable="true"
android:focusable="true"
android:text="@string/help_line_number" />

</LinearLayout>

Expand Down
Loading