Skip to content

Commit 48de913

Browse files
committed
feat(DMCategories): add option to hide category if empty
1 parent a1e5808 commit 48de913

File tree

3 files changed

+23
-8
lines changed

3 files changed

+23
-8
lines changed

plugin/DMCategories/build.gradle.kts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,11 @@
1-
version = "1.1.2"
1+
version = "1.2.0"
22
description = "Adds the ability to create categories for DMs, which will come first in the list"
33

44
aliucord.changelog.set(
55
"""
6+
# 1.2.0
7+
* Added option to hide categories if they have no channels
8+
69
# 1.1.1
710
* Fixed a major bug which caused categories to disappear
811

plugin/DMCategories/src/main/kotlin/DMCategories.kt

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ class DMCategories : Plugin() {
4141

4242
private val SettingsAPI.showSelected: Boolean by settings.delegate(true)
4343
private val SettingsAPI.showUnread: Boolean by settings.delegate(false)
44+
private val SettingsAPI.hideEmpty: Boolean by settings.delegate(false)
4445

4546
init {
4647
settingsTab = SettingsTab(PluginSettings::class.java, SettingsTab.Type.BOTTOM_SHEET).withArgs(settings)
@@ -131,24 +132,24 @@ class DMCategories : Plugin() {
131132
}
132133

133134
@OptIn(ExperimentalStdlibApi::class)
134-
patcher.before<WidgetChannelsList>(
135-
"configureUI",
136-
WidgetChannelListModel::class.java
137-
) { (_, model: WidgetChannelListModel) ->
135+
patcher.before<WidgetChannelsList>("configureUI", WidgetChannelListModel::class.java) { (_, model: WidgetChannelListModel) ->
136+
// Only run if this is the DMs tab
138137
if (model.selectedGuild != null) return@before
139138

140139
// I hate this but it works
141140
if (categories.none { (userId) -> userId == Util.getCurrentId() }) return@before
142141

143142
val privateChannels = model.items.filterIsInstance<ChannelListItemPrivate>()
144-
val items = buildList(1000) {
143+
val items = buildList(100) {
145144
categories.forEach { category ->
146-
add(ChannelListItemDMCategory(category))
147-
148145
val channels = privateChannels.filter { channel ->
149146
channel.channel.id in category.channelIds
150147
}
151148

149+
if (settings.hideEmpty && channels.isEmpty()) return@forEach
150+
151+
add(ChannelListItemDMCategory(category))
152+
152153
model.items.removeAll(channels)
153154

154155
addAll(

plugin/DMCategories/src/main/kotlin/dmcategories/PluginSettings.kt

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import com.lytefast.flexinput.R
1212
class PluginSettings(private val settings: SettingsAPI) : BottomSheet() {
1313
private var SettingsAPI.showSelected: Boolean by settings.delegate(true)
1414
private var SettingsAPI.showUnread: Boolean by settings.delegate(false)
15+
private var SettingsAPI.hideEmpty: Boolean by settings.delegate(false)
1516

1617
override fun onViewCreated(view: View, bundle: Bundle?) {
1718
super.onViewCreated(view, bundle)
@@ -45,5 +46,15 @@ class PluginSettings(private val settings: SettingsAPI) : BottomSheet() {
4546
setOnCheckedListener { settings.showUnread = it }
4647
}
4748
)
49+
addView(
50+
Util.createSwitch(
51+
ctx,
52+
"Hide if empty",
53+
"Whether categories should be hidden if they have no channels"
54+
).apply {
55+
isChecked = settings.hideEmpty
56+
setOnCheckedListener { settings.hideEmpty = it }
57+
}
58+
)
4859
}
4960
}

0 commit comments

Comments
 (0)