Skip to content

Commit

Permalink
Merge pull request #38 from Arctosoft/develop
Browse files Browse the repository at this point in the history
Share files to Valv, long press to select multiple files
  • Loading branch information
hej2010 authored Jan 15, 2024
2 parents 83d7629 + ddae4fa commit a083ebf
Show file tree
Hide file tree
Showing 14 changed files with 276 additions and 44 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 18
versionName "1.5.1"
versionCode 19
versionName "1.5.2"

testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}
Expand Down
23 changes: 22 additions & 1 deletion app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,28 @@
</activity>
<activity
android:name=".GalleryActivity"
android:exported="false" />
android:exported="true">
<intent-filter>
<action android:name="android.intent.action.SEND" />
<category android:name="android.intent.category.DEFAULT" />
<data android:mimeType="image/*" />
</intent-filter>
<intent-filter>
<action android:name="android.intent.action.SEND_MULTIPLE" />
<category android:name="android.intent.category.DEFAULT" />
<data android:mimeType="image/*" />
</intent-filter>
<intent-filter>
<action android:name="android.intent.action.SEND" />
<category android:name="android.intent.category.DEFAULT" />
<data android:mimeType="video/*" />
</intent-filter>
<intent-filter>
<action android:name="android.intent.action.SEND_MULTIPLE" />
<category android:name="android.intent.category.DEFAULT" />
<data android:mimeType="video/*" />
</intent-filter>
</activity>
</application>

</manifest>
89 changes: 75 additions & 14 deletions app/src/main/java/se/arctosoft/vault/GalleryActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@
import android.icu.text.DecimalFormat;
import android.net.Uri;
import android.os.Bundle;
import android.util.Log;
import android.util.Pair;
import android.view.Menu;
import android.view.MenuItem;
Expand Down Expand Up @@ -72,7 +71,9 @@ public class GalleryActivity extends AppCompatActivity {
private Settings settings;
private boolean cancelTask = false;
private boolean inSelectionMode = false;
private boolean isWaitingForUnlock = false;
private Snackbar snackBarBackPressed;
private Intent shareIntent;

@Override
protected void onCreate(Bundle savedInstanceState) {
Expand All @@ -87,17 +88,36 @@ protected void onCreate(Bundle savedInstanceState) {
ab.setDisplayHomeAsUpEnabled(false);
ab.setTitle(R.string.gallery_title);
}

init();

Intent intent = getIntent();
String action = intent.getAction();
String type = intent.getType();

if ((Intent.ACTION_SEND.equals(action) || Intent.ACTION_SEND_MULTIPLE.equals(action)) && type != null) {
if (settings.isLocked()) {
this.shareIntent = intent;
this.isWaitingForUnlock = true;
Toaster.getInstance(this).showShort(getString(R.string.gallery_share_locked));
startActivity(new Intent(this, LaunchActivity.class)
.putExtra(LaunchActivity.EXTRA_ONLY_UNLOCK, true));
} else {
handleShareIntent(intent, action, type);
}
} else {
if (settings.isLocked()) {
finish();
return;
}
setClickListeners();
findFolders();
}
}

private void init() {
viewModel = new ViewModelProvider(this).get(GalleryViewModel.class);
settings = Settings.getInstance(this);
if (settings.isLocked()) {
finish();
return;
}

galleryFiles = new ArrayList<>();
RecyclerView recyclerView = binding.recyclerView;
int spanCount = getResources().getConfiguration().orientation == Configuration.ORIENTATION_LANDSCAPE ? 6 : 3;
Expand All @@ -106,12 +126,45 @@ private void init() {
galleryGridAdapter = new GalleryGridAdapter(this, galleryFiles, true, true);
recyclerView.setAdapter(galleryGridAdapter);
galleryGridAdapter.setOnSelectionModeChanged(this::onSelectionModeChanged);
}

private void handleShareIntent(Intent intent, String action, String type) {
setClickListeners();

findFolders();
if (Intent.ACTION_SEND.equals(action)) {
if (type.startsWith("image/") || type.startsWith("video/")) {
handleSendSingle(intent);
}
} else if (Intent.ACTION_SEND_MULTIPLE.equals(action)) {
if (type.startsWith("image/") || type.startsWith("video/") || type.equals("*/*")) {
handleSendMultiple(intent);
}
}
}

private void handleSendSingle(Intent intent) {
Uri uri = (Uri) intent.getParcelableExtra(Intent.EXTRA_STREAM);
if (uri != null) {
List<Uri> list = new ArrayList<>(1);
list.add(uri);
List<DocumentFile> documentFiles = FileStuff.getDocumentsFromShareIntent(this, list);
if (!documentFiles.isEmpty()) {
importFiles(documentFiles);
}
}
}

private void handleSendMultiple(Intent intent) {
ArrayList<Uri> uris = intent.getParcelableArrayListExtra(Intent.EXTRA_STREAM);
if (uris != null) {
List<DocumentFile> documentFiles = FileStuff.getDocumentsFromShareIntent(this, uris);
if (!documentFiles.isEmpty()) {
importFiles(documentFiles);
}
}
}


private void onSelectionModeChanged(boolean inSelectionMode) {
this.inSelectionMode = inSelectionMode;
if (inSelectionMode) {
Expand Down Expand Up @@ -379,6 +432,18 @@ private void lock() {
finish();
}

@Override
protected void onResume() {
super.onResume();
if (isWaitingForUnlock && settings != null && !settings.isLocked() && shareIntent != null) {
handleShareIntent(shareIntent, shareIntent.getAction(), shareIntent.getType());
isWaitingForUnlock = false;
shareIntent = null;
} else if (!isWaitingForUnlock && (settings == null || settings.isLocked())) {
finishAffinity();
}
}

@Override
public void onBackPressed() {
if (binding.cLLoading.cLLoading.getVisibility() == View.VISIBLE) {
Expand All @@ -392,6 +457,9 @@ public void onBackPressed() {
snackBarBackPressed.setAnchorView(binding.lLButtons);
snackBarBackPressed.show();
} else {
if (isTaskRoot()) {
Password.lock(this, settings);
}
super.onBackPressed();
}
}
Expand All @@ -401,11 +469,4 @@ public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.menu_gallery, menu);
return super.onCreateOptionsMenu(menu);
}

@Override
protected void onDestroy() {
Log.d(TAG, "onDestroy: ");
//lock();
super.onDestroy();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,10 @@ private void setClickListeners() {
(dialog, which) -> deleteSelectedFiles()));
}

public void onSelectionChanged(int selected) {
binding.btnDeleteFiles.setText(getString(R.string.gallery_delete_selected_files, selected));
}

private void deleteSelectedFiles() { // TODO run in parallel to make it faster, ExecutorService
setLoading(true);
new Thread(() -> {
Expand Down
26 changes: 17 additions & 9 deletions app/src/main/java/se/arctosoft/vault/LaunchActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
import android.text.Editable;
import android.text.TextWatcher;
import android.util.Log;
import android.view.View;
import android.view.WindowManager;
import android.view.inputmethod.EditorInfo;

Expand All @@ -39,10 +38,12 @@
public class LaunchActivity extends AppCompatActivity {
private static final String TAG = "LaunchActivity";
public static long GLIDE_KEY = System.currentTimeMillis();
public static String EXTRA_ONLY_UNLOCK = "u";

private ActivityLaunchBinding binding;
private Settings settings;
private AtomicBoolean isStarting;
private boolean onlyUnlock;

@Override
protected void onCreate(Bundle savedInstanceState) {
Expand All @@ -51,13 +52,16 @@ protected void onCreate(Bundle savedInstanceState) {
binding = ActivityLaunchBinding.inflate(getLayoutInflater());
setContentView(binding.getRoot());

onlyUnlock = getIntent().getBooleanExtra(EXTRA_ONLY_UNLOCK, false);
init();
}

private void init() {
settings = Settings.getInstance(this);
isStarting = new AtomicBoolean(false);
Password.lock(this, settings);
if (!onlyUnlock) {
Password.lock(this, settings);
}

setListeners();
}
Expand Down Expand Up @@ -91,13 +95,17 @@ public void afterTextChanged(Editable s) {
if (isStarting.compareAndSet(false, true)) {
binding.btnUnlock.setEnabled(false);
settings.setTempPassword(binding.eTPassword.getText().toString().toCharArray());
startActivity(new Intent(this, GalleryActivity.class));
binding.eTPassword.postDelayed(() -> {
binding.eTPassword.setText(null);
binding.eTPassword.clearFocus();
binding.getRoot().requestFocus();
isStarting.set(false);
}, 400);
if (onlyUnlock) {
finish();
} else {
startActivity(new Intent(this, GalleryActivity.class));
binding.eTPassword.postDelayed(() -> {
binding.eTPassword.setText(null);
binding.eTPassword.clearFocus();
binding.getRoot().requestFocus();
isStarting.set(false);
}, 400);
}
}
});
binding.btnHelp.setOnClickListener(v -> Dialogs.showTextDialog(this, null, getString(R.string.launcher_help_message)));
Expand Down
Loading

0 comments on commit a083ebf

Please sign in to comment.