Search in sources :

Example 1 with RetrofitAPI

use of com.gladysinc.gladys.Utils.RetrofitAPI in project Gladys-Android-App by LeptitGeek.

the class AlarmFragment method createAlarmRec.

public void createAlarmRec() {
    Retrofit retrofit = new Retrofit.Builder().baseUrl(url).addConverterFactory(GsonConverterFactory.create()).client(SelfSigningClientBuilder.getUnsafeOkHttpClient()).build();
    RetrofitAPI service = retrofit.create(RetrofitAPI.class);
    Call<Alarm> call = service.createAlarmRec(rec_name, time, id_of_day, true, pref_token);
    call.enqueue(new Callback<Alarm>() {

        @Override
        public void onResponse(Call<Alarm> call, Response<Alarm> response) {
            if (response.code() == 201) {
                getAllAlarms();
                if (getActivity() != null) {
                    SnackbarUtils.simpleSnackBar(getContext(), getView(), getContext().getString(R.string.alarm_created));
                }
            } else {
                if (getActivity() != null) {
                    SnackbarUtils.simpleSnackBar(getContext(), getView(), getContext().getString(R.string.error_code_4));
                }
            }
        }

        @Override
        public void onFailure(Call<Alarm> call, Throwable t) {
            if (!Objects.equals(t.getMessage(), "java.net.SocketTimeoutException")) {
                if (getActivity() != null) {
                    SnackbarUtils.simpleSnackBar(getContext(), getView(), getContext().getString(R.string.error_code_5));
                }
            }
        }
    });
}
Also used : Retrofit(retrofit2.Retrofit) RetrofitAPI(com.gladysinc.gladys.Utils.RetrofitAPI) SelfSigningClientBuilder(com.gladysinc.gladys.Utils.SelfSigningClientBuilder) Alarm(com.gladysinc.gladys.Models.Alarm)

Example 2 with RetrofitAPI

use of com.gladysinc.gladys.Utils.RetrofitAPI in project Gladys-Android-App by LeptitGeek.

the class AlarmFragment method deleteAlarm.

public void deleteAlarm(Long alarm_id) {
    getConnection();
    if (connection) {
        Retrofit retrofit = new Retrofit.Builder().baseUrl(url).addConverterFactory(GsonConverterFactory.create()).client(SelfSigningClientBuilder.getUnsafeOkHttpClient()).build();
        RetrofitAPI service = retrofit.create(RetrofitAPI.class);
        Call<Void> call = service.deleteAlarm(alarm_id, pref_token);
        call.enqueue(new Callback<Void>() {

            @Override
            public void onResponse(Call<Void> call, Response<Void> response) {
                if (response.code() == 200) {
                    getAllAlarms();
                    if (getActivity() != null) {
                        SnackbarUtils.simpleSnackBar(getContext(), getView(), getContext().getString(R.string.alarm_removed));
                    }
                } else {
                    if (getActivity() != null) {
                        SnackbarUtils.simpleSnackBar(getContext(), getView(), getContext().getString(R.string.error_code_4));
                    }
                }
            }

            @Override
            public void onFailure(Call<Void> call, Throwable t) {
                if (!Objects.equals(t.getMessage(), "java.net.SocketTimeoutException")) {
                    if (getActivity() != null) {
                        SnackbarUtils.simpleSnackBar(getContext(), getView(), getContext().getString(R.string.error_code_5));
                    }
                }
            }
        });
    }
}
Also used : Retrofit(retrofit2.Retrofit) RetrofitAPI(com.gladysinc.gladys.Utils.RetrofitAPI) SelfSigningClientBuilder(com.gladysinc.gladys.Utils.SelfSigningClientBuilder)

Example 3 with RetrofitAPI

use of com.gladysinc.gladys.Utils.RetrofitAPI in project Gladys-Android-App by LeptitGeek.

the class ApprovedSentencesFragment method setStatus.

public void setStatus(final Long id) {
    getConnection();
    if (connection) {
        Retrofit retrofit = new Retrofit.Builder().baseUrl(url).addConverterFactory(GsonConverterFactory.create()).client(SelfSigningClientBuilder.getUnsafeOkHttpClient()).build();
        RetrofitAPI service = retrofit.create(RetrofitAPI.class);
        Call<Void> call = service.setStatus(id, "rejected", pref_token);
        call.enqueue(new Callback<Void>() {

            @Override
            public void onResponse(Call<Void> call, Response<Void> response) {
                if (response.code() == 200) {
                    if (getActivity() != null) {
                        SnackbarUtils.simpleSnackBar(getContext(), getView(), getContext().getString(R.string.command_send));
                    }
                    BrainSentences brainSentences = (SugarRecord.find(BrainSentences.class, "sentencesid = ?", id.toString())).get(0);
                    brainSentences.setStatue("rejected");
                    SugarRecord.save(brainSentences);
                    onCreateAdapterView();
                } else {
                    if (getActivity() != null) {
                        SnackbarUtils.simpleSnackBar(getContext(), getView(), getContext().getString(R.string.error_code_4));
                    }
                }
            }

            @Override
            public void onFailure(Call<Void> call, Throwable t) {
                if (getActivity() != null) {
                    SnackbarUtils.simpleSnackBar(getContext(), getView(), getContext().getString(R.string.error_code_5));
                }
            }
        });
    }
}
Also used : Retrofit(retrofit2.Retrofit) BrainSentences(com.gladysinc.gladys.Models.BrainSentences) RetrofitAPI(com.gladysinc.gladys.Utils.RetrofitAPI) SelfSigningClientBuilder(com.gladysinc.gladys.Utils.SelfSigningClientBuilder)

Example 4 with RetrofitAPI

use of com.gladysinc.gladys.Utils.RetrofitAPI in project Gladys-Android-App by LeptitGeek.

the class PendingSentencesFragment method setStatus.

public void setStatus(final Long id, final String status) {
    getConnection();
    if (connection) {
        Retrofit retrofit = new Retrofit.Builder().baseUrl(url).addConverterFactory(GsonConverterFactory.create()).client(SelfSigningClientBuilder.getUnsafeOkHttpClient()).build();
        RetrofitAPI service = retrofit.create(RetrofitAPI.class);
        Call<Void> call = service.setStatus(id, status, pref_token);
        call.enqueue(new Callback<Void>() {

            @Override
            public void onResponse(Call<Void> call, Response<Void> response) {
                if (response.code() == 200) {
                    if (getActivity() != null) {
                        SnackbarUtils.simpleSnackBar(getContext(), getView(), getContext().getString(R.string.command_send));
                    }
                    BrainSentences brainSentences = (SugarRecord.find(BrainSentences.class, "sentencesid = ?", id.toString())).get(0);
                    brainSentences.setStatue(status);
                    SugarRecord.save(brainSentences);
                    onCreateAdapterView();
                } else {
                    if (getActivity() != null) {
                        SnackbarUtils.simpleSnackBar(getContext(), getView(), getContext().getString(R.string.error_code_4));
                    }
                }
            }

            @Override
            public void onFailure(Call<Void> call, Throwable t) {
                if (getActivity() != null) {
                    SnackbarUtils.simpleSnackBar(getContext(), getView(), getContext().getString(R.string.error_code_5));
                }
            }
        });
    }
}
Also used : Retrofit(retrofit2.Retrofit) BrainSentences(com.gladysinc.gladys.Models.BrainSentences) RetrofitAPI(com.gladysinc.gladys.Utils.RetrofitAPI) SelfSigningClientBuilder(com.gladysinc.gladys.Utils.SelfSigningClientBuilder)

Example 5 with RetrofitAPI

use of com.gladysinc.gladys.Utils.RetrofitAPI in project Gladys-Android-App by LeptitGeek.

the class PendingSentencesFragment method setLabel.

public void setLabel(final Long id, final String label) {
    getConnection();
    if (connection) {
        Retrofit retrofit = new Retrofit.Builder().baseUrl(url).addConverterFactory(GsonConverterFactory.create()).client(SelfSigningClientBuilder.getUnsafeOkHttpClient()).build();
        RetrofitAPI service = retrofit.create(RetrofitAPI.class);
        Call<BrainSentences> call = service.setLabel(id, label, pref_token);
        call.enqueue(new Callback<BrainSentences>() {

            @Override
            public void onResponse(Call<BrainSentences> all, Response<BrainSentences> response) {
                if (response.code() == 200) {
                    if (getActivity() != null) {
                        SnackbarUtils.simpleSnackBar(getContext(), getView(), getContext().getString(R.string.command_send));
                    }
                    BrainSentences brainSentences = (SugarRecord.find(BrainSentences.class, "sentencesid = ?", id.toString())).get(0);
                    brainSentences.setLabel(response.body().getLabel());
                    brainSentences.setService(response.body().getService());
                    SugarRecord.save(brainSentences);
                    onCreateAdapterView();
                } else {
                    if (getActivity() != null) {
                        SnackbarUtils.simpleSnackBar(getContext(), getView(), getContext().getString(R.string.error_code_4));
                    }
                }
            }

            @Override
            public void onFailure(Call<BrainSentences> all, Throwable t) {
                if (getActivity() != null) {
                    SnackbarUtils.simpleSnackBar(getContext(), getView(), getContext().getString(R.string.error_code_5));
                }
            }
        });
    }
}
Also used : Retrofit(retrofit2.Retrofit) BrainSentences(com.gladysinc.gladys.Models.BrainSentences) RetrofitAPI(com.gladysinc.gladys.Utils.RetrofitAPI) SelfSigningClientBuilder(com.gladysinc.gladys.Utils.SelfSigningClientBuilder)

Aggregations

RetrofitAPI (com.gladysinc.gladys.Utils.RetrofitAPI)21 SelfSigningClientBuilder (com.gladysinc.gladys.Utils.SelfSigningClientBuilder)21 Retrofit (retrofit2.Retrofit)21 BrainSentences (com.gladysinc.gladys.Models.BrainSentences)8 List (java.util.List)5 Alarm (com.gladysinc.gladys.Models.Alarm)3 SharedPreferences (android.content.SharedPreferences)1 DialogAction (com.afollestad.materialdialogs.DialogAction)1 MaterialDialog (com.afollestad.materialdialogs.MaterialDialog)1 Event (com.gladysinc.gladys.Models.Event)1 User (com.gladysinc.gladys.Models.User)1