47
47
import org .mozilla .vrbrowser .ui .callbacks .LibraryItemContextMenuClickCallback ;
48
48
import org .mozilla .vrbrowser .ui .views .BookmarksView ;
49
49
import org .mozilla .vrbrowser .ui .views .HistoryView ;
50
- import org .mozilla .vrbrowser .ui .views .LibraryItemContextMenu ;
51
50
import org .mozilla .vrbrowser .ui .widgets .dialogs .BaseAppDialogWidget ;
52
51
import org .mozilla .vrbrowser .ui .widgets .dialogs .ClearCacheDialogWidget ;
53
- import org .mozilla .vrbrowser .ui .widgets .dialogs .LibraryItemContextMenuWidget ;
54
52
import org .mozilla .vrbrowser .ui .widgets .dialogs .MessageDialogWidget ;
55
53
import org .mozilla .vrbrowser .ui .widgets .dialogs .SelectionActionWidget ;
56
54
import org .mozilla .vrbrowser .ui .widgets .menus .ContextMenuWidget ;
55
+ import org .mozilla .vrbrowser .ui .widgets .menus .LibraryMenuWidget ;
57
56
import org .mozilla .vrbrowser .ui .widgets .prompts .AlertPromptWidget ;
58
57
import org .mozilla .vrbrowser .ui .widgets .prompts .ConfirmPromptWidget ;
59
58
import org .mozilla .vrbrowser .ui .widgets .prompts .PromptWidget ;
60
59
import org .mozilla .vrbrowser .ui .widgets .settings .SettingsWidget ;
61
60
import org .mozilla .vrbrowser .utils .SystemUtils ;
61
+ import org .mozilla .vrbrowser .utils .UIThreadExecutor ;
62
62
import org .mozilla .vrbrowser .utils .ViewUtils ;
63
63
64
64
import java .util .ArrayList ;
@@ -105,7 +105,7 @@ default void onBookmarksHidden(WindowWidget aWindow) {}
105
105
private ClearCacheDialogWidget mClearCacheDialog ;
106
106
private ContextMenuWidget mContextMenu ;
107
107
private SelectionActionWidget mSelectionMenu ;
108
- private LibraryItemContextMenuWidget mLibraryItemContextMenu ;
108
+ private LibraryMenuWidget mLibraryItemContextMenu ;
109
109
private int mWidthBackup ;
110
110
private int mHeightBackup ;
111
111
private int mBorderWidth ;
@@ -1310,7 +1310,7 @@ private int getWindowWidth(float aWorldWidth) {
1310
1310
return (int ) Math .floor (SettingsStore .WINDOW_WIDTH_DEFAULT * aWorldWidth / WidgetPlacement .floatDimension (getContext (), R .dimen .window_world_width ));
1311
1311
}
1312
1312
1313
- private void showLibraryItemContextMenu (@ NotNull View view , LibraryItemContextMenu .LibraryContextMenuItem item , boolean isLastVisibleItem ) {
1313
+ private void showLibraryItemContextMenu (@ NotNull View view , LibraryMenuWidget .LibraryContextMenuItem item , boolean isLastVisibleItem ) {
1314
1314
view .requestFocusFromTouch ();
1315
1315
1316
1316
hideContextMenus ();
@@ -1321,56 +1321,68 @@ private void showLibraryItemContextMenu(@NotNull View view, LibraryItemContextMe
1321
1321
getDrawingRect (offsetViewBounds );
1322
1322
offsetDescendantRectToMyCoords (view , offsetViewBounds );
1323
1323
1324
- mLibraryItemContextMenu = new LibraryItemContextMenuWidget ( getContext ());
1325
- mLibraryItemContextMenu . setItem ( item );
1326
- mLibraryItemContextMenu .mWidgetPlacement .parentHandle = getHandle ();
1324
+ SessionStore . get (). getBookmarkStore (). isBookmarked ( item . getUrl ()). thenAcceptAsync (( isBookmarked -> {
1325
+ mLibraryItemContextMenu = new LibraryMenuWidget ( getContext (), item , mWidgetManager . canOpenNewWindow (), isBookmarked );
1326
+ mLibraryItemContextMenu .getPlacement () .parentHandle = getHandle ();
1327
1327
1328
- PointF position ;
1329
- if (isLastVisibleItem ) {
1330
- mLibraryItemContextMenu .mWidgetPlacement .anchorY = 0.0f ;
1331
- position = new PointF (
1332
- (offsetViewBounds .left + view .getWidth ()) * ratio ,
1333
- -(offsetViewBounds .top ) * ratio );
1328
+ PointF position ;
1329
+ if (isLastVisibleItem ) {
1330
+ mLibraryItemContextMenu .mWidgetPlacement .anchorY = 0.0f ;
1331
+ position = new PointF (
1332
+ (offsetViewBounds .left + view .getWidth ()) * ratio ,
1333
+ -(offsetViewBounds .top ) * ratio );
1334
1334
1335
- } else {
1336
- mLibraryItemContextMenu .mWidgetPlacement .anchorY = 1.0f ;
1337
- position = new PointF (
1338
- (offsetViewBounds .left + view .getWidth ()) * ratio ,
1339
- -(offsetViewBounds .top + view .getHeight ()) * ratio );
1340
- }
1341
-
1342
- mLibraryItemContextMenu .setPosition (position );
1343
- mLibraryItemContextMenu .setHistoryContextMenuItemCallback ((new LibraryItemContextMenuClickCallback () {
1344
- @ Override
1345
- public void onOpenInNewWindowClick (LibraryItemContextMenu .LibraryContextMenuItem item ) {
1346
- mWidgetManager .openNewWindow (item .getUrl ());
1347
- hideContextMenus ();
1335
+ } else {
1336
+ mLibraryItemContextMenu .mWidgetPlacement .anchorY = 1.0f ;
1337
+ position = new PointF (
1338
+ (offsetViewBounds .left + view .getWidth ()) * ratio ,
1339
+ -(offsetViewBounds .top + view .getHeight ()) * ratio );
1348
1340
}
1341
+ mLibraryItemContextMenu .mWidgetPlacement .translationX = position .x - (mLibraryItemContextMenu .getWidth ()/mLibraryItemContextMenu .mWidgetPlacement .density );
1342
+ mLibraryItemContextMenu .mWidgetPlacement .translationY = position .y + getResources ().getDimension (R .dimen .library_menu_top_margin )/mLibraryItemContextMenu .mWidgetPlacement .density ;
1343
+
1344
+ mLibraryItemContextMenu .setItemDelegate ((new LibraryItemContextMenuClickCallback () {
1345
+ @ Override
1346
+ public void onOpenInNewWindowClick (LibraryMenuWidget .LibraryContextMenuItem item ) {
1347
+ mWidgetManager .openNewWindow (item .getUrl ());
1348
+ hideContextMenus ();
1349
+ }
1349
1350
1350
- @ Override
1351
- public void onAddToBookmarks ( LibraryItemContextMenu .LibraryContextMenuItem item ) {
1352
- SessionStore . get (). getBookmarkStore (). addBookmark ( item .getUrl (), item . getTitle ());
1353
- hideContextMenus ();
1354
- }
1351
+ @ Override
1352
+ public void onOpenInNewTabClick ( LibraryMenuWidget .LibraryContextMenuItem item ) {
1353
+ mWidgetManager . openNewTabForeground ( item .getUrl ());
1354
+ hideContextMenus ();
1355
+ }
1355
1356
1356
- @ Override
1357
- public void onRemoveFromBookmarks (LibraryItemContextMenu .LibraryContextMenuItem item ) {
1358
- SessionStore .get ().getBookmarkStore ().deleteBookmarkByURL (item .getUrl ());
1359
- hideContextMenus ();
1360
- }
1361
- }));
1362
- mLibraryItemContextMenu .show (REQUEST_FOCUS );
1357
+ @ Override
1358
+ public void onAddToBookmarks (LibraryMenuWidget .LibraryContextMenuItem item ) {
1359
+ SessionStore .get ().getBookmarkStore ().addBookmark (item .getUrl (), item .getTitle ());
1360
+ hideContextMenus ();
1361
+ }
1362
+
1363
+ @ Override
1364
+ public void onRemoveFromBookmarks (LibraryMenuWidget .LibraryContextMenuItem item ) {
1365
+ SessionStore .get ().getBookmarkStore ().deleteBookmarkByURL (item .getUrl ());
1366
+ hideContextMenus ();
1367
+ }
1368
+ }));
1369
+ mLibraryItemContextMenu .show (REQUEST_FOCUS );
1370
+
1371
+ }), new UIThreadExecutor ()).exceptionally (throwable -> {
1372
+ Log .d (LOGTAG , "Couldn't get the bookmarked status of the history item" );
1373
+ return null ;
1374
+ });
1363
1375
}
1364
1376
1365
1377
private BookmarksCallback mBookmarksListener = new BookmarksCallback () {
1366
1378
@ Override
1367
1379
public void onShowContextMenu (@ NonNull View view , @ NotNull Bookmark item , boolean isLastVisibleItem ) {
1368
1380
showLibraryItemContextMenu (
1369
1381
view ,
1370
- new LibraryItemContextMenu .LibraryContextMenuItem (
1382
+ new LibraryMenuWidget .LibraryContextMenuItem (
1371
1383
item .getUrl (),
1372
1384
item .getTitle (),
1373
- LibraryItemContextMenu .LibraryItemType .BOOKMARKS ),
1385
+ LibraryMenuWidget .LibraryItemType .BOOKMARKS ),
1374
1386
isLastVisibleItem );
1375
1387
}
1376
1388
@@ -1391,10 +1403,10 @@ public void onClearHistory(@NonNull View view) {
1391
1403
public void onShowContextMenu (@ NonNull View view , @ NonNull VisitInfo item , boolean isLastVisibleItem ) {
1392
1404
showLibraryItemContextMenu (
1393
1405
view ,
1394
- new LibraryItemContextMenu .LibraryContextMenuItem (
1406
+ new LibraryMenuWidget .LibraryContextMenuItem (
1395
1407
item .getUrl (),
1396
1408
item .getTitle (),
1397
- LibraryItemContextMenu .LibraryItemType .HISTORY ),
1409
+ LibraryMenuWidget .LibraryItemType .HISTORY ),
1398
1410
isLastVisibleItem );
1399
1411
}
1400
1412
0 commit comments