diff --git a/app/src/common/shared/com/igalia/wolvic/ui/adapters/NewTabAdapter.java b/app/src/common/shared/com/igalia/wolvic/ui/adapters/NewTabAdapter.java index 98dbc2d5c4..36b093dcc5 100644 --- a/app/src/common/shared/com/igalia/wolvic/ui/adapters/NewTabAdapter.java +++ b/app/src/common/shared/com/igalia/wolvic/ui/adapters/NewTabAdapter.java @@ -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; @@ -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; @@ -24,10 +29,17 @@ public class NewTabAdapter extends RecyclerView.Adapter { + private static final int ICON_ANIMATION_DURATION = 200; + private List 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 bookmarkNodes) { @@ -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(); @@ -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(); @@ -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; + }; } \ No newline at end of file diff --git a/app/src/common/shared/com/igalia/wolvic/ui/views/NewTabView.java b/app/src/common/shared/com/igalia/wolvic/ui/views/NewTabView.java index f91cd1bec8..8453bd0a17 100644 --- a/app/src/common/shared/com/igalia/wolvic/ui/views/NewTabView.java +++ b/app/src/common/shared/com/igalia/wolvic/ui/views/NewTabView.java @@ -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; @@ -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; @@ -68,6 +75,7 @@ public void updateUI() { v.requestFocusFromTouch(); return false; }); + } private void updateBookmarks() { @@ -86,4 +94,26 @@ private void showBookmarks(List 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) { + + } + }; } \ No newline at end of file diff --git a/app/src/common/shared/com/igalia/wolvic/ui/widgets/WindowWidget.java b/app/src/common/shared/com/igalia/wolvic/ui/widgets/WindowWidget.java index 7b26eca7d5..a5749080bd 100644 --- a/app/src/common/shared/com/igalia/wolvic/ui/widgets/WindowWidget.java +++ b/app/src/common/shared/com/igalia/wolvic/ui/widgets/WindowWidget.java @@ -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; @@ -2033,8 +2039,9 @@ WResult 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); @@ -2045,9 +2052,14 @@ WResult 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(); diff --git a/app/src/common/shared/com/igalia/wolvic/utils/UrlUtils.java b/app/src/common/shared/com/igalia/wolvic/utils/UrlUtils.java index 00567d996c..072051315d 100644 --- a/app/src/common/shared/com/igalia/wolvic/utils/UrlUtils.java +++ b/app/src/common/shared/com/igalia/wolvic/utils/UrlUtils.java @@ -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) { @@ -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) { diff --git a/app/src/main/res/layout/bookmark_item.xml b/app/src/main/res/layout/bookmark_item.xml index 25b590aaae..33f5aac161 100644 --- a/app/src/main/res/layout/bookmark_item.xml +++ b/app/src/main/res/layout/bookmark_item.xml @@ -23,26 +23,26 @@ + android:background="@color/void_color" + app:startMargin="@{item.level*100}"> - + android:soundEffectsEnabled="false"> + android:gravity="center_vertical" + android:orientation="vertical"> + android:visibility="visible" + tools:text="http://mozilla.org" /> + app:visibleInvisible="@{isHovered}"> - + diff --git a/app/src/main/res/layout/bookmark_item_1.xml b/app/src/main/res/layout/bookmark_item_1.xml new file mode 100644 index 0000000000..33f5aac161 --- /dev/null +++ b/app/src/main/res/layout/bookmark_item_1.xml @@ -0,0 +1,138 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/app/src/main/res/layout/new_tab_1.xml b/app/src/main/res/layout/new_tab_1.xml index 07db62907f..23c300592a 100644 --- a/app/src/main/res/layout/new_tab_1.xml +++ b/app/src/main/res/layout/new_tab_1.xml @@ -3,20 +3,50 @@ xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto"> - - - - - + android:layout_height="match_parent" + android:orientation="vertical" + android:gravity="center" + android:background="@color/void_color"> + + + + + + + + + + + + + \ No newline at end of file