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#1182 #1190

Merged
merged 1 commit into from
Feb 9, 2022
Merged
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 @@ -105,17 +105,8 @@ class SIDetailsActivity : BaseActivity(), StandingInstructionContract.SIDetailsV
mStandingInstructionPresenter.updateStandingInstruction(this.standingInstruction)
}
} else {
doSave = true
fab.hide()
fab.setImageDrawable(res.getDrawable(R.drawable.ic_save))

tv_si_amount.visibility = View.GONE
til_si_edit_amount.visibility = View.VISIBLE

tv_edit_pick.visibility = View.VISIBLE

tv_recurrence_interval.visibility = View.GONE
til_si_edit_interval.visibility = View.VISIBLE
editDetails(true);
}
}

Expand Down Expand Up @@ -259,6 +250,9 @@ class SIDetailsActivity : BaseActivity(), StandingInstructionContract.SIDetailsV
override fun onBackPressed() {
if (isDataSaveNecessary()) {
showDiscardChangesDialog()
} else if (!isDataSaveNecessary() && fab.isOrWillBeHidden) {
editDetails(false)
fab.show()
} else {
super.onBackPressed()
}
Expand All @@ -267,13 +261,51 @@ class SIDetailsActivity : BaseActivity(), StandingInstructionContract.SIDetailsV
private fun showDiscardChangesDialog() {
val dialogBox = DialogBox()
dialogBox.setOnPositiveListener { dialog, which ->
fab.hide()
dialog.dismiss()
finish()
editDetails(false)
revertLocalChanges()
fab.show()
}
dialogBox.setOnNegativeListener { dialog, which ->
dialog.dismiss()
}
dialogBox.show(this, R.string.discard_changes_and_exit,
R.string.discard_and_exit, R.string.accept, R.string.cancel)
}

private fun editDetails(doEdit : Boolean) {
if (doEdit) {
doSave = true

fab.setImageDrawable(res.getDrawable(R.drawable.ic_save))

tv_si_amount.visibility = View.GONE
til_si_edit_amount.visibility = View.VISIBLE

tv_edit_pick.visibility = View.VISIBLE

tv_recurrence_interval.visibility = View.GONE
til_si_edit_interval.visibility = View.VISIBLE
} else {
doSave = false

fab.setImageDrawable(res.getDrawable(R.drawable.ic_edit))

tv_si_amount.visibility = View.VISIBLE
til_si_edit_amount.visibility = View.GONE

tv_edit_pick.visibility = View.GONE

tv_recurrence_interval.visibility = View.VISIBLE
til_si_edit_interval.visibility = View.GONE
}
}

private fun revertLocalChanges() {
et_si_edit_amount.setText(this.standingInstruction.amount.toString());
et_si_edit_interval.setText(this.standingInstruction.recurrenceInterval.toString());
tv_valid_till.setText("${standingInstruction.validTill?.get(2)}-" +
"${standingInstruction.validTill?.get(1)}-${standingInstruction.validTill?.get(0)}")
}
}