diff --git a/build.gradle b/build.gradle
index a2fac55175..7f80eaf5fe 100644
--- a/build.gradle
+++ b/build.gradle
@@ -34,6 +34,8 @@ allprojects {
includeGroupByRegex "com\\.github\\.jaiselrahman"
// And monarchy
includeGroupByRegex "com\\.github\\.Zhuinden"
+ // And ucrop
+ includeGroupByRegex "com\\.github\\.yalantis"
}
}
maven {
diff --git a/vector/build.gradle b/vector/build.gradle
index 0517482904..7352adc712 100644
--- a/vector/build.gradle
+++ b/vector/build.gradle
@@ -341,6 +341,7 @@ dependencies {
implementation "com.github.bumptech.glide:glide:$glide_version"
kapt "com.github.bumptech.glide:compiler:$glide_version"
implementation 'com.danikula:videocache:2.7.1'
+ implementation 'com.github.yalantis:ucrop:2.2.4'
// Badge for compatibility
implementation 'me.leolin:ShortcutBadger:1.1.22@aar'
diff --git a/vector/src/main/AndroidManifest.xml b/vector/src/main/AndroidManifest.xml
index 3207ab257a..f908880e6f 100644
--- a/vector/src/main/AndroidManifest.xml
+++ b/vector/src/main/AndroidManifest.xml
@@ -134,6 +134,11 @@
+
+
+
() {
+
+ override fun buildModels(data: AttachmentsPreviewViewState) {
+ data.attachments.forEach {
+
+ }
+ }
+}
diff --git a/vector/src/main/java/im/vector/riotx/features/attachments/preview/AttachmentPreviewItem.kt b/vector/src/main/java/im/vector/riotx/features/attachments/preview/AttachmentPreviewItem.kt
new file mode 100644
index 0000000000..03ac160d62
--- /dev/null
+++ b/vector/src/main/java/im/vector/riotx/features/attachments/preview/AttachmentPreviewItem.kt
@@ -0,0 +1,58 @@
+/*
+ * Copyright 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 android.view.View
+import android.widget.ImageView
+import com.airbnb.epoxy.EpoxyAttribute
+import com.airbnb.epoxy.EpoxyModelClass
+import com.bumptech.glide.Glide
+import com.bumptech.glide.request.RequestOptions
+import im.vector.matrix.android.api.session.content.ContentAttachmentData
+import im.vector.riotx.R
+import im.vector.riotx.core.epoxy.VectorEpoxyHolder
+import im.vector.riotx.core.epoxy.VectorEpoxyModel
+import kotlinx.android.synthetic.main.item_attachment_preview.view.*
+
+@EpoxyModelClass(layout = R.layout.item_attachment_preview)
+abstract class AttachmentPreviewItem : VectorEpoxyModel() {
+
+ @EpoxyAttribute lateinit var attachment: ContentAttachmentData
+ @EpoxyAttribute var clickListener: View.OnClickListener? = null
+
+ override fun bind(holder: Holder) {
+ holder.view.setOnClickListener(clickListener)
+ // If name is empty, use userId as name and force it being centered
+ val mimeType = attachment.mimeType
+ val path = attachment.path
+ if (mimeType != null && (mimeType.startsWith("image") || mimeType.startsWith("video"))) {
+ Glide.with(holder.view.context)
+ .asBitmap()
+ .load(path)
+ .apply(RequestOptions().frame(0))
+ .into(holder.imageView)
+ } else {
+ holder.imageView.attachmentPreviewImageView.setImageResource(R.drawable.filetype_attachment)
+ holder.imageView.attachmentPreviewImageView.scaleType = ImageView.ScaleType.FIT_CENTER
+ }
+ }
+
+ class Holder : VectorEpoxyHolder() {
+ val imageView by bind(R.id.attachmentPreviewImageView)
+ }
+}
diff --git a/vector/src/main/java/im/vector/riotx/features/attachments/preview/AttachmentsPreviewAction.kt b/vector/src/main/java/im/vector/riotx/features/attachments/preview/AttachmentsPreviewAction.kt
new file mode 100644
index 0000000000..61fb41a774
--- /dev/null
+++ b/vector/src/main/java/im/vector/riotx/features/attachments/preview/AttachmentsPreviewAction.kt
@@ -0,0 +1,22 @@
+/*
+ * Copyright 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.riotx.core.platform.VectorViewModelAction
+
+sealed class AttachmentsPreviewAction : VectorViewModelAction
diff --git a/vector/src/main/java/im/vector/riotx/features/attachments/preview/AttachmentsPreviewActivity.kt b/vector/src/main/java/im/vector/riotx/features/attachments/preview/AttachmentsPreviewActivity.kt
new file mode 100644
index 0000000000..509be251c3
--- /dev/null
+++ b/vector/src/main/java/im/vector/riotx/features/attachments/preview/AttachmentsPreviewActivity.kt
@@ -0,0 +1,54 @@
+/*
+ * Copyright 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 android.content.Context
+import android.content.Intent
+import androidx.appcompat.widget.Toolbar
+import im.vector.riotx.R
+import im.vector.riotx.core.extensions.addFragment
+import im.vector.riotx.core.platform.ToolbarConfigurable
+import im.vector.riotx.core.platform.VectorBaseActivity
+
+class AttachmentsPreviewActivity : VectorBaseActivity(), ToolbarConfigurable {
+
+ companion object {
+
+ private const val EXTRA_FRAGMENT_ARGS = "EXTRA_FRAGMENT_ARGS"
+
+ fun newIntent(context: Context, args: AttachmentsPreviewArgs): Intent {
+ return Intent(context, AttachmentsPreviewArgs::class.java).apply {
+ putExtra(EXTRA_FRAGMENT_ARGS, args)
+ }
+ }
+ }
+
+ override fun getLayoutRes() = R.layout.activity_simple
+
+ override fun initUiAndData() {
+ if (isFirstCreation()) {
+ val fragmentArgs: AttachmentsPreviewArgs = intent?.extras?.getParcelable(EXTRA_FRAGMENT_ARGS)
+ ?: return
+ addFragment(R.id.simpleFragmentContainer, AttachmentsPreviewFragment::class.java, fragmentArgs)
+ }
+ }
+
+ override fun configure(toolbar: Toolbar) {
+ configureToolbar(toolbar)
+ }
+}
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
new file mode 100644
index 0000000000..6e99758c6d
--- /dev/null
+++ b/vector/src/main/java/im/vector/riotx/features/attachments/preview/AttachmentsPreviewFragment.kt
@@ -0,0 +1,67 @@
+/*
+ * Copyright 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 android.os.Bundle
+import android.os.Parcelable
+import android.view.View
+import com.airbnb.mvrx.args
+import com.airbnb.mvrx.fragmentViewModel
+import com.airbnb.mvrx.withState
+import im.vector.matrix.android.api.session.content.ContentAttachmentData
+import im.vector.riotx.R
+import im.vector.riotx.core.extensions.cleanup
+import im.vector.riotx.core.extensions.configureWith
+import im.vector.riotx.core.platform.VectorBaseFragment
+import kotlinx.android.parcel.Parcelize
+import kotlinx.android.synthetic.main.fragment_attachments_preview.*
+import javax.inject.Inject
+
+@Parcelize
+data class AttachmentsPreviewArgs(
+ val attachments: List
+) : Parcelable
+
+class AttachmentsPreviewFragment @Inject constructor(
+ val viewModelFactory: AttachmentsPreviewViewModel.Factory,
+ private val attachmentPreviewController: AttachmentPreviewController
+) : VectorBaseFragment() {
+
+ private val fragmentArgs: AttachmentsPreviewArgs by args()
+ private val viewModel: AttachmentsPreviewViewModel by fragmentViewModel()
+
+ override fun getLayoutResId() = R.layout.fragment_attachments_preview
+
+ override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
+ super.onViewCreated(view, savedInstanceState)
+ setupRecyclerView()
+ }
+
+ override fun onDestroyView() {
+ super.onDestroyView()
+ attachmentPreviewerList.cleanup()
+ }
+
+ private fun setupRecyclerView() {
+ attachmentPreviewerList.configureWith(attachmentPreviewController, hasFixedSize = true)
+ }
+
+ override fun invalidate() = withState(viewModel) { state ->
+
+ }
+}
diff --git a/vector/src/main/java/im/vector/riotx/features/attachments/preview/AttachmentsPreviewViewEvents.kt b/vector/src/main/java/im/vector/riotx/features/attachments/preview/AttachmentsPreviewViewEvents.kt
new file mode 100644
index 0000000000..12a9d9aa24
--- /dev/null
+++ b/vector/src/main/java/im/vector/riotx/features/attachments/preview/AttachmentsPreviewViewEvents.kt
@@ -0,0 +1,22 @@
+/*
+ * Copyright 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.riotx.core.platform.VectorViewEvents
+
+sealed class AttachmentsPreviewViewEvents : VectorViewEvents
diff --git a/vector/src/main/java/im/vector/riotx/features/attachments/preview/AttachmentsPreviewViewModel.kt b/vector/src/main/java/im/vector/riotx/features/attachments/preview/AttachmentsPreviewViewModel.kt
new file mode 100644
index 0000000000..28a0aaebd6
--- /dev/null
+++ b/vector/src/main/java/im/vector/riotx/features/attachments/preview/AttachmentsPreviewViewModel.kt
@@ -0,0 +1,47 @@
+/*
+ * Copyright 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 com.airbnb.mvrx.FragmentViewModelContext
+import com.airbnb.mvrx.MvRxViewModelFactory
+import com.airbnb.mvrx.ViewModelContext
+import com.squareup.inject.assisted.Assisted
+import com.squareup.inject.assisted.AssistedInject
+import im.vector.riotx.core.platform.VectorViewModel
+
+class AttachmentsPreviewViewModel @AssistedInject constructor(@Assisted initialState: AttachmentsPreviewViewState)
+ : VectorViewModel(initialState) {
+
+ @AssistedInject.Factory
+ interface Factory {
+ fun create(initialState: AttachmentsPreviewViewState): AttachmentsPreviewViewModel
+ }
+
+ companion object : MvRxViewModelFactory {
+
+ @JvmStatic
+ override fun create(viewModelContext: ViewModelContext, state: AttachmentsPreviewViewState): AttachmentsPreviewViewModel? {
+ val fragment: AttachmentsPreviewFragment = (viewModelContext as FragmentViewModelContext).fragment()
+ return fragment.viewModelFactory.create(state)
+ }
+ }
+
+ override fun handle(action: AttachmentsPreviewAction) {
+ //TODO
+ }
+}
diff --git a/vector/src/main/java/im/vector/riotx/features/attachments/preview/AttachmentsPreviewViewState.kt b/vector/src/main/java/im/vector/riotx/features/attachments/preview/AttachmentsPreviewViewState.kt
new file mode 100644
index 0000000000..f92abb97ea
--- /dev/null
+++ b/vector/src/main/java/im/vector/riotx/features/attachments/preview/AttachmentsPreviewViewState.kt
@@ -0,0 +1,28 @@
+/*
+ * Copyright 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 com.airbnb.mvrx.MvRxState
+import im.vector.matrix.android.api.session.content.ContentAttachmentData
+
+data class AttachmentsPreviewViewState(
+ val attachments: List
+) : MvRxState {
+
+ constructor(args: AttachmentsPreviewArgs) : this(attachments = args.attachments)
+}
diff --git a/vector/src/main/res/layout/fragment_attachments_preview.xml b/vector/src/main/res/layout/fragment_attachments_preview.xml
new file mode 100644
index 0000000000..60d311b96d
--- /dev/null
+++ b/vector/src/main/res/layout/fragment_attachments_preview.xml
@@ -0,0 +1,86 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/vector/src/main/res/layout/item_attachment_preview.xml b/vector/src/main/res/layout/item_attachment_preview.xml
new file mode 100644
index 0000000000..3c769d17d9
--- /dev/null
+++ b/vector/src/main/res/layout/item_attachment_preview.xml
@@ -0,0 +1,19 @@
+
+
+
+
+
+
\ No newline at end of file