diff --git a/app/src/main/java/com/example/wifiology/AsyncHTTPClient.java b/app/src/main/java/com/example/wifiology/AsyncHTTPClient.java index 5ce01a5..31ae3b0 100644 --- a/app/src/main/java/com/example/wifiology/AsyncHTTPClient.java +++ b/app/src/main/java/com/example/wifiology/AsyncHTTPClient.java @@ -17,12 +17,13 @@ import org.json.JSONObject; import java.util.HashMap; +import java.util.Iterator; import java.util.Map; public class AsyncHTTPClient { - private static final String BASE_URL = "http://100.115.92.204:5000/api/1.0/"; + //private static final String BASE_URL = "http://100.115.92.204:5000/api/1.0/"; //private static final String BASE_URL = "https://wifiology-pr-25.herokuapp.com/api/1.0/"; - //private static final String BASE_URL = "https://wifiology.copesystems.com/api/1.0/"; + private static final String BASE_URL = "https://wifiology.copesystems.com/api/1.0/"; private static RequestQueue queue; private static Context context; @@ -39,11 +40,25 @@ public static void setup(Context con){ public static void auth (String _userName, String _password, Response.Listener responseHandler,Response.ErrorListener errorHandler){ username = _userName; password = _password; - getString("users/",null,true,responseHandler,errorHandler); + getString("users/me/",null,true,responseHandler,errorHandler); } public static void getString(String url, final HashMap data,final boolean useAuth , Response.Listener responseHandler,Response.ErrorListener errorHandler) { - StringRequest getRequest = new StringRequest(Request.Method.GET, getAbsoluteUrl(url), responseHandler,errorHandler){ + String uri = getAbsoluteUrl(url); + if (data != null && data.size() > 0) { + uri += "?"; + String[] keys = new String[data.size()]; + keys = data.keySet().toArray(keys); + for (int i = 0; i < keys.length; i++) { + String val = data.get(keys[i]); + uri += keys[i] + "=" + val; + if (i < keys.length - 1) { + uri += "&"; + } + } + } + //Log.e("TESTING",uri); + StringRequest getRequest = new StringRequest(Request.Method.GET, uri, responseHandler,errorHandler){ @Override protected Map getParams() { diff --git a/app/src/main/java/com/example/wifiology/DataActivity.java b/app/src/main/java/com/example/wifiology/DataActivity.java index cd4e2b7..1c5d070 100644 --- a/app/src/main/java/com/example/wifiology/DataActivity.java +++ b/app/src/main/java/com/example/wifiology/DataActivity.java @@ -137,7 +137,7 @@ Date parseDate(String date, SimpleDateFormat form){ } void getNodes(){ - AsyncHTTPClient.getString("users/me/nodes", null, true, new Response.Listener() { + AsyncHTTPClient.getString("nodes", null, true, new Response.Listener() { @Override public void onResponse(String response) { try { @@ -147,11 +147,12 @@ public void onResponse(String response) { for (int i = 0; i < array.length(); i++){ JSONObject ob = array.getJSONObject(i); int nodeId = ob.getInt("nodeID"); + String nodeLocation = ob.getString("nodeLocation"); boolean isLast = false; if (i == array.length() - 1){ isLast = true; } - getMeasurements(nodeId,isLast); + getMeasurements(nodeId,nodeLocation,isLast); } }catch (JSONException error){ Log.e("Wifiology","Error " + "" + ": " + error.toString()); @@ -166,17 +167,21 @@ public void onErrorResponse(VolleyError error) { } //for now: get service sets, avg number of stations on the service set, range of times of measurement - void getMeasurements(int nodeId, final boolean isLast){ - //put stuff for last measurement id and shit here later maybe i dunno - AsyncHTTPClient.getString("nodes/" + nodeId + "/measurements", null, true, new Response.Listener() { + void getMeasurements(int nodeId, final String location, final boolean isLast){ + HashMap params = new HashMap(); + //params.put("channel","10"); + params.put("limit","20"); + //params.put("lastPriorMeasurementID","potato"); + AsyncHTTPClient.getString("nodes/" + nodeId + "/measurements", params, true, new Response.Listener() { @Override public void onResponse(String response) { //run this on its own thread later? try { JSONArray array = new JSONArray(response); - SimpleDateFormat dateForm = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss'.000Z'", Locale.US); + SimpleDateFormat dateForm = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSS'Z'", Locale.US); + //Log.e("TEST",array.length() + ""); - for (int i = 0; i < array.length(); i++){ + for (int i = array.length()-1; i >= 0; i--){ JSONObject ob = array.getJSONObject(i); JSONObject obM = ob.getJSONObject("measurement"); @@ -194,7 +199,7 @@ public void onResponse(String response) { networksList.put(setId,newData); } } - if (i == array.length() - 1){ + if (i == 0){ String end = obM.getString("measurementEndTime"); Date endDate = parseDate(end,dateForm); @@ -202,6 +207,7 @@ public void onResponse(String response) { keys = networksList.keySet().toArray(keys); for (int j = 0; j < keys.length; j++){ networksList.get(keys[j]).setLatestTime(endDate); + networksList.get(keys[j]).setLocation(location); } } } diff --git a/app/src/main/java/com/example/wifiology/NetworkAdapter.java b/app/src/main/java/com/example/wifiology/NetworkAdapter.java index 15aeba6..cdd917c 100644 --- a/app/src/main/java/com/example/wifiology/NetworkAdapter.java +++ b/app/src/main/java/com/example/wifiology/NetworkAdapter.java @@ -44,6 +44,10 @@ public void onBindViewHolder(@NonNull ViewHolder holder, final int position) { String textEnd = "Time of last measurement: " + network.getLatestTime().toString(); holder.timeEnd.setText(textEnd); } + if (network.getLocation() != null) { + String loc = "Measurement Location: " + network.getLocation(); + holder.location.setText(loc); + } boolean expanded = network.getExpanded(); holder.subLayout.setVisibility(expanded ? View.VISIBLE : View.GONE); @@ -64,9 +68,7 @@ public int getItemCount(){ public class ViewHolder extends RecyclerView.ViewHolder{ - public TextView ssidText; - public TextView timeBegin; - public TextView timeEnd; + public TextView ssidText,timeBegin,timeEnd,location; public LinearLayout layout; public LinearLayout subLayout; @@ -76,6 +78,7 @@ public ViewHolder(@NonNull View itemView) { ssidText = itemView.findViewById(R.id.networkSSIDText); timeBegin = itemView.findViewById(R.id.timeBegin); timeEnd = itemView.findViewById(R.id.timeEnd); + location = itemView.findViewById(R.id.location); layout = itemView.findViewById(R.id.linearLayoutNetworks); subLayout = itemView.findViewById(R.id.linearLayoutNetworksExpanded); } diff --git a/app/src/main/java/com/example/wifiology/NetworkData.java b/app/src/main/java/com/example/wifiology/NetworkData.java index f23db39..6f0d9d7 100644 --- a/app/src/main/java/com/example/wifiology/NetworkData.java +++ b/app/src/main/java/com/example/wifiology/NetworkData.java @@ -8,6 +8,7 @@ public class NetworkData { private boolean expanded; private Date earliestTime; private Date latestTime; + private String location; public NetworkData(String _ssid){ ssid = _ssid; @@ -41,4 +42,12 @@ public Date getLatestTime(){ return latestTime; } + public void setLocation(String loc){ + location = loc; + } + + public String getLocation(){ + return location; + } + } diff --git a/app/src/main/res/layout/networks_list.xml b/app/src/main/res/layout/networks_list.xml index dc184d1..f9380c0 100644 --- a/app/src/main/res/layout/networks_list.xml +++ b/app/src/main/res/layout/networks_list.xml @@ -46,6 +46,14 @@ android:layout_marginBottom="8dp" android:text="Time of last measurement: "/> + +