Skip to content

Commit

Permalink
Remove the empty instance folder when exiting the identity dialog
Browse files Browse the repository at this point in the history
  • Loading branch information
grzesiek2010 committed Mar 16, 2024
1 parent e49eae1 commit bc27c79
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,7 @@
import org.odk.collect.android.utilities.ContentUriHelper;
import org.odk.collect.android.utilities.ControllableLifecyleOwner;
import org.odk.collect.android.utilities.ExternalAppIntentProvider;
import org.odk.collect.android.utilities.FileUtils;
import org.odk.collect.android.utilities.FormsRepositoryProvider;
import org.odk.collect.android.utilities.InstancesRepositoryProvider;
import org.odk.collect.android.utilities.MediaUtils;
Expand Down Expand Up @@ -545,6 +546,7 @@ private void setupViewModels(FormEntryViewModelFactory formEntryViewModelFactory

identityPromptViewModel.isFormEntryCancelled().observe(this, isFormEntryCancelled -> {
if (isFormEntryCancelled) {
identityPromptViewModel.exit();
exit();
}
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import androidx.lifecycle.ViewModel;

import org.odk.collect.android.javarosawrapper.FormController;
import org.odk.collect.android.utilities.FileUtils;

public class IdentityPromptViewModel extends ViewModel {

Expand All @@ -20,6 +21,7 @@ public class IdentityPromptViewModel extends ViewModel {

private String identity = "";
private String formName;
private String instanceFolder;

public IdentityPromptViewModel() {
updateRequiresIdentity();
Expand All @@ -28,6 +30,7 @@ public IdentityPromptViewModel() {
public void formLoaded(@NonNull FormController formController) {
this.formName = formController.getFormTitle();
this.auditEventLogger = formController.getAuditEventLogger();
this.instanceFolder = formController.getInstanceFile().getParent();
updateRequiresIdentity();
}

Expand Down Expand Up @@ -72,4 +75,8 @@ private static boolean userIsValid(String user) {
public String getFormTitle() {
return formName;
}

public void exit() {
FileUtils.purgeMediaPath(instanceFolder);
}
}

0 comments on commit bc27c79

Please sign in to comment.