Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

New Tab Page Improvements #4454

Closed
wants to merge 6 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@
~
~ 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
~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
~ limitations under the License.
-->

Expand All @@ -25,46 +25,34 @@
android:layout_height="wrap_content"
tools:visibility="visible"
android:visibility="gone"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent">
style="@style/Widget.DuckDuckGo.Card">

<ImageView
android:id="@+id/deviceShieldCtaImage"
android:layout_width="48dp"
android:layout_height="48dp"
android:layout_marginTop="16dp"
android:layout_marginEnd="16dp"
android:layout_marginBottom="16dp"
android:scaleType="centerCrop"
android:src="@drawable/ic_apptp_default"
app:layout_constraintBottom_toTopOf="@+id/deviceShieldCtaSplitter"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toTopOf="parent"
tools:ignore="ContentDescription" />

<com.duckduckgo.common.ui.view.text.DaxTextView
android:id="@+id/deviceShieldCtaHeader"
app:typography="body2"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginStart="22dp"
android:layout_marginTop="16dp"
android:layout_marginEnd="16dp"
android:layout_marginBottom="16dp"
app:layout_constraintBottom_toTopOf="@+id/deviceShieldCtaSplitter"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toStartOf="@+id/deviceShieldCtaImage"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:typography="body2"
tools:text="App Tracking Protection is enabled and blocking tracking attempts across your apps" />

<com.duckduckgo.common.ui.view.divider.HorizontalDivider
android:id="@+id/deviceShieldCtaSplitter"
android:layout_width="0dp"
android:layout_height="wrap_content"
app:defaultPadding="false"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintStart_toStartOf="parent" />

</androidx.constraintlayout.widget.ConstraintLayout>

487 changes: 402 additions & 85 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 @@ -72,7 +72,7 @@ import com.duckduckgo.app.browser.customtabs.CustomTabPixelNames
import com.duckduckgo.app.browser.favicon.FaviconManager
import com.duckduckgo.app.browser.favicon.FaviconSource.ImageFavicon
import com.duckduckgo.app.browser.favicon.FaviconSource.UrlFavicon
import com.duckduckgo.app.browser.favorites.FavoritesQuickAccessAdapter
import com.duckduckgo.app.browser.favorites.NewTabSectionsItem
import com.duckduckgo.app.browser.history.NavigationHistoryAdapter.NavigationHistoryListener
import com.duckduckgo.app.browser.logindetection.FireproofDialogsEventHandler
import com.duckduckgo.app.browser.logindetection.FireproofDialogsEventHandler.Event
Expand Down Expand Up @@ -455,12 +455,14 @@ class BrowserTabViewModel @Inject constructor(

savedSitesRepository.getFavorites()
.combine(hiddenIds) { favorites, hiddenIds ->
Timber.d("New Tab: filteredFavourites combine")
favorites.filter { it.id !in hiddenIds.favorites }
}
.flowOn(dispatchers.io())
.onEach { filteredFavourites ->
withContext(dispatchers.main()) {
val favorites = filteredFavourites.map { FavoritesQuickAccessAdapter.QuickAccessFavorite(it) }
Timber.d("New Tab: filteredFavourites $filteredFavourites")
val favorites = filteredFavourites.map { NewTabSectionsItem.FavouriteItem(it) }
ctaViewState.value = currentCtaViewState().copy(favorites = favorites)
autoCompleteViewState.value = currentAutoCompleteViewState().copy(favorites = favorites)
val favorite = filteredFavourites.firstOrNull { it.url == url }
Expand Down Expand Up @@ -981,10 +983,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 @@ -993,6 +1003,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 @@ -1803,6 +1814,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 @@ -1812,23 +1827,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 Expand Up @@ -2810,9 +2835,9 @@ class BrowserTabViewModel @Inject constructor(
}
}

fun onQuickAccessListChanged(newList: List<FavoritesQuickAccessAdapter.QuickAccessFavorite>) {
fun onQuickAccessListChanged(newList: List<Favorite>) {
viewModelScope.launch(dispatchers.io()) {
savedSitesRepository.updateWithPosition(newList.map { it.favorite })
savedSitesRepository.updateWithPosition(newList)
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,13 @@ import androidx.recyclerview.widget.DiffUtil
import androidx.recyclerview.widget.ListAdapter
import androidx.recyclerview.widget.RecyclerView
import com.duckduckgo.app.browser.R
import com.duckduckgo.app.browser.databinding.ViewQuickAccessItemBinding
import com.duckduckgo.app.browser.favicon.FaviconManager
import com.duckduckgo.app.browser.favorites.FavoritesQuickAccessAdapter.QuickAccessFavorite
import com.duckduckgo.app.browser.favorites.FavoritesQuickAccessAdapter.QuickAccessViewHolder
import com.duckduckgo.app.browser.favorites.QuickAccessAdapterDiffCallback.Companion.DIFF_KEY_TITLE
import com.duckduckgo.app.browser.favorites.QuickAccessAdapterDiffCallback.Companion.DIFF_KEY_URL
import com.duckduckgo.common.ui.menu.PopupMenu
import com.duckduckgo.mobile.android.databinding.ViewGridListItemBinding
import com.duckduckgo.savedsites.api.models.SavedSite
import kotlin.math.absoluteValue
import kotlinx.coroutines.launch
Expand All @@ -57,7 +57,7 @@ class FavoritesQuickAccessAdapter(

class QuickAccessViewHolder(
private val inflater: LayoutInflater,
private val binding: ViewQuickAccessItemBinding,
private val binding: ViewGridListItemBinding,
private val lifecycleOwner: LifecycleOwner,
private val faviconManager: FaviconManager,
private val onMoveListener: (RecyclerView.ViewHolder) -> Unit,
Expand Down Expand Up @@ -213,7 +213,7 @@ class FavoritesQuickAccessAdapter(
viewType: Int,
): QuickAccessViewHolder {
val inflater = LayoutInflater.from(parent.context)
val binding = ViewQuickAccessItemBinding.inflate(inflater, parent, false)
val binding = ViewGridListItemBinding.inflate(inflater, parent, false)
return QuickAccessViewHolder(
inflater,
binding,
Expand Down