mirror of
https://github.com/nextcloud/talk-android
synced 2025-07-10 06:14:10 +01:00
Shared items: Add tab for locations
Resolves: #2029 Signed-off-by: Tim Krüger <t@timkrueger.me>
This commit is contained in:
parent
d5214ee29c
commit
26fde13292
@ -86,40 +86,7 @@ class SharedItemsActivity : AppCompatActivity() {
|
|||||||
viewModel = ViewModelProvider(this, viewModelFactory)[SharedItemsViewModel::class.java]
|
viewModel = ViewModelProvider(this, viewModelFactory)[SharedItemsViewModel::class.java]
|
||||||
|
|
||||||
viewModel.viewState.observe(this) { state ->
|
viewModel.viewState.observe(this) { state ->
|
||||||
clearEmptyLoading()
|
handleModelChange(state, user, roomToken, isUserConversationOwnerOrModerator)
|
||||||
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)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
binding.imageRecycler.addOnScrollListener(object : RecyclerView.OnScrollListener() {
|
binding.imageRecycler.addOnScrollListener(object : RecyclerView.OnScrollListener() {
|
||||||
@ -134,6 +101,49 @@ class SharedItemsActivity : AppCompatActivity() {
|
|||||||
viewModel.initialize(user, roomToken)
|
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() {
|
private fun clearEmptyLoading() {
|
||||||
binding.sharedItemsTabs.visibility = View.VISIBLE
|
binding.sharedItemsTabs.visibility = View.VISIBLE
|
||||||
binding.emptyContainer.emptyListView.visibility = View.GONE
|
binding.emptyContainer.emptyListView.visibility = View.GONE
|
||||||
@ -189,12 +199,12 @@ class SharedItemsActivity : AppCompatActivity() {
|
|||||||
binding.sharedItemsTabs.addTab(tabVoice)
|
binding.sharedItemsTabs.addTab(tabVoice)
|
||||||
}
|
}
|
||||||
|
|
||||||
// if(sharedItemTypes.contains(SharedItemType.LOCATION)) {
|
if (sharedItemTypes.contains(SharedItemType.LOCATION)) {
|
||||||
// val tabLocation: TabLayout.Tab = binding.sharedItemsTabs.newTab()
|
val tabLocation: TabLayout.Tab = binding.sharedItemsTabs.newTab()
|
||||||
// tabLocation.tag = SharedItemType.LOCATION
|
tabLocation.tag = SharedItemType.LOCATION
|
||||||
// tabLocation.text = "location"
|
tabLocation.setText(R.string.nc_shared_items_location)
|
||||||
// binding.sharedItemsTabs.addTab(tabLocation)
|
binding.sharedItemsTabs.addTab(tabLocation)
|
||||||
// }
|
}
|
||||||
|
|
||||||
// if(sharedItemTypes.contains(SharedItemType.DECKCARD)) {
|
// if(sharedItemTypes.contains(SharedItemType.DECKCARD)) {
|
||||||
// val tabDeckCard: TabLayout.Tab = binding.sharedItemsTabs.newTab()
|
// val tabDeckCard: TabLayout.Tab = binding.sharedItemsTabs.newTab()
|
||||||
|
@ -33,6 +33,7 @@ import com.nextcloud.talk.polls.ui.PollMainDialogFragment
|
|||||||
import com.nextcloud.talk.shareditems.activities.SharedItemsActivity
|
import com.nextcloud.talk.shareditems.activities.SharedItemsActivity
|
||||||
import com.nextcloud.talk.shareditems.model.SharedFileItem
|
import com.nextcloud.talk.shareditems.model.SharedFileItem
|
||||||
import com.nextcloud.talk.shareditems.model.SharedItem
|
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.shareditems.model.SharedPollItem
|
||||||
|
|
||||||
class SharedItemsAdapter(
|
class SharedItemsAdapter(
|
||||||
@ -71,6 +72,7 @@ class SharedItemsAdapter(
|
|||||||
when (val item = items[position]) {
|
when (val item = items[position]) {
|
||||||
is SharedPollItem -> holder.onBind(item, ::showPoll)
|
is SharedPollItem -> holder.onBind(item, ::showPoll)
|
||||||
is SharedFileItem -> holder.onBind(item)
|
is SharedFileItem -> holder.onBind(item)
|
||||||
|
is SharedLocationItem -> holder.onBind(item)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -23,6 +23,7 @@
|
|||||||
package com.nextcloud.talk.shareditems.adapters
|
package com.nextcloud.talk.shareditems.adapters
|
||||||
|
|
||||||
import android.content.Context
|
import android.content.Context
|
||||||
|
import android.content.Intent
|
||||||
import android.text.format.Formatter
|
import android.text.format.Formatter
|
||||||
import android.view.View
|
import android.view.View
|
||||||
import android.widget.ProgressBar
|
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.databinding.SharedItemListBinding
|
||||||
import com.nextcloud.talk.shareditems.model.SharedFileItem
|
import com.nextcloud.talk.shareditems.model.SharedFileItem
|
||||||
import com.nextcloud.talk.shareditems.model.SharedItem
|
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.shareditems.model.SharedPollItem
|
||||||
import com.nextcloud.talk.utils.DateUtils
|
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 {
|
companion object {
|
||||||
private const val ONE_SECOND_IN_MILLIS = 1000
|
private const val ONE_SECOND_IN_MILLIS = 1000
|
||||||
}
|
}
|
||||||
|
@ -42,6 +42,7 @@ import com.facebook.imagepipeline.request.ImageRequestBuilder
|
|||||||
import com.nextcloud.talk.data.user.model.User
|
import com.nextcloud.talk.data.user.model.User
|
||||||
import com.nextcloud.talk.shareditems.model.SharedFileItem
|
import com.nextcloud.talk.shareditems.model.SharedFileItem
|
||||||
import com.nextcloud.talk.shareditems.model.SharedItem
|
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.shareditems.model.SharedPollItem
|
||||||
import com.nextcloud.talk.utils.ApiUtils
|
import com.nextcloud.talk.utils.ApiUtils
|
||||||
import com.nextcloud.talk.utils.DrawableUtils
|
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: SharedPollItem, showPoll: (item: SharedItem, context: Context) -> Unit) {}
|
||||||
|
|
||||||
|
open fun onBind(item: SharedLocationItem) {}
|
||||||
|
|
||||||
private fun staticImage(
|
private fun staticImage(
|
||||||
mimeType: String?,
|
mimeType: String?,
|
||||||
image: SimpleDraweeView
|
image: SimpleDraweeView
|
||||||
|
@ -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
|
@ -22,6 +22,7 @@
|
|||||||
|
|
||||||
package com.nextcloud.talk.shareditems.repositories
|
package com.nextcloud.talk.shareditems.repositories
|
||||||
|
|
||||||
|
import android.net.Uri
|
||||||
import android.util.Log
|
import android.util.Log
|
||||||
import com.nextcloud.talk.R
|
import com.nextcloud.talk.R
|
||||||
import com.nextcloud.talk.api.NcApi
|
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.SharedItem
|
||||||
import com.nextcloud.talk.shareditems.model.SharedItemType
|
import com.nextcloud.talk.shareditems.model.SharedItemType
|
||||||
import com.nextcloud.talk.shareditems.model.SharedItems
|
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.shareditems.model.SharedPollItem
|
||||||
import com.nextcloud.talk.utils.ApiUtils
|
import com.nextcloud.talk.utils.ApiUtils
|
||||||
import io.reactivex.Observable
|
import io.reactivex.Observable
|
||||||
@ -101,16 +103,27 @@ class SharedItemsRepositoryImpl @Inject constructor(private val ncApi: NcApi) :
|
|||||||
)
|
)
|
||||||
} else if (it.value.messageParameters?.containsKey("object") == true) {
|
} else if (it.value.messageParameters?.containsKey("object") == true) {
|
||||||
val objectParameters = it.value.messageParameters!!["object"]!!
|
val objectParameters = it.value.messageParameters!!["object"]!!
|
||||||
if ("talk-poll" == objectParameters["type"]) {
|
when (objectParameters["type"]) {
|
||||||
items[it.value.id] = SharedPollItem(
|
"talk-poll" -> {
|
||||||
objectParameters["id"]!!,
|
items[it.value.id] = SharedPollItem(
|
||||||
objectParameters["name"]!!,
|
objectParameters["id"]!!,
|
||||||
actorParameters["id"]!!,
|
objectParameters["name"]!!,
|
||||||
actorParameters["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 {
|
} else {
|
||||||
Log.w(TAG, "location and deckcard are not yet supported")
|
Log.w(TAG, "Item contains neither 'file' or 'object'.")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -430,6 +430,7 @@
|
|||||||
<string name="nc_shared_items">Shared items</string>
|
<string name="nc_shared_items">Shared items</string>
|
||||||
<string name="nc_shared_items_description">Images, files, voice messages …</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_empty">No shared items</string>
|
||||||
|
<string name="nc_shared_items_location">Location</string>
|
||||||
|
|
||||||
<!-- voice messages -->
|
<!-- voice messages -->
|
||||||
<string name="nc_voice_message_filename">Talk recording from %1$s (%2$s)</string>
|
<string name="nc_voice_message_filename">Talk recording from %1$s (%2$s)</string>
|
||||||
|
Loading…
Reference in New Issue
Block a user