-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Wire per-row Rename in chat history overflow menu #8599
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
ade9ce5
Wire per-row Rename in chat history overflow menu
GerardPaligot fd27916
Fix Rename Chat single-line input and surface persistence failures
GerardPaligot ebe1873
Stop swallowing CancellationException on rename
GerardPaligot 5ccbaa1
Surface rename failure as a Boolean instead of an exception
GerardPaligot c62b930
Match rename-menu string names to how they are used
GerardPaligot File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
120 changes: 120 additions & 0 deletions
120
...at/duckchat-impl/src/main/java/com/duckduckgo/duckchat/impl/history/RenameChatFragment.kt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,120 @@ | ||
| /* | ||
| * Copyright (c) 2026 DuckDuckGo | ||
| * | ||
| * Licensed under the Apache License, Version 2.0 (the "License"); | ||
| * you may not use this file except in compliance with the License. | ||
| * You may obtain a copy of the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, software | ||
| * distributed under the License is distributed on an "AS IS" BASIS, | ||
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| * See the License for the specific language governing permissions and | ||
| * limitations under the License. | ||
| */ | ||
|
|
||
| package com.duckduckgo.duckchat.impl.history | ||
|
|
||
| import android.os.Bundle | ||
| import android.text.Editable | ||
| import android.view.View | ||
| import androidx.lifecycle.Lifecycle | ||
| import androidx.lifecycle.ViewModelProvider | ||
| import androidx.lifecycle.flowWithLifecycle | ||
| import androidx.lifecycle.lifecycleScope | ||
| import com.duckduckgo.anvil.annotations.InjectWith | ||
| import com.duckduckgo.common.ui.DuckDuckGoFragment | ||
| import com.duckduckgo.common.ui.viewbinding.viewBinding | ||
| import com.duckduckgo.common.utils.FragmentViewModelFactory | ||
| import com.duckduckgo.common.utils.extensions.hideKeyboard | ||
| import com.duckduckgo.common.utils.text.TextChangedWatcher | ||
| import com.duckduckgo.di.scopes.FragmentScope | ||
| import com.duckduckgo.duckchat.impl.R | ||
| import com.duckduckgo.duckchat.impl.databinding.FragmentRenameChatBinding | ||
| import com.google.android.material.snackbar.Snackbar | ||
| import kotlinx.coroutines.flow.launchIn | ||
| import kotlinx.coroutines.flow.onEach | ||
| import javax.inject.Inject | ||
|
|
||
| @InjectWith(FragmentScope::class) | ||
| class RenameChatFragment : DuckDuckGoFragment(R.layout.fragment_rename_chat) { | ||
|
|
||
| @Inject | ||
| lateinit var viewModelFactory: FragmentViewModelFactory | ||
|
|
||
| private val binding: FragmentRenameChatBinding by viewBinding() | ||
| private val viewModel: RenameChatViewModel by lazy { | ||
| ViewModelProvider(this, viewModelFactory)[RenameChatViewModel::class.java] | ||
| } | ||
|
|
||
| private val chatId: String by lazy { checkNotNull(requireArguments().getString(ARG_CHAT_ID)) } | ||
| private val initialTitle: String by lazy { requireArguments().getString(ARG_CURRENT_TITLE).orEmpty() } | ||
|
|
||
| override fun onViewCreated(view: View, savedInstanceState: Bundle?) { | ||
| super.onViewCreated(view, savedInstanceState) | ||
|
|
||
| binding.toolbar.setTitle(R.string.duck_ai_chat_history_rename_title) | ||
| binding.toolbar.setNavigationIcon(com.duckduckgo.mobile.android.R.drawable.ic_arrow_left_24) | ||
| binding.toolbar.setNavigationOnClickListener { dismiss() } | ||
| binding.toolbar.inflateMenu(R.menu.menu_rename_chat) | ||
| binding.toolbar.setOnMenuItemClickListener { item -> | ||
| if (item.itemId == R.id.action_rename_confirm) { | ||
| onConfirmClicked() | ||
| true | ||
| } else { | ||
| false | ||
| } | ||
| } | ||
|
|
||
| binding.titleInput.text = initialTitle | ||
| binding.titleInput.addTextChangedListener(titleTextWatcher) | ||
| binding.titleInput.showKeyboardDelayed() | ||
| setConfirmEnabled(false) | ||
|
|
||
| viewModel.results | ||
| .flowWithLifecycle(viewLifecycleOwner.lifecycle, Lifecycle.State.STARTED) | ||
| .onEach(::onRenameResult) | ||
| .launchIn(viewLifecycleOwner.lifecycleScope) | ||
| } | ||
|
|
||
| private fun onConfirmClicked() { | ||
| viewModel.onSaveClicked(chatId, binding.titleInput.text) | ||
| } | ||
|
|
||
| private fun onRenameResult(result: RenameChatViewModel.RenameResult) { | ||
| when (result) { | ||
| RenameChatViewModel.RenameResult.Success -> dismiss() | ||
| RenameChatViewModel.RenameResult.Error -> | ||
| Snackbar.make(binding.root, R.string.duck_ai_chat_history_rename_error, Snackbar.LENGTH_SHORT).show() | ||
| } | ||
| } | ||
|
|
||
| private fun dismiss() { | ||
| requireActivity().hideKeyboard() | ||
| parentFragmentManager.popBackStack() | ||
| } | ||
|
|
||
| private fun setConfirmEnabled(enabled: Boolean) { | ||
| binding.toolbar.menu.findItem(R.id.action_rename_confirm)?.isEnabled = enabled | ||
| } | ||
|
|
||
| private val titleTextWatcher = object : TextChangedWatcher() { | ||
| override fun afterTextChanged(editable: Editable) { | ||
| val candidate = editable.toString().trim() | ||
| setConfirmEnabled(candidate.isNotBlank() && candidate != initialTitle.trim()) | ||
| } | ||
| } | ||
|
|
||
| companion object { | ||
| private const val ARG_CHAT_ID = "arg_chat_id" | ||
| private const val ARG_CURRENT_TITLE = "arg_current_title" | ||
|
|
||
| fun newInstance(chatId: String, currentTitle: String): RenameChatFragment = RenameChatFragment().apply { | ||
| arguments = Bundle().apply { | ||
| putString(ARG_CHAT_ID, chatId) | ||
| putString(ARG_CURRENT_TITLE, currentTitle) | ||
| } | ||
| } | ||
| } | ||
| } |
58 changes: 58 additions & 0 deletions
58
...t/duckchat-impl/src/main/java/com/duckduckgo/duckchat/impl/history/RenameChatViewModel.kt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,58 @@ | ||
| /* | ||
| * Copyright (c) 2026 DuckDuckGo | ||
| * | ||
| * Licensed under the Apache License, Version 2.0 (the "License"); | ||
| * you may not use this file except in compliance with the License. | ||
| * You may obtain a copy of the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, software | ||
| * distributed under the License is distributed on an "AS IS" BASIS, | ||
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| * See the License for the specific language governing permissions and | ||
| * limitations under the License. | ||
| */ | ||
|
|
||
| package com.duckduckgo.duckchat.impl.history | ||
|
|
||
| import androidx.lifecycle.ViewModel | ||
| import com.duckduckgo.anvil.annotations.ContributesViewModel | ||
| import com.duckduckgo.app.di.AppCoroutineScope | ||
| import com.duckduckgo.di.scopes.FragmentScope | ||
| import kotlinx.coroutines.CancellationException | ||
| import kotlinx.coroutines.CoroutineScope | ||
| import kotlinx.coroutines.channels.BufferOverflow | ||
| import kotlinx.coroutines.channels.Channel | ||
| import kotlinx.coroutines.flow.Flow | ||
| import kotlinx.coroutines.flow.receiveAsFlow | ||
| import kotlinx.coroutines.launch | ||
| import javax.inject.Inject | ||
|
|
||
| @ContributesViewModel(FragmentScope::class) | ||
| class RenameChatViewModel @Inject constructor( | ||
| private val chatHistoryRepository: ChatHistoryRepository, | ||
| @AppCoroutineScope private val appScope: CoroutineScope, | ||
| ) : ViewModel() { | ||
|
|
||
| private val resultChannel = Channel<RenameResult>(capacity = Channel.BUFFERED, onBufferOverflow = BufferOverflow.DROP_OLDEST) | ||
| val results: Flow<RenameResult> = resultChannel.receiveAsFlow() | ||
|
|
||
| fun onSaveClicked(chatId: String, newTitle: String) { | ||
| appScope.launch { | ||
| val outcome = try { | ||
| if (chatHistoryRepository.renameChat(chatId, newTitle.trim())) RenameResult.Success else RenameResult.Error | ||
| } catch (e: CancellationException) { | ||
| throw e | ||
| } catch (e: Exception) { | ||
| RenameResult.Error | ||
| } | ||
| resultChannel.trySend(outcome) | ||
| } | ||
| } | ||
|
|
||
| sealed interface RenameResult { | ||
| data object Success : RenameResult | ||
| data object Error : RenameResult | ||
| } | ||
| } |
53 changes: 53 additions & 0 deletions
53
duckchat/duckchat-impl/src/main/res/layout/fragment_rename_chat.xml
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,53 @@ | ||
| <?xml version="1.0" encoding="utf-8"?><!-- | ||
| ~ Copyright (c) 2026 DuckDuckGo | ||
| ~ | ||
| ~ Licensed under the Apache License, Version 2.0 (the "License"); | ||
| ~ you may not use this file except in compliance with the License. | ||
| ~ You may obtain a copy of the License at | ||
| ~ | ||
| ~ http://www.apache.org/licenses/LICENSE-2.0 | ||
| ~ | ||
| ~ Unless required by applicable law or agreed to in writing, software | ||
| ~ distributed under the License is distributed on an "AS IS" BASIS, | ||
| ~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| ~ See the License for the specific language governing permissions and | ||
| ~ limitations under the License. | ||
| --> | ||
|
|
||
| <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="match_parent" | ||
| tools:context="com.duckduckgo.duckchat.impl.history.RenameChatFragment"> | ||
|
|
||
| <com.google.android.material.appbar.AppBarLayout | ||
| android:id="@+id/appBarLayout" | ||
| android:layout_width="match_parent" | ||
| android:layout_height="wrap_content" | ||
| android:theme="@style/Widget.DuckDuckGo.ToolbarTheme" | ||
| app:layout_constraintStart_toStartOf="parent" | ||
| app:layout_constraintTop_toTopOf="parent"> | ||
|
|
||
| <androidx.appcompat.widget.Toolbar | ||
| android:id="@+id/toolbar" | ||
| android:layout_width="match_parent" | ||
| android:layout_height="?attr/actionBarSize" | ||
| android:background="?attr/daxColorToolbar" | ||
| android:theme="@style/Widget.DuckDuckGo.ToolbarTheme" | ||
| app:popupTheme="@style/Widget.DuckDuckGo.PopUpOverflowMenu" /> | ||
| </com.google.android.material.appbar.AppBarLayout> | ||
|
|
||
| <com.duckduckgo.common.ui.view.text.DaxTextInput | ||
| android:id="@+id/titleInput" | ||
| android:layout_width="match_parent" | ||
| android:layout_height="wrap_content" | ||
| android:layout_margin="@dimen/keyline_4" | ||
| android:hint="@string/duck_ai_chat_history_rename_chat_title_hint" | ||
| app:capitalizeKeyboard="true" | ||
| app:layout_constraintEnd_toEndOf="parent" | ||
| app:layout_constraintStart_toStartOf="parent" | ||
| app:layout_constraintTop_toBottomOf="@id/appBarLayout" | ||
| app:type="single_line" /> | ||
|
|
||
| </androidx.constraintlayout.widget.ConstraintLayout> | ||
26 changes: 26 additions & 0 deletions
26
duckchat/duckchat-impl/src/main/res/menu/menu_rename_chat.xml
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,26 @@ | ||
| <?xml version="1.0" encoding="utf-8"?><!-- | ||
| ~ Copyright (c) 2026 DuckDuckGo | ||
| ~ | ||
| ~ Licensed under the Apache License, Version 2.0 (the "License"); | ||
| ~ you may not use this file except in compliance with the License. | ||
| ~ You may obtain a copy of the License at | ||
| ~ | ||
| ~ http://www.apache.org/licenses/LICENSE-2.0 | ||
| ~ | ||
| ~ Unless required by applicable law or agreed to in writing, software | ||
| ~ distributed under the License is distributed on an "AS IS" BASIS, | ||
| ~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| ~ See the License for the specific language governing permissions and | ||
| ~ limitations under the License. | ||
| --> | ||
|
|
||
| <menu xmlns:android="http://schemas.android.com/apk/res/android" | ||
| xmlns:app="http://schemas.android.com/apk/res-auto"> | ||
| <item | ||
| android:id="@+id/action_rename_confirm" | ||
| android:contentDescription="@string/duck_ai_chat_history_rename_confirm_content_description" | ||
| android:enabled="false" | ||
| android:icon="@drawable/ic_check_24" | ||
| android:title="@string/duck_ai_chat_history_rename_confirm_title" | ||
| app:showAsAction="always" /> | ||
| </menu> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.