bitfireAT / icsx5

ICSx⁵ is an Android app to subscribe to remote or local iCalendar files (like time tables of your school/university or event files of your sports team).
https://icsx5.bitfire.at
GNU General Public License v3.0
184 stars 9 forks source link

Upgrading to 2.1-beta.2: all subscriptions are "gone" until sync is forced #120

Closed rfc2822 closed 1 year ago

rfc2822 commented 1 year ago

@ArnyminerZ I have updated ICSx5 to 2.1-beta.2 on my phone, and I noticed that after upgrading, all subscriptions are "gone" until I synchronize. (Because only synchronization migrates the calendar subscripttions to DB subscriptions.)

For me, it's not a problem because I know that I only have to refresh, but there are many people who don't know that. The migration should run automatically. What is your suggestion?

ArnyminerZ commented 1 year ago

I was thinking about checking the amount of subscriptions in the database when launching the app. It the list is empty, synchronize. This won't be an issue when first launching the app, since the synchronization will just do nothing if there's no data stored. However, if there's data in the calendar, the migration will run, and once they are in the db, it won't be called automatically anymore.

The only issue I see is that the app will fetch all the subscriptions from the database every time the user launches the app.

rfc2822 commented 1 year ago

Maybe enqueue a sync when the DB is created the first time?

ArnyminerZ commented 1 year ago

I have found this snippet: https://stackoverflow.com/a/57933137

In theory we can create a function to check if the database has been initialized with:

Cursor csr = db.query("sqlite_master",null,"name = ?",new String[]{"room_master_table"},null,null,null);
if (csr.getCount() > 0) {
    //db is a room database
} else {
    // db is not a room database
}
csr.close();

Edit: doesn't seem to work

ArnyminerZ commented 1 year ago

Okay, I have tested this:

fun exists(context: Context): Boolean = context.getDatabasePath(DATABASE_NAME).exists()

This returns false the first time the app is launched, but once data has been fetched, it returns true, so maybe this is the way.

rfc2822 commented 1 year ago

Or maybe add a callback for the DB onCreate?

ArnyminerZ commented 1 year ago

Or maybe add a callback for the DB onCreate?

Maybe we can add a listener and just run migrateLegacyCalendars?

ArnyminerZ commented 1 year ago

Or add an extra to the worker which says to "just run migration"?

rfc2822 commented 1 year ago

Or maybe add a callback for the DB onCreate?

Maybe we can add a listener and just run migrateLegacyCalendars?

That sounds fine. Another extra would add more complexity without gain (except when we need it for some reason I don't know yet).