mirror of
https://github.com/SchildiChat/SchildiChat-android.git
synced 2024-11-26 19:36:08 +03:00
Rename DimensionUtils to DimensionConverter, and inject resources instead of context.
This commit is contained in:
parent
5cbc90e06a
commit
b25a130db1
10 changed files with 37 additions and 37 deletions
|
@ -27,7 +27,7 @@ import im.vector.riotx.EmojiCompatFontProvider
|
|||
import im.vector.riotx.EmojiCompatWrapper
|
||||
import im.vector.riotx.VectorApplication
|
||||
import im.vector.riotx.core.pushers.PushersManager
|
||||
import im.vector.riotx.core.utils.DimensionUtils
|
||||
import im.vector.riotx.core.utils.DimensionConverter
|
||||
import im.vector.riotx.features.configuration.VectorConfiguration
|
||||
import im.vector.riotx.features.crypto.keysrequest.KeyRequestHandler
|
||||
import im.vector.riotx.features.crypto.verification.IncomingVerificationRequestHandler
|
||||
|
@ -64,7 +64,7 @@ interface VectorComponent {
|
|||
|
||||
fun resources(): Resources
|
||||
|
||||
fun dimensionUtils(): DimensionUtils
|
||||
fun dimensionUtils(): DimensionConverter
|
||||
|
||||
fun vectorConfiguration(): VectorConfiguration
|
||||
|
||||
|
|
|
@ -15,18 +15,18 @@
|
|||
*/
|
||||
package im.vector.riotx.core.utils
|
||||
|
||||
import android.content.Context
|
||||
import android.content.res.Resources
|
||||
import android.util.TypedValue
|
||||
import javax.inject.Inject
|
||||
|
||||
|
||||
class DimensionUtils @Inject constructor(val context: Context) {
|
||||
class DimensionConverter @Inject constructor(val resources: Resources) {
|
||||
|
||||
fun dpToPx(dp: Int): Int {
|
||||
return TypedValue.applyDimension(
|
||||
TypedValue.COMPLEX_UNIT_DIP,
|
||||
dp.toFloat(),
|
||||
context.resources.displayMetrics
|
||||
resources.displayMetrics
|
||||
).toInt()
|
||||
}
|
||||
|
||||
|
@ -34,7 +34,7 @@ class DimensionUtils @Inject constructor(val context: Context) {
|
|||
return TypedValue.applyDimension(
|
||||
TypedValue.COMPLEX_UNIT_SP,
|
||||
sp.toFloat(),
|
||||
context.resources.displayMetrics
|
||||
resources.displayMetrics
|
||||
).toInt()
|
||||
}
|
||||
}
|
|
@ -36,7 +36,7 @@ import im.vector.riotx.core.extensions.hideKeyboard
|
|||
import im.vector.riotx.core.extensions.observeEvent
|
||||
import im.vector.riotx.core.extensions.setupAsSearch
|
||||
import im.vector.riotx.core.platform.VectorBaseFragment
|
||||
import im.vector.riotx.core.utils.DimensionUtils
|
||||
import im.vector.riotx.core.utils.DimensionConverter
|
||||
import im.vector.riotx.features.home.AvatarRenderer
|
||||
import kotlinx.android.synthetic.main.fragment_create_direct_room.*
|
||||
import javax.inject.Inject
|
||||
|
@ -51,7 +51,7 @@ class CreateDirectRoomKnownUsersFragment : VectorBaseFragment(), KnownUsersContr
|
|||
|
||||
@Inject lateinit var directRoomController: KnownUsersController
|
||||
@Inject lateinit var avatarRenderer: AvatarRenderer
|
||||
@Inject lateinit var dimensionUtils: DimensionUtils
|
||||
@Inject lateinit var dimensionConverter: DimensionConverter
|
||||
private lateinit var navigationViewModel: CreateDirectRoomNavigationViewModel
|
||||
|
||||
override fun injectWith(injector: ScreenComponent) {
|
||||
|
@ -157,7 +157,7 @@ class CreateDirectRoomKnownUsersFragment : VectorBaseFragment(), KnownUsersContr
|
|||
private fun addChipToGroup(user: User, chipGroup: ChipGroup) {
|
||||
val chip = Chip(requireContext())
|
||||
chip.setChipBackgroundColorResource(android.R.color.transparent)
|
||||
chip.chipStrokeWidth = dimensionUtils.dpToPx(1).toFloat()
|
||||
chip.chipStrokeWidth = dimensionConverter.dpToPx(1).toFloat()
|
||||
chip.text = if (user.displayName.isNullOrBlank()) user.userId else user.displayName
|
||||
chip.isClickable = true
|
||||
chip.isCheckable = false
|
||||
|
|
|
@ -25,7 +25,7 @@ import im.vector.riotx.core.epoxy.VectorEpoxyModel
|
|||
import im.vector.riotx.core.resources.ColorProvider
|
||||
import im.vector.riotx.core.resources.StringProvider
|
||||
import im.vector.riotx.core.utils.DebouncedClickListener
|
||||
import im.vector.riotx.core.utils.DimensionUtils
|
||||
import im.vector.riotx.core.utils.DimensionConverter
|
||||
import im.vector.riotx.features.home.AvatarRenderer
|
||||
import im.vector.riotx.features.home.room.detail.timeline.TimelineEventController
|
||||
import im.vector.riotx.features.home.room.detail.timeline.item.MessageTextItem_
|
||||
|
@ -38,7 +38,7 @@ class EncryptedItemFactory @Inject constructor(private val messageInformationDat
|
|||
private val colorProvider: ColorProvider,
|
||||
private val stringProvider: StringProvider,
|
||||
private val avatarRenderer: AvatarRenderer,
|
||||
private val dimensionUtils: DimensionUtils) {
|
||||
private val dimensionConverter: DimensionConverter) {
|
||||
|
||||
fun create(event: TimelineEvent,
|
||||
nextEvent: TimelineEvent?,
|
||||
|
@ -71,7 +71,7 @@ class EncryptedItemFactory @Inject constructor(private val messageInformationDat
|
|||
.message(spannableStr)
|
||||
.avatarRenderer(avatarRenderer)
|
||||
.colorProvider(colorProvider)
|
||||
.dimensionUtils(dimensionUtils)
|
||||
.dimensionConverter(dimensionConverter)
|
||||
.informationData(informationData)
|
||||
.highlighted(highlight)
|
||||
.avatarCallback(callback)
|
||||
|
|
|
@ -23,7 +23,7 @@ import im.vector.matrix.android.api.session.room.timeline.TimelineEvent
|
|||
import im.vector.matrix.android.internal.crypto.model.event.EncryptionEventContent
|
||||
import im.vector.riotx.R
|
||||
import im.vector.riotx.core.resources.StringProvider
|
||||
import im.vector.riotx.core.utils.DimensionUtils
|
||||
import im.vector.riotx.core.utils.DimensionConverter
|
||||
import im.vector.riotx.features.home.AvatarRenderer
|
||||
import im.vector.riotx.features.home.room.detail.timeline.TimelineEventController
|
||||
import im.vector.riotx.features.home.room.detail.timeline.helper.senderAvatar
|
||||
|
@ -35,7 +35,7 @@ import javax.inject.Inject
|
|||
|
||||
class EncryptionItemFactory @Inject constructor(private val stringProvider: StringProvider,
|
||||
private val avatarRenderer: AvatarRenderer,
|
||||
private val dimensionUtils: DimensionUtils) {
|
||||
private val dimensionConverter: DimensionConverter) {
|
||||
|
||||
fun create(event: TimelineEvent,
|
||||
highlight: Boolean,
|
||||
|
@ -52,7 +52,7 @@ class EncryptionItemFactory @Inject constructor(private val stringProvider: Stri
|
|||
)
|
||||
return NoticeItem_()
|
||||
.avatarRenderer(avatarRenderer)
|
||||
.dimensionUtils(dimensionUtils)
|
||||
.dimensionConverter(dimensionConverter)
|
||||
.noticeText(text)
|
||||
.informationData(informationData)
|
||||
.highlighted(highlight)
|
||||
|
|
|
@ -40,7 +40,7 @@ import im.vector.riotx.core.linkify.VectorLinkify
|
|||
import im.vector.riotx.core.resources.ColorProvider
|
||||
import im.vector.riotx.core.resources.StringProvider
|
||||
import im.vector.riotx.core.utils.DebouncedClickListener
|
||||
import im.vector.riotx.core.utils.DimensionUtils
|
||||
import im.vector.riotx.core.utils.DimensionConverter
|
||||
import im.vector.riotx.core.utils.containsOnlyEmojis
|
||||
import im.vector.riotx.features.home.AvatarRenderer
|
||||
import im.vector.riotx.features.home.room.detail.timeline.TimelineEventController
|
||||
|
@ -65,7 +65,7 @@ class MessageItemFactory @Inject constructor(
|
|||
private val messageInformationDataFactory: MessageInformationDataFactory,
|
||||
private val contentUploadStateTrackerBinder: ContentUploadStateTrackerBinder,
|
||||
private val noticeItemFactory: NoticeItemFactory,
|
||||
private val dimensionUtils: DimensionUtils) {
|
||||
private val dimensionConverter: DimensionConverter) {
|
||||
|
||||
|
||||
fun create(event: TimelineEvent,
|
||||
|
@ -116,7 +116,7 @@ class MessageItemFactory @Inject constructor(
|
|||
return MessageFileItem_()
|
||||
.avatarRenderer(avatarRenderer)
|
||||
.colorProvider(colorProvider)
|
||||
.dimensionUtils(dimensionUtils)
|
||||
.dimensionConverter(dimensionConverter)
|
||||
.informationData(informationData)
|
||||
.highlighted(highlight)
|
||||
.avatarCallback(callback)
|
||||
|
@ -146,7 +146,7 @@ class MessageItemFactory @Inject constructor(
|
|||
return MessageFileItem_()
|
||||
.avatarRenderer(avatarRenderer)
|
||||
.colorProvider(colorProvider)
|
||||
.dimensionUtils(dimensionUtils)
|
||||
.dimensionConverter(dimensionConverter)
|
||||
.informationData(informationData)
|
||||
.highlighted(highlight)
|
||||
.avatarCallback(callback)
|
||||
|
@ -176,7 +176,7 @@ class MessageItemFactory @Inject constructor(
|
|||
return DefaultItem_()
|
||||
.text(text)
|
||||
.avatarRenderer(avatarRenderer)
|
||||
.dimensionUtils(dimensionUtils)
|
||||
.dimensionConverter(dimensionConverter)
|
||||
.highlighted(highlight)
|
||||
.informationData(informationData)
|
||||
.baseCallback(callback)
|
||||
|
@ -203,7 +203,7 @@ class MessageItemFactory @Inject constructor(
|
|||
return MessageImageVideoItem_()
|
||||
.avatarRenderer(avatarRenderer)
|
||||
.colorProvider(colorProvider)
|
||||
.dimensionUtils(dimensionUtils)
|
||||
.dimensionConverter(dimensionConverter)
|
||||
.imageContentRenderer(imageContentRenderer)
|
||||
.contentUploadStateTrackerBinder(contentUploadStateTrackerBinder)
|
||||
.playable(messageContent.info?.mimeType == "image/gif")
|
||||
|
@ -258,7 +258,7 @@ class MessageItemFactory @Inject constructor(
|
|||
.contentUploadStateTrackerBinder(contentUploadStateTrackerBinder)
|
||||
.avatarRenderer(avatarRenderer)
|
||||
.colorProvider(colorProvider)
|
||||
.dimensionUtils(dimensionUtils)
|
||||
.dimensionConverter(dimensionConverter)
|
||||
.playable(true)
|
||||
.informationData(informationData)
|
||||
.highlighted(highlight)
|
||||
|
@ -302,7 +302,7 @@ class MessageItemFactory @Inject constructor(
|
|||
.avatarRenderer(avatarRenderer)
|
||||
.informationData(informationData)
|
||||
.colorProvider(colorProvider)
|
||||
.dimensionUtils(dimensionUtils)
|
||||
.dimensionConverter(dimensionConverter)
|
||||
.highlighted(highlight)
|
||||
.avatarCallback(callback)
|
||||
.urlClickCallback(callback)
|
||||
|
@ -337,7 +337,7 @@ class MessageItemFactory @Inject constructor(
|
|||
Spanned.SPAN_INCLUSIVE_EXCLUSIVE)
|
||||
|
||||
// Note: text size is set to 14sp
|
||||
spannable.setSpan(AbsoluteSizeSpan(dimensionUtils.spToPx(13)), editStart, editEnd, Spanned.SPAN_INCLUSIVE_EXCLUSIVE)
|
||||
spannable.setSpan(AbsoluteSizeSpan(dimensionConverter.spToPx(13)), editStart, editEnd, Spanned.SPAN_INCLUSIVE_EXCLUSIVE)
|
||||
spannable.setSpan(object : ClickableSpan() {
|
||||
override fun onClick(widget: View?) {
|
||||
callback?.onEditedDecorationClicked(informationData)
|
||||
|
@ -370,7 +370,7 @@ class MessageItemFactory @Inject constructor(
|
|||
.avatarRenderer(avatarRenderer)
|
||||
.message(message)
|
||||
.colorProvider(colorProvider)
|
||||
.dimensionUtils(dimensionUtils)
|
||||
.dimensionConverter(dimensionConverter)
|
||||
.informationData(informationData)
|
||||
.highlighted(highlight)
|
||||
.avatarCallback(callback)
|
||||
|
@ -412,7 +412,7 @@ class MessageItemFactory @Inject constructor(
|
|||
}
|
||||
.avatarRenderer(avatarRenderer)
|
||||
.colorProvider(colorProvider)
|
||||
.dimensionUtils(dimensionUtils)
|
||||
.dimensionConverter(dimensionConverter)
|
||||
.informationData(informationData)
|
||||
.highlighted(highlight)
|
||||
.avatarCallback(callback)
|
||||
|
@ -436,7 +436,7 @@ class MessageItemFactory @Inject constructor(
|
|||
return RedactedMessageItem_()
|
||||
.avatarRenderer(avatarRenderer)
|
||||
.colorProvider(colorProvider)
|
||||
.dimensionUtils(dimensionUtils)
|
||||
.dimensionConverter(dimensionConverter)
|
||||
.informationData(informationData)
|
||||
.highlighted(highlight)
|
||||
.avatarCallback(callback)
|
||||
|
|
|
@ -17,7 +17,7 @@
|
|||
package im.vector.riotx.features.home.room.detail.timeline.factory
|
||||
|
||||
import im.vector.matrix.android.api.session.room.timeline.TimelineEvent
|
||||
import im.vector.riotx.core.utils.DimensionUtils
|
||||
import im.vector.riotx.core.utils.DimensionConverter
|
||||
import im.vector.riotx.features.home.AvatarRenderer
|
||||
import im.vector.riotx.features.home.room.detail.timeline.TimelineEventController
|
||||
import im.vector.riotx.features.home.room.detail.timeline.format.NoticeEventFormatter
|
||||
|
@ -29,7 +29,7 @@ import javax.inject.Inject
|
|||
class NoticeItemFactory @Inject constructor(private val eventFormatter: NoticeEventFormatter,
|
||||
private val avatarRenderer: AvatarRenderer,
|
||||
private val informationDataFactory: MessageInformationDataFactory,
|
||||
private val dimensionUtils: DimensionUtils) {
|
||||
private val dimensionConverter: DimensionConverter) {
|
||||
|
||||
fun create(event: TimelineEvent,
|
||||
highlight: Boolean,
|
||||
|
@ -39,7 +39,7 @@ class NoticeItemFactory @Inject constructor(private val eventFormatter: NoticeEv
|
|||
|
||||
return NoticeItem_()
|
||||
.avatarRenderer(avatarRenderer)
|
||||
.dimensionUtils(dimensionUtils)
|
||||
.dimensionConverter(dimensionConverter)
|
||||
.noticeText(formattedText)
|
||||
.highlighted(highlight)
|
||||
.informationData(informationData)
|
||||
|
|
|
@ -99,7 +99,7 @@ abstract class AbsMessageItem<H : AbsMessageItem.Holder> : BaseEventItem<H>() {
|
|||
super.bind(holder)
|
||||
if (informationData.showInformation) {
|
||||
holder.avatarImageView.layoutParams = holder.avatarImageView.layoutParams?.apply {
|
||||
val size = dimensionUtils.dpToPx(avatarStyle.avatarSizeDP)
|
||||
val size = dimensionConverter.dpToPx(avatarStyle.avatarSizeDP)
|
||||
height = size
|
||||
width = size
|
||||
}
|
||||
|
|
|
@ -25,7 +25,7 @@ import im.vector.riotx.core.epoxy.VectorEpoxyHolder
|
|||
import im.vector.riotx.core.epoxy.VectorEpoxyModel
|
||||
import im.vector.riotx.core.platform.CheckableView
|
||||
import im.vector.riotx.core.ui.views.ReadReceiptsView
|
||||
import im.vector.riotx.core.utils.DimensionUtils
|
||||
import im.vector.riotx.core.utils.DimensionConverter
|
||||
|
||||
/**
|
||||
* Children must override getViewType()
|
||||
|
@ -39,12 +39,12 @@ abstract class BaseEventItem<H : BaseEventItem.BaseHolder> : VectorEpoxyModel<H>
|
|||
var highlighted: Boolean = false
|
||||
|
||||
@EpoxyAttribute
|
||||
lateinit var dimensionUtils: DimensionUtils
|
||||
lateinit var dimensionConverter: DimensionConverter
|
||||
|
||||
override fun bind(holder: H) {
|
||||
super.bind(holder)
|
||||
//optimize?
|
||||
val px = dimensionUtils.dpToPx(avatarStyle.avatarSizeDP + 8)
|
||||
val px = dimensionConverter.dpToPx(avatarStyle.avatarSizeDP + 8)
|
||||
holder.leftGuideline.setGuidelineBegin(px)
|
||||
|
||||
holder.checkableBackground.isChecked = highlighted
|
||||
|
|
|
@ -32,14 +32,14 @@ import im.vector.matrix.android.internal.crypto.attachments.ElementToDecrypt
|
|||
import im.vector.riotx.core.di.ActiveSessionHolder
|
||||
import im.vector.riotx.core.glide.GlideApp
|
||||
import im.vector.riotx.core.glide.GlideRequest
|
||||
import im.vector.riotx.core.utils.DimensionUtils
|
||||
import im.vector.riotx.core.utils.DimensionConverter
|
||||
import kotlinx.android.parcel.Parcelize
|
||||
import timber.log.Timber
|
||||
import java.io.File
|
||||
import javax.inject.Inject
|
||||
|
||||
class ImageContentRenderer @Inject constructor(private val activeSessionHolder: ActiveSessionHolder,
|
||||
private val dimensionUtils: DimensionUtils) {
|
||||
private val dimensionConverter: DimensionConverter) {
|
||||
|
||||
@Parcelize
|
||||
data class Data(
|
||||
|
@ -71,7 +71,7 @@ class ImageContentRenderer @Inject constructor(private val activeSessionHolder:
|
|||
|
||||
createGlideRequest(data, mode, imageView, width, height)
|
||||
.dontAnimate()
|
||||
.transform(RoundedCorners(dimensionUtils.dpToPx(8)))
|
||||
.transform(RoundedCorners(dimensionConverter.dpToPx(8)))
|
||||
.thumbnail(0.3f)
|
||||
.into(imageView)
|
||||
|
||||
|
|
Loading…
Reference in a new issue