1 00:00:00,720 --> 00:00:02,980 Now that you've seen what the final project looks like, 2 00:00:02,980 --> 00:00:05,730 we're going to get the project files set up on your computer. 3 00:00:05,730 --> 00:00:08,050 If you've watched online coding tutorials before, 4 00:00:08,050 --> 00:00:10,790 I'm sure you've probably done this kind of setup before. 5 00:00:10,790 --> 00:00:12,500 I strongly encourage you to stick around for 6 00:00:12,500 --> 00:00:15,580 this video just to make sure everything is in the right place. 7 00:00:15,580 --> 00:00:18,370 Having a different setup than the one we follow in the video can cause some 8 00:00:18,370 --> 00:00:21,610 unnecessary frustration, so we definitely don't want that to happen. 9 00:00:21,610 --> 00:00:24,120 I promise I'll keep this short, sweet, and to the point. 10 00:00:25,380 --> 00:00:25,890 Go ahead and 11 00:00:25,890 --> 00:00:29,320 click the link in the teacher's notes to download the zipped up starter files. 12 00:00:29,320 --> 00:00:32,030 In them, you'll find six folders in total. 13 00:00:32,030 --> 00:00:35,140 Each video where we write code will have a before and after state, 14 00:00:35,140 --> 00:00:38,180 in case you want to try and challenge yourself to perhaps watch a video, and 15 00:00:38,180 --> 00:00:41,050 then go and implement the changes I make from memory. 16 00:00:41,050 --> 00:00:43,300 You definitely don't have to do this, and it's simply an option, 17 00:00:43,300 --> 00:00:47,200 but this kind of set up helps me learn, so I figured I'd share it with you. 18 00:00:47,200 --> 00:00:49,490 In each video, I will start from the before state and 19 00:00:49,490 --> 00:00:52,960 end in the after state of the code for that particular video. 20 00:00:52,960 --> 00:00:55,990 I've also included to do comments in the code where I make changes so 21 00:00:55,990 --> 00:00:59,210 that can be easily found using Android Studios built in to do window. 22 00:01:00,420 --> 00:01:03,450 Once you've downloaded the zip of the project files, make sure that the zip 23 00:01:03,450 --> 00:01:06,490 files in the location on your computer where you'd like them to live. 24 00:01:06,490 --> 00:01:08,480 Once they're there go ahead and unzip them. 25 00:01:11,240 --> 00:01:14,650 Within the unzip folders, you will see sub folders corresponding to each 26 00:01:14,650 --> 00:01:18,150 video where we write code or where want to include it's due comment. 27 00:01:18,150 --> 00:01:23,570 To start, we'll open Android Studio and then open the folder called 01-exercise. 28 00:01:23,570 --> 00:01:24,700 Let's have a look around this code. 29 00:01:25,970 --> 00:01:28,220 In the project, there are two packages. 30 00:01:28,220 --> 00:01:31,990 One for the login related code and the other for the messages related code. 31 00:01:31,990 --> 00:01:34,720 Let's take a peak at the login package first. 32 00:01:34,720 --> 00:01:37,960 Once you open the package, you'll see there are two classes. 33 00:01:37,960 --> 00:01:40,990 One for the login screen itself, and a utility class for 34 00:01:40,990 --> 00:01:42,720 determining if a user is logged in. 35 00:01:44,018 --> 00:01:47,830 In the LoginActivity, if there's a user already logged in, I start the messaging 36 00:01:47,830 --> 00:01:52,660 activity, close the log in activity, and return so no further code is called. 37 00:01:52,660 --> 00:01:55,930 Then, I set a listener on the edit text to log in the user when the Enter 38 00:01:55,930 --> 00:01:57,260 button is pressed. 39 00:01:57,260 --> 00:02:00,840 I also set a listener on the log in button to do the same thing. 40 00:02:00,840 --> 00:02:03,250 Next, we'll explore the messages package. 41 00:02:03,250 --> 00:02:05,900 This is where all the fun FireBase stuff will happen. 42 00:02:05,900 --> 00:02:09,105 First, I want to show you the Messages class that will represent a message in our 43 00:02:09,105 --> 00:02:09,735 Firebase. 44 00:02:11,310 --> 00:02:14,660 There are a couple of key things here I want to call your attention to. 45 00:02:14,660 --> 00:02:17,950 First, notice that there is a no arguments constructor. 46 00:02:17,950 --> 00:02:21,770 Firebase requires this in order to deserialize objects. 47 00:02:21,770 --> 00:02:24,570 You'll also notice the @IgnoreExtraProperties 48 00:02:24,570 --> 00:02:26,320 annotation on this class. 49 00:02:26,320 --> 00:02:28,640 There will be an error with that annotation at first, but 50 00:02:28,640 --> 00:02:30,270 we'll fix this shortly. 51 00:02:30,270 --> 00:02:32,630 That annotation does exactly what it looks like. 52 00:02:32,630 --> 00:02:35,770 It ignores properties that don't map the class fields. 53 00:02:35,770 --> 00:02:39,220 In other words, if there is a method for getting a value that doesn't directly 54 00:02:39,220 --> 00:02:43,030 correspond to a class field, it's ignored when setting your data to Firebase. 55 00:02:44,040 --> 00:02:47,010 Next, we'll look at the MessagingActivity. 56 00:02:47,010 --> 00:02:50,402 We also have simple classes for MessageAdapter and MessageViewHolder. 57 00:02:50,402 --> 00:02:53,780 But those are simply boiler plate required to populate a recycler view. 58 00:02:53,780 --> 00:02:56,548 And I will leave it up to you to explore those classes. 59 00:02:56,548 --> 00:03:00,120 Within the MessagingActivity, I've set the adapter on the recycler view and 60 00:03:00,120 --> 00:03:01,890 wired up the button to send a message and 61 00:03:01,890 --> 00:03:04,530 the edit text to send a message when a user clicks the Enter button. 62 00:03:06,280 --> 00:03:09,790 Currently, the activity will show a toast when we attempt to send a message, but 63 00:03:09,790 --> 00:03:12,180 we will update that behavior soon. 64 00:03:12,180 --> 00:03:15,480 There are also methods below for clearing a text of the edit text, 65 00:03:15,480 --> 00:03:18,620 hiding the keyboard, and scrolling to the most recent message. 66 00:03:18,620 --> 00:03:19,920 Those methods are all simply for 67 00:03:19,920 --> 00:03:23,390 a better user experience and certainly aren't required by Firebase. 68 00:03:23,390 --> 00:03:26,120 Let's run the starter project and see what it looks like. 69 00:03:26,120 --> 00:03:29,380 I'm going to comment out the Firebase annotation on our Message class since 70 00:03:29,380 --> 00:03:32,120 I haven't yet included the Firebase library in this project. 71 00:03:32,120 --> 00:03:33,700 But, again, we'll fix that very soon. 72 00:03:35,560 --> 00:03:38,923 When you run this project, you'll first see the username entry screen. 73 00:03:44,400 --> 00:03:45,746 After you provide a username, 74 00:03:45,746 --> 00:03:49,590 you'll see a screen where a list of messages will eventually be displayed. 75 00:03:49,590 --> 00:03:52,239 For now, if we type a message and hit send. 76 00:03:59,242 --> 00:04:02,710 We'll see that the message goes away, but isn't actually sent anywhere. 77 00:04:02,710 --> 00:04:06,044 In the next video, we'll learn how to create a Firebase project in the Firebase 78 00:04:06,044 --> 00:04:09,510 console, taking the first step to sending your message to everyone in real time.