Skip to content

Conversation

@sunkup
Copy link
Member

@sunkup sunkup commented Aug 21, 2025

Purpose

Enable user to add custom user agent per subscription.

Short description

  • add custom user agent column to subscription table
  • add text fields in AddSubscriptionScreen and EditSubscriptionScreen
  • save the UI changes to the database through AddSubscriptionModel and EditSubscriptionModel
  • load and save the custom user agent string from/to json export
  • use a hilt assisted factory to create AppHttpClient
  • log used custom user agent at validation
  • use ktor's user agent plugin to set the user agent instead of the interceptor

Note:
The network interceptor approach introduced with the switch to ktor would have never worked. Kind of nice we notice it before releasing that. When I checked the user agent string with the android studio network inspector it simply said ktor-client or similar. Now with the ktor user agent plugin it actually sends the right user agent.

Checklist

  • The PR has a proper title, description and label.
  • I have self-reviewed the PR.
  • I have added documentation to complex functions and functions that can be used by other modules.
  • I have added reasonable tests or consciously decided to not add tests.

@sunkup sunkup linked an issue Aug 21, 2025 that may be closed by this pull request
@sunkup sunkup self-assigned this Aug 21, 2025
@sunkup sunkup added the enhancement New feature or request label Aug 21, 2025
@sunkup sunkup added this to the 2.3.2 milestone Aug 21, 2025
@sunkup sunkup force-pushed the 655-custom-user-agent-string-per-subscription branch from a6fc5b3 to 597e129 Compare August 21, 2025 14:32
@sunkup sunkup changed the title 655 custom user agent string per subscription Allow user to set custom user agent per subscription Aug 21, 2025
@sunkup sunkup changed the title Allow user to set custom user agent per subscription Allow user to set custom user agent Aug 21, 2025
@sunkup sunkup force-pushed the 655-custom-user-agent-string-per-subscription branch from 597e129 to 80ecbb2 Compare August 21, 2025 14:35
@sunkup sunkup requested a review from Copilot August 21, 2025 14:57

This comment was marked as outdated.

@sunkup
Copy link
Member Author

sunkup commented Aug 21, 2025

@ArnyminerZ This is really a rushed minimal implementation. During the weekend please take a proper look and test everything well. I think it should work out, but I did for example not test the import/export. I would leave the extra microsoft user agent for a separate PR.

@sunkup sunkup requested a review from ArnyminerZ August 21, 2025 15:05
Copy link
Member

@ArnyminerZ ArnyminerZ left a comment

Choose a reason for hiding this comment

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

Migration works correctly, and so does import-export. Only major issue I see is the field emptying issue.

Network inspection shows the correct User Agent:

Screenshot Image

@sunkup sunkup requested a review from Copilot August 25, 2025 10:55
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR enables users to set custom user agents per subscription to better handle servers that require specific user agent strings for access. This addresses the issue where the ktor-client default user agent was being sent instead of the intended custom one.

  • Add custom user agent support to subscription data model and UI screens
  • Switch from OkHttp interceptor to ktor UserAgent plugin for proper user agent handling
  • Implement dependency injection factory pattern for AppHttpClient to support per-subscription configuration

Reviewed Changes

Copilot reviewed 18 out of 18 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
strings.xml Add UI strings for custom user agent input field
SubscriptionSettingsComposable.kt Add custom user agent text field to subscription settings
EnterUrlComposable.kt Add custom user agent input to URL entry form with advanced settings section
EditSubscriptionScreen.kt Pass custom user agent data through edit subscription flow
AddSubscriptionScreen.kt Pass custom user agent data through add subscription flow
ValidationUseCase.kt Update validation to use custom user agent via factory pattern
SubscriptionSettingsUseCase.kt Add custom user agent state management and validation logic
EditSubscriptionModel.kt Add custom user agent persistence for existing subscriptions
AddSubscriptionModel.kt Add custom user agent persistence for new subscriptions
Subscription.kt Add customUserAgent field to database entity and JSON serialization
AppDatabase.kt Bump database version for schema migration
ProcessEventsTask.kt Use factory to create HTTP client with subscription's custom user agent
HttpUtils.kt Refactor authentication check to general protocol validation
AppHttpClient.kt Convert to factory pattern with ktor UserAgent plugin instead of interceptor
Comments suppressed due to low confidence (1)

app/src/main/java/at/bitfire/icsdroid/ui/views/EnterUrlComposable.kt:316

  • The parameter name supportsAuthentication is misleading since it's being passed validUrlInput. Consider renaming the parameter to match its actual purpose or verify the correct value is being passed.
        error,

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

@sunkup sunkup requested a review from ArnyminerZ August 25, 2025 12:02
@sunkup sunkup marked this pull request as ready for review August 25, 2025 12:02
@sunkup sunkup marked this pull request as draft August 25, 2025 12:05
@sunkup sunkup removed the request for review from ArnyminerZ August 25, 2025 12:05
- Introduce `ToggleTextField` composable for toggling and setting custom user agent
- Update strings for custom user agent title, description, and placeholder
- Replace `ResourceInput` with `ToggleTextField` in `EnterUrlComposable`
@sunkup sunkup requested a review from ArnyminerZ August 25, 2025 13:23
@sunkup
Copy link
Member Author

sunkup commented Aug 25, 2025

@ArnyminerZ

Please take a look. I incorporated the requested changes and:

  • used a normal text field for the custom user agent input - I think we should leave ResourceInput reserved for the two different subscription address values.
  • Renamed the "supportsAuthentication" notion to "acceptedProtocol", because it actually checks just that and we can use it more broadly.
  • moved the custom user agent textfield into the hidden content section when adding URL
  • added an extra spacer for consistency
  • remove the companion object completely in AppHttpClient.
  • Only when adding subscription - hide the custom user agent textfield within another toggle option with UI logic only

@sunkup sunkup marked this pull request as ready for review August 25, 2025 13:37
Copy link
Member

@ArnyminerZ ArnyminerZ left a comment

Choose a reason for hiding this comment

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

Some small changes, but my problem is with the redesign, I mean, moving it into the Enter url composable. I don't understand why doubling the field:

It's here and here
Screenshot Screenshot

For me it's a bit odd to double the field, since they are also different (one has a toggle, and the other one doesn't)

@sunkup sunkup force-pushed the 655-custom-user-agent-string-per-subscription branch from 986a882 to f22737c Compare August 26, 2025 08:23
@sunkup
Copy link
Member Author

sunkup commented Aug 26, 2025

hmm yes. Makes absolute sense. Thank you for the thorough review 👍

@sunkup sunkup requested a review from ArnyminerZ August 26, 2025 09:25
Copy link
Member

@ArnyminerZ ArnyminerZ left a comment

Choose a reason for hiding this comment

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

Got to a quite big PR, but works well for me.

@sunkup sunkup merged commit 088a84c into dev Aug 27, 2025
7 checks passed
@sunkup sunkup deleted the 655-custom-user-agent-string-per-subscription branch August 27, 2025 12:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Custom user agent string per subscription

2 participants