From 40a77118bff1c0f5d0a3132c7921bbef31fb5c92 Mon Sep 17 00:00:00 2001 From: Naveen Date: Mon, 7 Nov 2022 03:24:53 +0530 Subject: [PATCH] Add "Choose video" button --- .../smsmessenger/activities/ThreadActivity.kt | 57 +++++++++++-------- .../smsmessenger/helpers/Constants.kt | 3 +- .../res/drawable/ic_video_camera_vector.xml | 3 + .../res/layout/layout_attachment_picker.xml | 38 ++++++++++++- 4 files changed, 73 insertions(+), 28 deletions(-) create mode 100644 app/src/main/res/drawable/ic_video_camera_vector.xml diff --git a/app/src/main/kotlin/com/simplemobiletools/smsmessenger/activities/ThreadActivity.kt b/app/src/main/kotlin/com/simplemobiletools/smsmessenger/activities/ThreadActivity.kt index afb0317d..fac7604e 100644 --- a/app/src/main/kotlin/com/simplemobiletools/smsmessenger/activities/ThreadActivity.kt +++ b/app/src/main/kotlin/com/simplemobiletools/smsmessenger/activities/ThreadActivity.kt @@ -221,7 +221,7 @@ class ThreadActivity : SimpleActivity() { addAttachment(capturedImageUri!!) } else if (data != null) { when (requestCode) { - CAPTURE_VIDEO_INTENT, PICK_DOCUMENT_INTENT, CAPTURE_AUDIO_INTENT, PICK_PHOTO_VIDEO_INTENT -> addAttachment(data) + CAPTURE_VIDEO_INTENT, PICK_DOCUMENT_INTENT, CAPTURE_AUDIO_INTENT, PICK_PHOTO_INTENT, PICK_VIDEO_INTENT -> addAttachment(data) PICK_CONTACT_INTENT -> addContactAttachment(data) PICK_SAVE_FILE_INTENT -> saveAttachment(resultData) } @@ -828,23 +828,12 @@ class ThreadActivity : SimpleActivity() { launchActivityForResult(intent, CAPTURE_AUDIO_INTENT) } - private fun launchPickPhotoVideoIntent() { - val mimeTypes = arrayOf("image/*", "video/*") + private fun launchGetContentIntent(mimeTypes: Array, requestCode: Int) { Intent(Intent.ACTION_GET_CONTENT).apply { addCategory(Intent.CATEGORY_OPENABLE) type = "*/*" putExtra(Intent.EXTRA_MIME_TYPES, mimeTypes) - launchActivityForResult(this, PICK_PHOTO_VIDEO_INTENT) - } - } - - private fun launchPickDocumentIntent() { - val mimeTypes = arrayOf("*/*") - Intent(Intent.ACTION_GET_CONTENT).apply { - addCategory(Intent.CATEGORY_OPENABLE) - type = "*/*" - putExtra(Intent.EXTRA_MIME_TYPES, mimeTypes) - launchActivityForResult(this, PICK_DOCUMENT_INTENT) + launchActivityForResult(this, requestCode) } } @@ -1361,6 +1350,7 @@ class ThreadActivity : SimpleActivity() { private fun setupAttachmentPickerView() { val buttonColors = arrayOf( R.color.md_red_500, + R.color.md_brown_500, R.color.md_pink_500, R.color.md_purple_500, R.color.md_teal_500, @@ -1368,19 +1358,38 @@ class ThreadActivity : SimpleActivity() { R.color.md_indigo_500, R.color.md_blue_500 ).map { ResourcesCompat.getColor(resources, it, theme) } - arrayOf(choose_photo_icon, take_photo_icon, record_video_icon, record_audio_icon, pick_file_icon, pick_contact_icon, schedule_message_icon) - .forEachIndexed { index, icon -> - val iconColor = buttonColors[index] - icon.background.applyColorFilter(iconColor) - icon.applyColorFilter(iconColor.getContrastColor()) - } + arrayOf( + choose_photo_icon, + choose_video_icon, + take_photo_icon, + record_video_icon, + record_audio_icon, + pick_file_icon, + pick_contact_icon, + schedule_message_icon + ).forEachIndexed { index, icon -> + val iconColor = buttonColors[index] + icon.background.applyColorFilter(iconColor) + icon.applyColorFilter(iconColor.getContrastColor()) + } val textColor = getProperTextColor() - arrayOf(choose_photo_text, take_photo_text, record_video_text, record_audio_text, pick_file_text, pick_contact_text, schedule_message_text) - .forEach { it.setTextColor(textColor) } + arrayOf( + choose_photo_text, + choose_video_text, + take_photo_text, + record_video_text, + record_audio_text, + pick_file_text, + pick_contact_text, + schedule_message_text + ).forEach { it.setTextColor(textColor) } choose_photo.setOnClickListener { - launchPickPhotoVideoIntent() + launchGetContentIntent(arrayOf("image/*"), PICK_PHOTO_INTENT) + } + choose_video.setOnClickListener { + launchGetContentIntent(arrayOf("video/*"), PICK_VIDEO_INTENT) } take_photo.setOnClickListener { launchCapturePhotoIntent() @@ -1392,7 +1401,7 @@ class ThreadActivity : SimpleActivity() { launchCaptureAudioIntent() } pick_file.setOnClickListener { - launchPickDocumentIntent() + launchGetContentIntent(arrayOf("*/*"), PICK_DOCUMENT_INTENT) } pick_contact.setOnClickListener { launchPickContactIntent() diff --git a/app/src/main/kotlin/com/simplemobiletools/smsmessenger/helpers/Constants.kt b/app/src/main/kotlin/com/simplemobiletools/smsmessenger/helpers/Constants.kt index 2e96f376..bf8f2761 100644 --- a/app/src/main/kotlin/com/simplemobiletools/smsmessenger/helpers/Constants.kt +++ b/app/src/main/kotlin/com/simplemobiletools/smsmessenger/helpers/Constants.kt @@ -67,7 +67,8 @@ const val FILE_SIZE_2_MB = 2_097_152L const val MESSAGES_LIMIT = 50 // intent launch request codes -const val PICK_PHOTO_VIDEO_INTENT = 42 +const val PICK_PHOTO_INTENT = 42 +const val PICK_VIDEO_INTENT = 49 const val PICK_SAVE_FILE_INTENT = 43 const val CAPTURE_PHOTO_INTENT = 44 const val CAPTURE_VIDEO_INTENT = 45 diff --git a/app/src/main/res/drawable/ic_video_camera_vector.xml b/app/src/main/res/drawable/ic_video_camera_vector.xml new file mode 100644 index 00000000..872944c0 --- /dev/null +++ b/app/src/main/res/drawable/ic_video_camera_vector.xml @@ -0,0 +1,3 @@ + + + diff --git a/app/src/main/res/layout/layout_attachment_picker.xml b/app/src/main/res/layout/layout_attachment_picker.xml index c2d5b1a3..54b7328d 100644 --- a/app/src/main/res/layout/layout_attachment_picker.xml +++ b/app/src/main/res/layout/layout_attachment_picker.xml @@ -8,7 +8,7 @@ + + + + + + + @@ -203,7 +235,7 @@ android:layout_height="wrap_content" android:layout_gravity="center" android:layout_marginTop="@dimen/medium_margin" - android:text="@string/contacts_short" + android:text="@string/choose_contact" android:textAlignment="center" android:textColor="@color/default_text_color" android:textSize="@dimen/normal_text_size" />