From 2552245b442a06379dac7e6783528de76ce63e43 Mon Sep 17 00:00:00 2001 From: C10udburst <18114966+C10udburst@users.noreply.github.com> Date: Fri, 8 Oct 2021 20:51:29 +0200 Subject: [PATCH] #3 --- EditWebhooks/build.gradle.kts | 2 +- .../src/main/java/com/aliucord/plugins/EditWebhooks.kt | 2 +- .../main/java/com/aliucord/plugins/ui/WebhookList.kt | 10 ++++++++-- .../main/java/com/aliucord/plugins/ui/WebhookMenu.kt | 9 +++++++-- .../com/aliucord/plugins/ui/WebhookRecyclerAdapter.kt | 6 +++--- SendEmbeds/build.gradle.kts | 2 +- .../src/main/java/com/aliucord/plugins/SendEmbeds.kt | 2 +- 7 files changed, 22 insertions(+), 11 deletions(-) diff --git a/EditWebhooks/build.gradle.kts b/EditWebhooks/build.gradle.kts index ca0da8f..eb3a66c 100644 --- a/EditWebhooks/build.gradle.kts +++ b/EditWebhooks/build.gradle.kts @@ -1,2 +1,2 @@ -version = "1.0.4" +version = "1.0.5" description = "Edit Webhooks." diff --git a/EditWebhooks/src/main/java/com/aliucord/plugins/EditWebhooks.kt b/EditWebhooks/src/main/java/com/aliucord/plugins/EditWebhooks.kt index c85cf0d..a5b98ec 100644 --- a/EditWebhooks/src/main/java/com/aliucord/plugins/EditWebhooks.kt +++ b/EditWebhooks/src/main/java/com/aliucord/plugins/EditWebhooks.kt @@ -37,7 +37,7 @@ import com.aliucord.plugins.ui.WebhookList class EditWebhooks : Plugin() { @SuppressLint("SetTextI18n") override fun start(context: Context) { - val iconLeft = ContextCompat.getDrawable(context, R.d.ic_qr_code_24dp) + val iconLeft = ContextCompat.getDrawable(context, R.d.ic_send_24dp) val iconRight = ContextCompat.getDrawable(context, R.d.icon_carrot) val editWebooksId = View.generateViewId() diff --git a/EditWebhooks/src/main/java/com/aliucord/plugins/ui/WebhookList.kt b/EditWebhooks/src/main/java/com/aliucord/plugins/ui/WebhookList.kt index efe7fdc..46f0c14 100644 --- a/EditWebhooks/src/main/java/com/aliucord/plugins/ui/WebhookList.kt +++ b/EditWebhooks/src/main/java/com/aliucord/plugins/ui/WebhookList.kt @@ -30,8 +30,12 @@ class WebhookList(val channel: Channel) : SettingsPage() { override fun onViewBound(view: View) { super.onViewBound(view) setActionBarTitle(channel.m()) - val context = requireContext() + + fetchList() + } + public fun fetchList() { + val context = requireContext() Utils.threadPool.execute { val list = Http.Request("https://discord.com/api/v9/channels/%d/webhooks".format(channel.h()), "GET") .setHeader("Authorization", ReflectUtils.getField(StoreStream.getAuthentication(), "authToken") as String?) @@ -44,6 +48,7 @@ class WebhookList(val channel: Channel) : SettingsPage() { Utils.mainThread.post { + clear() val shape = ShapeDrawable(RectShape()) .apply { setTint(Color.TRANSPARENT) @@ -59,7 +64,7 @@ class WebhookList(val channel: Channel) : SettingsPage() { val recyclerView = RecyclerView(context) .apply { - adapter = WebhookRecyclerAdapter(list.toList(), parentFragmentManager) + adapter = WebhookRecyclerAdapter(list.toList(), this@WebhookList) layoutManager = LinearLayoutManager(context, RecyclerView.VERTICAL, false) addItemDecoration(decoration) } @@ -97,5 +102,6 @@ class WebhookList(val channel: Channel) : SettingsPage() { .setHeader("Accept", "*/*") .executeWithJson(WebhookRequest(name)) Utils.showToast(context, "Webhook created") + fetchList() } } \ No newline at end of file diff --git a/EditWebhooks/src/main/java/com/aliucord/plugins/ui/WebhookMenu.kt b/EditWebhooks/src/main/java/com/aliucord/plugins/ui/WebhookMenu.kt index bd36397..c5a6e99 100644 --- a/EditWebhooks/src/main/java/com/aliucord/plugins/ui/WebhookMenu.kt +++ b/EditWebhooks/src/main/java/com/aliucord/plugins/ui/WebhookMenu.kt @@ -29,9 +29,13 @@ import com.discord.api.message.attachment.MessageAttachment import com.discord.utilities.SnowflakeUtils import com.discord.widgets.chat.list.adapter.WidgetChatListAdapterItemAttachment -class WebhookMenu(private val webhook: Webhook) : AppBottomSheet() { - +import com.aliucord.plugins.ui.WebhookList +class WebhookMenu( + private val webhook: Webhook, + private val parent: WebhookList +) : AppBottomSheet() { + override fun getContentViewResId() = 0 override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, bundle: Bundle?): View { @@ -105,6 +109,7 @@ class WebhookMenu(private val webhook: Webhook) : AppBottomSheet() { .setHeader("Accept", "*/*") .execute() Utils.showToast(context, "Webhook deleted") + parent.fetchList() dismiss() } diff --git a/EditWebhooks/src/main/java/com/aliucord/plugins/ui/WebhookRecyclerAdapter.kt b/EditWebhooks/src/main/java/com/aliucord/plugins/ui/WebhookRecyclerAdapter.kt index 44de8b7..4aa1ae4 100644 --- a/EditWebhooks/src/main/java/com/aliucord/plugins/ui/WebhookRecyclerAdapter.kt +++ b/EditWebhooks/src/main/java/com/aliucord/plugins/ui/WebhookRecyclerAdapter.kt @@ -8,16 +8,16 @@ import androidx.recyclerview.widget.RecyclerView import android.widget.TextView import com.lytefast.flexinput.R import com.aliucord.plugins.utils.Webhook -import androidx.fragment.app.FragmentManager import com.aliucord.Utils import android.view.LayoutInflater import android.widget.RelativeLayout import com.discord.utilities.icon.IconUtils import com.discord.utilities.color.ColorCompat +import com.aliucord.plugins.ui.WebhookList class WebhookRecyclerAdapter( private val webhooks: List, - private val fragmentManager: FragmentManager + private val parent: WebhookList ) : RecyclerView.Adapter() { private val layoutId = Utils.getResId("widget_user_profile_adapter_item_server", "layout") @@ -39,6 +39,6 @@ class WebhookRecyclerAdapter( } fun onClick(position: Int) = webhooks.elementAt(position).let { - WebhookMenu(it).show(Utils.appActivity.supportFragmentManager, it.name) + WebhookMenu(it, parent).show(parent.parentFragmentManager, it.name) } } \ No newline at end of file diff --git a/SendEmbeds/build.gradle.kts b/SendEmbeds/build.gradle.kts index 829dbae..075996f 100644 --- a/SendEmbeds/build.gradle.kts +++ b/SendEmbeds/build.gradle.kts @@ -1,2 +1,2 @@ -version = "1.1.0" +version = "1.1.1" description = "Send embed messages with /embed or with a button." diff --git a/SendEmbeds/src/main/java/com/aliucord/plugins/SendEmbeds.kt b/SendEmbeds/src/main/java/com/aliucord/plugins/SendEmbeds.kt index 4fc7bf2..14663c7 100644 --- a/SendEmbeds/src/main/java/com/aliucord/plugins/SendEmbeds.kt +++ b/SendEmbeds/src/main/java/com/aliucord/plugins/SendEmbeds.kt @@ -39,7 +39,7 @@ class SendEmbeds : Plugin() { } override fun start(context: Context) { - val icon = ContextCompat.getDrawable(context, R.d.ic_qr_code_24dp) + val icon = ContextCompat.getDrawable(context, R.d.ic_embed_white_24dp) Utils.tintToTheme(icon).setAlpha(0x99); commands.registerCommand(