Setting Up the Project Files4:10 with Michael Lustig
In this video, we’re going to ensure that the project files are setup properly on your computer and then walk through the start state of the project.
Now that you've seen what the final project looks like, 0:00 we're going to get the project files set up on your computer. 0:02 If you've watched online coding tutorials before, 0:05 I'm sure you've probably done this kind of setup before. 0:08 I strongly encourage you to stick around for 0:10 this video just to make sure everything is in the right place. 0:12 Having a different setup than the one we follow in the video can cause some 0:15 unnecessary frustration, so we definitely don't want that to happen. 0:18 I promise I'll keep this short, sweet, and to the point. 0:21 Go ahead and 0:25 click the link in the teacher's notes to download the zipped up starter files. 0:25 In them, you'll find six folders in total. 0:29 Each video where we write code will have a before and after state, 0:32 in case you want to try and challenge yourself to perhaps watch a video, and 0:35 then go and implement the changes I make from memory. 0:38 You definitely don't have to do this, and it's simply an option, 0:41 but this kind of set up helps me learn, so I figured I'd share it with you. 0:43 In each video, I will start from the before state and 0:47 end in the after state of the code for that particular video. 0:49 I've also included to do comments in the code where I make changes so 0:52 that can be easily found using Android Studios built in to do window. 0:55 Once you've downloaded the zip of the project files, make sure that the zip 1:00 files in the location on your computer where you'd like them to live. 1:03 Once they're there go ahead and unzip them. 1:06 Within the unzip folders, you will see sub folders corresponding to each 1:11 video where we write code or where want to include it's due comment. 1:14 To start, we'll open Android Studio and then open the folder called 01-exercise. 1:18 Let's have a look around this code. 1:23 In the project, there are two packages. 1:25 One for the login related code and the other for the messages related code. 1:28 Let's take a peak at the login package first. 1:31 Once you open the package, you'll see there are two classes. 1:34 One for the login screen itself, and a utility class for 1:37 determining if a user is logged in. 1:40 In the LoginActivity, if there's a user already logged in, I start the messaging 1:44 activity, close the log in activity, and return so no further code is called. 1:47 Then, I set a listener on the edit text to log in the user when the Enter 1:52 button is pressed. 1:55 I also set a listener on the log in button to do the same thing. 1:57 Next, we'll explore the messages package. 2:00 This is where all the fun FireBase stuff will happen. 2:03 First, I want to show you the Messages class that will represent a message in our 2:05 Firebase. 2:09 There are a couple of key things here I want to call your attention to. 2:11 First, notice that there is a no arguments constructor. 2:14 Firebase requires this in order to deserialize objects. 2:17 You'll also notice the @IgnoreExtraProperties 2:21 annotation on this class. 2:24 There will be an error with that annotation at first, but 2:26 we'll fix this shortly. 2:28 That annotation does exactly what it looks like. 2:30 It ignores properties that don't map the class fields. 2:32 In other words, if there is a method for getting a value that doesn't directly 2:35 correspond to a class field, it's ignored when setting your data to Firebase. 2:39 Next, we'll look at the MessagingActivity. 2:44 We also have simple classes for MessageAdapter and MessageViewHolder. 2:47 But those are simply boiler plate required to populate a recycler view. 2:50 And I will leave it up to you to explore those classes. 2:53 Within the MessagingActivity, I've set the adapter on the recycler view and 2:56 wired up the button to send a message and 3:00 the edit text to send a message when a user clicks the Enter button. 3:01 Currently, the activity will show a toast when we attempt to send a message, but 3:06 we will update that behavior soon. 3:09 There are also methods below for clearing a text of the edit text, 3:12 hiding the keyboard, and scrolling to the most recent message. 3:15 Those methods are all simply for 3:18 a better user experience and certainly aren't required by Firebase. 3:19 Let's run the starter project and see what it looks like. 3:23 I'm going to comment out the Firebase annotation on our Message class since 3:26 I haven't yet included the Firebase library in this project. 3:29 But, again, we'll fix that very soon. 3:32 When you run this project, you'll first see the username entry screen. 3:35 After you provide a username, 3:44 you'll see a screen where a list of messages will eventually be displayed. 3:45 For now, if we type a message and hit send. 3:49 We'll see that the message goes away, but isn't actually sent anywhere. 3:59 In the next video, we'll learn how to create a Firebase project in the Firebase 4:02 console, taking the first step to sending your message to everyone in real time. 4:06
You need to sign up for Treehouse in order to download course files.Sign up