Search in sources :

Example 1 with ComplaintCreateRequest

use of app.insti.api.request.ComplaintCreateRequest 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();
            }
        });
    }
}
Also used : DialogInterface(android.content.DialogInterface) ComplaintCreateResponse(app.insti.api.response.ComplaintCreateResponse) Bundle(android.os.Bundle) FragmentManager(androidx.fragment.app.FragmentManager) FragmentTransaction(androidx.fragment.app.FragmentTransaction) ComplaintCreateRequest(app.insti.api.request.ComplaintCreateRequest) LatLng(com.google.android.gms.maps.model.LatLng) RetrofitInterface(app.insti.api.RetrofitInterface)

Aggregations

DialogInterface (android.content.DialogInterface)1 Bundle (android.os.Bundle)1 FragmentManager (androidx.fragment.app.FragmentManager)1 FragmentTransaction (androidx.fragment.app.FragmentTransaction)1 RetrofitInterface (app.insti.api.RetrofitInterface)1 ComplaintCreateRequest (app.insti.api.request.ComplaintCreateRequest)1 ComplaintCreateResponse (app.insti.api.response.ComplaintCreateResponse)1 LatLng (com.google.android.gms.maps.model.LatLng)1