chickendude / Natibo

Breathe new life into your Glossika PDF/MP3 courses!
The Unlicense
26 stars 3 forks source link

Export progress #29

Open jubalh opened 5 years ago

jubalh commented 5 years ago

I think it would be nice to export/backup once progress to a file. Useful when one buys a new phone (or resetted his progress by accident like it happened before https://github.com/chickendude/Natibo/pull/28 :-)

chickendude commented 5 years ago

That should be possible, though should it back up everything (mp3s and all) or just the database? If we just back up the database, there would be issues if you don't reinstall all the same language packs when loading the backup.

jubalh commented 5 years ago

I just build the apk again from another computer, for some reason it installs it as a second app, like it would if I would have changed the app id. But I specifically didn't do that. I'm not sure what is behind this Android magic yet and clearly have not understood the mechanism.

But it makes me think again, that exporting/importing would be great. Then I could just export from the old installation and import in the new and thus preserving my reps (I find them highly motivating).

So actually for me it wouldn't matter much whether we would just export the database or everything. Both would make debugging easier for me and I wouldn't have to leave my progress track behind :-) If it's a lot work to export the mp3s/texts too then only the DB is totally ok for me, because I could just import the gls again.

Or maybe having a checkbox which asks whether the data (mp3/text) or the progess only should be exported.

chickendude commented 5 years ago

That's because of the last pull request to add a debug version, so the production version and debug version will have different package names. If you build a release version (rather than debug) it'll install with the original apk name.

For now, it's too much effort to support changes to the database, however when the app has reached a release candidate state we'll start providing migration rules whenever a change to the database is made (which shouldn't be that often). This way your data won't get deleted from one build to the next. For now, you'll only lose your data if there have been changes to the database structure, if you want to ensure your data isn't being overwritten, make sure the deleteRealmIfMigrationNeeded() line is commented out (here). The app will crash if the database has changed and you haven't made the necessary migration, but your data will still be there so you can add the migration.

jubalh commented 5 years ago

That's because of the last pull request to add a debug version, so the production version and debug version will have different package names.

No, that's not the case. https://github.com/chickendude/Natibo/pull/28 is not the reason. I have this enabled if I want to build the testing-playing-around app. But I removed that change when I saw that everything works fine and wanted to update the version of the app that I use. So I have the app installed two times, with two different IDs.

But for some reason when I built the apk on another computer it installed it a third time. I assume that it's not just the app ID that matters but also some kind of hash or certificate. Probably something like this is the difference and caused the app to be installed a third time.

What would be an easy way to just insert the current reps into the DB myself? I could just add a temporary statement in the app that sets the reps to 42 (for example) and sais it should start playing the sentence at 30 (for example). As I understand it that would be all I need to have the app behave like before.

chickendude commented 5 years ago

Hmm, that is weird, i'll check it out when i get home, i don't think i've seen that issue. Could you try running something like adb shell dumpsys package | grep "Package \\[ch.ralena.natibo" and seeing how many packages there are? Sharing the package info for the (multiple?) debug packages should shed some light on the issue (e.g. adb shell dumpsys package ch.ralena.natibo.debug, in particular the "Packages:" section) . It shouldn't let you install two apps with the same package name...

However, you currently can set which sentence you want to start on from the course options page, it won't give you the previous days' reviews, but you can skip ahead (or back) if you want, i added that in precisely for the same reason, so i could quickly go back to where i was after losing my data in each new version.

jubalh commented 5 years ago

However, you currently can set which sentence you want to start on from the course options page, it won't give you the previous days' reviews, but you can skip ahead (or back) if you want, i added that in precisely for the same reason, so i could quickly go back to where i was after losing my data in each new version.

So I found since I loose my total rep counts I'm less motivated to continue studying. So I would like to change this and have the ability to insert my total number of reps.

I thought about just temporary adding a code line in a constructor that sets the total reps to my last result by hand, then commenting that line out again and relaunching the app to have it start form there. And doing this every time there is a release that might loose the data. I'm not yet too familiar with the codebase, maybe you can help me here.

I did a quick test and set totalReps at https://github.com/chickendude/Natibo/blob/master/app/src/main/java/ch/ralena/natibo/object/Course.java#L244 to 300 as a test value. And when I relaunched the app it also displayed 300, I then did a few reps (7) and closed the course. Then restored the original code line and relaunched the app, but I was not at 307 :/

Maybe I manipulated the wrong variable or I didn't get to a point where it's saved? Hope you can help me here :-)

chickendude commented 5 years ago

The getTotalReps method doesn't change any values, that's just used for displaying how many reps have been done.

As we're using Realm to manage the database stuff, you can't actually write to an object that is in the database outside of what's called a Realm transaction, the best place to add the 300 reps would probably be in the prepareNextDay() method here. I'd do something like this:

realm.executeTransaction(r -> {
    if (numReps == 0) // or "numReps < 300"
        numReps += 300;
    // ...

Eventually there will be a migration added to the database between each release so that your data is preserved, but there are so many changes being made to the database now that i don't really want to have to worry about it.

flackbash commented 5 years ago

I tried it, this line of code does the job.

chickendude commented 1 year ago

I've been thinking about this again and i think i have a partial workaround for now. I recently added back in the option to set your starting location in a course, what if changing your starting location in a course also asked you if you wanted to recalculate the previous reps? So if updating the app lost your progress, you would be able to start the course where you left it (this is the reason why i added it in the first place, so i can use my local build to study with and not have to worry about losing my progress) and it could calculate how many reps you would have if you had studied up to that point in the course.

Currently rep count isn't actually displayed anywhere, but that's one of the next things on my todo list. I'm currently working on a session browser so that you can browse through your previous sessions.

jubalh commented 1 year ago

Sounds like a solution. As long as this is optional it sounds good to me.