Search in sources :

Example 1 with RetrofitBucket

use of com.nextcloud.talk.models.RetrofitBucket in project talk-android by nextcloud.

the class ContactsController method fetchData.

private void fetchData() {
    dispose(null);
    Set<Sharee> shareeHashSet = new HashSet<>();
    contactItems = new ArrayList<>();
    userHeaderItems = new HashMap<>();
    RetrofitBucket retrofitBucket = ApiUtils.getRetrofitBucketForContactsSearch(userEntity.getBaseUrl(), "");
    contactsQueryDisposable = ncApi.getContactsWithSearchParam(ApiUtils.getCredentials(userEntity.getUsername(), userEntity.getToken()), retrofitBucket.getUrl(), retrofitBucket.getQueryMap()).subscribeOn(Schedulers.newThread()).observeOn(AndroidSchedulers.mainThread()).subscribe((ShareesOverall shareesOverall) -> {
        if (shareesOverall != null) {
            if (shareesOverall.getOcs().getData().getUsers() != null) {
                shareeHashSet.addAll(shareesOverall.getOcs().getData().getUsers());
            }
            if (shareesOverall.getOcs().getData().getExactUsers() != null && shareesOverall.getOcs().getData().getExactUsers().getExactSharees() != null) {
                shareeHashSet.addAll(shareesOverall.getOcs().getData().getExactUsers().getExactSharees());
            }
            Participant participant;
            for (Sharee sharee : shareeHashSet) {
                if (!sharee.getValue().getShareWith().equals(userEntity.getUsername())) {
                    participant = new Participant();
                    participant.setName(sharee.getLabel());
                    String headerTitle;
                    headerTitle = sharee.getLabel().substring(0, 1).toUpperCase();
                    UserHeaderItem userHeaderItem;
                    if (!userHeaderItems.containsKey(headerTitle)) {
                        userHeaderItem = new UserHeaderItem(headerTitle);
                        userHeaderItems.put(headerTitle, userHeaderItem);
                    }
                    participant.setUserId(sharee.getValue().getShareWith());
                    contactItems.add(new UserItem(participant, userEntity, userHeaderItems.get(headerTitle)));
                }
            }
            userHeaderItems = new HashMap<>();
            Collections.sort(contactItems, (o1, o2) -> {
                String firstName;
                String secondName;
                if (o1 instanceof UserItem) {
                    firstName = ((UserItem) o1).getModel().getName();
                } else {
                    firstName = ((UserHeaderItem) o1).getModel();
                }
                if (o2 instanceof UserItem) {
                    secondName = ((UserItem) o2).getModel().getName();
                } else {
                    secondName = ((UserHeaderItem) o2).getModel();
                }
                return firstName.compareToIgnoreCase(secondName);
            });
            if (isNewConversationView) {
                contactItems.add(0, new NewCallHeaderItem());
            }
            adapter.updateDataSet(contactItems, true);
            searchItem.setVisible(contactItems.size() > 0);
            swipeRefreshLayout.setRefreshing(false);
            if (isNewConversationView) {
                checkAndHandleBottomButtons();
            }
        }
    }, throwable -> {
        if (searchItem != null) {
            searchItem.setVisible(false);
        }
        if (throwable instanceof HttpException) {
            HttpException exception = (HttpException) throwable;
            switch(exception.code()) {
                case 401:
                    if (getParentController() != null && getParentController().getRouter() != null) {
                        getParentController().getRouter().pushController((RouterTransaction.with(new WebViewLoginController(userEntity.getBaseUrl(), true)).pushChangeHandler(new VerticalChangeHandler()).popChangeHandler(new VerticalChangeHandler())));
                    }
                    break;
                default:
                    break;
            }
        }
        swipeRefreshLayout.setRefreshing(false);
        dispose(contactsQueryDisposable);
    }, () -> {
        swipeRefreshLayout.setRefreshing(false);
        dispose(contactsQueryDisposable);
    });
}
Also used : AutoInjector(autodagger.AutoInjector) Bundle(android.os.Bundle) UserUtils(com.nextcloud.talk.utils.database.user.UserUtils) EntryMenuController(com.nextcloud.talk.controllers.bottomsheet.EntryMenuController) IFlexible(eu.davidea.flexibleadapter.items.IFlexible) SearchView(android.support.v7.widget.SearchView) RetrofitBucket(com.nextcloud.talk.models.RetrofitBucket) UserItem(com.nextcloud.talk.adapters.items.UserItem) AndroidSchedulers(io.reactivex.android.schedulers.AndroidSchedulers) OnClick(butterknife.OnClick) DividerItemDecoration(android.support.v7.widget.DividerItemDecoration) BindView(butterknife.BindView) ApiUtils(com.nextcloud.talk.utils.ApiUtils) ViewHidingBehaviourAnimation(com.nextcloud.talk.utils.animations.ViewHidingBehaviourAnimation) BottomSheet(com.kennyc.bottomsheet.BottomSheet) Handler(android.os.Handler) View(android.view.View) Button(android.widget.Button) UserHeaderItem(com.nextcloud.talk.adapters.items.UserHeaderItem) Schedulers(io.reactivex.schedulers.Schedulers) Sharee(com.nextcloud.talk.models.json.sharees.Sharee) SelectableAdapter(eu.davidea.flexibleadapter.SelectableAdapter) VerticalChangeHandler(com.bluelinelabs.conductor.changehandler.VerticalChangeHandler) Participant(com.nextcloud.talk.models.json.participants.Participant) MenuItemCompat(android.support.v4.view.MenuItemCompat) Optional(butterknife.Optional) HttpException(retrofit2.HttpException) InputType(android.text.InputType) Set(java.util.Set) FlexibleAdapter(eu.davidea.flexibleadapter.FlexibleAdapter) ThreadMode(org.greenrobot.eventbus.ThreadMode) ViewGroup(android.view.ViewGroup) BundleKeys(com.nextcloud.talk.utils.bundle.BundleKeys) List(java.util.List) Disposable(io.reactivex.disposables.Disposable) Parcels(org.parceler.Parcels) FastScroller(eu.davidea.fastscroller.FastScroller) AbstractFlexibleItem(eu.davidea.flexibleadapter.items.AbstractFlexibleItem) Nullable(android.support.annotation.Nullable) SearchManager(android.app.SearchManager) EditorInfo(android.view.inputmethod.EditorInfo) Context(android.content.Context) CoordinatorLayout(android.support.design.widget.CoordinatorLayout) UserEntity(com.nextcloud.talk.models.database.UserEntity) SmoothScrollLinearLayoutManager(eu.davidea.flexibleadapter.common.SmoothScrollLinearLayoutManager) Intent(android.content.Intent) HashMap(java.util.HashMap) NonNull(android.support.annotation.NonNull) MenuItem(android.view.MenuItem) ArrayList(java.util.ArrayList) BottomSheetLockEvent(com.nextcloud.talk.events.BottomSheetLockEvent) HashSet(java.util.HashSet) Inject(javax.inject.Inject) BaseController(com.nextcloud.talk.controllers.base.BaseController) MenuInflater(android.view.MenuInflater) EventBus(org.greenrobot.eventbus.EventBus) Menu(android.view.Menu) SwipeRefreshLayout(android.support.v4.widget.SwipeRefreshLayout) NcApi(com.nextcloud.talk.api.NcApi) BottomNavigationView(android.support.design.widget.BottomNavigationView) R(com.nextcloud.talk.R) Room(com.nextcloud.talk.models.json.rooms.Room) LayoutInflater(android.view.LayoutInflater) NewCallHeaderItem(com.nextcloud.talk.adapters.items.NewCallHeaderItem) TextUtils(android.text.TextUtils) FlipView(eu.davidea.flipview.FlipView) ShareesOverall(com.nextcloud.talk.models.json.sharees.ShareesOverall) HorizontalChangeHandler(com.bluelinelabs.conductor.changehandler.HorizontalChangeHandler) RecyclerView(android.support.v7.widget.RecyclerView) Subscribe(org.greenrobot.eventbus.Subscribe) KeyboardUtils(com.nextcloud.talk.utils.KeyboardUtils) CallActivity(com.nextcloud.talk.activities.CallActivity) Observer(io.reactivex.Observer) ViewTreeObserver(android.view.ViewTreeObserver) RoomOverall(com.nextcloud.talk.models.json.rooms.RoomOverall) Collections(java.util.Collections) NextcloudTalkApplication(com.nextcloud.talk.application.NextcloudTalkApplication) RouterTransaction(com.bluelinelabs.conductor.RouterTransaction) RetrofitBucket(com.nextcloud.talk.models.RetrofitBucket) HashMap(java.util.HashMap) NewCallHeaderItem(com.nextcloud.talk.adapters.items.NewCallHeaderItem) VerticalChangeHandler(com.bluelinelabs.conductor.changehandler.VerticalChangeHandler) UserItem(com.nextcloud.talk.adapters.items.UserItem) Sharee(com.nextcloud.talk.models.json.sharees.Sharee) UserHeaderItem(com.nextcloud.talk.adapters.items.UserHeaderItem) Participant(com.nextcloud.talk.models.json.participants.Participant) ShareesOverall(com.nextcloud.talk.models.json.sharees.ShareesOverall) HttpException(retrofit2.HttpException) HashSet(java.util.HashSet)

Example 2 with RetrofitBucket

use of com.nextcloud.talk.models.RetrofitBucket 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 3 with RetrofitBucket

use of com.nextcloud.talk.models.RetrofitBucket in project talk-android by nextcloud.

the class OperationsMenuController method inviteUsersToAConversation.

private void inviteUsersToAConversation() {
    RetrofitBucket retrofitBucket;
    final ArrayList<String> localInvitedUsers = invitedUsers;
    if (localInvitedUsers.size() > 0) {
        for (int i = 0; i < invitedUsers.size(); i++) {
            final String userId = invitedUsers.get(i);
            retrofitBucket = ApiUtils.getRetrofitBucketForAddParticipant(userEntity.getBaseUrl(), room.getToken(), userId);
            ncApi.addParticipant(credentials, retrofitBucket.getUrl(), retrofitBucket.getQueryMap()).subscribeOn(Schedulers.newThread()).observeOn(AndroidSchedulers.mainThread()).retry(1).subscribe(new Observer<AddParticipantOverall>() {

                @Override
                public void onSubscribe(Disposable d) {
                }

                @Override
                public void onNext(AddParticipantOverall addParticipantOverall) {
                }

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

                @Override
                public void onComplete() {
                    synchronized (localInvitedUsers) {
                        localInvitedUsers.remove(userId);
                    }
                    if (localInvitedUsers.size() == 0) {
                        initiateCall();
                    }
                    dispose();
                }
            });
        }
    } else {
        showResultImage(true, false);
    }
}
Also used : Disposable(io.reactivex.disposables.Disposable) RetrofitBucket(com.nextcloud.talk.models.RetrofitBucket) AddParticipantOverall(com.nextcloud.talk.models.json.participants.AddParticipantOverall)

Example 4 with RetrofitBucket

use of com.nextcloud.talk.models.RetrofitBucket 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 5 with RetrofitBucket

use of com.nextcloud.talk.models.RetrofitBucket in project talk-android by nextcloud.

the class ApiUtils method getRetrofitBucketForAddParticipant.

public static RetrofitBucket getRetrofitBucketForAddParticipant(String baseUrl, String token, String user) {
    RetrofitBucket retrofitBucket = new RetrofitBucket();
    retrofitBucket.setUrl(baseUrl + ocsApiVersion + spreedApiVersion + "/room/" + token + "/participants");
    Map<String, String> queryMap = new HashMap<>();
    queryMap.put("newParticipant", user);
    retrofitBucket.setQueryMap(queryMap);
    return retrofitBucket;
}
Also used : RetrofitBucket(com.nextcloud.talk.models.RetrofitBucket) HashMap(java.util.HashMap)

Aggregations

RetrofitBucket (com.nextcloud.talk.models.RetrofitBucket)8 Disposable (io.reactivex.disposables.Disposable)5 RoomOverall (com.nextcloud.talk.models.json.rooms.RoomOverall)4 HashMap (java.util.HashMap)4 Intent (android.content.Intent)3 Bundle (android.os.Bundle)3 CallActivity (com.nextcloud.talk.activities.CallActivity)3 UserItem (com.nextcloud.talk.adapters.items.UserItem)3 Handler (android.os.Handler)2 OnClick (butterknife.OnClick)2 Optional (butterknife.Optional)2 HorizontalChangeHandler (com.bluelinelabs.conductor.changehandler.HorizontalChangeHandler)2 VerticalChangeHandler (com.bluelinelabs.conductor.changehandler.VerticalChangeHandler)2 Room (com.nextcloud.talk.models.json.rooms.Room)2 ArrayList (java.util.ArrayList)2 SearchManager (android.app.SearchManager)1 Context (android.content.Context)1 NonNull (android.support.annotation.NonNull)1 Nullable (android.support.annotation.Nullable)1 BottomNavigationView (android.support.design.widget.BottomNavigationView)1