Skip to content

Commit f61a3f8

Browse files
authored
Add hasContent param to NTP (#6543)
Task/Issue URL: https://app.asana.com/1/137249556945/project/488551667048375/task/1210986747757664?focus=true ### Description - Adds an optional `hasContent` callback to `NewTabPageView` in order to notify of content to the Input Screen. ### Steps to test this PR - [ ] Verify that NTP works as expected - [ ] Verify that the Search Tab on the Input Screen works as expected
1 parent e58ceed commit f61a3f8

File tree

6 files changed

+34
-9
lines changed

6 files changed

+34
-9
lines changed

app/src/main/java/com/duckduckgo/app/browser/newtab/NewTabLegacyPageView.kt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@ class NewTabLegacyPageView @JvmOverloads constructor(
7474
attrs: AttributeSet? = null,
7575
defStyle: Int = 0,
7676
private val showLogo: Boolean = true,
77+
private val onHasContent: ((Boolean) -> Unit)? = null,
7778
) : LinearLayout(context, attrs, defStyle) {
7879

7980
@Inject
@@ -139,8 +140,10 @@ class NewTabLegacyPageView @JvmOverloads constructor(
139140

140141
if (!showLogo && isHomeBackgroundLogoVisible) {
141142
this.gone()
143+
onHasContent?.invoke(false)
142144
} else {
143145
this.show()
146+
onHasContent?.invoke(true)
144147
if (isHomeBackgroundLogoVisible) {
145148
homeBackgroundLogo.showLogo()
146149
} else {

app/src/main/java/com/duckduckgo/app/browser/newtab/NewTabPageProvider.kt

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,8 +51,12 @@ class RealNewTabPageProvider @Inject constructor(
5151
)
5252
class NewTabLegacyPage @Inject constructor() : NewTabPagePlugin {
5353

54-
override fun getView(context: Context, showLogo: Boolean): View {
55-
return NewTabLegacyPageView(context, showLogo = showLogo)
54+
override fun getView(
55+
context: Context,
56+
showLogo: Boolean,
57+
onHasContent: ((Boolean) -> Unit)?,
58+
): View {
59+
return NewTabLegacyPageView(context, showLogo = showLogo, onHasContent = onHasContent)
5660
}
5761
}
5862

app/src/test/java/com/duckduckgo/app/browser/newtab/NewTabPageProviderTest.kt

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -125,13 +125,21 @@ class NewTabPageProviderTest {
125125
}
126126

127127
class LegacyNewTabPlugin : NewTabPagePlugin {
128-
override fun getView(context: Context, showLogo: Boolean): View {
128+
override fun getView(
129+
context: Context,
130+
showLogo: Boolean,
131+
onHasContent: ((Boolean) -> Unit)?,
132+
): View {
129133
return View(context)
130134
}
131135
}
132136

133137
class NewNewTabPlugin : NewTabPagePlugin {
134-
override fun getView(context: Context, showLogo: Boolean): View {
138+
override fun getView(
139+
context: Context,
140+
showLogo: Boolean,
141+
onHasContent: ((Boolean) -> Unit)?,
142+
): View {
135143
return View(context)
136144
}
137145
}

new-tab-page/new-tab-page-api/src/main/java/com/duckduckgo/newtabpage/api/NewTabPagePlugin.kt

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,11 +31,14 @@ interface NewTabPagePlugin : ActivePlugin {
3131
* This method returns a [View] that will be used as the NewTabPage content
3232
* @param context The context to create the view with
3333
* @param showLogo Whether to show the logo in the new tab page
34+
* @param onHasContent Optional callback to notify when the view has content
3435
* @return [View]
3536
*/
36-
fun getView(context: Context, showLogo: Boolean = true): View {
37-
return getView(context)
38-
}
37+
fun getView(
38+
context: Context,
39+
showLogo: Boolean = true,
40+
onHasContent: ((Boolean) -> Unit)? = null,
41+
): View
3942

4043
companion object {
4144
const val PRIORITY_LEGACY_NTP = 0

new-tab-page/new-tab-page-impl/src/main/java/com/duckduckgo/newtabpage/impl/NewTabPage.kt

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,11 @@ import javax.inject.Inject
3535
)
3636
class NewTabPage @Inject constructor() : NewTabPagePlugin {
3737

38-
override fun getView(context: Context, showLogo: Boolean): View {
39-
return NewTabPageView(context, showLogo = showLogo)
38+
override fun getView(
39+
context: Context,
40+
showLogo: Boolean,
41+
onHasContent: ((Boolean) -> Unit)?,
42+
): View {
43+
return NewTabPageView(context, showLogo = showLogo, onHasContent = onHasContent)
4044
}
4145
}

new-tab-page/new-tab-page-impl/src/main/java/com/duckduckgo/newtabpage/impl/view/NewTabPageView.kt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ class NewTabPageView @JvmOverloads constructor(
5353
attrs: AttributeSet? = null,
5454
defStyle: Int = 0,
5555
private val showLogo: Boolean = true,
56+
private val onHasContent: ((Boolean) -> Unit)? = null,
5657
) : LinearLayout(context, attrs, defStyle) {
5758

5859
@Inject
@@ -98,8 +99,10 @@ class NewTabPageView @JvmOverloads constructor(
9899
} else {
99100
if (!showLogo && viewState.showDax) {
100101
this.gone()
102+
onHasContent?.invoke(false)
101103
} else {
102104
this.show()
105+
onHasContent?.invoke(true)
103106
if (viewState.showDax) {
104107
binding.ddgLogo.show()
105108
} else {

0 commit comments

Comments
 (0)