1
00:00:00,500 --> 00:00:05,330
Welcome back and the last video we saw how we can add an entry to the database.

2
00:00:05,380 --> 00:00:11,240
Now let's have a look at how we can read from the database in order to get that list, pretty much of

3
00:00:11,240 --> 00:00:16,520
all the entries that we have, because we want to display a list of all the different dates in which

4
00:00:16,520 --> 00:00:18,160
we finished the exercise.

5
00:00:18,290 --> 00:00:22,850
So I'm just going to create a new function here in my school Let Open Helper, which I'm going to call

6
00:00:23,120 --> 00:00:26,030
get all complete.

7
00:00:27,260 --> 00:00:28,730
Dates list.

8
00:00:29,790 --> 00:00:36,900
And maybe completed the list will be a better name here, and this function should return an array list

9
00:00:36,900 --> 00:00:37,530
of strings.

10
00:00:38,100 --> 00:00:40,290
So array list of string.

11
00:00:41,290 --> 00:00:44,050
Variables, all right, and then.

12
00:00:45,040 --> 00:00:49,780
In there, I, of course, need to return something at one point, so I'm just going to return.

13
00:00:51,910 --> 00:00:58,240
Now, for now, but then, of course, later on, I want to return a list, so let's create that list

14
00:00:58,240 --> 00:00:59,150
that I want to return.

15
00:00:59,320 --> 00:01:02,050
I'm just going to create a list, which will be a type of relist.

16
00:01:03,180 --> 00:01:05,260
Because that's what we need to return, right?

17
00:01:05,610 --> 00:01:14,250
A list of strings and a array of strings, to be precise, and then we need a database from which we

18
00:01:14,250 --> 00:01:14,880
want to reach.

19
00:01:15,210 --> 00:01:21,880
So here you saw we created the database variable or object that we needed in order to write.

20
00:01:22,050 --> 00:01:23,340
So we inserted something.

21
00:01:23,340 --> 00:01:25,020
But now we want to read from it.

22
00:01:25,500 --> 00:01:33,180
And in order to do so, we create a new DB, which will be this readable database.

23
00:01:34,500 --> 00:01:42,840
The next thing is I will create a cursor, so this cursor will be of DBE Roll Querrey.

24
00:01:43,920 --> 00:01:51,900
And here I run a school code, so here I'm executing school code, which will be select staff from and

25
00:01:51,900 --> 00:01:56,280
then the name of the table and the table name was table history.

26
00:01:56,970 --> 00:02:03,090
And then you can or you must also pass in the selection args but I'm just going to pass null.

27
00:02:04,290 --> 00:02:10,110
All right, so that's the rockery and now we have the cursus, so we can now go through every single

28
00:02:10,110 --> 00:02:16,610
entry that is inside of our database and in order to do so, well, I'm just going to use a while.

29
00:02:16,620 --> 00:02:20,010
So I'm just going to say while Curser Dot.

30
00:02:21,600 --> 00:02:27,060
Move to next, so it's going to move to the next one, as long as there is an entry in the database

31
00:02:27,060 --> 00:02:32,390
for that cursor and the cursor just selects everything from the table history.

32
00:02:32,400 --> 00:02:36,460
So if we have five entries, then it's going to run five times this while loop here.

33
00:02:36,930 --> 00:02:37,270
All right.

34
00:02:37,290 --> 00:02:39,530
If it's just two entries, of course, just two times.

35
00:02:40,260 --> 00:02:44,370
So what I want to do in here, I want to get to date value.

36
00:02:44,490 --> 00:02:47,070
So date value.

37
00:02:48,820 --> 00:02:49,390
We'll be.

38
00:02:51,510 --> 00:02:55,530
The result of curser thought jet stream.

39
00:02:57,200 --> 00:02:59,110
And from where do I want to get the strength?

40
00:02:59,150 --> 00:03:04,610
Well, from Curser that get Collum index.

41
00:03:05,810 --> 00:03:09,690
And the column index is the column completed date.

42
00:03:10,820 --> 00:03:12,080
OK, so what's going on here?

43
00:03:12,860 --> 00:03:21,170
Well, I'm checking the column, which is called Completed Date or actually it's called We have it up

44
00:03:21,170 --> 00:03:22,800
here called Completed Date.

45
00:03:22,830 --> 00:03:24,730
Well, it's called completed on the score date.

46
00:03:25,220 --> 00:03:28,760
So I want to have a look at this column and I want to get that value.

47
00:03:29,750 --> 00:03:33,230
So I want to only get the value from that specific column.

48
00:03:34,430 --> 00:03:42,320
And I want it as a string and I want it at the curse of precision, so that means if we are in row one,

49
00:03:42,860 --> 00:03:47,990
then I want to have the entry that is in the column for completed date for one.

50
00:03:48,380 --> 00:03:51,350
And I want to store that in this variable called date value.

51
00:03:52,740 --> 00:04:02,190
And then I want to add that they value to the list that we created earlier, so add date value because

52
00:04:02,190 --> 00:04:07,740
they value will be of type string because the entry in our completed date column is actually of type

53
00:04:07,740 --> 00:04:08,040
string.

54
00:04:08,700 --> 00:04:14,280
So this list that we have here is a list will be filled up step by step with all the date values that

55
00:04:14,280 --> 00:04:15,920
are inside of our database.

56
00:04:16,380 --> 00:04:17,730
So that's what this value this.

57
00:04:18,720 --> 00:04:24,410
And then once we are done going through all of them, we can close the cursor so cursor not close.

58
00:04:26,600 --> 00:04:32,150
So we're done with the whole curser work so we can just close it afterwards, so we should even close

59
00:04:32,150 --> 00:04:32,670
it afterwards.

60
00:04:32,900 --> 00:04:36,340
And then, of course, we don't want to return now, but we actually want to return the list.

61
00:04:37,070 --> 00:04:39,770
So let's do that here as we turn to list.

62
00:04:41,590 --> 00:04:47,650
All right, so that's our spotlight open helper class, which helps us to work with databases, right?

63
00:04:47,950 --> 00:04:49,900
But where do I actually need the database?

64
00:04:50,380 --> 00:04:56,110
Well, I want to open in the history activity, the functionality.

65
00:04:56,110 --> 00:04:59,270
I want to open the database and read whatever is in there.

66
00:04:59,800 --> 00:05:04,390
So here I'm going to create a new function, which I'm going to call.

67
00:05:06,630 --> 00:05:08,430
Private fund gets.

68
00:05:09,550 --> 00:05:12,520
All completed dates.

69
00:05:14,870 --> 00:05:16,900
OK, so this one is not going to return anything.

70
00:05:17,210 --> 00:05:24,680
This one is just going to later on fill our list or to be more precise, our recital of you that we

71
00:05:24,680 --> 00:05:25,760
still need to set up.

72
00:05:26,710 --> 00:05:28,630
But generally, that's going to be the idea of this.

73
00:05:29,110 --> 00:05:33,970
So what this needs is to get access to the SQLite open, help her.

74
00:05:35,020 --> 00:05:42,610
And actually to this function here, and we've done that before in our Finnish activity where we used

75
00:05:42,610 --> 00:05:47,710
to DB Hunter, so I'm just going to copy that code, the handler stuff.

76
00:05:48,370 --> 00:05:51,430
I'm going to paste that in here because I will need to be handler here.

77
00:05:52,120 --> 00:05:58,030
But then I don't want to call the add date function, but I actually want to call that get all completed

78
00:05:58,030 --> 00:06:01,210
dates list and I want to stored it somewhere.

79
00:06:01,240 --> 00:06:07,270
So I'm going to store that in this variable called All Completed Dates list.

80
00:06:09,290 --> 00:06:14,750
OK, so this will also be a list, actually, to be more precise, it will be in the list because that's

81
00:06:14,750 --> 00:06:16,290
what this function returns.

82
00:06:16,310 --> 00:06:21,410
So if we call that function and we store whatever the result of it is, then we store and the list in

83
00:06:21,410 --> 00:06:26,060
that all completed dates list is going to be in the list of strings.

84
00:06:27,930 --> 00:06:32,570
And in order to display something, what I'm going to do is I'm just going to use a Falu here.

85
00:06:32,610 --> 00:06:39,270
So I go through all of the elements in my all completed dates list for now, and I'm just going to log

86
00:06:39,270 --> 00:06:39,470
it.

87
00:06:39,750 --> 00:06:43,050
So I'm just going to say, OK, look, I.

88
00:06:44,060 --> 00:06:44,560
That's.

89
00:06:45,430 --> 00:06:49,320
It's going to be that hard, plus something like that.

90
00:06:50,310 --> 00:06:57,060
OK, and we need to import log here, so let's do that real quick import log and now we should be able

91
00:06:57,060 --> 00:07:04,410
to see all the entries that we have in our database now in order to not confuse this log with the other

92
00:07:04,410 --> 00:07:04,650
one.

93
00:07:04,650 --> 00:07:08,480
I'm going to call this one log history activity.

94
00:07:08,970 --> 00:07:11,310
And of course, we need to call this function at one point.

95
00:07:11,430 --> 00:07:14,190
And a good point would be in the uncreate directly.

96
00:07:14,190 --> 00:07:19,380
So inside of my history activity in the uncreate, I'm just going to say, OK, get all the complete

97
00:07:19,390 --> 00:07:19,920
dates.

98
00:07:20,310 --> 00:07:24,120
And for now it's just going to display them in the log.

99
00:07:24,300 --> 00:07:25,590
Nowhere, nowhere else for now.

100
00:07:26,220 --> 00:07:27,750
And we can already test it.

101
00:07:27,780 --> 00:07:30,690
So let's run it and see what's going to happen.

102
00:07:31,110 --> 00:07:33,480
And here I'm just going to look for date.

103
00:07:36,480 --> 00:07:38,280
OK, so there we are.

104
00:07:38,310 --> 00:07:39,360
Let's go to the history.

105
00:07:40,400 --> 00:07:45,620
And you could see state history activity already entered and you can see there are two entries.

106
00:07:45,950 --> 00:07:53,180
So I ran the score twice, once at half past one and another time, just about two o'clock.

107
00:07:54,780 --> 00:07:57,610
All right, so as you can see, it already works now.

108
00:07:57,630 --> 00:07:59,580
We, of course, want to display it in here.

109
00:08:00,560 --> 00:08:08,600
And because this video is so short, I'm just going to say, let's prepare the actual individual list

110
00:08:08,690 --> 00:08:11,450
elements so the list items, how we want them to look.

111
00:08:12,760 --> 00:08:15,040
So let's create a new XML file.

112
00:08:16,250 --> 00:08:17,380
Inside of our.

113
00:08:18,320 --> 00:08:25,070
Resources folder there in the layout folder, so I'm going to create a new XML file.

114
00:08:25,370 --> 00:08:28,010
It will be a linear layout.

115
00:08:28,100 --> 00:08:31,550
So the root element should be linear layout.

116
00:08:33,059 --> 00:08:38,340
And the file name will be item on the score, his story on the score Ro.

117
00:08:40,990 --> 00:08:44,530
All right, what do we want to have in there in this linear layout?

118
00:08:44,560 --> 00:08:51,370
Well, for one, I want to have a little padding, so I'm going to add padding to the whole rope, so

119
00:08:51,370 --> 00:08:51,940
to speak.

120
00:08:51,940 --> 00:08:53,910
15 density pixels should be fine.

121
00:08:54,220 --> 00:08:59,080
The orientation should be horizontal because I want to put the elements next to each other.

122
00:09:00,460 --> 00:09:01,000
And then.

123
00:09:02,080 --> 00:09:11,050
Background should be a very white color, so I'm going to use Ebbie SBB, it's not white as such, but

124
00:09:11,050 --> 00:09:13,630
it's slightly gray just a little bit.

125
00:09:14,550 --> 00:09:19,050
The layout height should be.

126
00:09:20,490 --> 00:09:25,500
Rep content, so it shouldn't take the whole screen, but only as much space as it needs.

127
00:09:27,560 --> 00:09:33,380
And I'm going to give it an idea, so let's give this linear layout an idea, I'm going to call this

128
00:09:33,380 --> 00:09:37,130
one El Al history item main.

129
00:09:39,150 --> 00:09:44,910
And you know what, I'm just going to paste a text use in here, because otherwise I'm probably going

130
00:09:44,910 --> 00:09:48,930
to bore you to death because you've seen is a thousand times how to create a text to you.

131
00:09:49,170 --> 00:09:51,260
So what I want to use is tools.

132
00:09:51,270 --> 00:09:54,060
And when I do that, you can see it doesn't know this namespace.

133
00:09:54,060 --> 00:09:58,440
So I will add tools namespace up here in my linear layout.

134
00:09:58,520 --> 00:10:02,490
So this is how you can do it and now it's not going to complain about it anymore.

135
00:10:02,730 --> 00:10:07,750
So the first text, you should only wrap its content and that in both directions.

136
00:10:07,760 --> 00:10:10,640
So in the end tonight I'm going to call it TV position.

137
00:10:11,010 --> 00:10:18,600
I'm going to send it from a gravity perspective with color size, which is a very dark gray or a black,

138
00:10:18,600 --> 00:10:21,270
almost 16 as a textiles.

139
00:10:21,270 --> 00:10:23,130
And the textile should be bold.

140
00:10:23,460 --> 00:10:24,960
Now the tools text should be one.

141
00:10:25,350 --> 00:10:32,580
And the second text view, I call it TV item, it has a width of zero because it should use the lighter

142
00:10:32,610 --> 00:10:36,570
weight of one in order to determine how much space it's going to get.

143
00:10:36,570 --> 00:10:39,660
And I just want to take all of the available space.

144
00:10:39,960 --> 00:10:41,970
The gravity will be center.

145
00:10:42,690 --> 00:10:45,480
Then the text color should be the same.

146
00:10:45,480 --> 00:10:48,640
Text size and text style should be the same at the tools.

147
00:10:48,640 --> 00:10:49,420
Text should be data.

148
00:10:49,500 --> 00:10:50,700
What does that even mean?

149
00:10:50,730 --> 00:10:52,280
Well, you can see that here.

150
00:10:52,680 --> 00:10:55,970
So that's pretty much what it means in this view.

151
00:10:56,280 --> 00:10:57,560
The item should look like this.

152
00:10:57,570 --> 00:11:03,960
So we have a little bit of padding surrounding it, 15 density pixels and we have this text one and

153
00:11:03,960 --> 00:11:05,010
then we have this date.

154
00:11:05,250 --> 00:11:10,950
So that's how I want one last element to look like, OK, and that's already pretty much it for this

155
00:11:10,950 --> 00:11:11,310
video.

156
00:11:11,310 --> 00:11:18,360
In the next one, we are going to prepare our recycler view and the adapter in order to display all

157
00:11:18,360 --> 00:11:20,970
of the dates that we have in our database.

158
00:11:21,300 --> 00:11:23,040
OK, so see you in the next one.

