use of de.bahnhoefe.deutschlands.bahnhofsfotos.model.InboxStateQuery in project RSAndroidApp by RailwayStations.
the class DetailsActivity method fetchUploadStatus.
private void fetchUploadStatus(final Upload upload) {
if (upload == null) {
return;
}
setButtonEnabled(binding.details.buttonUpload, true);
final List<InboxStateQuery> stateQueries = new ArrayList<>();
stateQueries.add(new InboxStateQuery(upload.getRemoteId(), upload.getCountry(), upload.getStationId()));
rsapiClient.queryUploadState(stateQueries).enqueue(new Callback<>() {
@Override
public void onResponse(@NonNull final Call<List<InboxStateQuery>> call, @NonNull final Response<List<InboxStateQuery>> response) {
final List<InboxStateQuery> stateQueries = response.body();
if (stateQueries != null && !stateQueries.isEmpty()) {
final InboxStateQuery stateQuery = stateQueries.get(0);
binding.details.licenseTag.setText(getString(R.string.upload_state, getString(stateQuery.getState().getTextId())));
binding.details.licenseTag.setTextColor(getResources().getColor(stateQuery.getState().getColorId(), null));
binding.details.licenseTag.setVisibility(View.VISIBLE);
upload.setUploadState(stateQuery.getState());
upload.setRejectReason(stateQuery.getRejectedReason());
upload.setCrc32(stateQuery.getCrc32());
upload.setRemoteId(stateQuery.getId());
baseApplication.getDbAdapter().updateUpload(upload);
} else {
Log.w(TAG, "Upload states not processable");
}
}
@Override
public void onFailure(@NonNull final Call<List<InboxStateQuery>> call, @NonNull final Throwable t) {
Log.e(TAG, "Error retrieving upload state", t);
Toast.makeText(DetailsActivity.this, R.string.error_retrieving_upload_state, Toast.LENGTH_LONG).show();
}
});
}
use of de.bahnhoefe.deutschlands.bahnhofsfotos.model.InboxStateQuery in project RSAndroidApp by RailwayStations.
the class OutboxActivity method onCreate.
@Override
public void onCreate(final Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
final BaseApplication baseApplication = (BaseApplication) getApplication();
dbAdapter = baseApplication.getDbAdapter();
final ActivityOutboxBinding binding = ActivityOutboxBinding.inflate(getLayoutInflater());
setContentView(binding.getRoot());
adapter = new OutboxAdapter(OutboxActivity.this, dbAdapter.getOutbox());
binding.lstUploads.setAdapter(adapter);
// item click
binding.lstUploads.setOnItemClickListener((parent, view, position, id) -> {
final Upload upload = dbAdapter.getUploadById(id);
final Intent detailIntent = new Intent(OutboxActivity.this, DetailsActivity.class);
detailIntent.putExtra(DetailsActivity.EXTRA_UPLOAD, upload);
startActivity(detailIntent);
});
binding.lstUploads.setOnItemLongClickListener((parent, view, position, id) -> {
final String uploadId = String.valueOf(id);
new SimpleDialogs().confirm(OutboxActivity.this, getResources().getString(R.string.delete_upload, uploadId), (dialog, which) -> {
dbAdapter.deleteUpload(id);
FileUtils.deleteQuietly(FileUtils.getStoredMediaFile(this, id));
adapter.changeCursor(dbAdapter.getOutbox());
});
return true;
});
final List<InboxStateQuery> query = new ArrayList<>();
for (final Upload upload : dbAdapter.getPendingUploads(true)) {
query.add(new InboxStateQuery(upload.getRemoteId()));
}
baseApplication.getRsapiClient().queryUploadState(query).enqueue(new Callback<>() {
@Override
public void onResponse(@NonNull final Call<List<InboxStateQuery>> call, @NonNull final Response<List<InboxStateQuery>> response) {
final List<InboxStateQuery> stateQueries = response.body();
if (stateQueries != null) {
dbAdapter.updateUploadStates(stateQueries);
adapter.changeCursor(dbAdapter.getOutbox());
} else {
Log.w(TAG, "Upload states not processable");
}
}
@Override
public void onFailure(@NonNull final Call<List<InboxStateQuery>> call, @NonNull final Throwable t) {
Log.e(TAG, "Error retrieving upload state", t);
Toast.makeText(OutboxActivity.this, R.string.error_retrieving_upload_state, Toast.LENGTH_LONG).show();
}
});
}
Aggregations