Skip to content

Commit efd60b1

Browse files
authored
fix(CompactMode): support new feature backports from core (#117)
* chore(deps): lock to kt1 aliucord core * fix(CompactMode): support avatar decorations * fix(CompactMode): support polls * refactor(deps): use different version ref names
1 parent b52f145 commit efd60b1

File tree

2 files changed

+60
-4
lines changed

2 files changed

+60
-4
lines changed

gradle/libs.versions.toml

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
[versions]
22
discord = "aliucord-SNAPSHOT"
3-
aliucord = "main-SNAPSHOT"
3+
aliucord-core = "2.4.0"
4+
aliucord-gradle = "753ad25"
45
#noinspection GradleDependency
56
kotlin = "1.5.21"
67
android = "7.4.2"
@@ -10,10 +11,10 @@ ktlint = "0.50.0"
1011

1112
[libraries]
1213
discord = { module = "com.discord:discord", version.ref = "discord" }
13-
aliucord = { module = "com.aliucord:Aliucord", version.ref = "aliucord" }
14+
aliucord = { module = "com.aliucord:Aliucord", version.ref = "aliucord-core" }
1415

1516
[plugins]
1617
android-library = { id = "com.android.library", version.ref = "android" }
1718
kotlin-android = { id = "org.jetbrains.kotlin.android", version.ref = "kotlin" }
18-
aliucord = { id = "com.aliucord.gradle", version.ref = "aliucord" }
19+
aliucord = { id = "com.aliucord.gradle", version.ref = "aliucord-gradle" }
1920
ktlint = { id = "org.jlleitschuh.gradle.ktlint", version.ref = "ktlintPlugin" }

plugin/CompactMode/src/main/kotlin/CompactMode.kt

Lines changed: 56 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -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

Comments
 (0)