-
-
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.
Initial implementation of browser tabs
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 8acbe88
Showing
18 changed files
with
874 additions
and
9 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
109 changes: 109 additions & 0 deletions
109
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,109 @@ | ||
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.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 final 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.clear(); | ||
mTabs.addAll(aTabs); | ||
|
||
Log.e(LOGTAG, "updateTabs: " + aTabs.size()); | ||
for (Session session : aTabs) { | ||
Log.e(LOGTAG, " " + session.getCurrentUri() + " " + session.getLastUse() + (session.isActive() ? " ACTIVE" : "")); | ||
} | ||
|
||
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) { | ||
holder.mTabBarItem.setDelegate(mItemDelegate); | ||
|
||
Session session = mTabs.get(position); | ||
holder.mTabBarItem.attachToSession(session); | ||
} | ||
|
||
@Override | ||
public int getItemCount() { | ||
return mTabs.size(); | ||
} | ||
|
||
private final TabsBarItem.Delegate mItemDelegate = new TabsBarItem.Delegate() { | ||
@Override | ||
public void onClick(TabsBarItem item) { | ||
Log.e(LOGTAG, "onClick"); | ||
|
||
mTabDelegate.onTabSelect(item.getSession()); | ||
} | ||
|
||
@Override | ||
public void onClose(TabsBarItem item) { | ||
Log.e(LOGTAG, "onClose"); | ||
|
||
mTabDelegate.onTabsClose(Collections.singletonList(item.getSession())); | ||
|
||
// this should eventually trigger a refresh of the tabs | ||
} | ||
}; | ||
} |
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
Oops, something went wrong.