Skip to content

Commit

Permalink
more work
Browse files Browse the repository at this point in the history
  • Loading branch information
malmstein committed May 3, 2024
1 parent 1e526be commit 70706c6
Show file tree
Hide file tree
Showing 29 changed files with 892 additions and 213 deletions.
289 changes: 237 additions & 52 deletions app/src/main/java/com/duckduckgo/app/browser/BrowserTabFragment.kt

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -978,10 +978,18 @@ class BrowserTabViewModel @Inject constructor(
}

if (!currentBrowserViewState().browserShowing) {
Timber.d("New Tab: onUserPressedBack browser not showing")
return false
}

if (currentAutoCompleteViewState().showSuggestions) {
Timber.d("New Tab: onUserPressedBack focused view showing")
autoCompleteViewState.value = currentAutoCompleteViewState().copy(showFavorites = false, showSuggestions = false)
return true
}

if (navigation.canGoBack) {
Timber.d("New Tab: onUserPressedBack navigation can go back")
command.value = NavigationCommand.NavigateBack(navigation.stepsToPreviousPage)
return true
} else if (hasSourceTab) {
Expand All @@ -990,6 +998,7 @@ class BrowserTabViewModel @Inject constructor(
}
return true
} else if (!skipHome) {
Timber.d("New Tab: onUserPressedBack navigate home")
navigateHome()
command.value = ShowKeyboard
return true
Expand Down Expand Up @@ -1799,6 +1808,10 @@ class BrowserTabViewModel @Inject constructor(
hasFocus: Boolean,
hasQueryChanged: Boolean,
) {
// business logic
// if omnibar focused and query is not blank and suggestions enabled -> show autocomplete suggestions
//

// determine if empty list to be shown, or existing search results
val autoCompleteSearchResults = if (query.isBlank() || !hasFocus) {
AutoCompleteResult(query, emptyList())
Expand All @@ -1808,23 +1821,33 @@ class BrowserTabViewModel @Inject constructor(

val autoCompleteSuggestionsEnabled = appSettingsPreferencesStore.autoCompleteSuggestionsEnabled
val showAutoCompleteSuggestions = hasFocus && query.isNotBlank() && hasQueryChanged && autoCompleteSuggestionsEnabled

val showFavoritesAsSuggestions = if (!showAutoCompleteSuggestions) {
val urlFocused = hasFocus && query.isNotBlank() && !hasQueryChanged && UriString.isWebUrl(query)
val emptyQueryBrowsing = query.isBlank() && currentBrowserViewState().browserShowing
val favoritesAvailable = currentAutoCompleteViewState().favorites.isNotEmpty()
hasFocus && (urlFocused || emptyQueryBrowsing) && favoritesAvailable
// val favoritesAvailable = currentAutoCompleteViewState().favorites.isNotEmpty()
hasFocus && (urlFocused || emptyQueryBrowsing)
} else {
false
}

// val showFavoritesAsSuggestions = if (!showAutoCompleteSuggestions) {
// val urlFocused = hasFocus && query.isNotBlank() && !hasQueryChanged && UriString.isWebUrl(query)
// val emptyQueryBrowsing = query.isBlank() && currentBrowserViewState().browserShowing
// val favoritesAvailable = currentAutoCompleteViewState().favorites.isNotEmpty()
// hasFocus && (urlFocused || emptyQueryBrowsing) && favoritesAvailable
// } else {
// false
// }

autoCompleteViewState.value = currentAutoCompleteViewState()
.copy(
showSuggestions = showAutoCompleteSuggestions,
showFavorites = showFavoritesAsSuggestions,
searchResults = autoCompleteSearchResults,
)

if (hasFocus && autoCompleteSuggestionsEnabled) {
if (showAutoCompleteSuggestions) {
autoCompletePublishSubject.accept(query.trim())
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ data class BrowserViewState(
val browserError: WebViewErrorResponse = WebViewErrorResponse.OMITTED,
val sslError: SSLErrorType = SSLErrorType.NONE,
val privacyProtectionsPopupViewState: PrivacyProtectionsPopupViewState = PrivacyProtectionsPopupViewState.Gone,
val showFocusedView: Boolean = false,
)

sealed class HighlightableButton {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,4 +49,11 @@ class GridViewColumnCalculator(val context: Context) {
val remainingSpace = screenWidthDp - columnsWidth
return if (remainingSpace <= 0) 0 else (remainingSpace / 2).toPx()
}

companion object {
const val FAVOURITES_GRID_MAX_COLUMNS = 6
const val FAVOURITES_ITEM_MAX_SIZE_DP = 90
const val FAVOURITES_GRID_MAX_ITEMS_PORTRAIT = 8
const val FAVOURITES_GRID_MAX_ITEMS_LANDSCAPE = 12
}
}
114 changes: 98 additions & 16 deletions app/src/main/res/layout/include_focused_quick_access_items.xml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/rootFocusedView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_height="match_parent"
android:background="?attr/daxColorSurface"
android:elevation="2dp"
android:orientation="vertical"
Expand All @@ -32,44 +32,126 @@
app:layout_behavior="@string/appbar_scrolling_view_behavior"
android:paddingTop="15dp">

<com.duckduckgo.common.ui.view.text.DaxTextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
<LinearLayout
android:layout_marginStart="@dimen/keyline_5"
android:layout_marginEnd="@dimen/keyline_5"
android:text="@string/newTabPageFavorites"
app:textType="primary"
app:typography="h4" />
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center_vertical"
android:orientation="horizontal">

<com.duckduckgo.common.ui.view.text.DaxTextView
android:id="@+id/sectionHeaderText"
android:layout_width="0dp"
android:layout_height="wrap_content"
app:typography="h4"
android:layout_weight="1"
app:textType="primary"
android:text="@string/newTabPageFavorites" />

<com.duckduckgo.common.ui.view.button.IconButton
android:id="@+id/sectionHeaderOverflowIcon"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="?selectableItemBackgroundBorderless"
app:srcCompat="@drawable/ic_info_black_16"
tools:ignore="ContentDescription" />

</LinearLayout>

<androidx.recyclerview.widget.RecyclerView
android:id="@+id/quickAccessSuggestionsRecyclerView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginStart="@dimen/keyline_2"
android:layout_marginEnd="@dimen/keyline_2"
android:clipToPadding="false"
android:overScrollMode="never"
tools:itemCount="8"
tools:listItem="@layout/view_quick_access_item"
tools:showIn="@layout/activity_system_search"
tools:spanCount="4" />

<LinearLayout
android:id="@+id/quickAccessRecyclerViewEmpty"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginStart="@dimen/keyline_2"
android:layout_marginEnd="@dimen/keyline_2"
android:visibility="gone"
android:orientation="horizontal">

<com.duckduckgo.common.ui.view.griditem.DaxNewTabGridItem
app:gridItemType="placeholder"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />

<com.duckduckgo.common.ui.view.griditem.DaxNewTabGridItem
app:gridItemType="placeholder"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />

<com.duckduckgo.common.ui.view.griditem.DaxNewTabGridItem
app:gridItemType="placeholder"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />

<com.duckduckgo.common.ui.view.griditem.DaxNewTabGridItem
app:gridItemType="placeholder"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />

</LinearLayout>

<com.duckduckgo.common.ui.view.text.DaxTextView
android:id="@+id/newTabFavoritesToggle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingTop="@dimen/keyline_1"
android:paddingBottom="@dimen/keyline_1"
android:includeFontPadding="false"
android:paddingStart="@dimen/keyline_2"
android:paddingEnd="@dimen/keyline_1"
android:layout_marginTop="@dimen/keyline_4"
android:gravity="center"
android:layout_gravity="center"
app:typography="caption"
app:textType="primary"
android:background="@drawable/chip_background"
android:text="@string/newTabFavoritesShowMore"
android:drawablePadding="@dimen/keyline_1"
android:drawableEnd="@drawable/ic_chevron_small_down_16" />

<com.duckduckgo.common.ui.view.text.DaxTextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginStart="@dimen/keyline_5"
android:layout_marginTop="@dimen/keyline_4"
android:layout_marginEnd="@dimen/keyline_5"
android:layout_marginTop="@dimen/keyline_5"
android:text="@string/newTabPageShortcuts"
app:textType="primary"
app:typography="h4" />

<com.duckduckgo.common.ui.view.DaxNewTabGridItem
android:id="@+id/newTabShortcutBookmarks"
android:layout_width="wrap_content"
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:primaryText="@string/newTabPageShortcutBookmarks"
app:leadingIcon="@drawable/ic_bookmark_20"
android:layout_marginStart="@dimen/keyline_2" />
android:orientation="horizontal">

<com.duckduckgo.common.ui.view.griditem.DaxNewTabGridItem
android:id="@+id/newTabShortcutBookmarks"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:gridItemType="shortcut"
app:primaryText="@string/newTabPageShortcutBookmarks"
app:leadingIcon="@drawable/ic_bookmarks_open_color_16"
android:layout_marginStart="@dimen/keyline_2" />

<com.duckduckgo.common.ui.view.griditem.DaxNewTabGridItem
android:id="@+id/newTabShortcutChat"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:gridItemType="shortcut"
app:primaryText="@string/newTabPageShortcutChat"
app:leadingIcon="@drawable/ic_placeholder_color_16"
android:layout_marginStart="@dimen/keyline_2" />
</LinearLayout>

</LinearLayout>
13 changes: 6 additions & 7 deletions app/src/main/res/layout/include_new_browser_tab.xml
Original file line number Diff line number Diff line change
Expand Up @@ -41,20 +41,18 @@
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
android:layout_marginTop="@dimen/keyline_4">
android:layout_marginTop="@dimen/keyline_2"
android:layout_marginBottom="@dimen/keyline_4">

<androidx.fragment.app.FragmentContainerView
android:id="@+id/fragmentDeviceShieldContainer"
android:name="com.duckduckgo.mobile.android.vpn.ui.report.DeviceShieldFragment"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginStart="@dimen/keyline_2"
android:layout_marginEnd="@dimen/keyline_2"/>
android:layout_height="wrap_content" />

<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="@dimen/keyline_4">
android:layout_height="wrap_content">

<ImageView
android:id="@+id/ddgLogo"
Expand All @@ -81,7 +79,8 @@
app:layout_constraintTop_toTopOf="parent" />
</androidx.constraintlayout.widget.ConstraintLayout>

<include layout="@layout/include_quick_access_items" />
<include
layout="@layout/include_quick_access_items" />

</LinearLayout>

Expand Down

0 comments on commit 70706c6

Please sign in to comment.