BookLogApplication: Connecting the dots with more logic
Today has been a long day and I realized I put my head into stuff where I can avoid :P Lol…. Although I am absolutely happy with where this app is heading and more than that I am feeling a weird sense of satisfaction of getting back to development again ❤
So, I was stuck with a few questions yesterday and with some collaborative discussions, I realized I did not structure it correctly.
(Telling you again to join me in this awesome journey of discipline, excitement, and habit-forming ;))
Some improvements to my Author and Book class as well as the fragment layouts.
So I removed Input for the book from Add Author screen as the author model has a backlink to books and that does not require user input
The Add Author Fragment code is as below, simple code, getting author value from UI, verifying it's not empty. Opening a Sync Realm and adding the object to the realm and closing it.
A slight change to the Book model, as I had forgotten to add the partition key. As I mentioned before partition key is important
open class Book(
@PrimaryKey
var _id: ObjectId = ObjectId(),
@Required
var name: String = "",
var isRead: Boolean = false,
var _partition: String ="PUBLIC",
var authors: RealmList<Author> = RealmList()
) : RealmObject() {}
The Add Book UI looks like below. The logic I am struggling to implement here is to select multiple choices for authors as a book can have multiple authors.
I tried using AlertDialog.Builder.setMultiChoiceItems()
but it’s not accepting the typed array. I may go ahead and write a custom adapter to display the list of authors that users can select.
The Add Book screen is different, if the author is not available, you would need to add Author first.
Since my add book fragment logic is still incomplete, I will not be posting it.
I further added Recycler View to the BookList Fragment and am using RealmRecyclerView Adapter to display the books. Ohh yes, Realm provides that.. Awesome, Right!!!!
Take a look at RealmAdapter, if you wanna give it a shot.
And also, nav graph error that I was facing yesterday, I made a stupid mistake of not renaming my class to AddAuthor, it was still showing AddOwner, not from the directory window that shows packages and class names, but the project window where you type the code..😹
So I am left with 2 things now and hopefully I will have a fully functional app tomorrow
- Adding code for BookList Display
- Making multiple selection choices for author to select from
Once, this is complete, my app can be run and schema will be populated to Atlas.
Let's see, what day 17/100 holds… Until tomorrow.. 👋