-
-
Notifications
You must be signed in to change notification settings - Fork 106
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
The Tabs Bar is a small window that sits adyacent to the current window and which lists the open tabs. This is a very simple implementation for now, as we test and iterate. Other minor changes: - TabsBar is managed by VRBrowserActivity - Add session change listeners to SessionStore - Move TabDelegate to a separate interface
- Loading branch information
1 parent
22da6fa
commit eb31be6
Showing
16 changed files
with
887 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
117 changes: 117 additions & 0 deletions
117
app/src/common/shared/com/igalia/wolvic/ui/adapters/TabsBarAdapter.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,117 @@ | ||
package com.igalia.wolvic.ui.adapters; | ||
|
||
import android.util.Log; | ||
import android.view.LayoutInflater; | ||
import android.view.ViewGroup; | ||
|
||
import androidx.annotation.LayoutRes; | ||
import androidx.annotation.NonNull; | ||
import androidx.recyclerview.widget.RecyclerView; | ||
|
||
import com.igalia.wolvic.R; | ||
import com.igalia.wolvic.browser.engine.Session; | ||
import com.igalia.wolvic.browser.engine.SessionStore; | ||
import com.igalia.wolvic.ui.views.TabsBarItem; | ||
import com.igalia.wolvic.ui.widgets.TabDelegate; | ||
import com.igalia.wolvic.utils.SystemUtils; | ||
|
||
import java.util.ArrayList; | ||
import java.util.Collections; | ||
import java.util.List; | ||
|
||
public class TabsBarAdapter extends RecyclerView.Adapter<TabsBarAdapter.ViewHolder> { | ||
|
||
private static final String LOGTAG = SystemUtils.createLogtag(TabsBarAdapter.class); | ||
|
||
public enum Orientation {HORIZONTAL, VERTICAL} | ||
|
||
private final TabDelegate mTabDelegate; | ||
private final Orientation mOrientation; | ||
private List<Session> mTabs = new ArrayList<>(); | ||
|
||
static class ViewHolder extends RecyclerView.ViewHolder { | ||
TabsBarItem mTabBarItem; | ||
|
||
ViewHolder(TabsBarItem v) { | ||
super(v); | ||
mTabBarItem = v; | ||
} | ||
} | ||
|
||
public TabsBarAdapter(@NonNull TabDelegate tabDelegate, Orientation orientation) { | ||
mTabDelegate = tabDelegate; | ||
mOrientation = orientation; | ||
} | ||
|
||
@Override | ||
public long getItemId(int position) { | ||
if (position == 0) { | ||
return 0; | ||
} else { | ||
return mTabs.get(position - 1).getId().hashCode(); | ||
} | ||
} | ||
|
||
public void updateTabs(List<Session> aTabs) { | ||
mTabs = aTabs; | ||
|
||
Log.e(LOGTAG, "updateTabs: " + aTabs.size()); | ||
for (Session session : aTabs) { | ||
Log.e(LOGTAG, " " + session.getCurrentUri() + " " + session.getLastUse()); | ||
} | ||
|
||
notifyDataSetChanged(); | ||
} | ||
|
||
@NonNull | ||
@Override | ||
public ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) { | ||
@LayoutRes int layout; | ||
if (mOrientation == Orientation.HORIZONTAL) { | ||
layout = R.layout.tabs_bar_item_horizontal; | ||
} else { | ||
layout = R.layout.tabs_bar_item_vertical; | ||
} | ||
TabsBarItem view = (TabsBarItem) LayoutInflater.from(parent.getContext()).inflate(layout, parent, false); | ||
return new ViewHolder(view); | ||
} | ||
|
||
@Override | ||
public void onBindViewHolder(@NonNull ViewHolder holder, int position) { | ||
if (position > 0) { | ||
Session session = mTabs.get(position - 1); | ||
holder.mTabBarItem.attachToSession(session); | ||
holder.mTabBarItem.setMode(TabsBarItem.Mode.TAB_DETAILS); | ||
holder.mTabBarItem.setDelegate(mItemDelegate); | ||
} else { | ||
holder.mTabBarItem.attachToSession(null); | ||
holder.mTabBarItem.setMode(TabsBarItem.Mode.ADD_TAB); | ||
} | ||
} | ||
|
||
@Override | ||
public int getItemCount() { | ||
return mTabs.size() + 1; | ||
} | ||
|
||
private final TabsBarItem.Delegate mItemDelegate = new TabsBarItem.Delegate() { | ||
@Override | ||
public void onAdd(TabsBarItem item) { | ||
|
||
Log.e(LOGTAG, "TabsBarItem.Delegate onAdd"); | ||
|
||
mTabDelegate.onTabAdd(); | ||
} | ||
|
||
@Override | ||
public void onClick(TabsBarItem item) { | ||
mTabDelegate.onTabSelect(item.getSession()); | ||
} | ||
|
||
@Override | ||
public void onClose(TabsBarItem item) { | ||
mTabDelegate.onTabsClose(Collections.singletonList(item.getSession())); | ||
// this should eventually trigger a refresh of the tabs | ||
} | ||
}; | ||
} |
Oops, something went wrong.