Search in sources :

Example 1 with FalaeMsgForJson

use of br.ufrj.caronae.models.modelsforjson.FalaeMsgForJson in project caronae-android by caronae.

the class FalaeFrag method sendBt.

@OnClick(R.id.send_bt)
public void sendBt() {
    String message = message_et.getText().toString();
    if (message.isEmpty()) {
        Util.toast(getActivity().getString(R.string.frag_falae_msgblank));
        return;
    }
    message = message + "\n\n--------------------------------\n" + "Device: " + android.os.Build.MODEL + " (Android " + android.os.Build.VERSION.RELEASE + ")\n" + "Versão do app: " + Util.getAppVersionName(getContext());
    int checkedId = radioGroup.getCheckedRadioButtonId();
    String subject = "";
    switch(checkedId) {
        case R.id.suggestion_rb:
            subject = getActivity().getString(R.string.frag_falae_suggestionRb);
            break;
        case R.id.question_rb:
            subject = getActivity().getString(R.string.frag_falae_questionRb);
            break;
        case R.id.report_rb:
            subject = getActivity().getString(R.string.frag_falae_reportRb);
            break;
    }
    subject = subject.concat(subject_et.getText().toString());
    final ProgressDialog pd = ProgressDialog.show(getContext(), "", getString(R.string.wait), true, true);
    CaronaeAPI.service(getContext()).falaeSendMessage(new FalaeMsgForJson(subject, message)).enqueue(new Callback<ResponseBody>() {

        @Override
        public void onResponse(Call<ResponseBody> call, Response<ResponseBody> response) {
            if (response.isSuccessful()) {
                pd.dismiss();
                Util.toast(getActivity().getString(R.string.frag_falae_thanksSent));
                subject_et.setText("");
                message_et.setText("");
                Log.i("falaeSendMessage", "falae message sent succesfully");
            } else {
                Util.treatResponseFromServer(response);
                pd.dismiss();
                Util.toast(getActivity().getString(R.string.frag_falae_errorSent));
                Log.e("falaeSendMessage", response.message());
            }
        }

        @Override
        public void onFailure(Call<ResponseBody> call, Throwable t) {
            pd.dismiss();
            Util.toast(getActivity().getString(R.string.frag_falae_errorSent));
            Log.e("falaeSendMessage", t.getMessage());
        }
    });
}
Also used : FalaeMsgForJson(br.ufrj.caronae.models.modelsforjson.FalaeMsgForJson) ProgressDialog(android.app.ProgressDialog) ResponseBody(okhttp3.ResponseBody) OnClick(butterknife.OnClick)

Example 2 with FalaeMsgForJson

use of br.ufrj.caronae.models.modelsforjson.FalaeMsgForJson in project caronae-android by caronae.

the class ProfileAct method reportBt.

@OnClick(R.id.report_bt)
public void reportBt() {
    Dialog.Builder builder = new SimpleDialog.Builder(R.style.SimpleDialogLight) {

        @Override
        protected void onBuildDone(Dialog dialog) {
            dialog.layoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT);
        }

        @Override
        public void onPositiveActionClicked(DialogFragment fragment) {
            EditText msg_et = (EditText) fragment.getDialog().findViewById(R.id.msg_et);
            String msg = msg_et.getText().toString();
            if (msg.isEmpty()) {
                Util.toast(getString(R.string.frag_falae_msgblank));
                return;
            }
            msg = msg + "\n\n--------------------------------\n" + "Device: " + android.os.Build.MODEL + " (Android " + android.os.Build.VERSION.RELEASE + ")\n" + "Versão do app: " + Util.getAppVersionName(getBaseContext());
            CaronaeAPI.service(getApplicationContext()).falaeSendMessage(new FalaeMsgForJson(getString(R.string.frag_falae_reportRb) + user.getName() + " - ID:" + user.getDbId(), msg)).enqueue(new Callback<ResponseBody>() {

                @Override
                public void onResponse(Call<ResponseBody> call, Response<ResponseBody> response) {
                    if (response.isSuccessful()) {
                        Util.toast(getString(R.string.act_profile_reportOk));
                        Log.i("falaeSendMessage", "falae message sent succesfully");
                    } else {
                        Util.treatResponseFromServer(response);
                        Util.toast(getString(R.string.frag_falae_errorSent));
                        Log.e("falaeSendMessage", response.message());
                    }
                }

                @Override
                public void onFailure(Call<ResponseBody> call, Throwable t) {
                    Util.toast(getString(R.string.frag_falae_errorSent));
                    Log.e("falaeSendMessage", t.getMessage());
                }
            });
            super.onPositiveActionClicked(fragment);
        }

        @Override
        public void onNegativeActionClicked(DialogFragment fragment) {
            super.onNegativeActionClicked(fragment);
        }
    };
    String name = user.getName().split(" ")[0];
    builder.title("Reportar " + name).positiveAction(getString(R.string.send_bt)).negativeAction(getString(R.string.cancel)).contentView(R.layout.report_dialog);
    DialogFragment fragment = DialogFragment.newInstance(builder);
    fragment.show(getSupportFragmentManager(), null);
}
Also used : EditText(android.widget.EditText) DialogFragment(com.rey.material.app.DialogFragment) FalaeMsgForJson(br.ufrj.caronae.models.modelsforjson.FalaeMsgForJson) ResponseBody(okhttp3.ResponseBody) AlertDialog(android.support.v7.app.AlertDialog) SimpleDialog(com.rey.material.app.SimpleDialog) Dialog(com.rey.material.app.Dialog) OnClick(butterknife.OnClick)

Aggregations

FalaeMsgForJson (br.ufrj.caronae.models.modelsforjson.FalaeMsgForJson)2 OnClick (butterknife.OnClick)2 ResponseBody (okhttp3.ResponseBody)2 ProgressDialog (android.app.ProgressDialog)1 AlertDialog (android.support.v7.app.AlertDialog)1 EditText (android.widget.EditText)1 Dialog (com.rey.material.app.Dialog)1 DialogFragment (com.rey.material.app.DialogFragment)1 SimpleDialog (com.rey.material.app.SimpleDialog)1