Search in sources :

Example 11 with RetrofitAPI

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

the class AlarmFragment method createCronRule.

public void createCronRule(String name, String rule) {
    Retrofit retrofit = new Retrofit.Builder().baseUrl(url).addConverterFactory(GsonConverterFactory.create()).client(SelfSigningClientBuilder.getUnsafeOkHttpClient()).build();
    RetrofitAPI service = retrofit.create(RetrofitAPI.class);
    Call<Alarm> call = service.createCronRule(name, rule, 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 12 with RetrofitAPI

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

the class BrainFragment method getAllBrainSentences.

public void getAllBrainSentences() {
    get_data_progress.setVisible(true);
    Retrofit retrofit = new Retrofit.Builder().baseUrl(url).addConverterFactory(GsonConverterFactory.create()).client(SelfSigningClientBuilder.getUnsafeOkHttpClient()).build();
    RetrofitAPI service = retrofit.create(RetrofitAPI.class);
    call = service.getBrainSentences(take, pref_token);
    call.enqueue(new Callback<List<BrainSentences>>() {

        @Override
        public void onResponse(Call<List<BrainSentences>> call, Response<List<BrainSentences>> response) {
            List<BrainSentences> brainSentencesList = response.body();
            if (brainSentencesList != null) {
                save_data = new SaveData(BrainFragment.this);
                save_data.execute(brainSentencesList);
            } else {
                get_data_progress.setVisible(false);
                if (getActivity() != null) {
                    SnackbarUtils.simpleSnackBar(getContext(), getView(), getContext().getString(R.string.error_code_4));
                }
            }
        }

        @Override
        public void onFailure(Call<List<BrainSentences>> 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));
                }
            }
            get_data_progress.setVisible(false);
        }
    });
}
Also used : Retrofit(retrofit2.Retrofit) RetrofitAPI(com.gladysinc.gladys.Utils.RetrofitAPI) SelfSigningClientBuilder(com.gladysinc.gladys.Utils.SelfSigningClientBuilder) List(java.util.List)

Example 13 with RetrofitAPI

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

the class AllSentencesFragment 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 14 with RetrofitAPI

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

the class AllSentencesFragment 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> call, 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> 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 15 with RetrofitAPI

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

the class ApprovedSentencesFragment 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> call, 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> 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)

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