Skip to content

Commit

Permalink
add user status option to account dialog (WIP)
Browse files Browse the repository at this point in the history
Signed-off-by: Marcel Hibbe <[email protected]>
  • Loading branch information
mahibi authored and timkrueger committed Nov 17, 2021
1 parent 2871122 commit b4ce31c
Show file tree
Hide file tree
Showing 19 changed files with 1,251 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ public static boolean hasExternalCapability(@Nullable UserEntity user, String ca
Capabilities capabilities = LoganSquare.parse(user.getCapabilities(), Capabilities.class);
if (capabilities.getExternalCapability() != null &&
capabilities.getExternalCapability().containsKey("v1")) {
return capabilities.getExternalCapability().get("v1").contains("capabilityName");
return capabilities.getExternalCapability().get("v1").contains(capabilityName);
}
} catch (IOException e) {
Log.e(TAG, "Failed to get capabilities for the user");
Expand Down Expand Up @@ -171,6 +171,22 @@ public static boolean isReadStatusPrivate(@Nullable UserEntity user) {
return false;
}

public static boolean isUserStatusAvailable(@Nullable UserEntity user) {
if (user != null && user.getCapabilities() != null) {
try {
Capabilities capabilities = LoganSquare.parse(user.getCapabilities(), Capabilities.class);
if (capabilities.getUserStatusCapability() != null &&
capabilities.getUserStatusCapability().isEnabled() &&
capabilities.getUserStatusCapability().isSupportsEmoji()) {
return true;
}
} catch (IOException e) {
Log.e(TAG, "Failed to get capabilities for the user");
}
}
return false;
}

public static String getAttachmentFolder(@Nullable UserEntity user) {
if (user != null && user.getCapabilities() != null) {
try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,9 @@ public class Capabilities {
@JsonField(name = "provisioning_api")
ProvisioningCapability provisioningCapability;

@JsonField(name = "user_status")
UserStatusCapability userStatusCapability;

public SpreedCapability getSpreedCapability() {
return this.spreedCapability;
}
Expand All @@ -66,6 +69,10 @@ public ProvisioningCapability getProvisioningCapability() {
return this.provisioningCapability;
}

public UserStatusCapability getUserStatusCapability() {
return userStatusCapability;
}

public void setSpreedCapability(SpreedCapability spreedCapability) {
this.spreedCapability = spreedCapability;
}
Expand All @@ -86,6 +93,10 @@ public void setProvisioningCapability(ProvisioningCapability provisioningCapabil
this.provisioningCapability = provisioningCapability;
}

public void setUserStatusCapability(UserStatusCapability userStatusCapability) {
this.userStatusCapability = userStatusCapability;
}

public boolean equals(final Object o) {
if (o == this) {
return true;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
package com.nextcloud.talk.models.json.capabilities;

import com.bluelinelabs.logansquare.annotation.JsonField;
import com.bluelinelabs.logansquare.annotation.JsonObject;

import org.parceler.Parcel;

@Parcel
@JsonObject
public class UserStatusCapability {
@JsonField(name = "enabled")
boolean enabled;

@JsonField(name = "supports_emoji")
boolean supportsEmoji;

public boolean isEnabled() {
return enabled;
}

public void setEnabled(boolean enabled) {
this.enabled = enabled;
}

public boolean isSupportsEmoji() {
return supportsEmoji;
}

public void setSupportsEmoji(boolean supportsEmoji) {
this.supportsEmoji = supportsEmoji;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,10 @@
import com.nextcloud.talk.R;
import com.nextcloud.talk.activities.MainActivity;
import com.nextcloud.talk.adapters.items.AdvancedUserItem;
import com.nextcloud.talk.api.NcApi;
import com.nextcloud.talk.application.NextcloudTalkApplication;
import com.nextcloud.talk.databinding.DialogChooseAccountBinding;
import com.nextcloud.talk.models.database.CapabilitiesUtil;
import com.nextcloud.talk.models.database.User;
import com.nextcloud.talk.models.database.UserEntity;
import com.nextcloud.talk.models.json.participants.Participant;
Expand Down Expand Up @@ -74,6 +76,9 @@ public class ChooseAccountDialogFragment extends DialogFragment {
@Inject
CookieManager cookieManager;

@Inject
NcApi ncApi;

private DialogChooseAccountBinding binding;
private View dialogView;

Expand Down Expand Up @@ -140,6 +145,16 @@ public void onViewCreated(@NonNull View view, Bundle savedInstanceState) {
});
}

binding.setStatus.setOnClickListener(v -> {
dismiss();
SetStatusDialogFragment setStatusDialog = SetStatusDialogFragment.newInstance(user);
setStatusDialog.show(((MainActivity) getActivity()).getSupportFragmentManager(), "fragment_set_status");
});

if (CapabilitiesUtil.isUserStatusAvailable(userUtils.getCurrentUser())){
binding.statusView.setVisibility(View.VISIBLE);
}

if (adapter == null) {
adapter = new FlexibleAdapter<>(userItems, getActivity(), false);

Expand Down
Loading

0 comments on commit b4ce31c

Please sign in to comment.