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