Skip to content

Commit de72236

Browse files
authored
Merge pull request #48 from Arctosoft/develop
Version 1.7.0
2 parents ac1066d + 39ce7ad commit de72236

File tree

16 files changed

+234
-34
lines changed

16 files changed

+234
-34
lines changed

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 21
14-
versionName "1.6.1"
13+
versionCode 23
14+
versionName "1.7.0"
1515

1616
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
1717
}

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

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -300,10 +300,10 @@ public void onAlreadyExists(boolean isRootDir) {
300300
}
301301

302302
private void importFiles(List<DocumentFile> documentFiles) {
303-
Dialogs.showImportGalleryChooseDestinationDialog(this, settings, new Dialogs.IOnDirectorySelected() {
303+
Dialogs.showImportGalleryChooseDestinationDialog(this, settings, documentFiles.size(), new Dialogs.IOnDirectorySelected() {
304304
@Override
305-
public void onDirectorySelected(@NonNull DocumentFile directory) {
306-
importToDirectory(documentFiles, directory);
305+
public void onDirectorySelected(@NonNull DocumentFile directory, boolean deleteOriginal) {
306+
importToDirectory(documentFiles, directory, deleteOriginal);
307307
}
308308

309309
@Override
@@ -314,7 +314,7 @@ public void onOtherDirectory() {
314314
});
315315
}
316316

317-
private void importToDirectory(@NonNull List<DocumentFile> documentFiles, @NonNull DocumentFile directory) {
317+
private void importToDirectory(@NonNull List<DocumentFile> documentFiles, @NonNull DocumentFile directory, boolean deleteOriginal) {
318318
new Thread(() -> {
319319
double totalSize = 0;
320320
for (DocumentFile file : documentFiles) {
@@ -324,6 +324,7 @@ private void importToDirectory(@NonNull List<DocumentFile> documentFiles, @NonNu
324324
final String totalMB = decimalFormat.format(totalSize);
325325
final int[] progress = new int[]{1};
326326
final double[] bytesDone = new double[]{0};
327+
final List<DocumentFile> filesToDelete = new ArrayList<>();
327328
runOnUiThread(() -> setLoadingProgress(progress[0], documentFiles.size(), "0", totalMB));
328329
for (DocumentFile file : documentFiles) {
329330
if (cancelTask) {
@@ -344,6 +345,12 @@ private void importToDirectory(@NonNull List<DocumentFile> documentFiles, @NonNu
344345
} else if (!imported.second) {
345346
runOnUiThread(() -> Toaster.getInstance(GalleryActivity.this).showLong(getString(R.string.gallery_importing_error_no_thumb, file.getName())));
346347
}
348+
if (deleteOriginal && imported.first) {
349+
filesToDelete.add(file);
350+
}
351+
}
352+
for (DocumentFile toDelete : filesToDelete) {
353+
toDelete.delete();
347354
}
348355
runOnUiThread(() -> {
349356
Toaster.getInstance(GalleryActivity.this).showLong(getString(R.string.gallery_importing_done, progress[0] - 1));

app/src/main/java/se/arctosoft/vault/adapters/GalleryGridAdapter.java

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@
2929

3030
import androidx.annotation.NonNull;
3131
import androidx.annotation.Nullable;
32-
import androidx.cardview.widget.CardView;
3332
import androidx.core.content.res.ResourcesCompat;
3433
import androidx.documentfile.provider.DocumentFile;
3534
import androidx.fragment.app.FragmentActivity;
@@ -120,7 +119,6 @@ public void setOnSelectionModeChanged(IOnSelectionModeChanged onSelectionModeCha
120119
@Override
121120
public GalleryGridViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
122121
AdapterGalleryGridItemBinding binding = AdapterGalleryGridItemBinding.inflate(LayoutInflater.from(parent.getContext()), parent, false);
123-
CardView v = (CardView) LayoutInflater.from(parent.getContext()).inflate(R.layout.adapter_gallery_grid_item, parent, false);
124122
return new GalleryGridViewHolder(binding);
125123
}
126124

app/src/main/java/se/arctosoft/vault/adapters/GalleryPagerAdapter.java

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@
7272
import se.arctosoft.vault.utils.Dialogs;
7373
import se.arctosoft.vault.utils.FileStuff;
7474
import se.arctosoft.vault.utils.Settings;
75+
import se.arctosoft.vault.utils.StringStuff;
7576
import se.arctosoft.vault.utils.Toaster;
7677

7778
public class GalleryPagerAdapter extends RecyclerView.Adapter<GalleryPagerViewHolder> {
@@ -120,17 +121,22 @@ public void onBindViewHolder(@NonNull GalleryPagerViewHolder holder, int positio
120121
FragmentActivity context = weakReference.get();
121122
GalleryFile galleryFile = galleryFiles.get(position);
122123

123-
holder.parentBinding.txtName.setText(galleryFile.getName());
124+
setName(holder, galleryFile);
124125
if (holder instanceof GalleryPagerViewHolder.GalleryPagerVideoViewHolder) {
125126
setupVideoView((GalleryPagerViewHolder.GalleryPagerVideoViewHolder) holder, context, galleryFile);
126127
} else {
128+
holder.parentBinding.imgFullscreen.setVisibility(View.GONE);
127129
setupImageView(holder, context, galleryFile);
128130
}
129131
setupButtons(holder, context, galleryFile);
130132
loadOriginalFilename(galleryFile, context, holder, position);
131133
loadNote(holder, context, galleryFile);
132134
}
133135

136+
private void setName(@NonNull GalleryPagerViewHolder holder, GalleryFile galleryFile) {
137+
holder.parentBinding.txtName.setText(weakReference.get().getString(R.string.gallery_adapter_file_name, galleryFile.getName(), StringStuff.bytesToReadableString(galleryFile.getSize())));
138+
}
139+
134140
@Override
135141
public void onBindViewHolder(@NonNull GalleryPagerViewHolder holder, int position, @NonNull List<Object> payloads) {
136142
boolean found = false;
@@ -142,7 +148,7 @@ public void onBindViewHolder(@NonNull GalleryPagerViewHolder holder, int positio
142148
break;
143149
} else if (o instanceof GalleryGridAdapter.Payload p) {
144150
if (p.type() == GalleryGridAdapter.Payload.TYPE_NEW_FILENAME) {
145-
holder.parentBinding.txtName.setText(galleryFiles.get(position).getName());
151+
setName(holder, galleryFiles.get(position));
146152
found = true;
147153
} else if (p.type() == GalleryGridAdapter.Payload.TYPE_LOADED_NOTE) {
148154
loadNote(holder, weakReference.get(), galleryFiles.get(position));
@@ -167,7 +173,7 @@ private void loadOriginalFilename(@NonNull GalleryFile galleryFile, FragmentActi
167173
galleryFile.setOriginalName(originalFilename);
168174
int pos = holder.getBindingAdapterPosition();
169175
if (pos == position) {
170-
context.runOnUiThread(() -> holder.parentBinding.txtName.setText(galleryFile.getName()));
176+
context.runOnUiThread(() -> setName(holder, galleryFile));
171177
} else if (pos >= 0 && pos < galleryFiles.size()) {
172178
context.runOnUiThread(() -> notifyItemChanged(pos, new GalleryGridAdapter.Payload(GalleryGridAdapter.Payload.TYPE_NEW_FILENAME)));
173179
}
@@ -185,8 +191,8 @@ private void setupVideoView(GalleryPagerViewHolder.GalleryPagerVideoViewHolder h
185191
Glide.with(context)
186192
.load(galleryFile.getThumbUri())
187193
.into(holder.binding.imgThumb);
188-
holder.binding.imgFullscreen.setOnClickListener(v -> toggleFullscreen(weakReference.get()));
189-
holder.binding.imgFullscreen.setVisibility(isFullscreen ? View.GONE : View.VISIBLE);
194+
holder.parentBinding.imgFullscreen.setOnClickListener(v -> toggleFullscreen(weakReference.get()));
195+
holder.parentBinding.imgFullscreen.setVisibility(isFullscreen ? View.GONE : View.VISIBLE);
190196
holder.binding.rLPlay.setOnClickListener(v -> {
191197
holder.binding.rLPlay.setVisibility(View.GONE);
192198
holder.binding.playerView.setVisibility(View.VISIBLE);
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
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.adapters;
20+
21+
import android.view.LayoutInflater;
22+
import android.view.ViewGroup;
23+
24+
import androidx.annotation.NonNull;
25+
import androidx.recyclerview.widget.RecyclerView;
26+
27+
import java.util.List;
28+
29+
import se.arctosoft.vault.adapters.viewholders.ImportListViewHolder;
30+
import se.arctosoft.vault.databinding.AdapterImportListItemBinding;
31+
import se.arctosoft.vault.utils.Dialogs;
32+
33+
public class ImportListAdapter extends RecyclerView.Adapter<ImportListViewHolder> {
34+
private final List<String> names;
35+
private final Dialogs.IOnPositionSelected onPositionSelected;
36+
37+
public ImportListAdapter(List<String> names, Dialogs.IOnPositionSelected onPositionSelected) {
38+
this.names = names;
39+
this.onPositionSelected = onPositionSelected;
40+
}
41+
42+
@NonNull
43+
@Override
44+
public ImportListViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
45+
AdapterImportListItemBinding binding = AdapterImportListItemBinding.inflate(LayoutInflater.from(parent.getContext()), parent, false);
46+
return new ImportListViewHolder(binding);
47+
}
48+
49+
@Override
50+
public void onBindViewHolder(@NonNull ImportListViewHolder holder, int position) {
51+
holder.binding.text.setText(names.get(position));
52+
holder.binding.text.setOnClickListener(v -> onPositionSelected.onSelected(position));
53+
}
54+
55+
@Override
56+
public int getItemCount() {
57+
return names.size();
58+
}
59+
}
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
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.adapters.viewholders;
20+
21+
import androidx.annotation.NonNull;
22+
import androidx.recyclerview.widget.RecyclerView;
23+
24+
import se.arctosoft.vault.databinding.AdapterImportListItemBinding;
25+
26+
public class ImportListViewHolder extends RecyclerView.ViewHolder {
27+
public final AdapterImportListItemBinding binding;
28+
29+
public ImportListViewHolder(@NonNull AdapterImportListItemBinding binding) {
30+
super(binding.getRoot());
31+
this.binding = binding;
32+
}
33+
}

app/src/main/java/se/arctosoft/vault/data/GalleryFile.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ private GalleryFile(@NonNull CursorFile file, @Nullable CursorFile thumb, @Nulla
6363
this.decryptedCacheUri = null;
6464
this.lastModified = file.getLastModified();
6565
this.isDirectory = false;
66-
this.fileType = FileType.fromMimeType(file.getMimeType());
66+
this.fileType = FileType.fromFilename(encryptedName);
6767
this.size = file.getSize();
6868
this.isAllFolder = false;
6969
}

app/src/main/java/se/arctosoft/vault/encryption/Encryption.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -86,8 +86,8 @@ public static Pair<Boolean, Boolean> importFileToDirectory(FragmentActivity cont
8686
}
8787

8888
String generatedName = StringStuff.getRandomFileName();
89-
DocumentFile file = directory.createFile(sourceFile.getType(), FileType.fromMimeType(sourceFile.getType()).encryptionPrefix + generatedName);
90-
DocumentFile thumb = directory.createFile(sourceFile.getType(), PREFIX_THUMB + generatedName);
89+
DocumentFile file = directory.createFile("", FileType.fromMimeType(sourceFile.getType()).encryptionPrefix + generatedName);
90+
DocumentFile thumb = directory.createFile("", PREFIX_THUMB + generatedName);
9191

9292
if (file == null) {
9393
Log.e(TAG, "importFileToDirectory: could not create file from " + sourceFile.getUri());
@@ -118,7 +118,7 @@ public static DocumentFile importNoteToDirectory(FragmentActivity context, Strin
118118
throw new RuntimeException("No password");
119119
}
120120

121-
DocumentFile file = directory.createFile("text/plain", Encryption.PREFIX_NOTE_FILE + fileNameWithoutPrefix);
121+
DocumentFile file = directory.createFile("", Encryption.PREFIX_NOTE_FILE + fileNameWithoutPrefix);
122122

123123
try {
124124
createFile(context, note, file, tempPassword, fileNameWithoutPrefix);

app/src/main/java/se/arctosoft/vault/utils/Dialogs.java

Lines changed: 27 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -24,44 +24,63 @@
2424

2525
import androidx.annotation.NonNull;
2626
import androidx.annotation.Nullable;
27+
import androidx.appcompat.app.AlertDialog;
2728
import androidx.documentfile.provider.DocumentFile;
2829
import androidx.fragment.app.FragmentActivity;
30+
import androidx.recyclerview.widget.LinearLayoutManager;
2931

3032
import com.google.android.material.dialog.MaterialAlertDialogBuilder;
3133
import com.mikepenz.aboutlibraries.LibsBuilder;
3234

35+
import java.util.ArrayList;
3336
import java.util.LinkedList;
3437
import java.util.List;
3538

3639
import se.arctosoft.vault.BuildConfig;
3740
import se.arctosoft.vault.R;
41+
import se.arctosoft.vault.adapters.ImportListAdapter;
3842
import se.arctosoft.vault.databinding.DialogEditTextBinding;
43+
import se.arctosoft.vault.databinding.DialogImportBinding;
3944
import se.arctosoft.vault.interfaces.IOnEdited;
4045

4146
public class Dialogs {
4247
private static final String TAG = "Dialogs";
4348

44-
public static void showImportGalleryChooseDestinationDialog(Context context, Settings settings, IOnDirectorySelected onDirectorySelected) {
49+
public static void showImportGalleryChooseDestinationDialog(FragmentActivity context, Settings settings, int fileCount, IOnDirectorySelected onDirectorySelected) {
4550
List<Uri> directories = settings.getGalleryDirectoriesAsUri(false);
46-
String[] names = new String[directories.size()];
47-
for (int i = 0; i < names.length; i++) {
48-
names[i] = FileStuff.getFilenameWithPathFromUri(directories.get(i));
51+
List<String> names = new ArrayList<>(directories.size());
52+
for (int i = 0; i < directories.size(); i++) {
53+
names.add(FileStuff.getFilenameWithPathFromUri(directories.get(i)));
4954
}
50-
//Log.e(TAG, "showImportGalleryChooseDestinationDialog: " + Arrays.toString(names));
51-
new MaterialAlertDialogBuilder(context)
55+
DialogImportBinding binding = DialogImportBinding.inflate(context.getLayoutInflater());
56+
57+
AlertDialog alertDialog = new MaterialAlertDialogBuilder(context)
5258
.setTitle(context.getString(R.string.dialog_import_to_title))
53-
.setItems(names, (dialog, which) -> onDirectorySelected.onDirectorySelected(DocumentFile.fromTreeUri(context, directories.get(which))))
59+
.setView(binding.getRoot())
5460
.setNegativeButton(android.R.string.cancel, null)
5561
.setNeutralButton(R.string.dialog_import_to_button_neutral, (dialog, which) -> onDirectorySelected.onOtherDirectory())
5662
.show();
63+
64+
ImportListAdapter adapter = new ImportListAdapter(names, pos -> {
65+
alertDialog.dismiss();
66+
Uri uri = directories.get(pos);
67+
onDirectorySelected.onDirectorySelected(DocumentFile.fromTreeUri(context, uri), binding.checkbox.isChecked());
68+
});
69+
binding.checkbox.setText(context.getResources().getQuantityString(R.plurals.dialog_import_to_delete_original, fileCount));
70+
binding.recycler.setLayoutManager(new LinearLayoutManager(context));
71+
binding.recycler.setAdapter(adapter);
5772
}
5873

5974
public interface IOnDirectorySelected {
60-
void onDirectorySelected(@NonNull DocumentFile directory);
75+
void onDirectorySelected(@NonNull DocumentFile directory, boolean deleteOriginal);
6176

6277
void onOtherDirectory();
6378
}
6479

80+
public interface IOnPositionSelected {
81+
void onSelected(int pos);
82+
}
83+
6584
public interface IOnEditedIncludedFolders {
6685
void onRemoved(@NonNull List<Uri> selectedToRemove);
6786
}

app/src/main/res/layout/adapter_gallery_viewpager_item.xml

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,22 @@
1212

1313
<TextView
1414
android:id="@+id/txtName"
15-
android:layout_width="match_parent"
15+
android:layout_width="0dp"
1616
android:layout_height="wrap_content"
1717
android:layout_marginStart="4dp"
1818
android:layout_marginEnd="4dp"
1919
android:textSize="12sp"
20+
app:layout_constraintEnd_toStartOf="@id/imgFullscreen"
21+
app:layout_constraintStart_toStartOf="parent"
22+
app:layout_constraintTop_toTopOf="parent" />
23+
24+
<se.arctosoft.vault.views.PressableImageView
25+
android:id="@+id/imgFullscreen"
26+
android:layout_width="32dp"
27+
android:layout_height="32dp"
28+
android:src="@drawable/ic_round_fullscreen_24"
29+
android:visibility="gone"
30+
app:layout_constraintEnd_toEndOf="parent"
2031
app:layout_constraintTop_toTopOf="parent" />
2132

2233
<se.arctosoft.vault.views.PressableConstraintLayout

app/src/main/res/layout/adapter_gallery_viewpager_item_video.xml

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -34,12 +34,4 @@
3434

3535
</RelativeLayout>
3636

37-
<se.arctosoft.vault.views.PressableImageView
38-
android:id="@+id/imgFullscreen"
39-
android:layout_width="32dp"
40-
android:layout_height="32dp"
41-
android:src="@drawable/ic_round_fullscreen_24"
42-
app:layout_constraintEnd_toEndOf="parent"
43-
app:layout_constraintTop_toTopOf="parent" />
44-
4537
</androidx.constraintlayout.widget.ConstraintLayout>
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
<?xml version="1.0" encoding="utf-8"?><!--
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+
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
20+
android:id="@+id/text"
21+
android:layout_width="match_parent"
22+
android:layout_height="wrap_content"
23+
android:background="?attr/selectableItemBackground"
24+
android:ellipsize="marquee"
25+
android:padding="16dp" />

0 commit comments

Comments
 (0)