Search in sources :

Example 6 with RetrofitAPI

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

the class DashboardFragment method changeDevicestate.

public void changeDevicestate(Long id, Float value) {
    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.changeDevicestate(id, value, 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));
                    }
                } else {
                    if (getActivity() != null) {
                        SnackbarUtils.simpleSnackBar(getContext(), getView(), getContext().getString(R.string.error_code_5));
                    }
                }
            }

            @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 7 with RetrofitAPI

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

the class MapsFragment method createLocation.

public void createLocation() {
    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.createLocation((float) loc.latitude, (float) loc.longitude, pref_token);
        call.enqueue(new Callback<Void>() {

            @Override
            public void onResponse(Call<Void> call, Response<Void> response) {
                if (response.code() == 201) {
                    if (getActivity() != null) {
                        SnackbarUtils.simpleSnackBar(getContext(), getView(), getContext().getString(R.string.command_send));
                    }
                } 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 8 with RetrofitAPI

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

the class TimelineFragment method createEvent.

public void createEvent(final String name) {
    SharedPreferences pref1 = PreferenceManager.getDefaultSharedPreferences(getContext());
    pref_house = pref1.getString("idhouse", "1");
    pref_user = pref1.getString("iduser", "1");
    getConnection();
    if (connection) {
        getCode(name);
        Retrofit retrofit = new Retrofit.Builder().baseUrl(url).addConverterFactory(GsonConverterFactory.create()).client(SelfSigningClientBuilder.getUnsafeOkHttpClient()).build();
        RetrofitAPI service = retrofit.create(RetrofitAPI.class);
        Call<Event> call = service.createEvents(code, pref_house, pref_user, pref_token);
        call.enqueue(new Callback<Event>() {

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

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

Example 9 with RetrofitAPI

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

the class AlarmFragment method createAlarmSpe.

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

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

the class AlarmFragment method getAllAlarms.

public void getAllAlarms() {
    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<List<Alarm>> call = service.getAlarms(pref_token);
    call.enqueue(new Callback<List<Alarm>>() {

        @Override
        public void onResponse(Call<List<Alarm>> call, Response<List<Alarm>> response) {
            List<Alarm> AlarmData = response.body();
            if (AlarmData != null) {
                save_data = new SaveData(AlarmFragment.this);
                save_data.execute(AlarmData);
            } else {
                onRefreshAdapterView();
                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<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) List(java.util.List)

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