Skip to content

Commit 9d5b28b

Browse files
committed
maxime_commit
1 parent f4558f0 commit 9d5b28b

File tree

4 files changed

+55
-28
lines changed

4 files changed

+55
-28
lines changed

.idea/misc.xml

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

app/src/main/java/com/example/golfier/android_youtube_api/MakeRequestTask.java

Lines changed: 8 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -31,10 +31,9 @@ public class MakeRequestTask extends AsyncTask<Void, Void, List<String>> {
3131

3232
private com.google.api.services.youtube.YouTube mService = null;
3333
private Exception mLastError = null;
34-
private String result;
35-
private int status;
3634
private ProgressDialog mProgress;
3735
private YoutubeUser youtubeUser;
36+
private RequestInfo ri = RequestInfo.getInstance();
3837

3938
private static final int REQUEST_AUTHORIZATION = 1001;
4039

@@ -158,21 +157,18 @@ private List<String> getDataFromApi() throws IOException {
158157

159158
@Override
160159
protected void onPreExecute() {
161-
result="";
162-
System.out.println(result);
160+
ri.addInfo("");
163161
mProgress.show();
164162
}
165163

166164
@Override
167165
protected void onPostExecute(List<String> output) {
168166
mProgress.hide();
169167
if (output == null || output.size() == 0) {
170-
result="No results returned.";
171-
System.out.println(result);
168+
ri.addInfo("No results returned.");
172169
} else {
173170
output.add(0, "Data retrieved using the YouTube Data API:");
174-
result=TextUtils.join("\n", output);
175-
System.out.println(result);
171+
ri.addInfo(TextUtils.join("\n", output));
176172
}
177173
}
178174

@@ -182,30 +178,17 @@ protected void onCancelled() {
182178
if (mLastError != null) {
183179
if (mLastError instanceof GooglePlayServicesAvailabilityIOException) {
184180
int connectionStatusCode = ((GooglePlayServicesAvailabilityIOException) mLastError).getConnectionStatusCode();
185-
setStatusErr(connectionStatusCode);
181+
ri.addStatus(connectionStatusCode);
186182
} else if (mLastError instanceof UserRecoverableAuthIOException) {
187-
setStatusErr(this.REQUEST_AUTHORIZATION);
183+
ri.addStatus(this.REQUEST_AUTHORIZATION);
188184
} else {
189-
result="The following error occurred:\n" +mLastError.getMessage();
190-
System.out.println(result);
185+
ri.addInfo("The following error occurred:\n" +mLastError.getMessage());
191186
}
192187
} else {
193-
result="Request cancelled.";
194-
System.out.println(result);
188+
ri.addInfo("Request cancelled.");
195189
}
196190
}
197191

198-
public String getResult () {
199-
return result;
200-
}
201-
202-
public int getStatusErr () {
203-
return status;
204-
}
205-
206-
public void setStatusErr (int nb) {
207-
this.status = nb;
208-
}
209192

210193
/*
211194
* Print information about all of the items in the playlist.
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
package com.example.golfier.android_youtube_api;
2+
3+
import java.util.ArrayList;
4+
import java.util.List;
5+
6+
public class RequestInfo {
7+
8+
private List<String> listInfo;
9+
private List<Integer> statusInfo;
10+
private static RequestInfo instance = null;
11+
12+
protected RequestInfo() {
13+
listInfo = new ArrayList<>();
14+
statusInfo = new ArrayList<>();
15+
}
16+
public static RequestInfo getInstance() {
17+
if(instance == null) {
18+
instance = new RequestInfo();
19+
}
20+
return instance;
21+
}
22+
23+
public List<String> getInfo () {
24+
return listInfo;
25+
}
26+
27+
public void setInfo (List<String> list) {
28+
this.listInfo = list;
29+
}
30+
31+
public void addInfo(String info) {
32+
this.listInfo.add(info);
33+
}
34+
35+
public List<Integer> getStatus () {
36+
return statusInfo;
37+
}
38+
39+
public void setStatus (List<Integer> list) {
40+
this.statusInfo = list;
41+
}
42+
43+
public void addStatus (Integer status) {
44+
this.statusInfo.add(status);
45+
}
46+
}

app/src/main/java/com/example/golfier/android_youtube_api/YoutubeVideo.java

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
package com.example.golfier.android_youtube_api;
22

3-
import com.google.api.client.util.DateTime;
4-
53
public class YoutubeVideo {
64
private String videoId;
75
private String title;

0 commit comments

Comments
 (0)