1
00:00:03,859 --> 00:00:06,750
In this section, we're going to create an

2
00:00:06,750 --> 00:00:09,450
app to process an RSS feed, then display

3
00:00:09,450 --> 00:00:11,790
the data on the phone or tablet screen.

4
00:00:11,790 --> 00:00:13,799
Now in the process, we're going to be

5
00:00:13,799 --> 00:00:16,379
looking at the following. So we're going to be

6
00:00:16,379 --> 00:00:18,420
downloading data over the Internet.

7
00:00:18,420 --> 00:00:20,760
We're going to be running tasks in the

8
00:00:20,760 --> 00:00:24,000
background using an AsyncTask, and we're

9
00:00:24,000 --> 00:00:25,170
also going to discuss why you should

10
00:00:25,170 --> 00:00:27,330
actually avoid using AsyncTasks in

11
00:00:27,330 --> 00:00:30,119
Kotlin. Next we're going to be parsing

12
00:00:30,119 --> 00:00:32,520
XML to extract data from a downloaded

13
00:00:32,520 --> 00:00:34,860
feed, and we're going to be using the

14
00:00:34,860 --> 00:00:36,570
ListView widget for displaying a

15
00:00:36,570 --> 00:00:39,450
scrollable list of items, and we'll

16
00:00:39,450 --> 00:00:41,579
be getting familiar with adapters for

17
00:00:41,579 --> 00:00:43,950
providing data to ListViews and also

18
00:00:43,950 --> 00:00:45,899
other objects. And we're also going to

19
00:00:45,899 --> 00:00:48,260
see how to create our own CustomAdapter.

20
00:00:48,260 --> 00:00:50,010
Context is something we're going to be

21
00:00:50,010 --> 00:00:51,600
talking about: what that is, what they are

22
00:00:51,600 --> 00:00:54,239
and why we need them. And then finally,

23
00:00:54,239 --> 00:00:57,410
we're going to be creating a menu for our app.

24
00:00:57,410 --> 00:01:00,530
Ok, so RSS stands for Rich Site Summary

25
00:01:00,530 --> 00:01:04,199
or Really Simple Syndication, but neither

26
00:01:04,199 --> 00:01:05,820
of those are particularly descriptive,

27
00:01:05,820 --> 00:01:08,070
and the term RSS is probably more

28
00:01:08,070 --> 00:01:11,070
informative these days. So RSS is a way

29
00:01:11,070 --> 00:01:14,070
to present web data in a standard format,

30
00:01:14,070 --> 00:01:16,650
so that users can subscribe to the RSS

31
00:01:16,650 --> 00:01:19,470
feed and receive updates automatically.

32
00:01:19,470 --> 00:01:22,200
Now data isn't pushed out from other

33
00:01:22,200 --> 00:01:24,390
websites, though. It's the responsibility

34
00:01:24,390 --> 00:01:27,119
of the feed reader program to monitor

35
00:01:27,119 --> 00:01:29,070
the site and pull down updated

36
00:01:29,070 --> 00:01:32,280
information, as it changes. So we're gonna

37
00:01:32,280 --> 00:01:33,840
start off now by having a look at an

38
00:01:33,840 --> 00:01:36,540
RSS feed. Now if you haven't seen them

39
00:01:36,540 --> 00:01:39,479
before, they're actually very common. Now

40
00:01:39,479 --> 00:01:41,759
you can find RSS feeds on just about any

41
00:01:41,759 --> 00:01:44,070
subject you care to think of, by searching

42
00:01:44,070 --> 00:01:46,259
online. And, in fact, we're going to do

43
00:01:46,259 --> 00:01:47,369
just that. We're going to switch over

44
00:01:47,369 --> 00:01:49,829
now to a browser. In fact, we're going to

45
00:01:49,829 --> 00:01:51,450
do that now and I've got my browser open.

46
00:01:51,450 --> 00:01:53,750
So I'm going to do a search for Apple

47
00:01:53,750 --> 00:01:59,189
RSS feed, and the first result that comes

48
00:01:59,189 --> 00:02:02,939
up here is for Apple.com slash RSS, or

49
00:02:02,939 --> 00:02:04,710
depending on your country, it might also

50
00:02:04,710 --> 00:02:06,030
have the country. In my case, it's got

51
00:02:06,030 --> 00:02:08,128
slash AU. But in any event, I'm going to

52
00:02:08,128 --> 00:02:10,679
click on that, and that actually gives us

53
00:02:10,679 --> 00:02:13,860
a list of all the public RSS feeds that

54
00:02:13,860 --> 00:02:16,470
Apple maintain. Now there's a lot of

55
00:02:16,470 --> 00:02:18,120
feeds with information from the iTunes

56
00:02:18,120 --> 00:02:20,670
Store, so you can get lists of the top 10,

57
00:02:20,670 --> 00:02:23,520
or 25, songs or albums, and the top apps -

58
00:02:23,520 --> 00:02:25,770
both paid and free - as well as

59
00:02:25,770 --> 00:02:27,870
information on movies and TV programs.

60
00:02:27,870 --> 00:02:30,000
And as you can see, there's even

61
00:02:30,000 --> 00:02:31,620
information that you can get on the

62
00:02:31,620 --> 00:02:33,840
latest press releases; news that might be

63
00:02:33,840 --> 00:02:35,360
of interest to developers and even

64
00:02:35,360 --> 00:02:38,370
documentation. Now keep in mind that the

65
00:02:38,370 --> 00:02:40,670
RSS itself is not the full information.

66
00:02:40,670 --> 00:02:43,920
It generally contains a summary, and was

67
00:02:43,920 --> 00:02:46,140
intended as a way to get notifications

68
00:02:46,140 --> 00:02:48,360
of changes, to the content of sites that

69
00:02:48,360 --> 00:02:49,920
you might be interested in, without

70
00:02:49,920 --> 00:02:51,360
having to keep visiting the sites in

71
00:02:51,360 --> 00:02:52,620
your browser to see if something's

72
00:02:52,620 --> 00:02:54,750
changed. Now we're going to be working

73
00:02:54,750 --> 00:02:57,330
with the top 10 free apps - that's this

74
00:02:57,330 --> 00:02:59,850
link, this RSS feed over here. But once

75
00:02:59,850 --> 00:03:01,230
you've got the app working with that,

76
00:03:01,230 --> 00:03:02,940
you'll actually be able to modify it to

77
00:03:02,940 --> 00:03:05,160
use any of these feeds you can see, or in

78
00:03:05,160 --> 00:03:07,410
fact, any RSS feed you want, anywhere on

79
00:03:07,410 --> 00:03:09,510
the Internet. So the app that we're

80
00:03:09,510 --> 00:03:11,040
going to be creating in this section of

81
00:03:11,040 --> 00:03:12,570
the course, is going to read the data

82
00:03:12,570 --> 00:03:16,470
from the top 10 free apps feed. It'll

83
00:03:16,470 --> 00:03:18,330
then decipher the contents, so that we

84
00:03:18,330 --> 00:03:19,890
can display selected bits of the

85
00:03:19,890 --> 00:03:21,660
information on the screen.

86
00:03:21,660 --> 00:03:23,190
So let's actually have a look at the

87
00:03:23,190 --> 00:03:24,420
contents, to see what we're going to be

88
00:03:24,420 --> 00:03:25,950
working with. So I'm going to click on

89
00:03:25,950 --> 00:03:28,799
the top 10 free apps link here, and the

90
00:03:28,799 --> 00:03:31,019
feed will load in the browser. Now if

91
00:03:31,019 --> 00:03:32,730
you're using Google's Chrome browser, as

92
00:03:32,730 --> 00:03:34,890
I'm using here, you can see that it shows

93
00:03:34,890 --> 00:03:38,430
raw XML rather than a formatted display.

94
00:03:38,430 --> 00:03:40,350
What I'm also going to do, though, is start up

95
00:03:40,350 --> 00:03:42,989
Firefox. I want to show you what the

96
00:03:42,989 --> 00:03:44,519
equivalent thing looks like in Firefox

97
00:03:44,519 --> 00:03:47,160
as well. We'll just go back to chrome

98
00:03:47,160 --> 00:03:50,010
initially and I'll get the URL, then

99
00:03:50,010 --> 00:03:54,209
we'll paste it into Firefox. Now you can see

100
00:03:54,209 --> 00:03:56,340
that Firefox, on the other hand, is giving

101
00:03:56,340 --> 00:03:58,230
us some more formatted view of the same

102
00:03:58,230 --> 00:04:00,390
output. So in other words, it's got sort

103
00:04:00,390 --> 00:04:02,610
of a built in RSS feed program, that can

104
00:04:02,610 --> 00:04:05,970
take the XML that we saw over here, in

105
00:04:05,970 --> 00:04:07,860
Google Chrome, and converted it to

106
00:04:07,860 --> 00:04:09,930
something that's a bit more readable. And

107
00:04:09,930 --> 00:04:11,400
that's because Google's Chrome browser

108
00:04:11,400 --> 00:04:13,769
hasn't got a feed reader built in,

109
00:04:13,769 --> 00:04:15,329
although you can download a plugin if

110
00:04:15,329 --> 00:04:17,608
you want. But you don't need to worry at

111
00:04:17,608 --> 00:04:20,130
this stage, because it's the raw XML that,

112
00:04:20,130 --> 00:04:21,988
ultimately, we want to look at anyway.

113
00:04:21,988 --> 00:04:24,599
So, as you can see, I've got the RSS feed

114
00:04:24,599 --> 00:04:27,070
rendered in Firefox here, to

115
00:04:27,070 --> 00:04:28,630
display the information that starts with

116
00:04:28,630 --> 00:04:31,210
the title, at the top here; iTunes

117
00:04:31,210 --> 00:04:34,210
Store: Top Free Apps. And below that, down

118
00:04:34,210 --> 00:04:36,280
here, there's a series of entries - each

119
00:04:36,280 --> 00:04:38,230
one starting with a title, the day it

120
00:04:38,230 --> 00:04:40,540
was updated, as well as a summary of what

121
00:04:40,540 --> 00:04:43,090
the app does. So let's just go back to

122
00:04:43,090 --> 00:04:45,040
google chrome now, and actually have a

123
00:04:45,040 --> 00:04:47,650
look at the actual RSS feed - the XML data

124
00:04:47,650 --> 00:04:49,150
behind all this - just to see what it

125
00:04:49,150 --> 00:04:51,520
looks like. And as I mentioned, there's a

126
00:04:51,520 --> 00:04:52,630
few ways to do that. If we're using

127
00:04:52,630 --> 00:04:54,340
Google's Chrome browser, you can already

128
00:04:54,340 --> 00:04:56,980
see the XML, and Microsoft's edge browser

129
00:04:56,980 --> 00:05:00,220
will also display the XML. But if

130
00:05:00,220 --> 00:05:01,570
you've got Firefox or you've got a

131
00:05:01,570 --> 00:05:03,250
browser that doesn't directly show the

132
00:05:03,250 --> 00:05:05,860
raw XML, what you can generally do, is

133
00:05:05,860 --> 00:05:07,990
right-click somewhere on the page, like I

134
00:05:07,990 --> 00:05:10,570
can in Firefox - a view page source - and

135
00:05:10,570 --> 00:05:12,880
that will actually give you the same XML

136
00:05:12,880 --> 00:05:15,130
anyway. So at this stage, I'm going to

137
00:05:15,130 --> 00:05:17,050
close down Firefox because I'm not using

138
00:05:17,050 --> 00:05:18,520
that. I just wanted to show you the

139
00:05:18,520 --> 00:05:20,470
formatted output, and we'll go back to

140
00:05:20,470 --> 00:05:23,640
Google Chrome, which has got the raw XML

141
00:05:23,640 --> 00:05:25,690
without us needing to right-click

142
00:05:25,690 --> 00:05:28,630
and view source. But generally speaking,

143
00:05:28,630 --> 00:05:30,220
if your browser doesn't have the option

144
00:05:30,220 --> 00:05:32,050
to view the page source, check its view

145
00:05:32,050 --> 00:05:34,630
menu or use Chrome, as you can see here,

146
00:05:34,630 --> 00:05:36,310
or Firefox where you can actually right

147
00:05:36,310 --> 00:05:38,320
click and view source. You saw me

148
00:05:38,320 --> 00:05:40,120
doing that. One way or the other, you want

149
00:05:40,120 --> 00:05:41,770
to get the XML showing up on the screen

150
00:05:41,770 --> 00:05:44,770
here. Alright, so in the XML, again, if you

151
00:05:44,770 --> 00:05:45,820
look carefully, we can see here that

152
00:05:45,820 --> 00:05:48,340
under the title, we've got iTunes Store:

153
00:05:48,340 --> 00:05:51,520
Top Free Apps. So an RSS feed is

154
00:05:51,520 --> 00:05:54,100
delivered as XML, and that's got standard

155
00:05:54,100 --> 00:05:56,650
tags such as author and title etc, and

156
00:05:56,650 --> 00:05:59,020
there's a separate feed standard called

157
00:05:59,020 --> 00:06:01,540
Atom. But, it's basically very similar and

158
00:06:01,540 --> 00:06:04,540
the term RSS feed also includes atom

159
00:06:04,540 --> 00:06:06,640
feeds. And in fact, looking at this

160
00:06:06,640 --> 00:06:08,920
particular feed here, this actually uses

161
00:06:08,920 --> 00:06:10,900
the Atom namespace, and that's this bit

162
00:06:10,900 --> 00:06:17,200
of code up here you can see; www.w3.org

163
00:06:17,200 --> 00:06:20,320
slash 2005/Atom. So it's using the

164
00:06:20,320 --> 00:06:22,780
Atom tag names rather than RSS,

165
00:06:22,780 --> 00:06:24,730
but there's very little difference as

166
00:06:24,730 --> 00:06:27,370
far as we're concerned, though. Now even if

167
00:06:27,370 --> 00:06:29,770
you're not familiar with XML, it's still

168
00:06:29,770 --> 00:06:31,630
not too hard to work out what the

169
00:06:31,630 --> 00:06:33,760
information represents. There's an

170
00:06:33,760 --> 00:06:37,080
updated tag, for example, here.

171
00:06:37,080 --> 00:06:39,520
That contains the date and time of the

172
00:06:39,520 --> 00:06:40,990
last update to this feed. And

173
00:06:40,990 --> 00:06:43,090
there's also a closing updated tag -

174
00:06:43,090 --> 00:06:45,639
that's his part here. So the information

175
00:06:45,639 --> 00:06:47,590
about when the feed was updated

176
00:06:47,590 --> 00:06:49,270
is everything between the opening and

177
00:06:49,270 --> 00:06:51,520
closing tags - this is the closing tag I've

178
00:06:51,520 --> 00:06:53,440
highlighted - and the opening tag for

179
00:06:53,440 --> 00:06:54,789
updated that I've highlighted there to

180
00:06:54,789 --> 00:06:55,210
the left.

181
00:06:55,210 --> 00:06:57,340
And scrolling down, we can also see there's

182
00:06:57,340 --> 00:07:01,120
other links there; ID, title, summary, and a

183
00:07:01,120 --> 00:07:02,229
bit further down there's things like

184
00:07:02,229 --> 00:07:05,199
pricing and so forth, as we look down the

185
00:07:05,199 --> 00:07:08,770
page. Now you don't have to understand

186
00:07:08,770 --> 00:07:10,990
too much about this. This is just a way

187
00:07:10,990 --> 00:07:13,870
to share data, with the tags describing

188
00:07:13,870 --> 00:07:16,240
what the data actually means, so that

189
00:07:16,240 --> 00:07:18,340
computers can manipulate that data, and

190
00:07:18,340 --> 00:07:21,099
in this case, display it on the screen. Now,

191
00:07:21,099 --> 00:07:23,050
or in the case of when I was on Firefox,

192
00:07:23,050 --> 00:07:24,280
at least to be able to display it on the

193
00:07:24,280 --> 00:07:26,169
screen. Obviously, in this

194
00:07:26,169 --> 00:07:28,389
particular view with Google Chrome, we're

195
00:07:28,389 --> 00:07:29,979
just looking at the raw unformatted

196
00:07:29,979 --> 00:07:33,009
XML. Now, for our application, we're only

197
00:07:33,009 --> 00:07:35,259
interested in some of this data. So the

198
00:07:35,259 --> 00:07:36,820
application that we're going to write in

199
00:07:36,820 --> 00:07:37,990
this section of the course, is going to

200
00:07:37,990 --> 00:07:39,789
extract the data from some of these

201
00:07:39,789 --> 00:07:42,599
fields or tags, and display it in the app.

202
00:07:42,599 --> 00:07:44,740
Now we're going to be using the entry

203
00:07:44,740 --> 00:07:46,270
tags, and you can see there's an entry

204
00:07:46,270 --> 00:07:50,050
tag here. And the entry tag, you can see,

205
00:07:50,050 --> 00:07:51,430
as you look further along or further

206
00:07:51,430 --> 00:07:53,800
down, contains things like a name for

207
00:07:53,800 --> 00:07:56,110
each app and a summary. We're also going

208
00:07:56,110 --> 00:07:57,940
to display the artist and release date,

209
00:07:57,940 --> 00:08:00,520
and we'll actually load the image URL as

210
00:08:00,520 --> 00:08:02,409
well. Now in this app we won't be

211
00:08:02,409 --> 00:08:04,000
displaying the image, but you'll be able

212
00:08:04,000 --> 00:08:05,889
to see how to do that in the next app.

213
00:08:05,889 --> 00:08:08,560
Now notice how each entry repeats, so

214
00:08:08,560 --> 00:08:10,780
we've got this section here, entry. But

215
00:08:10,780 --> 00:08:12,310
if I scroll down, there's another entry

216
00:08:12,310 --> 00:08:14,500
down here, and scrolling down there's the

217
00:08:14,500 --> 00:08:16,960
third entry. So basically, there's one of

218
00:08:16,960 --> 00:08:19,479
those for each of the top ten apps. And

219
00:08:19,479 --> 00:08:20,710
you can see it better if I go

220
00:08:20,710 --> 00:08:22,060
back up to the top again - if I actually

221
00:08:22,060 --> 00:08:23,349
start collapsing some of these entries

222
00:08:23,349 --> 00:08:25,990
by clicking on the arrow. Click that a

223
00:08:25,990 --> 00:08:33,289
few times,

224
00:08:33,289 --> 00:08:35,520
and you can see that there's 10 entries

225
00:08:35,520 --> 00:08:38,010
there now - one for each of the apps in

226
00:08:38,010 --> 00:08:40,559
the top 10 free apps in the

227
00:08:40,559 --> 00:08:42,299
Apple App Store, as of the time that I'm

228
00:08:42,299 --> 00:08:45,000
recording this video. Now, not all

229
00:08:45,000 --> 00:08:46,560
browsers will let you do that, which is

230
00:08:46,560 --> 00:08:48,510
why I'm using Google Chrome here to

231
00:08:48,510 --> 00:08:50,490
demonstrate this. And, obviously, we can

232
00:08:50,490 --> 00:08:51,870
open it up at any time again, if you want

233
00:08:51,870 --> 00:08:52,980
to see the details or just that one

234
00:08:52,980 --> 00:08:55,920
entry. So basically, though, the data that

235
00:08:55,920 --> 00:08:57,240
we're interested in will be everything

236
00:08:57,240 --> 00:08:59,040
that's in between these two entry tags.

237
00:08:59,040 --> 00:09:02,160
So once we find a starting entry tag, we

238
00:09:02,160 --> 00:09:03,750
can keep loading the information we want

239
00:09:03,750 --> 00:09:06,420
until we find the closing entry tag that

240
00:09:06,420 --> 00:09:08,970
matches the start tag. So basically, we

241
00:09:08,970 --> 00:09:10,350
get everything from, in this case, this

242
00:09:10,350 --> 00:09:12,810
first entry right through down to the

243
00:09:12,810 --> 00:09:15,000
last closing one, which is the slash

244
00:09:15,000 --> 00:09:17,520
forward slash entry - that's what we're

245
00:09:17,520 --> 00:09:18,420
going to be dealing with in this

246
00:09:18,420 --> 00:09:20,460
application we're creating in this section

247
00:09:20,460 --> 00:09:22,620
of the course. Alright, so with that said,

248
00:09:22,620 --> 00:09:24,390
let's switch over to Android Studio now

249
00:09:24,390 --> 00:09:28,170
and get started with our app. Now we're

250
00:09:28,170 --> 00:09:30,120
going to create a new project, obviously,

251
00:09:30,120 --> 00:09:32,730
so I'll just go ahead and do that, and I'm

252
00:09:32,730 --> 00:09:39,080
going to call this one Top 10 Downloader.

253
00:09:39,080 --> 00:09:41,520
I'm going to leave the company domain as

254
00:09:41,520 --> 00:09:43,260
it has been set to previously; learn

255
00:09:43,260 --> 00:09:45,480
programming.academy, just as we did for

256
00:09:45,480 --> 00:09:48,060
the previous apps. Once again, remember if

257
00:09:48,060 --> 00:09:51,000
include Kotlin support isn't checked, you

258
00:09:51,000 --> 00:09:52,890
want to check that if you want

259
00:09:52,890 --> 00:09:54,600
Android Studio to generate Kotlin code,

260
00:09:54,600 --> 00:09:56,490
and you want to make sure it's unticked

261
00:09:56,490 --> 00:09:59,280
if you want Java code. So I'm gonna click

262
00:09:59,280 --> 00:10:02,160
on Next there, and on this next screen

263
00:10:02,160 --> 00:10:04,410
I'm gonna leave the minimum SDK set to

264
00:10:04,410 --> 00:10:06,390
17. Again, we've done that in previous

265
00:10:06,390 --> 00:10:08,340
apps, and leave everything else 

266
00:10:08,340 --> 00:10:11,400
unticked. Click on Next, and we're going to

267
00:10:11,400 --> 00:10:14,220
use the Empty Activity template, as

268
00:10:14,220 --> 00:10:17,070
we've done before. Click on Next, and then

269
00:10:17,070 --> 00:10:18,720
finally we going to accept the suggested

270
00:10:18,720 --> 00:10:20,250
names for the activity and layout. And

271
00:10:20,250 --> 00:10:21,600
again, you want to make sure that both

272
00:10:21,600 --> 00:10:23,940
checkboxes here are checked, so that

273
00:10:23,940 --> 00:10:25,950
Android Studio generates a layout for us,

274
00:10:25,950 --> 00:10:27,990
and also so the app's compatible with

275
00:10:27,990 --> 00:10:29,910
previous versions of Android. So I'm

276
00:10:29,910 --> 00:10:33,060
going to click on Finish now, and that's

277
00:10:33,060 --> 00:10:34,530
our project created, or what's actually

278
00:10:34,530 --> 00:10:36,720
in the process as being created. So I'm

279
00:10:36,720 --> 00:10:38,820
going to stop the video here, and in the

280
00:10:38,820 --> 00:10:40,080
next video, we're going to start creating

281
00:10:40,080 --> 00:10:42,720
the code to download the feed data and

282
00:10:42,720 --> 00:10:45,240
extract the information from it. So I'll

283
00:10:45,240 --> 00:10:48,140
see you in the next video.

