Skip to content

Commit

Permalink
Reorganize Libraries and add search UI in panels
Browse files Browse the repository at this point in the history
Create a separate location in the UI for each functionality

- (Library) Bookmarks/History
- Downloads
- Add-ons
- Web Apps

Add launchers in the UI to open each of those locations

- (Library) Bookmarks/History, Downloads and Web Apps from the tray
- Add-ons from Hamburger Menu

Add Search UI in:

- Bookmarks
- History
- Downloads
- Web Apps

Signed-off-by: Songlin Jiang <[email protected]>
  • Loading branch information
HollowMan6 committed Mar 22, 2024
1 parent 4ccfb3b commit af26d40
Show file tree
Hide file tree
Showing 35 changed files with 1,389 additions and 234 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1137,7 +1137,7 @@ void handleMotionEvent(final int aHandle, final int aDevice, final boolean aFocu
// We shouldn't divide the scale factor when we pass the motion event to the web engine
if (widget instanceof WindowWidget) {
WindowWidget windowWidget = (WindowWidget) widget;
if (!windowWidget.isLibraryVisible()) {
if (windowWidget.isInWebPage()) {
scale = 1.0f;
}
}
Expand Down
149 changes: 149 additions & 0 deletions app/src/common/shared/com/igalia/wolvic/addons/views/AddonsPanel.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,149 @@
package com.igalia.wolvic.addons.views;

import android.annotation.SuppressLint;
import android.content.Context;
import android.content.res.Configuration;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.FrameLayout;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.databinding.DataBindingUtil;

import com.igalia.wolvic.BuildConfig;
import com.igalia.wolvic.R;
import com.igalia.wolvic.VRBrowserActivity;
import com.igalia.wolvic.VRBrowserApplication;
import com.igalia.wolvic.databinding.LibraryBinding;
import com.igalia.wolvic.ui.delegates.LibraryNavigationDelegate;
import com.igalia.wolvic.ui.widgets.WidgetManagerDelegate;

import java.util.concurrent.Executor;

public class AddonsPanel extends FrameLayout {

private LibraryBinding mBinding;
protected WidgetManagerDelegate mWidgetManager;
protected Executor mUIThreadExecutor;
private AddonsView mAddonsView;

public AddonsPanel(@NonNull Context context) {
super(context);
initialize();
}

public AddonsPanel(@NonNull Context context, @Nullable AttributeSet attrs) {
super(context, attrs);
initialize();
}

public AddonsPanel(@NonNull Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
super(context, attrs, defStyleAttr);
initialize();
}

protected void initialize() {
mWidgetManager = ((VRBrowserActivity) getContext());
mUIThreadExecutor = ((VRBrowserApplication) getContext().getApplicationContext()).getExecutors().mainThread();

mAddonsView = new AddonsView(getContext(), this);

updateUI();
}

@SuppressLint("ClickableViewAccessibility")
public void updateUI() {
removeAllViews();

LayoutInflater inflater = LayoutInflater.from(getContext());

// Inflate this data binding layout
mBinding = DataBindingUtil.inflate(inflater, R.layout.library, this, true);
mBinding.searchBar.setVisibility(View.GONE);
mBinding.buttons.setVisibility(View.GONE);
mBinding.setLifecycleOwner((VRBrowserActivity) getContext());
mBinding.setSupportsSystemNotifications(BuildConfig.SUPPORTS_SYSTEM_NOTIFICATIONS);
mBinding.setDelegate(new LibraryNavigationDelegate() {
@Override
public void onClose(@NonNull View view) {
requestFocus();
mWidgetManager.getFocusedWindow().hideAddonsPanel();
}

@Override
public void onBack(@NonNull View view) {
requestFocus();
mAddonsView.onBack();
mBinding.setCanGoBack(mAddonsView.canGoBack());
}

@Override
public void onButtonClick(@NonNull View view) {
requestFocus();
selectTab();
}
});
mBinding.executePendingBindings();

selectTab();

setOnTouchListener((v, event) -> {
v.requestFocusFromTouch();
return false;
});
}

@Override
public void onConfigurationChanged(Configuration newConfig) {
super.onConfigurationChanged(newConfig);

if (mBinding != null) {
mBinding.tabcontent.removeAllViews();
}

mAddonsView.updateUI();

updateUI();
}

public void onShow() {
if (mAddonsView != null) {
mAddonsView.onShow();
mBinding.searchBar.setQuery("", false);
mBinding.searchBar.clearFocus();
}
}

public void onHide() {
if (mAddonsView != null) {
mAddonsView.onHide();
}
}

public boolean onBack() {
if (mAddonsView != null) {
return mAddonsView.onBack();
}

return false;
}

public void onDestroy() {
mAddonsView.onDestroy();
}

private void selectTab() {
mBinding.setCanGoBack(mAddonsView.canGoBack());
mBinding.tabcontent.addView(mAddonsView);
mAddonsView.onShow();
}

public void onViewUpdated(@NonNull String title) {
if (mBinding != null) {
mBinding.title.setText(title);
mBinding.setCanGoBack(mAddonsView.canGoBack());
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
import com.igalia.wolvic.addons.adapters.AddonsViewAdapter;
import com.igalia.wolvic.addons.delegates.AddonsDelegate;
import com.igalia.wolvic.databinding.AddonsBinding;
import com.igalia.wolvic.ui.views.library.LibraryPanel;
import com.igalia.wolvic.ui.views.library.LibraryView;
import com.igalia.wolvic.utils.SystemUtils;

Expand All @@ -25,16 +24,17 @@ public class AddonsView extends LibraryView implements AddonsDelegate {

private AddonsBinding mBinding;
private AddonsViewAdapter mAdapter;
private AddonsPanel mAddonsPanel;

public AddonsView(@NonNull Context context) {
super(context);

initialize();
}

public AddonsView(@NonNull Context context, @NonNull LibraryPanel rootPanel) {
super(context, rootPanel);

public AddonsView(@NonNull Context context, @NonNull AddonsPanel panel) {
super(context);
mAddonsPanel = panel;
initialize();
}

Expand Down Expand Up @@ -79,12 +79,12 @@ public void onShow() {
updateLayout();

if (mBinding.pager.getCurrentItem() == AddonsViewAdapter.ADDONS_LEVEL_0) {
if (mRootPanel != null) {
mRootPanel.onViewUpdated(getContext().getString(R.string.addons_title));
if (mAddonsPanel != null) {
mAddonsPanel.onViewUpdated(getContext().getString(R.string.addons_title));
}
} else {
if (mRootPanel != null) {
mRootPanel.onViewUpdated(ExtensionsKt.translateName(mAdapter.getCurrentAddon(), getContext()));
if (mAddonsPanel != null) {
mAddonsPanel.onViewUpdated(ExtensionsKt.translateName(mAdapter.getCurrentAddon(), getContext()));
}
}
}
Expand Down Expand Up @@ -144,8 +144,8 @@ public void showAddonsList() {
mAdapter.setCurrentAddon(null);
mAdapter.setCurrentItem(AddonsViewAdapter.ADDONS_LIST);
mBinding.pager.setCurrentItem(AddonsViewAdapter.ADDONS_LEVEL_0);
if (mRootPanel != null) {
mRootPanel.onViewUpdated(getContext().getString(R.string.addons_title));
if (mAddonsPanel != null) {
mAddonsPanel.onViewUpdated(getContext().getString(R.string.addons_title));
}
}

Expand All @@ -154,8 +154,8 @@ public void showAddonOptions(@NonNull Addon addon) {
mAdapter.setCurrentAddon(addon);
mAdapter.setCurrentItem(AddonsViewAdapter.ADDON_OPTIONS);
mBinding.pager.setCurrentItem(AddonsViewAdapter.ADDONS_LEVEL_1);
if (mRootPanel != null) {
mRootPanel.onViewUpdated(ExtensionsKt.translateName(addon, getContext()));
if (mAddonsPanel != null) {
mAddonsPanel.onViewUpdated(ExtensionsKt.translateName(addon, getContext()));
}
}

Expand All @@ -164,8 +164,8 @@ public void showAddonOptionsDetails(@NonNull Addon addon, int page) {
mAdapter.setCurrentAddon(addon);
mAdapter.setCurrentItem(AddonsViewAdapter.ADDON_OPTIONS_DETAILS);
mBinding.pager.setCurrentItem(page);
if (mRootPanel != null) {
mRootPanel.onViewUpdated(ExtensionsKt.translateName(addon, getContext()));
if (mAddonsPanel != null) {
mAddonsPanel.onViewUpdated(ExtensionsKt.translateName(addon, getContext()));
}
}

Expand All @@ -174,8 +174,8 @@ public void showAddonOptionsPermissions(@NonNull Addon addon) {
mAdapter.setCurrentAddon(addon);
mAdapter.setCurrentItem(AddonsViewAdapter.ADDON_OPTIONS_PERMISSIONS);
mBinding.pager.setCurrentItem(AddonsViewAdapter.ADDONS_LEVEL_2);
if (mRootPanel != null) {
mRootPanel.onViewUpdated(ExtensionsKt.translateName(addon, getContext()));
if (mAddonsPanel != null) {
mAddonsPanel.onViewUpdated(ExtensionsKt.translateName(addon, getContext()));
}
}

Expand Down
11 changes: 11 additions & 0 deletions app/src/common/shared/com/igalia/wolvic/browser/WebAppsStore.java
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,17 @@ private void saveWebAppsListToStorage() {
SettingsStore.getInstance(mContext).setWebAppsData(json);
}

public void updateWebAppOpenTime(@NonNull String id) {
WebApp existingWebApp = mWebApps.get(id);
if (existingWebApp == null) {
return;
}

existingWebApp.setLastOpenTime();
saveWebAppsListToStorage();
notifyListeners();
}

/**
* @return {@code true} if the map did not contain the specified Web app (so it was added),
* and {@code false} if the Web app was already in the list (so it was updated).
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
import java.util.Collections;
import java.util.List;
import java.util.Objects;
import java.util.stream.Collectors;

import mozilla.appservices.places.BookmarkRoot;
import mozilla.components.browser.icons.IconRequest;
Expand All @@ -46,6 +47,7 @@ public class BookmarkAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolde
private int mMinPadding;
private int mMaxPadding;
private boolean mIsNarrowLayout;
private String mSearchFilter = "";

@Nullable
private final BookmarkItemCallback mBookmarkItemCallback;
Expand All @@ -68,13 +70,28 @@ public void setNarrow(boolean isNarrow) {
}
}

public void setSearchFilter(String s) {
mSearchFilter = s;
}

private List<Bookmark> filterBookmarkList(List<Bookmark> list) {
return list.stream()
.filter(value -> {
if (value.getTitle() != null && !mSearchFilter.isEmpty()) {
return value.getTitle().toLowerCase().contains(mSearchFilter);
}
return true;
})
.collect(Collectors.toList());
}

public void setBookmarkList(final List<BookmarkNode> bookmarkList) {
mBookmarksList = bookmarkList;

List<Bookmark> newDisplayList;
if (mDisplayList == null || mDisplayList.isEmpty()) {
newDisplayList = Bookmark.getDisplayListTree(mBookmarksList, Collections.singletonList(BookmarkRoot.Mobile.getId()));
mDisplayList = newDisplayList;
mDisplayList = filterBookmarkList(newDisplayList);
for (Bookmark node : mDisplayList) {
if (node.isExpanded()) {
if (mBookmarkItemCallback != null) {
Expand All @@ -86,7 +103,7 @@ public void setBookmarkList(final List<BookmarkNode> bookmarkList) {

} else {
List<String> openFoldersGuid = Bookmark.getOpenFoldersGuid(mDisplayList);
newDisplayList = Bookmark.getDisplayListTree(mBookmarksList, openFoldersGuid);
newDisplayList = filterBookmarkList(Bookmark.getDisplayListTree(mBookmarksList, openFoldersGuid));
notifyDiff(newDisplayList);
}
}
Expand Down
14 changes: 14 additions & 0 deletions app/src/common/shared/com/igalia/wolvic/ui/adapters/WebApp.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
*/
public class WebApp {
@NonNull private String mIdentity;
@NonNull private long mLastOpenTime;
private WebAppManifest mManifest;
private OptionalInt mHashCode = OptionalInt.empty();

Expand Down Expand Up @@ -54,6 +55,7 @@ public WebApp(JSONObject manifest) throws IOException {
String id = manifest.optString("id");
URL identityUrl = new URL(startUrl.getProtocol(), startUrl.getHost(), startUrl.getPort(), id);
mIdentity = identityUrl.toString();
mLastOpenTime = 0;
} else {
// Since Identity is used to uniquely identify the Web application,
// we treat its absence as an error.
Expand All @@ -66,6 +68,16 @@ public String getId() {
return mIdentity;
}

@NonNull
public long getLastOpenTime() {
return mLastOpenTime;
}

@NonNull
public void setLastOpenTime() {
mLastOpenTime = System.currentTimeMillis();
}

public String getName() {
return mManifest.getName();
}
Expand Down Expand Up @@ -105,6 +117,7 @@ public List<IconRequest.Resource> getIconResources() {

public void copyFrom(WebApp webApp) {
mIdentity = webApp.mIdentity;
mLastOpenTime = webApp.mLastOpenTime;
mManifest = webApp.mManifest;
mHashCode = OptionalInt.empty();
}
Expand Down Expand Up @@ -133,6 +146,7 @@ public int hashCode() {
public String toString() {
return "WebApp{" +
"mIdentity='" + mIdentity + '\'' +
", mLastOpenTime='" + mLastOpenTime + '\'' +
", mName='" + getName() + '\'' +
", mShortName='" + getShortName() + '\'' +
", mScope='" + getScope() + '\'' +
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package com.igalia.wolvic.ui.callbacks;

import com.igalia.wolvic.ui.widgets.menus.library.DownloadsContextMenuWidget;
import com.igalia.wolvic.ui.widgets.menus.DownloadsContextMenuWidget;

public interface DownloadsContextMenuCallback extends LibraryContextMenuCallback {
void onDelete(DownloadsContextMenuWidget.DownloadsContextMenuItem item);
Expand Down
Loading

0 comments on commit af26d40

Please sign in to comment.