Skip to content

Commit

Permalink
Use different icons for bookmarks and favorites
Browse files Browse the repository at this point in the history
  • Loading branch information
CrisBarreiro committed Apr 10, 2024
1 parent 464849a commit 6aef9e2
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -43,15 +43,14 @@ interface AutoComplete {
data class AutoCompleteSearchSuggestion(
override val phrase: String,
val isUrl: Boolean,
) :
AutoCompleteSuggestion(phrase)
) : AutoCompleteSuggestion(phrase)

data class AutoCompleteBookmarkSuggestion(
override val phrase: String,
val title: String,
val url: String,
) :
AutoCompleteSuggestion(phrase)
val isFavorite: Boolean = false,
) : AutoCompleteSuggestion(phrase)

data class AutoCompleteHistorySuggestion(
override val phrase: String,
Expand Down Expand Up @@ -108,7 +107,7 @@ class AutoCompleteApi @Inject constructor(
.map { rankBookmarks(query, it) }
.flattenAsObservable { it }
.map {
AutoCompleteBookmarkSuggestion(phrase = it.url.toUri().toStringDropScheme(), title = it.title.orEmpty(), url = it.url)
AutoCompleteBookmarkSuggestion(phrase = it.url.toUri().toStringDropScheme(), title = it.title, url = it.url, isFavorite = false)
}
.distinctUntilChanged()
.take(2)
Expand All @@ -121,7 +120,7 @@ class AutoCompleteApi @Inject constructor(
.map { rankFavorites(query, it) }
.flattenAsObservable { it }
.map {
AutoCompleteBookmarkSuggestion(phrase = it.url.toUri().toStringDropScheme(), title = it.title.orEmpty(), url = it.url)
AutoCompleteBookmarkSuggestion(phrase = it.url.toUri().toStringDropScheme(), title = it.title, url = it.url, isFavorite = true)
}
.distinctUntilChanged()
.take(2)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,7 @@ sealed class AutoCompleteViewHolder(itemView: View) : RecyclerView.ViewHolder(it
title.text = item.title
url.text = item.url

bookmarkIndicator.setImageResource(if (item.isFavorite) R.drawable.ic_bookmark_favorite_20 else R.drawable.ic_bookmark_20)
goToBookmarkImage.setOnClickListener { editableSearchClickListener(item) }
root.setOnClickListener { immediateSearchListener(item) }
}
Expand Down
10 changes: 10 additions & 0 deletions app/src/main/res/drawable/ic_bookmark_favorite_20.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="20dp"
android:height="20dp"
android:viewportWidth="20"
android:viewportHeight="20">
<path
android:pathData="M6.75,1C5.231,1 4,2.231 4,3.75V17.617C4,18.642 5.109,19.284 5.998,18.772L10,16.469L14.002,18.772C14.891,19.284 16,18.642 16,17.617V16.125C16,15.711 15.664,15.375 15.25,15.375C14.836,15.375 14.5,15.711 14.5,16.125V17.328L10.665,15.12C10.253,14.884 9.747,14.884 9.335,15.12L5.5,17.328V3.75C5.5,3.06 6.06,2.5 6.75,2.5H13.813C14.192,2.5 14.5,2.808 14.5,3.188V3.5C14.5,3.914 14.836,4.25 15.25,4.25C15.664,4.25 16,3.914 16,3.5V3.188C16,1.979 15.021,1 13.813,1H6.75ZM16.139,6.339C15.767,5.615 14.733,5.615 14.361,6.339L13.448,8.112L11.416,8.395C10.583,8.511 10.256,9.542 10.871,10.116L12.315,11.465L11.973,13.375C11.828,14.187 12.672,14.816 13.408,14.445L15.25,13.516L17.092,14.445C17.828,14.816 18.672,14.187 18.527,13.375L18.185,11.465L19.629,10.116C20.244,9.542 19.918,8.511 19.084,8.395L17.052,8.112L16.139,6.339ZM14.663,9.029L15.25,7.889L15.837,9.029C15.986,9.318 16.266,9.517 16.588,9.562L17.839,9.736L16.962,10.555C16.715,10.787 16.601,11.128 16.661,11.462L16.874,12.655L15.7,12.063C15.417,11.92 15.083,11.92 14.8,12.063L13.626,12.655L13.839,11.462C13.899,11.128 13.785,10.787 13.538,10.555L12.661,9.736L13.912,9.562C14.234,9.517 14.514,9.318 14.663,9.029Z"
android:fillColor="#000000"
android:fillType="evenOdd"/>
</vector>
Original file line number Diff line number Diff line change
Expand Up @@ -152,8 +152,8 @@ class AutoCompleteApiTest {

assertEquals(
listOf(
AutoCompleteBookmarkSuggestion(phrase = "favexample.com", "title", "https://favexample.com"),
AutoCompleteBookmarkSuggestion(phrase = "favfoo.com", "title", "https://favfoo.com"),
AutoCompleteBookmarkSuggestion(phrase = "favexample.com", "title", "https://favexample.com", true),
AutoCompleteBookmarkSuggestion(phrase = "favfoo.com", "title", "https://favfoo.com", true),
),
value.suggestions,
)
Expand Down Expand Up @@ -197,11 +197,12 @@ class AutoCompleteApiTest {

assertEquals(
listOf(
AutoCompleteBookmarkSuggestion(phrase = "example.com", "title example", "https://example.com"),
AutoCompleteBookmarkSuggestion(phrase = "example.com", "title example", "https://example.com", true),
AutoCompleteBookmarkSuggestion(
phrase = "foo.com/path/to/foo",
"title foo",
"https://foo.com/path/to/foo",
true,
),
AutoCompleteSearchSuggestion(phrase = "foo.com", true),
AutoCompleteSearchSuggestion(phrase = "bar.com", true),
Expand Down Expand Up @@ -240,8 +241,8 @@ class AutoCompleteApiTest {

assertEquals(
listOf(
AutoCompleteBookmarkSuggestion(phrase = "favexample.com", "title", "https://favexample.com"),
AutoCompleteBookmarkSuggestion(phrase = "example.com", "title", "https://example.com"),
AutoCompleteBookmarkSuggestion(phrase = "favexample.com", "title", "https://favexample.com", true),
AutoCompleteBookmarkSuggestion(phrase = "example.com", "title", "https://example.com", false),
),
value.suggestions,
)
Expand Down

0 comments on commit 6aef9e2

Please sign in to comment.