Skip to content

Commit

Permalink
Merge pull request #76 from Arctosoft/develop
Browse files Browse the repository at this point in the history
Version 1.9.0
  • Loading branch information
hej2010 authored May 3, 2024
2 parents 2766445 + 41fc92d commit 23182d2
Show file tree
Hide file tree
Showing 17 changed files with 456 additions and 73 deletions.
10 changes: 10 additions & 0 deletions .idea/deploymentTargetSelector.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 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 26
versionName "1.8.2"
versionCode 27
versionName "1.9.0"

testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}
Expand Down
30 changes: 30 additions & 0 deletions app/src/main/java/se/arctosoft/vault/BaseActivity.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
/*
* Valv-Android
* Copyright (C) 2023 Arctosoft AB
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see https://www.gnu.org/licenses/.
*/

package se.arctosoft.vault;

import android.content.Intent;

import androidx.activity.result.ActivityResult;
import androidx.appcompat.app.AppCompatActivity;

import se.arctosoft.vault.utils.BetterActivityResult;

public class BaseActivity extends AppCompatActivity {
protected final BetterActivityResult<Intent, ActivityResult> activityLauncher = BetterActivityResult.registerActivityForResult(this);
}
104 changes: 50 additions & 54 deletions app/src/main/java/se/arctosoft/vault/GalleryActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,10 @@
import android.view.View;
import android.view.WindowManager;

import androidx.activity.result.ActivityResult;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.appcompat.app.ActionBar;
import androidx.appcompat.app.AppCompatActivity;
import androidx.documentfile.provider.DocumentFile;
import androidx.lifecycle.ViewModelProvider;
import androidx.recyclerview.widget.GridLayoutManager;
Expand All @@ -57,11 +57,8 @@
import se.arctosoft.vault.utils.Toaster;
import se.arctosoft.vault.viewmodel.GalleryViewModel;

public class GalleryActivity extends AppCompatActivity {
public class GalleryActivity extends BaseActivity {
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 @@ -178,7 +175,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.btnAddFolder.setOnClickListener(v -> activityLauncher.launch(new Intent(Intent.ACTION_OPEN_DOCUMENT_TREE), this::addFolder));
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()),
Expand All @@ -199,16 +196,61 @@ private void setClickListeners() {
galleryGridAdapter.onSelectionModeChanged(false);
}));
binding.btnImportImages.setOnClickListener(v -> {
FileStuff.pickImageFiles(this, REQUEST_IMPORT_IMAGES);
FileStuff.pickImageFiles(activityLauncher, result -> onImportImagesOrVideos(result.getData()));
showImportOverlay(false);
});
binding.btnImportVideos.setOnClickListener(v -> {
FileStuff.pickVideoFiles(this, REQUEST_IMPORT_VIDEOS);
FileStuff.pickVideoFiles(activityLauncher, result -> onImportImagesOrVideos(result.getData()));
showImportOverlay(false);
});
binding.importChooseOverlay.setOnClickListener(v -> showImportOverlay(false));
}

private void onImportImagesOrVideos(@Nullable Intent data) {
if (data != null) {
List<DocumentFile> documentFiles = FileStuff.getDocumentsFromDirectoryResult(this, data);
if (!documentFiles.isEmpty()) {
importFiles(documentFiles);
}
}
}

private void addFolder(ActivityResult result) {
if (result.getResultCode() == Activity.RESULT_OK) {
Intent data = result.getData();
if (data != null) {
Uri uri = data.getData();
DocumentFile documentFile = DocumentFile.fromTreeUri(this, uri);
getContentResolver().takePersistableUriPermission(uri, Intent.FLAG_GRANT_READ_URI_PERMISSION | Intent.FLAG_GRANT_WRITE_URI_PERMISSION);
settings.addGalleryDirectory(documentFile.getUri(), new IOnDirectoryAdded() {
@Override
public void onAddedAsRoot() {
Toaster.getInstance(GalleryActivity.this).showLong(getString(R.string.gallery_added_folder, FileStuff.getFilenameWithPathFromUri(uri)));
addDirectory(documentFile.getUri());
}

@Override
public void onAddedAsChildOf(@NonNull Uri parentUri) {
Toaster.getInstance(GalleryActivity.this).showLong(getString(R.string.gallery_added_folder_child, FileStuff.getFilenameWithPathFromUri(uri), FileStuff.getFilenameWithPathFromUri(parentUri)));
}

@Override
public void onAlreadyExists(boolean isRootDir) {
Toaster.getInstance(GalleryActivity.this).showLong(getString(R.string.gallery_added_folder_duplicate, FileStuff.getFilenameWithPathFromUri(uri)));
if (isRootDir) {
findFolders();
}
}
});
if (viewModel.getFilesToAdd() != null) {
importFiles(viewModel.getFilesToAdd());
}
}
} else if (result.getResultCode() == Activity.RESULT_CANCELED) {
viewModel.setFilesToAdd(null);
}
}

private void showImportOverlay(boolean show) {
binding.cLImportChoose.setVisibility(show ? View.VISIBLE : View.GONE);
}
Expand Down Expand Up @@ -254,52 +296,6 @@ private void findFolders() {
}).start();
}

@Override
protected void onActivityResult(int requestCode, int resultCode, @Nullable Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if (requestCode == REQUEST_ADD_DIRECTORY) {
if (resultCode == Activity.RESULT_OK) {
if (data != null) {
Uri uri = data.getData();
DocumentFile documentFile = DocumentFile.fromTreeUri(this, uri);
getContentResolver().takePersistableUriPermission(uri, Intent.FLAG_GRANT_READ_URI_PERMISSION | Intent.FLAG_GRANT_WRITE_URI_PERMISSION);
settings.addGalleryDirectory(documentFile.getUri(), new IOnDirectoryAdded() {
@Override
public void onAddedAsRoot() {
Toaster.getInstance(GalleryActivity.this).showLong(getString(R.string.gallery_added_folder, FileStuff.getFilenameWithPathFromUri(uri)));
addDirectory(documentFile.getUri());
}

@Override
public void onAddedAsChildOf(@NonNull Uri parentUri) {
Toaster.getInstance(GalleryActivity.this).showLong(getString(R.string.gallery_added_folder_child, FileStuff.getFilenameWithPathFromUri(uri), FileStuff.getFilenameWithPathFromUri(parentUri)));
}

@Override
public void onAlreadyExists(boolean isRootDir) {
Toaster.getInstance(GalleryActivity.this).showLong(getString(R.string.gallery_added_folder_duplicate, FileStuff.getFilenameWithPathFromUri(uri)));
if (isRootDir) {
findFolders();
}
}
});
if (viewModel.getFilesToAdd() != null) {
importFiles(viewModel.getFilesToAdd());
}
}
} else if (resultCode == Activity.RESULT_CANCELED) {
viewModel.setFilesToAdd(null);
}
} 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()) {
importFiles(documentFiles);
}
}
}
}

private void importFiles(List<DocumentFile> documentFiles) {
Dialogs.showImportGalleryChooseDestinationDialog(this, settings, documentFiles.size(), new Dialogs.IOnDirectorySelected() {
@Override
Expand Down
Loading

0 comments on commit 23182d2

Please sign in to comment.