Bug 882081 - Restore bookmark indicator in TwoLinePageRow (r=sriram)

This commit is contained in:
Lucas Rocha 2013-06-14 17:26:36 +01:00
Родитель eb78699d20
Коммит 484ef34f06
3 изменённых файлов: 55 добавлений и 8 удалений

Просмотреть файл

@ -579,8 +579,6 @@ public class BrowserSearch extends Fragment implements AdapterView.OnItemClickLi
row.updateFromCursor(c);
// FIXME: show bookmark icon
return row;
}
}

Просмотреть файл

@ -8,6 +8,7 @@ package org.mozilla.gecko.home;
import org.mozilla.gecko.Favicons;
import org.mozilla.gecko.R;
import org.mozilla.gecko.Tabs;
import org.mozilla.gecko.db.BrowserContract.Combined;
import org.mozilla.gecko.db.BrowserDB.URLColumns;
import org.mozilla.gecko.gfx.BitmapUtils;
import org.mozilla.gecko.widget.FaviconView;
@ -23,11 +24,15 @@ import android.widget.LinearLayout;
import android.widget.TextView;
public class TwoLinePageRow extends LinearLayout {
private static final int NO_ICON = 0;
private final TextView mTitle;
private final TextView mUrl;
private final FaviconView mFavicon;
private int mUrlIconId;
private int mBookmarkIconId;
public TwoLinePageRow(Context context) {
this(context, null);
}
@ -37,6 +42,9 @@ public class TwoLinePageRow extends LinearLayout {
setGravity(Gravity.CENTER_VERTICAL);
mUrlIconId = NO_ICON;
mBookmarkIconId = NO_ICON;
LayoutInflater.from(context).inflate(R.layout.two_line_page_row, this);
mTitle = (TextView) findViewById(R.id.title);
mUrl = (TextView) findViewById(R.id.url);
@ -55,14 +63,28 @@ public class TwoLinePageRow extends LinearLayout {
mUrl.setText(stringId);
}
private void setUrlIcon(int resourceId) {
mUrl.setCompoundDrawablesWithIntrinsicBounds(resourceId, 0, 0, 0);
private void setUrlIcon(int urlIconId) {
if (mUrlIconId == urlIconId) {
return;
}
mUrlIconId = urlIconId;
mUrl.setCompoundDrawablesWithIntrinsicBounds(mUrlIconId, 0, mBookmarkIconId, 0);
}
private void setFaviconWithUrl(Bitmap favicon, String url) {
mFavicon.updateImage(favicon, url);
}
private void setBookmarkIcon(int bookmarkIconId) {
if (mBookmarkIconId == bookmarkIconId) {
return;
}
mBookmarkIconId = bookmarkIconId;
mUrl.setCompoundDrawablesWithIntrinsicBounds(mUrlIconId, 0, mBookmarkIconId, 0);
}
public void updateFromCursor(Cursor cursor) {
if (cursor == null) {
return;
@ -84,7 +106,7 @@ public class TwoLinePageRow extends LinearLayout {
setUrlIcon(R.drawable.ic_url_bar_tab);
} else {
setUrl(url);
setUrlIcon(0);
setUrlIcon(NO_ICON);
}
int faviconIndex = cursor.getColumnIndex(URLColumns.FAVICON);
@ -104,5 +126,30 @@ public class TwoLinePageRow extends LinearLayout {
// If favicons is not on the cursor, try to fetch it from the memory cache
setFaviconWithUrl(Favicons.getInstance().getFaviconFromMemCache(url), url);
}
final int bookmarkIdIndex = cursor.getColumnIndex(Combined.BOOKMARK_ID);
if (bookmarkIdIndex != -1) {
final long bookmarkId = cursor.getLong(bookmarkIdIndex);
final int displayIndex = cursor.getColumnIndex(Combined.DISPLAY);
final int display;
if (displayIndex != -1) {
display = cursor.getInt(displayIndex);
} else {
display = Combined.DISPLAY_NORMAL;
}
// The bookmark id will be 0 (null in database) when the url
// is not a bookmark.
if (bookmarkId == 0) {
setBookmarkIcon(NO_ICON);
} else if (display == Combined.DISPLAY_READER) {
setBookmarkIcon(R.drawable.ic_url_bar_reader);
} else {
setBookmarkIcon(R.drawable.ic_url_bar_star);
}
} else {
setBookmarkIcon(NO_ICON);
}
}
}

Просмотреть файл

@ -12,8 +12,9 @@
android:layout_marginLeft="10dip"
android:layout_marginRight="10dip"/>
<LinearLayout android:layout_width="wrap_content"
<LinearLayout android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginRight="10dip"
android:orientation="vertical">
<org.mozilla.gecko.home.FadedTextView
@ -25,8 +26,9 @@
<TextView android:id="@+id/url"
style="@style/Widget.TwoLinePageRow.Url"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:drawablePadding="5dp"/>
</LinearLayout>