Search in sources :

Example 1 with RoomOverall

use of com.nextcloud.talk.models.json.rooms.RoomOverall in project talk-android by nextcloud.

the class ContactsController method onDoneButtonClick.

@Optional
@OnClick(R.id.done_button)
public void onDoneButtonClick() {
    if (!isPublicCall && adapter.getSelectedPositions().size() == 1) {
        RetrofitBucket retrofitBucket = ApiUtils.getRetrofitBucketForCreateRoom(userEntity.getBaseUrl(), "1", ((UserItem) adapter.getItem(adapter.getSelectedPositions().get(0))).getModel().getUserId(), null);
        ncApi.createRoom(ApiUtils.getCredentials(userEntity.getUsername(), userEntity.getToken()), retrofitBucket.getUrl(), retrofitBucket.getQueryMap()).subscribeOn(Schedulers.newThread()).observeOn(AndroidSchedulers.mainThread()).subscribe(new Observer<RoomOverall>() {

            @Override
            public void onSubscribe(Disposable d) {
            }

            @Override
            public void onNext(RoomOverall roomOverall) {
                if (getActivity() != null) {
                    Intent callIntent = new Intent(getActivity(), CallActivity.class);
                    Bundle bundle = new Bundle();
                    bundle.putString(BundleKeys.KEY_ROOM_TOKEN, roomOverall.getOcs().getData().getToken());
                    bundle.putParcelable(BundleKeys.KEY_USER_ENTITY, Parcels.wrap(userEntity));
                    callIntent.putExtras(bundle);
                    startActivity(callIntent);
                    new Handler().postDelayed(() -> getRouter().popCurrentController(), 100);
                }
            }

            @Override
            public void onError(Throwable e) {
            }

            @Override
            public void onComplete() {
            }
        });
    } else {
        Bundle bundle = new Bundle();
        Room.RoomType roomType;
        if (isPublicCall) {
            roomType = Room.RoomType.ROOM_PUBLIC_CALL;
        } else {
            roomType = Room.RoomType.ROOM_GROUP_CALL;
        }
        bundle.putParcelable(BundleKeys.KEY_CONVERSATION_TYPE, Parcels.wrap(roomType));
        ArrayList<String> userIds = new ArrayList<>();
        Set<Integer> selectedPositions = adapter.getSelectedPositionsAsSet();
        for (int selectedPosition : selectedPositions) {
            if (adapter.getItem(selectedPosition) instanceof UserItem) {
                UserItem userItem = (UserItem) adapter.getItem(selectedPosition);
                userIds.add(userItem.getModel().getUserId());
            }
        }
        bundle.putStringArrayList(BundleKeys.KEY_INVITED_PARTICIPANTS, userIds);
        bundle.putInt(BundleKeys.KEY_OPERATION_CODE, 11);
        prepareAndShowBottomSheetWithBundle(bundle);
    }
}
Also used : RoomOverall(com.nextcloud.talk.models.json.rooms.RoomOverall) Disposable(io.reactivex.disposables.Disposable) RetrofitBucket(com.nextcloud.talk.models.RetrofitBucket) Bundle(android.os.Bundle) ArrayList(java.util.ArrayList) Handler(android.os.Handler) VerticalChangeHandler(com.bluelinelabs.conductor.changehandler.VerticalChangeHandler) HorizontalChangeHandler(com.bluelinelabs.conductor.changehandler.HorizontalChangeHandler) Intent(android.content.Intent) CallActivity(com.nextcloud.talk.activities.CallActivity) UserItem(com.nextcloud.talk.adapters.items.UserItem) Room(com.nextcloud.talk.models.json.rooms.Room) Optional(butterknife.Optional) OnClick(butterknife.OnClick)

Example 2 with RoomOverall

use of com.nextcloud.talk.models.json.rooms.RoomOverall in project talk-android by nextcloud.

the class OperationsMenuController method processOperation.

private void processOperation() {
    userEntity = userUtils.getCurrentUser();
    OperationsObserver operationsObserver = new OperationsObserver();
    if (!TextUtils.isEmpty(callUrl)) {
        conversationToken = callUrl.substring(callUrl.lastIndexOf("/") + 1, callUrl.length());
        if (callUrl.contains("/index.php")) {
            baseUrl = callUrl.substring(0, callUrl.indexOf("/index.php"));
        } else {
            baseUrl = callUrl.substring(0, callUrl.indexOf("/call"));
        }
    }
    if (userEntity != null) {
        credentials = ApiUtils.getCredentials(userEntity.getUsername(), userEntity.getToken());
        if (!TextUtils.isEmpty(baseUrl) && !baseUrl.equals(userEntity.getBaseUrl())) {
            credentials = null;
        }
        switch(operationCode) {
            case 1:
                ncApi.removeSelfFromRoom(credentials, ApiUtils.getUrlForRemoveSelfFromRoom(userEntity.getBaseUrl(), room.getToken())).subscribeOn(Schedulers.newThread()).observeOn(AndroidSchedulers.mainThread()).retry(1).subscribe(operationsObserver);
                break;
            case 2:
                ncApi.renameRoom(credentials, ApiUtils.getRoom(userEntity.getBaseUrl(), room.getToken()), room.getName()).subscribeOn(Schedulers.newThread()).observeOn(AndroidSchedulers.mainThread()).retry(1).subscribe(operationsObserver);
                break;
            case 3:
                ncApi.makeRoomPublic(credentials, ApiUtils.getUrlForRoomVisibility(userEntity.getBaseUrl(), room.getToken())).subscribeOn(Schedulers.newThread()).observeOn(AndroidSchedulers.mainThread()).retry(1).subscribe(operationsObserver);
                break;
            case 4:
            case 5:
            case 6:
                String pass = "";
                if (room.getPassword() != null) {
                    pass = room.getPassword();
                }
                ncApi.setPassword(credentials, ApiUtils.getUrlForPassword(userEntity.getBaseUrl(), room.getToken()), pass).subscribeOn(Schedulers.newThread()).observeOn(AndroidSchedulers.mainThread()).retry(1).subscribe(operationsObserver);
                break;
            case 7:
                // Operation 7 is sharing, so we handle this differently
                break;
            case 8:
                ncApi.makeRoomPrivate(credentials, ApiUtils.getUrlForRoomVisibility(userEntity.getBaseUrl(), room.getToken())).subscribeOn(Schedulers.newThread()).observeOn(AndroidSchedulers.mainThread()).retry(1).subscribe(operationsObserver);
                break;
            case 9:
                ncApi.deleteRoom(credentials, ApiUtils.getUrlForRoomParticipants(userEntity.getBaseUrl(), room.getToken())).subscribeOn(Schedulers.newThread()).observeOn(AndroidSchedulers.mainThread()).retry(1).subscribe(operationsObserver);
                break;
            case 10:
                ncApi.getRoom(credentials, ApiUtils.getRoom(baseUrl, conversationToken)).subscribeOn(Schedulers.newThread()).observeOn(AndroidSchedulers.mainThread()).retry(1).subscribe(new Observer<RoomOverall>() {

                    @Override
                    public void onSubscribe(Disposable d) {
                        disposable = d;
                    }

                    @Override
                    public void onNext(RoomOverall roomOverall) {
                        room = roomOverall.getOcs().getData();
                        fetchCapabilities(credentials);
                    }

                    @Override
                    public void onError(Throwable e) {
                        showResultImage(false, false);
                        dispose();
                    }

                    @Override
                    public void onComplete() {
                        dispose();
                    }
                });
                break;
            case 11:
                RetrofitBucket retrofitBucket;
                boolean isGroupCallWorkaround = false;
                if (conversationType.equals(Room.RoomType.ROOM_PUBLIC_CALL) || !userEntity.hasSpreedCapabilityWithName("empty-group-room")) {
                    retrofitBucket = ApiUtils.getRetrofitBucketForCreateRoom(userEntity.getBaseUrl(), "3", null, conversationName);
                } else {
                    String roomType = "2";
                    if (!userEntity.hasSpreedCapabilityWithName("empty-group-room")) {
                        isGroupCallWorkaround = true;
                        roomType = "3";
                    }
                    retrofitBucket = ApiUtils.getRetrofitBucketForCreateRoom(userEntity.getBaseUrl(), roomType, null, conversationName);
                }
                final boolean isGroupCallWorkaroundFinal = isGroupCallWorkaround;
                ncApi.createRoom(credentials, retrofitBucket.getUrl(), retrofitBucket.getQueryMap()).subscribeOn(Schedulers.newThread()).observeOn(AndroidSchedulers.mainThread()).retry(1).subscribe(new Observer<RoomOverall>() {

                    @Override
                    public void onSubscribe(Disposable d) {
                    }

                    @Override
                    public void onNext(RoomOverall roomOverall) {
                        room = roomOverall.getOcs().getData();
                        if (conversationType.equals(Room.RoomType.ROOM_PUBLIC_CALL) && isGroupCallWorkaroundFinal) {
                            performGroupCallWorkaround(credentials);
                        } else {
                            inviteUsersToAConversation();
                        }
                    }

                    @Override
                    public void onError(Throwable e) {
                        showResultImage(false, false);
                        dispose();
                    }

                    @Override
                    public void onComplete() {
                        dispose();
                    }
                });
                break;
            case 99:
                ncApi.joinRoom(credentials, ApiUtils.getUrlForRoomParticipants(baseUrl, conversationToken), callPassword).subscribeOn(Schedulers.newThread()).observeOn(AndroidSchedulers.mainThread()).retry(1).subscribe(operationsObserver);
                break;
            default:
                break;
        }
    }
}
Also used : RoomOverall(com.nextcloud.talk.models.json.rooms.RoomOverall) Disposable(io.reactivex.disposables.Disposable) RetrofitBucket(com.nextcloud.talk.models.RetrofitBucket)

Example 3 with RoomOverall

use of com.nextcloud.talk.models.json.rooms.RoomOverall in project talk-android by nextcloud.

the class ContactsController method onItemClick.

@Override
public boolean onItemClick(View view, int position) {
    if (adapter.getItem(position) instanceof UserItem) {
        if (!isNewConversationView) {
            UserItem userItem = (UserItem) adapter.getItem(position);
            RetrofitBucket retrofitBucket = ApiUtils.getRetrofitBucketForCreateRoom(userEntity.getBaseUrl(), "1", userItem.getModel().getUserId(), null);
            ncApi.createRoom(ApiUtils.getCredentials(userEntity.getUsername(), userEntity.getToken()), retrofitBucket.getUrl(), retrofitBucket.getQueryMap()).subscribeOn(Schedulers.newThread()).observeOn(AndroidSchedulers.mainThread()).subscribe(new Observer<RoomOverall>() {

                @Override
                public void onSubscribe(Disposable d) {
                }

                @Override
                public void onNext(RoomOverall roomOverall) {
                    if (getActivity() != null) {
                        Intent callIntent = new Intent(getActivity(), CallActivity.class);
                        Bundle bundle = new Bundle();
                        bundle.putString(BundleKeys.KEY_ROOM_TOKEN, roomOverall.getOcs().getData().getToken());
                        bundle.putParcelable(BundleKeys.KEY_USER_ENTITY, Parcels.wrap(userEntity));
                        callIntent.putExtras(bundle);
                        startActivity(callIntent);
                    }
                }

                @Override
                public void onError(Throwable e) {
                }

                @Override
                public void onComplete() {
                }
            });
        } else {
            ((UserItem) adapter.getItem(position)).flipItemSelection();
            adapter.toggleSelection(position);
            checkAndHandleBottomButtons();
        }
    } else if (adapter.getItem(position) instanceof NewCallHeaderItem) {
        adapter.toggleSelection(position);
        isPublicCall = adapter.isSelected(position);
        ((NewCallHeaderItem) adapter.getItem(position)).togglePublicCall(isPublicCall);
        checkAndHandleBottomButtons();
    }
    return true;
}
Also used : RoomOverall(com.nextcloud.talk.models.json.rooms.RoomOverall) Disposable(io.reactivex.disposables.Disposable) RetrofitBucket(com.nextcloud.talk.models.RetrofitBucket) Bundle(android.os.Bundle) NewCallHeaderItem(com.nextcloud.talk.adapters.items.NewCallHeaderItem) Intent(android.content.Intent) CallActivity(com.nextcloud.talk.activities.CallActivity) UserItem(com.nextcloud.talk.adapters.items.UserItem)

Aggregations

RetrofitBucket (com.nextcloud.talk.models.RetrofitBucket)3 RoomOverall (com.nextcloud.talk.models.json.rooms.RoomOverall)3 Disposable (io.reactivex.disposables.Disposable)3 Intent (android.content.Intent)2 Bundle (android.os.Bundle)2 CallActivity (com.nextcloud.talk.activities.CallActivity)2 UserItem (com.nextcloud.talk.adapters.items.UserItem)2 Handler (android.os.Handler)1 OnClick (butterknife.OnClick)1 Optional (butterknife.Optional)1 HorizontalChangeHandler (com.bluelinelabs.conductor.changehandler.HorizontalChangeHandler)1 VerticalChangeHandler (com.bluelinelabs.conductor.changehandler.VerticalChangeHandler)1 NewCallHeaderItem (com.nextcloud.talk.adapters.items.NewCallHeaderItem)1 Room (com.nextcloud.talk.models.json.rooms.Room)1 ArrayList (java.util.ArrayList)1