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));
}
}
}
});
}
}
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));
}
}
}
});
}
}
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));
}
}
});
}
}
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));
}
}
}
});
}
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));
}
}
}
});
}
Aggregations