Skip to content

Commit 23182d2

Browse files
authored
Merge pull request #76 from Arctosoft/develop
Version 1.9.0
2 parents 2766445 + 41fc92d commit 23182d2

File tree

17 files changed

+456
-73
lines changed

17 files changed

+456
-73
lines changed

.idea/deploymentTargetSelector.xml

Lines changed: 10 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

app/build.gradle

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@ android {
1010
applicationId "se.arctosoft.vault"
1111
minSdk 28
1212
targetSdk 34
13-
versionCode 26
14-
versionName "1.8.2"
13+
versionCode 27
14+
versionName "1.9.0"
1515

1616
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
1717
}
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
/*
2+
* Valv-Android
3+
* Copyright (C) 2023 Arctosoft AB
4+
*
5+
* This program is free software: you can redistribute it and/or modify
6+
* it under the terms of the GNU General Public License as published by
7+
* the Free Software Foundation, either version 3 of the License, or
8+
* (at your option) any later version.
9+
*
10+
* This program is distributed in the hope that it will be useful,
11+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
12+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13+
* GNU General Public License for more details.
14+
*
15+
* You should have received a copy of the GNU General Public License
16+
* along with this program. If not, see https://www.gnu.org/licenses/.
17+
*/
18+
19+
package se.arctosoft.vault;
20+
21+
import android.content.Intent;
22+
23+
import androidx.activity.result.ActivityResult;
24+
import androidx.appcompat.app.AppCompatActivity;
25+
26+
import se.arctosoft.vault.utils.BetterActivityResult;
27+
28+
public class BaseActivity extends AppCompatActivity {
29+
protected final BetterActivityResult<Intent, ActivityResult> activityLauncher = BetterActivityResult.registerActivityForResult(this);
30+
}

app/src/main/java/se/arctosoft/vault/GalleryActivity.java

Lines changed: 50 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -30,10 +30,10 @@
3030
import android.view.View;
3131
import android.view.WindowManager;
3232

33+
import androidx.activity.result.ActivityResult;
3334
import androidx.annotation.NonNull;
3435
import androidx.annotation.Nullable;
3536
import androidx.appcompat.app.ActionBar;
36-
import androidx.appcompat.app.AppCompatActivity;
3737
import androidx.documentfile.provider.DocumentFile;
3838
import androidx.lifecycle.ViewModelProvider;
3939
import androidx.recyclerview.widget.GridLayoutManager;
@@ -57,11 +57,8 @@
5757
import se.arctosoft.vault.utils.Toaster;
5858
import se.arctosoft.vault.viewmodel.GalleryViewModel;
5959

60-
public class GalleryActivity extends AppCompatActivity {
60+
public class GalleryActivity extends BaseActivity {
6161
private static final String TAG = "GalleryActivity";
62-
private static final int REQUEST_ADD_DIRECTORY = 1;
63-
private static final int REQUEST_IMPORT_IMAGES = 3;
64-
private static final int REQUEST_IMPORT_VIDEOS = 4;
6562

6663
private static final Object LOCK = new Object();
6764

@@ -178,7 +175,7 @@ private void onSelectionModeChanged(boolean inSelectionMode) {
178175
}
179176

180177
private void setClickListeners() {
181-
binding.btnAddFolder.setOnClickListener(v -> startActivityForResult(new Intent(Intent.ACTION_OPEN_DOCUMENT_TREE), REQUEST_ADD_DIRECTORY));
178+
binding.btnAddFolder.setOnClickListener(v -> activityLauncher.launch(new Intent(Intent.ACTION_OPEN_DOCUMENT_TREE), this::addFolder));
182179
binding.btnImportFiles.setOnClickListener(v -> showImportOverlay(true));
183180
binding.btnRemoveFolder.setOnClickListener(v -> Dialogs.showConfirmationDialog(this, getString(R.string.dialog_remove_folder_title),
184181
getResources().getQuantityString(R.plurals.dialog_remove_folder_message, galleryGridAdapter.getSelectedFiles().size()),
@@ -199,16 +196,61 @@ private void setClickListeners() {
199196
galleryGridAdapter.onSelectionModeChanged(false);
200197
}));
201198
binding.btnImportImages.setOnClickListener(v -> {
202-
FileStuff.pickImageFiles(this, REQUEST_IMPORT_IMAGES);
199+
FileStuff.pickImageFiles(activityLauncher, result -> onImportImagesOrVideos(result.getData()));
203200
showImportOverlay(false);
204201
});
205202
binding.btnImportVideos.setOnClickListener(v -> {
206-
FileStuff.pickVideoFiles(this, REQUEST_IMPORT_VIDEOS);
203+
FileStuff.pickVideoFiles(activityLauncher, result -> onImportImagesOrVideos(result.getData()));
207204
showImportOverlay(false);
208205
});
209206
binding.importChooseOverlay.setOnClickListener(v -> showImportOverlay(false));
210207
}
211208

209+
private void onImportImagesOrVideos(@Nullable Intent data) {
210+
if (data != null) {
211+
List<DocumentFile> documentFiles = FileStuff.getDocumentsFromDirectoryResult(this, data);
212+
if (!documentFiles.isEmpty()) {
213+
importFiles(documentFiles);
214+
}
215+
}
216+
}
217+
218+
private void addFolder(ActivityResult result) {
219+
if (result.getResultCode() == Activity.RESULT_OK) {
220+
Intent data = result.getData();
221+
if (data != null) {
222+
Uri uri = data.getData();
223+
DocumentFile documentFile = DocumentFile.fromTreeUri(this, uri);
224+
getContentResolver().takePersistableUriPermission(uri, Intent.FLAG_GRANT_READ_URI_PERMISSION | Intent.FLAG_GRANT_WRITE_URI_PERMISSION);
225+
settings.addGalleryDirectory(documentFile.getUri(), new IOnDirectoryAdded() {
226+
@Override
227+
public void onAddedAsRoot() {
228+
Toaster.getInstance(GalleryActivity.this).showLong(getString(R.string.gallery_added_folder, FileStuff.getFilenameWithPathFromUri(uri)));
229+
addDirectory(documentFile.getUri());
230+
}
231+
232+
@Override
233+
public void onAddedAsChildOf(@NonNull Uri parentUri) {
234+
Toaster.getInstance(GalleryActivity.this).showLong(getString(R.string.gallery_added_folder_child, FileStuff.getFilenameWithPathFromUri(uri), FileStuff.getFilenameWithPathFromUri(parentUri)));
235+
}
236+
237+
@Override
238+
public void onAlreadyExists(boolean isRootDir) {
239+
Toaster.getInstance(GalleryActivity.this).showLong(getString(R.string.gallery_added_folder_duplicate, FileStuff.getFilenameWithPathFromUri(uri)));
240+
if (isRootDir) {
241+
findFolders();
242+
}
243+
}
244+
});
245+
if (viewModel.getFilesToAdd() != null) {
246+
importFiles(viewModel.getFilesToAdd());
247+
}
248+
}
249+
} else if (result.getResultCode() == Activity.RESULT_CANCELED) {
250+
viewModel.setFilesToAdd(null);
251+
}
252+
}
253+
212254
private void showImportOverlay(boolean show) {
213255
binding.cLImportChoose.setVisibility(show ? View.VISIBLE : View.GONE);
214256
}
@@ -254,52 +296,6 @@ private void findFolders() {
254296
}).start();
255297
}
256298

257-
@Override
258-
protected void onActivityResult(int requestCode, int resultCode, @Nullable Intent data) {
259-
super.onActivityResult(requestCode, resultCode, data);
260-
if (requestCode == REQUEST_ADD_DIRECTORY) {
261-
if (resultCode == Activity.RESULT_OK) {
262-
if (data != null) {
263-
Uri uri = data.getData();
264-
DocumentFile documentFile = DocumentFile.fromTreeUri(this, uri);
265-
getContentResolver().takePersistableUriPermission(uri, Intent.FLAG_GRANT_READ_URI_PERMISSION | Intent.FLAG_GRANT_WRITE_URI_PERMISSION);
266-
settings.addGalleryDirectory(documentFile.getUri(), new IOnDirectoryAdded() {
267-
@Override
268-
public void onAddedAsRoot() {
269-
Toaster.getInstance(GalleryActivity.this).showLong(getString(R.string.gallery_added_folder, FileStuff.getFilenameWithPathFromUri(uri)));
270-
addDirectory(documentFile.getUri());
271-
}
272-
273-
@Override
274-
public void onAddedAsChildOf(@NonNull Uri parentUri) {
275-
Toaster.getInstance(GalleryActivity.this).showLong(getString(R.string.gallery_added_folder_child, FileStuff.getFilenameWithPathFromUri(uri), FileStuff.getFilenameWithPathFromUri(parentUri)));
276-
}
277-
278-
@Override
279-
public void onAlreadyExists(boolean isRootDir) {
280-
Toaster.getInstance(GalleryActivity.this).showLong(getString(R.string.gallery_added_folder_duplicate, FileStuff.getFilenameWithPathFromUri(uri)));
281-
if (isRootDir) {
282-
findFolders();
283-
}
284-
}
285-
});
286-
if (viewModel.getFilesToAdd() != null) {
287-
importFiles(viewModel.getFilesToAdd());
288-
}
289-
}
290-
} else if (resultCode == Activity.RESULT_CANCELED) {
291-
viewModel.setFilesToAdd(null);
292-
}
293-
} else if ((requestCode == REQUEST_IMPORT_IMAGES || requestCode == REQUEST_IMPORT_VIDEOS) && resultCode == Activity.RESULT_OK) {
294-
if (data != null) {
295-
List<DocumentFile> documentFiles = FileStuff.getDocumentsFromDirectoryResult(this, data);
296-
if (!documentFiles.isEmpty()) {
297-
importFiles(documentFiles);
298-
}
299-
}
300-
}
301-
}
302-
303299
private void importFiles(List<DocumentFile> documentFiles) {
304300
Dialogs.showImportGalleryChooseDestinationDialog(this, settings, documentFiles.size(), new Dialogs.IOnDirectorySelected() {
305301
@Override

0 commit comments

Comments
 (0)