Shared items: Add tab for locations

Resolves: #2029

Signed-off-by: Tim Krüger <t@timkrueger.me>
This commit is contained in:
Tim Krüger 2022-08-08 18:50:10 +02:00
parent d5214ee29c
commit 26fde13292
No known key found for this signature in database
GPG key ID: FECE3A7222C52A4E
7 changed files with 128 additions and 48 deletions

View file

@ -86,40 +86,7 @@ class SharedItemsActivity : AppCompatActivity() {
viewModel = ViewModelProvider(this, viewModelFactory)[SharedItemsViewModel::class.java]
viewModel.viewState.observe(this) { state ->
clearEmptyLoading()
when (state) {
is SharedItemsViewModel.LoadingItemsState, SharedItemsViewModel.InitialState -> {
showLoading()
}
is SharedItemsViewModel.NoSharedItemsState -> {
showEmpty()
}
is SharedItemsViewModel.LoadedState -> {
val sharedMediaItems = state.items
Log.d(TAG, "Items received: $sharedMediaItems")
val showGrid = state.selectedType == SharedItemType.MEDIA
val layoutManager = if (showGrid) {
GridLayoutManager(this, SPAN_COUNT)
} else {
LinearLayoutManager(this, LinearLayoutManager.VERTICAL, false)
}
val adapter = SharedItemsAdapter(
showGrid,
user,
roomToken,
isUserConversationOwnerOrModerator
).apply {
items = sharedMediaItems.items
}
binding.imageRecycler.adapter = adapter
binding.imageRecycler.layoutManager = layoutManager
}
is SharedItemsViewModel.TypesLoadedState -> {
initTabs(state.types)
}
}
handleModelChange(state, user, roomToken, isUserConversationOwnerOrModerator)
}
binding.imageRecycler.addOnScrollListener(object : RecyclerView.OnScrollListener() {
@ -134,6 +101,49 @@ class SharedItemsActivity : AppCompatActivity() {
viewModel.initialize(user, roomToken)
}
private fun handleModelChange(
state: SharedItemsViewModel.ViewState?,
user: User,
roomToken: String,
isUserConversationOwnerOrModerator: Boolean
) {
clearEmptyLoading()
when (state) {
is SharedItemsViewModel.LoadingItemsState, SharedItemsViewModel.InitialState -> {
showLoading()
}
is SharedItemsViewModel.NoSharedItemsState -> {
showEmpty()
}
is SharedItemsViewModel.LoadedState -> {
val sharedMediaItems = state.items
Log.d(TAG, "Items received: $sharedMediaItems")
val showGrid = state.selectedType == SharedItemType.MEDIA
val layoutManager = if (showGrid) {
GridLayoutManager(this, SPAN_COUNT)
} else {
LinearLayoutManager(this, LinearLayoutManager.VERTICAL, false)
}
val adapter = SharedItemsAdapter(
showGrid,
user,
roomToken,
isUserConversationOwnerOrModerator
).apply {
items = sharedMediaItems.items
}
binding.imageRecycler.adapter = adapter
binding.imageRecycler.layoutManager = layoutManager
}
is SharedItemsViewModel.TypesLoadedState -> {
initTabs(state.types)
}
else -> {}
}
}
private fun clearEmptyLoading() {
binding.sharedItemsTabs.visibility = View.VISIBLE
binding.emptyContainer.emptyListView.visibility = View.GONE
@ -189,12 +199,12 @@ class SharedItemsActivity : AppCompatActivity() {
binding.sharedItemsTabs.addTab(tabVoice)
}
// if(sharedItemTypes.contains(SharedItemType.LOCATION)) {
// val tabLocation: TabLayout.Tab = binding.sharedItemsTabs.newTab()
// tabLocation.tag = SharedItemType.LOCATION
// tabLocation.text = "location"
// binding.sharedItemsTabs.addTab(tabLocation)
// }
if (sharedItemTypes.contains(SharedItemType.LOCATION)) {
val tabLocation: TabLayout.Tab = binding.sharedItemsTabs.newTab()
tabLocation.tag = SharedItemType.LOCATION
tabLocation.setText(R.string.nc_shared_items_location)
binding.sharedItemsTabs.addTab(tabLocation)
}
// if(sharedItemTypes.contains(SharedItemType.DECKCARD)) {
// val tabDeckCard: TabLayout.Tab = binding.sharedItemsTabs.newTab()

View file

@ -33,6 +33,7 @@ import com.nextcloud.talk.polls.ui.PollMainDialogFragment
import com.nextcloud.talk.shareditems.activities.SharedItemsActivity
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.SharedPollItem
class SharedItemsAdapter(
@ -71,6 +72,7 @@ class SharedItemsAdapter(
when (val item = items[position]) {
is SharedPollItem -> holder.onBind(item, ::showPoll)
is SharedFileItem -> holder.onBind(item)
is SharedLocationItem -> holder.onBind(item)
}
}

View file

@ -23,6 +23,7 @@
package com.nextcloud.talk.shareditems.adapters
import android.content.Context
import android.content.Intent
import android.text.format.Formatter
import android.view.View
import android.widget.ProgressBar
@ -33,6 +34,7 @@ import com.nextcloud.talk.data.user.model.User
import com.nextcloud.talk.databinding.SharedItemListBinding
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.SharedPollItem
import com.nextcloud.talk.utils.DateUtils
@ -79,6 +81,25 @@ class SharedItemsListViewHolder(
}
}
override fun onBind(item: SharedLocationItem) {
super.onBind(item)
binding.fileName.text = item.name
binding.fileMetadata.visibility = View.GONE
image.hierarchy.setPlaceholderImage(R.drawable.ic_baseline_location_on_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.geoUri)
browserIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
it.context.startActivity(browserIntent)
}
}
companion object {
private const val ONE_SECOND_IN_MILLIS = 1000
}

View file

@ -42,6 +42,7 @@ import com.facebook.imagepipeline.request.ImageRequestBuilder
import com.nextcloud.talk.data.user.model.User
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.SharedPollItem
import com.nextcloud.talk.utils.ApiUtils
import com.nextcloud.talk.utils.DrawableUtils
@ -128,6 +129,8 @@ abstract class SharedItemsViewHolder(
open fun onBind(item: SharedPollItem, showPoll: (item: SharedItem, context: Context) -> Unit) {}
open fun onBind(item: SharedLocationItem) {}
private fun staticImage(
mimeType: String?,
image: SimpleDraweeView

View file

@ -0,0 +1,30 @@
/*
* Nextcloud Talk application
*
* @author Tim Krüger
* Copyright (C) 2022 Tim Krüger <t@timkrueger.me>
*
* 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 <http://www.gnu.org/licenses/>.
*/
package com.nextcloud.talk.shareditems.model
import android.net.Uri
data class SharedLocationItem(
override val id: String,
override val name: String,
override val actorId: String,
override val actorName: String,
val geoUri: Uri
) : SharedItem

View file

@ -22,6 +22,7 @@
package com.nextcloud.talk.shareditems.repositories
import android.net.Uri
import android.util.Log
import com.nextcloud.talk.R
import com.nextcloud.talk.api.NcApi
@ -31,6 +32,7 @@ import com.nextcloud.talk.shareditems.model.SharedFileItem
import com.nextcloud.talk.shareditems.model.SharedItem
import com.nextcloud.talk.shareditems.model.SharedItemType
import com.nextcloud.talk.shareditems.model.SharedItems
import com.nextcloud.talk.shareditems.model.SharedLocationItem
import com.nextcloud.talk.shareditems.model.SharedPollItem
import com.nextcloud.talk.utils.ApiUtils
import io.reactivex.Observable
@ -101,16 +103,27 @@ class SharedItemsRepositoryImpl @Inject constructor(private val ncApi: NcApi) :
)
} else if (it.value.messageParameters?.containsKey("object") == true) {
val objectParameters = it.value.messageParameters!!["object"]!!
if ("talk-poll" == objectParameters["type"]) {
items[it.value.id] = SharedPollItem(
objectParameters["id"]!!,
objectParameters["name"]!!,
actorParameters["id"]!!,
actorParameters["name"]!!
)
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 {
Log.w(TAG, "location and deckcard are not yet supported")
Log.w(TAG, "Item contains neither 'file' or 'object'.")
}
}
}

View file

@ -430,6 +430,7 @@
<string name="nc_shared_items">Shared items</string>
<string name="nc_shared_items_description">Images, files, voice messages …</string>
<string name="nc_shared_items_empty">No shared items</string>
<string name="nc_shared_items_location">Location</string>
<!-- voice messages -->
<string name="nc_voice_message_filename">Talk recording from %1$s (%2$s)</string>