‫After we succeeded in creating the adapter class, let's move to the journal list activity in order
‫to get all the journals and display them into the recycler view.
‫So I need to use the Firebase authentication because I need to get the current state of the user and
‫later on implement the sign out functionality for the user private Firebase auth and the listener and
‫the Firebase user.
‫Then I need to create a Firebase instance for Firestore.
‫And here I need to create a Firebase Storage reference.
‫Please concentrate with me because we're going to use the storage to get the images.
‫I'll start with a private list, because I'm going to get all the journals and display them to the recycler
‫view and store them into a data structure of type list, journal list.
‫And here in the Firebase Firestore I need to add the collection reference.
‫So private collection reference equals to DB dot collection.
‫And here I need to specify the journal node.
‫Then add the recycler view.
‫So private recycler view widget recycler view.
‫And I need to create an instance from the adapter.
‫So my adapter my adapter.
‫Then we need to move to the Oncreate method to start initializing the variables and the references.
‫I'll start with Firebase OAuth.
‫Then the widgets.
‫And we'll initialize the posts array list.
‫We are done with the Oncreate method.
‫Now let's move and add the menu.
‫So here we're going to create a menu.
‫For that I'll go to the project.
‫And here in the resource folder I'll create a new Android resource directory.
‫And I'll select the menu.
‫Click okay and the menu folder will be created.
‫Then create menu resource file my menu.
‫I'll create two items inside this menu menu file.
‫So this attribute for the item will assign a unique identifier to the menu item.
‫This ID can be used to reference the menu item in Java or Kotlin code.
‫When handling menu item clicks and Android icon is attribute that used to set the icon for the menu
‫item, and in this case, it's using a built in Android system icon named as IK menu add.
‫This will refer for the built in menus title.
‫This attribute or this attribute sets the text label for the menu item.
‫It specifies what text will be displayed alongside with the icon in the app's menu.
‫In Android Show as action.
‫This attribute is specific to the Appcompat library, and is used to specify how the menu items should
‫be displayed in the action Bar or App bar.
‫If room.
‫If room indicates that the menu item should be shown in the action bar.
‫If there is enough room.
‫If there isn't enough room, it may be hidden in the overflow menu.
‫Then I'll create another item here.
‫Title sign out ID would be Action Score.
‫Sign out and show as action.
‫Now when you set the app, show as action to never for a menu item in Android, you are specifying that
‫this particular menu item should never be displayed in the Action bar or the app Bar.
‫Instead, it will always be placed in the overflow menu, which is accessible through the three dot
‫icon located in the top right corner of the action bar, so you can see the plus sign here for adding
‫the journal and the three dots.
‫If you click on it, it will display sign out item.
‫Let's go back to the journal list.
‫And here we need to specify our menu Oncreate option menu I'll override this.
‫And here I need to use get menu inflator dot inflate.
‫And here I need to inflate our dot menu dot my menu and I name it as menu.
‫Now if the user clicks any of these icons, the sign out or the plus of these items, we need to handle
‫them.
‫So on options item selected, I need to create a switch to get the item ID, because here I specified
‫an ID action add, and here I specify the ID action sign out.
‫We need to refer for these items and allow the user to click on them.
‫Switch AR or item dot.
‫Get item ID.
‫We need to start with the first case where the user clicks on the add journal.
‫So r.id dot action underscore add.
‫I need to direct the user to the journal activity.
‫So if user doesn't equal to null and there is a authentication, we need to start activity or create
‫an intent I equals to new intent journal activity dot this and we need to direct it to the add journal
‫activity.
‫And this is an activity that we're going to create now.
‫Create a new activity.
‫Empty views activity and I'll name it as Add Journal Activity.
‫Click enter.
‫In the next videos, we're going to create the layout for this activity and add the functionality for
‫adding new journals.
‫Then we need to use the break.
‫Then we need to test for the case.
‫Number two.
‫If it is equals to the sign up, then we need to sign out the user.
‫So if user doesn't equal to null.
‫Firebase auth dot sign out.
‫This is the method that it is used to sign out the user from Firebase.
‫And we need to direct this user.
‫And here we didn't use the start activity.
‫Oops I and here I need to create I equals to new intent journal list activity dot this.
‫And we need to direct the user to the login and the main activity.
‫And don't miss to use the brake.
‫Clean the project.
‫And here we go.
‫Then the last thing we need to do is to return super dot on options menu.
‫Select it and I need to pass the.
‫And if the error persists for the case where we need to pass constant expression required, we can get
‫like this.
‫We can store int value equals to item dot, get item ID or item id and I can replace the switch by if
‫statement.
‫So if item id equals to r.id dot action add, I can execute this line of code.
‫And in the same way I'll check for else if.
‫Item id equals to r.id dot action signout.
‫We need to copy this and cut it.
‫And here we go.
‫So whenever you have this error and many people asked me about this error, please convert the switch
‫into if and else statements.