use of com.nextcloud.talk.adapters.items.UserItem 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);
});
}
use of com.nextcloud.talk.adapters.items.UserItem 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);
}
}
use of com.nextcloud.talk.adapters.items.UserItem 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());
}
use of com.nextcloud.talk.adapters.items.UserItem in project talk-android by nextcloud.
the class ContactsController method onClearButtonClick.
@Optional
@OnClick(R.id.clear_button)
public void onClearButtonClick() {
if (adapter != null) {
List<Integer> selectedPositions = adapter.getSelectedPositions();
for (Integer position : selectedPositions) {
if (adapter.getItem(position) instanceof UserItem) {
UserItem userItem = (UserItem) adapter.getItem(position);
adapter.toggleSelection(position);
if (userItem != null) {
userItem.flipItemSelection();
}
}
}
}
checkAndHandleBottomButtons();
}
use of com.nextcloud.talk.adapters.items.UserItem 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;
}
Aggregations