diff --git a/plugin/FavoriteChannels/build.gradle.kts b/plugin/FavoriteChannels/build.gradle.kts index e592874..b923aea 100644 --- a/plugin/FavoriteChannels/build.gradle.kts +++ b/plugin/FavoriteChannels/build.gradle.kts @@ -1,12 +1,14 @@ -version = "1.1.0" +version = "1.1.1" description = "Add your favorite channels to the top of the channel list for easy access." aliucord.changelog.set( """ + # 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: This update will reset your favorite channels* *Note: There is currently a bug where channels will not show if the category they're in is collapsed* # 1.0.1 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 962d3fa..a98b464 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,17 +1,10 @@ package dev.zt64.aliucord.plugins.favoritechannels import android.content.Context -import android.content.res.ColorStateList -import android.view.View import android.view.ViewGroup -import android.widget.FrameLayout -import android.widget.ImageView import android.widget.LinearLayout import android.widget.TextView -import androidx.appcompat.content.res.AppCompatResources import androidx.core.content.ContextCompat -import androidx.core.widget.NestedScrollView -import androidx.fragment.app.FragmentManager import com.aliucord.annotations.AliucordPlugin import com.aliucord.entities.Plugin import com.aliucord.patcher.after @@ -19,53 +12,31 @@ import com.aliucord.patcher.before import com.aliucord.patcher.component1 import com.aliucord.patcher.component2 import com.aliucord.patcher.component3 -import com.aliucord.patcher.instead -import com.aliucord.utils.RxUtils -import com.aliucord.utils.RxUtils.switchMap import com.aliucord.wrappers.ChannelWrapper.Companion.id import com.aliucord.wrappers.ChannelWrapper.Companion.isDM import com.aliucord.wrappers.ChannelWrapper.Companion.parentId -import com.discord.api.channel.Channel import com.discord.databinding.WidgetChannelsListItemActionsBinding import com.discord.restapi.RestAPIParams -import com.discord.stores.StoreChannelsSelected -import com.discord.stores.StoreChannelsSelected.UserChannelSelection -import com.discord.stores.StoreGuildSelected -import com.discord.stores.StoreGuildSubscriptions -import com.discord.stores.StoreNavigation import com.discord.stores.StoreStream import com.discord.stores.StoreUserGuildSettings -import com.discord.utilities.collections.LeastRecentlyAddedSet import com.discord.utilities.color.ColorCompat -import com.discord.utilities.persister.Persister import com.discord.widgets.channels.list.WidgetChannelListModel -import com.discord.widgets.channels.list.`WidgetChannelListModel$Companion$guildListBuilder$$inlined$forEach$lambda$1$2` 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.items.ChannelListItemTextChannel import com.discord.widgets.channels.list.items.ChannelListItemThread -import com.discord.widgets.guilds.list.GuildListItem -import com.discord.widgets.guilds.list.GuildListViewHolder -import com.discord.widgets.guilds.list.WidgetGuildListAdapter -import com.discord.widgets.guilds.list.`WidgetGuildListAdapter$onCreateViewHolder$1` -import com.discord.widgets.guilds.list.WidgetGuildsListViewModel import com.lytefast.flexinput.R -import de.robv.android.xposed.XposedBridge 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 +private const val FLAG_FAVORITE = 1 shl 11 + @Suppress("MISSING_DEPENDENCY_SUPERCLASS") @AliucordPlugin(requiresRestart = true) class FavoriteChannels : Plugin() { - private val getBindingMethod = WidgetChannelsListItemChannelActions::class.java - .getDeclaredMethod("getBinding") - .apply { isAccessible = true } - - private fun WidgetChannelsListItemChannelActions.getBinding() = getBindingMethod(this) as WidgetChannelsListItemActionsBinding - init { settingsTab = SettingsTab(PluginSettings::class.java, SettingsTab.Type.BOTTOM_SHEET).withArgs(settings) } @@ -73,7 +44,9 @@ class FavoriteChannels : Plugin() { override fun start(context: Context) { val userGuildSettings = StoreStream.getUserGuildSettings() - StoreStream.getStoreChannelCategories().collapsedCategories + val getBindingMethod = WidgetChannelsListItemChannelActions::class.java + .getDeclaredMethod("getBinding") + .apply { isAccessible = true } patcher.after( "configureUI", @@ -82,13 +55,13 @@ class FavoriteChannels : Plugin() { // Only run in servers if (model.channel.isDM()) return@after - val root = getBinding().root as NestedScrollView - val ctx = root.context - val flags = userGuildSettings.guildSettings[model.guild.id] ?.channelOverrides ?.find { it.channelId == model.channel.id } - ?.flags ?: return@after + ?.flags ?: 0 + + val root = (getBindingMethod(this) as WidgetChannelsListItemActionsBinding).root as ViewGroup + val ctx = root.context (root.getChildAt(0) as LinearLayout).addView( TextView( @@ -98,7 +71,7 @@ class FavoriteChannels : Plugin() { R.i.UiKit_Settings_Item_Icon ).apply { if (flags and (1 shl 11) != 0) { - text = "Unfavorite" + text = "Remove from favorites" setOnClickListener { dismiss() @@ -108,7 +81,7 @@ class FavoriteChannels : Plugin() { model.guild.id, RestAPIParams.UserGuildSettings( model.channel.id, - RestAPIParams.UserGuildSettings.ChannelOverride(null, flags and (1 shl 11).inv()) + RestAPIParams.UserGuildSettings.ChannelOverride(null, flags and (FLAG_FAVORITE).inv()) ), StoreUserGuildSettings.SettingsUpdateType.CHANNEL ) @@ -125,7 +98,7 @@ class FavoriteChannels : Plugin() { null ) } else { - text = "Favorite" + text = "Add to favorites" setOnClickListener { dismiss() @@ -135,7 +108,7 @@ class FavoriteChannels : Plugin() { model.guild.id, RestAPIParams.UserGuildSettings( model.channel.id, - RestAPIParams.UserGuildSettings.ChannelOverride(null, flags or (1 shl 11)) + RestAPIParams.UserGuildSettings.ChannelOverride(null, flags or FLAG_FAVORITE) ), StoreUserGuildSettings.SettingsUpdateType.CHANNEL ) @@ -166,7 +139,7 @@ class FavoriteChannels : Plugin() { val favoriteChannels = userGuildSettings .guildSettings[model.selectedGuild.id] ?.channelOverrides - ?.mapNotNull { c -> c.channelId.takeIf { c.flags and (1 shl 11) != 0 } } + ?.mapNotNull { c -> c.channelId.takeIf { c.flags and FLAG_FAVORITE != 0 } } if (favoriteChannels.isNullOrEmpty()) return@before @@ -190,7 +163,7 @@ class FavoriteChannels : Plugin() { ) } - patcher.after( + patcher.before( "onCreateViewHolder", ViewGroup::class.java, Int::class.java @@ -198,7 +171,7 @@ class FavoriteChannels : Plugin() { param.result = when (type) { ChannelListItemFavoriteCategory.type -> ItemFavoriteCategory(this) ChannelListItemDivider.type -> ItemDivider(this) - else -> param.result + else -> return@before } } } diff --git a/plugin/FavoriteChannels/src/main/kotlin/dev/zt64/aliucord/plugins/favoritechannels/Util.kt b/plugin/FavoriteChannels/src/main/kotlin/dev/zt64/aliucord/plugins/favoritechannels/Util.kt deleted file mode 100644 index d7af9ba..0000000 --- a/plugin/FavoriteChannels/src/main/kotlin/dev/zt64/aliucord/plugins/favoritechannels/Util.kt +++ /dev/null @@ -1,20 +0,0 @@ -package dev.zt64.aliucord.plugins.favoritechannels - -import android.content.Context -import com.aliucord.Utils -import com.discord.stores.StoreStream -import com.discord.views.CheckedSetting - -@Suppress("MISSING_DEPENDENCY_SUPERCLASS") -object Util { - // Update the channel list causing a re-render - fun updateChannels() { - StoreStream.`access$getDispatcher$p`(StoreStream.getPresences().stream).schedule { - StoreStream.getChannels().markChanged() - } - } - - fun createSwitch(context: Context, text: String, subText: String): CheckedSetting { - return Utils.createCheckedSetting(context, CheckedSetting.ViewType.SWITCH, text, subText) - } -} \ No newline at end of file