mirror of
https://github.com/nextcloud/talk-android
synced 2025-06-21 12:39:58 +01:00
Improve contacts
Signed-off-by: Mario Danic <mario@lovelyhq.com>
This commit is contained in:
parent
74fb018a8e
commit
4b9f47c6b5
@ -114,7 +114,7 @@ import okhttp3.ResponseBody;
|
|||||||
|
|
||||||
@AutoInjector(NextcloudTalkApplication.class)
|
@AutoInjector(NextcloudTalkApplication.class)
|
||||||
public class ContactsController extends BaseController implements SearchView.OnQueryTextListener,
|
public class ContactsController extends BaseController implements SearchView.OnQueryTextListener,
|
||||||
FlexibleAdapter.OnItemClickListener, FastScroller.OnScrollStateChangeListener, FlexibleAdapter.EndlessScrollListener {
|
FlexibleAdapter.OnItemClickListener, FastScroller.OnScrollStateChangeListener {
|
||||||
|
|
||||||
public static final String TAG = "ContactsController";
|
public static final String TAG = "ContactsController";
|
||||||
|
|
||||||
@ -245,7 +245,7 @@ public class ContactsController extends BaseController implements SearchView.OnQ
|
|||||||
|
|
||||||
if (adapter == null) {
|
if (adapter == null) {
|
||||||
contactItems = new ArrayList<>();
|
contactItems = new ArrayList<>();
|
||||||
adapter = new FlexibleAdapter<>(contactItems, getActivity(), true);
|
adapter = new FlexibleAdapter<>(contactItems, getActivity(), false);
|
||||||
|
|
||||||
if (currentUser != null) {
|
if (currentUser != null) {
|
||||||
fetchData(true);
|
fetchData(true);
|
||||||
@ -260,8 +260,6 @@ public class ContactsController extends BaseController implements SearchView.OnQ
|
|||||||
adapter.setNotifyChangeOfUnfilteredItems(true)
|
adapter.setNotifyChangeOfUnfilteredItems(true)
|
||||||
.setMode(SelectableAdapter.Mode.MULTI);
|
.setMode(SelectableAdapter.Mode.MULTI);
|
||||||
|
|
||||||
adapter.setEndlessScrollListener(this, new ProgressItem());
|
|
||||||
|
|
||||||
adapter.setStickyHeaderElevation(5)
|
adapter.setStickyHeaderElevation(5)
|
||||||
.setUnlinkAllItemsOnRemoveHeaders(true)
|
.setUnlinkAllItemsOnRemoveHeaders(true)
|
||||||
.setDisplayHeadersAtStartUp(true)
|
.setDisplayHeadersAtStartUp(true)
|
||||||
@ -455,52 +453,30 @@ public class ContactsController extends BaseController implements SearchView.OnQ
|
|||||||
dispose(null);
|
dispose(null);
|
||||||
|
|
||||||
alreadyFetching = true;
|
alreadyFetching = true;
|
||||||
Set<Sharee> shareeHashSet = new HashSet<>();
|
|
||||||
Set<AutocompleteUser> autocompleteUsersHashSet = new HashSet<>();
|
Set<AutocompleteUser> autocompleteUsersHashSet = new HashSet<>();
|
||||||
|
|
||||||
userHeaderItems = new HashMap<>();
|
userHeaderItems = new HashMap<>();
|
||||||
|
|
||||||
String query = (String) adapter.getFilter(String.class);
|
String query = (String) adapter.getFilter(String.class);
|
||||||
|
|
||||||
RetrofitBucket retrofitBucket;
|
RetrofitBucket retrofitBucket = ApiUtils.getRetrofitBucketForContactsSearchFor14(currentUser.getBaseUrl(), query);
|
||||||
boolean serverIs14OrUp = false;
|
Map<String, Object> modifiedQueryMap = new HashMap<String, Object>(retrofitBucket.getQueryMap());
|
||||||
if (currentUser.hasSpreedFeatureCapability("last-room-activity")) {
|
modifiedQueryMap.put("limit", 50);
|
||||||
// a hack to see if we're on 14 or not
|
|
||||||
retrofitBucket = ApiUtils.getRetrofitBucketForContactsSearchFor14(currentUser.getBaseUrl(), query);
|
|
||||||
serverIs14OrUp = true;
|
|
||||||
} else {
|
|
||||||
retrofitBucket = ApiUtils.getRetrofitBucketForContactsSearch(currentUser.getBaseUrl(), query);
|
|
||||||
}
|
|
||||||
|
|
||||||
int page = 1;
|
if (isAddingParticipantsView) {
|
||||||
if (!startFromScratch) {
|
modifiedQueryMap.put("itemId", conversationToken);
|
||||||
if (TextUtils.isEmpty(query)) {
|
|
||||||
page = currentPage + 1;
|
|
||||||
} else {
|
|
||||||
page = currentSearchPage + 1;
|
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
Map<String, Object> modifiedQueryMap = new HashMap<>(retrofitBucket.getQueryMap());
|
|
||||||
modifiedQueryMap.put("page", page);
|
|
||||||
modifiedQueryMap.put("perPage", 100);
|
|
||||||
|
|
||||||
List<String> shareTypesList = null;
|
List<String> shareTypesList = null;
|
||||||
|
|
||||||
if (serverIs14OrUp) {
|
|
||||||
shareTypesList = new ArrayList<>();
|
shareTypesList = new ArrayList<>();
|
||||||
// users
|
// users
|
||||||
shareTypesList.add("0");
|
shareTypesList.add("0");
|
||||||
// groups
|
// groups
|
||||||
shareTypesList.add("1");
|
shareTypesList.add("1");
|
||||||
// mails
|
|
||||||
//shareTypesList.add("4");
|
|
||||||
|
|
||||||
|
|
||||||
modifiedQueryMap.put("shareTypes[]", shareTypesList);
|
modifiedQueryMap.put("shareTypes[]", shareTypesList);
|
||||||
}
|
|
||||||
|
|
||||||
boolean finalServerIs14OrUp = serverIs14OrUp;
|
|
||||||
ncApi.getContactsWithSearchParam(
|
ncApi.getContactsWithSearchParam(
|
||||||
credentials,
|
credentials,
|
||||||
retrofitBucket.getUrl(), shareTypesList, modifiedQueryMap)
|
retrofitBucket.getUrl(), shareTypesList, modifiedQueryMap)
|
||||||
@ -521,47 +497,6 @@ public class ContactsController extends BaseController implements SearchView.OnQ
|
|||||||
List<AbstractFlexibleItem> newUserItemList = new ArrayList<>();
|
List<AbstractFlexibleItem> newUserItemList = new ArrayList<>();
|
||||||
|
|
||||||
try {
|
try {
|
||||||
if (!finalServerIs14OrUp) {
|
|
||||||
ShareesOverall shareesOverall = LoganSquare.parse(responseBody.string(), ShareesOverall.class);
|
|
||||||
|
|
||||||
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());
|
|
||||||
}
|
|
||||||
|
|
||||||
for (Sharee sharee : shareeHashSet) {
|
|
||||||
if (!sharee.getValue().getShareWith().equals(currentUser.getUserId()) && !existingParticipants.contains(sharee.getValue().getShareWith())) {
|
|
||||||
participant = new Participant();
|
|
||||||
participant.setDisplayName(sharee.getLabel());
|
|
||||||
String headerTitle;
|
|
||||||
|
|
||||||
headerTitle = sharee.getLabel().substring(0, 1).toUpperCase();
|
|
||||||
|
|
||||||
GenericTextHeaderItem genericTextHeaderItem;
|
|
||||||
if (!userHeaderItems.containsKey(headerTitle)) {
|
|
||||||
genericTextHeaderItem = new GenericTextHeaderItem(headerTitle);
|
|
||||||
userHeaderItems.put(headerTitle, genericTextHeaderItem);
|
|
||||||
}
|
|
||||||
|
|
||||||
participant.setUserId(sharee.getValue().getShareWith());
|
|
||||||
|
|
||||||
UserItem newContactItem = new UserItem(participant, currentUser,
|
|
||||||
userHeaderItems.get(headerTitle));
|
|
||||||
|
|
||||||
if (!contactItems.contains(newContactItem)) {
|
|
||||||
newUserItemList.add(newContactItem);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
} else {
|
|
||||||
AutocompleteOverall autocompleteOverall = LoganSquare.parse(responseBody.string(), AutocompleteOverall.class);
|
AutocompleteOverall autocompleteOverall = LoganSquare.parse(responseBody.string(), AutocompleteOverall.class);
|
||||||
autocompleteUsersHashSet.addAll(autocompleteOverall.getOcs().getData());
|
autocompleteUsersHashSet.addAll(autocompleteOverall.getOcs().getData());
|
||||||
|
|
||||||
@ -596,19 +531,10 @@ public class ContactsController extends BaseController implements SearchView.OnQ
|
|||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
} catch (Exception exception) {
|
} catch (Exception exception) {
|
||||||
Log.e(TAG, "Parsing response body failed while getting contacts");
|
Log.e(TAG, "Parsing response body failed while getting contacts");
|
||||||
}
|
}
|
||||||
|
|
||||||
if (TextUtils.isEmpty((CharSequence) modifiedQueryMap.get("search"))) {
|
|
||||||
canFetchFurther = !shareeHashSet.isEmpty() || (finalServerIs14OrUp && autocompleteUsersHashSet.size() == 100);
|
|
||||||
currentPage = (int) modifiedQueryMap.get("page");
|
|
||||||
} else {
|
|
||||||
canFetchSearchFurther = !shareeHashSet.isEmpty() || (finalServerIs14OrUp && autocompleteUsersHashSet.size() == 100);
|
|
||||||
currentSearchPage = (int) modifiedQueryMap.get("page");
|
|
||||||
}
|
|
||||||
|
|
||||||
userHeaderItems = new HashMap<>();
|
userHeaderItems = new HashMap<>();
|
||||||
contactItems.addAll(newUserItemList);
|
contactItems.addAll(newUserItemList);
|
||||||
|
|
||||||
@ -1049,20 +975,4 @@ public class ContactsController extends BaseController implements SearchView.OnQ
|
|||||||
secondaryRelativeLayout.setVisibility(View.VISIBLE);
|
secondaryRelativeLayout.setVisibility(View.VISIBLE);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public void noMoreLoad(int newItemsSize) {
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onLoadMore(int lastPosition, int currentPage) {
|
|
||||||
String query = (String) adapter.getFilter(String.class);
|
|
||||||
|
|
||||||
if (!alreadyFetching && ((searchView != null && searchView.isIconified() && canFetchFurther)
|
|
||||||
|| (!TextUtils.isEmpty(query) && canFetchSearchFurther))) {
|
|
||||||
fetchData(false);
|
|
||||||
} else {
|
|
||||||
adapter.onLoadMoreComplete(null);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user