Search in sources :

Example 6 with Retrofit

use of retrofit.Retrofit in project xDrip-plus by jamorham.

the class FollowerManagementActivity method setInviteListener.

private void setInviteListener() {
    addFollowerButton.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            final Dialog dialog = new Dialog(FollowerManagementActivity.this);
            dialog.setContentView(R.layout.dialog_invite_follower);
            dialog.setTitle("Invite a Follower");
            Button saveButton = (Button) dialog.findViewById(R.id.saveButton);
            Button cancelButton = (Button) dialog.findViewById(R.id.cancelButton);
            final EditText followerName = (EditText) dialog.findViewById(R.id.followerNameField);
            final EditText followerNicName = (EditText) dialog.findViewById(R.id.followerDisplayNameField);
            final EditText followerEmail = (EditText) dialog.findViewById(R.id.followerEmailField);
            saveButton.setOnClickListener(new View.OnClickListener() {

                @Override
                public void onClick(View v) {
                    if (!TextUtils.isEmpty(followerName.getText()) && !TextUtils.isEmpty(followerNicName.getText()) && !TextUtils.isEmpty(followerEmail.getText())) {
                        shareRest.createContact(followerName.getText().toString().trim(), followerEmail.getText().toString().trim(), new Callback<String>() {

                            @Override
                            public void onResponse(Response<String> response, Retrofit retrofit) {
                                if (response.isSuccess()) {
                                    shareRest.createInvitationForContact(response.body(), new InvitationPayload(followerNicName.getText().toString().trim()), new Callback<String>() {

                                        @Override
                                        public void onResponse(Response<String> response, Retrofit retrofit) {
                                            if (response.isSuccess()) {
                                                populateFollowerList();
                                                Toast.makeText(getApplicationContext(), "Follower invite sent succesfully", Toast.LENGTH_LONG).show();
                                            } else {
                                                Toast.makeText(getApplicationContext(), "Failed to invite follower", Toast.LENGTH_LONG).show();
                                            }
                                        }

                                        @Override
                                        public void onFailure(Throwable t) {
                                            Toast.makeText(getApplicationContext(), "Failed to invite follower", Toast.LENGTH_LONG).show();
                                        }
                                    });
                                } else {
                                    Toast.makeText(getApplicationContext(), "Failed to invite follower", Toast.LENGTH_LONG).show();
                                }
                            }

                            @Override
                            public void onFailure(Throwable t) {
                                Toast.makeText(getApplicationContext(), "Failed to invite follower", Toast.LENGTH_LONG).show();
                            }
                        });
                    }
                    dialog.dismiss();
                }
            });
            cancelButton.setOnClickListener(new View.OnClickListener() {

                @Override
                public void onClick(View v) {
                    dialog.dismiss();
                }
            });
            WindowManager.LayoutParams lp = new WindowManager.LayoutParams();
            lp.copyFrom(dialog.getWindow().getAttributes());
            lp.width = WindowManager.LayoutParams.MATCH_PARENT;
            dialog.show();
            dialog.getWindow().setAttributes(lp);
        }
    });
}
Also used : EditText(android.widget.EditText) View(android.view.View) ListView(android.widget.ListView) WindowManager(android.view.WindowManager) Response(retrofit.Response) Retrofit(retrofit.Retrofit) Callback(retrofit.Callback) Button(android.widget.Button) Dialog(android.app.Dialog) InvitationPayload(com.eveningoutpost.dexdrip.ShareModels.Models.InvitationPayload)

Aggregations

Retrofit (retrofit.Retrofit)6 View (android.view.View)4 Button (android.widget.Button)4 Callback (retrofit.Callback)4 Dialog (android.app.Dialog)2 LayoutInflater (android.view.LayoutInflater)2 WindowManager (android.view.WindowManager)2 EditText (android.widget.EditText)2 ListView (android.widget.ListView)2 TextView (android.widget.TextView)2 ExistingFollower (com.eveningoutpost.dexdrip.ShareModels.Models.ExistingFollower)2 InvitationPayload (com.eveningoutpost.dexdrip.ShareModels.Models.InvitationPayload)2 ResponseBody (com.squareup.okhttp.ResponseBody)2 Response (retrofit.Response)2 Cache (com.squareup.okhttp.Cache)1 OkHttpClient (com.squareup.okhttp.OkHttpClient)1 File (java.io.File)1