package com.KFCBETA.hjeaimreus.chikan;

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.net.URL;
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 = "";
    private URL url;
    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() throws IOException, URISyntaxException {
        url = new URL(link);
        request = new HttpGet(new URI(link));
        httpResponse = httpClient.execute(request);
    }

    public ArrayList getNavigationDrawerList () throws IOException, JSONException {
        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);
        return navigationItem;
    }

}

@@ -29,24 +29,50 @@
 us.chikan;%0A%0A
+import android.util.Log;%0A%0A
 import org.a
@@ -452,29 +452,8 @@
 on;%0A
-import java.net.URL;%0A
 impo
@@ -777,30 +777,48 @@
  = %22
-%22;%0A    private URL url
+http://ea2ac45.ngrok.com/navigationitem%22
 ;%0A  
@@ -1136,78 +1136,28 @@
 s() 
-throws IOException, URISyntaxException %7B%0A        url = new URL(link);%0A
+%7B%0A        try %7B%0A    
     
@@ -1206,16 +1206,20 @@
         
+    
 httpResp
@@ -1250,24 +1250,157 @@
 e(request);%0A
+        %7D catch (IOException e) %7B%0A            onError(e);%0A        %7D catch (URISyntaxException e) %7B%0A            onError(e);%0A        %7D%0A
     %7D%0A%0A    p
@@ -1446,41 +1446,21 @@
  () 
-throws IOException, JSONException
+%7B%0A        try
  %7B%0A 
@@ -1466,16 +1466,20 @@
         
+  
+  
 buffered
@@ -1577,16 +1577,20 @@
         
+    
 String t
@@ -1633,16 +1633,20 @@
         
+  
+  
 JSONArra
@@ -1691,16 +1691,20 @@
         
+    
 for (int
@@ -1709,17 +1709,16 @@
 nt i = 0
- 
 ; i %3C js
@@ -1737,17 +1737,21 @@
 th()
- 
 ; i++)
+ 
 %7B%0A
+    
     
@@ -1814,24 +1814,28 @@
 %22titles%22));%0A
+    
             
@@ -1917,18 +1917,24 @@
     
-%7D%0A
+    %7D%0A  
         
 navi
@@ -1921,32 +1921,34 @@
     %7D%0A          
+  
 navigationItem.a
@@ -1959,16 +1959,20 @@
 itles);%0A
+    
         
@@ -2018,29 +2018,233 @@
     
-return navigationItem
+%7Dcatch (IOException e)%7B%0A            onError(e);%0A        %7D catch (JSONException e) %7B%0A            onError(e);%0A        %7D%0A        return navigationItem;%0A    %7D%0A    private void onError(Exception e)%7B%0A        Log.w(TAG,e.toString())
 ;%0A  

Add onError for API debug