Skip to content

Commit

Permalink
Show only containers in recent documents (#209)
Browse files Browse the repository at this point in the history
* MOPPAND-823
  • Loading branch information
martenrebane authored Nov 30, 2021
1 parent 500a83f commit ed28338
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

import java.io.File;

import ee.ria.DigiDoc.android.utils.files.FileSystem;
import ee.ria.DigiDoc.android.utils.mvi.MviResult;

interface Result extends MviResult<ViewState> {
Expand Down Expand Up @@ -38,7 +39,7 @@ static ContainersLoadResult progress(boolean indicateActivity) {
}

static ContainersLoadResult success(ImmutableList<File> containerFiles) {
return create(true, false, containerFiles, null);
return create(true, false, FileSystem.filterContainers(containerFiles), null);
}

static ContainersLoadResult failure(Throwable error) {
Expand Down Expand Up @@ -113,7 +114,7 @@ static ContainerRemoveResult progress() {
}

static ContainerRemoveResult success(ImmutableList<File> containerFiles) {
return create(null, false, containerFiles, null);
return create(null, false, FileSystem.filterContainers(containerFiles), null);
}

static ContainerRemoveResult failure(Throwable error) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
import com.google.common.io.ByteStreams;
import com.google.common.io.Files;

import org.apache.commons.io.FileUtils;
import org.apache.commons.io.FilenameUtils;

import java.io.File;
Expand All @@ -20,10 +19,12 @@
import java.util.Comparator;
import java.util.List;
import java.util.Locale;
import java.util.stream.Collectors;

import javax.inject.Inject;

import ee.ria.DigiDoc.common.FileUtil;
import ee.ria.DigiDoc.crypto.CryptoContainer;
import ee.ria.DigiDoc.sign.SignedContainer;
import timber.log.Timber;

Expand Down Expand Up @@ -182,6 +183,19 @@ public static boolean isEmptyDataFileInContainer(File containerFile) {
return false;
}

/**
* Filter out container files
*
* @param files List of files.
* @return ImmutableList<File> of containers only.
*/
public static ImmutableList<File> filterContainers(ImmutableList<File> files) {
return ImmutableList.copyOf(files.stream()
.filter(file -> SignedContainer.isContainer(file) ||
CryptoContainer.isCryptoContainer(file))
.collect(Collectors.toList()));
}

private File cacheDir() {
return application.getCacheDir();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,10 @@
import java.io.File;
import java.io.FileInputStream;
import java.io.InputStream;
import java.nio.file.FileSystem;
import java.util.List;
import java.util.Locale;

import ee.ria.DigiDoc.common.Certificate;
import ee.ria.DigiDoc.common.FileUtil;
import okio.ByteString;

import static com.google.common.io.Files.getFileExtension;
Expand Down Expand Up @@ -188,4 +186,16 @@ private static CryptoContainer create(File file, ImmutableList<File> dataFiles,
boolean decrypted) {
return new AutoValue_CryptoContainer(file, dataFiles, recipients, decrypted);
}

/**
* Check whether this is a crypto container file which should be opened as such
* or a regular file which should be added to the container.
*
* @param file File to check.
* @return True if it is a crypto container, false otherwise.
*/
public static boolean isCryptoContainer(File file) {
String extension = getFileExtension(file.getName()).toLowerCase();
return "cdoc".equals(extension);
}
}

0 comments on commit ed28338

Please sign in to comment.