Skip to content

Commit

Permalink
Merge pull request #1190 from EGOR-IND/Fix#1182
Browse files Browse the repository at this point in the history
Fix#1182
  • Loading branch information
devansh-299 authored Feb 9, 2022
2 parents 81e448d + ba8cdb4 commit b5df833
Showing 1 changed file with 43 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -106,17 +106,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 @@ -267,6 +258,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 @@ -290,13 +284,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)}")
}
}

0 comments on commit b5df833

Please sign in to comment.