Skip to content

Commit

Permalink
Merge pull request #48 from Arctosoft/develop
Browse files Browse the repository at this point in the history
Version 1.7.0
  • Loading branch information
hej2010 authored Feb 18, 2024
2 parents ac1066d + 39ce7ad commit de72236
Show file tree
Hide file tree
Showing 16 changed files with 234 additions and 34 deletions.
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 21
versionName "1.6.1"
versionCode 23
versionName "1.7.0"

testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}
Expand Down
15 changes: 11 additions & 4 deletions app/src/main/java/se/arctosoft/vault/GalleryActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -300,10 +300,10 @@ public void onAlreadyExists(boolean isRootDir) {
}

private void importFiles(List<DocumentFile> documentFiles) {
Dialogs.showImportGalleryChooseDestinationDialog(this, settings, new Dialogs.IOnDirectorySelected() {
Dialogs.showImportGalleryChooseDestinationDialog(this, settings, documentFiles.size(), new Dialogs.IOnDirectorySelected() {
@Override
public void onDirectorySelected(@NonNull DocumentFile directory) {
importToDirectory(documentFiles, directory);
public void onDirectorySelected(@NonNull DocumentFile directory, boolean deleteOriginal) {
importToDirectory(documentFiles, directory, deleteOriginal);
}

@Override
Expand All @@ -314,7 +314,7 @@ public void onOtherDirectory() {
});
}

private void importToDirectory(@NonNull List<DocumentFile> documentFiles, @NonNull DocumentFile directory) {
private void importToDirectory(@NonNull List<DocumentFile> documentFiles, @NonNull DocumentFile directory, boolean deleteOriginal) {
new Thread(() -> {
double totalSize = 0;
for (DocumentFile file : documentFiles) {
Expand All @@ -324,6 +324,7 @@ private void importToDirectory(@NonNull List<DocumentFile> documentFiles, @NonNu
final String totalMB = decimalFormat.format(totalSize);
final int[] progress = new int[]{1};
final double[] bytesDone = new double[]{0};
final List<DocumentFile> filesToDelete = new ArrayList<>();
runOnUiThread(() -> setLoadingProgress(progress[0], documentFiles.size(), "0", totalMB));
for (DocumentFile file : documentFiles) {
if (cancelTask) {
Expand All @@ -344,6 +345,12 @@ private void importToDirectory(@NonNull List<DocumentFile> documentFiles, @NonNu
} else if (!imported.second) {
runOnUiThread(() -> Toaster.getInstance(GalleryActivity.this).showLong(getString(R.string.gallery_importing_error_no_thumb, file.getName())));
}
if (deleteOriginal && imported.first) {
filesToDelete.add(file);
}
}
for (DocumentFile toDelete : filesToDelete) {
toDelete.delete();
}
runOnUiThread(() -> {
Toaster.getInstance(GalleryActivity.this).showLong(getString(R.string.gallery_importing_done, progress[0] - 1));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.cardview.widget.CardView;
import androidx.core.content.res.ResourcesCompat;
import androidx.documentfile.provider.DocumentFile;
import androidx.fragment.app.FragmentActivity;
Expand Down Expand Up @@ -120,7 +119,6 @@ public void setOnSelectionModeChanged(IOnSelectionModeChanged onSelectionModeCha
@Override
public GalleryGridViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
AdapterGalleryGridItemBinding binding = AdapterGalleryGridItemBinding.inflate(LayoutInflater.from(parent.getContext()), parent, false);
CardView v = (CardView) LayoutInflater.from(parent.getContext()).inflate(R.layout.adapter_gallery_grid_item, parent, false);
return new GalleryGridViewHolder(binding);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@
import se.arctosoft.vault.utils.Dialogs;
import se.arctosoft.vault.utils.FileStuff;
import se.arctosoft.vault.utils.Settings;
import se.arctosoft.vault.utils.StringStuff;
import se.arctosoft.vault.utils.Toaster;

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

holder.parentBinding.txtName.setText(galleryFile.getName());
setName(holder, galleryFile);
if (holder instanceof GalleryPagerViewHolder.GalleryPagerVideoViewHolder) {
setupVideoView((GalleryPagerViewHolder.GalleryPagerVideoViewHolder) holder, context, galleryFile);
} else {
holder.parentBinding.imgFullscreen.setVisibility(View.GONE);
setupImageView(holder, context, galleryFile);
}
setupButtons(holder, context, galleryFile);
loadOriginalFilename(galleryFile, context, holder, position);
loadNote(holder, context, galleryFile);
}

private void setName(@NonNull GalleryPagerViewHolder holder, GalleryFile galleryFile) {
holder.parentBinding.txtName.setText(weakReference.get().getString(R.string.gallery_adapter_file_name, galleryFile.getName(), StringStuff.bytesToReadableString(galleryFile.getSize())));
}

@Override
public void onBindViewHolder(@NonNull GalleryPagerViewHolder holder, int position, @NonNull List<Object> payloads) {
boolean found = false;
Expand All @@ -142,7 +148,7 @@ public void onBindViewHolder(@NonNull GalleryPagerViewHolder holder, int positio
break;
} else if (o instanceof GalleryGridAdapter.Payload p) {
if (p.type() == GalleryGridAdapter.Payload.TYPE_NEW_FILENAME) {
holder.parentBinding.txtName.setText(galleryFiles.get(position).getName());
setName(holder, galleryFiles.get(position));
found = true;
} else if (p.type() == GalleryGridAdapter.Payload.TYPE_LOADED_NOTE) {
loadNote(holder, weakReference.get(), galleryFiles.get(position));
Expand All @@ -167,7 +173,7 @@ private void loadOriginalFilename(@NonNull GalleryFile galleryFile, FragmentActi
galleryFile.setOriginalName(originalFilename);
int pos = holder.getBindingAdapterPosition();
if (pos == position) {
context.runOnUiThread(() -> holder.parentBinding.txtName.setText(galleryFile.getName()));
context.runOnUiThread(() -> setName(holder, galleryFile));
} else if (pos >= 0 && pos < galleryFiles.size()) {
context.runOnUiThread(() -> notifyItemChanged(pos, new GalleryGridAdapter.Payload(GalleryGridAdapter.Payload.TYPE_NEW_FILENAME)));
}
Expand All @@ -185,8 +191,8 @@ private void setupVideoView(GalleryPagerViewHolder.GalleryPagerVideoViewHolder h
Glide.with(context)
.load(galleryFile.getThumbUri())
.into(holder.binding.imgThumb);
holder.binding.imgFullscreen.setOnClickListener(v -> toggleFullscreen(weakReference.get()));
holder.binding.imgFullscreen.setVisibility(isFullscreen ? View.GONE : View.VISIBLE);
holder.parentBinding.imgFullscreen.setOnClickListener(v -> toggleFullscreen(weakReference.get()));
holder.parentBinding.imgFullscreen.setVisibility(isFullscreen ? View.GONE : View.VISIBLE);
holder.binding.rLPlay.setOnClickListener(v -> {
holder.binding.rLPlay.setVisibility(View.GONE);
holder.binding.playerView.setVisibility(View.VISIBLE);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
/*
* 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.adapters;

import android.view.LayoutInflater;
import android.view.ViewGroup;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;

import java.util.List;

import se.arctosoft.vault.adapters.viewholders.ImportListViewHolder;
import se.arctosoft.vault.databinding.AdapterImportListItemBinding;
import se.arctosoft.vault.utils.Dialogs;

public class ImportListAdapter extends RecyclerView.Adapter<ImportListViewHolder> {
private final List<String> names;
private final Dialogs.IOnPositionSelected onPositionSelected;

public ImportListAdapter(List<String> names, Dialogs.IOnPositionSelected onPositionSelected) {
this.names = names;
this.onPositionSelected = onPositionSelected;
}

@NonNull
@Override
public ImportListViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
AdapterImportListItemBinding binding = AdapterImportListItemBinding.inflate(LayoutInflater.from(parent.getContext()), parent, false);
return new ImportListViewHolder(binding);
}

@Override
public void onBindViewHolder(@NonNull ImportListViewHolder holder, int position) {
holder.binding.text.setText(names.get(position));
holder.binding.text.setOnClickListener(v -> onPositionSelected.onSelected(position));
}

@Override
public int getItemCount() {
return names.size();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
/*
* 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.adapters.viewholders;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;

import se.arctosoft.vault.databinding.AdapterImportListItemBinding;

public class ImportListViewHolder extends RecyclerView.ViewHolder {
public final AdapterImportListItemBinding binding;

public ImportListViewHolder(@NonNull AdapterImportListItemBinding binding) {
super(binding.getRoot());
this.binding = binding;
}
}
2 changes: 1 addition & 1 deletion app/src/main/java/se/arctosoft/vault/data/GalleryFile.java
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ private GalleryFile(@NonNull CursorFile file, @Nullable CursorFile thumb, @Nulla
this.decryptedCacheUri = null;
this.lastModified = file.getLastModified();
this.isDirectory = false;
this.fileType = FileType.fromMimeType(file.getMimeType());
this.fileType = FileType.fromFilename(encryptedName);
this.size = file.getSize();
this.isAllFolder = false;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,8 +86,8 @@ public static Pair<Boolean, Boolean> importFileToDirectory(FragmentActivity cont
}

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

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

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

try {
createFile(context, note, file, tempPassword, fileNameWithoutPrefix);
Expand Down
35 changes: 27 additions & 8 deletions app/src/main/java/se/arctosoft/vault/utils/Dialogs.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,44 +24,63 @@

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.appcompat.app.AlertDialog;
import androidx.documentfile.provider.DocumentFile;
import androidx.fragment.app.FragmentActivity;
import androidx.recyclerview.widget.LinearLayoutManager;

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

import java.util.ArrayList;
import java.util.LinkedList;
import java.util.List;

import se.arctosoft.vault.BuildConfig;
import se.arctosoft.vault.R;
import se.arctosoft.vault.adapters.ImportListAdapter;
import se.arctosoft.vault.databinding.DialogEditTextBinding;
import se.arctosoft.vault.databinding.DialogImportBinding;
import se.arctosoft.vault.interfaces.IOnEdited;

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

public static void showImportGalleryChooseDestinationDialog(Context context, Settings settings, IOnDirectorySelected onDirectorySelected) {
public static void showImportGalleryChooseDestinationDialog(FragmentActivity context, Settings settings, int fileCount, IOnDirectorySelected onDirectorySelected) {
List<Uri> directories = settings.getGalleryDirectoriesAsUri(false);
String[] names = new String[directories.size()];
for (int i = 0; i < names.length; i++) {
names[i] = FileStuff.getFilenameWithPathFromUri(directories.get(i));
List<String> names = new ArrayList<>(directories.size());
for (int i = 0; i < directories.size(); i++) {
names.add(FileStuff.getFilenameWithPathFromUri(directories.get(i)));
}
//Log.e(TAG, "showImportGalleryChooseDestinationDialog: " + Arrays.toString(names));
new MaterialAlertDialogBuilder(context)
DialogImportBinding binding = DialogImportBinding.inflate(context.getLayoutInflater());

AlertDialog alertDialog = new MaterialAlertDialogBuilder(context)
.setTitle(context.getString(R.string.dialog_import_to_title))
.setItems(names, (dialog, which) -> onDirectorySelected.onDirectorySelected(DocumentFile.fromTreeUri(context, directories.get(which))))
.setView(binding.getRoot())
.setNegativeButton(android.R.string.cancel, null)
.setNeutralButton(R.string.dialog_import_to_button_neutral, (dialog, which) -> onDirectorySelected.onOtherDirectory())
.show();

ImportListAdapter adapter = new ImportListAdapter(names, pos -> {
alertDialog.dismiss();
Uri uri = directories.get(pos);
onDirectorySelected.onDirectorySelected(DocumentFile.fromTreeUri(context, uri), binding.checkbox.isChecked());
});
binding.checkbox.setText(context.getResources().getQuantityString(R.plurals.dialog_import_to_delete_original, fileCount));
binding.recycler.setLayoutManager(new LinearLayoutManager(context));
binding.recycler.setAdapter(adapter);
}

public interface IOnDirectorySelected {
void onDirectorySelected(@NonNull DocumentFile directory);
void onDirectorySelected(@NonNull DocumentFile directory, boolean deleteOriginal);

void onOtherDirectory();
}

public interface IOnPositionSelected {
void onSelected(int pos);
}

public interface IOnEditedIncludedFolders {
void onRemoved(@NonNull List<Uri> selectedToRemove);
}
Expand Down
13 changes: 12 additions & 1 deletion app/src/main/res/layout/adapter_gallery_viewpager_item.xml
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,22 @@

<TextView
android:id="@+id/txtName"
android:layout_width="match_parent"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginStart="4dp"
android:layout_marginEnd="4dp"
android:textSize="12sp"
app:layout_constraintEnd_toStartOf="@id/imgFullscreen"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />

<se.arctosoft.vault.views.PressableImageView
android:id="@+id/imgFullscreen"
android:layout_width="32dp"
android:layout_height="32dp"
android:src="@drawable/ic_round_fullscreen_24"
android:visibility="gone"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toTopOf="parent" />

<se.arctosoft.vault.views.PressableConstraintLayout
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,12 +34,4 @@

</RelativeLayout>

<se.arctosoft.vault.views.PressableImageView
android:id="@+id/imgFullscreen"
android:layout_width="32dp"
android:layout_height="32dp"
android:src="@drawable/ic_round_fullscreen_24"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toTopOf="parent" />

</androidx.constraintlayout.widget.ConstraintLayout>
25 changes: 25 additions & 0 deletions app/src/main/res/layout/adapter_import_list_item.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<?xml version="1.0" encoding="utf-8"?><!--
~ 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/.
-->

<TextView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/text"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="?attr/selectableItemBackground"
android:ellipsize="marquee"
android:padding="16dp" />
Loading

0 comments on commit de72236

Please sign in to comment.