Skip to content

Commit

Permalink
Safe guard if context menu info is not set seen on Xiaomi Mi 10T Andr…
Browse files Browse the repository at this point in the history
…oid 12
  • Loading branch information
mtotschnig committed Nov 17, 2024
1 parent 017ef5c commit 84cf035
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -621,7 +621,8 @@ open class ExpenseEdit : AmountActivity<TransactionEditViewModel>(), ContribIFac
}

override fun onContextItemSelected(item: MenuItem): Boolean {
val info = item.menuInfo as ContextAwareRecyclerView.RecyclerContextMenuInfo
val info = item.menuInfo as? ContextAwareRecyclerView.RecyclerContextMenuInfo
?: return super.onContextItemSelected(item)
return when (item.itemId) {
R.id.EDIT_COMMAND -> {
startActivityForResult(Intent(this, ExpenseEdit::class.java).apply {
Expand Down Expand Up @@ -1430,8 +1431,12 @@ open class ExpenseEdit : AmountActivity<TransactionEditViewModel>(), ContribIFac
if (!isSplitPartOrTemplate) {
val criterionInfos = listOfNotNull(
currentAccount!!.run {
val previousAmount = with(delegate) { passedInAmount?.takeIf { passedInAccountId == id } ?: 0 }
val previousTransferAmount = (delegate as? TransferDelegate)?.run { passedInTransferAmount?.takeIf { passedInTransferAccountId == id } } ?: 0
val previousAmount = with(delegate) {
passedInAmount?.takeIf { passedInAccountId == id } ?: 0
}
val previousTransferAmount =
(delegate as? TransferDelegate)?.run { passedInTransferAmount?.takeIf { passedInTransferAccountId == id } }
?: 0
criterion?.let {
CriterionInfo(
id,
Expand All @@ -1448,9 +1453,12 @@ open class ExpenseEdit : AmountActivity<TransactionEditViewModel>(), ContribIFac
transferAccount?.run {
val transaction = transaction as Transfer
val delegate = delegate as TransferDelegate
val previousAmount = with(delegate) { passedInAmount?.takeIf { passedInAccountId == id } ?: 0 }
val previousTransferAmount = with(delegate) { passedInTransferAmount?.takeIf { passedInTransferAccountId == id } }
?: 0
val previousAmount = with(delegate) {
passedInAmount?.takeIf { passedInAccountId == id } ?: 0
}
val previousTransferAmount =
with(delegate) { passedInTransferAmount?.takeIf { passedInTransferAccountId == id } }
?: 0
criterion?.let {
CriterionInfo(
id,
Expand All @@ -1465,19 +1473,23 @@ open class ExpenseEdit : AmountActivity<TransactionEditViewModel>(), ContribIFac
}
}?.takeIf { it.hasReached() }
)
when(criterionInfos.size) {
when (criterionInfos.size) {
//if a transfer leads to a credit limit and a saving goal being hit at the same time
//in two different accounts, we give a priority to the credit limit and show saving goal in toast
2 -> criterionInfos.first { it.criterion < 0}
2 -> criterionInfos.first { it.criterion < 0 }
1 -> criterionInfos.first()
else -> null
}?.let {
CriterionReachedDialogFragment
.newInstance(it,
if (criterionInfos.size == 2) with(criterionInfos.first { it.criterion > 0 }) { accountLabel + ": " + getString(dialogTitle) } else null
if (criterionInfos.size == 2) with(criterionInfos.first { it.criterion > 0 }) {
accountLabel + ": " + getString(
dialogTitle
)
} else null
)
.show(supportFragmentManager, "CRITERION")
if(!createNew) return
if (!createNew) return
}
}
if (createNew) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -263,7 +263,8 @@ class RoadmapVoteActivity : ProtectedFragmentActivity(), OnDialogResultListener
}

override fun onContextItemSelected(item: MenuItem): Boolean {
val info = item.menuInfo as RecyclerContextMenuInfo
val info = item.menuInfo as? RecyclerContextMenuInfo
?: return super.onContextItemSelected(item)
val itemId = item.itemId
if (itemId == R.id.ROADMAP_DETAILS_COMMAND) {
startActionView("https://github.com/mtotschnig/MyExpenses/issues/" + info.id)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,10 @@ import org.totschnig.myexpenses.provider.DatabaseConstants.KEY_ACCOUNTID
import org.totschnig.myexpenses.provider.DatabaseConstants.KEY_COLOR
import org.totschnig.myexpenses.provider.DatabaseConstants.KEY_LABEL
import org.totschnig.myexpenses.provider.filter.KEY_SELECTION
import org.totschnig.myexpenses.ui.ContextAwareRecyclerView
import org.totschnig.myexpenses.ui.ContextAwareRecyclerView.RecyclerContextMenuInfo
import org.totschnig.myexpenses.util.ui.setColor
import org.totschnig.myexpenses.viewmodel.TagBaseViewModel.Companion.KEY_DELETED_IDS
import org.totschnig.myexpenses.viewmodel.TagListViewModel
import org.totschnig.myexpenses.viewmodel.TagListViewModel.Companion.KEY_SELECTED_IDS
import org.totschnig.myexpenses.viewmodel.data.Tag

class TagList : Fragment(), OnDialogResultListener {
Expand Down Expand Up @@ -84,9 +83,9 @@ class TagList : Fragment(), OnDialogResultListener {
}

override fun onContextItemSelected(item: MenuItem): Boolean {
val tag = adapter.getItem(
(item.menuInfo as ContextAwareRecyclerView.RecyclerContextMenuInfo).position
)
val info = item.menuInfo as? RecyclerContextMenuInfo
?: return super.onContextItemSelected(item)
val tag = adapter.getItem(info.position)
return when (item.itemId) {
R.id.DELETE_COMMAND -> {
SimpleDialog.build()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ class ContextAwareRecyclerView : RecyclerView {
constructor(context: Context, attrs: AttributeSet?, defStyle: Int) :
super(context, attrs, defStyle)

override fun getContextMenuInfo(): RecyclerContextMenuInfo {
return contextMenuInfo!!
override fun getContextMenuInfo(): RecyclerContextMenuInfo? {
return contextMenuInfo
}

override fun showContextMenuForChild(originalView: View): Boolean {
Expand Down

0 comments on commit 84cf035

Please sign in to comment.