Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 2 additions & 5 deletions app/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ plugins {

val kotlinVersion: String by rootProject.extra

val androidxCameraVersion = "1.6.1"
val coilKtVersion = "2.7.0"
val daggerVersion = "2.59.2"
val emojiVersion = "1.6.0"
Expand Down Expand Up @@ -232,10 +231,6 @@ dependencies {
implementation("org.conscrypt:conscrypt-android:2.5.3")
implementation("com.github.nextcloud-deps:qrcodescanner:0.1.2.4") // "com.github.blikoon:QRCodeScanner:0.1.2"

implementation("androidx.camera:camera-core:$androidxCameraVersion")
implementation("androidx.camera:camera-camera2:$androidxCameraVersion")
implementation("androidx.camera:camera-lifecycle:$androidxCameraVersion")
implementation("androidx.camera:camera-view:$androidxCameraVersion")
implementation("androidx.exifinterface:exifinterface:1.4.2")

implementation("androidx.lifecycle:lifecycle-runtime-ktx:$lifecycleVersion")
Expand Down Expand Up @@ -302,6 +297,8 @@ dependencies {

implementation("androidx.media3:media3-exoplayer:$media3Version")
implementation("androidx.media3:media3-ui:$media3Version")
implementation("androidx.media3:media3-transformer:$media3Version")
implementation("androidx.media3:media3-effect:$media3Version")

implementation("com.github.chrisbanes:PhotoView:2.3.0")
implementation("pl.droidsonroids.gif:android-gif-drawable:1.2.32")
Expand Down
5 changes: 0 additions & 5 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -225,11 +225,6 @@
android:configChanges="orientation|keyboardHidden|screenSize"
android:theme="@style/FullScreenTextTheme" />

<activity
android:name=".activities.TakePhotoActivity"
android:theme="@style/TakePhotoTheme"
android:windowSoftInputMode="stateHidden" />

<activity
android:name=".shareditems.activities.SharedItemsActivity"
android:theme="@style/AppTheme" />
Expand Down
427 changes: 0 additions & 427 deletions app/src/main/java/com/nextcloud/talk/activities/TakePhotoActivity.java

This file was deleted.

118 changes: 60 additions & 58 deletions app/src/main/java/com/nextcloud/talk/chat/ChatActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,6 @@ import com.nextcloud.talk.BuildConfig
import com.nextcloud.talk.R
import com.nextcloud.talk.activities.BaseActivity
import com.nextcloud.talk.activities.CallActivity
import com.nextcloud.talk.activities.TakePhotoActivity
import com.nextcloud.talk.adapters.messages.CallStartedMessageInterface
import com.nextcloud.talk.api.NcApi
import com.nextcloud.talk.api.NcApiCoroutines
Expand Down Expand Up @@ -390,7 +389,7 @@ class ChatActivity :
private val _participantPermissionsFlow = MutableStateFlow<ParticipantPermissions?>(null)
val participantPermissionsFlow: StateFlow<ParticipantPermissions?> = _participantPermissionsFlow.asStateFlow()

private var videoURI: Uri? = null
private var pendingCameraUri: Uri? = null
private var pendingTargetMessageId: Long? = null
private var pendingTargetThreadId: Long? = null
private var pendingTargetSearchQuery: String? = null
Expand Down Expand Up @@ -2330,19 +2329,12 @@ class ChatActivity :
try {
require(filesToUpload.isNotEmpty())

val filenamesWithLineBreaks = StringBuilder("\n")

for (file in filesToUpload) {
val filename = FileUtils.getFileName(file, context)
filenamesWithLineBreaks.append(filename).append("\n")
}

val newFragment = FileAttachmentPreviewFragment.newInstance(
filenamesWithLineBreaks.toString(),
filesToUpload.map { it.toString() }.toMutableList()
filesToUpload.map { it.toString() }.toMutableList(),
currentConversation?.displayName ?: ""
)
newFragment.setListener { files, caption ->
uploadFiles(files, caption)
newFragment.setListener { files, caption, compressImages ->
uploadFiles(files, caption, compressImages)
}
newFragment.show(supportFragmentManager, FileAttachmentPreviewFragment.TAG)
} catch (e: IllegalStateException) {
Expand Down Expand Up @@ -2410,33 +2402,25 @@ class ChatActivity :
try {
filesToUpload.clear()

if (intent != null && intent.data != null) {
run {
intent.data.let {
filesToUpload.add(intent.data.toString())
}
}
require(filesToUpload.isNotEmpty())
} else if (videoURI != null) {
filesToUpload.add(videoURI.toString())
videoURI = null
// The system camera app is only guaranteed to write to the URI passed via EXTRA_OUTPUT;
// whether it also populates the result intent's data is device/vendor-dependent, so the
// URI we supplied up front is the one source of truth here.
val uri = pendingCameraUri ?: intent?.data
pendingCameraUri = null
if (uri != null) {
filesToUpload.add(uri.toString())
} else {
error("Failed to get data from intent and uri")
}

if (permissionUtil.isFilesPermissionGranted()) {
val filenamesWithLineBreaks = StringBuilder("\n")

for (file in filesToUpload) {
val filename = FileUtils.getFileName(file.toUri(), context)
filenamesWithLineBreaks.append(filename).append("\n")
}

val newFragment = FileAttachmentPreviewFragment.newInstance(
filenamesWithLineBreaks.toString(),
filesToUpload
filesToUpload,
currentConversation?.displayName ?: ""
)
newFragment.setListener { files, caption -> uploadFiles(files, caption) }
newFragment.setListener { files, caption, compressImages ->
uploadFiles(files, caption, compressImages)
}
newFragment.show(supportFragmentManager, FileAttachmentPreviewFragment.TAG)
} else {
UploadAndShareFilesWorker.requestStoragePermission(this)
Expand Down Expand Up @@ -2544,27 +2528,17 @@ class ChatActivity :
}
}

private fun uploadFiles(files: MutableList<String>, caption: String = "") {
private fun uploadFiles(files: MutableList<String>, caption: String = "", compressImages: Boolean = false) {
for (i in 0 until files.size) {
if (i == files.size - 1) {
uploadFile(
fileUri = files[i],
isVoiceMessage = false,
caption = caption,
roomToken = roomToken,
replyToMessageId = getReplyToMessageId(),
displayName = currentConversation?.displayName!!
)
} else {
uploadFile(
fileUri = files[i],
isVoiceMessage = false,
caption = "",
roomToken = roomToken,
replyToMessageId = getReplyToMessageId(),
displayName = currentConversation?.displayName!!
)
}
uploadFile(
fileUri = files[i],
isVoiceMessage = false,
caption = if (i == files.size - 1) caption else "",
roomToken = roomToken,
replyToMessageId = getReplyToMessageId(),
displayName = currentConversation?.displayName!!,
compressImages = compressImages
)
}
}

Expand Down Expand Up @@ -3824,7 +3798,31 @@ class ChatActivity :
if (!permissionUtil.isCameraPermissionGranted()) {
requestCameraPermissions()
} else {
startPickCameraIntentForResult.launch(TakePhotoActivity.createIntent(context))
Intent(MediaStore.ACTION_IMAGE_CAPTURE).also { takePictureIntent ->
takePictureIntent.resolveActivity(packageManager)?.also {
val photoFile: File? = try {
val outputDir = FileUtils.getSharedAttachmentsDirectory(context.cacheDir)
?: throw IOException("Could not create shared attachments directory")
val dateFormat = SimpleDateFormat(FILE_DATE_PATTERN, Locale.ROOT)
val date = dateFormat.format(Date())
val photoName = String.format(
context.resources.getString(R.string.nc_picture_filename),
date
)
File(outputDir, "$photoName$PICTURE_SUFFIX")
} catch (e: IOException) {
Snackbar.make(binding.root, R.string.nc_common_error_sorry, Snackbar.LENGTH_LONG).show()
Log.e(TAG, "error while creating photo file", e)
null
}

photoFile?.also {
pendingCameraUri = FileProvider.getUriForFile(context, context.packageName, it)
takePictureIntent.putExtra(MediaStore.EXTRA_OUTPUT, pendingCameraUri)
startPickCameraIntentForResult.launch(takePictureIntent)
}
}
}
}
}

Expand All @@ -3851,8 +3849,8 @@ class ChatActivity :
}

videoFile?.also {
videoURI = FileProvider.getUriForFile(context, context.packageName, it)
takeVideoIntent.putExtra(MediaStore.EXTRA_OUTPUT, videoURI)
pendingCameraUri = FileProvider.getUriForFile(context, context.packageName, it)
takeVideoIntent.putExtra(MediaStore.EXTRA_OUTPUT, pendingCameraUri)
startPickCameraIntentForResult.launch(takeVideoIntent)
}
}
Expand Down Expand Up @@ -3944,21 +3942,24 @@ class ChatActivity :
)
}

@Suppress("LongParameterList")
fun uploadFile(
fileUri: String,
isVoiceMessage: Boolean,
caption: String = "",
roomToken: String = "",
replyToMessageId: Int? = null,
displayName: String
displayName: String,
compressImages: Boolean = false
) {
chatViewModel.uploadFile(
fileUri,
isVoiceMessage,
caption,
roomToken,
replyToMessageId,
displayName
displayName,
compressImages
)
cancelReply()
}
Expand Down Expand Up @@ -3996,6 +3997,7 @@ class ChatActivity :
private const val REQUEST_CAMERA_PERMISSION = 223
private const val FILE_DATE_PATTERN = "yyyy-MM-dd HH-mm-ss"
private const val VIDEO_SUFFIX = ".mp4"
private const val PICTURE_SUFFIX = ".jpg"
private const val VOICE_MESSAGE_SEEKBAR_BASE = 1000
private const val HTTP_BAD_REQUEST = 400
private const val HTTP_FORBIDDEN = 403
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1972,7 +1972,8 @@ class ChatViewModel @AssistedInject constructor(
caption: String = "",
roomToken: String = "",
replyToMessageId: Int? = null,
displayName: String
displayName: String,
compressImages: Boolean = false
) {
val metaDataMap = mutableMapOf<String, Any>()
var room = ""
Expand Down Expand Up @@ -2004,7 +2005,8 @@ class ChatViewModel @AssistedInject constructor(
fileUri,
room,
displayName,
metaData
metaData,
compressImages
)
} catch (e: IllegalArgumentException) {
Log.e(javaClass.simpleName, "Something went wrong when trying to upload file", e)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ fun ConversationCreationScreen(
contract = ActivityResultContracts.StartActivityForResult()
) { result ->
if (result.resultCode == Activity.RESULT_OK) {
pickImage?.onTakePictureResult(imagePickerLauncher, result.data)
pickImage?.onTakePictureResult(imagePickerLauncher)
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,8 @@ class ConversationInfoEditActivity : BaseActivity() {
private val startTakePictureIntentForResult = registerForActivityResult(
ActivityResultContracts.StartActivityForResult()
) {
handleResult(it) { result ->
pickImage?.onTakePictureResult(startImagePickerForResult, result.data)
handleResult(it) {
pickImage?.onTakePictureResult(startImagePickerForResult)
}
}

Expand Down
Loading
Loading