mirror of
https://github.com/nextcloud/talk-android.git
synced 2024-11-21 12:35:30 +03:00
remove lib com.amulyakhare:com.amulyakhare.textdrawable
replace with own TextDrawable class Signed-off-by: Marcel Hibbe <dev@mhibbe.de>
This commit is contained in:
parent
dfa8ad483a
commit
f19e1b8a19
5 changed files with 80 additions and 24 deletions
|
@ -259,7 +259,6 @@ dependencies {
|
|||
implementation "com.github.nextcloud-deps.hwsecurity:hwsecurity-fido2:${fidoVersion}"
|
||||
|
||||
implementation 'com.github.nextcloud:PopupBubble:2.0.0'
|
||||
implementation 'com.amulyakhare:com.amulyakhare.textdrawable:1.0.1'
|
||||
|
||||
implementation "com.afollestad.material-dialogs:core:${materialDialogsVersion}"
|
||||
implementation "com.afollestad.material-dialogs:datetime:${materialDialogsVersion}"
|
||||
|
|
|
@ -16,17 +16,16 @@ import android.util.Log
|
|||
import android.view.View
|
||||
import android.widget.SeekBar
|
||||
import androidx.core.content.ContextCompat
|
||||
import androidx.core.content.res.ResourcesCompat
|
||||
import androidx.work.WorkInfo
|
||||
import androidx.work.WorkManager
|
||||
import autodagger.AutoInjector
|
||||
import coil.load
|
||||
import com.amulyakhare.textdrawable.TextDrawable
|
||||
import com.nextcloud.android.common.ui.theme.utils.ColorRole
|
||||
import com.nextcloud.talk.R
|
||||
import com.nextcloud.talk.application.NextcloudTalkApplication
|
||||
import com.nextcloud.talk.application.NextcloudTalkApplication.Companion.sharedApplication
|
||||
import com.nextcloud.talk.databinding.ItemCustomIncomingVoiceMessageBinding
|
||||
import com.nextcloud.talk.extensions.loadBotsAvatar
|
||||
import com.nextcloud.talk.extensions.loadChangelogBotAvatar
|
||||
import com.nextcloud.talk.extensions.loadFederatedUserAvatar
|
||||
import com.nextcloud.talk.models.json.chat.ChatMessage
|
||||
|
@ -259,16 +258,7 @@ class IncomingVoiceMessageViewHolder(incomingView: View, payload: Any) :
|
|||
} else if (message.actorType == "bots" && message.actorId == "changelog") {
|
||||
binding.messageUserAvatar.loadChangelogBotAvatar()
|
||||
} else if (message.actorType == "bots") {
|
||||
val drawable = TextDrawable.builder()
|
||||
.beginConfig()
|
||||
.bold()
|
||||
.endConfig()
|
||||
.buildRound(
|
||||
">",
|
||||
ResourcesCompat.getColor(context!!.resources, R.color.black, null)
|
||||
)
|
||||
binding.messageUserAvatar.visibility = View.VISIBLE
|
||||
binding.messageUserAvatar.setImageDrawable(drawable)
|
||||
binding.messageUserAvatar.loadBotsAvatar()
|
||||
} else if (message.actorType == "federated_users") {
|
||||
binding.messageUserAvatar.loadFederatedUserAvatar(message)
|
||||
}
|
||||
|
|
|
@ -10,13 +10,13 @@
|
|||
|
||||
package com.nextcloud.talk.extensions
|
||||
|
||||
import android.graphics.drawable.ColorDrawable
|
||||
import android.graphics.drawable.Drawable
|
||||
import android.graphics.drawable.LayerDrawable
|
||||
import android.os.Build
|
||||
import android.util.Log
|
||||
import android.widget.ImageView
|
||||
import androidx.core.content.ContextCompat
|
||||
import androidx.core.content.res.ResourcesCompat
|
||||
import coil.annotation.ExperimentalCoilApi
|
||||
import coil.imageLoader
|
||||
import coil.load
|
||||
|
@ -26,7 +26,6 @@ import coil.request.SuccessResult
|
|||
import coil.result
|
||||
import coil.transform.CircleCropTransformation
|
||||
import coil.transform.RoundedCornersTransformation
|
||||
import com.amulyakhare.textdrawable.TextDrawable
|
||||
import com.nextcloud.talk.R
|
||||
import com.nextcloud.talk.data.user.model.User
|
||||
import com.nextcloud.talk.models.domain.ConversationModel
|
||||
|
@ -36,6 +35,7 @@ import com.nextcloud.talk.models.json.conversations.Conversation
|
|||
import com.nextcloud.talk.ui.theme.ViewThemeUtils
|
||||
import com.nextcloud.talk.utils.ApiUtils
|
||||
import com.nextcloud.talk.utils.DisplayUtils
|
||||
import com.nextcloud.talk.utils.TextDrawable
|
||||
|
||||
private const val ROUNDING_PIXEL = 16f
|
||||
private const val TAG = "ImageViewExtensions"
|
||||
|
@ -315,15 +315,20 @@ fun ImageView.loadChangelogBotAvatar(): io.reactivex.disposables.Disposable {
|
|||
}
|
||||
|
||||
fun ImageView.loadBotsAvatar(): io.reactivex.disposables.Disposable {
|
||||
return loadUserAvatar(
|
||||
TextDrawable.builder()
|
||||
.beginConfig()
|
||||
.bold()
|
||||
.endConfig()
|
||||
.buildRound(
|
||||
">",
|
||||
ResourcesCompat.getColor(context.resources, R.color.black, null)
|
||||
)
|
||||
val data: Any = if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
|
||||
val layers = arrayOfNulls<Drawable>(2)
|
||||
layers[0] = ColorDrawable(context.getColor(R.color.black))
|
||||
layers[1] = TextDrawable(context, ">")
|
||||
val layerDrawable = LayerDrawable(layers)
|
||||
layerDrawable
|
||||
} else {
|
||||
R.mipmap.ic_launcher
|
||||
}
|
||||
|
||||
return DisposableWrapper(
|
||||
load(data) {
|
||||
transformations(CircleCropTransformation())
|
||||
}
|
||||
)
|
||||
}
|
||||
|
||||
|
|
61
app/src/main/java/com/nextcloud/talk/utils/TextDrawable.kt
Normal file
61
app/src/main/java/com/nextcloud/talk/utils/TextDrawable.kt
Normal file
|
@ -0,0 +1,61 @@
|
|||
/*
|
||||
* Nextcloud Talk - Android Client
|
||||
*
|
||||
* SPDX-FileCopyrightText: 2024 Marcel Hibbe <dev@mhibbe.de>
|
||||
* SPDX-License-Identifier: GPL-3.0-or-later
|
||||
*/
|
||||
|
||||
package com.nextcloud.talk.utils
|
||||
|
||||
import android.content.Context
|
||||
import android.graphics.Canvas
|
||||
import android.graphics.ColorFilter
|
||||
import android.graphics.Paint
|
||||
import android.graphics.PixelFormat
|
||||
import android.graphics.Rect
|
||||
import android.graphics.drawable.Drawable
|
||||
import com.nextcloud.talk.R
|
||||
|
||||
class TextDrawable(val context: Context, private var text: String) : Drawable() {
|
||||
private val paint = Paint()
|
||||
private val bounds: Rect
|
||||
|
||||
init {
|
||||
paint.color = context.getColor(R.color.textColorOnPrimaryBackground)
|
||||
paint.isAntiAlias = true
|
||||
paint.textSize = TEXT_SIZE
|
||||
bounds = Rect()
|
||||
}
|
||||
|
||||
override fun draw(canvas: Canvas) {
|
||||
if (text.isNotEmpty()) {
|
||||
paint.getTextBounds(
|
||||
text,
|
||||
0,
|
||||
text.length,
|
||||
bounds
|
||||
)
|
||||
val x: Int = (getBounds().width() - bounds.width()) / 2
|
||||
val y: Int = ((getBounds().height() + bounds.height()) / 2) + Y_OFFSET
|
||||
canvas.drawText(text, x.toFloat(), y.toFloat(), paint)
|
||||
}
|
||||
}
|
||||
|
||||
override fun setColorFilter(colorFilter: ColorFilter?) {
|
||||
paint.setColorFilter(colorFilter)
|
||||
}
|
||||
|
||||
override fun setAlpha(alpha: Int) {
|
||||
paint.alpha = alpha
|
||||
}
|
||||
|
||||
@Deprecated("Deprecated in Java", ReplaceWith("PixelFormat.OPAQUE", "android.graphics.PixelFormat"))
|
||||
override fun getOpacity(): Int {
|
||||
return PixelFormat.OPAQUE
|
||||
}
|
||||
|
||||
companion object {
|
||||
private const val Y_OFFSET = 5
|
||||
private const val TEXT_SIZE = 50f
|
||||
}
|
||||
}
|
|
@ -49,6 +49,7 @@
|
|||
<color name="chat_separator">#E8E8E8</color>
|
||||
<color name="grey_600">#757575</color>
|
||||
<color name="nc_grey">#D5D5D5</color>
|
||||
<color name="black">#000000</color>
|
||||
<color name="call_incomingCallTextView">#E9FFFFFF</color>
|
||||
<color name="grey950">#111111</color>
|
||||
<color name="textColorMaxContrast">#767676</color>
|
||||
|
|
Loading…
Reference in a new issue