-
Notifications
You must be signed in to change notification settings - Fork 939
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add ability to generate Tabs from Developer Settings (#5653)
Task/Issue URL: https://app.asana.com/0/488551667048375/1209407906356235 ### Description Added a new developer settings screen for managing tabs, allowing developers to quickly create or clear multiple tabs for testing purposes. The screen includes functionality to specify the number of tabs to create and automatically generates tabs with random privacy-focused URLs. ### Steps to test this PR _Tab Management_ - [x] Access the new Tabs section from Developer Settings - [x] Enter a number of tabs to create and tap "Add Tabs" - [x] Verify tabs are created with random URLs from the predefined list - [x] Verify the tab count header updates correctly - [x] Test the "Clear Tabs" button removes all tabs - [x] Verify navigation and toolbar functionality works as expected ### UI changes https://github.com/user-attachments/assets/187de4a3-433d-497f-8782-f591a41ff59e
- Loading branch information
1 parent
1c15cb9
commit 5f5a0a7
Showing
8 changed files
with
310 additions
and
0 deletions.
There are no files selected for viewing
This file contains 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 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 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
79 changes: 79 additions & 0 deletions
79
app/src/internal/java/com/duckduckgo/app/dev/settings/tabs/DevTabsActivity.kt
This file contains 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,79 @@ | ||
/* | ||
* Copyright (c) 2025 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.app.dev.settings.tabs | ||
|
||
import android.content.Context | ||
import android.content.Intent | ||
import android.os.Bundle | ||
import androidx.lifecycle.Lifecycle.State.STARTED | ||
import androidx.lifecycle.flowWithLifecycle | ||
import androidx.lifecycle.lifecycleScope | ||
import com.duckduckgo.anvil.annotations.InjectWith | ||
import com.duckduckgo.app.browser.R | ||
import com.duckduckgo.app.browser.databinding.ActivityDevTabsBinding | ||
import com.duckduckgo.app.dev.settings.tabs.DevTabsViewModel.ViewState | ||
import com.duckduckgo.app.notification.NotificationFactory | ||
import com.duckduckgo.common.ui.DuckDuckGoActivity | ||
import com.duckduckgo.common.ui.viewbinding.viewBinding | ||
import com.duckduckgo.di.scopes.ActivityScope | ||
import javax.inject.Inject | ||
import kotlinx.coroutines.flow.launchIn | ||
import kotlinx.coroutines.flow.onEach | ||
|
||
@InjectWith(ActivityScope::class) | ||
class DevTabsActivity : DuckDuckGoActivity() { | ||
|
||
@Inject | ||
lateinit var viewModel: DevTabsViewModel | ||
|
||
@Inject | ||
lateinit var factory: NotificationFactory | ||
|
||
private val binding: ActivityDevTabsBinding by viewBinding() | ||
|
||
override fun onCreate(savedInstanceState: Bundle?) { | ||
super.onCreate(savedInstanceState) | ||
setContentView(binding.root) | ||
setupToolbar(binding.includeToolbar.toolbar) | ||
|
||
binding.addTabsButton.setOnClickListener { | ||
viewModel.addTabs(binding.tabCount.text.toString().toInt()) | ||
} | ||
|
||
binding.clearTabsButton.setOnClickListener { | ||
viewModel.clearTabs() | ||
} | ||
|
||
observeViewState() | ||
} | ||
|
||
private fun observeViewState() { | ||
viewModel.viewState.flowWithLifecycle(lifecycle, STARTED).onEach { render(it) } | ||
.launchIn(lifecycleScope) | ||
} | ||
|
||
private fun render(viewState: ViewState) { | ||
binding.tabCountHeader.text = getString(R.string.devSettingsTabsScreenHeader, viewState.tabCount) | ||
} | ||
|
||
companion object { | ||
|
||
fun intent(context: Context): Intent { | ||
return Intent(context, DevTabsActivity::class.java) | ||
} | ||
} | ||
} |
95 changes: 95 additions & 0 deletions
95
app/src/internal/java/com/duckduckgo/app/dev/settings/tabs/DevTabsViewModel.kt
This file contains 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,95 @@ | ||
/* | ||
* Copyright (c) 2025 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.app.dev.settings.tabs | ||
|
||
import androidx.lifecycle.ViewModel | ||
import androidx.lifecycle.viewModelScope | ||
import com.duckduckgo.anvil.annotations.ContributesViewModel | ||
import com.duckduckgo.app.tabs.model.TabDataRepository | ||
import com.duckduckgo.common.utils.DispatcherProvider | ||
import com.duckduckgo.di.scopes.ActivityScope | ||
import javax.inject.Inject | ||
import kotlinx.coroutines.flow.MutableStateFlow | ||
import kotlinx.coroutines.flow.asStateFlow | ||
import kotlinx.coroutines.flow.flowOn | ||
import kotlinx.coroutines.flow.launchIn | ||
import kotlinx.coroutines.flow.onEach | ||
import kotlinx.coroutines.flow.update | ||
import kotlinx.coroutines.launch | ||
|
||
private val randomUrls = listOf( | ||
"https://duckduckgo.com", | ||
"https://blog.duckduckgo.com", | ||
"https://duck.com", | ||
"https://privacy.com", | ||
"https://spreadprivacy.com", | ||
"https://wikipedia.org", | ||
"https://privacyguides.org", | ||
"https://tosdr.org", | ||
"https://signal.org", | ||
"https://eff.org", | ||
"https://fsf.org", | ||
"https://opensource.org", | ||
"https://archive.org", | ||
"https://torproject.org", | ||
"https://linux.org", | ||
"https://gnu.org", | ||
"https://apache.org", | ||
"https://debian.org", | ||
"https://ubuntu.com", | ||
"https://openbsd.org", | ||
) | ||
|
||
@ContributesViewModel(ActivityScope::class) | ||
class DevTabsViewModel @Inject constructor( | ||
private val dispatcher: DispatcherProvider, | ||
private val tabDataRepository: TabDataRepository, | ||
) : ViewModel() { | ||
|
||
data class ViewState( | ||
val tabCount: Int = 0, | ||
) | ||
|
||
private val _viewState = MutableStateFlow(ViewState()) | ||
val viewState = _viewState.asStateFlow() | ||
|
||
init { | ||
tabDataRepository.flowTabs | ||
.onEach { tabs -> | ||
_viewState.update { it.copy(tabCount = tabs.count()) } | ||
} | ||
.flowOn(dispatcher.io()) | ||
.launchIn(viewModelScope) | ||
} | ||
|
||
fun addTabs(count: Int) { | ||
viewModelScope.launch { | ||
repeat(count) { | ||
val randomIndex = randomUrls.indices.random() | ||
tabDataRepository.add( | ||
url = randomUrls[randomIndex], | ||
) | ||
} | ||
} | ||
} | ||
|
||
fun clearTabs() { | ||
viewModelScope.launch(dispatcher.io()) { | ||
tabDataRepository.deleteAll() | ||
} | ||
} | ||
} |
This file contains 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 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,104 @@ | ||
<?xml version="1.0" encoding="utf-8"?><!-- | ||
~ Copyright (c) 2025 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. | ||
--> | ||
|
||
<LinearLayout 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" | ||
android:orientation="vertical" | ||
tools:context="com.duckduckgo.app.dev.settings.notifications.NotificationsActivity"> | ||
|
||
<include | ||
android:id="@+id/includeToolbar" | ||
layout="@layout/include_default_toolbar" /> | ||
|
||
<LinearLayout | ||
android:layout_width="match_parent" | ||
android:layout_height="wrap_content" | ||
android:orientation="vertical"> | ||
|
||
<com.duckduckgo.common.ui.view.text.DaxTextView | ||
android:id="@+id/tabCountHeader" | ||
android:layout_width="match_parent" | ||
android:layout_height="48dp" | ||
android:gravity="center" | ||
android:text="@string/devSettingsTabsScreenHeader" | ||
app:typography="caption_allCaps" /> | ||
|
||
<Space | ||
android:layout_width="match_parent" | ||
android:layout_height="8dp" /> | ||
|
||
<androidx.constraintlayout.widget.ConstraintLayout | ||
android:layout_width="match_parent" | ||
android:layout_height="wrap_content"> | ||
|
||
<com.duckduckgo.common.ui.view.listitem.OneLineListItem | ||
android:id="@+id/generateTabsItem" | ||
android:layout_width="0dp" | ||
android:layout_height="wrap_content" | ||
app:layout_constraintEnd_toStartOf="@id/tabCount" | ||
app:layout_constraintStart_toStartOf="parent" | ||
app:layout_constraintTop_toTopOf="parent" | ||
app:primaryText="@string/devSettingsTabsScreenTabsToAdd" /> | ||
|
||
<com.duckduckgo.common.ui.view.text.DaxTextInput | ||
android:id="@+id/tabCount" | ||
style="@style/Widget.DuckDuckGo.TextInput" | ||
android:layout_width="72dp" | ||
android:layout_height="wrap_content" | ||
android:layout_marginEnd="@dimen/keyline_4" | ||
android:gravity="center" | ||
android:inputType="number" | ||
android:text="100" | ||
app:layout_constraintBottom_toBottomOf="@id/generateTabsItem" | ||
app:layout_constraintEnd_toEndOf="parent" | ||
app:layout_constraintStart_toEndOf="@id/generateTabsItem" | ||
app:layout_constraintTop_toTopOf="@id/generateTabsItem" | ||
app:type="single_line" | ||
tools:ignore="HardcodedText" /> | ||
|
||
<com.duckduckgo.common.ui.view.button.DaxButtonPrimary | ||
android:id="@+id/addTabsButton" | ||
android:layout_width="wrap_content" | ||
android:layout_height="wrap_content" | ||
android:layout_marginTop="@dimen/keyline_4" | ||
android:text="@string/devSettingsTabsScreenAddTabsButtonText" | ||
app:buttonSize="large" /> | ||
|
||
<com.duckduckgo.common.ui.view.button.DaxButtonPrimary | ||
android:id="@+id/clearTabsButton" | ||
android:layout_width="wrap_content" | ||
android:layout_height="wrap_content" | ||
android:layout_marginTop="@dimen/keyline_4" | ||
android:text="@string/devSettingsTabsScreenClearTabsButtonText" | ||
app:buttonSize="large" /> | ||
|
||
<androidx.constraintlayout.helper.widget.Flow | ||
android:id="@+id/flowView" | ||
android:layout_width="match_parent" | ||
android:layout_height="0dp" | ||
android:layout_marginTop="@dimen/keyline_4" | ||
app:constraint_referenced_ids="addTabsButton,clearTabsButton" | ||
app:flow_horizontalStyle="spread" | ||
app:flow_wrapMode="chain" | ||
app:layout_constraintTop_toBottomOf="@id/generateTabsItem" /> | ||
|
||
</androidx.constraintlayout.widget.ConstraintLayout> | ||
|
||
</LinearLayout> | ||
</LinearLayout> |
This file contains 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