-
Notifications
You must be signed in to change notification settings - Fork 16
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
FEAT: added alarm and timer export and import functionality #53
Conversation
Hey, So this is fully working and tested, it does export the alarms and import them correctly. I tried debugging this a little but I am not very good it this, here is what I tested:
I am guessing this has to do with main vs background threat or both activities are not using the same instant of the DBHelper. Any help would be appreciated. |
I'll take a look at this later but in the future, please create a discussion or feature request first (because we may not want to implement everything that is suggested):
|
@naveensingh I am sorry, I did read the contribution guidelines or I would not have ticked it, but I just have missed that part and I am sorry for that. I do change ROMs a lot and every time I have to setup all my alarms again (I have many) and this was a feature I really needed so hopefully you will consider it :-) |
I moved the export and import to the settings and removed them from the menu, the exporter now exports both alarms and timers, the import is broken now, will fix it soon. |
@naveensingh This might not be a priority, but I did complete this PR, now timers and alarms are exported and imported together and I have done my best to handle errors especially while importing, your review of this when you have time is greatly appreciated :-) |
We should keep consistent behavior, looks and naming between all the apps. Also, where it's possible, we should use strings defined in Commons. |
@Aga-C I fixed all of the above. For the space, I had put a subtitle but it was not showing when building, so I just removed it and now there is no space. I did not completely understand point 4, I did remove the toast messages for aborting, I just don't know what "pressing back on save" means. I am sorry for the inconveniences, next time I will make sure a string is available in the commons or that it is consistent with the other apps. BTW, alarms and timers are populated correctly in the app now when imported, no need to restart the app to see them. |
It seems to work fine, but there are two edge cases where it behaves strange. First issue - duplicating alarmsWhen you import the same alarms and timers as you currently have in the app, the import:
I think the behavior should be consistent in both tabs, either with duplicating or not. IMO, we shouldn't duplicate at all. Second issue - overwriting timersDuplicate checking in Timers while import shouldn't remove already edited timers. I did something like this:
Instead of creating a new entry with old data, it has overwritten the current entry. I assume you check it only by ID (I haven't checked the code, just testing from the user perspective), because when I created another timer with exactly the same name, time and sound, it hasn't overwritten it. |
I will test this tomorrow and see what is going on. I hadn't thought about duplicates tbh, thank you for testing. |
Ok, for the first problem, I think I got what the issue is, not very sure how to fix it yet. first, I was not backing up the isEnabled state, and was always setting it to false, this made a problem in comparing to see the if the values of insertAlarm are generated here
What do you suggest we do about this? Make an insertFromBackup function in DBHelper? For the second issue, I think this is causing it
EDIT: I have forgotten to push the latest changes where I am checking if the entries are in the database already or not. |
But if you will consider ID in alarm data, you will probably have the same issue in alarms as there's now in timers. I think it should be manually checked if an entry with the same fields already exists. People won't have an enormous amount of alarms, so it shouldn't be slow. |
I already fixed the alarms by comparing every entry but the ID. Same did not work for the timers, as the |
Ok so, it all is working now. for the timers, I am comparing all entries but the ID, and if it does not exist, I am updating the ID of the inserted timers with I am not sure if this is the best approach, so I will await your comments. |
In timers, if you export two entries with the same name (but different time), only one of them is imported. You can test on a JSON I've exported: Also, I've found another problem - if you have empty timers list, there's an exception and nothing gets imported. |
@Aga-C fixed, the problem was that I was inserting new alarms with the id set to last timer in the list + 1, so now I am just making sure to set the id to 1 if no timers are available. |
It seems to be working fine. The only thing that bothers me is that whenever there are duplicates, it says In Calendar, it works like this:
|
I agree, will update soon. |
and it is done. |
Fixes #105. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hey @ronniedroid! I’ve suggested some changes that you might want to work on if you are still around. If not, I’ll address them myself later.
app/src/main/kotlin/org/fossify/clock/dialogs/ExportDataDialog.kt
Outdated
Show resolved
Hide resolved
Hey @naveensingh I am sorry, I would have applied the changes myself but can't as I don't have much time at hand, and my current PC is very underpowered for android Studio 😅 |
No worries, I'll do it. |
- Replaced manual serialization/deserialization with kotlin serialization - Removed unnecessary intent creation - Fixed import/export with SAF on Android 8 & 9 (storage permission was being requested but was never added to the manifest)
User pressing back is not an error.
val alarms = dbHelper.getAlarms()
val timers = timerDb.getTimers()
if (alarms.isEmpty()) {
toast(org.fossify.commons.R.string.no_entries_for_exporting)
} else ... It doesn't export timers when there are no alarms, is it intended or an oversight? EDIT: I fixed it. |
Timers alone couldn't be exported before.
Thanks, both of you! |
What is it?
Description of the changes in your PR
toJson()
method to the Alarm and Timer modelsAcknowledgement