Skip to content

Commit

Permalink
Merge pull request #71 from Arctosoft/develop
Browse files Browse the repository at this point in the history
Filenames, sharing, encoding
  • Loading branch information
hej2010 authored Apr 23, 2024
2 parents fb9e231 + f6f2296 commit bb47a6a
Show file tree
Hide file tree
Showing 10 changed files with 49 additions and 28 deletions.
8 changes: 4 additions & 4 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ android {
applicationId "se.arctosoft.vault"
minSdk 28
targetSdk 34
versionCode 25
versionName "1.8.1"
versionCode 26
versionName "1.8.2"

testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}
Expand Down Expand Up @@ -53,8 +53,8 @@ dependencies {
implementation 'com.google.android.material:material:1.11.0'
implementation 'androidx.constraintlayout:constraintlayout:2.1.4'
implementation 'androidx.security:security-crypto:1.0.0'
implementation 'androidx.media3:media3-exoplayer:1.3.0'
implementation 'androidx.media3:media3-ui:1.3.0'
implementation 'androidx.media3:media3-exoplayer:1.3.1'
implementation 'androidx.media3:media3-ui:1.3.1'

implementation 'com.github.bumptech.glide:glide:4.15.1'
annotationProcessor 'com.github.bumptech.glide:compiler:4.15.1'
Expand Down
2 changes: 1 addition & 1 deletion app/src/main/java/se/arctosoft/vault/GalleryActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ private void handleShareIntent(Intent intent, String action, String type) {
}

private void handleSendSingle(Intent intent) {
Uri uri = (Uri) intent.getParcelableExtra(Intent.EXTRA_STREAM);
Uri uri = intent.getParcelableExtra(Intent.EXTRA_STREAM);
if (uri != null) {
List<Uri> list = new ArrayList<>(1);
list.add(uri);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -236,10 +236,11 @@ private void deleteSelectedFiles() {
}
Collections.sort(positionsDeleted);
runOnUiThread(() -> {
for (int i = positionsDeleted.size() - 1; i >= 0; i--) {
viewModel.getGalleryFiles().remove(i);
galleryGridAdapter.notifyItemRemoved(i);
galleryPagerAdapter.notifyItemRemoved(i);
while (!positionsDeleted.isEmpty()) {
int pos = positionsDeleted.remove(positionsDeleted.size() - 1);
viewModel.getGalleryFiles().remove(pos);
galleryGridAdapter.notifyItemRemoved(pos);
galleryPagerAdapter.notifyItemRemoved(pos);
}
galleryGridAdapter.onSelectionModeChanged(false);
setLoading(false);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -302,7 +302,7 @@ public void onCenterChanged(PointF newCenter, int origin) {
((GalleryPagerViewHolder.GalleryPagerGifViewHolder) holder).binding.gifImageView.setOnClickListener(v -> onItemPressed(context));
}
if (galleryFile.getDecryptedCacheUri() == null) {
new Thread(() -> Encryption.decryptToCache(context, galleryFile.getUri(), FileStuff.getExtension(galleryFile.getName()), Settings.getInstance(context).getTempPassword(), new Encryption.IOnUriResult() {
new Thread(() -> Encryption.decryptToCache(context, galleryFile.getUri(), FileStuff.getExtensionOrDefault(galleryFile), Settings.getInstance(context).getTempPassword(), new Encryption.IOnUriResult() {
@Override
public void onUriResult(Uri outputUri) {
galleryFile.setDecryptedCacheUri(outputUri);
Expand Down Expand Up @@ -439,7 +439,7 @@ private void loadShareOrOpen(FragmentActivity context, GalleryFile galleryFile,
shareOrOpenWith(context, galleryFile.getDecryptedCacheUri(), open);
} else {
Toaster.getInstance(context).showShort(context.getString(R.string.gallery_share_decrypting));
Encryption.decryptToCache(context, galleryFile.getUri(), FileStuff.getExtension(galleryFile.getName()), Settings.getInstance(context).getTempPassword(), new Encryption.IOnUriResult() {
Encryption.decryptToCache(context, galleryFile.getUri(), FileStuff.getExtensionOrDefault(galleryFile), Settings.getInstance(context).getTempPassword(), new Encryption.IOnUriResult() {
@Override
public void onUriResult(Uri outputUri) {
galleryFile.setDecryptedCacheUri(outputUri);
Expand Down Expand Up @@ -551,7 +551,7 @@ private void loadNote(GalleryPagerViewHolder holder, FragmentActivity context, G
} else {
holder.parentBinding.noteLayout.setVisibility(View.VISIBLE);
holder.parentBinding.note.setText(context.getString(R.string.gallery_loading_note));
Encryption.decryptToCache(context, galleryFile.getNoteUri(), FileStuff.getExtension(galleryFile.getName()), settings.getTempPassword(), new Encryption.IOnUriResult() {
Encryption.decryptToCache(context, galleryFile.getNoteUri(), FileStuff.getExtensionOrDefault(galleryFile), settings.getTempPassword(), new Encryption.IOnUriResult() {
@Override
public void onUriResult(Uri outputUri) { // decrypted, now read it
try {
Expand Down
13 changes: 7 additions & 6 deletions app/src/main/java/se/arctosoft/vault/data/FileType.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,17 +26,18 @@
import se.arctosoft.vault.encryption.Encryption;

public enum FileType {
DIRECTORY(0, null),
IMAGE(1, Encryption.PREFIX_IMAGE_FILE),
GIF(2, Encryption.PREFIX_GIF_FILE),
VIDEO(3, Encryption.PREFIX_VIDEO_FILE);
DIRECTORY(0, null, null),
IMAGE(1, Encryption.PREFIX_IMAGE_FILE, ".jpg"),
GIF(2, Encryption.PREFIX_GIF_FILE, ".gif"),
VIDEO(3, Encryption.PREFIX_VIDEO_FILE, ".mp4");

public final int i;
public final String encryptionPrefix;
public final String encryptionPrefix, extension;

FileType(int i, String encryptionPrefix) {
FileType(int i, String encryptionPrefix, String extension) {
this.i = i;
this.encryptionPrefix = encryptionPrefix;
this.extension = extension;
}

public static FileType fromFilename(@NonNull String name) {
Expand Down
16 changes: 11 additions & 5 deletions app/src/main/java/se/arctosoft/vault/encryption/Encryption.java
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
import java.security.GeneralSecurityException;
import java.security.SecureRandom;
import java.security.spec.KeySpec;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.concurrent.ExecutionException;

Expand Down Expand Up @@ -268,23 +269,28 @@ public static Streams getCipherInputStream(@NonNull InputStream inputStream, cha
throw new InvalidPasswordException("Invalid password");
}
}
StringBuilder sb = new StringBuilder();
ArrayList<Byte> bytes = new ArrayList<>();

if (cipherInputStream.read() == 0x0A) {
int count = 0;
byte[] read = new byte[1];
while ((cipherInputStream.read(read)) > 0) {
if (read[0] == 0x0A) {
break;
}
sb.append(new String(read));
bytes.add(read[0]);
if (++count > 300) {
throw new IOException("Not valid file");
}
}
} else {
throw new IOException("Not valid file");
}
return new Streams(cipherInputStream, secretKey, sb.toString());
byte[] arr = new byte[bytes.size()];
for (int i = 0; i < bytes.size(); i++) {
arr[i] = bytes.get(i);
}
return new Streams(cipherInputStream, secretKey, new String(arr, StandardCharsets.UTF_8));
}

private static Streams getCipherOutputStream(FragmentActivity context, Uri input, DocumentFile outputFile, char[] password, boolean isThumb, String sourceFileName) throws GeneralSecurityException, IOException {
Expand All @@ -310,7 +316,7 @@ private static Streams getCipherOutputStream(FragmentActivity context, Uri input
if (isThumb) {
cipherOutputStream.write(checkBytes);
}
cipherOutputStream.write(("\n" + sourceFileName + "\n").getBytes());
cipherOutputStream.write(("\n" + sourceFileName + "\n").getBytes(StandardCharsets.UTF_8));
return new Streams(inputStream, cipherOutputStream, secretKey);
}

Expand All @@ -332,7 +338,7 @@ private static Streams getNoteCipherOutputStream(FragmentActivity context, Strin
writeSaltAndIV(false, salt, ivBytes, null, fos);
fos.flush();
CipherOutputStream cipherOutputStream = new CipherOutputStream(fos, cipher);
cipherOutputStream.write(("\n" + sourceFileName + "\n").getBytes());
cipherOutputStream.write(("\n" + sourceFileName + "\n").getBytes(StandardCharsets.UTF_8));
return new Streams(input, cipherOutputStream, secretKey);
}

Expand Down
13 changes: 10 additions & 3 deletions app/src/main/java/se/arctosoft/vault/utils/FileStuff.java
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ private static List<GalleryFile> getEncryptedFilesInFolder(@NonNull List<CursorF

for (CursorFile file : documentFiles) {
if (file.isDirectory()) {
galleryFiles.add(GalleryFile.asDirectory(file, null)); // TODO fix later
galleryFiles.add(GalleryFile.asDirectory(file, null));
continue;
}
file.setNameWithoutPrefix(FileStuff.getNameWithoutPrefix(file.getName()));
Expand Down Expand Up @@ -186,14 +186,12 @@ public static String readTextFromUri(@NonNull Uri uri, Context context) throws I
public static List<DocumentFile> getDocumentsFromDirectoryResult(Context context, @NonNull Intent data) {
ClipData clipData = data.getClipData();
List<Uri> uris = FileStuff.uriListFromClipData(clipData);
//Log.e(TAG, "getDocumentsFromDirectoryResult: got " + uris.size());
if (uris.isEmpty()) {
Uri dataUri = data.getData();
if (dataUri != null) {
uris.add(dataUri);
}
}
//Log.e(TAG, "getDocumentsFromDirectoryResult: got " + uris.size());
List<DocumentFile> documentFiles = new ArrayList<>();
for (Uri uri : uris) {
DocumentFile pickedFile = DocumentFile.fromSingleUri(context, uri);
Expand Down Expand Up @@ -258,4 +256,13 @@ public static String getExtension(String name) {
}
return null;
}

@Nullable
public static String getExtensionOrDefault(GalleryFile file) {
String extension = getExtension(file.getName());
if (extension != null) {
return extension;
}
return file.getFileType().extension;
}
}
4 changes: 2 additions & 2 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Top-level build file where you can add configuration options common to all sub-projects/modules.
plugins {
id 'com.android.application' version '8.3.1' apply false
id 'com.android.library' version '8.3.1' apply false
id 'com.android.application' version '8.3.2' apply false
id 'com.android.library' version '8.3.2' apply false
id 'com.mikepenz.aboutlibraries.plugin' version '10.8.3' apply false
}

Expand Down
3 changes: 3 additions & 0 deletions fastlane/metadata/android/en-US/changelogs/26.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
* Fixed a bug where deleting a file in the grid always removed the first file in the grid
* Fixed files having the wrong extension when sharing/opening with another app
* Filenames are now UTF-8 encoded. This fixes question marks in some filenames and exported files
3 changes: 3 additions & 0 deletions fastlane/metadata/android/sv-SE/changelogs/26.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
* Fixade en bugg där radering av en fil i rutnätet alltid tog bort den första filen i rutnätet
* Fix för att filer har fel filtillägg när de delas/öppnas med en annan app
* Filnamnen är nu UTF-8 kodade. Det här åtgärdar frågetecken i vissa filnamn och exporterade filer

0 comments on commit bb47a6a

Please sign in to comment.