android: revert to using gallery for images and videos (#2209)

* core: revert to using gallery for images and videos

* remove comment
This commit is contained in:
Evgeny Poberezkin
2023-04-19 12:07:14 +02:00
committed by GitHub
parent 37f835be8c
commit 2caff25fa2
15 changed files with 77 additions and 35 deletions

View File

@@ -14,6 +14,7 @@ import android.os.Build
import android.provider.MediaStore
import android.webkit.MimeTypeMap
import android.widget.Toast
import androidx.activity.compose.rememberLauncherForActivityResult
import androidx.activity.result.contract.ActivityResultContract
import androidx.compose.foundation.layout.*
import androidx.compose.foundation.shape.CircleShape
@@ -260,13 +261,17 @@ fun ComposeView(
}
}
}
val mediaLauncherWithFiles = rememberGetMultipleContentsLauncher { processPickedMedia(it, null) }
val galleryImageLauncher = rememberLauncherForActivityResult(contract = PickMultipleImagesFromGallery()) { processPickedMedia(it, null) }
val galleryImageLauncherFallback = rememberGetMultipleContentsLauncher { processPickedMedia(it, null) }
val galleryVideoLauncher = rememberLauncherForActivityResult(contract = PickMultipleVideosFromGallery()) { processPickedMedia(it, null) }
val galleryVideoLauncherFallback = rememberGetMultipleContentsLauncher { processPickedMedia(it, null) }
val filesLauncher = rememberGetContentLauncher { processPickedFile(it, null) }
val recState: MutableState<RecordingState> = remember { mutableStateOf(RecordingState.NotStarted) }
LaunchedEffect(attachmentOption.value) {
when (attachmentOption.value) {
AttachmentOption.TakePhoto -> {
AttachmentOption.CameraPhoto -> {
when (PackageManager.PERMISSION_GRANTED) {
ContextCompat.checkSelfPermission(context, Manifest.permission.CAMERA) -> {
cameraLauncher.launchWithFallback()
@@ -277,11 +282,23 @@ fun ComposeView(
}
attachmentOption.value = null
}
AttachmentOption.PickMedia -> {
mediaLauncherWithFiles.launch("image/*;video/*")
AttachmentOption.GalleryImage -> {
try {
galleryImageLauncher.launch(0)
} catch (e: ActivityNotFoundException) {
galleryImageLauncherFallback.launch("image/*")
}
attachmentOption.value = null
}
AttachmentOption.PickFile -> {
AttachmentOption.GalleryVideo -> {
try {
galleryVideoLauncher.launch(0)
} catch (e: ActivityNotFoundException) {
galleryVideoLauncherFallback.launch("video/*")
}
attachmentOption.value = null
}
AttachmentOption.File -> {
filesLauncher.launch("*/*")
attachmentOption.value = null
}

View File

@@ -13,9 +13,10 @@ import chat.simplex.app.R
import chat.simplex.app.views.newchat.ActionButton
sealed class AttachmentOption {
object TakePhoto: AttachmentOption()
object PickMedia: AttachmentOption()
object PickFile: AttachmentOption()
object CameraPhoto: AttachmentOption()
object GalleryImage: AttachmentOption()
object GalleryVideo: AttachmentOption()
object File: AttachmentOption()
}
@Composable
@@ -38,15 +39,19 @@ fun ChooseAttachmentView(
horizontalArrangement = Arrangement.SpaceEvenly
) {
ActionButton(null, stringResource(R.string.use_camera_button), icon = Icons.Outlined.PhotoCamera) {
attachmentOption.value = AttachmentOption.TakePhoto
attachmentOption.value = AttachmentOption.CameraPhoto
hide()
}
ActionButton(null, stringResource(R.string.from_gallery_button), icon = Icons.Outlined.Collections) {
attachmentOption.value = AttachmentOption.PickMedia
ActionButton(null, stringResource(R.string.gallery_image_button), icon = Icons.Outlined.Image) {
attachmentOption.value = AttachmentOption.GalleryImage
hide()
}
ActionButton(null, stringResource(R.string.gallery_video_button), icon = Icons.Outlined.SmartDisplay) {
attachmentOption.value = AttachmentOption.GalleryVideo
hide()
}
ActionButton(null, stringResource(R.string.choose_file), icon = Icons.Outlined.InsertDriveFile) {
attachmentOption.value = AttachmentOption.PickFile
attachmentOption.value = AttachmentOption.File
hide()
}
}

View File

@@ -18,8 +18,7 @@ import androidx.activity.result.contract.ActivityResultContracts
import androidx.annotation.CallSuper
import androidx.compose.foundation.layout.*
import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.outlined.Collections
import androidx.compose.material.icons.outlined.PhotoCamera
import androidx.compose.material.icons.outlined.*
import androidx.compose.runtime.*
import androidx.compose.runtime.saveable.Saver
import androidx.compose.runtime.saveable.rememberSaveable
@@ -259,7 +258,7 @@ fun GetImageBottomSheet(
}
}
}
ActionButton(null, stringResource(R.string.from_gallery_button), icon = Icons.Outlined.Collections) {
ActionButton(null, stringResource(R.string.from_gallery_button), icon = Icons.Outlined.Image) {
try {
galleryLauncher.launch(0)
} catch (e: ActivityNotFoundException) {

View File

@@ -186,9 +186,11 @@
<string name="to_share_with_your_contact">(sdílet s kontaktem)</string>
<string name="only_stored_on_members_devices">(uloženo pouze členy skupiny)</string>
<string name="toast_permission_denied">Oprávnění zamítnuto!</string>
<string name="use_camera_button">Použít fotoaparát</string>
<string name="use_camera_button">Fotoaparát</string>
<string name="from_gallery_button">Z Galerie</string>
<string name="choose_file">Vybrat soubor</string>
<string name="choose_file">Soubor</string>
<string name="gallery_image_button">Obrázek</string>
<string name="gallery_video_button">Video</string>
<string name="to_start_a_new_chat_help_header">Pro zahájení nové konverzace</string>
<string name="chat_help_tap_button">Klepněte na tlačítko</string>
<string name="above_then_preposition_continuation">potom:</string>

View File

@@ -254,9 +254,11 @@
<string name="only_stored_on_members_devices">(Wird nur von Gruppenmitgliedern gespeichert)</string>
<!-- GetImageView -->
<string name="toast_permission_denied">Berechtigung verweigert!</string>
<string name="use_camera_button">Kamera\nverwenden</string>
<string name="use_camera_button">Kamera</string>
<string name="from_gallery_button">Aus dem\nFotoalbum</string>
<string name="choose_file">Datei\nauswählen</string>
<string name="choose_file">Datei</string>
<string name="gallery_image_button">Bild</string>
<string name="gallery_video_button">Video</string>
<!-- help - ChatHelpView.kt -->
<string name="thank_you_for_installing_simplex">Danke, dass Sie <xliff:g id="appNameFull">SimpleX Chat</xliff:g> installiert haben!</string>
<string name="you_can_connect_to_simplex_chat_founder">Sie können sich <font color="#0088ff">mit <xliff:g id="appNameFull">SimpleX Chat</xliff:g> Entwicklern verbinden, um Fragen zu stellen und Updates zu erhalten</font>.</string>

View File

@@ -263,7 +263,7 @@
<string name="clear_contacts_selection_button">Limpiar</string>
<string name="change_member_role_question">¿Cambiar rol de grupo\?</string>
<string name="v4_4_verify_connection_security_desc">Compara los códigos de seguridad con tus contactos</string>
<string name="choose_file">Elije archivo</string>
<string name="choose_file">Archivo</string>
<string name="clear_verb">Limpiar</string>
<string name="clear_chat_button">Limpiar chat</string>
<string name="configure_ICE_servers">Configurar servidores ICE</string>
@@ -359,6 +359,8 @@
<string name="error_saving_file">Error al guardar archivo</string>
<string name="icon_descr_server_status_error">Error</string>
<string name="from_gallery_button">De la Galería</string>
<string name="gallery_image_button">Imagen</string>
<string name="gallery_video_button">Video</string>
<string name="if_you_received_simplex_invitation_link_you_can_open_in_browser">Si has recibido el enlace de invitación a <xliff:g id="appName">SimpleX Chat</xliff:g>, puedes abrirlo en tu navegador:</string>
<string name="if_you_choose_to_reject_the_sender_will_not_be_notified">Si eliges rechazar, el remitente NO será notificado.</string>
<string name="invalid_contact_link">¡Enlace no válido!</string>
@@ -748,7 +750,7 @@
<string name="icon_descr_received_msg_status_unread">no leído</string>
<string name="text_field_set_contact_placeholder">Escribe un nombre para el contacto…</string>
<string name="switch_receiving_address_question">¿Cambiar dirección de recepción\?</string>
<string name="use_camera_button">Usar cámara</string>
<string name="use_camera_button">Cámara</string>
<string name="contact_you_shared_link_with_wont_be_able_to_connect">¡El contacto con el que has compartido este enlace NO podrá conectarse!</string>
<string name="show_QR_code">Mostrar código QR</string>
<string name="this_link_is_not_a_valid_connection_link">¡El enlace no es un enlace de conexión válido!</string>

View File

@@ -201,7 +201,9 @@
<string name="to_share_with_your_contact">(à partager avec votre contact)</string>
<string name="create_group">Créer un groupe secret</string>
<string name="from_gallery_button">Depuis la Phototèque</string>
<string name="choose_file">Choisir le fichier</string>
<string name="choose_file">Fichier</string>
<string name="gallery_image_button">Image</string>
<string name="gallery_video_button">Vidéo</string>
<string name="to_start_a_new_chat_help_header">Pour démarrer une nouvelle discussion</string>
<string name="chat_help_tap_button">Appuyez sur le bouton</string>
<string name="scan_QR_code_to_connect_to_contact_who_shows_QR_code"><b>Scanner un code QR</b> : pour vous connecter à votre contact qui vous montre un code QR.</string>
@@ -294,7 +296,7 @@
<string name="waiting_for_file">En attente du fichier</string>
<string name="voice_message">Message vocal</string>
<string name="toast_permission_denied">Autorisation refusée !</string>
<string name="use_camera_button">Utiliser l\'Appareil photo</string>
<string name="use_camera_button">Appareil\nphoto</string>
<string name="thank_you_for_installing_simplex">Merci d\'avoir installé <xliff:g id="appNameFull">SimpleX Chat</xliff:g> !</string>
<string name="you_can_connect_to_simplex_chat_founder">Vous pouvez <font color="#0088ff">vous connecter aux développeurs de <xliff:g id="appNameFull">SimpleX Chat</xliff:g> pour leur poser des questions et recevoir des réponses :</font>.</string>
<string name="above_then_preposition_continuation">ci-dessus, puis :</string>

View File

@@ -298,7 +298,7 @@
<string name="display_name">Nome da mostrare</string>
<string name="add_new_contact_to_create_one_time_QR_code"><b>Aggiungi un contatto</b>: per creare il tuo codice QR una tantum per il tuo contatto.</string>
<string name="scan_QR_code_to_connect_to_contact_who_shows_QR_code"><b>Scansiona codice QR</b>: per connetterti al contatto che ti mostra il codice QR.</string>
<string name="choose_file">Scegli file</string>
<string name="choose_file">File</string>
<string name="clear_chat_button">Svuota chat</string>
<string name="clear_chat_question">Svuotare la chat\?</string>
<string name="clear_verb">Svuota</string>
@@ -308,6 +308,8 @@
<string name="create_group">Crea gruppo segreto</string>
<string name="desktop_scan_QR_code_from_app_via_scan_QR_code">💻 desktop: scansiona dall\'app il codice QR mostrato, tramite <b>Scansiona codice QR</b>.</string>
<string name="from_gallery_button">Dalla Galleria</string>
<string name="gallery_image_button">Immagine</string>
<string name="gallery_video_button">Video</string>
<string name="if_you_choose_to_reject_the_sender_will_not_be_notified">Se scegli di rifiutare, il mittente NON verrà avvisato.</string>
<string name="clear_chat_menu_action">Svuota</string>
<string name="icon_descr_close_button">Pulsante di chiusura</string>
@@ -545,7 +547,7 @@
<string name="to_connect_via_link_title">Per connettersi via link</string>
<string name="to_share_with_your_contact">(da condividere con il tuo contatto)</string>
<string name="to_start_a_new_chat_help_header">Per iniziare una nuova chat</string>
<string name="use_camera_button">Usa la fotocamera</string>
<string name="use_camera_button">Fotocamera</string>
<string name="you_can_connect_to_simplex_chat_founder">Puoi <font color="#0088ff">connetterti con gli sviluppatori di <xliff:g id="appNameFull">SimpleX Chat</xliff:g> per porre domande e ricevere aggiornamenti</font>.</string>
<string name="invalid_contact_link">Link non valido!</string>
<string name="invalid_QR_code">Codice QR non valido</string>

View File

@@ -385,6 +385,8 @@
<string name="file_not_found">Bestand niet gevonden</string>
<string name="file_saved">Bestand opgeslagen</string>
<string name="from_gallery_button">Galerij</string>
<string name="gallery_image_button">Foto</string>
<string name="gallery_video_button">Video</string>
<string name="error_saving_ICE_servers">Fout bij opslaan van ICE servers</string>
<string name="callstate_ended">geëindigd</string>
<string name="group_members_can_send_disappearing">Groepsleden kunnen verdwijnende berichten sturen.</string>

View File

@@ -224,9 +224,9 @@
<string name="scan_QR_code">Zeskanuj kod QR</string>
<string name="add_contact_or_create_group">Rozpocznij nowy czat</string>
<string name="to_share_with_your_contact">(aby udostępnić Twojemu kontaktowi)</string>
<string name="choose_file">Wybierz plik</string>
<string name="choose_file">Plik</string>
<string name="toast_permission_denied">Odmowa Uprawnienia!</string>
<string name="use_camera_button">Użyj Aparatu</string>
<string name="use_camera_button">Aparatu</string>
<string name="accept_contact_button">Akceptuj</string>
<string name="accept_contact_incognito_button">Akceptuj incognito</string>
<string name="clear_chat_warning">Wszystkie wiadomości zostaną usunięte - nie można tego cofnąć! Wiadomości zostaną usunięte TYLKO dla Ciebie.</string>
@@ -968,6 +968,8 @@
\n- usuwać wiadomości członków.
\n- wyłączyć członków (rola \"obserwatora\")</string>
<string name="from_gallery_button">Z Galerii</string>
<string name="gallery_image_button">Obraz</string>
<string name="gallery_video_button">Wideo</string>
<string name="feature_offered_item_with_param">zaproponował %s: %2s</string>
<string name="only_group_owners_can_enable_voice">Tylko właściciele grup mogą włączyć wiadomości głosowe.</string>
<string name="network_use_onion_hosts_no_desc_in_alert">Hosty onion nie będą używane.</string>

View File

@@ -24,7 +24,7 @@
<string name="icon_descr_asked_to_receive">Pediu para receber a imagem</string>
<string name="icon_descr_cancel_live_message">Cancelar mensagem ao vivo</string>
<string name="back">Voltar</string>
<string name="choose_file">Selecione o arquivo</string>
<string name="choose_file">Arquivo</string>
<string name="add_new_contact_to_create_one_time_QR_code"><b>Adicionar novo contato</b>: para criar seu QR code de uso único para seu contato.</string>
<string name="scan_QR_code_to_connect_to_contact_who_shows_QR_code"><b>Escanear código QR</b>: para se conectar ao seu contato que mostra o código QR para você.</string>
<string name="accept_contact_button">Aceitar</string>
@@ -352,6 +352,7 @@
<string name="description_via_one_time_link_incognito">anônimo via link único</string>
<string name="hide_verb">Ocultar</string>
<string name="from_gallery_button">Da Galeria</string>
<string name="gallery_video_button">Vídeo</string>
<string name="group_members_can_send_disappearing">Os membros do grupo podem enviar mensagens que desaparecem.</string>
<string name="icon_descr_file">Arquivo</string>
<string name="full_name__field">Nome completo:</string>
@@ -499,7 +500,7 @@
<string name="save_color">Salvar cor</string>
<string name="v4_5_italian_interface">interface italiana</string>
<string name="periodic_notifications">Notificações periódicas</string>
<string name="use_camera_button">Usar câmera</string>
<string name="use_camera_button">Câmera</string>
<string name="your_ICE_servers">Seus servidores ICE</string>
<string name="your_ice_servers">Seus servidores ICE</string>
<string name="your_privacy">Sua privacidade</string>

View File

@@ -258,7 +258,9 @@
<string name="toast_permission_denied">Разрешение не получено!</string>
<string name="use_camera_button">Камера</string>
<string name="from_gallery_button">Галерея</string>
<string name="choose_file">Файлы</string>
<string name="gallery_image_button">Изображение</string>
<string name="gallery_video_button">Видео</string>
<string name="choose_file">Файл</string>
<!-- help - ChatHelpView.kt -->
<string name="thank_you_for_installing_simplex">Спасибо, что установили <xliff:g id="appNameFull">SimpleX Chat</xliff:g>!</string>
<string name="you_can_connect_to_simplex_chat_founder">Вы можете <font color="#0088ff">соединиться с разработчиками</font>, чтобы задать любые вопросы или получать уведомления о новых версиях.</string>

View File

@@ -238,7 +238,7 @@
<string name="callstate_connected">已连接</string>
<string name="connect_button">连接</string>
<string name="connect_via_link_verb">连接</string>
<string name="choose_file">选择文件</string>
<string name="choose_file">文件</string>
<string name="network_session_mode_user">聊天资料</string>
<string name="v4_5_transport_isolation_descr">按聊天资料默认或按连接BETA</string>
<string name="smp_servers_check_address">检查服务器地址并再试一次。</string>
@@ -435,6 +435,8 @@
<string name="maximum_supported_file_size">目前支持的最大文件尺寸是 <xliff:g id="maxFileSize">%1$s</xliff:g></string>
<string name="file_will_be_received_when_contact_is_online">文件将在您的联系人在线时收到,请稍等或稍后再查看!</string>
<string name="from_gallery_button">从图库</string>
<string name="gallery_image_button">照片</string>
<string name="gallery_video_button">视频</string>
<string name="exit_without_saving">退出而不保存</string>
<string name="icon_descr_flip_camera">翻转相机</string>
<string name="enable_automatic_deletion_question">启用自动删除消息?</string>
@@ -855,7 +857,7 @@
<string name="toast_permission_denied">权限被拒绝!</string>
<string name="chat_help_tap_button">点击按钮</string>
<string name="thank_you_for_installing_simplex">感谢您安装 <xliff:g id="appNameFull">SimpleX Chat</xliff:g></string>
<string name="use_camera_button">使用相机</string>
<string name="use_camera_button">相机</string>
<string name="smp_servers_preset_address">预设服务器地址</string>
<string name="smp_servers_scan_qr">扫描服务器二维码</string>
<string name="smp_servers_test_failed">服务器测试失败!</string>

View File

@@ -52,7 +52,7 @@
<string name="add_new_contact_to_create_one_time_QR_code"><b>新增新的聯絡人</b>:新增新的聯絡人可以使用二維碼建立你的一次性二維碼。</string>
<string name="scan_QR_code_to_connect_to_contact_who_shows_QR_code"><b>掃描二維碼</b>:連接到向你出示二維碼的聯絡人。</string>
<string name="choose_file">選擇檔案</string>
<string name="use_camera_button">使用相機</string>
<string name="use_camera_button">相機</string>
<string name="from_gallery_button">從圖片庫選擇圖片</string>
<string name="accept_contact_incognito_button">接受匿名聊天模式</string>
<string name="clear_chat_warning">所有訊息記錄會刪除 - 這不能還原!這些訊息只會在你裝置中刪除。</string>

View File

@@ -360,9 +360,11 @@
<!-- GetImageView -->
<string name="toast_permission_denied">Permission Denied!</string>
<string name="use_camera_button">Use Camera</string>
<string name="use_camera_button">Camera</string>
<string name="from_gallery_button">From Gallery</string>
<string name="choose_file">Choose file</string>
<string name="choose_file">File</string>
<string name="gallery_image_button">Image</string>
<string name="gallery_video_button">Video</string>
<!-- help - ChatHelpView.kt -->
<string name="thank_you_for_installing_simplex">Thank you for installing <xliff:g id="appNameFull">SimpleX Chat</xliff:g>!</string>