Search in sources :

Example 1 with MenuItem

use of com.nextcloud.talk.adapters.items.MenuItem in project talk-android by nextcloud.

the class CallMenuController method prepareMenu.

private void prepareMenu() {
    menuItems = new ArrayList<>();
    if (menuType.equals(MenuType.REGULAR)) {
        menuItems.add(new MenuItem(getResources().getString(R.string.nc_what), 0));
        menuItems.add(new MenuItem(getResources().getString(R.string.nc_leave), 1));
        if (room.isNameEditable()) {
            menuItems.add(new MenuItem(getResources().getString(R.string.nc_rename), 2));
        }
        if (room.canModerate()) {
            if (!room.isPublic()) {
                menuItems.add(new MenuItem(getResources().getString(R.string.nc_make_call_public), 3));
            } else {
                if (room.isHasPassword()) {
                    menuItems.add(new MenuItem(getResources().getString(R.string.nc_change_password), 4));
                    menuItems.add(new MenuItem(getResources().getString(R.string.nc_clear_password), 5));
                } else {
                    menuItems.add(new MenuItem(getResources().getString(R.string.nc_set_password), 6));
                }
            }
        }
        if (room.isPublic()) {
            menuItems.add(new MenuItem(getResources().getString(R.string.nc_share_link), 7));
            if (room.canModerate()) {
                menuItems.add(new MenuItem(getResources().getString(R.string.nc_make_call_private), 8));
            }
        }
        if (room.isDeletable()) {
            menuItems.add(new MenuItem(getResources().getString(R.string.nc_delete_call), 9));
        }
    } else if (menuType.equals(MenuType.SHARE)) {
        prepareIntent();
        List<AppAdapter.AppInfo> appInfoList = ShareUtils.getShareApps(getActivity(), shareIntent, null, null);
        menuItems.add(new AppItem(getResources().getString(R.string.nc_share_link_via), "", "", null));
        if (appInfoList != null) {
            for (AppAdapter.AppInfo appInfo : appInfoList) {
                menuItems.add(new AppItem(appInfo.title, appInfo.packageName, appInfo.name, appInfo.drawable));
            }
        }
    } else {
        menuItems.add(new MenuItem(getResources().getString(R.string.nc_what), 0));
        menuItems.add(new MenuItem(getResources().getString(R.string.nc_new_conversation), 1));
        menuItems.add(new MenuItem(getResources().getString(R.string.nc_join_via_link), 2));
    }
}
Also used : AppAdapter(com.kennyc.bottomsheet.adapters.AppAdapter) AppItem(com.nextcloud.talk.adapters.items.AppItem) MenuItem(com.nextcloud.talk.adapters.items.MenuItem) ArrayList(java.util.ArrayList) List(java.util.List)

Example 2 with MenuItem

use of com.nextcloud.talk.adapters.items.MenuItem in project talk-android by nextcloud.

the class CallMenuController method onItemClick.

@Override
public boolean onItemClick(View view, int position) {
    Bundle bundle = new Bundle();
    bundle.putParcelable(BundleKeys.KEY_ROOM, Parcels.wrap(room));
    if (menuType.equals(MenuType.REGULAR)) {
        MenuItem menuItem = (MenuItem) adapter.getItem(position);
        if (menuItem != null) {
            int tag = menuItem.getTag();
            if (tag == 5) {
                room.setPassword("");
            }
            if (tag > 0 && tag < 10) {
                bundle.putInt(BundleKeys.KEY_OPERATION_CODE, tag);
                if (tag != 2 && tag != 4 && tag != 6 && tag != 7) {
                    eventBus.post(new BottomSheetLockEvent(false, 0, false, false));
                    getRouter().pushController(RouterTransaction.with(new OperationsMenuController(bundle)).pushChangeHandler(new HorizontalChangeHandler()).popChangeHandler(new HorizontalChangeHandler()));
                } else if (tag != 7) {
                    getRouter().pushController(RouterTransaction.with(new EntryMenuController(bundle)).pushChangeHandler(new HorizontalChangeHandler()).popChangeHandler(new HorizontalChangeHandler()));
                } else {
                    bundle.putParcelable(BundleKeys.KEY_MENU_TYPE, Parcels.wrap(MenuType.SHARE));
                    getRouter().pushController(RouterTransaction.with(new CallMenuController(bundle)).pushChangeHandler(new HorizontalChangeHandler()).popChangeHandler(new HorizontalChangeHandler()));
                }
            }
        }
    } else if (menuType.equals(MenuType.SHARE) && position != 0) {
        AppItem appItem = (AppItem) adapter.getItem(position);
        if (appItem != null && getActivity() != null) {
            if (!room.hasPassword) {
                shareIntent.putExtra(Intent.EXTRA_TEXT, ShareUtils.getStringForIntent(getActivity(), null, userUtils, room));
                Intent intent = new Intent(shareIntent);
                intent.setComponent(new ComponentName(appItem.getPackageName(), appItem.getName()));
                intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
                eventBus.post(new BottomSheetLockEvent(true, 0, false, true));
                getActivity().startActivity(intent);
            } else {
                bundle.putInt(BundleKeys.KEY_OPERATION_CODE, 7);
                bundle.putParcelable(BundleKeys.KEY_SHARE_INTENT, Parcels.wrap(shareIntent));
                bundle.putString(BundleKeys.KEY_APP_ITEM_PACKAGE_NAME, appItem.getPackageName());
                bundle.putString(BundleKeys.KEY_APP_ITEM_NAME, appItem.getName());
                getRouter().pushController(RouterTransaction.with(new EntryMenuController(bundle)).pushChangeHandler(new HorizontalChangeHandler()).popChangeHandler(new HorizontalChangeHandler()));
            }
        }
    } else if (menuType.equals(MenuType.NEW_CONVERSATION) && position != 0) {
        MenuItem menuItem = (MenuItem) adapter.getItem(position);
        if (menuItem != null) {
            if (menuItem.getTag() == 1) {
                eventBus.post(new BottomSheetLockEvent(true, 0, false, true));
                bundle = new Bundle();
                bundle.putBoolean(BundleKeys.KEY_NEW_CONVERSATION, true);
                getParentController().getParentController().getRouter().pushController((RouterTransaction.with(new ContactsController(bundle)).pushChangeHandler(new VerticalChangeHandler()).popChangeHandler(new VerticalChangeHandler())));
            } else {
                bundle = new Bundle();
                bundle.putInt(BundleKeys.KEY_OPERATION_CODE, 10);
                getRouter().pushController(RouterTransaction.with(new EntryMenuController(bundle)).pushChangeHandler(new HorizontalChangeHandler()).popChangeHandler(new HorizontalChangeHandler()));
            }
        }
    }
    return true;
}
Also used : ContactsController(com.nextcloud.talk.controllers.ContactsController) Bundle(android.os.Bundle) MenuItem(com.nextcloud.talk.adapters.items.MenuItem) Intent(android.content.Intent) VerticalChangeHandler(com.bluelinelabs.conductor.changehandler.VerticalChangeHandler) HorizontalChangeHandler(com.bluelinelabs.conductor.changehandler.HorizontalChangeHandler) BottomSheetLockEvent(com.nextcloud.talk.events.BottomSheetLockEvent) AppItem(com.nextcloud.talk.adapters.items.AppItem) ComponentName(android.content.ComponentName)

Aggregations

AppItem (com.nextcloud.talk.adapters.items.AppItem)2 MenuItem (com.nextcloud.talk.adapters.items.MenuItem)2 ComponentName (android.content.ComponentName)1 Intent (android.content.Intent)1 Bundle (android.os.Bundle)1 HorizontalChangeHandler (com.bluelinelabs.conductor.changehandler.HorizontalChangeHandler)1 VerticalChangeHandler (com.bluelinelabs.conductor.changehandler.VerticalChangeHandler)1 AppAdapter (com.kennyc.bottomsheet.adapters.AppAdapter)1 ContactsController (com.nextcloud.talk.controllers.ContactsController)1 BottomSheetLockEvent (com.nextcloud.talk.events.BottomSheetLockEvent)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1