DT @2.11.2015: Vote Functions implemented. Deactive incident now possible (but has to be tested).
This commit is contained in:
@@ -6,6 +6,8 @@ import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.database.Cursor;
|
||||
import android.graphics.Color;
|
||||
import android.location.Address;
|
||||
import android.location.Geocoder;
|
||||
import android.os.Bundle;
|
||||
import android.support.v4.app.LoaderManager;
|
||||
import android.support.v4.content.CursorLoader;
|
||||
@@ -39,7 +41,10 @@ import org.json.JSONArray;
|
||||
import org.json.JSONException;
|
||||
import org.json.JSONObject;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
import java.util.Map;
|
||||
|
||||
|
||||
@@ -62,6 +67,7 @@ public class MapsActivity extends BaseActivity implements LoaderManager.LoaderCa
|
||||
|
||||
mMap = ((SupportMapFragment) getSupportFragmentManager().findFragmentById(R.id.frag_maps_map)).getMap();
|
||||
mMap.getUiSettings().setZoomControlsEnabled(true);
|
||||
|
||||
handleIntent(getIntent());
|
||||
|
||||
findViewById(R.id.btn_maps_confirm_position).setVisibility(View.GONE);
|
||||
@@ -99,10 +105,20 @@ public class MapsActivity extends BaseActivity implements LoaderManager.LoaderCa
|
||||
{
|
||||
String query = intent.getStringExtra(SearchManager.QUERY);
|
||||
doSearch(query);
|
||||
}
|
||||
else if(Intent.ACTION_VIEW.equals(intent.getAction()))
|
||||
{
|
||||
} else if(Intent.ACTION_VIEW.equals(intent.getAction())) {
|
||||
getPlace(intent.getStringExtra(SearchManager.EXTRA_DATA_KEY));
|
||||
} else {
|
||||
String pos = intent.getStringExtra(EXTRA_MESSAGE);
|
||||
|
||||
if(pos != null) {
|
||||
String[] position = pos.split(":");
|
||||
|
||||
String latitude = position[0];
|
||||
String longitude = position[1];
|
||||
|
||||
LatLng point = new LatLng(Double.parseDouble(latitude),Double.parseDouble(longitude));
|
||||
mMap.animateCamera(CameraUpdateFactory.newLatLngZoom(point, 12.0f));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -15,14 +15,17 @@ import com.android.volley.Request;
|
||||
import com.android.volley.Response;
|
||||
import com.android.volley.VolleyError;
|
||||
import com.android.volley.toolbox.StringRequest;
|
||||
import com.beardedhen.androidbootstrap.BootstrapLabel;
|
||||
|
||||
import org.deke.risk.riskahead.helper.AppConfig;
|
||||
import org.deke.risk.riskahead.helper.AppController;
|
||||
import org.deke.risk.riskahead.helper.BaseActivity;
|
||||
import org.json.JSONArray;
|
||||
import org.json.JSONException;
|
||||
import org.json.JSONObject;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
@@ -46,6 +49,9 @@ public class ViewReportActivity extends BaseActivity {
|
||||
super.onCreate(savedInstanceState);
|
||||
userHasToBeLoggedIn();
|
||||
|
||||
Intent intent = getIntent();
|
||||
final String uid = intent.getStringExtra(BaseActivity.EXTRA_MESSAGE);
|
||||
|
||||
txtTitle = (EditText) findViewById(R.id.input_viewreport_short);
|
||||
txtDescription = (EditText) findViewById(R.id.input_viewreport_long);
|
||||
txtCrimeCategory = (EditText) findViewById(R.id.input_viewreport_category);
|
||||
@@ -54,21 +60,33 @@ public class ViewReportActivity extends BaseActivity {
|
||||
txtPosition = (EditText) findViewById(R.id.input_viewreport_position);
|
||||
txtPositionDetail = (TextView) findViewById(R.id.lbl_viewreport_position_detail);
|
||||
|
||||
getIncident();
|
||||
getIncident(uid);
|
||||
getIncidentVoteScore(uid);
|
||||
|
||||
findViewById(R.id.btn_viewreport_upvote).setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
showMessage("Upvote!");
|
||||
makeUpvote(uid);
|
||||
}
|
||||
});
|
||||
|
||||
findViewById(R.id.btn_viewreport_downvote).setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
showMessage("Downvote!");
|
||||
makeDownvote(uid);
|
||||
}
|
||||
});
|
||||
|
||||
findViewById(R.id.btn_viewreport_delete).setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
deleteReport(uid);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private void deleteReport(String uid) {
|
||||
deleteIncident(uid);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -81,6 +99,71 @@ public class ViewReportActivity extends BaseActivity {
|
||||
return mActivityTitle;
|
||||
}
|
||||
|
||||
public void deleteIncident(String uid) {
|
||||
String tag_string_req = "deactivateIncident";
|
||||
StringRequest strReq = getStringRequestGetIncidentWithPositionFromID(uid);
|
||||
AppController.getInstance().addToRequestQueue(strReq, tag_string_req);
|
||||
}
|
||||
|
||||
public void getIncident(String uid) {
|
||||
String tag_string_req = "getincidentwithpositionfromid";
|
||||
StringRequest strReq = getStringRequestDeleteIncident(uid);
|
||||
AppController.getInstance().addToRequestQueue(strReq, tag_string_req);
|
||||
}
|
||||
|
||||
private StringRequest getStringRequestDeleteIncident(final String incidentid) {
|
||||
return new StringRequest(Request.Method.POST, AppConfig.URL_REGISTER, new Response.Listener<String>() {
|
||||
|
||||
@Override
|
||||
public void onResponse(String response) {
|
||||
Log.d(TAG, "Delete Incident with ID response: " + response);
|
||||
hideDialog();
|
||||
|
||||
try {
|
||||
JSONObject jObj = new JSONObject(response);
|
||||
boolean error = jObj.getBoolean("error");
|
||||
|
||||
// Check for error node in json
|
||||
if (!error) {
|
||||
showMessage("Incident deleted");
|
||||
gotoProfileActivity();
|
||||
} else {
|
||||
// Error in login. Get the error message
|
||||
String errorMsg = jObj.getString("error_msg");
|
||||
Toast.makeText(getApplicationContext(), errorMsg, Toast.LENGTH_LONG).show();
|
||||
}
|
||||
} catch (JSONException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}, new Response.ErrorListener() {
|
||||
|
||||
@Override
|
||||
public void onErrorResponse(VolleyError error) {
|
||||
Log.e(TAG, "Report Error: " + error.getMessage());
|
||||
Toast.makeText(getApplicationContext(),
|
||||
error.getMessage(), Toast.LENGTH_LONG).show();
|
||||
hideDialog();
|
||||
}
|
||||
}) {
|
||||
|
||||
@Override
|
||||
protected Map<String, String> getParams() {
|
||||
// Posting parameters to login url
|
||||
Map<String, String> params = new HashMap<>();
|
||||
params.put("tag", "deactivateIncident");
|
||||
params.put("uid", user.get("uid"));
|
||||
params.put("token", user.get("token"));
|
||||
params.put("incidentid", incidentid);
|
||||
|
||||
|
||||
return params;
|
||||
}
|
||||
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
private StringRequest getStringRequestGetIncidentWithPositionFromID(final String incidentid) {
|
||||
return new StringRequest(Request.Method.POST, AppConfig.URL_REGISTER, new Response.Listener<String>() {
|
||||
|
||||
@@ -103,13 +186,28 @@ public class ViewReportActivity extends BaseActivity {
|
||||
|
||||
String[] happened_at = incident.getString("happened_at").split(" ");
|
||||
txtDate.setText(happened_at[0]);
|
||||
txtTime.setText(happened_at[1].substring(0,5));
|
||||
txtTime.setText(happened_at[1].substring(0, 5));
|
||||
|
||||
Geocoder geocoder = new Geocoder(getApplicationContext(), Locale.getDefault());
|
||||
List<Address> addresses = geocoder.getFromLocation(incident.getDouble("latitude"), incident.getDouble("longitude"), 1);
|
||||
|
||||
txtPosition.setText(addresses.get(0).getLocality());
|
||||
txtPositionDetail.setText(addresses.get(0).getAddressLine(0));
|
||||
try{
|
||||
txtPosition.setText(addresses.get(0).getLocality());
|
||||
txtPositionDetail.setText(addresses.get(0).getAddressLine(0));
|
||||
} catch (Exception e) {
|
||||
//do nothing
|
||||
}
|
||||
|
||||
|
||||
final String latitude = incident.getString("latitude");
|
||||
final String longitude = incident.getString("longitude");
|
||||
|
||||
findViewById(R.id.btn_viewreport_position).setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
gotoMapActivity(latitude+":"+longitude);
|
||||
}
|
||||
});
|
||||
|
||||
} else {
|
||||
// Error in login. Get the error message
|
||||
@@ -149,13 +247,129 @@ public class ViewReportActivity extends BaseActivity {
|
||||
};
|
||||
}
|
||||
|
||||
public void getIncident() {
|
||||
Intent intent = getIntent();
|
||||
String uid = intent.getStringExtra(BaseActivity.EXTRA_MESSAGE);
|
||||
|
||||
String tag_string_req = "getincidentwithpositionfromid";
|
||||
StringRequest strReq = getStringRequestGetIncidentWithPositionFromID(uid);
|
||||
public void getIncidentVoteScore(String uid) {
|
||||
String tag_string_req = "getincidentvotescore";
|
||||
StringRequest strReq = getStringRequestGetIncidentVoteScore(uid);
|
||||
AppController.getInstance().addToRequestQueue(strReq, tag_string_req);
|
||||
}
|
||||
|
||||
private StringRequest getStringRequestGetIncidentVoteScore(final String incidentid) {
|
||||
return new StringRequest(Request.Method.POST, AppConfig.URL_REGISTER, new Response.Listener<String>() {
|
||||
|
||||
@Override
|
||||
public void onResponse(String response) {
|
||||
Log.d(TAG, "IncidentScore with ID response: " + response);
|
||||
hideDialog();
|
||||
|
||||
try {
|
||||
JSONObject jObj = new JSONObject(response);
|
||||
boolean error = jObj.getBoolean("error");
|
||||
|
||||
// Check for error node in json
|
||||
if (!error) {
|
||||
BootstrapLabel scorelabel = (BootstrapLabel) findViewById(R.id.txt_viewreport_points);
|
||||
scorelabel.setText(jObj.getString("points"));
|
||||
} else {
|
||||
// Error in login. Get the error message
|
||||
String errorMsg = jObj.getString("error_msg");
|
||||
Toast.makeText(getApplicationContext(), errorMsg, Toast.LENGTH_LONG).show();
|
||||
}
|
||||
} catch (JSONException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}, new Response.ErrorListener() {
|
||||
|
||||
@Override
|
||||
public void onErrorResponse(VolleyError error) {
|
||||
Log.e(TAG, "Report Error: " + error.getMessage());
|
||||
Toast.makeText(getApplicationContext(),
|
||||
error.getMessage(), Toast.LENGTH_LONG).show();
|
||||
hideDialog();
|
||||
}
|
||||
}) {
|
||||
|
||||
@Override
|
||||
protected Map<String, String> getParams() {
|
||||
// Posting parameters to login url
|
||||
Map<String, String> params = new HashMap<>();
|
||||
params.put("tag", "getincidentvotescore");
|
||||
params.put("uid", user.get("uid"));
|
||||
params.put("token", user.get("token"));
|
||||
params.put("incidentid", incidentid);
|
||||
|
||||
|
||||
return params;
|
||||
}
|
||||
|
||||
};
|
||||
}
|
||||
|
||||
public void makeUpvote(String uid) {
|
||||
String tag_string_req = "addvote";
|
||||
StringRequest strReq = getStringRequestAddVote(uid, "1");
|
||||
AppController.getInstance().addToRequestQueue(strReq, tag_string_req);
|
||||
}
|
||||
|
||||
public void makeDownvote(String uid) {
|
||||
String tag_string_req = "addvote";
|
||||
StringRequest strReq = getStringRequestAddVote(uid, "2");
|
||||
AppController.getInstance().addToRequestQueue(strReq, tag_string_req);
|
||||
}
|
||||
|
||||
private StringRequest getStringRequestAddVote(final String incidentid, final String votetype) {
|
||||
return new StringRequest(Request.Method.POST, AppConfig.URL_REGISTER, new Response.Listener<String>() {
|
||||
|
||||
@Override
|
||||
public void onResponse(String response) {
|
||||
Log.d(TAG, "MadeVote: " + response);
|
||||
hideDialog();
|
||||
|
||||
try {
|
||||
JSONObject jObj = new JSONObject(response);
|
||||
boolean error = jObj.getBoolean("error");
|
||||
|
||||
// Check for error node in json
|
||||
if (!error) {
|
||||
showMessage("Voted! Score updated.");
|
||||
BootstrapLabel scorelabel = (BootstrapLabel) findViewById(R.id.txt_viewreport_points);
|
||||
scorelabel.setText(jObj.getString("points"));
|
||||
|
||||
} else {
|
||||
// Error in login. Get the error message
|
||||
String errorMsg = jObj.getString("error_msg");
|
||||
Toast.makeText(getApplicationContext(), errorMsg, Toast.LENGTH_LONG).show();
|
||||
}
|
||||
} catch (JSONException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}, new Response.ErrorListener() {
|
||||
|
||||
@Override
|
||||
public void onErrorResponse(VolleyError error) {
|
||||
Log.e(TAG, "Report Error: " + error.getMessage());
|
||||
Toast.makeText(getApplicationContext(),
|
||||
error.getMessage(), Toast.LENGTH_LONG).show();
|
||||
hideDialog();
|
||||
}
|
||||
}) {
|
||||
|
||||
@Override
|
||||
protected Map<String, String> getParams() {
|
||||
// Posting parameters to login url
|
||||
Map<String, String> params = new HashMap<>();
|
||||
params.put("tag", "addvote");
|
||||
params.put("uid", user.get("uid"));
|
||||
params.put("token", user.get("token"));
|
||||
params.put("incidentid", incidentid);
|
||||
params.put("votetype", votetype);
|
||||
|
||||
|
||||
return params;
|
||||
}
|
||||
|
||||
};
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -224,6 +224,13 @@ public abstract class BaseActivity extends AppCompatActivity {
|
||||
startActivity(intent);
|
||||
}
|
||||
|
||||
public void gotoMapActivity(String position){
|
||||
Intent intent;
|
||||
intent = new Intent(getApplicationContext(), MapsActivity.class);
|
||||
intent.putExtra(EXTRA_MESSAGE, position);
|
||||
startActivity(intent);
|
||||
}
|
||||
|
||||
public void gotoProfileActivity(){
|
||||
Intent intent;
|
||||
intent = new Intent(getApplicationContext(), ProfileActivity.class);
|
||||
|
||||
@@ -151,6 +151,17 @@
|
||||
android:layout_alignStart="@+id/lbl_viewreport_position"
|
||||
android:editable="false"/>
|
||||
|
||||
<com.beardedhen.androidbootstrap.BootstrapButton
|
||||
android:id="@+id/btn_viewreport_position"
|
||||
bootstrap:bootstrapText="@string/btn_report_position"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
bootstrap:bootstrapBrand="primary"
|
||||
bootstrap:roundedCorners="true"
|
||||
android:layout_marginTop="7dp"
|
||||
android:layout_alignTop="@+id/lbl_viewreport_position"
|
||||
android:layout_alignRight="@+id/input_viewreport_time"
|
||||
android:layout_alignEnd="@+id/input_viewreport_time" />
|
||||
|
||||
<TextView
|
||||
android:layout_width="wrap_content"
|
||||
@@ -216,15 +227,14 @@
|
||||
android:layout_alignParentStart="true"
|
||||
android:layout_marginBottom="0dp">
|
||||
|
||||
<Button
|
||||
android:text="Edit"
|
||||
<com.beardedhen.androidbootstrap.BootstrapButton
|
||||
android:id="@+id/btn_viewreport_delete"
|
||||
bootstrap:bootstrapText="@string/btn_viewreport_delete"
|
||||
android:minWidth="300dp"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content" />
|
||||
|
||||
<Button
|
||||
android:text="Delete"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content" />
|
||||
android:layout_height="wrap_content"
|
||||
bootstrap:bootstrapBrand="danger"
|
||||
bootstrap:roundedCorners="true" />
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
|
||||
@@ -65,7 +65,7 @@
|
||||
<string name="lbl_report_category">Crime Category</string>
|
||||
<string name="lbl_report_time">Time </string>
|
||||
<string name="lbl_report_date">Date (yyyy-mm-dd)</string>
|
||||
|
||||
<string name="btn_viewreport_delete">Delete Report</string>
|
||||
<string name="lbl_settings_name">Name</string>
|
||||
<string name="lbl_settings_surname">Surname</string>
|
||||
<string name="lbl_settings_email">E-Mail</string>
|
||||
|
||||
Reference in New Issue
Block a user