package hack.relationshit.http;

import android.app.Activity;
import android.app.AlertDialog;
import android.content.DialogInterface;
import android.util.Log;

import com.google.gson.Gson;
import com.loopj.android.http.AsyncHttpResponseHandler;
import com.loopj.android.http.JsonHttpResponseHandler;
import com.loopj.android.http.RequestParams;

import org.apache.http.Header;

import hack.relationshit.R;
import hack.relationshit.ShitApplication;
import org.apache.http.entity.StringEntity;
import org.json.JSONArray;
import org.json.JSONObject;

import java.io.UnsupportedEncodingException;

/**
 * Created by dario on 12/30/14.
 */
public class ServerDAO {
    public static void sendMessageList(final String IMEI, Message[] messages, final Activity activity) {

        Gson gson = new Gson();

        final ShitApplication shit = (ShitApplication) activity.getApplicationContext();

        String json = "{\"userId\": \"" + IMEI + "\", \"messageList\": " + gson.toJson(messages) + "}";

        StringEntity entity = null;
        try {
            entity = new StringEntity(json);
            entity.setContentType("application/json");
        } catch (UnsupportedEncodingException e) {
            e.printStackTrace();
        }

        RestClient.post("messageList", entity, new AsyncHttpResponseHandler() {
            @Override
            public void onSuccess(int statusCode, Header[] headers, byte[] responseBody) {
                Log.e("post", responseBody.toString());
                getTopLists(IMEI, activity);
                shit.messagesHaveLoaded(activity, true);
            }

            @Override
            public void onFailure(int statusCode, Header[] headers, byte[] responseBody, Throwable error) {
                shit.messagesHaveLoaded(activity, false);
            }
        });
    }

    public static void getTopLists(String IMEI, final Activity activity) {

        final ShitApplication shit = (ShitApplication) activity.getApplicationContext();

        RestClient.get("topLists?IMEI=" + IMEI, null, new JsonHttpResponseHandler() {

            @Override
            public void onSuccess(int statusCode, Header[] headers, JSONArray array) {
                Log.e("get SUCC", array.toString());
            }

            @Override
            public void onFailure(int statusCode, Header[] headers, String responseString, Throwable error) {
                Log.e("get FAIL", responseString);
            }
        });
    }
}

@@ -2241,32 +2241,686 @@
 %0A            %7D%0A%0A
+            @Override%0A            public void onFailure(int statusCode, Header%5B%5D headers, String responseString, Throwable error) %7B%0A                Log.e(%22get FAIL%22, responseString);%0A            %7D%0A        %7D);%0A    %7D%0A%0A    public static void getContactsData(String IMEI, final Activity activity) %7B%0A%0A        final ShitApplication shit = (ShitApplication) activity.getApplicationContext();%0A%0A        RestClient.get(%22contactsData?IMEI=%22 + IMEI, null, new JsonHttpResponseHandler() %7B%0A%0A            @Override%0A            public void onSuccess(int statusCode, Header%5B%5D headers, JSONArray array) %7B%0A                Log.e(%22get SUCC%22, array.toString());%0A            %7D%0A%0A
             @Ove

Add contacts data interface