1
00:00:00,265 --> 00:00:03,682
(bright piano key notes)

2
00:00:05,060 --> 00:00:07,590
Alright so we've changed our layout to allow

3
00:00:07,590 --> 00:00:10,470
the edited fragment to be displayed where we need it.

4
00:00:10,470 --> 00:00:13,400
But there's still some work to do before it's fully working.

5
00:00:13,400 --> 00:00:15,160
You can run the app to make sure we haven't made

6
00:00:15,160 --> 00:00:16,660
any mistakes in the layout.

7
00:00:16,660 --> 00:00:20,150
Firstly though, we need to fix the error in main activity.

8
00:00:20,150 --> 00:00:23,730
Now the error is actually in the task edit request function

9
00:00:23,730 --> 00:00:25,470
and you may need to rebuild the project

10
00:00:25,470 --> 00:00:28,150
to get Android Studio to highlight that for you.

11
00:00:28,150 --> 00:00:30,210
And you can see that I'm not showing an error currently.

12
00:00:30,210 --> 00:00:32,990
So if I do that, I can rebuild the project.

13
00:00:32,990 --> 00:00:34,340
Just fast forward this bit.

14
00:00:37,810 --> 00:00:39,980
Okay so you can see that there's no more error there,

15
00:00:39,980 --> 00:00:42,610
now that we have rebuilt the project.

16
00:00:42,610 --> 00:00:44,440
And the problem there is that we've

17
00:00:44,440 --> 00:00:48,100
called our frame layer task_details_container,

18
00:00:48,100 --> 00:00:50,493
so that's the ID we should be using here.

19
00:00:50,493 --> 00:00:52,281
So I'm just going to delete that, that should be

20
00:00:52,281 --> 00:00:54,198
task_details_container.

21
00:00:55,410 --> 00:00:58,290
Before I continue, there seems to be a slight problem

22
00:00:58,290 --> 00:01:01,040
at the moment, and you may get an error with the

23
00:01:01,040 --> 00:01:04,129
tool power reference in onCreate,

24
00:01:04,129 --> 00:01:05,860
that's the code on line 17.

25
00:01:05,860 --> 00:01:07,870
If you haven't got an error, which I haven't,

26
00:01:07,870 --> 00:01:11,600
comment out the synthetic import on line eight,

27
00:01:11,600 --> 00:01:12,610
to see what I'm talking about.

28
00:01:12,610 --> 00:01:14,190
So I'm just going to comment that out.

29
00:01:14,190 --> 00:01:17,720
Sometimes Android Studio doesn't recognise the static import

30
00:01:17,720 --> 00:01:20,260
and will add another import, and I'm just gonna bring that

31
00:01:20,260 --> 00:01:23,423
up on the screen and show you the potential two imports.

32
00:01:24,600 --> 00:01:26,330
So sometimes you might see that this other one

33
00:01:26,330 --> 00:01:29,330
will be imported automatically.

34
00:01:29,330 --> 00:01:30,800
If I click on that to add it,

35
00:01:30,800 --> 00:01:32,660
you'll then get this weird error there.

36
00:01:32,660 --> 00:01:35,860
So the error is now showing Type mismatch Required: Toolbar?

37
00:01:35,860 --> 00:01:37,840
Safe operator found int.

38
00:01:37,840 --> 00:01:40,430
So if you get strange errors like that when your code

39
00:01:40,430 --> 00:01:43,060
was working fine, rebuild the project.

40
00:01:43,060 --> 00:01:45,490
That will often fix it, although you might have to use the

41
00:01:45,490 --> 00:01:48,750
File, Invalidate caches/Restart option first.

42
00:01:48,750 --> 00:01:49,603
This one up here.

43
00:01:52,270 --> 00:01:53,800
But also check your imports as well.

44
00:01:53,800 --> 00:01:55,110
That's annoying that it does happen,

45
00:01:55,110 --> 00:01:58,090
but bugs like this do tend to be fixed quite quickly.

46
00:01:58,090 --> 00:01:59,670
But I'm going to undo those two changes since

47
00:01:59,670 --> 00:02:01,860
I didn't really originally have that error.

48
00:02:01,860 --> 00:02:03,490
So you go back to the original import

49
00:02:03,490 --> 00:02:05,530
and the error disappears.

50
00:02:05,530 --> 00:02:06,970
Right, so moving on now let's actually run

51
00:02:06,970 --> 00:02:08,793
our application in portrait mode.

52
00:02:15,380 --> 00:02:17,630
Alright, so at this point with our app running

53
00:02:17,630 --> 00:02:19,910
you can see that we've got no task selected at the moment.

54
00:02:19,910 --> 00:02:20,743
So if you come over here

55
00:02:20,743 --> 00:02:22,883
and click on the plus in the toolbar,

56
00:02:23,860 --> 00:02:25,900
and you can see now a task and a request function

57
00:02:25,900 --> 00:02:29,470
adds the Add Edit fragment to the frame layout.

58
00:02:29,470 --> 00:02:31,410
This isn't quite what we want,

59
00:02:31,410 --> 00:02:33,050
but we've still got some code to write.

60
00:02:33,050 --> 00:02:36,140
At the moment, we can see that the layout seems to be okay.

61
00:02:36,140 --> 00:02:39,013
If you rotate the emulator now into our landscape mode,

62
00:02:41,070 --> 00:02:43,640
and you can see that's the correct effect that we wanted.

63
00:02:43,640 --> 00:02:45,140
So we've got the task on the left,

64
00:02:45,140 --> 00:02:47,380
which will ultimately be the task list,

65
00:02:47,380 --> 00:02:50,780
and the details for a new task on the right hand side.

66
00:02:50,780 --> 00:02:53,073
Now switching back to portrait mode again now.

67
00:02:54,350 --> 00:02:57,420
That'll look fine if we can hide the left hand fragment.

68
00:02:57,420 --> 00:02:59,120
We also need to show it again,

69
00:02:59,120 --> 00:03:01,730
after we've finished adding the task.

70
00:03:01,730 --> 00:03:03,300
When we do finish the editing,

71
00:03:03,300 --> 00:03:06,080
we also need to remove the Add Edit fragment

72
00:03:06,080 --> 00:03:07,600
from the right hand pane.

73
00:03:07,600 --> 00:03:09,880
We need to do that in portrait to make room for

74
00:03:09,880 --> 00:03:12,720
the task list again and also in landscape.

75
00:03:12,720 --> 00:03:14,370
And I'll rotate the device again.

76
00:03:16,260 --> 00:03:17,800
We need to then remove the right hand fragment

77
00:03:17,800 --> 00:03:19,190
in landscape as well.

78
00:03:19,190 --> 00:03:22,010
We won't hide the frame layout in landscape,

79
00:03:22,010 --> 00:03:24,530
we'll just remove the fragment from it.

80
00:03:24,530 --> 00:03:27,940
That way, the task list will only occupy half the screen.

81
00:03:27,940 --> 00:03:31,540
The right hand side is reserved for the task details.

82
00:03:31,540 --> 00:03:34,290
So, there's at least three places where we need to remove

83
00:03:34,290 --> 00:03:35,590
the Add Edit fragment.

84
00:03:35,590 --> 00:03:37,620
Obviously when the user taps the save button,

85
00:03:37,620 --> 00:03:41,260
and they won't want the details to remain.

86
00:03:41,260 --> 00:03:44,150
But they may also cancel editing by tapping either the

87
00:03:44,150 --> 00:03:45,910
back or up buttons.

88
00:03:45,910 --> 00:03:48,160
Rather than duplicating code each time,

89
00:03:48,160 --> 00:03:51,110
I'm going to create a function to remove the fragment

90
00:03:51,110 --> 00:03:53,630
and deal with hiding and showing the frame.

91
00:03:53,630 --> 00:03:54,860
Let's go ahead and do that.

92
00:03:54,860 --> 00:03:57,710
I'm going to put that just after the onCreate method

93
00:03:57,710 --> 00:04:00,190
here in our main activity class.

94
00:04:00,190 --> 00:04:05,190
So, private fun removeEditPane, parenthesis fragment, colon

95
00:04:11,610 --> 00:04:14,870
fragment with a capital F, and in the save call operator

96
00:04:14,870 --> 00:04:16,170
question mark equals null.

97
00:04:18,029 --> 00:04:19,410
If you're asked to confirm the import,

98
00:04:19,410 --> 00:04:21,310
which I am here because there's two of them,

99
00:04:21,310 --> 00:04:23,280
make sure you select the support version,

100
00:04:23,280 --> 00:04:27,113
in this case android.support.v4.app.Fragment.

101
00:04:28,480 --> 00:04:31,760
So you wouldn't want to select the frame cast version there.

102
00:04:31,760 --> 00:04:32,890
Alright so let's start with a log.

103
00:04:32,890 --> 00:04:37,890
So Log.d, parenthesis TAG comma removeEditPane called.

104
00:04:42,716 --> 00:04:44,250
Then we are gonna start with if parenthesis

105
00:04:44,250 --> 00:04:48,953
fragment is not equal to null, and the code blocker

106
00:04:50,120 --> 00:04:54,470
is going to be supportFragmentManager.beginTransaction.

107
00:04:54,470 --> 00:04:58,113
On the next line, .remove parenthesis fragment,

108
00:04:59,850 --> 00:05:01,653
and on the next line, .commit.

109
00:05:04,000 --> 00:05:05,550
Next, start another code block.

110
00:05:07,820 --> 00:05:09,270
First thing you want to set the visibility

111
00:05:09,270 --> 00:05:10,210
of the right hand pane.

112
00:05:10,210 --> 00:05:12,563
So I'm going to add a current to that effect.

113
00:05:13,490 --> 00:05:17,503
I set the visibility of the right hand pane,

114
00:05:19,310 --> 00:05:20,495
and we'll do that by typing

115
00:05:20,495 --> 00:05:25,495
task_details_container.visibility, set that equal to

116
00:05:26,390 --> 00:05:30,387
if parenthesis mTwoPane, then it's going to be

117
00:05:31,760 --> 00:05:36,760
View.INVISIBLE else View.GONE.

118
00:05:39,510 --> 00:05:42,560
So I'm going to import the android.view.view first,

119
00:05:42,560 --> 00:05:44,548
that's at the top one there.

120
00:05:44,548 --> 00:05:47,320
Now in terms of this mTwoPane, we also need to set up

121
00:05:47,320 --> 00:05:51,020
a variable for that too, so this is gonna actually track

122
00:05:51,020 --> 00:05:53,740
whether our app's running in portrait or landscape mode.

123
00:05:53,740 --> 00:05:55,150
So let's go ahead and add that up here

124
00:05:55,150 --> 00:05:56,783
to our main activity class.

125
00:05:57,780 --> 00:05:59,630
We'll just put a note here to the effect of

126
00:05:59,630 --> 00:06:04,630
whether or not the activity is in two pane mode,

127
00:06:06,800 --> 00:06:09,653
i.e, running in landscape or on a tablet.

128
00:06:14,760 --> 00:06:19,073
And the definition will be private var mTwoPane,

129
00:06:20,340 --> 00:06:22,140
it will set that initially to false.

130
00:06:23,260 --> 00:06:26,380
That obviously fixes up the error now in remove edit pane.

131
00:06:26,380 --> 00:06:28,610
So continuing with that, so first thing, we've set

132
00:06:28,610 --> 00:06:31,390
the visibility of the right hand pane there.

133
00:06:31,390 --> 00:06:33,060
And then the line after that they want to

134
00:06:33,060 --> 00:06:34,490
show the left hand pane.

135
00:06:34,490 --> 00:06:39,320
Okay, add a comment here and show the left hand pane.

136
00:06:40,630 --> 00:06:44,890
And it's gonna be mainFragment.view

137
00:06:44,890 --> 00:06:47,127
safe call operator, which is a question mark,

138
00:06:47,127 --> 00:06:51,253
.visibility is equal to View.VISIBLE.

139
00:06:52,770 --> 00:06:57,090
task_details_container may also need its import

140
00:06:57,090 --> 00:06:59,600
to be specified. We want the synthetic import

141
00:06:59,600 --> 00:07:01,630
and definitely not the entry source.

142
00:07:01,630 --> 00:07:04,223
Alright, so back to our removeEditPane function.

143
00:07:05,743 --> 00:07:08,110
If you ever pass, then you can see a fragment reference,

144
00:07:08,110 --> 00:07:09,730
or the fragment reference,

145
00:07:09,730 --> 00:07:11,720
rather than finding it in this function,

146
00:07:11,720 --> 00:07:14,630
that probably isn't an obvious thing to do at this stage.

147
00:07:14,630 --> 00:07:16,200
I don't want to give the impression that code

148
00:07:16,200 --> 00:07:18,500
is written perfectly the first time.

149
00:07:18,500 --> 00:07:21,690
While developing this app, the natural thing to do here

150
00:07:21,690 --> 00:07:25,480
was to find the fragment inside the removeEditPane function.

151
00:07:25,480 --> 00:07:27,110
So the earlier version of this function

152
00:07:27,110 --> 00:07:28,930
did something along these lines.

153
00:07:28,930 --> 00:07:32,010
On this line, before the quote test for null,

154
00:07:32,010 --> 00:07:36,190
we did something like var fragment is equal to

155
00:07:37,230 --> 00:07:39,830
supportFragmentManager.findFragmentByID

156
00:07:41,264 --> 00:07:45,170
and then parenthesis R.ID.task_details_container.

157
00:07:46,630 --> 00:07:48,450
Now that's fine and it works.

158
00:07:48,450 --> 00:07:51,190
As we develop the app, you'll notice that, most of the time,

159
00:07:51,190 --> 00:07:54,530
we get a reference to the fragment before removing it.

160
00:07:54,530 --> 00:07:57,840
The only time we don't is when the save button's tapped.

161
00:07:57,840 --> 00:08:00,270
So it makes sense to pass in the fragment reference

162
00:08:00,270 --> 00:08:03,260
that we've already got, rather than finding it again.

163
00:08:03,260 --> 00:08:05,582
Calls like findVYID, and this one,

164
00:08:05,582 --> 00:08:08,750
findFragmentByID are quite expensive.

165
00:08:08,750 --> 00:08:10,510
They use a lot of processing time.

166
00:08:10,510 --> 00:08:13,240
If we can reduce the number of times we do that,

167
00:08:13,240 --> 00:08:15,740
we save the users battery on their Android device,

168
00:08:17,115 --> 00:08:18,630
and that's always a good thing.

169
00:08:18,630 --> 00:08:20,280
So we're gonna cut that line out,

170
00:08:22,160 --> 00:08:23,203
and we're gonna paste it into the

171
00:08:23,203 --> 00:08:25,420
onSaveClicked function instead.

172
00:08:25,420 --> 00:08:27,220
One that we haven't yet implemented.

173
00:08:28,100 --> 00:08:29,023
Paste it in there.

174
00:08:30,500 --> 00:08:32,830
Alright, so back to removeEditPane.

175
00:08:32,830 --> 00:08:35,000
It checks to see if the frame isn't null,

176
00:08:35,000 --> 00:08:37,320
and then it removes it, if it isn't.

177
00:08:37,320 --> 00:08:39,030
Next we have to decide whether to show

178
00:08:39,030 --> 00:08:41,539
or hide the task details frame.

179
00:08:41,539 --> 00:08:45,010
Now if we're in landscape, mTwoPane will be true.

180
00:08:45,010 --> 00:08:48,090
In that case, we set the frame to invisible.

181
00:08:48,090 --> 00:08:50,030
This is the code on line 37.

182
00:08:50,030 --> 00:08:54,000
Otherwise, in portrait, we set the frame to gone.

183
00:08:54,000 --> 00:08:55,690
These two settings are very similar.

184
00:08:55,690 --> 00:08:58,700
Invisible makes the widget, the frame layout in this case,

185
00:08:58,700 --> 00:09:00,890
invisible. Gone does the same thing.

186
00:09:00,890 --> 00:09:04,050
The difference is that invisible still reserves space

187
00:09:04,050 --> 00:09:07,040
in the display, whereas gone doesn't.

188
00:09:07,040 --> 00:09:09,720
If you use gone, the frame won't take up any space.

189
00:09:09,720 --> 00:09:12,120
That's what we want in portrait, because it allows the

190
00:09:12,120 --> 00:09:14,370
main fragment to fill the screen.

191
00:09:14,370 --> 00:09:16,690
In landscape, the frame won't be visible,

192
00:09:16,690 --> 00:09:19,360
but it still takes up space on the screen.

193
00:09:19,360 --> 00:09:21,773
Alright, and then that last line, line 39,

194
00:09:21,773 --> 00:09:23,830
makes sure that the main fragment,

195
00:09:23,830 --> 00:09:26,580
the task list in this case, is visible again.

196
00:09:26,580 --> 00:09:29,090
Now we have to use the save call operator there,

197
00:09:29,090 --> 00:09:31,130
which may seem a bit strange.

198
00:09:31,130 --> 00:09:36,070
The task_details_container on the line above, line 37,

199
00:09:36,070 --> 00:09:39,010
is part of our layout and can't be null.

200
00:09:39,010 --> 00:09:41,490
Main fragment also can't be null.

201
00:09:41,490 --> 00:09:43,400
That's the fragment widget in the layout.

202
00:09:43,400 --> 00:09:45,930
Fragments don't have to have layouts, though.

203
00:09:45,930 --> 00:09:48,630
You can create a fragment that just does things,

204
00:09:48,630 --> 00:09:50,720
rather than displaying things.

205
00:09:50,720 --> 00:09:53,610
So, in that case, the fragment doesn't have a view,

206
00:09:53,610 --> 00:09:55,940
which is why we have to use the save call operator

207
00:09:55,940 --> 00:09:57,010
when making it visible.

208
00:09:57,010 --> 00:09:59,750
We haven't edited the code to make it invisible yet,

209
00:09:59,750 --> 00:10:02,500
but let's actually see if our function works first.

210
00:10:02,500 --> 00:10:05,810
And we can call that in the onSaveClicked method.

211
00:10:05,810 --> 00:10:08,230
So let's add some logging to that.

212
00:10:08,230 --> 00:10:11,730
I set method.function, so Log.d parenthesis TAG

213
00:10:11,730 --> 00:10:16,730
comma double quote onSavedClicked colon called.

214
00:10:17,612 --> 00:10:21,020
We go to our R fragment line to find our fragment.

215
00:10:21,020 --> 00:10:23,850
And let's try calling our method removeEditPane

216
00:10:23,850 --> 00:10:25,980
parsing in fragment.

217
00:10:25,980 --> 00:10:27,560
So obviously that's gonna occur

218
00:10:27,560 --> 00:10:30,800
when the save button's clicked.

219
00:10:30,800 --> 00:10:33,450
So basically the activity removes the fragment

220
00:10:33,450 --> 00:10:35,520
when the user taps the save button.

221
00:10:35,520 --> 00:10:38,510
So the last thing we now need to do to test this, is to

222
00:10:38,510 --> 00:10:41,800
call this onSaveClicked function from the fragment.

223
00:10:41,800 --> 00:10:45,410
So in Add Edit Fragment, we're going to

224
00:10:45,410 --> 00:10:47,720
add a listener to the save button.

225
00:10:47,720 --> 00:10:50,860
So you may try to add that to the onCreate function,

226
00:10:50,860 --> 00:10:53,770
and as we haven't discussed the fragment life cycle yet,

227
00:10:53,770 --> 00:10:56,320
that may well be where you'd expect it to go.

228
00:10:56,320 --> 00:10:58,780
But I'm going to override the

229
00:10:58,780 --> 00:11:01,170
onActivityCreated function instead.

230
00:11:01,170 --> 00:11:04,610
Now that function is called after onCreate and we'll see

231
00:11:04,610 --> 00:11:07,500
how this fits into the activity lifecycle soon.

232
00:11:07,500 --> 00:11:09,120
Very briefly though, let's have a look at that

233
00:11:09,120 --> 00:11:12,260
fragment life cycle diagram and let's go quickly

234
00:11:12,260 --> 00:11:13,510
bring up our guide there.

235
00:11:18,520 --> 00:11:20,990
If we move down a little bit to the creating a fragment

236
00:11:20,990 --> 00:11:23,860
section, you can see over here to the right hand side,

237
00:11:23,860 --> 00:11:26,980
there's a diagram there outlining what happens.

238
00:11:26,980 --> 00:11:29,530
That's very similar to the activity life cycle,

239
00:11:29,530 --> 00:11:31,920
but it has got a few extra functions.

240
00:11:31,920 --> 00:11:33,570
The ones we're interested in at the moment are

241
00:11:33,570 --> 00:11:37,880
onCreate(), onCreateView(), and onActivtityCreated().

242
00:11:37,880 --> 00:11:40,420
Now, we'll look at these in more detail soon.

243
00:11:40,420 --> 00:11:42,980
What's important now, is that onCreate is called

244
00:11:42,980 --> 00:11:45,960
before the onCreateView function.

245
00:11:45,960 --> 00:11:47,770
So why is that important?

246
00:11:47,770 --> 00:11:50,483
Well, go back to our Add Edit Fragment code.

247
00:11:52,006 --> 00:11:54,180
We can see here that the layout for the fragment

248
00:11:54,180 --> 00:11:58,950
is inflated in onCreateView. That's the code on line 41.

249
00:11:58,950 --> 00:12:01,636
Until then, we can't access any of the widgets

250
00:12:01,636 --> 00:12:03,690
in our fragments layout.

251
00:12:03,690 --> 00:12:06,150
Attempting to attach a listener to any button

252
00:12:06,150 --> 00:12:08,290
in onCreate just won't work,

253
00:12:08,290 --> 00:12:10,640
and that's because we don't yet have a button.

254
00:12:10,640 --> 00:12:13,240
Now, when you first start dealing with fragment layouts,

255
00:12:13,240 --> 00:12:15,000
rather than activity layouts,

256
00:12:15,000 --> 00:12:17,500
things like that aren't obvious.

257
00:12:17,500 --> 00:12:20,090
It makes perfect sense that you can't access the widgets

258
00:12:20,090 --> 00:12:22,660
until the layout's been inflated from the XML,

259
00:12:22,660 --> 00:12:25,460
but it's an easy thing to overlook first.

260
00:12:25,460 --> 00:12:28,320
Alright, so I'm going to override the onActivityCreated

261
00:12:28,320 --> 00:12:30,510
function and I'm gonna get Android Studio

262
00:12:30,510 --> 00:12:33,853
to do that just after the onCreateView function.

263
00:12:35,780 --> 00:12:37,843
So onActivityCreated is the one we want.

264
00:12:39,858 --> 00:12:41,508
Override that.

265
00:12:41,508 --> 00:12:43,030
We're going to add some logging.

266
00:12:43,030 --> 00:12:46,405
Log.D parenthesis TAG comma double quotes

267
00:12:46,405 --> 00:12:48,488
onActivityCreated starts.

268
00:12:54,090 --> 00:12:56,950
I've got a super call which I'm going to leave in.

269
00:12:56,950 --> 00:13:00,983
And we're going to do addedit_save.setOnClickListener.

270
00:13:06,740 --> 00:13:07,640
And within there we're gonna add a

271
00:13:07,640 --> 00:13:09,800
left to right curly brace.

272
00:13:09,800 --> 00:13:11,690
And the actual code is gonna be listener,

273
00:13:11,690 --> 00:13:14,533
safe call operator.onSaveClicked.

274
00:13:16,552 --> 00:13:18,810
And you can see we've got a closing right curly brace

275
00:13:18,810 --> 00:13:21,600
and a closing right parenthesis.

276
00:13:21,600 --> 00:13:23,200
And, again, you want to make sure that you choose

277
00:13:23,200 --> 00:13:26,670
the synthetic import, if Android Studio offers a choice

278
00:13:26,670 --> 00:13:28,790
for the AddEdit_save button.

279
00:13:28,790 --> 00:13:30,210
We have to look at our imports.

280
00:13:30,210 --> 00:13:32,440
You can see it's added that for me automatically,

281
00:13:32,440 --> 00:13:34,470
but make sure you do choose the right one,

282
00:13:34,470 --> 00:13:36,273
if you are prompted to import.

283
00:13:38,640 --> 00:13:41,470
All the onClickListed does at the moment, as you can see,

284
00:13:41,470 --> 00:13:43,890
is call the activities onSaveClicked function

285
00:13:43,890 --> 00:13:46,550
that we've added. That code on line 50.

286
00:13:46,550 --> 00:13:48,380
We'll be adding more code in here later.

287
00:13:48,380 --> 00:13:50,940
We need to save the cast details, but for now we're

288
00:13:50,940 --> 00:13:53,500
just getting the fragments working.

289
00:13:53,500 --> 00:13:56,850
Android Studio's offering a suggestion to tidy the code up.

290
00:13:56,850 --> 00:14:01,210
The parenthesis around the listener block are redundant,

291
00:14:01,210 --> 00:14:03,110
so I come over here and click on that.

292
00:14:04,170 --> 00:14:07,430
We can use the option here to

293
00:14:07,430 --> 00:14:09,666
move lambda argument out of parenthesis.

294
00:14:09,666 --> 00:14:11,230
If I do that, you can see that it's

295
00:14:11,230 --> 00:14:13,400
removed the parenthesis for us.

296
00:14:13,400 --> 00:14:15,854
Notice also that we have to use the save call operator

297
00:14:15,854 --> 00:14:18,430
after listener on line 50.

298
00:14:18,430 --> 00:14:21,120
The activity can be destroyed, and attempting to

299
00:14:21,120 --> 00:14:24,450
call its functions after it's destroyed won't go well.

300
00:14:24,450 --> 00:14:26,720
Alright, the app should now run.

301
00:14:26,720 --> 00:14:28,163
So let's run this now.

302
00:14:32,160 --> 00:14:33,480
I'm just gonna open Logcat as well,

303
00:14:33,480 --> 00:14:35,410
so I can see what's going on.

304
00:14:35,410 --> 00:14:36,243
Have a look at that app.

305
00:14:36,243 --> 00:14:38,880
Now we're still in landscape mode, as you can see there.

306
00:14:38,880 --> 00:14:43,000
Tapping on the plus button displays the

307
00:14:43,000 --> 00:14:44,627
details fragment to add a new task.

308
00:14:44,627 --> 00:14:47,293
Now if I come down here and click on the save button,

309
00:14:48,627 --> 00:14:51,040
and again the fragment was removed from the display.

310
00:14:51,040 --> 00:14:52,950
In the Logcat down here, we can see that

311
00:14:52,950 --> 00:14:55,420
onSaveClicked was called.

312
00:14:55,420 --> 00:14:58,090
That call was removeEditPane and the fragments

313
00:14:58,090 --> 00:15:00,710
onDetach function got called there, as you can see,

314
00:15:00,710 --> 00:15:04,210
when the fragments removed from the activity.

315
00:15:04,210 --> 00:15:05,800
Should work the same in portrait,

316
00:15:05,800 --> 00:15:07,900
so I'll go back to portrait mode here now.

317
00:15:09,310 --> 00:15:11,963
Tap the plus button to display the fragment,

318
00:15:13,300 --> 00:15:17,910
then tap save again, and it's actually removed.

319
00:15:17,910 --> 00:15:20,050
Incidentally, this doesn't work for a second time,

320
00:15:20,050 --> 00:15:21,600
because we've now hidden the frame layer.

321
00:15:21,600 --> 00:15:25,230
So if I tap on the plus again, you can see that

322
00:15:25,230 --> 00:15:27,360
nothing seems to happen on the screen.

323
00:15:27,360 --> 00:15:29,850
It has actually worked, and you'll see the fragment

324
00:15:29,850 --> 00:15:31,710
when you rotate the device back into landscape,

325
00:15:31,710 --> 00:15:32,610
which I'll do now.

326
00:15:34,100 --> 00:15:35,610
There's the fragment showing up.

327
00:15:35,610 --> 00:15:37,420
So we've still got a bit of work to do,

328
00:15:37,420 --> 00:15:40,720
but the basic functionality is now working.

329
00:15:40,720 --> 00:15:42,970
In the next video, we'll finish up this display,

330
00:15:42,970 --> 00:15:44,360
so that it works properly

331
00:15:44,360 --> 00:15:46,690
in both portrait and landscape mode.

332
00:15:46,690 --> 00:15:47,990
See you in the next video.

