-
Notifications
You must be signed in to change notification settings - Fork 928
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: General settings entry point (#4946)
Task/Issue URL: https://app.asana.com/0/1207908166761516/1208156273709078/f Adds the “Show on App Launch” entry point in the General settings screen. We will likely not use a `String` to determine the secondary text but this makes it easier for step by step implementation. [Designs](https://www.figma.com/design/N2GbF5HEvopp5iwmAlMwyD/New-Tab-Page-Customization?node-id=1741-64494&t=SpS14wACEtPydb2z-4) - [x] Open settings - [x] Click “General” - [x] Check “Show on App Launch” is bottom of the list | Before | After | | ------ | ----- | | ![image](https://github.com/user-attachments/assets/d0026bad-e17d-47aa-9eae-2f853669a6a9) | ![image](https://github.com/user-attachments/assets/f031338b-9feb-4cc4-86a1-67ba9a11df58) | --------- Co-authored-by: Marcos Holgado <[email protected]> Co-authored-by: Dax The Translator <[email protected]>
- Loading branch information
1 parent
5e6a526
commit b88274f
Showing
59 changed files
with
1,594 additions
and
38 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 | ||
} | ||
} |
Oops, something went wrong.