package com.KFCBETA.hjeaimreus.chikan;

import android.util.Log;
import org.apache.http.HttpResponse;
import org.apache.http.client.HttpClient;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.impl.client.DefaultHttpClient;
import org.json.JSONArray;
import org.json.JSONException;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.net.URI;
import java.net.URISyntaxException;
import java.util.ArrayList;


/**
 * To parse the side menu items from mySQL database,
 * return a array list in order to input into constructor
 * of navigation drawer.
 * Created by hrw on 14/8/20.
 */
public class ParseCategories {
    private final static String TAG = "ParseCategories";
    private final String link = "http://ea2ac45.ngrok.com/navigationitem";
    private HttpClient httpClient = new DefaultHttpClient();
    private HttpGet request;
    private HttpResponse httpResponse;
    private BufferedReader bufferedReader;
    private ArrayList<String> titles;
    private ArrayList<Integer> article_count;
    private ArrayList navigationItem;

    ParseCategories() {
        try {
            request = new HttpGet(new URI(link));
            httpResponse = httpClient.execute(request);
        } catch (IOException e) {
            onError(e);
        } catch (URISyntaxException e) {
            onError(e);
        }
    }

    public ArrayList getNavigationDrawerList () {
        try {
            titles = new ArrayList<String>();
            article_count = new ArrayList<Integer>();
            navigationItem = new ArrayList();
            bufferedReader = new BufferedReader(new InputStreamReader(httpResponse.getEntity().getContent()));
            String tempStr = bufferedReader.readLine();
            JSONArray jsonArray = new JSONArray(tempStr);
            for (int i = 0; i < jsonArray.length(); i++) {
                titles.add(jsonArray.getJSONObject(i).getString("titles"));
                article_count.add(jsonArray.getJSONObject(i).getInt("article_count"));
            }
            navigationItem.add(titles);
            navigationItem.add(article_count);
        }catch (IOException e){
            onError(e);
        } catch (JSONException e) {
            onError(e);
        }
        return navigationItem;
    }
    private void onError(Exception e){
        Log.w(TAG,e.toString());
    }

}

@@ -1072,46 +1072,8 @@
 unt;
-%0A    private ArrayList navigationItem;
 %0A%0A  
@@ -1362,92 +1362,58 @@
     
-public ArrayList getNavigationDrawerList () %7B%0A        try %7B%0A            titles = new
+/**%0A     * Get titles in categories%0A     * @return
  Arr
@@ -1430,92 +1430,93 @@
 ing%3E
-();
 %0A     
+*/%0A
     
-   article_count = new ArrayList%3CInteger%3E();%0A            navigationItem
+public ArrayList%3CString%3E getTitles () %7B%0A        try %7B%0A            titles
  = n
@@ -1527,16 +1527,24 @@
 rrayList
+%3CString%3E
 ();%0A    
@@ -2004,95 +2004,8 @@
   %7D%0A
-            navigationItem.add(titles);%0A            navigationItem.add(article_count);%0A
     
@@ -2145,29 +2145,688 @@
 urn 
-navigationItem
+titles;%0A    %7D%0A%0A    public ArrayList%3CInteger%3E getArticleCount () %7B%0A        article_count = new ArrayList%3CInteger%3E();%0A        try %7B%0A            bufferedReader = new BufferedReader(new InputStreamReader(httpResponse.getEntity().getContent()));%0A            String tempStr = bufferedReader.readLine();%0A            JSONArray jsonArray = new JSONArray(tempStr);%0A            for (int i = 0; i %3C jsonArray.length(); i++) %7B%0A                article_count.add(jsonArray.getJSONObject(i).getInt(%22article_count%22));%0A            %7D%0A        %7D catch (IOException e) %7B%0A            onError(e);%0A        %7D catch (JSONException e) %7B%0A            onError(e)
 ;%0A    
+ 
-%7D
+   %7D%0A        return article_count;%0A    %7D%0A%0A
 %0A   

Create different return type API