Urgent.News

What's breaking now, across hundreds of outlets.

Tech

Designing a Cost-Per-Use Tracker for Android: Calculations, State and Data Integrity

Most personal finance applications focus on transactions. You buy something, record the amount, assign a category, and move on. But what if the interesting part of a purchase begins after the transaction? Consider a pair of shoes, a laptop, or a power tool. The purchase price is fixed, but its practical value changes as the item is used, repaired, returned, or eventually sold. At TSI Dev Studio,…

Designing a cost-per-use tracker for Android involves careful consideration of several factors related to calculations, state management, data integrity, and user experience. The HEZX application demonstrates how to approach these challenges in a robust way.

The first key point is that a cost-per-use tracker requires a more complex model than a traditional expense tracker. An item needs to store its original purchase price, currency, purchase date, warranty periods, usage count, repair costs, confirmed refunds, resale proceeds, and a history of relevant events. Storing values in minor currency units can help avoid floating-point rounding errors, but it's important to respect each currency's precision rules.

The cost per use calculation is simple - purchase price divided by recorded usage. However, before the first use is recorded, dividing by zero is invalid and misleading. Instead, the result should be represented as unavailable until the usage count is positive. The code example shows how to implement this in Kotlin using null values.

Tracking uses requires an undo feature to allow accidental corrections. But the undo operation must be carefully implemented to ensure it reverses the intended operation. This requires using identifiers or transaction history to track the sequence of events.

Net ownership cost is another important metric, calculated as purchase price plus repair costs minus confirmed refunds minus resale proceeds. This calculation needs to handle uncertainties like incomplete refunds or unsold items. The key is to separate intentions and estimates from completed financial events.

Throughout the design process, it's crucial to clearly define the semantics of each value and operation. The code examples provide general implementation approaches rather than HEZX's specific source code. The overall goal is to create a reliable tracker that communicates uncertainties clearly to users and maintains data integrity.

Rewritten by urgent.news; may contain errors — check the original.

Read the original at dev.to →

Report a problem with this story

More in Tech

CVE-2025-42884 remediation without overstating the evidence

CVE-2025-42884 remediation without overstating the evidence Known exploitation is enough to raise priority, but it is not a substitute for evidence about this vulnerability.

  • CVE-2025-42884 vulnerability affects SAP NetWeaver EP-BASIS and EP-RUNTIME versions 7.50.
  • Unauthenticated attacker can inject JNDI properties/URLs, but exploit chain not confirmed.
  • Remediation involves SAP Security Note 3660969, configuration validation, and system restart.

More from Saturday 21 November →