use of de.bahnhoefe.deutschlands.bahnhofsfotos.dialogs.SimpleDialogs 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