Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
Jorge Guerra Schleske
/
harrishack3
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Merge Requests
0
Pipelines
Members
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit
4965b9d9
authored
Jan 11, 2020
by
Simeon Markind
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fully minimally functional
parent
6e496c13
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
301 additions
and
24 deletions
DynamicDuals2/app/src/main/AndroidManifest.xml
DynamicDuals2/app/src/main/java/com/example/dynamicduals2/MainActivity.java
DynamicDuals2/app/src/main/java/com/example/dynamicduals2/jigs/statusCount.java
DynamicDuals2/app/src/main/res/layout/content_main.xml
DynamicDuals2/app/src/main/res/values/styles.xml
DynamicDuals2/app/src/main/AndroidManifest.xml
View file @
4965b9d9
...
...
@@ -11,8 +11,12 @@
android:label=
"@string/app_name"
android:roundIcon=
"@mipmap/ic_launcher_round"
android:supportsRtl=
"true"
android:theme=
"@style/AppTheme"
>
<activity
android:name=
".MainActivity"
>
android:theme=
"@style/AppTheme"
>
<activity
android:name=
".MainActivity"
android:windowSoftInputMode=
"stateHidden|adjustPan"
>
<intent-filter>
<action
android:name=
"android.intent.action.MAIN"
/>
...
...
DynamicDuals2/app/src/main/java/com/example/dynamicduals2/MainActivity.java
View file @
4965b9d9
...
...
@@ -16,6 +16,7 @@ import com.android.volley.VolleyError;
import
com.android.volley.toolbox.StringRequest
;
import
com.android.volley.toolbox.Volley
;
import
com.example.dynamicduals2.jigs.ComplaintTypeCount
;
import
com.example.dynamicduals2.jigs.statusCount
;
import
com.google.gson.Gson
;
import
com.google.gson.reflect.TypeToken
;
...
...
@@ -34,8 +35,15 @@ public class MainActivity extends AppCompatActivity {
private
EditText
mWard
;
private
Gson
gson
;
private
TextView
mSR_TYPE0
;
private
TextView
mC_0
;
private
TextView
mSR_TYPE1
;
private
TextView
mC_1
;
private
TextView
mSR_TYPE2
;
private
TextView
mC_2
;
private
TextView
mNewOpenTxt
;
private
TextView
mBacklogOpenTxt
;
private
TextView
mClosedTxt
;
private
RequestQueue
mQueue
;
@Override
...
...
@@ -49,44 +57,80 @@ public class MainActivity extends AppCompatActivity {
mBtnTop3
=
findViewById
(
R
.
id
.
btnTop3Complaints
);
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
);
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
()
{
@Override
public
void
onClick
(
View
v
)
{
//Build the URL
Integer
wardInt
=
Integer
.
parseInt
(
mWard
.
getText
().
toString
());
if
(
wardInt
<=
0
||
wardInt
>
50
)
{
if
(
wardInt
<=
0
||
wardInt
>
50
)
{
System
.
out
.
println
(
"Invalid Ward Number"
);
Toast
.
makeText
(
getApplicationContext
(),
"Invalid Ward Number"
,
Toast
.
LENGTH_SHORT
).
show
();
}
else
{
String
url
=
createURL
(
mWard
.
getText
().
toString
());
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
);
out
.
append
(
"?$query=SELECT sr_type, COUNT(*) AS C WHERE 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
{
return
out
.
toString
();
}
catch
(
Exception
e
){
}
catch
(
Exception
e
)
{
e
.
printStackTrace
();
}
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
)
{
StringRequest
stringRequest
=
new
StringRequest
(
Request
.
Method
.
GET
,
url
,
onTop3ListLoaded
,
onTop3ListError
);
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
>()
{
@Override
public
void
onResponse
(
String
response
)
{
...
...
@@ -94,8 +138,12 @@ public class MainActivity extends AppCompatActivity {
ComplaintTypeCount
[]
complaintTypeCounts
=
gson
.
fromJson
(
response
,
ComplaintTypeCount
[].
class
);
mSR_TYPE1
.
setText
(
complaintTypeCounts
[
0
].
getSrType
());
mC_1
.
setText
(
complaintTypeCounts
[
0
].
getC
());
mSR_TYPE0
.
setText
(
complaintTypeCounts
[
0
].
getSrType
());
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();
}
};
...
...
@@ -107,4 +155,92 @@ public class MainActivity extends AppCompatActivity {
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
DynamicDuals2/app/src/main/java/com/example/dynamicduals2/jigs/statusCount.java
0 → 100644
View file @
4965b9d9
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
;
}
}
DynamicDuals2/app/src/main/res/layout/content_main.xml
View file @
4965b9d9
...
...
@@ -10,8 +10,9 @@
<LinearLayout
android:layout_width=
"match_parent"
android:layout_height=
"0dp"
android:layout_weight=
"10"
android:layout_height=
"25dp"
android:layout_gravity=
"center"
android:layout_weight=
"15"
android:orientation=
"horizontal"
android:weightSum=
"100"
>
...
...
@@ -31,17 +32,133 @@
<Button
android:id=
"@+id/btnTop3Complaints"
android:layout_width=
"100dp"
android:layout_height=
"
20dp
"
android:layout_height=
"
wrap_content
"
android:layout_gravity=
"center_horizontal"
android:layout_weight=
"5"
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
android:layout_width=
"match_parent"
android:layout_height=
"wrap_content"
android:layout_weight=
"10"
android:weightSum=
"100"
android:orientation=
"vertical"
>
android:layout_weight=
"30"
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
...
...
@@ -83,9 +200,9 @@
<LinearLayout
android:layout_width=
"match_parent"
android:layout_height=
"wrap_content"
android:layout_weight=
"
10
"
android:
weightSum=
"100
"
android:
orientation=
"vertical
"
>
android:layout_weight=
"
5
"
android:
orientation=
"vertical
"
android:
weightSum=
"100
"
>
<LinearLayout
...
...
DynamicDuals2/app/src/main/res/values/styles.xml
View file @
4965b9d9
...
...
@@ -10,22 +10,23 @@
<style
name=
"CharLabelTxt"
>
<item
name=
"android:layout_width"
>
0dp
</item>
<item
name=
"android:layout_weight"
>
2
0
</item>
<item
name=
"android:layout_weight"
>
4
0
</item>
<item
name=
"android:layout_height"
>
wrap_content
</item>
<item
name=
"android:textSize"
>
16dp
</item>
<item
name=
"android:textStyle"
>
bold
</item>
<item
name=
"android:gravity"
>
righ
t
</item>
<item
name=
"android:padding
Righ
t"
>
5dp
</item>
<item
name=
"android:gravity"
>
lef
t
</item>
<item
name=
"android:padding
Lef
t"
>
5dp
</item>
</style>
<style
name=
"CharLabelValue"
>
<item
name=
"android:layout_width"
>
0dp
</item>
<item
name=
"android:layout_weight"
>
8
0
</item>
<item
name=
"android:layout_weight"
>
6
0
</item>
<item
name=
"android:layout_height"
>
wrap_content
</item>
<item
name=
"android:textSize"
>
16dp
</item>
<item
name=
"android:textStyle"
>
bold
</item>
<item
name=
"android:gravity"
>
right
</item>
<item
name=
"android:paddingRight"
>
5dp
</item>
<item
name=
"android:scrollbars"
>
vertical
</item>
<item
name=
"android:gravity"
>
left
</item>
<item
name=
"android:paddingLeft"
>
5dp
</item>
</style>
</resources>
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment