Skip to content

Commit

Permalink
Fix#1182
Browse files Browse the repository at this point in the history
  • Loading branch information
EGOR-IND committed Jan 29, 2021
1 parent 58f53b9 commit 3b0c819
Showing 1 changed file with 43 additions and 11 deletions.
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)}")
}
}

0 comments on commit 3b0c819

Please sign in to comment.