-
Notifications
You must be signed in to change notification settings - Fork 909
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Show on App Launch: Setting screen (#4950)
Task/Issue URL: https://app.asana.com/0/1207908166761516/1208156273709081/f ### Description Adds the UI for the Show on App Launch settings screen and allows switching options. Nothing is stored and no validation. I moved RadioListItem to the `common-ui` module seeing as it’s now being used in multiple places. [Designs](https://www.figma.com/design/N2GbF5HEvopp5iwmAlMwyD/New-Tab-Page-Customization?node-id=1741-64495&t=SpS14wACEtPydb2z-4) ### Steps to test this PR - [x] Open Settings - [x] Open General section - [x] Click “Show on App Launch” - [x] Ensure each setting can be switched - [x] Ensure the TextInput for the “Specific Page” option is only visible when selected - [x] Ensure you cannot do multiple lines when entering a URL for “Specific Page" ### UI changes [Screen_recording_20240828_162354.webm](https://github.com/user-attachments/assets/7e45b454-2bd3-455b-af19-499ac19cabfa) --------- Co-authored-by: Marcos Holgado <marcosh@duckduckgo.com> Co-authored-by: Dax The Translator <daxmobile@duckduckgo.com>
- Loading branch information
1 parent
03f047d
commit 811fdf5
Showing
59 changed files
with
1,534 additions
and
44 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
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
135 changes: 135 additions & 0 deletions
135
...c/main/java/com/duckduckgo/app/generalsettings/showonapplaunch/ShowOnAppLaunchActivity.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,135 @@ | ||
/* | ||
* Copyright (c) 2024 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.generalsettings.showonapplaunch | ||
|
||
import android.os.Bundle | ||
import android.view.MenuItem | ||
import androidx.lifecycle.Lifecycle | ||
import androidx.lifecycle.flowWithLifecycle | ||
import androidx.lifecycle.lifecycleScope | ||
import com.duckduckgo.anvil.annotations.ContributeToActivityStarter | ||
import com.duckduckgo.anvil.annotations.InjectWith | ||
import com.duckduckgo.app.browser.databinding.ActivityShowOnAppLaunchSettingBinding | ||
import com.duckduckgo.app.generalsettings.showonapplaunch.model.ShowOnAppLaunchOption.LastOpenedTab | ||
import com.duckduckgo.app.generalsettings.showonapplaunch.model.ShowOnAppLaunchOption.NewTabPage | ||
import com.duckduckgo.app.generalsettings.showonapplaunch.model.ShowOnAppLaunchOption.SpecificPage | ||
import com.duckduckgo.common.ui.DuckDuckGoActivity | ||
import com.duckduckgo.common.ui.viewbinding.viewBinding | ||
import com.duckduckgo.di.scopes.ActivityScope | ||
import kotlinx.coroutines.flow.launchIn | ||
import kotlinx.coroutines.flow.onEach | ||
|
||
@InjectWith(ActivityScope::class) | ||
@ContributeToActivityStarter(ShowOnAppLaunchScreenNoParams::class) | ||
class ShowOnAppLaunchActivity : DuckDuckGoActivity() { | ||
|
||
private val viewModel: ShowOnAppLaunchViewModel by bindViewModel() | ||
private val binding: ActivityShowOnAppLaunchSettingBinding by viewBinding() | ||
|
||
override fun onCreate(savedInstanceState: Bundle?) { | ||
super.onCreate(savedInstanceState) | ||
|
||
setContentView(binding.root) | ||
setupToolbar(binding.includeToolbar.toolbar) | ||
|
||
binding.specificPageUrlInput.setSelectAllOnFocus(true) | ||
|
||
configureUiEventHandlers() | ||
observeViewModel() | ||
} | ||
|
||
override fun onPause() { | ||
super.onPause() | ||
viewModel.setSpecificPageUrl(binding.specificPageUrlInput.text) | ||
} | ||
|
||
override fun onOptionsItemSelected(item: MenuItem): Boolean { | ||
return when (item.itemId) { | ||
android.R.id.home -> { | ||
finish() | ||
overridePendingTransition(android.R.anim.fade_in, android.R.anim.fade_out) | ||
true | ||
} | ||
else -> super.onOptionsItemSelected(item) | ||
} | ||
} | ||
|
||
private fun configureUiEventHandlers() { | ||
binding.lastOpenedTabCheckListItem.setClickListener { | ||
viewModel.onShowOnAppLaunchOptionChanged(LastOpenedTab) | ||
} | ||
|
||
binding.newTabCheckListItem.setClickListener { | ||
viewModel.onShowOnAppLaunchOptionChanged(NewTabPage) | ||
} | ||
|
||
binding.specificPageCheckListItem.setClickListener { | ||
viewModel.onShowOnAppLaunchOptionChanged(SpecificPage(binding.specificPageUrlInput.text)) | ||
} | ||
|
||
binding.specificPageUrlInput.addFocusChangedListener { _, hasFocus -> | ||
if (hasFocus) { | ||
viewModel.onShowOnAppLaunchOptionChanged( | ||
SpecificPage(binding.specificPageUrlInput.text), | ||
) | ||
} | ||
} | ||
} | ||
|
||
private fun observeViewModel() { | ||
viewModel.viewState | ||
.flowWithLifecycle(lifecycle, Lifecycle.State.STARTED) | ||
.onEach { viewState -> | ||
when (viewState.selectedOption) { | ||
LastOpenedTab -> { | ||
uncheckNewTabCheckListItem() | ||
uncheckSpecificPageCheckListItem() | ||
binding.lastOpenedTabCheckListItem.setChecked(true) | ||
} | ||
NewTabPage -> { | ||
uncheckLastOpenedTabCheckListItem() | ||
uncheckSpecificPageCheckListItem() | ||
binding.newTabCheckListItem.setChecked(true) | ||
} | ||
is SpecificPage -> { | ||
uncheckLastOpenedTabCheckListItem() | ||
uncheckNewTabCheckListItem() | ||
binding.specificPageCheckListItem.setChecked(true) | ||
} | ||
} | ||
|
||
if (binding.specificPageUrlInput.text != viewState.specificPageUrl) { | ||
binding.specificPageUrlInput.text = viewState.specificPageUrl | ||
} | ||
} | ||
.launchIn(lifecycleScope) | ||
} | ||
|
||
private fun uncheckLastOpenedTabCheckListItem() { | ||
binding.lastOpenedTabCheckListItem.setChecked(false) | ||
} | ||
|
||
private fun uncheckNewTabCheckListItem() { | ||
binding.newTabCheckListItem.setChecked(false) | ||
} | ||
|
||
private fun uncheckSpecificPageCheckListItem() { | ||
binding.specificPageCheckListItem.setChecked(false) | ||
binding.specificPageUrlInput.isEditable = false | ||
binding.specificPageUrlInput.isEditable = true | ||
} | ||
} |
24 changes: 24 additions & 0 deletions
24
...rc/main/java/com/duckduckgo/app/generalsettings/showonapplaunch/ShowOnAppLaunchScreens.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,24 @@ | ||
/* | ||
* Copyright (c) 2024 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.generalsettings.showonapplaunch | ||
|
||
import com.duckduckgo.navigation.api.GlobalActivityStarter.ActivityParams | ||
|
||
/** | ||
* Use this model to launch the Show On App Launch screen | ||
*/ | ||
object ShowOnAppLaunchScreenNoParams : ActivityParams |
Oops, something went wrong.