Search in sources :

Example 1 with UserHeaderItem

use of com.nextcloud.talk.adapters.items.UserHeaderItem 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 UserHeaderItem

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

the class ContactsController method prepareViews.

private void prepareViews() {
    layoutManager = new SmoothScrollLinearLayoutManager(getActivity());
    recyclerView.setLayoutManager(layoutManager);
    recyclerView.setHasFixedSize(true);
    recyclerView.setAdapter(adapter);
    recyclerView.addItemDecoration(new DividerItemDecoration(recyclerView.getContext(), layoutManager.getOrientation()));
    swipeRefreshLayout.setOnRefreshListener(this::fetchData);
    swipeRefreshLayout.setColorSchemeResources(R.color.colorPrimary);
    fastScroller.addOnScrollStateChangeListener(this);
    adapter.setFastScroller(fastScroller);
    fastScroller.setBubbleTextCreator(position -> {
        IFlexible abstractFlexibleItem = adapter.getItem(position);
        if (abstractFlexibleItem instanceof UserItem) {
            return ((UserItem) adapter.getItem(position)).getHeader().getModel();
        } else {
            return ((UserHeaderItem) adapter.getItem(position)).getModel();
        }
    });
    CoordinatorLayout.LayoutParams layoutParams = (CoordinatorLayout.LayoutParams) bottomButtonsLinearLayout.getLayoutParams();
    layoutParams.setBehavior(new ViewHidingBehaviourAnimation());
}
Also used : CoordinatorLayout(android.support.design.widget.CoordinatorLayout) UserHeaderItem(com.nextcloud.talk.adapters.items.UserHeaderItem) ViewHidingBehaviourAnimation(com.nextcloud.talk.utils.animations.ViewHidingBehaviourAnimation) IFlexible(eu.davidea.flexibleadapter.items.IFlexible) SmoothScrollLinearLayoutManager(eu.davidea.flexibleadapter.common.SmoothScrollLinearLayoutManager) DividerItemDecoration(android.support.v7.widget.DividerItemDecoration) UserItem(com.nextcloud.talk.adapters.items.UserItem)

Aggregations

CoordinatorLayout (android.support.design.widget.CoordinatorLayout)2 DividerItemDecoration (android.support.v7.widget.DividerItemDecoration)2 UserHeaderItem (com.nextcloud.talk.adapters.items.UserHeaderItem)2 UserItem (com.nextcloud.talk.adapters.items.UserItem)2 SearchManager (android.app.SearchManager)1 Context (android.content.Context)1 Intent (android.content.Intent)1 Bundle (android.os.Bundle)1 Handler (android.os.Handler)1 NonNull (android.support.annotation.NonNull)1 Nullable (android.support.annotation.Nullable)1 BottomNavigationView (android.support.design.widget.BottomNavigationView)1 MenuItemCompat (android.support.v4.view.MenuItemCompat)1 SwipeRefreshLayout (android.support.v4.widget.SwipeRefreshLayout)1 RecyclerView (android.support.v7.widget.RecyclerView)1 SearchView (android.support.v7.widget.SearchView)1 InputType (android.text.InputType)1 TextUtils (android.text.TextUtils)1 LayoutInflater (android.view.LayoutInflater)1 Menu (android.view.Menu)1