use of com.nextcloud.talk.models.database.UserEntity 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.models.database.UserEntity in project talk-android by nextcloud.
the class SettingsController method onAttach.
@Override
protected void onAttach(@NonNull View view) {
super.onAttach(view);
if (getActionBar() != null) {
getActionBar().show();
}
dispose(null);
userEntity = userUtils.getCurrentUser();
if ("No proxy".equals(appPreferences.getProxyType()) || appPreferences.getProxyType() == null) {
hideProxySettings();
} else {
showProxySettings();
}
if (appPreferences.getProxyCredentials()) {
showProxyCredentials();
} else {
hideProxyCredentials();
}
if (userEntity != null) {
baseUrlTextView.setText(userEntity.getBaseUrl());
reauthorizeButton.addPreferenceClickListener(view14 -> {
getParentController().getRouter().pushController(RouterTransaction.with(new WebViewLoginController(userEntity.getBaseUrl(), true)).pushChangeHandler(new VerticalChangeHandler()).popChangeHandler(new VerticalChangeHandler()));
});
if (userEntity.getDisplayName() != null) {
displayNameTextView.setText(userEntity.getDisplayName());
}
loadAvatarImage();
profileQueryDisposable = ncApi.getUserProfile(ApiUtils.getCredentials(userEntity.getUsername(), userEntity.getToken()), ApiUtils.getUrlForUserProfile(userEntity.getBaseUrl())).subscribeOn(Schedulers.newThread()).observeOn(AndroidSchedulers.mainThread()).subscribe(userProfileOverall -> {
String displayName = null;
if (!TextUtils.isEmpty(userProfileOverall.getOcs().getData().getDisplayName())) {
displayName = userProfileOverall.getOcs().getData().getDisplayName();
} else if (!TextUtils.isEmpty(userProfileOverall.getOcs().getData().getDisplayNameAlt())) {
displayName = userProfileOverall.getOcs().getData().getDisplayNameAlt();
}
boolean needsToUpdateUserId = !TextUtils.isEmpty(userProfileOverall.getOcs().getData().getUserId()) && !userProfileOverall.getOcs().getData().getUserId().equals(userEntity.getUserId());
if ((!TextUtils.isEmpty(displayName) && !displayName.equals(userEntity.getDisplayName())) || needsToUpdateUserId) {
dbQueryDisposable = userUtils.createOrUpdateUser(null, null, null, displayName, null, true, userProfileOverall.getOcs().getData().getUserId(), userEntity.getId(), null).subscribeOn(Schedulers.newThread()).observeOn(AndroidSchedulers.mainThread()).subscribe(userEntityResult -> {
displayNameTextView.setText(userEntityResult.getDisplayName());
if (needsToUpdateUserId) {
loadAvatarImage();
}
}, throwable -> {
dispose(dbQueryDisposable);
}, () -> dispose(dbQueryDisposable));
}
}, throwable -> {
dispose(profileQueryDisposable);
}, () -> dispose(profileQueryDisposable));
removeAccountButton.addPreferenceClickListener(view1 -> {
cookieManager.getCookieStore().removeAll();
boolean otherUserExists = userUtils.scheduleUserForDeletionWithId(userEntity.getId());
new JobRequest.Builder(AccountRemovalJob.TAG).setUpdateCurrent(true).startNow().build().schedule();
if (otherUserExists && getView() != null) {
onViewBound(getView());
onAttach(getView());
} else if (!otherUserExists) {
if (getParentController() == null || getParentController().getRouter() == null) {
if (getActivity() != null) {
// Something went very wrong, finish the app
getActivity().finish();
}
} else {
getParentController().getRouter().setRoot(RouterTransaction.with(new ServerSelectionController()).pushChangeHandler(new VerticalChangeHandler()).popChangeHandler(new VerticalChangeHandler()));
}
}
});
}
if (userUtils.getUsers().size() <= 1) {
switchAccountButton.setVisibility(View.GONE);
}
if (ApplicationWideMessageHolder.getInstance().getMessageType() != null) {
switch(ApplicationWideMessageHolder.getInstance().getMessageType()) {
case ACCOUNT_UPDATED_NOT_ADDED:
messageText.setTextColor(getResources().getColor(R.color.colorPrimary));
messageText.setText(getResources().getString(R.string.nc_settings_account_updated));
messageView.setVisibility(View.VISIBLE);
break;
case WRONG_ACCOUNT:
messageText.setTextColor(getResources().getColor(R.color.nc_darkRed));
messageText.setText(getResources().getString(R.string.nc_settings_wrong_account));
messageView.setVisibility(View.VISIBLE);
break;
case SERVER_WITHOUT_TALK:
messageText.setTextColor(getResources().getColor(R.color.nc_darkRed));
messageText.setText(getResources().getString(R.string.nc_settings_wrong_account));
messageView.setVisibility(View.VISIBLE);
case ACCOUNT_WAS_IMPORTED:
messageText.setTextColor(getResources().getColor(R.color.colorPrimary));
messageText.setText(getResources().getString(R.string.nc_Server_account_imported));
messageView.setVisibility(View.VISIBLE);
break;
case FAILED_TO_IMPORT_ACCOUNT:
messageText.setTextColor(getResources().getColor(R.color.nc_darkRed));
messageText.setText(getResources().getString(R.string.nc_server_failed_to_import_account));
messageView.setVisibility(View.VISIBLE);
break;
default:
messageView.setVisibility(View.GONE);
break;
}
ApplicationWideMessageHolder.getInstance().setMessageType(null);
messageView.animate().translationY(0).alpha(0.0f).setDuration(2500).setStartDelay(5000).setListener(new AnimatorListenerAdapter() {
@Override
public void onAnimationEnd(Animator animation) {
super.onAnimationEnd(animation);
if (messageView != null) {
messageView.setVisibility(View.GONE);
}
}
});
} else {
if (messageView != null) {
messageView.setVisibility(View.GONE);
}
}
}
use of com.nextcloud.talk.models.database.UserEntity in project talk-android by nextcloud.
the class WebViewLoginController method parseAndLoginFromWebView.
private void parseAndLoginFromWebView(String dataString) {
LoginData loginData = parseLoginData(assembledPrefix, dataString);
if (loginData != null) {
dispose();
UserEntity currentUser = userUtils.getCurrentUser();
ApplicationWideMessageHolder.MessageType messageType = null;
if (currentUser != null && isPasswordUpdate && !currentUser.getUsername().equals(loginData.getUsername())) {
ApplicationWideMessageHolder.getInstance().setMessageType(ApplicationWideMessageHolder.MessageType.WRONG_ACCOUNT);
getRouter().popToRoot();
} else {
if (!isPasswordUpdate && userUtils.getIfUserWithUsernameAndServer(loginData.getUsername(), baseUrl)) {
messageType = ApplicationWideMessageHolder.MessageType.ACCOUNT_UPDATED_NOT_ADDED;
}
if (userUtils.checkIfUserIsScheduledForDeletion(loginData.getUsername(), baseUrl)) {
ApplicationWideMessageHolder.getInstance().setMessageType(ApplicationWideMessageHolder.MessageType.ACCOUNT_SCHEDULED_FOR_DELETION);
getRouter().popToRoot();
}
ApplicationWideMessageHolder.MessageType finalMessageType = messageType;
cookieManager.getCookieStore().removeAll();
if (!isPasswordUpdate && finalMessageType == null) {
Bundle bundle = new Bundle();
bundle.putString(BundleKeys.KEY_USERNAME, loginData.getUsername());
bundle.putString(BundleKeys.KEY_TOKEN, loginData.getToken());
bundle.putString(BundleKeys.KEY_BASE_URL, loginData.getServerUrl());
String protocol = "";
if (baseUrl.startsWith("http://")) {
protocol = "http://";
} else if (baseUrl.startsWith("https://")) {
protocol = "https://";
}
if (!TextUtils.isEmpty(protocol)) {
bundle.putString(BundleKeys.KEY_ORIGINAL_PROTOCOL, protocol);
}
getRouter().pushController(RouterTransaction.with(new AccountVerificationController(bundle)).pushChangeHandler(new HorizontalChangeHandler()).popChangeHandler(new HorizontalChangeHandler()));
} else {
if (isPasswordUpdate) {
if (currentUser != null) {
userQueryDisposable = userUtils.createOrUpdateUser(null, null, null, null, null, true, null, currentUser.getId(), null).subscribe(userEntity -> {
if (finalMessageType != null) {
ApplicationWideMessageHolder.getInstance().setMessageType(finalMessageType);
}
getRouter().popToRoot();
}, throwable -> dispose(), this::dispose);
}
} else {
if (finalMessageType != null) {
ApplicationWideMessageHolder.getInstance().setMessageType(finalMessageType);
}
getRouter().popToRoot();
}
}
}
}
}
use of com.nextcloud.talk.models.database.UserEntity in project talk-android by nextcloud.
the class UserUtils method getAnyUserAndSetAsActive.
public UserEntity getAnyUserAndSetAsActive() {
Result findUserQueryResult = dataStore.select(User.class).where(UserEntity.SCHEDULED_FOR_DELETION.notEqual(true)).limit(1).get();
UserEntity userEntity;
if ((userEntity = (UserEntity) findUserQueryResult.firstOrNull()) != null) {
userEntity.setCurrent(true);
dataStore.update(userEntity).blockingGet();
return userEntity;
}
return null;
}
use of com.nextcloud.talk.models.database.UserEntity in project talk-android by nextcloud.
the class UserUtils method disableAllUsersWithoutId.
public void disableAllUsersWithoutId(long userId) {
Result findUserQueryResult = dataStore.select(User.class).where(UserEntity.ID.notEqual(userId)).get();
for (Object object : findUserQueryResult) {
UserEntity userEntity = (UserEntity) object;
userEntity.setCurrent(false);
dataStore.update(userEntity).blockingGet();
}
}
Aggregations