use of com.gladysinc.gladys.Utils.RetrofitAPI in project Gladys-Android-App by LeptitGeek.
the class RejectedSentencesFragment 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 RejectedSentencesFragment 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();
final RetrofitAPI service = retrofit.create(RetrofitAPI.class);
Call<Void> call = service.setStatus(id, "approved", 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("approved");
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 ConfigIntroFragment method connection.
public void connection() {
Retrofit retrofit = new Retrofit.Builder().baseUrl(url).addConverterFactory(GsonConverterFactory.create()).client(SelfSigningClientBuilder.getUnsafeOkHttpClient()).build();
RetrofitAPI service = retrofit.create(RetrofitAPI.class);
Call<User> call = service.whoAmI(token);
call.enqueue(new Callback<User>() {
@Override
public void onResponse(Call<User> call, Response<User> response) {
if (response.code() == 200) {
final String firstname = response.body().getFirstname();
final String lastname = response.body().getLastname();
final Long user_id = response.body().getUserId();
new MaterialDialog.Builder(getActivity()).contentColor(Color.GRAY).backgroundColorRes(R.color.white).positiveColorRes(R.color.colorAccent).negativeColorRes(R.color.colorAccent).content(getString(R.string.are_you) + " " + firstname + " " + lastname + " ?").positiveText(R.string.is_me).onPositive(new MaterialDialog.SingleButtonCallback() {
@Override
public void onClick(@NonNull MaterialDialog dialog, @NonNull DialogAction which) {
connection_passed = true;
snackBarMessage(getString(R.string.you_are_ready));
savePrefs("name", lastname);
savePrefs("first_name", firstname);
savePrefs("user_id", user_id.toString());
}
}).negativeText(R.string.is_not_me).onNegative(new MaterialDialog.SingleButtonCallback() {
@Override
public void onClick(@NonNull MaterialDialog dialog, @NonNull DialogAction which) {
new MaterialDialog.Builder(getActivity()).titleColor(Color.BLACK).contentColor(Color.GRAY).backgroundColorRes(R.color.white).positiveColorRes(R.color.colorAccent).title(R.string.it_is_not_you).content(R.string.it_is_not_you_message).positiveText(R.string.positve_button).show();
}
}).show();
}
}
@Override
public void onFailure(Call<User> call, Throwable t) {
snackBarMessage(getString(R.string.error));
}
});
}
use of com.gladysinc.gladys.Utils.RetrofitAPI in project Gladys-Android-App by LeptitGeek.
the class DashboardFragment method getAllDevicetypeByRoom.
public void getAllDevicetypeByRoom() {
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.getDevicetypeByRoom(pref_token);
call.enqueue(new Callback<List<DevicetypeByRoom>>() {
@Override
public void onResponse(Call<List<DevicetypeByRoom>> call, Response<List<DevicetypeByRoom>> response) {
List<DevicetypeByRoom> devicetypeData = response.body();
if (devicetypeData != null) {
save_data = new SaveData(DashboardFragment.this);
save_data.execute(devicetypeData);
} 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<DevicetypeByRoom>> 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 RoomsFragment method getAllRooms.
public void getAllRooms() {
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.getDevicetypeByRoom(pref_token);
call.enqueue(new Callback<List<DevicetypeByRoom>>() {
@Override
public void onResponse(Call<List<DevicetypeByRoom>> call, Response<List<DevicetypeByRoom>> response) {
List<DevicetypeByRoom> devicetypeData = response.body();
if (devicetypeData != null) {
save_data = new SaveData(RoomsFragment.this);
save_data.execute(devicetypeData);
} 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<DevicetypeByRoom>> 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);
}
});
}
Aggregations