use of app.insti.api.response.ComplaintCreateResponse in project IITB-App by wncc.
the class FileComplaintFragment method addComplaint.
private void addComplaint() {
final String complaint = descriptionAutoCompleteTextview.getText().toString();
final String suggestion;
final String locationDetails;
if (!(editTextSuggestions.getText().toString().isEmpty())) {
suggestion = editTextSuggestions.getText().toString();
} else {
suggestion = "";
}
if (!(editTextLocationDetails.getText().toString().isEmpty())) {
locationDetails = editTextLocationDetails.getText().toString();
} else {
locationDetails = "";
}
if (Location == null) {
// Show an explanation to the user *asynchronously* -- don't block
// this thread waiting for the user's response!
new AlertDialog.Builder(getContext()).setTitle("Location Needed").setMessage("You have not specified your location. The app will by default make \"IIT Area\" as your location.").setPositiveButton("OK", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialogInterface, int i) {
Location = new LatLng(19.133810, 72.913257);
Address = "IIT Area";
ComplaintCreateRequest complaintCreateRequest = new ComplaintCreateRequest(complaint, suggestion, locationDetails, Address, (float) Location.latitude, (float) Location.longitude, Tags, uploadedImagesUrl);
RetrofitInterface retrofitInterface = Utils.getRetrofitInterface();
retrofitInterface.postComplaint("sessionid=" + getArguments().getString(Constants.SESSION_ID), complaintCreateRequest).enqueue(new Callback<ComplaintCreateResponse>() {
@Override
public void onResponse(Call<ComplaintCreateResponse> call, Response<ComplaintCreateResponse> response) {
Toast.makeText(getContext(), "Complaint successfully posted", Toast.LENGTH_LONG).show();
Bundle bundle = getArguments();
bundle.putString(Constants.USER_ID, userId);
ComplaintsFragment complaintsFragment = new ComplaintsFragment();
complaintsFragment.setArguments(bundle);
FragmentManager manager = getFragmentManager();
FragmentTransaction transaction = manager.beginTransaction();
transaction.replace(R.id.framelayout_for_fragment, complaintsFragment, complaintsFragment.getTag());
transaction.addToBackStack(complaintsFragment.getTag());
manager.popBackStackImmediate("Complaint Fragment", FragmentManager.POP_BACK_STACK_INCLUSIVE);
transaction.commit();
}
@Override
public void onFailure(Call<ComplaintCreateResponse> call, Throwable t) {
Log.i(TAG, "failure in addComplaint: " + t.toString());
Toast.makeText(getContext(), "Complaint Creation Failed", Toast.LENGTH_SHORT).show();
}
});
}
}).setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
Toast.makeText(getContext(), "Submission aborted", Toast.LENGTH_SHORT).show();
dialog.cancel();
}
}).create().show();
} else {
ComplaintCreateRequest complaintCreateRequest = new ComplaintCreateRequest(complaint, suggestion, locationDetails, Address, (float) Location.latitude, (float) Location.longitude, Tags, uploadedImagesUrl);
RetrofitInterface retrofitInterface = Utils.getRetrofitInterface();
retrofitInterface.postComplaint("sessionid=" + getArguments().getString(Constants.SESSION_ID), complaintCreateRequest).enqueue(new Callback<ComplaintCreateResponse>() {
@Override
public void onResponse(Call<ComplaintCreateResponse> call, Response<ComplaintCreateResponse> response) {
Toast.makeText(getContext(), "Complaint successfully posted", Toast.LENGTH_LONG).show();
Bundle bundle = getArguments();
bundle.putString(Constants.USER_ID, userId);
ComplaintsFragment complaintsFragment = new ComplaintsFragment();
complaintsFragment.setArguments(bundle);
FragmentManager manager = getFragmentManager();
FragmentTransaction transaction = manager.beginTransaction();
transaction.replace(R.id.framelayout_for_fragment, complaintsFragment, complaintsFragment.getTag());
transaction.addToBackStack(complaintsFragment.getTag());
manager.popBackStackImmediate("Complaint Fragment", FragmentManager.POP_BACK_STACK_INCLUSIVE);
transaction.commit();
}
@Override
public void onFailure(Call<ComplaintCreateResponse> call, Throwable t) {
Log.i(TAG, "failure in addComplaint: " + t.toString());
Toast.makeText(getContext(), "Complaint Creation Failed", Toast.LENGTH_SHORT).show();
}
});
}
}
Aggregations