tom-anders / Easy_xkcd

An easy and simple open source xkcd reader
Apache License 2.0
165 stars 41 forks source link

Store and show comic date #273

Closed rootmeanclaire closed 2 years ago

rootmeanclaire commented 2 years ago

Stores the publication date alongside other comic metadata.

Right now the date just displays in the raw ISO 8601 as a subtitle for the comic, but localized formatting and other tweaks could be implemented. I haven't worked with Android UI in a while though, so I didn't want to risk making too many changes in that respect.

Screenshot as of commit e403737
rootmeanclaire commented 2 years ago

I forgot to check before committing, but it seems like it doesn't handle migration from the old database well, so that will have to be fixed to avoid a startup crash before merging. I'll see if I can do it myself, but I'll have to read up a bit on how realm.io works first.

java.lang.RuntimeException: Unable to start activity ComponentInfo{de.tap.easy_xkcd/de.tap.easy_xkcd.Activities.MainActivity}: io.realm.exceptions.RealmMigrationNeededException: Field count does not match - expected 9 but was 8
        at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3449)
        at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3601)
        at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:85)
        at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:135)
        at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:95)
        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2066)
        at android.os.Handler.dispatchMessage(Handler.java:106)
        at android.os.Looper.loop(Looper.java:223)
        at android.app.ActivityThread.main(ActivityThread.java:7656)
        at java.lang.reflect.Method.invoke(Native Method)
        at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:592)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:947)
     Caused by: io.realm.exceptions.RealmMigrationNeededException: Field count does not match - expected 9 but was 8
        at io.realm.RealmComicRealmProxy.validateTable(RealmComicRealmProxy.java:259)
        at io.realm.DefaultRealmModuleMediator.validateTable(DefaultRealmModuleMediator.java:47)
        at io.realm.Realm.initializeRealm(Realm.java:293)
        at io.realm.Realm.createAndValidate(Realm.java:261)
        at io.realm.Realm.createInstance(Realm.java:240)
        at io.realm.RealmCache.createRealmOrGetFromCache(RealmCache.java:114)
        at io.realm.Realm.getDefaultInstance(Realm.java:181)
        at de.tap.easy_xkcd.database.DatabaseManager.<init>(DatabaseManager.java:88)
        at de.tap.easy_xkcd.Activities.MainActivity.onCreate(MainActivity.java:156)
        at android.app.Activity.performCreate(Activity.java:8000)
        at android.app.Activity.performCreate(Activity.java:7984)
        at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1309)
        at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3422)
        at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3601) 
        at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:85) 
        at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:135) 
        at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:95) 
        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2066) 
        at android.os.Handler.dispatchMessage(Handler.java:106) 
        at android.os.Looper.loop(Looper.java:223) 
        at android.app.ActivityThread.main(ActivityThread.java:7656) 
        at java.lang.reflect.Method.invoke(Native Method) 
        at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:592) 
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:947) 
2021-10-04 12:36:39.209 22488-22488/? E/ACRA: ACRA caught a RuntimeException for de.tap.easy_xkcd
    java.lang.RuntimeException: Unable to start activity ComponentInfo{de.tap.easy_xkcd/de.tap.easy_xkcd.Activities.MainActivity}: io.realm.exceptions.RealmMigrationNeededException: Field count does not match - expected 9 but was 8
        at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3449)
        at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3601)
        at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:85)
        at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:135)
        at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:95)
        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2066)
        at android.os.Handler.dispatchMessage(Handler.java:106)
        at android.os.Looper.loop(Looper.java:223)
        at android.app.ActivityThread.main(ActivityThread.java:7656)
        at java.lang.reflect.Method.invoke(Native Method)
        at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:592)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:947)
     Caused by: io.realm.exceptions.RealmMigrationNeededException: Field count does not match - expected 9 but was 8
        at io.realm.RealmComicRealmProxy.validateTable(RealmComicRealmProxy.java:259)
        at io.realm.DefaultRealmModuleMediator.validateTable(DefaultRealmModuleMediator.java:47)
        at io.realm.Realm.initializeRealm(Realm.java:293)
        at io.realm.Realm.createAndValidate(Realm.java:261)
        at io.realm.Realm.createInstance(Realm.java:240)
        at io.realm.RealmCache.createRealmOrGetFromCache(RealmCache.java:114)
        at io.realm.Realm.getDefaultInstance(Realm.java:181)
        at de.tap.easy_xkcd.database.DatabaseManager.<init>(DatabaseManager.java:88)
        at de.tap.easy_xkcd.Activities.MainActivity.onCreate(MainActivity.java:156)
        at android.app.Activity.performCreate(Activity.java:8000)
        at android.app.Activity.performCreate(Activity.java:7984)
        at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1309)
        at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3422)
        at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3601) 
        at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:85) 
        at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:135) 
        at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:95) 
        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2066) 
        at android.os.Handler.dispatchMessage(Handler.java:106) 
        at android.os.Looper.loop(Looper.java:223) 
        at android.app.ActivityThread.main(ActivityThread.java:7656) 
        at java.lang.reflect.Method.invoke(Native Method) 
        at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:592) 
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:947) 

Also, when zooming in the date is covered by the comic image, which may or may not be desirable.

tom-anders commented 2 years ago

Hi,

yeah for the Realm you basically have to define a new database version and a migration to it. You can have a look at DatabaseManager.java I think to see how I did it the last time the database changed. If you have trouble, I can help of course.

I'm currently moving to a new flat, so I don't have time to look at the PR in detail yet. If it's ok with you, I'll check back in 1-2 weeks.

Tom

tom-anders commented 2 years ago

@eshimoniak I'm currently in the process of migrating the whole database from Realm to Room (see the commit above). Most of the UI layer is also being rewritten in Kotlin. I already added the date to the new database (so that we don't have to do a migration later on).

tom-anders commented 2 years ago

Year, month and day are now stored in the new Room-based database (but now yet displayed). I recently merged it to master. Feel free to take a look and adapt this PR if you want

rootmeanclaire commented 2 years ago

I'll probably redo it if anything. I'll close this PR for now because I don't know when I'll get around to implementing it, if ever.