Skip to content

feat: 聊天界面模型快速切换下拉框 + 切换提示优化#2

Merged
LangLang03 merged 1 commit into
LangLang03:masterfrom
iooxxh:model-quick-switch
Jun 13, 2026
Merged

feat: 聊天界面模型快速切换下拉框 + 切换提示优化#2
LangLang03 merged 1 commit into
LangLang03:masterfrom
iooxxh:model-quick-switch

Conversation

@iooxxh

@iooxxh iooxxh commented Jun 11, 2026

Copy link
Copy Markdown
Contributor

改动内容

新增功能

  • 聊天输入框区域新增模型快速切换下拉选择器(圆角按钮 + 图标箭头)
  • 下拉框显示模型名称 + 供应商标签,模型>8个自动滚动
  • 底部"管理模型..."入口,跳转到模型管理页面
  • 切换提示改为发送消息时检测,显示"模型已从 A 更改为 B。"

修复

  • 输入框获焦点时自动关闭弹窗,修复键盘遮挡导致弹窗残留的问题
  • 点击模型只切换不跳转,与模型管理页面完全分离
  • 修复 ToolCallUtils 测试在 Windows 上的路径问题

涉及文件(共 9 个)

  • ChatMessage.java — 新增 modelSwitchNotification 字段
  • ChatUiState.java — 新增 availableModels / selectedModelId
  • ChatUiStateAssembler.java — 传递模型列表到 UI
  • MainCoordinator.java — 发送时检测 + onModelQuickSwitch
  • ModelController.java — 新增 onModelQuickSwitch 接口
  • MainChatView.java — 回调适配
  • ComposerView.java — 模型选择器 UI + 焦点监听
  • ChatMessageListView.java — 模型切换通知渲染
  • ToolCallUtils.java — 修复 Windows 路径问题

构建验证

  • testDebugUnitTest — 136 tests, 0 failed
  • lintDebug — passed
  • assembleDebug — passed
  • assembleRelease — 需要 signing.properties,本地未配置

Summary by Sourcery

Add quick model switching and model change notifications to the chat UI, and refine tool handling and path utilities.

New Features:

  • Introduce a model quick-switch dropdown in the chat composer with model list and provider labels, plus an entry point to model management.
  • Display inline system-style messages in the conversation when the active model changes between user messages.

Bug Fixes:

  • Auto-dismiss chat popups when the input field gains focus to avoid lingering overlays, particularly with the keyboard.
  • Fix ToolCallUtils path normalization to behave correctly on Windows paths.

Enhancements:

  • Wire model quick-switch actions from the composer through the main view to the coordinator and model controller, decoupling quick switches from the model management screen.
  • Track the last-used model per conversation when sending messages and reset this state on new or loaded conversations.
  • Simplify tool handling by removing special-case image generation result handling and tightening agent tool category checks to exclude generate tools from explore mode.
  • Unify tool categorization by treating image generation tools as read tools for filtering and display.

- 新增模型快速切换下拉选择器(圆角按钮 + 图标箭头)
- 下拉框显示模型名称 + 供应商标签,模型>8个自动滚动
- 底部管理模型入口,跳转模型管理页面
- 切换提示改为发送时检测,显示模型已从 A 更改为 B
- 新增 ChatMessage.modelSwitchNotification 字段
- 输入框获焦点自动关闭弹窗,修复键盘遮挡问题
- 点击模型只切换不跳转,与模型管理页面完全分离
- 修复 ToolCallUtils 测试在 Windows 上的路径问题
@sourcery-ai

sourcery-ai Bot commented Jun 11, 2026

Copy link
Copy Markdown

Reviewer's Guide

Implements a quick model-switch dropdown in the chat composer, propagates selected model state and available models through the UI layer, adds in-chat model switch notification messages on send, decouples quick switch from the model management screen navigation, improves popup dismissal on input focus, and simplifies tool/image handling including a Windows‑safe path normalization fix.

Sequence diagram for quick model switch and notification on send

sequenceDiagram
    actor User
    participant ComposerView
    participant MainChatView
    participant MainCoordinator
    participant ModelRepository
    participant ChatUiStateAssembler
    participant ChatMessageListView

    %% Quick model switch via dropdown
    User->>ComposerView: tap modelSelectorButton
    ComposerView->>ComposerView: showModelPopup(anchor)
    User->>ComposerView: tap modelOptionRow
    ComposerView->>MainChatView: Listener.onModelQuickSwitch(modelId)
    MainChatView->>MainCoordinator: onModelQuickSwitch(modelId)
    MainCoordinator->>MainCoordinator: isStreaming() check
    MainCoordinator->>ModelRepository: setSelectedModelId(modelId)
    MainCoordinator->>ChatUiStateAssembler: assemble(...)
    ChatUiStateAssembler-->>MainCoordinator: ChatUiState(selectedModelId, availableModels)
    MainCoordinator-->>ComposerView: render(ChatUiState)
    ComposerView->>ComposerView: updateModelSelector()

    %% Notification on send after model change
    User->>ComposerView: press send
    ComposerView->>MainChatView: Listener.onSend(text, attachments)
    MainChatView->>MainCoordinator: onSendMessage(text, attachments)
    MainCoordinator->>MainCoordinator: currentModelId = selectedModel.getModelId()
    MainCoordinator->>MainCoordinator: [lastMessageModelId != "" && != currentModelId]
    MainCoordinator->>MainCoordinator: messages.add(ChatMessage.modelSwitchNotice(...))
    MainCoordinator->>MainCoordinator: persistCurrentConversation()
    MainCoordinator->>MainCoordinator: lastMessageModelId = currentModelId
    MainCoordinator-->>ChatMessageListView: render(messages)
    ChatMessageListView->>ChatMessageListView: message.isModelSwitchNotification()
    ChatMessageListView->>ChatMessageListView: createModelSwitchNotice(text)
Loading

File-Level Changes

Change Details Files
Add model selection state and available model list to ChatUiState and wire them from the model repository into the UI.
  • Introduce selectedModelId and availableModels fields on ChatUiState with an extended constructor and getters.
  • Update ChatUiStateAssembler to compute selectedModelId and fetch available models from the repository.
  • Refactor ChatUiState constructors into compact chained overloads while preserving default behavior.
app/src/main/java/cn/lineai/model/ChatUiState.java
app/src/main/java/cn/lineai/mvp/ChatUiStateAssembler.java
Implement a model quick-switch dropdown UI in the composer with scrollable model list, provider labels, and a manage-models entry.
  • Wrap the existing model label in a clickable rounded button with a chevron icon tied to a new PopupWindow for model selection.
  • Render model options with selection highlighting, a leading dot indicator, and provider label text, supporting scrolling when more than eight models exist.
  • Expose onModelQuickSwitch and onModelManageClick callbacks on ComposerView.Listener and disable/dim the selector while streaming.
  • Dismiss mode/model popups when the input gains focus to avoid lingering overlays.
app/src/main/java/cn/lineai/ui/component/ComposerView.java
Add model switch notification messages that appear in the chat message list when the model is changed between user sends.
  • Extend ChatMessage with a modelSwitchNotification field, accessor helpers, and a static factory method modelSwitchNotice.
  • Track lastMessageModelId in MainCoordinator and, on send, insert a model-switch notice message when the selected model changed since the last user message.
  • Reset lastMessageModelId on new conversation/load and persist conversations when adding switch notices.
  • Add a dedicated view type in ChatMessageListView to render centered, compact model switch notices and include the notification text in message equality checks.
app/src/main/java/cn/lineai/model/ChatMessage.java
app/src/main/java/cn/lineai/mvp/MainCoordinator.java
app/src/main/java/cn/lineai/ui/component/ChatMessageListView.java
Wire the quick model switch and manage-model entry from the chat UI into the presenter and model controller.
  • Forward ComposerView model quick-switch and manage-model callbacks from MainChatView to the presenter.
  • Extend ModelController with an onModelQuickSwitch method and implement it in MainCoordinator to update the repository selection and re-render when not streaming.
  • Add showModelManagement implementation in MainCoordinator to navigate to the models screen when requested from the composer dropdown.
app/src/main/java/cn/lineai/ui/MainChatView.java
app/src/main/java/cn/lineai/mvp/ModelController.java
app/src/main/java/cn/lineai/mvp/MainCoordinator.java
Adjust tool handling and path normalization, simplifying image tool behavior and fixing Windows path issues.
  • Remove special-casing of image_generation prompts from ToolCallUtils.displayInputLabel and fold image_generation into isReadTool, eliminating isImageGenerationTool.
  • Drop MainCoordinator logic that halted after image generation tool results and no longer passes the selected model into buildToolPrompt.
  • Update normalizePath in ToolCallUtils to handle Unix-style absolute paths explicitly before canonicalization to behave correctly on Windows paths.
app/src/main/java/cn/lineai/ui/component/toolcall/ToolCallUtils.java
app/src/main/java/cn/lineai/mvp/MainCoordinator.java

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

@sourcery-ai sourcery-ai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Hey - I've left some high level feedback:

  • The ChatUiState class is getting a large number of telescoping constructors with long parameter lists (especially the new one including selectedModelId and availableModels); consider introducing a builder/factory or a value object for the UI config to improve readability and reduce the chance of parameter-order bugs.
  • User-visible texts like the model switch notice ("模型已从 A 更改为 B。") and the "管理模型..." label are currently hard-coded in Java; consider moving them into localized string resources (or a centralized constants/strings helper) to keep presentation copy maintainable and easier to translate.
Prompt for AI Agents
Please address the comments from this code review:

## Overall Comments
- The `ChatUiState` class is getting a large number of telescoping constructors with long parameter lists (especially the new one including `selectedModelId` and `availableModels`); consider introducing a builder/factory or a value object for the UI config to improve readability and reduce the chance of parameter-order bugs.
- User-visible texts like the model switch notice (`"模型已从 A 更改为 B。"`) and the "管理模型..." label are currently hard-coded in Java; consider moving them into localized string resources (or a centralized constants/strings helper) to keep presentation copy maintainable and easier to translate.

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

@LangLang03 LangLang03 merged commit c864fc2 into LangLang03:master Jun 13, 2026
2 of 3 checks passed
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.

2 participants