Comments (8)
Ahhhh that makes sense. I might write a really simple Pair implementation that is mutable to make the fix more readable. Thanks for explaining that haha
from sobriety.
Closing now because a solution has been found, thanks so much ^^
from sobriety.
Honestly what even could cause this? A spontaneous bug affecting all versions that was definitely not there before just isn't possible.
from sobriety.
The problem seems to be in line 129 in Main.kt:
date = Instant.now()
This creates a new Instant with the correct current date. date
then points to this new Instant, but the Instant in the HashMap is never updated. This date
reference is also used to update the displayed text, which is why everything appears to be working as expected.
In the previous versions this could be fixed, by updating addictions[name]
directly, instead of the local variable date
. In the current version, where addiction is a HashMap of a String and a Pair, the equivalent would be updating it via
addictions[key].first = Instant.now()
however Pair is immutable, thats why my current workaround is constructing a new Pair using the updated date and the old Buffer like so:
addictions[key] = Pair(Instant.now(), addictions[key]!!.second)
Im sure there is a cleaner way to do it but this seems to work
from sobriety.
I was confused about this as well at first๐ This stackoverflow answer explains it very nice in detail. Just like Java, Kotlin is pass-by-value, e.g. it passes a copy of a reference to a method, so reassigning this copy to a new object does not change the original.
from sobriety.
I might write a really simple Pair implementation that is mutable
Maybe its a better idea, to just create a serializable class "Addiction", with fields name, date, buffer etc. and save that as an ArrayList, then createNewCard
could take an Addiction object as input, and simply modify the fields of this object.
This would also make it easier to add new fields later on, (e.g. total money / time saved?), because you wouldnt need to continue stacking Pairs into Pairs
from sobriety.
Ahaha I feel so stupid now. I wrote it the way I did at first because I thought Kotlin was PBR but thanks for explaining that.
from sobriety.
And yeah that's a good idea
from sobriety.
Related Issues (20)
- Savings dashboard : overview of total saved units HOT 1
- Cant reset the tracker at the bottom of the list HOT 2
- Provide Option to Turn off Hours,Minutes & Seconds. With Only Years ,Months and Days !! HOT 4
- Reset to a specific date HOT 1
- link to the github repository HOT 1
- Change to neutral background Color HOT 1
- UI suggestions HOT 3
- Recent Average is inaccurate for the first few relapses HOT 1
- Add About section to settings HOT 1
- 8.0.0 update crashes on open HOT 3
- App crashes Immediately after v8.0.0 update HOT 13
- Reimplement average relapse duration HOT 1
- date_format setting does not apply to stopped addictions
- Average calculator in timeline does not show last attempt on stopped addictions
- Cleanup of Addiction class HOT 1
- Use third-party service to manage translations HOT 4
- Allow multiple notes per day
- Bug: Miscalculation by one day HOT 3
- Counter widget HOT 2
- Bad time passed calculation when <24 hours HOT 8
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. ๐๐๐
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google โค๏ธ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from sobriety.