@@ -56,6 +56,21 @@ class CompactMode : Plugin() {
5656 val usernameViewId = getResId(" chat_list_adapter_item_text_name" , " id" )
5757 val loadingTextId = getResId(" chat_list_adapter_item_text_loading" , " id" )
5858
59+ val avatarDecorationId = try {
60+ Class .forName(" com.aliucord.coreplugins.decorations.avatar.AvatarDecoratorKt" )
61+ .getDeclaredField(" decoId" )
62+ .also { it.isAccessible = true }
63+ .get(null ) as Int
64+ } catch (_: Throwable ) {
65+ null
66+ }
67+
68+ val pollsClass = try {
69+ Class .forName(" com.aliucord.coreplugins.polls.chatview.WidgetChatListAdapterItemPoll" )
70+ } catch (_: Throwable ) {
71+ null
72+ }
73+
5974 patcher.after<WidgetChatListItem >(
6075 " onConfigure" ,
6176 Int ::class .java,
@@ -73,6 +88,13 @@ class CompactMode : Plugin() {
7388 }
7489 }
7590
91+ if (pollsClass?.isInstance(this ) == true ) {
92+ itemView.run {
93+ setPadding(contentMargin, paddingTop, paddingRight, paddingBottom)
94+ }
95+ return @after
96+ }
97+
7698 val layoutParams = when (this ) {
7799 is WidgetChatListAdapterItemInvite ,
78100 is WidgetChatListAdapterItemStageInvite ,
@@ -101,13 +123,28 @@ class CompactMode : Plugin() {
101123 when (itemView.id) {
102124 // Regular message
103125 messageRootId -> {
126+ val avatarDecoration = avatarDecorationId?.let { itemView.findViewById<View ?>(it) }
127+ val decoEnabled = avatarDecoration != null
128+
104129 itemView
105130 .findViewById<View >(loadingTextId)
106131 .layoutParams<MarginLayoutParams >()
107132 .marginStart = 0
108133
109134 val headerView = itemView.findViewById<ConstraintLayout >(headerLayoutId)
110135
136+ // Reverts avatar decorator's top padding on header, so the avatar gets centred properly
137+ if (decoEnabled) {
138+ headerView.run {
139+ setPadding(
140+ paddingLeft,
141+ paddingTop - 6 .dp,
142+ paddingRight,
143+ paddingBottom
144+ )
145+ }
146+ }
147+
111148 itemView.findViewById<Guideline >(guidelineId).setGuidelineBegin(contentMargin)
112149 itemView.setPadding(0 , settings.messagePadding.dp, 0 , 0 )
113150
@@ -116,13 +153,26 @@ class CompactMode : Plugin() {
116153 }
117154 if (settings.hideAvatar) {
118155 avatarView!! .visibility = View .GONE
156+ avatarDecoration?.visibility = View .GONE
119157
120158 headerView.layoutParams<ConstraintLayout .LayoutParams >().marginStart = contentMargin
121159
122160 return @after
123161 }
124162
125- 2 .dp.let { dp -> avatarView!! .setPadding(dp, dp, dp, dp) }
163+ 2 .dp.let { dp ->
164+ val decoOffset = if (decoEnabled) {
165+ // Adds offset for decorations
166+ dp + (settings.avatarScale.dp / 11 )
167+ } else {
168+ dp
169+ }
170+ avatarView!! .setPadding(decoOffset, decoOffset, dp, dp)
171+ avatarDecoration?.layoutParams<MarginLayoutParams >()?.apply {
172+ topMargin = dp
173+ leftMargin = dp
174+ }
175+ }
126176
127177 val constraintLayout = itemView as ConstraintLayout
128178 val constraintSet = ConstraintSet ().apply {
@@ -134,6 +184,11 @@ class CompactMode : Plugin() {
134184 settings.avatarScale.dp.let { dp ->
135185 constrainWidth(id, dp)
136186 constrainHeight(id, dp)
187+ avatarDecorationId?.let { decoId ->
188+ val decoSize = dp * 12 / 11 - 4 .dp
189+ constrainWidth(decoId, decoSize)
190+ constrainHeight(decoId, decoSize)
191+ }
137192 }
138193
139194 setMargin(id, ConstraintSet .START , settings.headerMargin.dp)
0 commit comments