1 00:00:00,530 --> 00:00:03,910 Okay, now that we've converted to using RX Java form, 2 00:00:03,910 --> 00:00:06,640 most of the core functionality of our app lets just kind and 3 00:00:06,640 --> 00:00:09,950 clean up this code a bit and then run it and see it in action. 4 00:00:09,950 --> 00:00:14,810 So, firstly we can do to clean up is we get rid of this completely change listener 5 00:00:14,810 --> 00:00:20,900 which we converted into an observable in the last section. 6 00:00:20,900 --> 00:00:22,160 So let's go and delete that. 7 00:00:23,320 --> 00:00:28,460 And in our main activity what we can do is if you want 8 00:00:28,460 --> 00:00:33,970 you can convert all these to using butterknife which is much easier. 9 00:00:33,970 --> 00:00:35,657 So we can say bind here. 10 00:01:03,179 --> 00:01:08,542 Or to do adapters here so we put all of our views together and 11 00:01:08,542 --> 00:01:13,210 we have our list of data and our adapter down here. 12 00:01:13,210 --> 00:01:17,450 It turns out we don't really need to keep our adapter anywhere else. 13 00:01:17,450 --> 00:01:21,609 The adapter is not being utilized any place else outside of on create. 14 00:01:22,620 --> 00:01:26,250 So what we're gonna do is just make it a local variable. 15 00:01:28,380 --> 00:01:29,516 Let's just move it down to here. 16 00:01:34,927 --> 00:01:38,020 So we're simplifying our main activity. 17 00:01:38,020 --> 00:01:41,380 Has our views, it has our data set, our list. 18 00:01:41,380 --> 00:01:44,890 And it has our subscriptions Let's make sure that we 19 00:01:49,800 --> 00:01:51,880 bind so we can get all those views. 20 00:01:51,880 --> 00:01:59,160 We no longer need to do any of these look ups by ID here or here. 21 00:02:01,310 --> 00:02:03,230 So we're gonna create our list. 22 00:02:03,230 --> 00:02:04,770 And let's go ahead and 23 00:02:04,770 --> 00:02:10,360 add a few items to our list if it's the first time we're in here. 24 00:02:10,360 --> 00:02:17,331 So let's just go ahead down here and add a new todo. 25 00:02:32,174 --> 00:02:37,740 This is just so we can run it later in a minute and see it in action. 26 00:02:37,740 --> 00:02:43,570 We'll also be able to add our own items as well through the UI. 27 00:02:43,570 --> 00:02:48,820 To create our adapter, make sure we set up our recycler view 28 00:02:48,820 --> 00:02:51,790 request focus that's fine. 29 00:02:51,790 --> 00:02:55,910 Do our subscription here, or toolbar we don't need to do this anymore. 30 00:02:55,910 --> 00:02:59,825 Let's go ahead and move this up to the top 31 00:03:05,129 --> 00:03:08,283 We don't need to find our spinner anymore. 32 00:03:11,072 --> 00:03:12,650 We do need to call setAdapter. 33 00:03:13,650 --> 00:03:18,170 And actually the last thing that we're gonna do is we're gonna set the adapter. 34 00:03:22,510 --> 00:03:27,430 And then we also need to set on the spinner the last 35 00:03:27,430 --> 00:03:32,210 selected position so set selection with the position. 36 00:03:32,210 --> 00:03:35,870 So we need to keep track of that filter position. 37 00:03:35,870 --> 00:03:38,200 Let's go ahead and add the ability to do that now. 38 00:03:38,200 --> 00:03:41,690 So up here, we have our list. 39 00:03:41,690 --> 00:03:48,100 And what we wanna do is just add the int for the filter position. 40 00:03:49,440 --> 00:03:51,580 And by default. 41 00:03:51,580 --> 00:03:58,160 It's going to be, all And then we want 42 00:03:58,160 --> 00:04:02,880 to save that across rotation too so let's go ahead and put in a value for that. 43 00:04:04,350 --> 00:04:06,580 This is our key for our bundle. 44 00:04:10,080 --> 00:04:13,450 And we want to make sure that we get that data as well. 45 00:04:13,450 --> 00:04:15,940 So here savings in state is not nul. 46 00:04:15,940 --> 00:04:20,780 We want to go ahead and get our filter positions from our statements and 47 00:04:20,780 --> 00:04:21,440 stay bundle. 48 00:04:26,580 --> 00:04:30,540 And we can supply a default, as well. 49 00:04:33,520 --> 00:04:36,990 And let's make sure we save it in on save instant state. 50 00:04:50,634 --> 00:04:57,190 And what we want here is, we wanna get the item that was currently selected. 51 00:04:57,190 --> 00:05:00,727 So it's getSelectedItemPosition. 52 00:05:07,600 --> 00:05:14,770 Okay so we've just cleaned up some things here and simplified our code a bit. 53 00:05:14,770 --> 00:05:17,550 Let's go ahead and run it and see this happen in action. 54 00:05:24,510 --> 00:05:25,300 Here's the old version. 55 00:05:26,530 --> 00:05:27,690 Let's see it after we clean it up. 56 00:05:32,990 --> 00:05:39,290 Here it is so we have the sample items and we can add another item as well. 57 00:05:41,140 --> 00:05:44,980 And we can check some and select a filter, 58 00:05:47,910 --> 00:05:52,950 and see that our UI dynamically adjusts as we select and check things. 59 00:05:54,990 --> 00:05:58,620 In this workshop, we introduced the concepts of RX Java and 60 00:05:58,620 --> 00:06:02,100 we walked through converting a simple to do app to use it. 61 00:06:02,100 --> 00:06:04,250 With this concept you can move forward and 62 00:06:04,250 --> 00:06:08,120 start using RX Java in many parts of your own apps. 63 00:06:08,120 --> 00:06:12,290 To start using RX Java to manage your networking take a look at retrofit 64 00:06:12,290 --> 00:06:14,250 which supports RX Java out of the box. 65 00:06:15,320 --> 00:06:19,410 If you haven't used retrofit before I've left a link to the retrofit workshop 66 00:06:19,410 --> 00:06:20,470 in the teacher's notes. 67 00:06:21,500 --> 00:06:23,750 Thanks for joining me in this workshop. 68 00:06:23,750 --> 00:06:27,100 I hope RX Java helps you build better android apps. 69 00:06:27,100 --> 00:06:27,750 Will see you soon.