diff --git a/app/src/main/java/com/nextcloud/talk/shareditems/activities/SharedItemsActivity.kt b/app/src/main/java/com/nextcloud/talk/shareditems/activities/SharedItemsActivity.kt index 483dbbeb6..2689e0829 100644 --- a/app/src/main/java/com/nextcloud/talk/shareditems/activities/SharedItemsActivity.kt +++ b/app/src/main/java/com/nextcloud/talk/shareditems/activities/SharedItemsActivity.kt @@ -206,12 +206,12 @@ class SharedItemsActivity : AppCompatActivity() { binding.sharedItemsTabs.addTab(tabLocation) } - // if(sharedItemTypes.contains(SharedItemType.DECKCARD)) { - // val tabDeckCard: TabLayout.Tab = binding.sharedItemsTabs.newTab() - // tabDeckCard.tag = SharedItemType.DECKCARD - // tabDeckCard.text = "deckcard" - // binding.sharedItemsTabs.addTab(tabDeckCard) - // } + if (sharedItemTypes.contains(SharedItemType.DECKCARD)) { + val tabDeckCard: TabLayout.Tab = binding.sharedItemsTabs.newTab() + tabDeckCard.tag = SharedItemType.DECKCARD + tabDeckCard.setText(R.string.nc_shared_items_deck_card) + binding.sharedItemsTabs.addTab(tabDeckCard) + } if (sharedItemTypes.contains(SharedItemType.OTHER)) { val tabOther: TabLayout.Tab = binding.sharedItemsTabs.newTab() diff --git a/app/src/main/java/com/nextcloud/talk/shareditems/adapters/SharedItemsAdapter.kt b/app/src/main/java/com/nextcloud/talk/shareditems/adapters/SharedItemsAdapter.kt index 0445195ab..ac98b91b1 100644 --- a/app/src/main/java/com/nextcloud/talk/shareditems/adapters/SharedItemsAdapter.kt +++ b/app/src/main/java/com/nextcloud/talk/shareditems/adapters/SharedItemsAdapter.kt @@ -31,6 +31,7 @@ import com.nextcloud.talk.databinding.SharedItemGridBinding import com.nextcloud.talk.databinding.SharedItemListBinding import com.nextcloud.talk.polls.ui.PollMainDialogFragment import com.nextcloud.talk.shareditems.activities.SharedItemsActivity +import com.nextcloud.talk.shareditems.model.SharedDeckCardItem import com.nextcloud.talk.shareditems.model.SharedFileItem import com.nextcloud.talk.shareditems.model.SharedItem import com.nextcloud.talk.shareditems.model.SharedLocationItem @@ -75,6 +76,7 @@ class SharedItemsAdapter( is SharedFileItem -> holder.onBind(item) is SharedLocationItem -> holder.onBind(item) is SharedOtherItem -> holder.onBind(item) + is SharedDeckCardItem -> holder.onBind(item) } } diff --git a/app/src/main/java/com/nextcloud/talk/shareditems/adapters/SharedItemsListViewHolder.kt b/app/src/main/java/com/nextcloud/talk/shareditems/adapters/SharedItemsListViewHolder.kt index 28195e0ee..fa611d839 100644 --- a/app/src/main/java/com/nextcloud/talk/shareditems/adapters/SharedItemsListViewHolder.kt +++ b/app/src/main/java/com/nextcloud/talk/shareditems/adapters/SharedItemsListViewHolder.kt @@ -32,12 +32,12 @@ import com.facebook.drawee.view.SimpleDraweeView import com.nextcloud.talk.R import com.nextcloud.talk.data.user.model.User import com.nextcloud.talk.databinding.SharedItemListBinding +import com.nextcloud.talk.shareditems.model.SharedDeckCardItem import com.nextcloud.talk.shareditems.model.SharedFileItem import com.nextcloud.talk.shareditems.model.SharedItem import com.nextcloud.talk.shareditems.model.SharedLocationItem import com.nextcloud.talk.shareditems.model.SharedOtherItem import com.nextcloud.talk.shareditems.model.SharedPollItem -import com.nextcloud.talk.utils.DateUtils class SharedItemsListViewHolder( override val binding: SharedItemListBinding, @@ -62,16 +62,18 @@ class SharedItemsListViewHolder( it ) } - binding.fileDate.text = DateUtils.getLocalDateTimeStringFromTimestamp( - item.date * ONE_SECOND_IN_MILLIS - ) + binding.fileDate.text = item.dateTime + binding.actor.text = item.actorName } override fun onBind(item: SharedPollItem, showPoll: (item: SharedItem, context: Context) -> Unit) { super.onBind(item, showPoll) binding.fileName.text = item.name - binding.fileMetadata.visibility = View.GONE + binding.fileSize.visibility = View.GONE + binding.separator1.visibility = View.GONE + binding.fileDate.text = item.dateTime + binding.actor.text = item.actorName image.hierarchy.setPlaceholderImage(R.drawable.ic_baseline_bar_chart_24) image.setColorFilter( ContextCompat.getColor(image.context, R.color.high_emphasis_menu_icon), @@ -86,7 +88,10 @@ class SharedItemsListViewHolder( super.onBind(item) binding.fileName.text = item.name - binding.fileMetadata.visibility = View.GONE + binding.fileSize.visibility = View.GONE + binding.separator1.visibility = View.GONE + binding.fileDate.text = item.dateTime + binding.actor.text = item.actorName image.hierarchy.setPlaceholderImage(R.drawable.ic_baseline_location_on_24) image.setColorFilter( ContextCompat.getColor(image.context, R.color.high_emphasis_menu_icon), @@ -94,7 +99,6 @@ class SharedItemsListViewHolder( ) clickTarget.setOnClickListener { - val browserIntent = Intent(Intent.ACTION_VIEW, item.geoUri) browserIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK) it.context.startActivity(browserIntent) @@ -105,7 +109,10 @@ class SharedItemsListViewHolder( super.onBind(item) binding.fileName.text = item.name - binding.fileMetadata.visibility = View.GONE + binding.fileSize.visibility = View.GONE + binding.separator1.visibility = View.GONE + binding.fileDate.text = item.dateTime + binding.actor.text = item.actorName image.hierarchy.setPlaceholderImage(R.drawable.ic_mimetype_file) image.setColorFilter( ContextCompat.getColor(image.context, R.color.high_emphasis_menu_icon), @@ -113,7 +120,24 @@ class SharedItemsListViewHolder( ) } - companion object { - private const val ONE_SECOND_IN_MILLIS = 1000 + override fun onBind(item: SharedDeckCardItem) { + super.onBind(item) + + binding.fileName.text = item.name + binding.fileSize.visibility = View.GONE + binding.separator1.visibility = View.GONE + binding.fileDate.text = item.dateTime + binding.actor.text = item.actorName + image.hierarchy.setPlaceholderImage(R.drawable.ic_baseline_deck_24) + image.setColorFilter( + ContextCompat.getColor(image.context, R.color.high_emphasis_menu_icon), + android.graphics.PorterDuff.Mode.SRC_IN + ) + + clickTarget.setOnClickListener { + val browserIntent = Intent(Intent.ACTION_VIEW, item.link) + browserIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK) + it.context.startActivity(browserIntent) + } } } diff --git a/app/src/main/java/com/nextcloud/talk/shareditems/adapters/SharedItemsViewHolder.kt b/app/src/main/java/com/nextcloud/talk/shareditems/adapters/SharedItemsViewHolder.kt index 0c05be81f..205bbcb7c 100644 --- a/app/src/main/java/com/nextcloud/talk/shareditems/adapters/SharedItemsViewHolder.kt +++ b/app/src/main/java/com/nextcloud/talk/shareditems/adapters/SharedItemsViewHolder.kt @@ -40,6 +40,7 @@ import com.facebook.imagepipeline.common.RotationOptions import com.facebook.imagepipeline.image.ImageInfo import com.facebook.imagepipeline.request.ImageRequestBuilder import com.nextcloud.talk.data.user.model.User +import com.nextcloud.talk.shareditems.model.SharedDeckCardItem import com.nextcloud.talk.shareditems.model.SharedFileItem import com.nextcloud.talk.shareditems.model.SharedItem import com.nextcloud.talk.shareditems.model.SharedLocationItem @@ -134,6 +135,8 @@ abstract class SharedItemsViewHolder( open fun onBind(item: SharedOtherItem) {} + open fun onBind(item: SharedDeckCardItem) {} + private fun staticImage( mimeType: String?, image: SimpleDraweeView diff --git a/app/src/main/java/com/nextcloud/talk/shareditems/model/SharedDeckCardItem.kt b/app/src/main/java/com/nextcloud/talk/shareditems/model/SharedDeckCardItem.kt new file mode 100644 index 000000000..e5230a126 --- /dev/null +++ b/app/src/main/java/com/nextcloud/talk/shareditems/model/SharedDeckCardItem.kt @@ -0,0 +1,31 @@ +/* + * Nextcloud Talk application + * + * @author Tim Krüger + * Copyright (C) 2022 Tim Krüger + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ +package com.nextcloud.talk.shareditems.model + +import android.net.Uri + +data class SharedDeckCardItem( + override val id: String, + override val name: String, + override val actorId: String, + override val actorName: String, + override val dateTime: String, + val link: Uri +) : SharedItem diff --git a/app/src/main/java/com/nextcloud/talk/shareditems/model/SharedFileItem.kt b/app/src/main/java/com/nextcloud/talk/shareditems/model/SharedFileItem.kt index 2366b7e13..904dc0b12 100644 --- a/app/src/main/java/com/nextcloud/talk/shareditems/model/SharedFileItem.kt +++ b/app/src/main/java/com/nextcloud/talk/shareditems/model/SharedFileItem.kt @@ -27,8 +27,8 @@ data class SharedFileItem( override val name: String, override val actorId: String, override val actorName: String, + override val dateTime: String, val fileSize: Long, - val date: Long, val path: String, val link: String, val mimeType: String, diff --git a/app/src/main/java/com/nextcloud/talk/shareditems/model/SharedItem.kt b/app/src/main/java/com/nextcloud/talk/shareditems/model/SharedItem.kt index 5c577b4c4..7575ae2bb 100644 --- a/app/src/main/java/com/nextcloud/talk/shareditems/model/SharedItem.kt +++ b/app/src/main/java/com/nextcloud/talk/shareditems/model/SharedItem.kt @@ -5,4 +5,5 @@ interface SharedItem { val name: String val actorId: String val actorName: String + val dateTime: String } diff --git a/app/src/main/java/com/nextcloud/talk/shareditems/model/SharedLocationItem.kt b/app/src/main/java/com/nextcloud/talk/shareditems/model/SharedLocationItem.kt index 2d5c6ea2b..291840e13 100644 --- a/app/src/main/java/com/nextcloud/talk/shareditems/model/SharedLocationItem.kt +++ b/app/src/main/java/com/nextcloud/talk/shareditems/model/SharedLocationItem.kt @@ -26,5 +26,6 @@ data class SharedLocationItem( override val name: String, override val actorId: String, override val actorName: String, + override val dateTime: String, val geoUri: Uri ) : SharedItem diff --git a/app/src/main/java/com/nextcloud/talk/shareditems/model/SharedOtherItem.kt b/app/src/main/java/com/nextcloud/talk/shareditems/model/SharedOtherItem.kt index 7d3ae324a..9d23a6a61 100644 --- a/app/src/main/java/com/nextcloud/talk/shareditems/model/SharedOtherItem.kt +++ b/app/src/main/java/com/nextcloud/talk/shareditems/model/SharedOtherItem.kt @@ -24,4 +24,5 @@ data class SharedOtherItem( override val name: String, override val actorId: String, override val actorName: String, + override val dateTime: String ) : SharedItem diff --git a/app/src/main/java/com/nextcloud/talk/shareditems/model/SharedPollItem.kt b/app/src/main/java/com/nextcloud/talk/shareditems/model/SharedPollItem.kt index 367aba189..ed19917b1 100644 --- a/app/src/main/java/com/nextcloud/talk/shareditems/model/SharedPollItem.kt +++ b/app/src/main/java/com/nextcloud/talk/shareditems/model/SharedPollItem.kt @@ -24,4 +24,5 @@ data class SharedPollItem( override val name: String, override val actorId: String, override val actorName: String, + override val dateTime: String ) : SharedItem diff --git a/app/src/main/java/com/nextcloud/talk/shareditems/repositories/SharedItemsRepositoryImpl.kt b/app/src/main/java/com/nextcloud/talk/shareditems/repositories/SharedItemsRepositoryImpl.kt index f2d669560..e012bb18b 100644 --- a/app/src/main/java/com/nextcloud/talk/shareditems/repositories/SharedItemsRepositoryImpl.kt +++ b/app/src/main/java/com/nextcloud/talk/shareditems/repositories/SharedItemsRepositoryImpl.kt @@ -28,6 +28,7 @@ import com.nextcloud.talk.R import com.nextcloud.talk.api.NcApi import com.nextcloud.talk.application.NextcloudTalkApplication.Companion.sharedApplication import com.nextcloud.talk.models.json.chat.ChatShareOverall +import com.nextcloud.talk.shareditems.model.SharedDeckCardItem import com.nextcloud.talk.shareditems.model.SharedFileItem import com.nextcloud.talk.shareditems.model.SharedItem import com.nextcloud.talk.shareditems.model.SharedItemType @@ -36,8 +37,10 @@ import com.nextcloud.talk.shareditems.model.SharedLocationItem import com.nextcloud.talk.shareditems.model.SharedOtherItem import com.nextcloud.talk.shareditems.model.SharedPollItem import com.nextcloud.talk.utils.ApiUtils +import com.nextcloud.talk.utils.DateUtils import io.reactivex.Observable import retrofit2.Response +import java.util.HashMap import java.util.Locale import javax.inject.Inject @@ -83,6 +86,10 @@ class SharedItemsRepositoryImpl @Inject constructor(private val ncApi: NcApi) : if (mediaItems != null) { for (it in mediaItems) { val actorParameters = it.value.messageParameters!!["actor"]!! + val dateTime = DateUtils.getLocalDateTimeStringFromTimestamp( + it.value.timestamp * ONE_SECOND_IN_MILLIS + ) + if (it.value.messageParameters?.containsKey("file") == true) { val fileParameters = it.value.messageParameters!!["file"]!! @@ -94,8 +101,8 @@ class SharedItemsRepositoryImpl @Inject constructor(private val ncApi: NcApi) : fileParameters["name"]!!, actorParameters["id"]!!, actorParameters["name"]!!, + dateTime, fileParameters["size"]!!.toLong(), - it.value.timestamp, fileParameters["path"]!!, fileParameters["link"]!!, fileParameters["mimetype"]!!, @@ -104,33 +111,7 @@ class SharedItemsRepositoryImpl @Inject constructor(private val ncApi: NcApi) : ) } else if (it.value.messageParameters?.containsKey("object") == true) { val objectParameters = it.value.messageParameters!!["object"]!! - when (objectParameters["type"]) { - "talk-poll" -> { - items[it.value.id] = SharedPollItem( - objectParameters["id"]!!, - objectParameters["name"]!!, - actorParameters["id"]!!, - actorParameters["name"]!! - ) - } - "geo-location" -> { - items[it.value.id] = SharedLocationItem( - objectParameters["id"]!!, - objectParameters["name"]!!, - actorParameters["id"]!!, - actorParameters["name"]!!, - Uri.parse(objectParameters["id"]!!.replace("geo:", "geo:0,0?z=11&q=")) - ) - } - else -> { - items[it.value.id] = SharedOtherItem( - objectParameters["id"]!!, - objectParameters["name"]!!, - actorParameters["id"]!!, - actorParameters["name"]!! - ) - } - } + items[it.value.id] = itemFromObject(objectParameters, actorParameters, dateTime) } else { Log.w(TAG, "Item contains neither 'file' or 'object'.") } @@ -148,6 +129,55 @@ class SharedItemsRepositoryImpl @Inject constructor(private val ncApi: NcApi) : ) } + private fun itemFromObject( + objectParameters: HashMap, + actorParameters: HashMap, + dateTime: String + ): SharedItem { + val returnValue: SharedItem + when (objectParameters["type"]) { + "talk-poll" -> { + returnValue = SharedPollItem( + objectParameters["id"]!!, + objectParameters["name"]!!, + actorParameters["id"]!!, + actorParameters["name"]!!, + dateTime + ) + } + "geo-location" -> { + returnValue = SharedLocationItem( + objectParameters["id"]!!, + objectParameters["name"]!!, + actorParameters["id"]!!, + actorParameters["name"]!!, + dateTime, + Uri.parse(objectParameters["id"]!!.replace("geo:", "geo:0,0?z=11&q=")) + ) + } + "deck-card" -> { + returnValue = SharedDeckCardItem( + objectParameters["id"]!!, + objectParameters["name"]!!, + actorParameters["id"]!!, + actorParameters["name"]!!, + dateTime, + Uri.parse(objectParameters["link"]!!) + ) + } + else -> { + returnValue = SharedOtherItem( + objectParameters["id"]!!, + objectParameters["name"]!!, + actorParameters["id"]!!, + actorParameters["name"]!!, + dateTime + ) + } + } + return returnValue + } + override fun availableTypes(parameters: SharedItemsRepository.Parameters): Observable> { val credentials = ApiUtils.getCredentials(parameters.userName, parameters.userToken) @@ -182,6 +212,7 @@ class SharedItemsRepositoryImpl @Inject constructor(private val ncApi: NcApi) : companion object { const val BATCH_SIZE: Int = 28 + private const val ONE_SECOND_IN_MILLIS = 1000 private val TAG = SharedItemsRepositoryImpl::class.simpleName } } diff --git a/app/src/main/res/drawable/ic_baseline_deck_24.xml b/app/src/main/res/drawable/ic_baseline_deck_24.xml new file mode 100644 index 000000000..a93dfce01 --- /dev/null +++ b/app/src/main/res/drawable/ic_baseline_deck_24.xml @@ -0,0 +1,39 @@ + + + + + + + + + diff --git a/app/src/main/res/layout/controller_chat.xml b/app/src/main/res/layout/controller_chat.xml index 5453d27df..60be4c6d4 100644 --- a/app/src/main/res/layout/controller_chat.xml +++ b/app/src/main/res/layout/controller_chat.xml @@ -115,7 +115,7 @@ android:orientation="vertical"> diff --git a/app/src/main/res/layout/shared_item_list.xml b/app/src/main/res/layout/shared_item_list.xml index 81c680408..5b399bc0f 100644 --- a/app/src/main/res/layout/shared_item_list.xml +++ b/app/src/main/res/layout/shared_item_list.xml @@ -92,7 +92,7 @@ tools:text="11 KB" /> + + + + diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index a9e332253..1322cb462 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -431,6 +431,7 @@ Images, files, voice messages … No shared items Location + Deck card Talk recording from %1$s (%2$s) @@ -563,5 +564,4 @@ Call without notification Set avatar from camera -