Skip to content

Commit

Permalink
Added dividers between sections. Updated color on switch to tab icon.
Browse files Browse the repository at this point in the history
  • Loading branch information
anikiki committed Oct 10, 2024
1 parent 686a155 commit 16012e8
Show file tree
Hide file tree
Showing 5 changed files with 122 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,7 @@ import com.duckduckgo.app.browser.api.WebViewCapabilityChecker.WebViewCapability
import com.duckduckgo.app.browser.applinks.AppLinksLauncher
import com.duckduckgo.app.browser.applinks.AppLinksSnackBarConfigurator
import com.duckduckgo.app.browser.autocomplete.BrowserAutoCompleteSuggestionsAdapter
import com.duckduckgo.app.browser.autocomplete.SuggestionItemDecoration
import com.duckduckgo.app.browser.commands.Command
import com.duckduckgo.app.browser.commands.Command.ShowBackNavigationHistory
import com.duckduckgo.app.browser.commands.NavigationCommand
Expand Down Expand Up @@ -2329,6 +2330,9 @@ class BrowserTabFragment :
omnibarPosition = settingsDataStore.omnibarPosition,
)
binding.autoCompleteSuggestionsList.adapter = autoCompleteSuggestionsAdapter
binding.autoCompleteSuggestionsList.addItemDecoration(
SuggestionItemDecoration(ContextCompat.getDrawable(context, R.drawable.suggestions_divider)!!),
)
}

private fun configureNewTab() {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
/*
* 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.browser.autocomplete

import android.graphics.Canvas
import android.graphics.drawable.Drawable
import android.view.ViewGroup.MarginLayoutParams
import androidx.recyclerview.widget.RecyclerView

class SuggestionItemDecoration(private val divider: Drawable) : RecyclerView.ItemDecoration() {

override fun onDrawOver(
canvas: Canvas,
parent: RecyclerView,
state: RecyclerView.State,
) {
canvas.save()

val childCount = parent.childCount
val parentRight = parent.width - parent.paddingRight

for (i in 0 until childCount) {
val child = parent.getChildAt(i)
val params = child.layoutParams as MarginLayoutParams
val currentViewType = child.tag
val nextViewType = if (i + 1 < childCount) parent.getChildAt(i + 1).tag else UNKNOWN

if (nextViewType == UNKNOWN) {
continue
}

if (currentViewType == SEARCH_ITEM && nextViewType == OTHER_ITEM) {
drawDivider(canvas, child, params, parentRight)
}

if (currentViewType == OTHER_ITEM && nextViewType == SEARCH_ITEM) {
drawDivider(canvas, child, params, parentRight)
}
}

canvas.restore()
}

private fun drawDivider(
canvas: Canvas,
child: android.view.View,
params: MarginLayoutParams,
parentRight: Int,
) {
val horizontalSize = parentRight
val verticalSize = child.bottom + params.bottomMargin
divider.setBounds(0, verticalSize, horizontalSize, verticalSize + divider.intrinsicHeight)
divider.draw(canvas)
}

companion object {
internal const val SEARCH_ITEM = "SEARCH_ITEM"
internal const val OTHER_ITEM = "OTHER_ITEM"
internal const val UNKNOWN = "UNKNOWN"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ import com.duckduckgo.app.autocomplete.api.AutoComplete.AutoCompleteSuggestion.A
import com.duckduckgo.app.autocomplete.api.AutoComplete.AutoCompleteSuggestion.AutoCompleteUrlSuggestion.AutoCompleteSwitchToTabSuggestion
import com.duckduckgo.app.browser.R
import com.duckduckgo.app.browser.autocomplete.AutoCompleteViewHolder.InAppMessageViewHolder
import com.duckduckgo.app.browser.autocomplete.SuggestionItemDecoration.Companion.OTHER_ITEM
import com.duckduckgo.app.browser.autocomplete.SuggestionItemDecoration.Companion.SEARCH_ITEM
import com.duckduckgo.app.browser.databinding.ItemAutocompleteBookmarkSuggestionBinding
import com.duckduckgo.app.browser.databinding.ItemAutocompleteDefaultBinding
import com.duckduckgo.app.browser.databinding.ItemAutocompleteHistorySuggestionBinding
Expand Down Expand Up @@ -269,6 +271,8 @@ sealed class AutoCompleteViewHolder(itemView: View) : RecyclerView.ViewHolder(it
if (omnibarPosition == OmnibarPosition.BOTTOM) {
editQueryImage.setImageResource(R.drawable.ic_autocomplete_down_20dp)
}

root.tag = SEARCH_ITEM
}
}

Expand All @@ -294,6 +298,8 @@ sealed class AutoCompleteViewHolder(itemView: View) : RecyclerView.ViewHolder(it
if (omnibarPosition == OmnibarPosition.BOTTOM) {
editQueryImage.setImageResource(R.drawable.ic_autocomplete_down_20dp)
}

root.tag = OTHER_ITEM
}
}

Expand All @@ -307,6 +313,8 @@ sealed class AutoCompleteViewHolder(itemView: View) : RecyclerView.ViewHolder(it

bookmarkIndicator.setImageResource(if (item.isFavorite) R.drawable.ic_bookmark_favorite_20 else R.drawable.ic_bookmark_20)
root.setOnClickListener { immediateSearchListener(item) }

root.tag = OTHER_ITEM
}
}

Expand All @@ -324,6 +332,8 @@ sealed class AutoCompleteViewHolder(itemView: View) : RecyclerView.ViewHolder(it
longPressClickListener(item)
true
}

root.tag = OTHER_ITEM
}
}

Expand All @@ -336,6 +346,8 @@ sealed class AutoCompleteViewHolder(itemView: View) : RecyclerView.ViewHolder(it
url.text = root.context.getString(R.string.autocompleteSwitchToTab, item.phrase.formatIfUrl())

root.setOnClickListener { immediateSearchListener(item) }

root.tag = OTHER_ITEM
}
}

Expand All @@ -353,6 +365,8 @@ sealed class AutoCompleteViewHolder(itemView: View) : RecyclerView.ViewHolder(it
if (omnibarPosition == OmnibarPosition.BOTTOM) {
binding.editQueryImage.setImageResource(R.drawable.ic_autocomplete_down_20dp)
}

binding.root.tag = OTHER_ITEM
}
}

Expand All @@ -371,6 +385,8 @@ sealed class AutoCompleteViewHolder(itemView: View) : RecyclerView.ViewHolder(it
)
binding.messageCta.onCloseButtonClicked { deleteClickListener(item) }
binding.messageCta.onPrimaryActionClicked { openSettingsClickListener() }

binding.root.tag = OTHER_ITEM
}
}

Expand Down
2 changes: 1 addition & 1 deletion app/src/main/res/drawable/ic_switch_to_tab_20.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,6 @@
android:viewportHeight="20">
<path
android:pathData="M4.5,1A3.5,3.5 0,0 0,1 4.5L1,13a3.501,3.501 0,0 0,2.88 3.445A3.501,3.501 0,0 0,7.25 19h8.25a3.5,3.5 0,0 0,3.5 -3.5L19,7.25a3.501,3.501 0,0 0,-2.555 -3.37A3.501,3.501 0,0 0,13 1zM16.5,5.518L16.5,13a3.5,3.5 0,0 1,-3.5 3.5L5.518,16.5a2,2 0,0 0,1.732 1h8.25a2,2 0,0 0,2 -2L17.5,7.25a2,2 0,0 0,-1 -1.732M2.5,4.5a2,2 0,0 1,2 -2L13,2.5a2,2 0,0 1,2 2L15,13a2,2 0,0 1,-2 2L4.5,15a2,2 0,0 1,-2 -2z"
android:fillColor="#000"
android:fillColor="?attr/daxColorPrimaryIcon"
android:fillType="evenOdd"/>
</vector>
26 changes: 26 additions & 0 deletions app/src/main/res/drawable/suggestions_divider.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<?xml version="1.0" encoding="utf-8"?><!--
~ 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.
-->

<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">

<size
android:width="1dp"
android:height="1dp" />

<solid android:color="?daxColorLines" />

</shape>

0 comments on commit 16012e8

Please sign in to comment.