Skip to content

Commit

Permalink
Merge pull request nextcloud#12995 from timedin-de/master
Browse files Browse the repository at this point in the history
Added direct upload from video camera
  • Loading branch information
AndyScherzinger authored Jun 19, 2024
2 parents 40d8e7b + d00c157 commit 5c6ddae
Show file tree
Hide file tree
Showing 7 changed files with 78 additions and 33 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,7 @@ public class FileDisplayActivity extends FileActivity
public static final int REQUEST_CODE__SELECT_FILES_FROM_FILE_SYSTEM = REQUEST_CODE__LAST_SHARED + 2;
public static final int REQUEST_CODE__MOVE_OR_COPY_FILES = REQUEST_CODE__LAST_SHARED + 3;
public static final int REQUEST_CODE__UPLOAD_FROM_CAMERA = REQUEST_CODE__LAST_SHARED + 5;
public static final int REQUEST_CODE__UPLOAD_FROM_VIDEO_CAMERA = REQUEST_CODE__LAST_SHARED + 6;

protected static final long DELAY_TO_REQUEST_REFRESH_OPERATION_LATER = DELAY_TO_REQUEST_OPERATIONS_LATER + 350;

Expand Down Expand Up @@ -447,7 +448,7 @@ public void onRequestPermissionsResult(int requestCode, @NonNull String[] permis
// If request is cancelled, result arrays are empty.
if (grantResults.length > 0 && grantResults[0] == PackageManager.PERMISSION_GRANTED) {
// permission was granted
getFileOperationsHelper().uploadFromCamera(this, FileDisplayActivity.REQUEST_CODE__UPLOAD_FROM_CAMERA);
getOCFileListFragmentFromFile().directCameraUpload();
}
break;
default:
Expand Down Expand Up @@ -851,7 +852,7 @@ protected void onActivityResult(int requestCode, int resultCode, Intent data) {

requestUploadOfFilesFromFileSystem(data, resultCode);

} else if (requestCode == REQUEST_CODE__UPLOAD_FROM_CAMERA && (resultCode == RESULT_OK || resultCode == UploadFilesActivity.RESULT_OK_AND_DELETE)) {
} else if ((requestCode == REQUEST_CODE__UPLOAD_FROM_CAMERA || requestCode == REQUEST_CODE__UPLOAD_FROM_VIDEO_CAMERA) && (resultCode == RESULT_OK || resultCode == UploadFilesActivity.RESULT_OK_AND_DELETE)) {

new CheckAvailableSpaceTask(new CheckAvailableSpaceTask.CheckAvailableSpaceListener() {
@Override
Expand All @@ -865,17 +866,22 @@ public void onCheckAvailableSpaceFinish(boolean hasEnoughSpaceAvailable, String.

if (hasEnoughSpaceAvailable) {
File file = new File(filesToUpload[0]);
File renamedFile = new File(file.getParent() + PATH_SEPARATOR + FileOperationsHelper.getCapturedImageName());
File renamedFile;
if(requestCode == REQUEST_CODE__UPLOAD_FROM_CAMERA) {
renamedFile = new File(file.getParent() + PATH_SEPARATOR + FileOperationsHelper.getCapturedImageName());
} else {
renamedFile = new File(file.getParent() + PATH_SEPARATOR + FileOperationsHelper.getCapturedVideoName());
}

if (!file.renameTo(renamedFile)) {
DisplayUtils.showSnackMessage(getActivity(), "Fail to upload taken image!");
DisplayUtils.showSnackMessage(getActivity(), R.string.error_uploading_direct_camera_upload);
return;
}

requestUploadOfFilesFromFileSystem(renamedFile.getParentFile().getAbsolutePath(), new String[]{renamedFile.getAbsolutePath()}, FileUploadWorker.LOCAL_BEHAVIOUR_DELETE);
}
}
}, new String[]{FileOperationsHelper.createImageFile(getActivity()).getAbsolutePath()}).execute();
}, new String[]{FileOperationsHelper.createCameraFile(getActivity(), requestCode == REQUEST_CODE__UPLOAD_FROM_VIDEO_CAMERA).getAbsolutePath()}).execute();
} else if (requestCode == REQUEST_CODE__MOVE_OR_COPY_FILES && resultCode == RESULT_OK) {
exitSelectionMode();
} else if (requestCode == PermissionUtil.REQUEST_CODE_MANAGE_ALL_FILES) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

import com.google.android.material.bottomsheet.BottomSheetDialog;
import com.google.gson.Gson;
import com.nextcloud.android.common.ui.theme.utils.ColorRole;
import com.nextcloud.client.account.User;
import com.nextcloud.client.device.DeviceInfo;
import com.nextcloud.client.di.Injectable;
Expand Down Expand Up @@ -75,12 +76,12 @@ protected void onCreate(Bundle savedInstanceState) {
binding = FileListActionsBottomSheetFragmentBinding.inflate(getLayoutInflater());
setContentView(binding.getRoot());

viewThemeUtils.platform.colorImageView(binding.menuIconUploadFiles);
viewThemeUtils.platform.colorImageView(binding.menuIconUploadFromApp);
viewThemeUtils.platform.colorImageView(binding.menuIconDirectCameraUpload);
viewThemeUtils.platform.colorImageView(binding.menuIconScanDocUpload);
viewThemeUtils.platform.colorImageView(binding.menuIconMkdir);
viewThemeUtils.platform.colorImageView(binding.menuIconAddFolderInfo);
viewThemeUtils.platform.colorImageView(binding.menuIconUploadFiles, ColorRole.PRIMARY);
viewThemeUtils.platform.colorImageView(binding.menuIconUploadFromApp, ColorRole.PRIMARY);
viewThemeUtils.platform.colorImageView(binding.menuIconDirectCameraUpload, ColorRole.PRIMARY);
viewThemeUtils.platform.colorImageView(binding.menuIconScanDocUpload, ColorRole.PRIMARY);
viewThemeUtils.platform.colorImageView(binding.menuIconMkdir, ColorRole.PRIMARY);
viewThemeUtils.platform.colorImageView(binding.menuIconAddFolderInfo, ColorRole.PRIMARY);

binding.addToCloud.setText(getContext().getResources().getString(R.string.add_to_cloud,
themeUtils.getDefaultDisplayNameForRootFolder(getContext())));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
*/
package com.owncloud.android.ui.fragment;

import android.Manifest;
import android.app.Activity;
import android.content.Context;
import android.content.Intent;
Expand Down Expand Up @@ -108,6 +109,7 @@
import com.owncloud.android.utils.FileSortOrder;
import com.owncloud.android.utils.FileStorageUtils;
import com.owncloud.android.utils.MimeTypeUtil;
import com.owncloud.android.utils.PermissionUtil;
import com.owncloud.android.utils.theme.ThemeUtils;
import com.owncloud.android.utils.theme.ViewThemeUtils;

Expand All @@ -131,6 +133,7 @@
import androidx.annotation.OptIn;
import androidx.annotation.StringRes;
import androidx.appcompat.app.ActionBar;
import androidx.appcompat.app.AlertDialog;
import androidx.coordinatorlayout.widget.CoordinatorLayout;
import androidx.core.content.ContextCompat;
import androidx.drawerlayout.widget.DrawerLayout;
Expand Down Expand Up @@ -521,12 +524,29 @@ public void uploadFromApp() {
public void directCameraUpload() {
FileDisplayActivity fileDisplayActivity = (FileDisplayActivity) getActivity();

if (fileDisplayActivity != null) {
fileDisplayActivity.getFileOperationsHelper()
.uploadFromCamera(fileDisplayActivity, FileDisplayActivity.REQUEST_CODE__UPLOAD_FROM_CAMERA);
} else {
if (fileDisplayActivity == null) {
DisplayUtils.showSnackMessage(getView(), getString(R.string.error_starting_direct_camera_upload));
return;
}

if (!PermissionUtil.checkSelfPermission(fileDisplayActivity, Manifest.permission.CAMERA)) {
PermissionUtil.requestCameraPermission(fileDisplayActivity, PermissionUtil.PERMISSIONS_CAMERA);
return;
}

showDirectCameraUploadAlertDialog(fileDisplayActivity);
}

private void showDirectCameraUploadAlertDialog(FileDisplayActivity fileDisplayActivity) {
AlertDialog.Builder builder = new AlertDialog.Builder(fileDisplayActivity);
AlertDialog dialog = builder.setIcon(R.mipmap.ic_launcher)
.setTitle(R.string.upload_direct_camera_promt)
.setNegativeButton(R.string.upload_direct_camera_video, (iface, id) ->
fileDisplayActivity.getFileOperationsHelper().uploadFromCamera(fileDisplayActivity,FileDisplayActivity.REQUEST_CODE__UPLOAD_FROM_VIDEO_CAMERA, true))
.setPositiveButton(R.string.upload_direct_camera_photo, (iface, id) ->
fileDisplayActivity.getFileOperationsHelper().uploadFromCamera(fileDisplayActivity, FileDisplayActivity.REQUEST_CODE__UPLOAD_FROM_CAMERA, false))
.create();
dialog.show();
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
*/
package com.owncloud.android.ui.helpers;

import android.Manifest;
import android.accounts.Account;
import android.app.Activity;
import android.content.ActivityNotFoundException;
Expand Down Expand Up @@ -69,7 +68,6 @@
import com.owncloud.android.utils.DisplayUtils;
import com.owncloud.android.utils.EncryptionUtils;
import com.owncloud.android.utils.FileStorageUtils;
import com.owncloud.android.utils.PermissionUtil;
import com.owncloud.android.utils.UriUtils;
import com.owncloud.android.utils.theme.ViewThemeUtils;

Expand Down Expand Up @@ -1058,36 +1056,44 @@ public void checkCurrentCredentials(User user) {
fileActivity.showLoadingDialog(fileActivity.getString(R.string.wait_checking_credentials));
}

public void uploadFromCamera(Activity activity, int requestCode) {
Intent pictureIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
public void uploadFromCamera(Activity activity, int requestCode, boolean isVideo) {
Intent intent;
if (isVideo) {

File photoFile = createImageFile(activity);
// FIXME Not working on Emulator
intent = new Intent(MediaStore.ACTION_VIDEO_CAPTURE);
} else {
intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
}

Uri photoUri = FileProvider.getUriForFile(activity.getApplicationContext(),
activity.getResources().getString(R.string.file_provider_authority), photoFile);
pictureIntent.putExtra(MediaStore.EXTRA_OUTPUT, photoUri);
File cameraFile = createCameraFile(activity, isVideo);

if (pictureIntent.resolveActivity(activity.getPackageManager()) != null) {
if (PermissionUtil.checkSelfPermission(activity, Manifest.permission.CAMERA)) {
activity.startActivityForResult(pictureIntent, requestCode);
} else {
PermissionUtil.requestCameraPermission(activity, PermissionUtil.PERMISSIONS_CAMERA);
}
Uri cameraUri = FileProvider.getUriForFile(activity.getApplicationContext(),
activity.getResources().getString(R.string.file_provider_authority), cameraFile);
intent.putExtra(MediaStore.EXTRA_OUTPUT, cameraUri);

if (intent.resolveActivity(activity.getPackageManager()) != null) {
activity.startActivityForResult(intent, requestCode);
} else {
DisplayUtils.showSnackMessage(activity, "No Camera found");
}
}

public static File createImageFile(Activity activity) {
File storageDir = activity.getExternalFilesDir(Environment.DIRECTORY_PICTURES);

return new File(storageDir + "/directCameraUpload.jpg");
public static File createCameraFile(Activity activity, boolean isVideo) {
String directory = isVideo ? Environment.DIRECTORY_MOVIES : Environment.DIRECTORY_PICTURES;
File storageDir = activity.getExternalFilesDir(directory);
String fileName = isVideo ? "/directCameraUpload.mp4" : "/directCameraUpload.jpg";
return new File(storageDir + fileName);
}

public static String getCapturedImageName() {
return getTimestampedFileName(".jpg");
}

public static String getCapturedVideoName() {
return getTimestampedFileName(".mp4");
}

/**
* @param extension a file extension, including the dot
* @return a filename with the given extension, based on the current date and time.
Expand Down
4 changes: 4 additions & 0 deletions app/src/main/res/values-b+en+001/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -904,6 +904,10 @@
<string name="upload_chooser_title">Upload from…</string>
<string name="upload_content_from_other_apps">Upload content from other apps</string>
<string name="upload_direct_camera_upload">Upload from camera</string>
<string name="upload_direct_camera_promt">Do you want to take a photo or video?</string>
<string name="upload_direct_camera_photo">Photo</string>
<string name="upload_direct_camera_video">Video</string>
<string name="error_uploading_direct_camera_upload">Failed to upload taken media</string>
<string name="upload_file_dialog_filename">Filename</string>
<string name="upload_file_dialog_filetype">Filetype</string>
<string name="upload_file_dialog_filetype_googlemap_shortcut">Google Maps shortcut file(%s)</string>
Expand Down
4 changes: 4 additions & 0 deletions app/src/main/res/values-de/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -904,6 +904,10 @@
<string name="upload_chooser_title">Dateien hochladen von…</string>
<string name="upload_content_from_other_apps">Inhalt anderer Apps hochladen</string>
<string name="upload_direct_camera_upload">Von Kamera hochladen</string>
<string name="upload_direct_camera_promt">Möchten Sie ein Foto oder Video aufnehmen?</string>
<string name="upload_direct_camera_photo">Foto</string>
<string name="upload_direct_camera_video">Video</string>
<string name="error_uploading_direct_camera_upload">Hochladen von Medien fehlgeschlagen</string>
<string name="upload_file_dialog_filename">Dateiname</string>
<string name="upload_file_dialog_filetype">Dateityp</string>
<string name="upload_file_dialog_filetype_googlemap_shortcut">Google Maps Abkürzungs-Datei (%s)</string>
Expand Down
4 changes: 4 additions & 0 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -812,6 +812,10 @@
<string name="add_to_cloud">Add to %1$s</string>
<string name="upload_files">Upload files</string>
<string name="upload_direct_camera_upload">Upload from camera</string>
<string name="upload_direct_camera_promt">Do you want to take a photo or video?</string>
<string name="upload_direct_camera_photo">Photo</string>
<string name="upload_direct_camera_video">Video</string>
<string name="error_uploading_direct_camera_upload">Failed to upload taken media</string>
<string name="upload_scan_doc_upload">Scan document from camera</string>
<string name="upload_content_from_other_apps">Upload content from other apps</string>
<string name="create_new_folder">New folder</string>
Expand Down

0 comments on commit 5c6ddae

Please sign in to comment.