use of de.bahnhoefe.deutschlands.bahnhofsfotos.model.Upload in project RSAndroidApp by RailwayStations.
the class DetailsActivity method verifyCurrentPhotoUploadExists.
private void verifyCurrentPhotoUploadExists() {
if (upload == null || upload.isProblemReport() || upload.isUploaded()) {
upload = new Upload();
if (station != null) {
upload.setCountry(station.getCountry());
upload.setStationId(station.getId());
}
upload.setLat(latitude);
upload.setLon(longitude);
upload = baseApplication.getDbAdapter().insertUpload(upload);
}
}
use of de.bahnhoefe.deutschlands.bahnhofsfotos.model.Upload in project RSAndroidApp by RailwayStations.
the class OutboxActivity method deleteCompletedUploads.
private void deleteCompletedUploads() {
final List<Upload> uploads = dbAdapter.getCompletedUploads();
if (uploads.isEmpty()) {
return;
}
new AlertDialog.Builder(new ContextThemeWrapper(this, R.style.AlertDialogCustom)).setIcon(R.mipmap.ic_launcher).setTitle(R.string.confirm_delete_processed_uploads).setPositiveButton(R.string.button_ok_text, (dialog, which) -> {
for (final Upload upload : uploads) {
dbAdapter.deleteUpload(upload.getId());
FileUtils.deleteQuietly(FileUtils.getStoredMediaFile(this, upload.getId()));
}
adapter.changeCursor(dbAdapter.getOutbox());
}).setNegativeButton(R.string.button_cancel_text, null).create().show();
}
use of de.bahnhoefe.deutschlands.bahnhofsfotos.model.Upload in project RSAndroidApp by RailwayStations.
the class DetailsActivity method reportProblem.
void reportProblem() {
if (isNotLoggedIn()) {
Toast.makeText(this, R.string.please_login, Toast.LENGTH_LONG).show();
return;
}
final var reportProblemBinding = ReportProblemBinding.inflate(getLayoutInflater());
if (upload != null && upload.isProblemReport()) {
reportProblemBinding.etProblemComment.setText(upload.getComment());
}
final List<String> problemTypes = new ArrayList<>();
problemTypes.add(getString(R.string.problem_please_specify));
int selected = -1;
for (final ProblemType type : ProblemType.values()) {
problemTypes.add(getString(type.getMessageId()));
if (upload != null && upload.getProblemType() == type) {
selected = problemTypes.size() - 1;
}
}
final ArrayAdapter<String> adapter = new ArrayAdapter<>(this, android.R.layout.simple_spinner_item, problemTypes);
adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
reportProblemBinding.problemType.setAdapter(adapter);
if (selected > -1) {
reportProblemBinding.problemType.setSelection(selected);
}
final var builder = new AlertDialog.Builder(new ContextThemeWrapper(this, R.style.AlertDialogCustom));
builder.setTitle(R.string.report_problem).setView(reportProblemBinding.getRoot()).setIcon(R.drawable.ic_bullhorn_48px).setPositiveButton(android.R.string.ok, null).setNegativeButton(android.R.string.cancel, (dialog, id1) -> dialog.cancel());
final AlertDialog alertDialog = builder.create();
alertDialog.show();
alertDialog.getButton(AlertDialog.BUTTON_POSITIVE).setOnClickListener(v -> {
final int selectedType = reportProblemBinding.problemType.getSelectedItemPosition();
if (selectedType == 0) {
Toast.makeText(getApplicationContext(), getString(R.string.problem_please_specify), Toast.LENGTH_LONG).show();
return;
}
final ProblemType type = ProblemType.values()[selectedType - 1];
final String comment = reportProblemBinding.etProblemComment.getText().toString();
if (StringUtils.isBlank(comment)) {
Toast.makeText(getApplicationContext(), getString(R.string.problem_please_comment), Toast.LENGTH_LONG).show();
return;
}
alertDialog.dismiss();
if (upload == null || !upload.isProblemReport() || upload.isUploaded()) {
upload = new Upload();
upload.setCountry(station.getCountry());
upload.setStationId(station.getId());
upload.setProblemType(type);
upload.setComment(comment);
upload = baseApplication.getDbAdapter().insertUpload(upload);
} else {
upload.setProblemType(type);
upload.setComment(comment);
baseApplication.getDbAdapter().updateUpload(upload);
}
rsapiClient.reportProblem(new ProblemReport(station.getCountry(), bahnhofId, comment, type)).enqueue(new Callback<>() {
@Override
public void onResponse(@NonNull final Call<InboxResponse> call, @NonNull final Response<InboxResponse> response) {
final InboxResponse inboxResponse;
if (response.isSuccessful()) {
inboxResponse = response.body();
} else if (response.code() == 401) {
new SimpleDialogs().confirm(DetailsActivity.this, R.string.authorization_failed);
return;
} else {
final Gson gson = new Gson();
inboxResponse = gson.fromJson(response.errorBody().charStream(), InboxResponse.class);
if (inboxResponse.getState() == null) {
inboxResponse.setState(InboxResponse.InboxResponseState.ERROR);
}
}
upload.setRemoteId(inboxResponse.getId());
upload.setUploadState(inboxResponse.getState().getUploadState());
baseApplication.getDbAdapter().updateUpload(upload);
if (inboxResponse.getState() == InboxResponse.InboxResponseState.ERROR) {
new SimpleDialogs().confirm(DetailsActivity.this, String.format(getText(R.string.problem_report_failed).toString(), response.message()));
// try to get the upload state again
fetchUploadStatus(upload);
} else {
new SimpleDialogs().confirm(DetailsActivity.this, inboxResponse.getState().getMessageId());
}
}
@Override
public void onFailure(@NonNull final Call<InboxResponse> call, @NonNull final Throwable t) {
Log.e(TAG, "Error reporting problem", t);
new SimpleDialogs().confirm(DetailsActivity.this, String.format(getText(R.string.problem_report_failed).toString(), t.getMessage()));
}
});
});
}
use of de.bahnhoefe.deutschlands.bahnhofsfotos.model.Upload 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