Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,4 @@
.cxx
local.properties
/app/release/
/.idea/deploymentTargetDropDown.xml
5 changes: 4 additions & 1 deletion app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ android {
debug {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
applicationIdSuffix ".dev"
}
applicationVariants.all { variant ->
variant.outputs.all {
Expand All @@ -49,10 +50,12 @@ dependencies {
implementation 'androidx.appcompat:appcompat:1.5.0'
implementation 'com.google.android.material:material:1.6.1'
implementation 'androidx.constraintlayout:constraintlayout:2.1.4'

implementation 'androidx.security:security-crypto:1.0.0'

implementation 'com.github.bumptech.glide:glide:4.13.2'
annotationProcessor 'com.github.bumptech.glide:compiler:4.13.2'
implementation 'com.davemorrissey.labs:subsampling-scale-image-view-androidx:3.10.0'
implementation 'com.google.android.exoplayer:exoplayer-core:2.18.1'
implementation 'com.google.android.exoplayer:exoplayer-ui:2.18.1'

}
96 changes: 58 additions & 38 deletions app/src/main/java/se/arctosoft/vault/GalleryActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ public class GalleryActivity extends AppCompatActivity {
private static final String TAG = "GalleryActivity";
private static final int REQUEST_ADD_DIRECTORY = 1;
private static final int REQUEST_IMPORT_IMAGES = 3;
private static final int REQUEST_IMPORT_VIDEOS = 4;

private static final Object lock = new Object();

Expand Down Expand Up @@ -95,7 +96,7 @@ private void onSelectionModeChanged(boolean inSelectionMode) {

private void setClickListeners() {
binding.btnAddFolder.setOnClickListener(v -> startActivityForResult(new Intent(Intent.ACTION_OPEN_DOCUMENT_TREE), REQUEST_ADD_DIRECTORY));
binding.btnImportFiles.setOnClickListener(v -> FileStuff.pickImageFiles(this, REQUEST_IMPORT_IMAGES));
binding.btnImportFiles.setOnClickListener(v -> showImportOverlay(true));
binding.btnRemoveFolder.setOnClickListener(v -> Dialogs.showConfirmationDialog(this, getString(R.string.dialog_remove_folder_title),
getResources().getQuantityString(R.plurals.dialog_remove_folder_message, galleryGridAdapter.getSelectedFiles().size()),
(dialog, which) -> {
Expand All @@ -114,6 +115,19 @@ private void setClickListeners() {
}
galleryGridAdapter.onSelectionModeChanged(false);
}));
binding.btnImportImages.setOnClickListener(v -> {
FileStuff.pickImageFiles(this, REQUEST_IMPORT_IMAGES);
showImportOverlay(false);
});
binding.btnImportVideos.setOnClickListener(v -> {
FileStuff.pickVideoFiles(this, REQUEST_IMPORT_VIDEOS);
showImportOverlay(false);
});
binding.importChooseOverlay.setOnClickListener(v -> showImportOverlay(false));
}

private void showImportOverlay(boolean show) {
binding.cLImportChoose.setVisibility(show ? View.VISIBLE : View.GONE);
}

private void setLoading(boolean loading) {
Expand Down Expand Up @@ -169,50 +183,54 @@ protected void onActivityResult(int requestCode, int resultCode, @Nullable Inten
addDirectory(documentFile.getUri());
}
}
} else if (requestCode == REQUEST_IMPORT_IMAGES && resultCode == Activity.RESULT_OK) {
} else if ((requestCode == REQUEST_IMPORT_IMAGES || requestCode == REQUEST_IMPORT_VIDEOS) && resultCode == Activity.RESULT_OK) {
if (data != null) {
List<DocumentFile> documentFiles = FileStuff.getDocumentsFromDirectoryResult(this, data);
if (!documentFiles.isEmpty()) {
Dialogs.showImportGalleryChooseDestinationDialog(this, settings, directory -> {
double totalSize = 0;
for (DocumentFile file : documentFiles) {
totalSize += (file.length() / 1000000.0);
}
final DecimalFormat decimalFormat = new DecimalFormat("0.00");
final String totalMB = decimalFormat.format(totalSize);
new Thread(() -> {
final int[] progress = new int[]{1};
final double[] bytesDone = new double[]{0};
runOnUiThread(() -> setLoadingProgress(progress[0], documentFiles.size(), "0", totalMB));
for (DocumentFile file : documentFiles) {
if (cancelTask) {
break;
}
boolean imported = false;
try {
imported = Encryption.importImageFileToDirectory(this, file, directory, settings);
} catch (SecurityException e) {
e.printStackTrace();
}
progress[0]++;
bytesDone[0] += file.length();
runOnUiThread(() -> setLoadingProgress(progress[0], documentFiles.size(), decimalFormat.format(bytesDone[0] / 1000000.0), totalMB));
if (!imported) {
runOnUiThread(() -> Toaster.getInstance(this).showLong("Failed to import " + file.getName()));
}
}
runOnUiThread(() -> {
Toaster.getInstance(this).showLong("Encrypted and imported " + (progress[0] - 1) + " files");
findFolders();
});

}).start();
});
importFiles(documentFiles, requestCode == REQUEST_IMPORT_VIDEOS);
}
}
}
}

private void importFiles(List<DocumentFile> documentFiles, boolean isVideo) {
Dialogs.showImportGalleryChooseDestinationDialog(this, settings, directory -> {
double totalSize = 0;
for (DocumentFile file : documentFiles) {
totalSize += (file.length() / 1000000.0);
}
final DecimalFormat decimalFormat = new DecimalFormat("0.00");
final String totalMB = decimalFormat.format(totalSize);
new Thread(() -> {
final int[] progress = new int[]{1};
final double[] bytesDone = new double[]{0};
runOnUiThread(() -> setLoadingProgress(progress[0], documentFiles.size(), "0", totalMB));
for (DocumentFile file : documentFiles) {
if (cancelTask) {
break;
}
boolean imported = false;
try {
imported = Encryption.importFileToDirectory(this, file, directory, settings, isVideo);
} catch (SecurityException e) {
e.printStackTrace();
}
progress[0]++;
bytesDone[0] += file.length();
runOnUiThread(() -> setLoadingProgress(progress[0], documentFiles.size(), decimalFormat.format(bytesDone[0] / 1000000.0), totalMB));
if (!imported) {
runOnUiThread(() -> Toaster.getInstance(this).showLong(getString(R.string.gallery_importing_error, file.getName())));
}
}
runOnUiThread(() -> {
Toaster.getInstance(this).showLong(getString(R.string.gallery_importing_done, progress[0] - 1));
findFolders();
});

}).start();
});
}

private void addDirectory(Uri directoryUri) {
List<GalleryFile> galleryFiles = FileStuff.getFilesInFolder(this, directoryUri);

Expand Down Expand Up @@ -264,6 +282,8 @@ private void lock() {
public void onBackPressed() {
if (binding.cLLoading.cLLoading.getVisibility() == View.VISIBLE) {
cancelTask = true;
} else if (binding.cLImportChoose.getVisibility() == View.VISIBLE) {
showImportOverlay(false);
} else if (inSelectionMode && galleryGridAdapter != null) {
galleryGridAdapter.onSelectionModeChanged(false);
} else {
Expand All @@ -279,7 +299,7 @@ public boolean onCreateOptionsMenu(Menu menu) {

@Override
protected void onDestroy() {
Log.e(TAG, "onDestroy: ");
Log.d(TAG, "onDestroy: ");
//lock();
super.onDestroy();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@
import androidx.appcompat.app.ActionBar;
import androidx.appcompat.app.AppCompatActivity;
import androidx.lifecycle.ViewModelProvider;
import androidx.recyclerview.widget.GridLayoutManager;
import androidx.recyclerview.widget.RecyclerView;
import androidx.recyclerview.widget.StaggeredGridLayoutManager;
import androidx.viewpager2.widget.ViewPager2;

import java.util.ArrayList;
Expand Down Expand Up @@ -104,7 +104,7 @@ private void init() {
setClickListeners();

if (!viewModel.isInitialised()) {
Log.e(TAG, "init: not initialised, find files");
//Log.e(TAG, "init: not initialised, find files");
findFilesIn(currentDirectory);
}
}
Expand All @@ -121,7 +121,6 @@ private void setClickListeners() {
FileStuff.deleteFile(this, f.getThumbUri());
if (deleted) {
int i = viewModel.getGalleryFiles().indexOf(f);
Log.e(TAG, "setClickListeners: deleted " + i);
if (i >= 0) {
viewModel.getGalleryFiles().remove(i);
runOnUiThread(() -> {
Expand All @@ -143,7 +142,7 @@ private void setClickListeners() {
private void setupRecycler() {
RecyclerView recyclerView = binding.recyclerView;
int spanCount = getResources().getConfiguration().orientation == Configuration.ORIENTATION_LANDSCAPE ? 6 : 3;
RecyclerView.LayoutManager layoutManager = new GridLayoutManager(this, spanCount, RecyclerView.VERTICAL, false);
RecyclerView.LayoutManager layoutManager = new StaggeredGridLayoutManager(spanCount, RecyclerView.VERTICAL);
recyclerView.setLayoutManager(layoutManager);
galleryGridAdapter = new GalleryGridAdapter(this, viewModel.getGalleryFiles(), true); // TODO setting to show/hide names
galleryGridAdapter.setOnFileDeleted(pos -> galleryPagerAdapter.notifyItemRemoved(pos));
Expand Down Expand Up @@ -172,6 +171,7 @@ public void onPageSelected(int position) {
super.onPageSelected(position);
binding.recyclerView.scrollToPosition(position);
viewModel.setCurrentPosition(position);
galleryPagerAdapter.releaseVideo();
}
});
binding.viewPager.postDelayed(() -> {
Expand All @@ -183,6 +183,7 @@ public void onPageSelected(int position) {
private void showViewpager(boolean show, int pos, boolean animate) {
//Log.e(TAG, "showViewpager: " + show + " " + pos);
viewModel.setViewpagerVisible(show);
galleryPagerAdapter.setIsPagerShown(show);
if (show) {
binding.viewPager.setVisibility(View.VISIBLE);
binding.viewPager.setCurrentItem(pos, false);
Expand Down Expand Up @@ -258,7 +259,7 @@ private void exportSelected() {
if (isFinishing() || isDestroyed() || !isExporting) {
break;
}
Encryption.decryptAndExport(this, f.getUri(), currentDirectory, settings.getTempPassword(), new Encryption.IOnUriResult() {
Encryption.IOnUriResult result = new Encryption.IOnUriResult() {
@Override
public void onUriResult(Uri outputUri) {
exported[0]++;
Expand All @@ -273,7 +274,8 @@ public void onError(Exception e) {
public void onInvalidPassword(InvalidPasswordException e) {
failed[0]++;
}
});
};
Encryption.decryptAndExport(this, f.getUri(), currentDirectory, settings.getTempPassword(), result, f.isVideo());
runOnUiThread(() -> setLoadingProgress(exported[0], failed[0], galleryFilesCopy.size()));
}
runOnUiThread(() -> {
Expand Down
2 changes: 1 addition & 1 deletion app/src/main/java/se/arctosoft/vault/LaunchActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ protected void onResume() {

@Override
public void onBackPressed() {
Log.e(TAG, "onBackPressed: ");
Log.d(TAG, "onBackPressed: ");
Password.lock(this, settings);
finishAffinity();
super.onBackPressed();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.cardview.widget.CardView;
import androidx.core.content.res.ResourcesCompat;
import androidx.fragment.app.FragmentActivity;
import androidx.recyclerview.widget.RecyclerView;

Expand Down Expand Up @@ -79,7 +80,12 @@ public void onBindViewHolder(@NonNull GalleryGridViewHolder holder, int position

updateSelectedView(holder, galleryFile);
holder.txtName.setVisibility(showFileNames ? View.VISIBLE : View.GONE);

if (galleryFile.isGif() || galleryFile.isVideo()) {
holder.imgType.setVisibility(View.VISIBLE);
holder.imgType.setImageDrawable(ResourcesCompat.getDrawable(context.getResources(), galleryFile.isGif() ? R.drawable.ic_round_gif_24 : R.drawable.ic_outline_video_file_24, context.getTheme()));
} else {
holder.imgType.setVisibility(View.GONE);
}
if (galleryFile.isDirectory()) {
GalleryFile firstFile = galleryFile.getFirstFile();
if (firstFile != null) {
Expand Down
Loading