Skip to content

Commit

Permalink
Change the layout of bookmark items and hide NewTabView when not needed
Browse files Browse the repository at this point in the history
  • Loading branch information
haanhvu committed Nov 4, 2024
1 parent efd8dd2 commit e3080e9
Show file tree
Hide file tree
Showing 7 changed files with 296 additions and 46 deletions.
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
package com.igalia.wolvic.ui.adapters;

import android.annotation.SuppressLint;
import android.content.Context;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.MotionEvent;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;

import androidx.annotation.NonNull;
import androidx.databinding.DataBindingUtil;
Expand All @@ -13,6 +16,8 @@
import com.igalia.wolvic.R;
import com.igalia.wolvic.browser.engine.SessionStore;
import com.igalia.wolvic.databinding.BookmarkItemBinding;
import com.igalia.wolvic.ui.widgets.WidgetPlacement;
import com.igalia.wolvic.utils.AnimationHelper;

import java.util.ArrayList;
import java.util.Collections;
Expand All @@ -24,10 +29,17 @@

public class NewTabAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> {

private static final int ICON_ANIMATION_DURATION = 200;

private List<Bookmark> bookmarkItems;

public NewTabAdapter() {
private int mMinPadding;
private int mMaxPadding;


public NewTabAdapter(Context aContext) {
mMinPadding = WidgetPlacement.pixelDimension(aContext, R.dimen.library_icon_padding_min);
mMaxPadding = WidgetPlacement.pixelDimension(aContext, R.dimen.library_icon_padding_max);
}

public void setBookmarkListInNewTab(final List<BookmarkNode> bookmarkNodes) {
Expand Down Expand Up @@ -113,7 +125,7 @@ public void onBindViewHolder(@NonNull RecyclerView.ViewHolder holder, int positi
}
return false;
});
//binding.more.setOnHoverListener(mIconHoverListener);
binding.more.setOnHoverListener(mIconHoverListener);
binding.more.setOnTouchListener((view, motionEvent) -> {
binding.setIsHovered(true);
int ev = motionEvent.getActionMasked();
Expand All @@ -136,7 +148,7 @@ public void onBindViewHolder(@NonNull RecyclerView.ViewHolder holder, int positi
}
return false;
});
//binding.trash.setOnHoverListener(mIconHoverListener);
binding.trash.setOnHoverListener(mIconHoverListener);
binding.trash.setOnTouchListener((view, motionEvent) -> {
binding.setIsHovered(true);
int ev = motionEvent.getActionMasked();
Expand Down Expand Up @@ -166,4 +178,27 @@ public int getItemCount() {
return bookmarkItems == null ? 0 : bookmarkItems.size();
}

private View.OnHoverListener mIconHoverListener = (view, motionEvent) -> {
ImageView icon = (ImageView) view;
int ev = motionEvent.getActionMasked();
switch (ev) {
case MotionEvent.ACTION_HOVER_ENTER:
icon.setImageState(new int[]{android.R.attr.state_hovered}, true);
AnimationHelper.animateViewPadding(view,
mMaxPadding,
mMinPadding,
ICON_ANIMATION_DURATION);
return false;

case MotionEvent.ACTION_HOVER_EXIT:
icon.setImageState(new int[]{android.R.attr.state_active}, true);
AnimationHelper.animateViewPadding(view,
mMinPadding,
mMaxPadding,
ICON_ANIMATION_DURATION);
return false;
}

return false;
};
}
32 changes: 31 additions & 1 deletion app/src/common/shared/com/igalia/wolvic/ui/views/NewTabView.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,19 @@
import android.view.View;
import android.widget.FrameLayout;

import androidx.annotation.NonNull;
import androidx.databinding.DataBindingUtil;
import androidx.recyclerview.widget.LinearLayoutManager;

import com.igalia.wolvic.R;
import com.igalia.wolvic.VRBrowserActivity;
import com.igalia.wolvic.VRBrowserApplication;
import com.igalia.wolvic.browser.engine.SessionStore;
import com.igalia.wolvic.databinding.NewTab1Binding;
import com.igalia.wolvic.ui.adapters.Bookmark;
import com.igalia.wolvic.ui.adapters.CustomLinearLayoutManager;
import com.igalia.wolvic.ui.adapters.NewTabAdapter;
import com.igalia.wolvic.ui.callbacks.BookmarkItemCallback;

import mozilla.appservices.places.BookmarkRoot;
import mozilla.components.concept.storage.BookmarkNode;
Expand Down Expand Up @@ -47,8 +52,10 @@ public void updateUI() {
mBinding = DataBindingUtil.inflate(inflater, R.layout.new_tab_1, this, true);
mBinding.setLifecycleOwner((VRBrowserActivity)getContext());

mNewTabAdapter = new NewTabAdapter();
mNewTabAdapter = new NewTabAdapter(getContext());
mBinding.bookmarksList.setAdapter(mNewTabAdapter);
CustomLinearLayoutManager layoutManager = new CustomLinearLayoutManager(getContext(), LinearLayoutManager.HORIZONTAL, false);
mBinding.bookmarksList.setLayoutManager(layoutManager);
mBinding.bookmarksList.setOnTouchListener((v, event) -> {
v.requestFocusFromTouch();
return false;
Expand All @@ -68,6 +75,7 @@ public void updateUI() {
v.requestFocusFromTouch();
return false;
});

}

private void updateBookmarks() {
Expand All @@ -86,4 +94,26 @@ private void showBookmarks(List<BookmarkNode> aBookmarks) {
mNewTabAdapter.setBookmarkListInNewTab(aBookmarks);
mBinding.executePendingBindings();
}

private final BookmarkItemCallback mBookmarkItemCallback = new BookmarkItemCallback() {
@Override
public void onClick(@NonNull View view, @NonNull Bookmark item) {

}

@Override
public void onDelete(@NonNull View view, @NonNull Bookmark item) {

}

@Override
public void onMore(@NonNull View view, @NonNull Bookmark item) {

}

@Override
public void onFolderOpened(@NonNull Bookmark item) {

}
};
}
Original file line number Diff line number Diff line change
Expand Up @@ -596,6 +596,12 @@ private void hidePanel(boolean switchSurface) {
}
}

private void hideNewTab(boolean switchSurface) {
unsetView(mNewTab, switchSurface);
mRestoreFirstPaint.run();
mRestoreFirstPaint = null;
}

public void pauseCompositor() {
if (mSession == null) {
return;
Expand Down Expand Up @@ -2033,8 +2039,9 @@ WResult<WAllowOrDeny> onLoadRequest(WSession aSession, @NonNull LoadRequest aReq

Uri uri = Uri.parse(aRequest.uri);
if (UrlUtils.isAboutPage(uri.toString())) {
if(UrlUtils.isBookmarksUrl(uri.toString())) {
showPanel(Windows.BOOKMARKS);
if(UrlUtils.isBookmarksUrl(uri.toString())) {
hideNewTab(true);
showPanel(Windows.BOOKMARKS);

} else if (UrlUtils.isHistoryUrl(uri.toString())) {
showPanel(Windows.HISTORY);
Expand All @@ -2045,9 +2052,14 @@ WResult<WAllowOrDeny> onLoadRequest(WSession aSession, @NonNull LoadRequest aReq
} else if (UrlUtils.isAddonsUrl(uri.toString())) {
showPanel(Windows.ADDONS);

} else {
} else if (UrlUtils.isNewTabUrl(uri.toString())) {
hideLibraryPanel();
}
showNewTab();

} else {
hideLibraryPanel();

}

} else {
hideLibraryPanel();
Expand Down
8 changes: 7 additions & 1 deletion app/src/common/shared/com/igalia/wolvic/utils/UrlUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,12 @@ public static boolean isBookmarksUrl(@Nullable String url) {
return url != null && url.equalsIgnoreCase(ABOUT_BOOKMARKS);
}

public static final String ABOUT_NEWTAB = "about://newtab";

public static boolean isNewTabUrl(@Nullable String url) {
return url != null && url.equalsIgnoreCase(ABOUT_NEWTAB);
}

public static final String ABOUT_DOWNLOADS = "about://downloads";

public static boolean isDownloadsUrl(@Nullable String url) {
Expand Down Expand Up @@ -225,7 +231,7 @@ public static boolean isPrivateUrl(@Nullable String url) {
}

public static boolean isAboutPage(@Nullable String url) {
return isHistoryUrl(url) || isBookmarksUrl(url) || isDownloadsUrl(url) || isAddonsUrl(url) || isPrivateUrl(url);
return isHistoryUrl(url) || isBookmarksUrl(url) || isDownloadsUrl(url) || isAddonsUrl(url) || isPrivateUrl(url) || isNewTabUrl(url);
}

public static boolean isContentFeed(Context aContext, @Nullable String url) {
Expand Down
43 changes: 21 additions & 22 deletions app/src/main/res/layout/bookmark_item.xml
Original file line number Diff line number Diff line change
Expand Up @@ -23,37 +23,36 @@
</data>

<FrameLayout
android:layout_width="match_parent"
android:layout_height="@dimen/library_item_row_height"
app:layout_height="@{isNarrow ? @dimen/library_item_row_height_narrow : @dimen/library_item_row_height}"
app:startMargin="@{item.level*100}"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginEnd="20dp"
android:background="@color/void_color">
android:background="@color/void_color"
app:startMargin="@{item.level*100}">

<RelativeLayout
<LinearLayout
android:id="@+id/layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:addStatesFromChildren="true"
android:background="@drawable/library_item_background_color"
android:clickable="true"
android:focusable="true"
android:gravity="center_vertical"
android:gravity="center"
android:onClick="@{(view) -> callback.onClick(view, item)}"
android:orientation="vertical"
android:paddingStart="10dp"
android:paddingEnd="10dp"
android:soundEffectsEnabled="false"
android:addStatesFromChildren="true">
android:soundEffectsEnabled="false">

<LinearLayout
android:id="@+id/title_url"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentStart="true"
android:layout_centerVertical="true"
android:gravity="center_vertical"
android:layout_toStartOf="@id/buttons_container"
android:addStatesFromChildren="true"
android:orientation="@{isNarrow ? LinearLayout.VERTICAL : LinearLayout.HORIZONTAL}">
android:gravity="center_vertical"
android:orientation="vertical">

<LinearLayout
android:layout_width="wrap_content"
Expand Down Expand Up @@ -87,8 +86,8 @@

<TextView
android:id="@+id/url"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:layout_height="38dp"
android:layout_weight="1"
android:ellipsize="middle"
android:paddingEnd="20dp"
Expand All @@ -97,8 +96,8 @@
android:text="@{item.url}"
android:textColor="@color/library_panel_description_color"
android:textSize="@dimen/library_item_url_text_size"
tools:text="http://mozilla.org"
android:visibility="visible"/>
android:visibility="visible"
tools:text="http://mozilla.org" />
</LinearLayout>

<LinearLayout
Expand All @@ -107,10 +106,10 @@
android:layout_height="wrap_content"
android:layout_alignParentEnd="true"
android:layout_centerVertical="true"
android:layout_gravity="end"
android:layout_gravity="center"
android:addStatesFromChildren="true"
android:orientation="horizontal"
app:visibleInvisible="@{isHovered}"
android:addStatesFromChildren="true">
app:visibleInvisible="@{isHovered}">

<ImageView
android:id="@+id/trash"
Expand All @@ -134,6 +133,6 @@
android:tint="@color/library_panel_icon_color"
app:srcCompat="@drawable/ic_icon_more_options" />
</LinearLayout>
</RelativeLayout>
</LinearLayout>
</FrameLayout>
</layout>
Loading

0 comments on commit e3080e9

Please sign in to comment.