mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-10-17 23:35:34 +00:00
Bug 1246243 - Use book icon for reading list folder r=liuche
This approach is extensible and would allow easy addition of special icons for e.g. the screenshots folder. MozReview-Commit-ID: 44yWq85x2HG --HG-- extra : rebase_source : be15df11f474f4db5546b823ca4040bdb2a63b6f extra : amend_source : be16d760fa2c32cce3af7b2985d3549f9993664b
This commit is contained in:
parent
b06178a07e
commit
0879705388
@ -8,47 +8,65 @@ package org.mozilla.gecko.home;
|
||||
import org.mozilla.gecko.R;
|
||||
|
||||
import android.content.Context;
|
||||
import android.support.annotation.NonNull;
|
||||
import android.util.AttributeSet;
|
||||
import android.widget.TextView;
|
||||
|
||||
public class BookmarkFolderView extends TextView {
|
||||
private static final int[] STATE_OPEN = { R.attr.state_open };
|
||||
public enum FolderState {
|
||||
/**
|
||||
* A standard folder, i.e. a folder in a list of bookmarks and folders.
|
||||
*/
|
||||
FOLDER(0),
|
||||
|
||||
private boolean mIsOpen;
|
||||
/**
|
||||
* The parent folder: this indicates that you are able to return to the previous
|
||||
* folder ("Back to {name}").
|
||||
*/
|
||||
PARENT(R.attr.parent),
|
||||
|
||||
/**
|
||||
* The reading list smartfolder: this displays a reading list icon instead of the
|
||||
* normal folder icon.
|
||||
*/
|
||||
READING_LIST(R.attr.reading_list);
|
||||
|
||||
public final int state;
|
||||
|
||||
FolderState(final int state) { this.state = state; }
|
||||
}
|
||||
|
||||
private FolderState mState;
|
||||
|
||||
public BookmarkFolderView(Context context) {
|
||||
super(context);
|
||||
mState = FolderState.FOLDER;
|
||||
}
|
||||
|
||||
public BookmarkFolderView(Context context, AttributeSet attrs) {
|
||||
super(context, attrs);
|
||||
mState = FolderState.FOLDER;
|
||||
}
|
||||
|
||||
public BookmarkFolderView(Context context, AttributeSet attrs, int defStyle) {
|
||||
super(context, attrs, defStyle);
|
||||
mState = FolderState.FOLDER;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int[] onCreateDrawableState(int extraSpace) {
|
||||
final int[] drawableState = super.onCreateDrawableState(extraSpace + 1);
|
||||
|
||||
if (mIsOpen) {
|
||||
mergeDrawableStates(drawableState, STATE_OPEN);
|
||||
if (mState != null && mState != FolderState.FOLDER) {
|
||||
mergeDrawableStates(drawableState, new int[] { mState.state });
|
||||
}
|
||||
|
||||
return drawableState;
|
||||
}
|
||||
|
||||
public void open() {
|
||||
if (!mIsOpen) {
|
||||
mIsOpen = true;
|
||||
refreshDrawableState();
|
||||
}
|
||||
}
|
||||
|
||||
public void close() {
|
||||
if (mIsOpen) {
|
||||
mIsOpen = false;
|
||||
public void setState(@NonNull FolderState state) {
|
||||
if (state != mState) {
|
||||
mState = state;
|
||||
refreshDrawableState();
|
||||
}
|
||||
}
|
||||
|
@ -11,6 +11,7 @@ import java.util.List;
|
||||
|
||||
import org.mozilla.gecko.R;
|
||||
import org.mozilla.gecko.db.BrowserContract.Bookmarks;
|
||||
import org.mozilla.gecko.home.BookmarkFolderView.FolderState;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.res.Resources;
|
||||
@ -329,10 +330,16 @@ class BookmarksListAdapter extends MultiTypeCursorAdapter {
|
||||
if (cursor == null) {
|
||||
final Resources res = context.getResources();
|
||||
row.setText(res.getString(R.string.home_move_back_to_filter, mParentStack.get(1).title));
|
||||
row.open();
|
||||
row.setState(FolderState.PARENT);
|
||||
} else {
|
||||
row.setText(getFolderTitle(context, cursor));
|
||||
row.close();
|
||||
|
||||
int id = cursor.getInt(cursor.getColumnIndexOrThrow(Bookmarks._ID));
|
||||
if (id == Bookmarks.FAKE_READINGLIST_SMARTFOLDER_ID) {
|
||||
row.setState(FolderState.READING_LIST);
|
||||
} else {
|
||||
row.setState(FolderState.FOLDER);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Binary file not shown.
After Width: | Height: | Size: 424 B |
Binary file not shown.
After Width: | Height: | Size: 542 B |
Binary file not shown.
After Width: | Height: | Size: 726 B |
@ -7,9 +7,13 @@
|
||||
xmlns:gecko="http://schemas.android.com/apk/res-auto">
|
||||
|
||||
<!-- state open -->
|
||||
<item gecko:state_open="true"
|
||||
<item gecko:parent="true"
|
||||
android:drawable="@drawable/bookmark_folder_arrow_up"/>
|
||||
|
||||
<!-- reading list folder -->
|
||||
<item gecko:reading_list="true"
|
||||
android:drawable="@drawable/reading_list_folder"/>
|
||||
|
||||
<!-- state close -->
|
||||
<item android:drawable="@drawable/folder_closed"/>
|
||||
|
||||
|
@ -137,7 +137,8 @@
|
||||
</declare-styleable>
|
||||
|
||||
<declare-styleable name="BookmarkFolderView">
|
||||
<attr name="state_open" format="boolean"/>
|
||||
<attr name="parent" format="boolean"/>
|
||||
<attr name="reading_list" format="boolean"/>
|
||||
</declare-styleable>
|
||||
|
||||
<declare-styleable name="IconTabWidget">
|
||||
|
Loading…
Reference in New Issue
Block a user