Skip to content

Commit

Permalink
Fix: records delete (#35)
Browse files Browse the repository at this point in the history
* fixed: checkbox not visible in records list

* image capture: show message if there is an error

---------

Co-authored-by: Stefano Ricci <[email protected]>
  • Loading branch information
SteRiccio and SteRiccio authored Apr 10, 2024
1 parent f7bdc4a commit 7bfe896
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 50 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -115,55 +115,50 @@ private void rotateImage() {

private void setupCaptureButton() {
captureButton = inputView.findViewById(R.id.file_attribute_capture);
if (canCapture()) {
captureButton.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
Runnable captureImageRunnable = new Runnable() {
public void run() {
capture();
}
};
if (file != null && file.exists()) {
Dialogs.confirm(context, R.string.warning, R.string.file_attribute_captured_file_overwrite_confirm_message,
captureImageRunnable, null, R.string.overwrite_label, android.R.string.cancel);
} else {
captureImageRunnable.run();
captureButton.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
Runnable captureImageRunnable = new Runnable() {
public void run() {
capture();
}
};
if (file != null && file.exists()) {
Dialogs.confirm(context, R.string.warning, R.string.file_attribute_captured_file_overwrite_confirm_message,
captureImageRunnable, null, R.string.overwrite_label, android.R.string.cancel);
} else {
captureImageRunnable.run();
}
});
} else {
captureButton.setVisibility(View.GONE);
}
}

protected boolean canCapture() {
Intent takePictureIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
return takePictureIntent.resolveActivity(context.getPackageManager()) != null;
}
});
}

protected void capture() {
Intent takePictureIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
if (takePictureIntent.resolveActivity(context.getPackageManager()) != null &&
Permissions.checkCameraPermissionOrRequestIt(context)) {
((SurveyNodeActivity) context).setImageChangedListener(this);
Uri imageUri;
if (AndroidVersion.greaterThan20()) {
// Create temp file and store image there
File imageFile = createTempImageFile();
if (imageFile == null) {
Toast.makeText(context, R.string.file_attribute_capture_image_error_creating_temp_file, Toast.LENGTH_SHORT).show();
return;
try {
Intent takePictureIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
if (Permissions.checkCameraPermissionOrRequestIt(context)) {
((SurveyNodeActivity) context).setImageChangedListener(this);
Uri imageUri;
if (AndroidVersion.greaterThan20()) {
// Create temp file and store image there
File imageFile = createTempImageFile();
if (imageFile == null) {
Toast.makeText(context, R.string.file_attribute_capture_image_error_creating_temp_file, Toast.LENGTH_SHORT).show();
return;
}
imageUri = AndroidFiles.getUriForFile(context, imageFile);
} else {
// Store image directly to "file"
//TODO find nicer solution to prevent FileUriExposedException
StrictMode.VmPolicy.Builder builder = new StrictMode.VmPolicy.Builder();
StrictMode.setVmPolicy(builder.build());
imageUri = Uri.fromFile(file);
}
imageUri = AndroidFiles.getUriForFile(context, imageFile);
} else {
// Store image directly to "file"
//TODO find nicer solution to prevent FileUriExposedException
StrictMode.VmPolicy.Builder builder = new StrictMode.VmPolicy.Builder();
StrictMode.setVmPolicy(builder.build());
imageUri = Uri.fromFile(file);
takePictureIntent.putExtra(MediaStore.EXTRA_OUTPUT, imageUri);
context.startActivityForResult(takePictureIntent, SurveyNodeActivity.IMAGE_CAPTURE_REQUEST_CODE);
}
takePictureIntent.putExtra(MediaStore.EXTRA_OUTPUT, imageUri);
context.startActivityForResult(takePictureIntent, SurveyNodeActivity.IMAGE_CAPTURE_REQUEST_CODE);
} catch (Exception e) {
String errorMessage = context.getString(R.string.file_attribute_capture_image_error, e.getMessage());
Toast.makeText(context, errorMessage, Toast.LENGTH_LONG).show();
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,6 @@ public VideoFileAttributeComponent(UiFileAttribute attribute, SurveyService surv
super(attribute, surveyService, context);
}

@Override
protected boolean canCapture() {
Intent takePictureIntent = new Intent(MediaStore.ACTION_VIDEO_CAPTURE);
return takePictureIntent.resolveActivity(context.getPackageManager()) != null;
}

@Override
protected void capture() {
if (Permissions.checkCameraPermissionOrRequestIt(context)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,14 @@ public View getView(int position, View convertView, ViewGroup parent) {
return row;
}

@Override
public void setSelectionEnabled(boolean selectionEnabled) {
super.setSelectionEnabled(selectionEnabled);
if (!selectionEnabled && actionMode != null) {
actionMode.finish();
}
}

public List<UiAttribute> getSummaryAttributes(UiNode node) {
return UiNodes.getSummaryAttributes(node);
}
Expand Down Expand Up @@ -152,9 +160,9 @@ protected int layoutResourceId() {
}

protected void onPrepareView(final UiNode node, View row) {
final CheckBox checkbox = (CheckBox) row.findViewById(R.id.nodeSelectedForAction);
final CheckBox checkbox = row.findViewById(R.id.nodeSelectedForAction);
Definition parentDef = node.getParent().getDefinition();
if (!isSelectionEnabled() ||
if ((!(node instanceof UiRecord.Placeholder) && !isSelectionEnabled()) ||
(parentDef instanceof UiEntityCollectionDefinition &&
((UiEntityCollectionDefinition) parentDef).isEnumerated())
) {
Expand Down

0 comments on commit 7bfe896

Please sign in to comment.