Search in sources :

Example 1 with User

use of com.gladysinc.gladys.Models.User in project Gladys-Android-App by LeptitGeek.

the class ConfigIntroFragment method connection.

public void connection() {
    Retrofit retrofit = new Retrofit.Builder().baseUrl(url).addConverterFactory(GsonConverterFactory.create()).client(SelfSigningClientBuilder.getUnsafeOkHttpClient()).build();
    RetrofitAPI service = retrofit.create(RetrofitAPI.class);
    Call<User> call = service.whoAmI(token);
    call.enqueue(new Callback<User>() {

        @Override
        public void onResponse(Call<User> call, Response<User> response) {
            if (response.code() == 200) {
                final String firstname = response.body().getFirstname();
                final String lastname = response.body().getLastname();
                final Long user_id = response.body().getUserId();
                new MaterialDialog.Builder(getActivity()).contentColor(Color.GRAY).backgroundColorRes(R.color.white).positiveColorRes(R.color.colorAccent).negativeColorRes(R.color.colorAccent).content(getString(R.string.are_you) + " " + firstname + " " + lastname + " ?").positiveText(R.string.is_me).onPositive(new MaterialDialog.SingleButtonCallback() {

                    @Override
                    public void onClick(@NonNull MaterialDialog dialog, @NonNull DialogAction which) {
                        connection_passed = true;
                        snackBarMessage(getString(R.string.you_are_ready));
                        savePrefs("name", lastname);
                        savePrefs("first_name", firstname);
                        savePrefs("user_id", user_id.toString());
                    }
                }).negativeText(R.string.is_not_me).onNegative(new MaterialDialog.SingleButtonCallback() {

                    @Override
                    public void onClick(@NonNull MaterialDialog dialog, @NonNull DialogAction which) {
                        new MaterialDialog.Builder(getActivity()).titleColor(Color.BLACK).contentColor(Color.GRAY).backgroundColorRes(R.color.white).positiveColorRes(R.color.colorAccent).title(R.string.it_is_not_you).content(R.string.it_is_not_you_message).positiveText(R.string.positve_button).show();
                    }
                }).show();
            }
        }

        @Override
        public void onFailure(Call<User> call, Throwable t) {
            snackBarMessage(getString(R.string.error));
        }
    });
}
Also used : User(com.gladysinc.gladys.Models.User) MaterialDialog(com.afollestad.materialdialogs.MaterialDialog) RetrofitAPI(com.gladysinc.gladys.Utils.RetrofitAPI) SelfSigningClientBuilder(com.gladysinc.gladys.Utils.SelfSigningClientBuilder) Retrofit(retrofit2.Retrofit) DialogAction(com.afollestad.materialdialogs.DialogAction)

Aggregations

DialogAction (com.afollestad.materialdialogs.DialogAction)1 MaterialDialog (com.afollestad.materialdialogs.MaterialDialog)1 User (com.gladysinc.gladys.Models.User)1 RetrofitAPI (com.gladysinc.gladys.Utils.RetrofitAPI)1 SelfSigningClientBuilder (com.gladysinc.gladys.Utils.SelfSigningClientBuilder)1 Retrofit (retrofit2.Retrofit)1