Skip to content

Commit

Permalink
Merge branch 'develop'
Browse files Browse the repository at this point in the history
  • Loading branch information
federicoiosue committed Apr 18, 2023
2 parents 96a2db3 + 5ba3924 commit 9bf9f0b
Show file tree
Hide file tree
Showing 10 changed files with 134 additions and 32 deletions.
4 changes: 2 additions & 2 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
VERSION_NAME=6.2.3
VERSION_CODE=318
VERSION_NAME=6.2.4
VERSION_CODE=319
PACKAGE=it.feio.android.omninotes
MIN_SDK=21
TARGET_SDK=31
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ protected Note createTestNote(String title, String content, int attachmentsNumbe
return note;
}

private Attachment createTestAttachment(String attachmentName) {
protected Attachment createTestAttachment(String attachmentName) {
try {
File testAttachment = File.createTempFile(attachmentName, ".txt");
IOUtils.write(
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
/*
* Copyright (C) 2013-2023 Federico Iosue ([email protected])
*
* 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 <http://www.gnu.org/licenses/>.
*/

package it.feio.android.omninotes.utils


import android.net.Uri
import androidx.core.net.toUri
import it.feio.android.omninotes.OmniNotes.getAppContext
import it.feio.android.omninotes.models.Attachment
import it.feio.android.omninotes.testutils.BaseAndroidTestCase
import it.feio.android.omninotes.utils.ConstantsBase.MIME_TYPE_IMAGE
import org.junit.Assert.*
import org.junit.Test
import java.io.File

class FileProviderHelperTest : BaseAndroidTestCase() {

@Test
fun getShareableUri() {
val file = File("/storage/emulated/0/Android/data/it.feio.android.omninotes/files/424242.png")
assertTrue(file.createNewFile() || file.exists())
val attachment = Attachment(file.toUri(), MIME_TYPE_IMAGE)

val res = FileProviderHelper.getShareableUri(attachment)

assertNotNull(res)
assertNotEquals(file.toUri(), res)
assertTrue(res?.scheme.equals("content") && res?.authority.equals(getAppContext().packageName + ".authority"))

file.deleteOnExit()
}

@Test
fun getShareableUri_contentScheme() {
val uri = "content://it.feio.android.omninotes.authority/external_files/Android/data/it.feio.android.omninotes/files/20230418_091959_730.jpeg"
val attachment = Attachment(Uri.parse(uri), "")

val res = FileProviderHelper.getShareableUri(attachment)

assertEquals(uri, res)
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
/*
* Copyright (C) 2013-2023 Federico Iosue ([email protected])
*
* 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 <http://www.gnu.org/licenses/>.
*/

package it.feio.android.omninotes.utils;

import android.content.Intent
import android.provider.MediaStore.ACTION_IMAGE_CAPTURE
import it.feio.android.omninotes.testutils.BaseAndroidTestCase
import org.junit.Assert.assertTrue
import org.junit.Test


class IntentCheckerTest : BaseAndroidTestCase() {

@Test
fun resolveActivityPackage() {
val res = IntentChecker.resolveActivityPackage(testContext, Intent(ACTION_IMAGE_CAPTURE))
assertTrue(res.isNotEmpty())
}

}
3 changes: 3 additions & 0 deletions omniNotes/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -337,6 +337,9 @@
<action android:name="android.intent.action.VIEW" />
<data android:scheme="http"/>
</intent>
<intent>
<action android:name="android.media.action.IMAGE_CAPTURE" />
</intent>
</queries>

</manifest>
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@

import static android.content.Context.CLIPBOARD_SERVICE;
import static android.content.Context.LAYOUT_INFLATER_SERVICE;
import static android.content.pm.PackageManager.FEATURE_CAMERA;
import static androidx.core.view.ViewCompat.animate;
import static it.feio.android.omninotes.BaseActivity.TRANSITION_HORIZONTAL;
import static it.feio.android.omninotes.BaseActivity.TRANSITION_VERTICAL;
Expand Down Expand Up @@ -1290,12 +1291,9 @@ private void showAttachmentsPopup() {
}

private void takePhoto() {
// Checks for camera app available
Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
if (!IntentChecker
.isAvailable(mainActivity, intent, new String[]{PackageManager.FEATURE_CAMERA})) {
if (!IntentChecker.isAvailable(mainActivity, intent, new String[]{FEATURE_CAMERA})) {
mainActivity.showMessage(R.string.feature_not_available_on_this_device, ONStyle.ALERT);

return;
}
// Checks for created file validity
Expand All @@ -1304,18 +1302,16 @@ private void takePhoto() {
mainActivity.showMessage(R.string.error, ONStyle.ALERT);
return;
}
attachmentUri = FileProviderHelper.getFileProvider(f);
attachmentUri = Uri.fromFile(f);
intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
intent.putExtra(MediaStore.EXTRA_OUTPUT, attachmentUri);
intent.putExtra(MediaStore.EXTRA_OUTPUT, FileProviderHelper.getFileProvider(f));
startActivityForResult(intent, TAKE_PHOTO);
}

private void takeVideo() {
Intent takeVideoIntent = new Intent(MediaStore.ACTION_VIDEO_CAPTURE);
if (!IntentChecker
.isAvailable(mainActivity, takeVideoIntent, new String[]{PackageManager.FEATURE_CAMERA})) {
if (!IntentChecker.isAvailable(mainActivity, takeVideoIntent, new String[]{FEATURE_CAMERA})) {
mainActivity.showMessage(R.string.feature_not_available_on_this_device, ONStyle.ALERT);

return;
}
// File is stored in custom ON folder to speedup the attachment
Expand All @@ -1324,18 +1320,17 @@ private void takeVideo() {
mainActivity.showMessage(R.string.error, ONStyle.ALERT);
return;
}
attachmentUri = FileProviderHelper.getFileProvider(f);
attachmentUri = Uri.fromFile(f);
takeVideoIntent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
takeVideoIntent.putExtra(MediaStore.EXTRA_OUTPUT, attachmentUri);
String maxVideoSizeStr = "".equals(Prefs.getString("settings_max_video_size",
"")) ? "0" : Prefs.getString("settings_max_video_size", "");
takeVideoIntent.putExtra(MediaStore.EXTRA_OUTPUT, FileProviderHelper.getFileProvider(f));
String maxVideoSizeStr = "".equals(Prefs.getString("settings_max_video_size", ""))
? "0" : Prefs.getString("settings_max_video_size", "");
long maxVideoSize = parseLong(maxVideoSizeStr) * 1024L * 1024L;
takeVideoIntent.putExtra(MediaStore.EXTRA_SIZE_LIMIT, maxVideoSize);
startActivityForResult(takeVideoIntent, TAKE_VIDEO);
}

private void takeSketch(Attachment attachment) {

File f = StorageHelper.createNewAttachmentFile(mainActivity, MIME_TYPE_SKETCH_EXT);
if (f == null) {
mainActivity.showMessage(R.string.error, ONStyle.ALERT);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,9 @@ private void exportData(Intent intent) {

BackupHelper.exportNotes(backupDir);
BackupHelper.exportAttachments(backupDir, mNotificationsHelper);
mNotificationsHelper.finish(getString(R.string.data_export_completed), backupDir.getUri().getPath());

var readableBackupFolder = BackupHelper.getBackupFolderPath() + "/" + backupName;
mNotificationsHelper.finish(getString(R.string.data_export_completed), readableBackupFolder);
}

@TargetApi(VERSION_CODES.O)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,14 +29,12 @@
import it.feio.android.omninotes.factory.MediaStoreFactory;
import it.feio.android.omninotes.helpers.LogDelegate;
import java.io.File;
import lombok.experimental.UtilityClass;


@UtilityClass
public class FileHelper {

private FileHelper() {
// hides public constructor
}

/**
* Get a file path from a Uri. This will get the the path for Storage Access Framework Documents,
* as well as the _data field for the MediaStore and other file-based ContentProviders.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,37 +17,42 @@

package it.feio.android.omninotes.utils;

import static androidx.core.content.FileProvider.getUriForFile;
import static it.feio.android.omninotes.OmniNotes.getAppContext;

import android.net.Uri;
import androidx.annotation.Nullable;
import androidx.core.content.FileProvider;
import it.feio.android.omninotes.OmniNotes;
import it.feio.android.omninotes.models.Attachment;
import java.io.File;
import java.io.FileNotFoundException;
import lombok.experimental.UtilityClass;

@UtilityClass
public class FileProviderHelper {

private FileProviderHelper() {
// hides public constructor
}

/**
* Generates the FileProvider URI for a given existing file
*/
public static Uri getFileProvider(File file) {
return FileProvider.getUriForFile(OmniNotes.getAppContext(),
OmniNotes.getAppContext().getPackageName() + ".authority", file);
return getUriForFile(getAppContext(), getAppContext().getPackageName() + ".authority", file);
}

/**
* Generates a shareable URI for a given attachment by evaluating its stored (into DB) path
*/
public static @Nullable Uri getShareableUri(Attachment attachment) throws FileNotFoundException {
File attachmentFile = new File(attachment.getUri().getPath());
var uri = attachment.getUri();

if (uri.getScheme().equals("content")
&& uri.getAuthority().equals(getAppContext().getPackageName() + ".authority")) {
return uri;
}

File attachmentFile = new File(uri.getPath());
if (!attachmentFile.exists()) {
throw new FileNotFoundException("Required attachment not found in " + attachment.getUriPath());
}
return FileProviderHelper.getFileProvider(attachmentFile);
return getFileProvider(attachmentFile);
}

}
6 changes: 6 additions & 0 deletions omniNotes/src/main/res/raw/changelog.xml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,12 @@
-->
<changelog bulletedList="true">

<changelogversion
changeDate="Apr 18, 2023"
versionName="6.2.4">
<changelogtext>[u]Fix[/u] Take camera picture action from some devices</changelogtext>
</changelogversion>

<changelogversion
changeDate="Apr 16, 2023"
versionName="6.2.3">
Expand Down

0 comments on commit 9bf9f0b

Please sign in to comment.