Created
November 23, 2017 13:07
-
-
Save yooouuri/76d2fcfe7a25d95beb558e8a09ff4c46 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| String url = "http://feetback-api.yourivanmill.nl/api/videos"; | |
| Request request = new Request.Builder() | |
| .url(url) | |
| .header("Authorization", String.format("Bearer %s", token)) | |
| .build(); | |
| OkHttpClient client = new OkHttpClient(); | |
| client.newCall(request).enqueue(new Callback() { | |
| @Override | |
| public void onFailure(Call call, IOException e) { | |
| } | |
| @Override | |
| public void onResponse(Call call, Response response) throws IOException { | |
| try { | |
| JSONObject body = new JSONObject(response.body().string()); | |
| JSONArray videos = body.getJSONObject("success").getJSONArray("videos"); | |
| // Videos | |
| for (int i = 0; i < videos.length(); i++) { | |
| JSONObject video = videos.getJSONObject(i); | |
| JSONArray drawings = video.getJSONArray("drawings"); | |
| List<Drawing> drawingList = new ArrayList<>(); | |
| // Drawings | |
| for (int j = 0; j < drawings.length(); j++) { | |
| JSONObject drawing = drawings.getJSONObject(j); | |
| JSONArray feedback = drawing.getJSONArray("feedback"); | |
| List<Feedback> feedbackList = new ArrayList<>(); | |
| // Feedback | |
| for (int k = 0; k < feedback.length(); k++) { | |
| String description = feedback.getJSONObject(k).getString("description"); | |
| feedbackList.add(new Feedback(description)); | |
| } | |
| drawingList.add(new Drawing(drawing.getString("time_start"), drawing.getString("time_end"), feedbackList)); | |
| } | |
| mVideos.add(new Video(video.getInt("id"), video.getString("name"), video.getString("url"), drawingList)); | |
| } | |
| } catch (JSONException e) { | |
| Log.d(TAG, "Something when wrong parsing json"); | |
| Log.d(TAG, e.getMessage()); | |
| } | |
| runOnUiThread(new Runnable() { | |
| @Override | |
| public void run() { | |
| Log.d(TAG, "Received videos"); | |
| adapter.notifyDataSetChanged(); | |
| } | |
| }); | |
| } | |
| }); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment