Commit 4965b9d9 by Simeon Markind

Fully minimally functional

parent 6e496c13
...@@ -11,8 +11,12 @@ ...@@ -11,8 +11,12 @@
android:label="@string/app_name" android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round" android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true" android:supportsRtl="true"
android:theme="@style/AppTheme"> android:theme="@style/AppTheme"
<activity android:name=".MainActivity"> >
<activity
android:name=".MainActivity"
android:windowSoftInputMode="stateHidden|adjustPan">
<intent-filter> <intent-filter>
<action android:name="android.intent.action.MAIN" /> <action android:name="android.intent.action.MAIN" />
......
...@@ -16,6 +16,7 @@ import com.android.volley.VolleyError; ...@@ -16,6 +16,7 @@ import com.android.volley.VolleyError;
import com.android.volley.toolbox.StringRequest; import com.android.volley.toolbox.StringRequest;
import com.android.volley.toolbox.Volley; import com.android.volley.toolbox.Volley;
import com.example.dynamicduals2.jigs.ComplaintTypeCount; import com.example.dynamicduals2.jigs.ComplaintTypeCount;
import com.example.dynamicduals2.jigs.statusCount;
import com.google.gson.Gson; import com.google.gson.Gson;
import com.google.gson.reflect.TypeToken; import com.google.gson.reflect.TypeToken;
...@@ -34,8 +35,15 @@ public class MainActivity extends AppCompatActivity { ...@@ -34,8 +35,15 @@ public class MainActivity extends AppCompatActivity {
private EditText mWard; private EditText mWard;
private Gson gson; private Gson gson;
private TextView mSR_TYPE0;
private TextView mC_0;
private TextView mSR_TYPE1; private TextView mSR_TYPE1;
private TextView mC_1; private TextView mC_1;
private TextView mSR_TYPE2;
private TextView mC_2;
private TextView mNewOpenTxt;
private TextView mBacklogOpenTxt;
private TextView mClosedTxt;
private RequestQueue mQueue; private RequestQueue mQueue;
@Override @Override
...@@ -49,44 +57,80 @@ public class MainActivity extends AppCompatActivity { ...@@ -49,44 +57,80 @@ public class MainActivity extends AppCompatActivity {
mBtnTop3 = findViewById(R.id.btnTop3Complaints); mBtnTop3 = findViewById(R.id.btnTop3Complaints);
mWard = findViewById(R.id.ward); mWard = findViewById(R.id.ward);
mSR_TYPE0 = findViewById(R.id.sr_type0Label);
mC_0 = findViewById(R.id.sr_type0Count);
mSR_TYPE1 = findViewById(R.id.sr_type1Label); mSR_TYPE1 = findViewById(R.id.sr_type1Label);
mC_1 = findViewById(R.id.sr_type1Count); mC_1 = findViewById(R.id.sr_type1Count);
mSR_TYPE2 = findViewById(R.id.sr_type2Label);
mC_2 = findViewById(R.id.sr_type2Count);
mBacklogOpenTxt = findViewById(R.id.sr_open_backlog);
mNewOpenTxt = findViewById(R.id.sr_new_open);
mClosedTxt = findViewById(R.id.sr_closed);
mBtnTop3.setOnClickListener(new View.OnClickListener() { mBtnTop3.setOnClickListener(new View.OnClickListener() {
@Override @Override
public void onClick(View v) { public void onClick(View v) {
//Build the URL //Build the URL
Integer wardInt = Integer.parseInt(mWard.getText().toString()); Integer wardInt = Integer.parseInt(mWard.getText().toString());
if(wardInt <= 0 || wardInt > 50){ if (wardInt <= 0 || wardInt > 50) {
System.out.println("Invalid Ward Number"); System.out.println("Invalid Ward Number");
Toast.makeText(getApplicationContext(), Toast.makeText(getApplicationContext(),
"Invalid Ward Number", Toast.LENGTH_SHORT).show(); "Invalid Ward Number", Toast.LENGTH_SHORT).show();
} else { } else {
String url = createURL(mWard.getText().toString()); String url = createURL(mWard.getText().toString());
fetchTop3(url); fetchTop3(url);
String url_new_opened = createURL_new_opened(mWard.getText().toString());
fetchNewOpened(url_new_opened);
String url_backlog = createURL_backlog(mWard.getText().toString());
fetchBacklog(url_backlog);
String url_closed = createURL_closed(mWard.getText().toString());
fetchClosed(url_closed);
} }
} }
}); });
} }
private String createURL(String ward){ private String createURL(String ward) {
StringBuilder out = new StringBuilder(BASE_URL); StringBuilder out = new StringBuilder(BASE_URL);
out.append("?$query=SELECT sr_type, COUNT(*) AS C WHERE ward == "); out.append("?$query=SELECT sr_type, COUNT(*) AS C WHERE ward == ");
out.append(ward); out.append(ward);
out.append(" GROUP BY sr_type ORDER BY C DESC LIMIT 3"); out.append(" AND created_date BETWEEN '2019-12-01T00:00:00' AND '2020-01-01T00:00:00' GROUP BY sr_type ORDER BY C DESC LIMIT 3");
try { try {
return out.toString(); return out.toString();
} catch (Exception e){ } catch (Exception e) {
e.printStackTrace(); e.printStackTrace();
} }
return null; //URL was malformed return null; //URL was malformed
} }
private String createURL_new_opened(String ward) {
StringBuilder out = new StringBuilder(BASE_URL);
out.append("?$query=SELECT COUNT(*) AS C WHERE ward == ");
out.append(ward);
out.append(" AND status == 'Open' AND created_date BETWEEN '2019-12-01T00:00:00' AND '2020-01-01T00:00:00' GROUP BY status");
try {
return out.toString();
} catch (Exception e) {
e.printStackTrace();
}
return null; //URL was malformed
}
private void fetchTop3(String url) { private void fetchTop3(String url) {
StringRequest stringRequest = new StringRequest(Request.Method.GET, url, onTop3ListLoaded, onTop3ListError); StringRequest stringRequest = new StringRequest(Request.Method.GET, url, onTop3ListLoaded, onTop3ListError);
mQueue.add(stringRequest); mQueue.add(stringRequest);
} }
private void fetchNewOpened(String url) {
StringRequest stringRequest = new StringRequest(Request.Method.GET, url, newOpenedLoaded, newOpenedError);
mQueue.add(stringRequest);
}
private final Response.Listener<String> onTop3ListLoaded = new Response.Listener<String>() { private final Response.Listener<String> onTop3ListLoaded = new Response.Listener<String>() {
@Override @Override
public void onResponse(String response) { public void onResponse(String response) {
...@@ -94,8 +138,12 @@ public class MainActivity extends AppCompatActivity { ...@@ -94,8 +138,12 @@ public class MainActivity extends AppCompatActivity {
ComplaintTypeCount[] complaintTypeCounts = ComplaintTypeCount[] complaintTypeCounts =
gson.fromJson(response, ComplaintTypeCount[].class); gson.fromJson(response, ComplaintTypeCount[].class);
mSR_TYPE1.setText(complaintTypeCounts[0].getSrType()); mSR_TYPE0.setText(complaintTypeCounts[0].getSrType());
mC_1.setText(complaintTypeCounts[0].getC()); mC_0.setText(complaintTypeCounts[0].getC());
mSR_TYPE1.setText(complaintTypeCounts[1].getSrType());
mC_1.setText(complaintTypeCounts[1].getC());
mSR_TYPE2.setText(complaintTypeCounts[2].getSrType());
mC_2.setText(complaintTypeCounts[2].getC());
//Toast.makeText(MainActivity.this, "parsed JSON").show(); //Toast.makeText(MainActivity.this, "parsed JSON").show();
} }
}; };
...@@ -107,4 +155,92 @@ public class MainActivity extends AppCompatActivity { ...@@ -107,4 +155,92 @@ public class MainActivity extends AppCompatActivity {
Toast.makeText(MainActivity.this, "Failed to return ward data", Toast.LENGTH_SHORT).show(); Toast.makeText(MainActivity.this, "Failed to return ward data", Toast.LENGTH_SHORT).show();
} }
}; };
}
private final Response.Listener<String> newOpenedLoaded = new Response.Listener<String>() {
@Override
public void onResponse(String response) {
statusCount[] statusCounts =
gson.fromJson(response, statusCount[].class);
mNewOpenTxt.setText(statusCounts[0].getC());
//Toast.makeText(MainActivity.this, "parsed JSON").show();
}
};
private final Response.ErrorListener newOpenedError = new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {
Log.e("newOpened", error.toString());
Toast.makeText(MainActivity.this, "Failed to return ward data", Toast.LENGTH_SHORT).show();
}
};
private String createURL_backlog(String ward) {
StringBuilder out = new StringBuilder(BASE_URL);
out.append("?$query=SELECT COUNT(*) AS C WHERE ward == ");
out.append(ward);
out.append(" AND status == 'Open' AND created_date < '2019-12-01T00:00:00' GROUP BY status");
try {
return out.toString();
} catch (Exception e) {
e.printStackTrace();
}
return null; //URL was malformed
}
private void fetchBacklog(String url) {
StringRequest stringRequest = new StringRequest(Request.Method.GET, url, backlogLoaded, backlogError);
mQueue.add(stringRequest);
}
private final Response.Listener<String> backlogLoaded = new Response.Listener<String>() {
@Override
public void onResponse(String response) {
statusCount[] statusCounts =
gson.fromJson(response, statusCount[].class);
mBacklogOpenTxt.setText(statusCounts[0].getC());
//Toast.makeText(MainActivity.this, "parsed JSON").show();
}
};
private final Response.ErrorListener backlogError = new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {
Log.e("backlog", error.toString());
Toast.makeText(MainActivity.this, "Failed to return ward data", Toast.LENGTH_SHORT).show();
}
};
private String createURL_closed(String ward) {
StringBuilder out = new StringBuilder(BASE_URL);
out.append("?$query=SELECT COUNT(*) AS C WHERE ward == ");
out.append(ward);
out.append(" AND status == 'Completed' AND closed_date BETWEEN '2019-12-01T00:00:00' AND '2020-01-01T00:00:00' GROUP BY status");
try {
return out.toString();
} catch (Exception e) {
e.printStackTrace();
}
return null; //URL was malformed
}
private void fetchClosed(String url) {
StringRequest stringRequest = new StringRequest(Request.Method.GET, url, closedLoaded, closedError);
mQueue.add(stringRequest);
}
private final Response.Listener<String> closedLoaded = new Response.Listener<String>() {
@Override
public void onResponse(String response) {
statusCount[] statusCounts =
gson.fromJson(response, statusCount[].class);
mClosedTxt.setText(statusCounts[0].getC());
//Toast.makeText(MainActivity.this, "parsed JSON").show();
}
};
private final Response.ErrorListener closedError = new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {
Log.e("closed", error.toString());
Toast.makeText(MainActivity.this, "Failed to return ward data", Toast.LENGTH_SHORT).show();
}
};
}
\ No newline at end of file
package com.example.dynamicduals2.jigs;
import com.google.gson.annotations.Expose;
import com.google.gson.annotations.SerializedName;
public class statusCount {
@SerializedName("C")
@Expose
private String c;
public String getC() {
return c;
}
public void setC(String c) {
this.c = c;
}
}
...@@ -10,8 +10,9 @@ ...@@ -10,8 +10,9 @@
<LinearLayout <LinearLayout
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="0dp" android:layout_height="25dp"
android:layout_weight="10" android:layout_gravity="center"
android:layout_weight="15"
android:orientation="horizontal" android:orientation="horizontal"
android:weightSum="100"> android:weightSum="100">
...@@ -31,17 +32,133 @@ ...@@ -31,17 +32,133 @@
<Button <Button
android:id="@+id/btnTop3Complaints" android:id="@+id/btnTop3Complaints"
android:layout_width="100dp" android:layout_width="100dp"
android:layout_height="20dp" android:layout_height="wrap_content"
android:layout_gravity="center_horizontal" android:layout_gravity="center_horizontal"
android:layout_weight="5" android:layout_weight="5"
android:text="Search" /> android:text="Search" />
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="5"
android:gravity="center"
android:text="Summary for December 2019"
android:textSize="20dp" />
<LinearLayout <LinearLayout
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_weight="10" android:layout_weight="30"
android:weightSum="100" android:orientation="vertical"
android:orientation="vertical"> android:weightSum="100">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="33"
android:orientation="horizontal"
android:weightSum="100">
<TextView
style="@style/CharLabelTxt"
android:text="Open requests backlog: " />
<TextView
android:id="@+id/sr_open_backlog"
style="@style/CharLabelValue" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="33"
android:orientation="horizontal"
android:weightSum="100">
<TextView
style="@style/CharLabelTxt"
android:text="New opened requests: " />
<TextView
android:id="@+id/sr_new_open"
style="@style/CharLabelValue" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="33"
android:orientation="horizontal"
android:weightSum="100">
<TextView
style="@style/CharLabelTxt"
android:text="Closed requests: " />
<TextView
android:id="@+id/sr_closed"
style="@style/CharLabelValue" />
</LinearLayout>
</LinearLayout>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="5"
android:gravity="center"
android:text="Top 3 Complaint Types"
android:textSize="20dp" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="5"
android:orientation="vertical"
android:weightSum="100">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="50"
android:orientation="horizontal"
android:weightSum="100">
<TextView
style="@style/CharLabelTxt"
android:text="Request Type: " />
<TextView
android:id="@+id/sr_type0Label"
style="@style/CharLabelValue" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="50"
android:orientation="horizontal"
android:weightSum="100">
<TextView
style="@style/CharLabelTxt"
android:text="Count: " />
<TextView
android:id="@+id/sr_type0Count"
style="@style/CharLabelValue" />
</LinearLayout>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="5"
android:orientation="vertical"
android:weightSum="100">
<LinearLayout <LinearLayout
...@@ -83,9 +200,9 @@ ...@@ -83,9 +200,9 @@
<LinearLayout <LinearLayout
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_weight="10" android:layout_weight="5"
android:weightSum="100" android:orientation="vertical"
android:orientation="vertical"> android:weightSum="100">
<LinearLayout <LinearLayout
......
...@@ -10,22 +10,23 @@ ...@@ -10,22 +10,23 @@
<style name="CharLabelTxt"> <style name="CharLabelTxt">
<item name="android:layout_width">0dp</item> <item name="android:layout_width">0dp</item>
<item name="android:layout_weight">20</item> <item name="android:layout_weight">40</item>
<item name="android:layout_height">wrap_content</item> <item name="android:layout_height">wrap_content</item>
<item name="android:textSize">16dp</item> <item name="android:textSize">16dp</item>
<item name="android:textStyle">bold</item> <item name="android:textStyle">bold</item>
<item name="android:gravity">right</item> <item name="android:gravity">left</item>
<item name="android:paddingRight">5dp</item> <item name="android:paddingLeft">5dp</item>
</style> </style>
<style name="CharLabelValue"> <style name="CharLabelValue">
<item name="android:layout_width">0dp</item> <item name="android:layout_width">0dp</item>
<item name="android:layout_weight">80</item> <item name="android:layout_weight">60</item>
<item name="android:layout_height">wrap_content</item> <item name="android:layout_height">wrap_content</item>
<item name="android:textSize">16dp</item> <item name="android:textSize">16dp</item>
<item name="android:textStyle">bold</item> <item name="android:textStyle">bold</item>
<item name="android:gravity">right</item> <item name="android:scrollbars">vertical</item>
<item name="android:paddingRight">5dp</item> <item name="android:gravity">left</item>
<item name="android:paddingLeft">5dp</item>
</style> </style>
</resources> </resources>
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment