зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1220928 - Add remote client children. r=sebastian
MozReview-Commit-ID: F5DYHrR5p99 --HG-- extra : rebase_source : 45031585da6ad7bca4d7d3fa6b04d3d14d0b83ca extra : source : 875fbe8190d373075e85eaf5dd692f707cdcdcfa
This commit is contained in:
Родитель
df5f443116
Коммит
6b0f5b6bfc
|
@ -14,15 +14,17 @@ import android.view.View;
|
|||
import android.view.ViewGroup;
|
||||
import org.mozilla.gecko.R;
|
||||
import org.mozilla.gecko.db.RemoteClient;
|
||||
import org.mozilla.gecko.db.RemoteTab;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class CombinedHistoryAdapter extends RecyclerView.Adapter<CombinedHistoryItem> {
|
||||
private static final String LOGTAG = "GeckoCombinedHistAdapt";
|
||||
|
||||
public enum ItemType {
|
||||
CLIENT, HISTORY;
|
||||
CLIENT, HISTORY, NAVIGATION_BACK, CHILD;
|
||||
|
||||
public static ItemType viewTypeToItemType(int viewType) {
|
||||
if (viewType >= ItemType.values().length) {
|
||||
|
@ -37,9 +39,12 @@ public class CombinedHistoryAdapter extends RecyclerView.Adapter<CombinedHistory
|
|||
}
|
||||
|
||||
private List<RemoteClient> remoteClients = Collections.emptyList();
|
||||
private List<RemoteTab> clientChildren;
|
||||
private Cursor historyCursor;
|
||||
private final Context context;
|
||||
|
||||
private boolean inChildView = false;
|
||||
|
||||
public CombinedHistoryAdapter(Context context) {
|
||||
super();
|
||||
this.context = context;
|
||||
|
@ -55,11 +60,30 @@ public class CombinedHistoryAdapter extends RecyclerView.Adapter<CombinedHistory
|
|||
notifyDataSetChanged();
|
||||
}
|
||||
|
||||
public void showChildView(int parentPosition) {
|
||||
if (clientChildren == null) {
|
||||
clientChildren = new ArrayList<>();
|
||||
}
|
||||
// Handle "back" view.
|
||||
clientChildren.add(null);
|
||||
clientChildren.addAll(remoteClients.get(transformPosition(ItemType.CLIENT, parentPosition)).tabs);
|
||||
inChildView = true;
|
||||
notifyDataSetChanged();
|
||||
}
|
||||
|
||||
public void exitChildView() {
|
||||
inChildView = false;
|
||||
clientChildren.clear();
|
||||
notifyDataSetChanged();
|
||||
}
|
||||
|
||||
private int transformPosition(ItemType type, int position) {
|
||||
if (type == ItemType.CLIENT) {
|
||||
return position;
|
||||
} else {
|
||||
} else if (type == ItemType.HISTORY){
|
||||
return position - remoteClients.size();
|
||||
} else {
|
||||
return position;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -74,6 +98,12 @@ public class CombinedHistoryAdapter extends RecyclerView.Adapter<CombinedHistory
|
|||
case CLIENT:
|
||||
view = inflater.inflate(R.layout.home_remote_tabs_group, viewGroup, false);
|
||||
return new CombinedHistoryItem.ClientItem(view);
|
||||
|
||||
case NAVIGATION_BACK:
|
||||
view = inflater.inflate(R.layout.home_combined_back_item, viewGroup, false);
|
||||
return new CombinedHistoryItem.HistoryItem(view);
|
||||
|
||||
case CHILD:
|
||||
case HISTORY:
|
||||
view = inflater.inflate(R.layout.home_item_row, viewGroup, false);
|
||||
return new CombinedHistoryItem.HistoryItem(view);
|
||||
|
@ -84,15 +114,28 @@ public class CombinedHistoryAdapter extends RecyclerView.Adapter<CombinedHistory
|
|||
|
||||
@Override
|
||||
public int getItemViewType(int position) {
|
||||
final int numClients = remoteClients.size();
|
||||
return (position < numClients) ? ItemType.itemTypeToViewType(ItemType.CLIENT) : ItemType.itemTypeToViewType(ItemType.HISTORY);
|
||||
if (inChildView) {
|
||||
if (position == 0) {
|
||||
return ItemType.itemTypeToViewType(ItemType.NAVIGATION_BACK);
|
||||
} else {
|
||||
return ItemType.itemTypeToViewType(ItemType.CHILD);
|
||||
}
|
||||
} else {
|
||||
final int numClients = remoteClients.size();
|
||||
return (position < numClients) ? ItemType.itemTypeToViewType(ItemType.CLIENT) : ItemType.itemTypeToViewType(ItemType.HISTORY);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getItemCount() {
|
||||
final int remoteSize = remoteClients.size();
|
||||
final int historySize = historyCursor == null ? 0 : historyCursor.getCount();
|
||||
return remoteSize + historySize;
|
||||
|
||||
if (inChildView) {
|
||||
return (clientChildren == null) ? 0 : clientChildren.size();
|
||||
} else {
|
||||
final int remoteSize = remoteClients.size();
|
||||
final int historySize = historyCursor == null ? 0 : historyCursor.getCount();
|
||||
return remoteSize + historySize;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -107,6 +150,11 @@ public class CombinedHistoryAdapter extends RecyclerView.Adapter<CombinedHistory
|
|||
clientItem.bind(client, context);
|
||||
break;
|
||||
|
||||
case CHILD:
|
||||
RemoteTab remoteTab = clientChildren.get(position);
|
||||
((CombinedHistoryItem.HistoryItem) viewHolder).bind(remoteTab);
|
||||
break;
|
||||
|
||||
case HISTORY:
|
||||
if (historyCursor == null || !historyCursor.moveToPosition(localPosition)) {
|
||||
throw new IllegalStateException("Couldn't move cursor to position " + localPosition);
|
||||
|
|
|
@ -14,6 +14,7 @@ import android.widget.TextView;
|
|||
import org.mozilla.gecko.R;
|
||||
import org.mozilla.gecko.RemoteTabsExpandableListAdapter;
|
||||
import org.mozilla.gecko.db.RemoteClient;
|
||||
import org.mozilla.gecko.db.RemoteTab;
|
||||
|
||||
public abstract class CombinedHistoryItem extends RecyclerView.ViewHolder {
|
||||
public CombinedHistoryItem(View view) {
|
||||
|
@ -30,6 +31,12 @@ public abstract class CombinedHistoryItem extends RecyclerView.ViewHolder {
|
|||
pageRow.setShowIcons(true);
|
||||
pageRow.updateFromCursor(historyCursor);
|
||||
}
|
||||
|
||||
public void bind(RemoteTab remoteTab) {
|
||||
final TwoLinePageRow childPageRow = (TwoLinePageRow) this.itemView;
|
||||
childPageRow.setShowIcons(true);
|
||||
childPageRow.update(remoteTab.title, remoteTab.url);
|
||||
}
|
||||
}
|
||||
|
||||
public static class ClientItem extends CombinedHistoryItem {
|
||||
|
|
|
@ -57,14 +57,19 @@ public class CombinedHistoryRecyclerView extends RecyclerView
|
|||
|
||||
switch(itemType) {
|
||||
case CLIENT:
|
||||
// TODO: open new panel with all the remote children, and hide all the other items
|
||||
return;
|
||||
((CombinedHistoryAdapter) getAdapter()).showChildView(position);
|
||||
break;
|
||||
case NAVIGATION_BACK:
|
||||
((CombinedHistoryAdapter) getAdapter()).exitChildView();
|
||||
break;
|
||||
case CHILD:
|
||||
case HISTORY:
|
||||
if (mOnUrlOpenListener != null) {
|
||||
final TwoLinePageRow historyItem = (TwoLinePageRow) v;
|
||||
Telemetry.sendUIEvent(TelemetryContract.Event.LOAD_URL, TelemetryContract.Method.LIST_ITEM, "history");
|
||||
mOnUrlOpenListener.onUrlOpen(historyItem.getUrl(), EnumSet.of(HomePager.OnUrlOpenListener.Flags.ALLOW_SWITCH_TO_TAB));
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -523,6 +523,7 @@ size. -->
|
|||
with the page title defined in aboutHome.dtd -->
|
||||
<!ENTITY home_title "&brandShortName; Home">
|
||||
<!ENTITY home_history_title "History">
|
||||
<!ENTITY home_history_back_to "Go back to all history">
|
||||
<!ENTITY home_clear_history_button "Clear browsing history">
|
||||
<!ENTITY home_clear_history_confirm "Are you sure you want to clear your history?">
|
||||
<!ENTITY home_bookmarks_empty "Bookmarks you save show up here.">
|
||||
|
|
|
@ -4,8 +4,7 @@
|
|||
- file, You can obtain one at http://mozilla.org/MPL/2.0/. -->
|
||||
|
||||
<org.mozilla.gecko.home.BookmarkFolderView xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
style="@style/Widget.BookmarkFolderView"
|
||||
style="@style/Widget.FolderView"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="@dimen/page_group_height"
|
||||
android:minHeight="@dimen/page_group_height"
|
||||
android:drawableLeft="@drawable/bookmark_folder"
|
||||
android:gravity="center_vertical"/>
|
||||
|
|
|
@ -0,0 +1,11 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<!-- This Source Code Form is subject to the terms of the Mozilla Public
|
||||
- License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
- file, You can obtain one at http://mozilla.org/MPL/2.0/. -->
|
||||
|
||||
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
style="@style/Widget.FolderView"
|
||||
android:layout_width="match_parent"
|
||||
android:text="@string/home_history_back_to"
|
||||
android:drawableLeft="@drawable/arrow_up"
|
||||
android:gravity="center_vertical"/>
|
|
@ -163,13 +163,14 @@
|
|||
<item name="android:textColor">@color/fennec_ui_orange</item>
|
||||
</style>
|
||||
|
||||
<style name="Widget.BookmarkFolderView" parent="Widget.TwoLinePageRow.Title">
|
||||
<style name="Widget.FolderView" parent="Widget.TwoLinePageRow.Title">
|
||||
<item name="android:layout_height">@dimen/page_group_height</item>
|
||||
<item name="android:minHeight">@dimen/page_group_height</item>
|
||||
<item name="android:singleLine">true</item>
|
||||
<item name="android:ellipsize">none</item>
|
||||
<item name="android:background">@color/about_page_header_grey</item>
|
||||
<item name="android:paddingLeft">20dp</item>
|
||||
<item name="android:drawablePadding">20dp</item>
|
||||
<item name="android:drawableLeft">@drawable/bookmark_folder</item>
|
||||
</style>
|
||||
|
||||
<style name="Widget.PanelItemView" />
|
||||
|
|
|
@ -425,6 +425,7 @@
|
|||
<string name="home_top_sites_title">&home_top_sites_title;</string>
|
||||
<string name="home_top_sites_add">&home_top_sites_add;</string>
|
||||
<string name="home_history_title">&home_history_title;</string>
|
||||
<string name="home_history_back_to">&home_history_back_to;</string>
|
||||
<string name="home_clear_history_button">&home_clear_history_button;</string>
|
||||
<string name="home_clear_history_confirm">&home_clear_history_confirm;</string>
|
||||
<string name="home_bookmarks_empty">&home_bookmarks_empty;</string>
|
||||
|
|
Загрузка…
Ссылка в новой задаче