1 00:00:00,311 --> 00:00:04,878 [MUSIC] 2 00:00:04,878 --> 00:00:07,000 Fantastic work so far. 3 00:00:07,000 --> 00:00:09,050 We've set up our adapter and our view holder, 4 00:00:09,050 --> 00:00:12,930 and we're getting some sample static data displayed in our RecyclerView. 5 00:00:12,930 --> 00:00:14,620 That's pretty exciting, right? 6 00:00:14,620 --> 00:00:15,760 We're getting super close. 7 00:00:16,940 --> 00:00:19,110 We have a little bit of formatting to do, 8 00:00:19,110 --> 00:00:22,750 much in the same way that we had to format data in main activity. 9 00:00:22,750 --> 00:00:26,590 We also need to convert the icon string that Dark Sky provides us 10 00:00:26,590 --> 00:00:27,510 to our icon name. 11 00:00:28,550 --> 00:00:32,880 Once we get this formatting done, we'll get it connected to our actual data model. 12 00:00:32,880 --> 00:00:36,450 Let's head back into Android Studio and tackle these next tasks. 13 00:00:37,570 --> 00:00:38,830 In the Hour class, 14 00:00:38,830 --> 00:00:42,660 let's update the getTime method to display our time properly. 15 00:00:42,660 --> 00:00:47,065 We'll be returning the string value now, so we'll need to change that. 16 00:00:47,065 --> 00:00:50,969 So here under getTime, change this to String. 17 00:00:55,106 --> 00:00:59,440 Inside here, we'll use the simple date formatter to format the time. 18 00:00:59,440 --> 00:01:04,010 SimpleDateFormat, we'll call it formatter, so new SimpleDateFormat. 19 00:01:05,120 --> 00:01:06,730 We'll pass in our pattern. 20 00:01:06,730 --> 00:01:10,710 For our purposes, we just want the hour and AM or PM. 21 00:01:10,710 --> 00:01:12,422 So we'll pass in h a. 22 00:01:15,689 --> 00:01:17,960 Check the teacher's notes as well for more on these patterns. 23 00:01:19,070 --> 00:01:21,840 And we need to set the timezone for this formatter. 24 00:01:21,840 --> 00:01:27,150 Otherwise, our calculations will all be based on GMT, or Greenwich Mean Time. 25 00:01:27,150 --> 00:01:30,378 That's why we added the timezone to this class way back when we started. 26 00:01:30,378 --> 00:01:37,520 So formatter.setTimeZone.(TimeZone). 27 00:01:37,520 --> 00:01:40,514 We'll get the TimeZone and here we pass in our TimeZone. 28 00:01:44,759 --> 00:01:48,335 In case you couldn't tell yet, working with dates, times, and 29 00:01:48,335 --> 00:01:53,470 timezones is one of the most frustrating things programmers had to deal with. 30 00:01:53,470 --> 00:01:56,681 Check the teacher's notes for a funny video on it. 31 00:01:56,681 --> 00:02:01,072 So in getTime, we need to convert the time to milliseconds. 32 00:02:01,072 --> 00:02:02,371 You can do that with date. 33 00:02:02,371 --> 00:02:02,871 We'll call it dateTime. 34 00:02:05,310 --> 00:02:06,920 Do our imports. 35 00:02:06,920 --> 00:02:08,609 We want the Java util import. 36 00:02:11,749 --> 00:02:16,737 New Date(time * 1000) convert to milliseconds, and now, 37 00:02:16,737 --> 00:02:19,952 we just need to return our formatted time. 38 00:02:22,388 --> 00:02:24,854 So we turn our formatter and format the time. 39 00:02:28,054 --> 00:02:30,760 The temperature didn't look real great in our app either. 40 00:02:30,760 --> 00:02:33,535 We want to return an int here and not a double. 41 00:02:41,270 --> 00:02:43,800 We want the temperature rounded to get rid of our decimal. 42 00:02:43,800 --> 00:02:50,187 So we can cast to an int and use the Math.round function. 43 00:02:53,172 --> 00:02:56,790 Note that here we're updating this formatting in the data model itself. 44 00:02:56,790 --> 00:03:01,170 We could do this in a layout as well, like we did in the main activity layout. 45 00:03:01,170 --> 00:03:04,250 I just wanted to show you how to do it here for the option. 46 00:03:04,250 --> 00:03:08,585 Now for the icon, we already have the code to get an icon 47 00:03:08,585 --> 00:03:12,087 ID from a string over in our current object. 48 00:03:12,087 --> 00:03:15,621 Let's create a helper method that both current and 49 00:03:15,621 --> 00:03:17,765 hour can call to get that info. 50 00:03:17,765 --> 00:03:18,590 Let's go to the forecast class. 51 00:03:20,250 --> 00:03:22,256 We'll write a new method here at the bottom. 52 00:03:24,133 --> 00:03:27,150 It will be a public static method. 53 00:03:27,150 --> 00:03:28,490 It will return an int. 54 00:03:28,490 --> 00:03:35,080 We'll call it getIconId, and we'll pass in our iconString. 55 00:03:38,123 --> 00:03:38,710 We can go over here to Current. 56 00:03:39,990 --> 00:03:41,754 Grab our long switch statement. 57 00:03:45,242 --> 00:03:47,922 And cut it out of here, and now paste it over into Forecast. 58 00:03:50,678 --> 00:03:55,733 Okay our import for R, and change icon to iconString. 59 00:03:59,098 --> 00:04:02,066 Back over in Current, we can use that method. 60 00:04:02,066 --> 00:04:07,530 You want to return forecast.getIconID, and pass in our icon. 61 00:04:10,820 --> 00:04:14,836 Now over in Hour, under getIcon(), 62 00:04:14,836 --> 00:04:20,070 we want to return Forecast.getIconId(icon), 63 00:04:20,070 --> 00:04:26,655 and we want to change our method signature here to return an int. 64 00:04:29,266 --> 00:04:34,418 Lastly, we need to update our hourly list item layout to use our imagery source for 65 00:04:34,418 --> 00:04:35,100 the icon. 66 00:04:35,100 --> 00:04:44,447 Go to the layout, hourly list item, Come down here to our ImageView. 67 00:04:49,581 --> 00:04:59,062 We'll add app:imageResource="@{hour.icon}". 68 00:05:00,500 --> 00:05:04,810 Okay, let's run this one more time with our sample data and see what we get. 69 00:05:14,020 --> 00:05:19,217 And if we hit Hourly Forecast, nice work. 70 00:05:19,217 --> 00:05:21,670 Our data is coming through and looking great. 71 00:05:21,670 --> 00:05:23,640 Let's take a breather here and come back and 72 00:05:23,640 --> 00:05:26,170 change our static data to the Dark Sky data.