From 31d5578063037ac687db009ef848e887ffb7a5ae Mon Sep 17 00:00:00 2001 From: Benoit Marty Date: Mon, 17 Feb 2020 14:35:57 +0100 Subject: [PATCH] Media preview: do not propose to edit Gif --- .../preview/AttachmentsPreviewFragment.kt | 12 ++++++++ .../attachments/preview/Extensions.kt | 28 +++++++++++++++++++ 2 files changed, 40 insertions(+) create mode 100644 vector/src/main/java/im/vector/riotx/features/attachments/preview/Extensions.kt diff --git a/vector/src/main/java/im/vector/riotx/features/attachments/preview/AttachmentsPreviewFragment.kt b/vector/src/main/java/im/vector/riotx/features/attachments/preview/AttachmentsPreviewFragment.kt index d05dcc5593..062295f586 100644 --- a/vector/src/main/java/im/vector/riotx/features/attachments/preview/AttachmentsPreviewFragment.kt +++ b/vector/src/main/java/im/vector/riotx/features/attachments/preview/AttachmentsPreviewFragment.kt @@ -23,6 +23,7 @@ import android.content.Intent import android.graphics.Color import android.os.Bundle import android.os.Parcelable +import android.view.Menu import android.view.MenuItem import android.view.View import android.view.ViewGroup @@ -107,6 +108,16 @@ class AttachmentsPreviewFragment @Inject constructor( } } + override fun onPrepareOptionsMenu(menu: Menu) { + withState(viewModel) { state -> + val editMenuItem = menu.findItem(R.id.attachmentsPreviewEditAction) + val showEditMenuItem = state.attachments[state.currentAttachmentIndex].isEditable() + editMenuItem.setVisible(showEditMenuItem) + } + + super.onPrepareOptionsMenu(menu) + } + override fun getMenuRes() = R.menu.vector_attachments_preview override fun onDestroyView() { @@ -116,6 +127,7 @@ class AttachmentsPreviewFragment @Inject constructor( } override fun invalidate() = withState(viewModel) { state -> + requireActivity().invalidateOptionsMenu() if (state.attachments.isEmpty()) { requireActivity().setResult(RESULT_CANCELED) requireActivity().finish() diff --git a/vector/src/main/java/im/vector/riotx/features/attachments/preview/Extensions.kt b/vector/src/main/java/im/vector/riotx/features/attachments/preview/Extensions.kt new file mode 100644 index 0000000000..3bd47baa89 --- /dev/null +++ b/vector/src/main/java/im/vector/riotx/features/attachments/preview/Extensions.kt @@ -0,0 +1,28 @@ +/* + * Copyright (c) 2020 New Vector Ltd + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package im.vector.riotx.features.attachments.preview + +import im.vector.matrix.android.api.session.content.ContentAttachmentData + +/** + * All images are editable, expect Gif + */ +fun ContentAttachmentData.isEditable(): Boolean { + return type == ContentAttachmentData.Type.IMAGE + && mimeType?.startsWith("image/") == true + && mimeType != "image/gif" +}