Skip to content

Comments

[webhooks] add read-only list UI#222

Merged
capcom6 merged 2 commits intomasterfrom
issue/215-webhook-management-ui
May 14, 2025
Merged

[webhooks] add read-only list UI#222
capcom6 merged 2 commits intomasterfrom
issue/215-webhook-management-ui

Conversation

@capcom6
Copy link
Owner

@capcom6 capcom6 commented May 14, 2025

Summary by CodeRabbit

  • New Features

    • Introduced a dedicated Webhooks List screen displaying all registered webhooks with details such as ID, URL, event, and source.
    • Added a clickable preference in settings to access the Webhooks List.
    • Enabled copying of webhook IDs to the clipboard with a confirmation toast.
    • Added empty state messaging when no webhooks are present.
  • User Interface

    • Added new icons and layouts for displaying webhook lists and items.
    • Improved visual distinction between local and cloud webhooks.
  • Localization

    • Added new string resources for webhooks-related UI elements and messages.

@github-actions
Copy link
Contributor

github-actions bot commented May 14, 2025

🤖 Pull request artifacts

file commit
app-release.apk b35931f
app-release.aab b35931f

@capcom6 capcom6 force-pushed the issue/215-webhook-management-ui branch from 5e13045 to 80f7e79 Compare May 14, 2025 12:13
@coderabbitai
Copy link

coderabbitai bot commented May 14, 2025

Walkthrough

The changes introduce a new UI for displaying a list of registered webhooks, including a fragment, adapter, and associated layouts and icons. The data model for webhooks is extended to include a source field. Service and DAO layers are updated to support retrieving all webhooks or filtering by source. New string resources and a navigation preference are added for the webhooks list.

Changes

File(s) / Path(s) Change Summary
app/src/main/java/me/capcom/smsgateway/modules/gateway/workers/WebhooksUpdateWorker.kt Sets the source field to EntitySource.Cloud when constructing WebHookDTO in the toDTO() function.
app/src/main/java/me/capcom/smsgateway/modules/webhooks/WebHooksService.kt Changes select method to accept nullable EntitySource?; returns all webhooks if null, otherwise filters by source. Adds source property to WebHookDTO in select and replace methods. Updates method signature accordingly.
app/src/main/java/me/capcom/smsgateway/modules/webhooks/db/WebHooksDao.kt Adds a new method select() to retrieve all webhook records from the database table.
app/src/main/java/me/capcom/smsgateway/modules/webhooks/domain/WebHookDTO.kt Adds a new source: EntitySource property to the WebHookDTO data class and updates imports.
app/src/main/java/me/capcom/smsgateway/modules/webhooks/domain/WebHookEvent.kt Adds a constructor parameter value: String to the WebHookEvent enum; each constant now has an explicit string value.
app/src/main/java/me/capcom/smsgateway/ui/adapters/WebhookAdapter.kt Introduces a new WebhookAdapter class for displaying WebHookDTO items in a RecyclerView, including a diff callback and view holder logic for binding webhook data and handling clipboard copy on item click.
app/src/main/java/me/capcom/smsgateway/ui/settings/WebhooksListFragment.kt Adds a new WebhooksListFragment for displaying a list of webhooks using the adapter, with empty state handling and dependency injection of the service.
app/src/main/res/drawable-notnight/ic_webhooks_list.xml,
app/src/main/res/drawable/ic_webhooks_list.xml
Adds new vector drawable icons representing a webhook list, for use in the UI.
app/src/main/res/layout/fragment_webhooks_list.xml Adds a layout for the webhooks list fragment, including a RecyclerView and an empty state view.
app/src/main/res/layout/item_webhook.xml Adds a layout for individual webhook items, including fields for URL, ID, source, and event.
app/src/main/res/values/strings.xml Adds new string resources for the webhook list UI and adjusts formatting for readability.
app/src/main/res/xml/webhooks_preferences.xml Adds a new Preference element for navigating to the webhooks list fragment, with icon and summary/title.

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant WebhooksListFragment
    participant WebHooksService
    participant WebHooksDao
    participant RecyclerView/WebhookAdapter

    User->>WebhooksListFragment: Navigates to fragment (via settings)
    WebhooksListFragment->>WebHooksService: select(source = null)
    WebHooksService->>WebHooksDao: select() (fetch all webhooks)
    WebHooksDao-->>WebHooksService: List<WebHook>
    WebHooksService-->>WebhooksListFragment: List<WebHookDTO> (with source)
    WebhooksListFragment->>RecyclerView/WebhookAdapter: submitList(webhooks)
    RecyclerView/WebhookAdapter-->>User: Displays webhooks or empty state
    User->>RecyclerView/WebhookAdapter: Clicks webhook item
    RecyclerView/WebhookAdapter-->>User: Copies webhook ID to clipboard, shows toast
Loading

Tip

⚡️ Faster reviews with caching
  • CodeRabbit now supports caching for code and dependencies, helping speed up reviews. This means quicker feedback, reduced wait times, and a smoother review experience overall. Cached data is encrypted and stored securely. This feature will be automatically enabled for all accounts on May 16th. To opt out, configure Review - Disable Cache at either the organization or repository level. If you prefer to disable all data retention across your organization, simply turn off the Data Retention setting under your Organization Settings.

Enjoy the performance boost—your workflow just got faster.


📜 Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 80f7e79 and b35931f.

📒 Files selected for processing (10)
  • app/src/main/java/me/capcom/smsgateway/modules/webhooks/db/WebHooksDao.kt (1 hunks)
  • app/src/main/java/me/capcom/smsgateway/modules/webhooks/domain/WebHookEvent.kt (1 hunks)
  • app/src/main/java/me/capcom/smsgateway/ui/adapters/WebhookAdapter.kt (1 hunks)
  • app/src/main/java/me/capcom/smsgateway/ui/settings/WebhooksListFragment.kt (1 hunks)
  • app/src/main/res/drawable-notnight/ic_webhooks_list.xml (1 hunks)
  • app/src/main/res/drawable/ic_webhooks_list.xml (1 hunks)
  • app/src/main/res/layout/fragment_webhooks_list.xml (1 hunks)
  • app/src/main/res/layout/item_webhook.xml (1 hunks)
  • app/src/main/res/values/strings.xml (5 hunks)
  • app/src/main/res/xml/webhooks_preferences.xml (1 hunks)
✅ Files skipped from review due to trivial changes (2)
  • app/src/main/res/layout/fragment_webhooks_list.xml
  • app/src/main/res/layout/item_webhook.xml
🚧 Files skipped from review as they are similar to previous changes (8)
  • app/src/main/java/me/capcom/smsgateway/modules/webhooks/db/WebHooksDao.kt
  • app/src/main/res/drawable-notnight/ic_webhooks_list.xml
  • app/src/main/res/drawable/ic_webhooks_list.xml
  • app/src/main/java/me/capcom/smsgateway/modules/webhooks/domain/WebHookEvent.kt
  • app/src/main/res/xml/webhooks_preferences.xml
  • app/src/main/java/me/capcom/smsgateway/ui/settings/WebhooksListFragment.kt
  • app/src/main/java/me/capcom/smsgateway/ui/adapters/WebhookAdapter.kt
  • app/src/main/res/values/strings.xml
⏰ Context from checks skipped due to timeout of 90000ms (1)
  • GitHub Check: Build / build-apk
✨ Finishing Touches
  • 📝 Generate Docstrings

🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Explain this complex logic.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai explain this code block.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and explain its main purpose.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🧹 Nitpick comments (7)
app/src/main/res/layout/item_webhook.xml (3)

29-34: Add content description for accessibility.

The ImageView is missing a content description, which is required for screen readers to properly describe this element to users with visual impairments.

<ImageView
    android:id="@+id/sourceIcon"
    android:layout_width="24dp"
    android:layout_height="24dp"
    android:layout_marginEnd="8dp"
+   android:contentDescription="@string/webhook_source_icon_description"
    android:src="@drawable/ic_local_server" />

2-7: Consider using ConstraintLayout for better performance.

While LinearLayout works for this simple case, ConstraintLayout would be more efficient for list items, especially since you're already using nested layouts.

-<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
+<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
+    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
-    android:orientation="vertical"
    android:padding="8dp">

The child views would then need to be constrained appropriately using ConstraintLayout attributes.


7-7: Use dimension resources for consistency.

Replace hardcoded padding values with dimension resources for better maintainability and consistency across the app.

-    android:padding="8dp">
+    android:padding="@dimen/list_item_padding">
app/src/main/res/xml/webhooks_preferences.xml (1)

25-29: Consider adding this preference within the existing PreferenceCategory

The new webhook list preference is currently defined outside any PreferenceCategory. For consistency with other webhook-related settings, consider moving this preference inside the existing "webhooks" PreferenceCategory (lines 4-24).

This would group all webhook-related preferences together in the UI, improving user experience and navigation.

 <?xml version="1.0" encoding="utf-8"?>
 <androidx.preference.PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android"
     xmlns:app="http://schemas.android.com/apk/res-auto">
     <PreferenceCategory app:title="@string/webhooks">
         <SwitchPreference
             android:icon="@drawable/ic_no_internet"
             android:defaultValue="true"
             android:key="webhooks.internet_required"
             app:summary="@string/the_webhook_request_will_wait_for_an_internet_connection"
             app:title="@string/require_internet_connection" />
         <EditTextPreference
             android:icon="@drawable/ic_retry"
             android:key="webhooks.retry_count"
             app:title="@string/retry_count"
             app:defaultValue="15"
             app:useSimpleSummaryProvider="true" />

         <EditTextPreference
             android:icon="@drawable/ic_signing_key"
             app:enableCopying="true"
             app:key="webhooks.signing_key"
             app:title="@string/signing_key"
             app:useSimpleSummaryProvider="true" />
+        <Preference
+            android:icon="@drawable/ic_webhooks_list"
+            app:fragment="me.capcom.smsgateway.ui.settings.WebhooksListFragment"
+            app:summary="@string/webhook_list_summary"
+            app:title="@string/webhook_list_title" />
     </PreferenceCategory>
-    <Preference
-        android:icon="@drawable/ic_webhooks_list"
-        app:fragment="me.capcom.smsgateway.ui.settings.WebhooksListFragment"
-        app:summary="@string/webhook_list_summary"
-        app:title="@string/webhook_list_title" />
 </androidx.preference.PreferenceScreen>
app/src/main/res/layout/fragment_webhooks_list.xml (1)

16-36: Add content description for empty state icon.

The ImageView is missing a content description, which is needed for accessibility. Users with screen readers will not get proper information about this icon.

<ImageView
    android:layout_width="48dp"
    android:layout_height="48dp"
-   android:src="@drawable/ic_webhook" />
+   android:src="@drawable/ic_webhook"
+   android:contentDescription="@string/webhooks" />
app/src/main/java/me/capcom/smsgateway/ui/adapters/WebhookAdapter.kt (1)

16-36: Extract hardcoded strings and simplify entity source references.

There are a few improvements that could make this adapter more maintainable:

  1. The "ID: " prefix should be in string resources
  2. Fully qualified references to EntitySource are repeated many times
+import me.capcom.smsgateway.domain.EntitySource

class WebhookAdapter : ListAdapter<WebHookDTO, WebhookAdapter.ViewHolder>(WebhookDiffCallback()) {
    class ViewHolder(private val binding: ItemWebhookBinding) :
        RecyclerView.ViewHolder(binding.root) {
        fun bind(webhook: WebHookDTO) {
            binding.apply {
-               idText.text = "ID: ${webhook.id}"
+               idText.text = binding.root.context.getString(R.string.webhook_id_format, webhook.id)
                urlText.text = webhook.url
                eventText.text = webhook.event.value
                sourceText.text = when (webhook.source) {
-                   me.capcom.smsgateway.domain.EntitySource.Local -> "Local"
-                   me.capcom.smsgateway.domain.EntitySource.Gateway, me.capcom.smsgateway.domain.EntitySource.Cloud -> "Cloud"
+                   EntitySource.Local -> binding.root.context.getString(R.string.local)
+                   EntitySource.Gateway, EntitySource.Cloud -> binding.root.context.getString(R.string.cloud_server)
                }
                sourceIcon.setImageResource(
                    when (webhook.source) {
-                       me.capcom.smsgateway.domain.EntitySource.Local -> R.drawable.ic_local_server
-                       me.capcom.smsgateway.domain.EntitySource.Cloud, me.capcom.smsgateway.domain.EntitySource.Gateway -> R.drawable.ic_cloud_server
+                       EntitySource.Local -> R.drawable.ic_local_server
+                       EntitySource.Gateway, EntitySource.Cloud -> R.drawable.ic_cloud_server
                    }
                )
            }
        }
    }

You'll need to add the following string resource:

<string name="webhook_id_format">ID: %1$s</string>
app/src/main/java/me/capcom/smsgateway/ui/settings/WebhooksListFragment.kt (1)

1-56: Consider adding refresh functionality and handling configuration changes.

The fragment currently doesn't have a way to refresh data when webhooks change while the fragment is visible. Additionally, consider using a ViewModel to handle configuration changes more efficiently.

You could implement a swipe-to-refresh layout or observe changes from a LiveData/Flow source:

// Example addition to implement refresh functionality
private fun setupObservers() {
    lifecycleScope.launch {
        repeatOnLifecycle(Lifecycle.State.STARTED) {
            webhookService.observeWebhooks().collect { webhooks ->
                adapter.submitList(webhooks)
                updateVisibility(webhooks)
            }
        }
    }
}

private fun updateVisibility(webhooks: List<WebhookDTO>?) {
    binding.emptyState.visibility = if (webhooks.isNullOrEmpty()) View.VISIBLE else View.GONE
    binding.webhookList.visibility = if (webhooks.isNullOrEmpty()) View.GONE else View.VISIBLE
}

This assumes webhookService provides a Flow of webhooks. If it doesn't, consider refactoring it to do so for better reactivity.

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between a6ec4ae and 80f7e79.

📒 Files selected for processing (13)
  • app/src/main/java/me/capcom/smsgateway/modules/gateway/workers/WebhooksUpdateWorker.kt (1 hunks)
  • app/src/main/java/me/capcom/smsgateway/modules/webhooks/WebHooksService.kt (2 hunks)
  • app/src/main/java/me/capcom/smsgateway/modules/webhooks/db/WebHooksDao.kt (1 hunks)
  • app/src/main/java/me/capcom/smsgateway/modules/webhooks/domain/WebHookDTO.kt (1 hunks)
  • app/src/main/java/me/capcom/smsgateway/modules/webhooks/domain/WebHookEvent.kt (1 hunks)
  • app/src/main/java/me/capcom/smsgateway/ui/adapters/WebhookAdapter.kt (1 hunks)
  • app/src/main/java/me/capcom/smsgateway/ui/settings/WebhooksListFragment.kt (1 hunks)
  • app/src/main/res/drawable-notnight/ic_webhooks_list.xml (1 hunks)
  • app/src/main/res/drawable/ic_webhooks_list.xml (1 hunks)
  • app/src/main/res/layout/fragment_webhooks_list.xml (1 hunks)
  • app/src/main/res/layout/item_webhook.xml (1 hunks)
  • app/src/main/res/values/strings.xml (5 hunks)
  • app/src/main/res/xml/webhooks_preferences.xml (1 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (1)
  • GitHub Check: Build / build-apk
🔇 Additional comments (18)
app/src/main/res/drawable/ic_webhooks_list.xml (1)

1-12: LGTM! Well-structured vector drawable for webhooks list.

The icon follows Material Design guidelines with appropriate dimensions (24dp x 24dp) and proper RTL support via auto-mirroring. The path data creates a recognizable list icon that's suitable for representing a collection of webhooks.

app/src/main/java/me/capcom/smsgateway/modules/webhooks/db/WebHooksDao.kt (1)

15-16: LGTM! Well-implemented DAO query method.

The added select() method follows the existing pattern in the DAO and provides a clean way to retrieve all webhooks without filtering. This complements the existing filtered query methods.

app/src/main/java/me/capcom/smsgateway/modules/webhooks/domain/WebHookDTO.kt (1)

3-9: LGTM! Good addition of source tracking.

Adding the source property to WebHookDTO enables valuable differentiation between local and cloud webhooks, which can be reflected in the UI and used for filtering operations.

app/src/main/java/me/capcom/smsgateway/modules/gateway/workers/WebhooksUpdateWorker.kt (1)

43-43: LGTM: Source correctly set for webhook DTOs

The addition of source = EntitySource.Cloud properly identifies webhooks synced from the cloud service, which is essential for the new webhook listing UI to correctly display the source of each webhook.

app/src/main/java/me/capcom/smsgateway/modules/webhooks/WebHooksService.kt (2)

35-47: LGTM: Well-implemented source filtering logic

The changes to make the source parameter nullable and handle it appropriately are well implemented. The when expression clearly handles both the null case (returning all webhooks) and the non-null case (filtering by source).


84-84: LGTM: Properly added source to DTO

Correctly added the source field to the WebHookDTO constructor, ensuring consistency with the changes in the select method.

app/src/main/res/drawable-notnight/ic_webhooks_list.xml (1)

1-12: LGTM: Well-structured vector drawable for webhook list

The vector drawable is properly formatted and follows Android best practices. The icon visually represents a list which is appropriate for the webhooks list feature.

app/src/main/java/me/capcom/smsgateway/modules/webhooks/domain/WebHookEvent.kt (1)

5-5: Good approach for exposing event values!

Adding the value parameter to the enum constructor provides a clean, type-safe way to access the serialized event names. This will make it easier to display these values in the UI and maintain consistency between serialization and display.

Also applies to: 7-7, 10-10, 13-13, 16-16, 19-19

app/src/main/res/values/strings.xml (2)

9-10: Formatting improvements to long string resources look good.

Breaking long strings into multiple lines improves readability of the XML source without affecting the string content.

Also applies to: 15-17, 61-62, 71-72, 105-110, 112-113


120-124: String resources for webhooks list UI look good.

The new string resources follow the project's naming conventions and provide clear, concise text for the webhooks list UI.

app/src/main/res/layout/fragment_webhooks_list.xml (1)

8-14: RecyclerView implementation looks good.

The RecyclerView is properly configured with padding and tool attributes for preview.

app/src/main/java/me/capcom/smsgateway/ui/adapters/WebhookAdapter.kt (2)

66-74: DiffUtil implementation looks correct.

Using ID comparison for item identity and full object comparison for content is a good approach.


46-57:

Details

❌ Incorrect review comment

Consider compatibility with Android 13+ for clipboard operations.

Starting with Android 13 (API 33), the system shows a clipboard access dialog when an app accesses the clipboard programmatically. Additionally, setPrimaryClip() behavior changes in Android 10+ to reduce unintended clipboard access.


🏁 Script executed:

#!/bin/bash
# Check the app's target SDK version to determine if we need to handle clipboard operations differently

grep -A 3 "compileSdk" app/build.gradle || grep -A 3 "compileSdkVersion" app/build.gradle

Length of output: 123


🏁 Script executed:

#!/bin/bash
# Verify the targetSdk setting to confirm Android 13 behavior applicability
grep -R "targetSdk" -n app/build.gradle

Length of output: 63


No Action Required: Clipboard write is unchanged on Android 13+
Writing to the clipboard via setPrimaryClip remains supported in API 33; only background reads incur new permission/dialog requirements. Since your compileSdk and targetSdk are both 33 and you’re only writing to the clipboard, no additional compatibility code is needed here.

Likely an incorrect or invalid review comment.

app/src/main/java/me/capcom/smsgateway/ui/settings/WebhooksListFragment.kt (5)

15-21: Good class structure and DI setup.

The fragment is well-structured with proper use of view binding pattern and dependency injection. The adapter is initialized early which is good for clarity.


22-29: View binding implementation looks good.

The onCreateView method correctly inflates the layout using view binding and returns the root view.


31-35: Lifecycle methods implementation is concise.

The onViewCreated method appropriately calls the required setup methods after calling the superclass method.


37-43: RecyclerView setup is well implemented.

Good use of Kotlin's apply scope function to keep the RecyclerView setup concise and readable.


52-55: Proper binding cleanup in onDestroyView.

Setting _binding to null in onDestroyView is a good practice to prevent memory leaks.

Comment on lines 45 to 51
private fun loadWebhooks() {
val webhooks = webhookService.select(null)
adapter.submitList(webhooks)
binding.emptyState.visibility = if (webhooks.isNullOrEmpty()) View.VISIBLE else View.GONE
binding.webhookList.visibility = if (webhooks.isNullOrEmpty()) View.GONE else View.VISIBLE
}
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛠️ Refactor suggestion

Consider loading webhooks asynchronously to avoid blocking the UI thread.

The current implementation appears to be loading webhooks synchronously, which could cause UI freezes if loading takes time. Also, there's no error handling if the webhook service call fails.

Consider using coroutines or another asynchronous approach:

-private fun loadWebhooks() {
-    val webhooks = webhookService.select(null)
-    adapter.submitList(webhooks)
-    binding.emptyState.visibility = if (webhooks.isNullOrEmpty()) View.VISIBLE else View.GONE
-    binding.webhookList.visibility = if (webhooks.isNullOrEmpty()) View.GONE else View.VISIBLE
-}
+private fun loadWebhooks() {
+    // Show loading state
+    binding.progressBar.visibility = View.VISIBLE
+    binding.emptyState.visibility = View.GONE
+    binding.webhookList.visibility = View.GONE
+    
+    lifecycleScope.launch {
+        try {
+            val webhooks = withContext(Dispatchers.IO) {
+                webhookService.select(null)
+            }
+            adapter.submitList(webhooks)
+            
+            // Update UI based on result
+            binding.progressBar.visibility = View.GONE
+            binding.emptyState.visibility = if (webhooks.isNullOrEmpty()) View.VISIBLE else View.GONE
+            binding.webhookList.visibility = if (webhooks.isNullOrEmpty()) View.GONE else View.VISIBLE
+        } catch (e: Exception) {
+            // Handle error
+            binding.progressBar.visibility = View.GONE
+            binding.emptyState.visibility = View.VISIBLE
+            binding.webhookList.visibility = View.GONE
+            // Show error message
+        }
+    }
+}

Note: This assumes you have a progress bar in your layout. If not, you'll need to add one.

🤖 Prompt for AI Agents (early access)
In app/src/main/java/me/capcom/smsgateway/ui/settings/WebhooksListFragment.kt
around lines 45 to 50, the loadWebhooks function loads data synchronously, which
can block the UI thread and lacks error handling. Refactor this method to use
Kotlin coroutines by launching a coroutine in the appropriate scope (e.g.,
lifecycleScope), perform the webhookService.select call asynchronously on a
background dispatcher, and update the UI on the main thread. Add error handling
to catch exceptions from the service call and update the UI accordingly.
Optionally, show and hide a progress bar during loading to improve user
experience.

@capcom6 capcom6 force-pushed the issue/215-webhook-management-ui branch from 80f7e79 to b35931f Compare May 14, 2025 13:03
@capcom6 capcom6 merged commit 9d5cc83 into master May 14, 2025
3 checks passed
@capcom6 capcom6 deleted the issue/215-webhook-management-ui branch May 14, 2025 23:12
@capcom6 capcom6 linked an issue May 15, 2025 that may be closed by this pull request
@coderabbitai coderabbitai bot mentioned this pull request Dec 2, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Improve Webhook Management

1 participant