mirror of
https://github.com/nextcloud/talk-android
synced 2025-06-20 12:09:45 +01:00
Improve previews
Signed-off-by: Mario Danic <mario@lovelyhq.com>
This commit is contained in:
parent
1e251d4696
commit
f2f9cc50ad
@ -0,0 +1,30 @@
|
|||||||
|
/*
|
||||||
|
* Nextcloud Talk application
|
||||||
|
*
|
||||||
|
* @author Mario Danic
|
||||||
|
* Copyright (C) 2017-2019 Mario Danic <mario@lovelyhq.com>
|
||||||
|
*
|
||||||
|
* 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.adapters.messages
|
||||||
|
|
||||||
|
import android.os.Parcelable
|
||||||
|
import kotlinx.android.parcel.Parcelize
|
||||||
|
import kotlinx.android.parcel.RawValue
|
||||||
|
|
||||||
|
@Parcelize
|
||||||
|
data class ImageLoaderPayload(
|
||||||
|
val map: @RawValue HashMap<String, Any>?
|
||||||
|
): Parcelable
|
@ -55,6 +55,7 @@ import com.nextcloud.talk.utils.DrawableUtils.getDrawableResourceIdForMimeType
|
|||||||
import com.nextcloud.talk.utils.bundle.BundleKeys.KEY_ACCOUNT
|
import com.nextcloud.talk.utils.bundle.BundleKeys.KEY_ACCOUNT
|
||||||
import com.nextcloud.talk.utils.bundle.BundleKeys.KEY_FILE_ID
|
import com.nextcloud.talk.utils.bundle.BundleKeys.KEY_FILE_ID
|
||||||
import com.stfalcon.chatkit.messages.MessageHolders.IncomingImageMessageViewHolder
|
import com.stfalcon.chatkit.messages.MessageHolders.IncomingImageMessageViewHolder
|
||||||
|
import eu.davidea.flexibleadapter.Payload
|
||||||
import io.reactivex.Single
|
import io.reactivex.Single
|
||||||
import io.reactivex.SingleObserver
|
import io.reactivex.SingleObserver
|
||||||
import io.reactivex.disposables.Disposable
|
import io.reactivex.disposables.Disposable
|
||||||
@ -109,14 +110,17 @@ class MagicPreviewMessageViewHolder(itemView: View?) : IncomingImageMessageViewH
|
|||||||
message.getSelectedIndividualHashMap()["name"]!!,
|
message.getSelectedIndividualHashMap()["name"]!!,
|
||||||
message.getSelectedIndividualHashMap()["link"]!!, messageText!!
|
message.getSelectedIndividualHashMap()["link"]!!, messageText!!
|
||||||
)
|
)
|
||||||
|
|
||||||
if (message.getSelectedIndividualHashMap().containsKey("mimetype")) {
|
if (message.getSelectedIndividualHashMap().containsKey("mimetype")) {
|
||||||
image.load(getDrawableResourceIdForMimeType(message.getSelectedIndividualHashMap().get("mimetype")))
|
// we now handle this directly in imageloader
|
||||||
|
//image.load(getDrawableResourceIdForMimeType(message.getSelectedIndividualHashMap().get ("mimetype")))
|
||||||
} else {
|
} else {
|
||||||
fetchFileInformation(
|
fetchFileInformation(
|
||||||
"/" + message.getSelectedIndividualHashMap()["path"],
|
"/" + message.getSelectedIndividualHashMap()["path"],
|
||||||
message.activeUser
|
message.activeUser
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
image.setOnClickListener { v: View? ->
|
image.setOnClickListener { v: View? ->
|
||||||
val accountString =
|
val accountString =
|
||||||
message.activeUser.username + "@" + message.activeUser
|
message.activeUser.username + "@" + message.activeUser
|
||||||
@ -209,6 +213,15 @@ class MagicPreviewMessageViewHolder(itemView: View?) : IncomingImageMessageViewH
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
override fun getPayloadForImageLoader(message: ChatMessage): Any {
|
||||||
|
val map = HashMap<String, Any>()
|
||||||
|
if (message.getSelectedIndividualHashMap().containsKey("mimetype")) {
|
||||||
|
map.put("mimetype", message.getSelectedIndividualHashMap().get("mimetype")!!)
|
||||||
|
}
|
||||||
|
|
||||||
|
return ImageLoaderPayload(map)
|
||||||
|
}
|
||||||
|
|
||||||
init {
|
init {
|
||||||
ButterKnife.bind(this, itemView!!)
|
ButterKnife.bind(this, itemView!!)
|
||||||
sharedApplication!!.componentApplication.inject(this)
|
sharedApplication!!.componentApplication.inject(this)
|
||||||
|
@ -58,9 +58,9 @@ import coil.transform.CircleCropTransformation
|
|||||||
import com.bluelinelabs.conductor.RouterTransaction
|
import com.bluelinelabs.conductor.RouterTransaction
|
||||||
import com.bluelinelabs.conductor.changehandler.HorizontalChangeHandler
|
import com.bluelinelabs.conductor.changehandler.HorizontalChangeHandler
|
||||||
import com.bluelinelabs.conductor.changehandler.VerticalChangeHandler
|
import com.bluelinelabs.conductor.changehandler.VerticalChangeHandler
|
||||||
import com.facebook.drawee.backends.pipeline.Fresco
|
|
||||||
import com.nextcloud.talk.R
|
import com.nextcloud.talk.R
|
||||||
import com.nextcloud.talk.activities.MagicCallActivity
|
import com.nextcloud.talk.activities.MagicCallActivity
|
||||||
|
import com.nextcloud.talk.adapters.messages.ImageLoaderPayload
|
||||||
import com.nextcloud.talk.adapters.messages.MagicIncomingTextMessageViewHolder
|
import com.nextcloud.talk.adapters.messages.MagicIncomingTextMessageViewHolder
|
||||||
import com.nextcloud.talk.adapters.messages.MagicOutcomingTextMessageViewHolder
|
import com.nextcloud.talk.adapters.messages.MagicOutcomingTextMessageViewHolder
|
||||||
import com.nextcloud.talk.adapters.messages.MagicPreviewMessageViewHolder
|
import com.nextcloud.talk.adapters.messages.MagicPreviewMessageViewHolder
|
||||||
@ -88,6 +88,7 @@ import com.nextcloud.talk.utils.ApiUtils
|
|||||||
import com.nextcloud.talk.utils.ConductorRemapping
|
import com.nextcloud.talk.utils.ConductorRemapping
|
||||||
import com.nextcloud.talk.utils.DateUtils
|
import com.nextcloud.talk.utils.DateUtils
|
||||||
import com.nextcloud.talk.utils.DisplayUtils
|
import com.nextcloud.talk.utils.DisplayUtils
|
||||||
|
import com.nextcloud.talk.utils.DrawableUtils.getDrawableResourceIdForMimeType
|
||||||
import com.nextcloud.talk.utils.KeyboardUtils
|
import com.nextcloud.talk.utils.KeyboardUtils
|
||||||
import com.nextcloud.talk.utils.MagicCharPolicy
|
import com.nextcloud.talk.utils.MagicCharPolicy
|
||||||
import com.nextcloud.talk.utils.NotificationUtils
|
import com.nextcloud.talk.utils.NotificationUtils
|
||||||
@ -387,8 +388,24 @@ class ChatController(args: Bundle) : BaseController(), MessagesListAdapter
|
|||||||
adapter = MessagesListAdapter(
|
adapter = MessagesListAdapter(
|
||||||
conversationUser?.userId, messageHolders, ImageLoader { imageView, url, payload ->
|
conversationUser?.userId, messageHolders, ImageLoader { imageView, url, payload ->
|
||||||
imageView.load(url) {
|
imageView.load(url) {
|
||||||
transformations(CircleCropTransformation())
|
if (url!!.contains("/avatar/")) {
|
||||||
if (conversationUser != null) {
|
transformations(CircleCropTransformation())
|
||||||
|
} else {
|
||||||
|
if (payload is ImageLoaderPayload) {
|
||||||
|
payload.map?.let {
|
||||||
|
if (payload.map.containsKey("mimetype")) {
|
||||||
|
placeholder(
|
||||||
|
getDrawableResourceIdForMimeType(
|
||||||
|
payload.map.get("mimetype") as String?
|
||||||
|
)
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (conversationUser != null && url.startsWith(conversationUser.baseUrl) && url.contains(
|
||||||
|
"index.php/core/preview?fileId=")) {
|
||||||
addHeader("Authorization", conversationUser.getCredentials())
|
addHeader("Authorization", conversationUser.getCredentials())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -1137,7 +1154,8 @@ class ChatController(args: Bundle) : BaseController(), MessagesListAdapter
|
|||||||
isFromTheFuture: Boolean,
|
isFromTheFuture: Boolean,
|
||||||
timeout: Int
|
timeout: Int
|
||||||
) {
|
) {
|
||||||
val xChatLastGivenHeader: String? = response.headers().get("X-Chat-Last-Given")
|
val xChatLastGivenHeader: String? = response.headers()
|
||||||
|
.get("X-Chat-Last-Given")
|
||||||
if (response.headers().size() > 0 && !TextUtils.isEmpty(xChatLastGivenHeader)) {
|
if (response.headers().size() > 0 && !TextUtils.isEmpty(xChatLastGivenHeader)) {
|
||||||
|
|
||||||
val header = Integer.parseInt(xChatLastGivenHeader!!)
|
val header = Integer.parseInt(xChatLastGivenHeader!!)
|
||||||
|
Loading…
Reference in New Issue
Block a user