The Journey of #100DaysOfCode (@henna_dev)

#Day26 of #100DaysOfCode

Today was a tiring day… I am not as young as I once was and that hurts…(oooffff) lol but I still feel like a child inside :stuck_out_tongue:
I decided to come back to my BookLog App and finish it completely by tomrow, only if there were fewer bugs to fix :wink:

:sparkles: Twitter: https://twitter.com/henna_dev/status/1499893476720320515

2 Likes

#Day27 of #100DaysOfCode

Today I had a great start to my day, went for a morning walk close to the sea, had a good breakfast and then cycled to the library and spent some good hours there… :two_hearts:

Edit: Me at the Sea :smiley:

:sparkles: Twitter: https://twitter.com/henna_dev/status/1500261523998007302

2 Likes

#Day28 of #100DaysOfCode

Sunday rhymes with Funday and so eggjactly that way it was :stuck_out_tongue: Food Market Fun and Evening with a Fren

:sparkles: Twitter: https://twitter.com/henna_dev/status/1500616573609984000

2 Likes

#Day29 of #100DaysOfCode

Today was full of meetings… I could not get a lot done and the day did not end with a happy note. I spent time solving the error I was stuck at for a while… :slight_smile:

I got some suggestions from a Senior Developer, but I could not implement them in the app until late evening :unamused: :unamused: and the code did not work. Realm Queries is a little harder to understand :stuck_out_tongue: I will understand them soon…

I made some changes in the Add Book Fragment, I was suggested not to use transactions in Read queries, so I removed transaction code from all of them.

 private fun openDialogBox(nameList: ArrayList<Author>) {

        val builder: AlertDialog.Builder = AlertDialog.Builder(requireContext())
        builder.setTitle("Select Author/s")
        val selectedAuthors = BooleanArray(nameList.size)
        val stringAuthorList = nameList.map{it.name}.toTypedArray()
        builder.setMultiChoiceItems(stringAuthorList, selectedAuthors) { dialog, which, isChecked ->
            if (isChecked) {
                //when checkbox selected, add position
                selectedItems.add(which)
            } else if (selectedItems.contains(which)) {
                //when checkbox unselected
                //remove pos from list
                selectedItems.remove(which)
            }
        }
        builder.setPositiveButton("OK") { dialog, which ->

            selectedItems.forEach{
                Timber.d("Authors, ${stringAuthorList[it]}")
                nameList.forEach {author ->
                    if(stringAuthorList[it] == author.name){
                        bookObject.authors.add(author)
                    }
                }
//                realmClass.executeTransactionAsync({ realm ->
//                   realm.where(Author::class.java).equalTo("name", nameList[it]).findAll()
//                       .map{addAuthor ->
//                      bookObject.authors.add(addAuthor)
//                   }
//                }, {
//                    Timber.d("Author added successfully")
//                }, { throwable ->
//                    Timber.d("Error adding the author %s", throwable.localizedMessage)
//                })
            }
        }
            .setNegativeButton("Cancel", DialogInterface.OnClickListener{ dialog, id ->
                    dialog.dismiss()
            })

        builder.create().show()
    }

I didn’t feel like deleting the code, so I commented it :smiley: I changed the way I was processing the selected Authors, I used copyFromRealm to get the AuthorList in form of ArrayList that I passed to openDialogBox

The loadAuthors is called when I click on Text Button to add Book Author, it reads the list of authors in the database and displays it on a dialog for the user to select shown in above code.

    private fun loadAuthors() {
        var nameList = ArrayList<Author>()
        realmClass.executeTransactionAsync({
            val authorList = it.where(Author::class.java).sort("name").findAll()
             nameList = it.copyFromRealm(authorList) as ArrayList<Author>
//            authorList.toTypedArray().map { obj ->
//                nameList.add(obj.name)
//            }
        }, {
            if(nameList.size>0) openDialogBox(nameList)
            else {
                Toast.makeText(context, "Author List is empty, please add Author Name first", Toast.LENGTH_LONG).show()
            }
        }, {
            Timber.d("Error happened while reading Author List %s", it.localizedMessage)
            Toast.makeText(context, "Error happened while reading List, ${it.localizedMessage}", Toast.LENGTH_LONG).show()
        })
    }

Once the user selects the author index, it searches the list for a name that was selected and saves that to the bookObject.

When submit button is pressed, click listeners get called and save the book to realm database. The last part is giving errors and I have no clue how to solve, so I will continue tomorrow.

2022-03-07 22:42:42.517 14699-14699/? D/AddBookFragment: Error adding the bookObject to Database 'BookRealm' has a primary key, use 'createObject(Class<E>, Object)' instead.

I changed the code after above error to following

        addBinding!!.buttonAddBook.setOnClickListener{
                realmClass.executeTransactionAsync ({realm ->
                    val booktoAdd = realm.createObject(BookRealm::class.java, ObjectId())
                    booktoAdd.name = bookObject.name
                    booktoAdd.isRead = bookObject.isRead
                    booktoAdd.authors = realm.copyToRealm(bookObject.authors) as RealmList<Author>

                }, {
                    Timber.d("Book Object Added Successfuly")
                }, {throwError ->
                    Timber.d("Error adding the bookObject to Database %s", throwError.localizedMessage)
                })
        }

And this gives me a different error that I cannot solve

2022-03-07 23:42:34.721 5257-5257/? D/AddBookFragment: Error adding the bookObject to Database Attempting to create an object of type 'Author' with an existing primary key value '621a992338d6fd61a1126414'.

My Add BookFragment screen is as below:

Until Tomorrow… :performing_arts:

2 Likes

#Day30 of #100DaysOfCode

I cracked the error that I was stuck at for a long time, now finally the puzzle pieces are complete. I drafted part one on our forums, Stay Tuned for part two :wink:

:sparkles: Twitter: https://twitter.com/henna_dev/status/1501342938785329155

2 Likes

#Day31 of 100daysofcode

Today I went to the office and we had loads of fun with colleagues… It was a day spent well :heart_eyes:
I continued with my BookLog application and talked about errors I faced and how I resolved them

Until tomorrow… :performing_arts:

3 Likes

#Day32 of #100DaysOfCode

Today was a productive day… I got up lazy as I was very tired from yesterday but the day went well :smiley:
I also managed to book my classes for Martial Arts :martial_arts_uniform: something that I am very excited to start :heart_eyes:

Today I came back to HTML as I also want to finish the Flashcards project soon.

:sparkles: Twitter: https://twitter.com/henna_dev/status/1502067350044090369

2 Likes

#Day 33 of #100DaysOfCode

Happy Friday :tada: always exciting to mark the end of the week and I ended on a high point… I and my Friend are fans of each other… :revolving_hearts: :stuck_out_tongue:

:sparkles: Twitter: https://twitter.com/henna_dev/status/1502434278654849025

3 Likes

#Day 34 of #100DaysOfCode

Today was a lazy day… hehhehhe I started a new game on PS4 and it’s fun although I am still learning to fight. The evilest thing I did was kill the cutie elephant queen in “It Takes Two” I feel like a devil :smiling_imp:

I also managed to study Transformations in CSS :smiley:

:sparkles: Twitter: https://twitter.com/henna_dev/status/1502797540303020040

5 Likes

Oh, nice! You are playing “It takes two” - I love the game!

34 days into it #100daysofcode! 1/3 there! Woohoo!
How does it feel @henna.s? It is said that do a thing for 21 days and it will become a habit.

Love reading your updates, looking forward to the next 66 days!

All the best!

3 Likes

#Day35 of #100DaysOfCode

Today was a long day… I was in Galway today to give a talk at the Leadership and Empowerment event :rocket: to celebrate International Women’s Day :tada: :smiley: … It was also 5-hour travel to and fro Galway :sweat_smile:

I am proud to say everybody loved :revolving_hearts: my talk and am super excited that we are back with in-person events.

Some highlights

I am 3 chapters away from finishing the CSS concepts before I complete the remaining parts of the Flashcards project … :confetti_ball: :tada:

I finished studying backface-visibility in CSS. It means if you want backside of the element to be visible or not.
You can set the following values for the backface-visibility property:

  • visible is used to make the backside of the element visible and mirrored through the front surface of the element. This is the default value.
  • hidden makes the backside invisible behind the front surface of the element.
  • inherit will allow you to inherit the value of the parent element.
  • initial sets the property to its default value;
  • unset is basically a combination of the initial and inherit values. The unset keyword sets the property value as inherit if the property is inherited from the parent element; otherwise, the value is set as initial

Too tired today, so I am skipping writing :frowning: I will continue this section in the CSS: Visibility Blogpost.

5 Likes

Thanks, Harshit, I absolutely adore the game as well… playing for the second time now… :smiley:

It feels great :heart_eyes: I am more focussed on what I am learning each day :wink: and I feel absolutely satisfied that I started this and @Kushagra_Kesav motivates me a lot and keeps me on track :smiley:

I can’t wait to see what all will I learn in next 66 days :wink:

Cheers, :performing_arts:

4 Likes

#Day36 of #100DaysOfCode

Today was Monday, as all Monday blues goes… :upside_down_face: I finished another CSS topic which totally jumbled up my brain… I will do some practice on this because its an interesting topic… Tomorrow I will do more Realm :blush:

:sparkles: Twitter: https://twitter.com/henna_dev/status/1503523626863243267

2 Likes

#Day37 of #100DaysOfCode

The morning started a little meh but cycling towards the sea coast. helped freshen up and then a scary turned awesome meeting added more color to my day :heart_eyes: :confetti_ball:

One day I definitely will swim here :wink:

I did a sample codepen to learn transitions, I learned to flip

I also updated the article with details on backface-visibility and added a codepen

2 Likes

#Day38 of 100daysofcode

Today was a productive day :smiley: I manage to do lot of tasks :star_struck: I also enjoyed my second Martial Arts Class and it was sooo intensive but fun… I am absolutely in love :revolving_hearts:

Today I did 2 codepens and learned about z-index

Transition on a login card :smiley:

Some theory on z-index is :

The z-index property can change the layer order of an element and change the position of an element on its z-axis.

The z-index property is defined by a positive or negative integer value, or by an auto value. An auto value gives the element the same layer order as its parent’s.

  • auto: Same layer order as its parent’s. This is the default value.
  • number: Sets the layer order of the element. Negative numbers can also be used.
  • inherit: Inherits this property from its parent element.

The z-index property will only work on elements whose position has been defined as absolute , fixed , or relative .

:sparkles: Twitter: https://twitter.com/henna_dev/status/1504237152674238469

3 Likes

Noice! Great job being consistent. The all powerful z-index is now yours to keep! It has served me well in many animation projects. Hooray for you my friend :vulcan_salute:

2 Likes

Thank you sooo much @Jason_Nutt :revolving_hearts:

Animations are pretty exciting :heart_eyes: only if I could do better designing as well… In another world, I may want to be a designer… :stuck_out_tongue:

Would love to see your animation projects :star_struck: How are you progressing with MongoDB? Any thoughts on recording your voice? :wink: Lets have a zoom sometime when you are available :blush:

Cheers, :performing_arts:

4 Likes

#Day39 of #100DaysOfCode

Today I went to the city and enjoyed St.Patricks Day Parade… :four_leaf_clover: It was absolute fun and equally tiring…

Some Highlights:

I finally finished the remaining puzzle pieces of the BookLog Application and now it displays the list of books and authors.

In continuation from the Realm Bytes: BookLog Topic.

the code for retrieving the booklist in the booklist fragment is all below:

override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
        super.onViewCreated(view, savedInstanceState)
        listBinding?.rvBookList?.layoutManager = LinearLayoutManager(context)
        setUpRecyclerView()
    }


    private fun setUpRecyclerView() {
       adapter = BookListAdapter(realmList.where(BookRealm::class.java).sort("name").findAll())
        listBinding?.rvBookList?.adapter = adapter
    }

The Recycler View is used to display the list, the setup is called once the activity view is created, otherwise it throws error. Realm provides Realm Adapter to use with Recycler View to display the list.

The Recycler Adapter code is as follows:

class BookListAdapter(books: OrderedRealmCollection<BookRealm>): RealmRecyclerViewAdapter<BookRealm, BookListHolder>(books, true) {

    override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): BookListHolder {
        val view = LayoutInflater.from(parent.context)
            .inflate(R.layout.booklist_item_layout, parent, false)
        return BookListHolder(view)
    }

    override fun onBindViewHolder(holder: BookListHolder, position: Int) {
        val book = getItem(position)
        holder.bindValues(book)
    }
}

The Holder code is as below:

class BookListHolder(itemView: View) : RecyclerView.ViewHolder(itemView) {

    private val bookName = itemView.bookName
    private val authorName = itemView.authorName
    val stringBuilder = StringBuilder("")

    fun bindValues(book: BookRealm?){
        bookName.text = book?.name
        book?.authors?.forEach{
            stringBuilder.append(it.name).append(" ")
        }
        authorName.text = stringBuilder
    }
}

If you fancy read Realm Recycler Adapter in detail.

So, the list is displayed as:

Until tomorrow…

3 Likes

Well to be honest @henna.s I am struggling to understand somethings but that is part of growth. I only have so much time to spend trying to figure something out per night so it is going slow. I am excited that I started the MongoDB for javascript developers, but not so excited to realize that means I have to face the fact that I have to go back and re-learn or re-iterate through asnyc/await and callbacks and the first ticket in the course has me at a standstill already but there is no giving up this time… Oh and I would love to share the few animated projects I’ve built with you any time. I appreciate the interest and we will make some time to zoom for sure soon. Maybe on a Saturday or something. Thanks for the accountability my friend!

2 Likes

#Day40 of 100daysofcode

I am in Edinburgh for the extended weekend and it has been a good fun day… I dint do a lot except publish the realm bytes and upload the app on the Github :smiley:

Some highlights of me being crazy :wink: (Pro Tip: If you don’t have a good height, get a good mirror :stuck_out_tongue: )

:sparkles: Twitter: https://twitter.com/henna_dev/status/1504963199950536706

4 Likes