diff --git a/plugin/FavoriteChannels/build.gradle.kts b/plugin/FavoriteChannels/build.gradle.kts index b923aea..013d4b7 100644 --- a/plugin/FavoriteChannels/build.gradle.kts +++ b/plugin/FavoriteChannels/build.gradle.kts @@ -1,19 +1,20 @@ -version = "1.1.1" +version = "1.1.2" description = "Add your favorite channels to the top of the channel list for easy access." aliucord.changelog.set( """ + # 1.1.2 + - Fixed favorited channels being hidden if their parent category is collapsed + # 1.1.1 - Fixed improper handling of channels causing the button to not get displayed - + # 1.1.0 - Switched to using Discord's API for syncing favorite channels - - *Note: There is currently a bug where channels will not show if the category they're in is collapsed* - + # 1.0.1 - Fixed threads not moving along with their parent channels - + # 1.0.0 - Initial release """.trimIndent() diff --git a/plugin/FavoriteChannels/src/main/kotlin/dev/zt64/aliucord/plugins/favoritechannels/FavoriteChannels.kt b/plugin/FavoriteChannels/src/main/kotlin/dev/zt64/aliucord/plugins/favoritechannels/FavoriteChannels.kt index a98b464..3069a47 100644 --- a/plugin/FavoriteChannels/src/main/kotlin/dev/zt64/aliucord/plugins/favoritechannels/FavoriteChannels.kt +++ b/plugin/FavoriteChannels/src/main/kotlin/dev/zt64/aliucord/plugins/favoritechannels/FavoriteChannels.kt @@ -1,3 +1,5 @@ +@file:Suppress("MISSING_DEPENDENCY_CLASS") + package dev.zt64.aliucord.plugins.favoritechannels import android.content.Context @@ -7,11 +9,8 @@ import android.widget.TextView import androidx.core.content.ContextCompat import com.aliucord.annotations.AliucordPlugin import com.aliucord.entities.Plugin -import com.aliucord.patcher.after -import com.aliucord.patcher.before -import com.aliucord.patcher.component1 -import com.aliucord.patcher.component2 -import com.aliucord.patcher.component3 +import com.aliucord.patcher.* +import com.aliucord.wrappers.ChannelWrapper.Companion.guildId import com.aliucord.wrappers.ChannelWrapper.Companion.id import com.aliucord.wrappers.ChannelWrapper.Companion.isDM import com.aliucord.wrappers.ChannelWrapper.Companion.parentId @@ -20,17 +19,11 @@ import com.discord.restapi.RestAPIParams import com.discord.stores.StoreStream import com.discord.stores.StoreUserGuildSettings import com.discord.utilities.color.ColorCompat -import com.discord.widgets.channels.list.WidgetChannelListModel -import com.discord.widgets.channels.list.WidgetChannelsList -import com.discord.widgets.channels.list.WidgetChannelsListAdapter -import com.discord.widgets.channels.list.WidgetChannelsListItemChannelActions +import com.discord.widgets.channels.list.* import com.discord.widgets.channels.list.items.ChannelListItemTextChannel import com.discord.widgets.channels.list.items.ChannelListItemThread import com.lytefast.flexinput.R -import dev.zt64.aliucord.plugins.favoritechannels.items.ChannelListItemDivider -import dev.zt64.aliucord.plugins.favoritechannels.items.ChannelListItemFavoriteCategory -import dev.zt64.aliucord.plugins.favoritechannels.items.ItemDivider -import dev.zt64.aliucord.plugins.favoritechannels.items.ItemFavoriteCategory +import dev.zt64.aliucord.plugins.favoritechannels.items.* private const val FLAG_FAVORITE = 1 shl 11 @@ -48,6 +41,7 @@ class FavoriteChannels : Plugin() { .getDeclaredMethod("getBinding") .apply { isAccessible = true } + // Add favorite/unfavorite button to the channel item context menu patcher.after( "configureUI", WidgetChannelsListItemChannelActions.Model::class.java @@ -56,8 +50,7 @@ class FavoriteChannels : Plugin() { if (model.channel.isDM()) return@after val flags = userGuildSettings.guildSettings[model.guild.id] - ?.channelOverrides - ?.find { it.channelId == model.channel.id } + ?.getChannelOverride(model.channel.id) ?.flags ?: 0 val root = (getBindingMethod(this) as WidgetChannelsListItemActionsBinding).root as ViewGroup @@ -70,7 +63,7 @@ class FavoriteChannels : Plugin() { 0, R.i.UiKit_Settings_Item_Icon ).apply { - if (flags and (1 shl 11) != 0) { + if (flags and FLAG_FAVORITE != 0) { text = "Remove from favorites" setOnClickListener { dismiss() @@ -174,6 +167,31 @@ class FavoriteChannels : Plugin() { else -> return@before } } + + // This unholy patch makes it so that collapsed categories do not remove channels if they are favorited + @Suppress("CAST_NEVER_SUCCEEDS") + patcher.instead<`WidgetChannelListModel$Companion$guildListBuilder$$inlined$forEach$lambda$1$2`>("invoke") { + with((`this$0` as `WidgetChannelListModel$Companion$guildListBuilder$$inlined$forEach$lambda$1`)) { + val noMentions = `$mentionCount` <= 0 + val isCollapsed = `$textChannel`.parentId in `$collapsedCategories$inlined` + val isChannelOrChildFavorited = userGuildSettings.guildSettings[`$textChannel`.guildId] + ?.getChannelOverride(`$textChannelId`) + ?.let { it.flags and FLAG_FAVORITE != 0 } ?: false + val isChannelOrChildSelected = `$channelSelected` || + (`$areAnyChildThreadsSelected$5$inlined` as `WidgetChannelListModel$Companion$guildListBuilder$5`) + .invoke(`$textChannel`.id) + val areAllChildThreadsRead = (`$areAllChildThreadsRead$4$inlined` as `WidgetChannelListModel$Companion$guildListBuilder$4`) + .invoke(`$textChannel`.id) + val shouldHideChannel = (isCollapsed && noMentions && (`$isCategoryMuted` || `$isMuted` || !`$unread`)) || + (`$isMuted` && `$guild$inlined`.hideMutedChannels) + val shouldBeHidden = + !(isChannelOrChildFavorited || isChannelOrChildSelected || !areAllChildThreadsRead || !shouldHideChannel) + + if (shouldBeHidden) `$hiddenChannelsIds$inlined`.add(`$textChannelId`) + + shouldBeHidden + } + } } override fun stop(context: Context) = patcher.unpatchAll() diff --git a/plugin/FavoriteChannels/src/main/kotlin/dev/zt64/aliucord/plugins/favoritechannels/items/ItemDivider.kt b/plugin/FavoriteChannels/src/main/kotlin/dev/zt64/aliucord/plugins/favoritechannels/items/ItemDivider.kt index fc348b6..8dae375 100644 --- a/plugin/FavoriteChannels/src/main/kotlin/dev/zt64/aliucord/plugins/favoritechannels/items/ItemDivider.kt +++ b/plugin/FavoriteChannels/src/main/kotlin/dev/zt64/aliucord/plugins/favoritechannels/items/ItemDivider.kt @@ -13,7 +13,7 @@ object ChannelListItemDivider : ChannelListItem { class ItemDivider(adapter: WidgetChannelsListAdapter) : WidgetChannelsListAdapter.Item(Utils.getResId("widget_channels_list_item_stage_events_separator", "layout"), adapter) { - init { - itemView.layoutParams.height = 2.dp - } -} \ No newline at end of file + init { + itemView.layoutParams.height = 2.dp + } + } \ No newline at end of file diff --git a/plugin/FavoriteChannels/src/main/kotlin/dev/zt64/aliucord/plugins/favoritechannels/items/ItemFavoriteCategory.kt b/plugin/FavoriteChannels/src/main/kotlin/dev/zt64/aliucord/plugins/favoritechannels/items/ItemFavoriteCategory.kt index 4367a79..b05c1d0 100644 --- a/plugin/FavoriteChannels/src/main/kotlin/dev/zt64/aliucord/plugins/favoritechannels/items/ItemFavoriteCategory.kt +++ b/plugin/FavoriteChannels/src/main/kotlin/dev/zt64/aliucord/plugins/favoritechannels/items/ItemFavoriteCategory.kt @@ -15,25 +15,25 @@ object ChannelListItemFavoriteCategory : ChannelListItem { class ItemFavoriteCategory(adapter: WidgetChannelsListAdapter) : WidgetChannelsListAdapter.Item(Utils.getResId("widget_channels_list_item_category", "layout"), adapter) { - private val nameView = itemView.findViewById( - Utils.getResId("channels_item_category_name", "id") - ) + private val nameView = itemView.findViewById( + Utils.getResId("channels_item_category_name", "id") + ) - init { - itemView - .findViewById(Utils.getResId("channels_item_category_add", "id")) - .visibility = View.GONE + init { + itemView + .findViewById(Utils.getResId("channels_item_category_add", "id")) + .visibility = View.GONE - itemView - .findViewById(Utils.getResId("channels_item_category_arrow", "id")) - .visibility = View.INVISIBLE + itemView + .findViewById(Utils.getResId("channels_item_category_arrow", "id")) + .visibility = View.INVISIBLE - nameView.text = "Favorites" - } + nameView.text = "Favorites" + } - override fun onConfigure(i: Int, channelListItem: ChannelListItem) { - super.onConfigure(i, channelListItem) + override fun onConfigure(i: Int, channelListItem: ChannelListItem) { + super.onConfigure(i, channelListItem) - channelListItem as ChannelListItemFavoriteCategory - } -} \ No newline at end of file + channelListItem as ChannelListItemFavoriteCategory + } + } \ No newline at end of file