8000 Improve layout as Zeplin design: · roychowdhuryrohit-dev/Android@82d6fd6 · GitHub
[go: up one dir, main page]

Skip to content

Commit 82d6fd6

Browse files
committed
Improve layout as Zeplin design:
- Align the omnibus with the autocomplete suggestion results. - Make the suggestion results use two colors for the query and the rest of the result.
1 parent d488921 commit 82d6fd6

File tree

9 files changed

+45
-19
lines changed

9 files changed

+45
-19
lines changed

app/src/main/java/com/duckduckgo/app/ui/autocomplete/Autocomplete.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -82,8 +82,8 @@ public void onAddToQuery(View v, int position) {
8282
}
8383

8484
@Override
85-
public void addSuggestions(@NonNull List<SuggestionEntity> suggestions) {
86-
adapter.setSuggestions(suggestions);
85+
public void addSuggestions(@NonNull List<SuggestionEntity> suggestions, @NonNull String filter) {
86+
adapter.setSuggestions(suggestions, filter);
8787
if (showAutocompleteResults) {
8888
if (getVisibility() != View.VISIBLE) {
8989
setVisibility(View.VISIBLE);

app/src/main/java/com/duckduckgo/app/ui/autocomplete/AutocompleteTask.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
public class AutocompleteTask extends AsyncTask<String, Void, List<SuggestionEntity>> {
3131
private WeakReference<BrowserPresenter> browserPresenterRef;
3232
private SuggestionRepository suggestionRepository;
33+
private String query;
3334

3435
public AutocompleteTask(@NonNull BrowserPresenter browserPresenter, @NonNull SuggestionRepository suggestionRepository) {
3536
browserPresenterRef = new WeakReference<>(browserPresenter);
@@ -38,7 +39,7 @@ public AutocompleteTask(@NonNull BrowserPresenter browserPresenter, @NonNull Sug
3839

3940
@Override
4041
protected List<SuggestionEntity> doInBackground(String... params) {
41-
String query = params[0];
42+
query = params[0];
4243
List<SuggestionEntity> list = new ArrayList<>();
4344
for (Suggestion suggestion : suggestionRepository.getSuggestions(query)) {
4445
list.add(new SuggestionEntity(suggestion));
@@ -50,7 +51,7 @@ protected List<SuggestionEntity> doInBackground(String... params) {
5051
protected void onPostExecute(List<SuggestionEntity> suggestionEntities) {
5152
super.onPostExecute(suggestionEntities);
5253
if (browserPresenterRef.get() != null) {
53-
browserPresenterRef.get().onReceiveNewSuggestions(suggestionEntities);
54+
browserPresenterRef.get().onReceiveNewSuggestionsForQuery(suggestionEntities, query);
5455
}
5556
}
5657
}

app/src/main/java/com/duckduckgo/app/ui/autocomplete/AutocompleteView.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
import java.util.List;
2222

2323
public interface AutocompleteView {
24-
void addSuggestions(@NonNull List<SuggestionEntity> suggestions);
24+
void addSuggestions(@NonNull List<SuggestionEntity> suggestions, @NonNull String filter);
2525

2626
void show();
2727

app/src/main/java/com/duckduckgo/app/ui/autocomplete/SuggestionAdapter.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,13 +33,15 @@ public interface OnSuggestionListener {
3333

3434
private OnSuggestionListener onSuggestionListener;
3535
private List<SuggestionEntity> suggestions;
36+
private String filter = "";
3637

3738
public SuggestionAdapter(@NonNull OnSuggestionListener onSuggestionListener) {
3839
this.onSuggestionListener = onSuggestionListener;
3940
}
4041

41-
public void setSuggestions(@NonNull List<SuggestionEntity> suggestions) {
42+
public void setSuggestions(@NonNull List<SuggestionEntity> suggestions, @NonNull String filter) {
4243
this.suggestions = suggestions;
44+
this.filter = filter;
4345
notifyDataSetChanged();
4446
}
4547

@@ -66,7 +68,7 @@ public void onAddToQuerySelected(View v, int position) {
6668
@Override
6769
public void onBindViewHolder(SuggestionViewHolder holder, int position) {
6870
SuggestionEntity suggestion = suggestions.get(position);
69-
holder.setSuggestion(suggestion);
71+
holder.setSuggestion(suggestion, filter);
7072
}
7173

7274
@Override

app/src/main/java/com/duckduckgo/app/ui/autocomplete/SuggestionViewHolder.java

Lines changed: 26 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,14 @@
1616

1717
package com.duckduckgo.app.ui.autocomplete;
1818

19+
import android.content.Context;
20+
import android.support.annotation.ColorRes;
21+
import android.support.annotation.NonNull;
22+
import android.support.v4.content.ContextCompat;
1923
import android.support.v7.widget.RecyclerView;
24+
import android.text.Spannable;
25+
import android.text.SpannableString;
26+
import android.text.style.ForegroundColorSpan;
2027
import android.view.LayoutInflater;
2128
import android.view.View;
2229
import android.view.ViewGroup;
@@ -65,15 +72,31 @@ public void onClick(View v) {
6572

6673
}
6774

68-
public void setSuggestion(SuggestionEntity suggestion) {
69-
String suggestionText = suggestion.getSuggestion();
75+
public void setSuggestion(@NonNull SuggestionEntity suggestion, @NonNull String filter) {
76+
Spannable filterStyled = getColoredText(itemView.getContext(), filter, R.color.suggestion_text_primary);
7077

71-
suggestionTextView.setText(suggestionText);
78+
suggestionTextView.setText(filterStyled);
79+
80+
String suggestionText = suggestion.getSuggestion().replace(filter, "");
81+
Spannable suggestionStyled = getColoredText(itemView.getContext(), suggestionText, R.color.suggestion_text_secondary);
82+
83+
suggestionTextView.append(suggestionStyled);
7284

7385
int iconResId = UrlUtils.isUrl(suggestionText) ? R.drawable.ic_globe : R.drawable.ic_small_loupe;
7486
iconImageView.setImageResource(iconResId);
7587
}
7688

89+
private Spannable getColoredText(Context context, @NonNull String text, @ColorRes int color) {
90+
Spannable textStyled = new SpannableString(text);
91+
textStyled.setSpan(
92+
new ForegroundColorSpan(
93+
ContextCompat.getColor(context, color)),
94+
0,
95+
text.length(),
96+
Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
97+
return textStyled;
98+
}
99+
77100
public static SuggestionViewHolder inflate(ViewGroup parent, OnSuggestionListener onSuggestionListener) {
78101
return new SuggestionViewHolder(
79102
LayoutInflater.from(parent.getContext())

app/src/main/java/com/duckduckgo/app/ui/browser/BrowserPresenter.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -126,5 +126,5 @@ public interface BrowserPresenter {
126126

127127
void autocompleteSuggestionAddToQuery(int position);
128128

129-
void onReceiveNewSuggestions(List<SuggestionEntity> list);
129+
void onReceiveNewSuggestionsForQuery(@NonNull List<SuggestionEntity> list, @NonNull String query);
130130
}

app/src/main/java/com/duckduckgo/app/ui/browser/BrowserPresenterImpl.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -528,10 +528,10 @@ public void autocompleteSuggestionAddToQuery(int position) {
528528
}
529529

530530
@Override
531-
public void onReceiveNewSuggestions(List<SuggestionEntity> list) {
531+
public void onReceiveNewSuggestionsForQuery(@NonNull List<SuggestionEntity> list, @NonNull String query) {
532532
suggestions.clear();
533533
suggestions.addAll(list);
534-
autocompleteView.addSuggestions(suggestions);
534+
autocompleteView.addSuggestions(suggestions, query);
535535
}
536536

537537
@Nullable

app/src/main/res/layout/view_omnibar.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,8 @@
4040
android:layout_width="18dp"
4141
android:layout_height="18dp"
4242
android:layout_gravity="center_vertical"
43-
android:layout_marginStart="4dp"
44-
android:layout_marginLeft="4dp"
43+
android:layout_marginStart="5dp"
44+
android:layout_marginLeft="5dp"
4545
android:layout_marginEnd="12dp"
4646
android:layout_marginRight="12dp"
4747
android:src="@drawable/ic_prev_arrow"

app/src/main/res/layout/viewholder_suggestion.xml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,10 +29,10 @@
2929
android:src="@drawable/ic_small_loupe"/>
3030
<ImageButton
3131
android:id="@+id/suggestion_add_image_button"
32-
android:layout_width="wrap_content"
33-
android:layout_height="wrap_content"
34-
android:layout_marginEnd="24dp"
35-
android:layout_marginRight="24dp"
32+
android:layout_width="41dp"
33+
android:layout_height="40dp"
34+
android:layout_marginEnd="10dp"
35+
android:layout_marginRight="10dp"
3636
android:layout_gravity="center_vertical|end"
3737
android:src="@drawable/ic_add_to_query"
3838
android:background="?attr/selectableItemBackgroundBorderless"/>

0 commit comments

Comments
 (0)
0