@@ -0,0 +1,3368 @@
+package flickr.usth.edu.com.Network;%0A%0Aimport android.net.Uri;%0Aimport android.util.Log;%0A%0Aimport org.json.JSONArray;%0Aimport org.json.JSONException;%0Aimport org.json.JSONObject;%0A%0Aimport java.io.ByteArrayOutputStream;%0Aimport java.io.IOException;%0Aimport java.io.InputStream;%0Aimport java.net.HttpURLConnection;%0Aimport java.net.URL;%0Aimport java.util.ArrayList;%0Aimport java.util.List;%0A%0Aimport flickr.usth.edu.com.GalleryItem;%0A%0A/**%0A * Created by laptop on 12/1/2016.%0A */%0A%0Apublic class FlickrFetchr %7B%0A    private static final String TAG = %22FlickrFetchr%22;%0A    private static final String API_KEY = %227ceb055fba096a529598b351e3685e6e%22;%0A%0A    public byte%5B%5D getUrlBytes(String urlSpec) throws IOException %7B%0A        URL url = new URL(urlSpec);%0A        HttpURLConnection connection = (HttpURLConnection)url.openConnection();%0A%0A        try %7B%0A            ByteArrayOutputStream out = new ByteArrayOutputStream();%0A            InputStream in = connection.getInputStream();%0A%0A            if (connection.getResponseCode() != HttpURLConnection.HTTP_OK) %7B%0A                throw new IOException(connection.getResponseMessage() + %22: with%22 + urlSpec);%0A            %7D%0A%0A            int bytesRead = 0;%0A            byte%5B%5D buffer = new byte%5B1024%5D;%0A            while ((bytesRead = in.read(buffer)) %3E 0) %7B%0A                out.write(buffer, 0, bytesRead);%0A            %7D%0A            out.close();%0A            return out.toByteArray();%0A        %7D finally %7B%0A            connection.disconnect();%0A        %7D%0A    %7D%0A%0A    public String getUrlString(String urlSpec) throws IOException %7B%0A        return new String(getUrlBytes(urlSpec));%0A    %7D%0A%0A    public  List%3CGalleryItem%3E fetchItems()%7B%0A%0A        List%3CGalleryItem%3E items = new ArrayList%3C%3E();%0A%0A        try %7B%0A            String url = Uri.parse(%22https://api.flickr.com/services/rest/%22)                    .buildUpon()%0A                    .appendQueryParameter(%22method%22, %22flickr.photos.getRecent%22)%0A                    .appendQueryParameter(%22api_key%22, API_KEY)%0A                    .appendQueryParameter(%22format%22, %22json%22)%0A                    .appendQueryParameter(%22nojsoncallback%22, %221%22)%0A                    .appendQueryParameter(%22extras%22, %22url_s%22)%0A                    .build().toString();%0A            String jsonString = getUrlString(url);%0A            Log.i(TAG, %22Received JSON: %22 + jsonString);%0A            JSONObject jsonBody = new JSONObject(jsonString);%0A            parseItems(items, jsonBody);%0A        %7D catch (JSONException je)%7B%0A            Log.e(TAG, %22Failed to parse JSON%22, je);%0A        %7D catch (IOException ioe) %7B%0A            Log.e(TAG, %22failed to fetch item%22, ioe);%0A        %7D%0A        return items;%0A    %7D%0A%0A    private void parseItems(List%3CGalleryItem%3E items, JSONObject jsonBody) throws IOException, JSONException %7B%0A        JSONObject photosJsonObject = jsonBody.getJSONObject(%22photos%22);%0A        JSONArray photoJsonArray = photosJsonObject.getJSONArray(%22photo%22);%0A%0A        for (int i = 0; i %3C photoJsonArray.length(); i++) %7B%0A            JSONObject photoJsonObject = photoJsonArray.getJSONObject(i);%0A%0A            GalleryItem item = new GalleryItem();%0A            item.setId(photoJsonObject.getString(%22id%22));%0A            item.setCaption(photoJsonObject.getString(%22title%22));%0A%0A            if (!photoJsonObject.has(%22url_s%22)) %7B%0A                continue;%0A            %7D%0A            item.setUrl(photoJsonObject.getString(%22url_s%22));%0A            items.add(item);%0A        %7D%0A    %7D%0A%0A%7D%0A

add network class, modify api