From 8669b0d0edd44abcd748507474617c53413ed12a Mon Sep 17 00:00:00 2001 From: Tien Date: Sun, 29 May 2022 14:42:03 +0700 Subject: [PATCH] Update Admin messages --- uikit-custom-sample/build.gradle | 6 +-- .../uikit/customsample/BaseApplication.java | 6 ++- .../GroupChannelMainActivity.java | 2 +- .../activities/CustomChannelActivity.java | 4 +- .../CustomCreateChannelFragment.java | 2 +- .../CustomInviteChannelFragment.java | 2 +- .../uikit/activities/ChannelActivity.java | 2 + .../uikit/model/admin/AdminChannelChange.java | 41 ++++++++++++++++++ .../model/admin/AdminChannelChangeType.java | 5 +++ .../uikit/model/admin/AdminMessageData.java | 42 ++++++++++++++++++- .../uikit/model/admin/AdminMessageType.java | 2 + .../uikit/widgets/AdminMessageView.java | 2 + 12 files changed, 106 insertions(+), 10 deletions(-) create mode 100644 uikit/src/main/java/com/sendbird/uikit/model/admin/AdminChannelChange.java create mode 100644 uikit/src/main/java/com/sendbird/uikit/model/admin/AdminChannelChangeType.java diff --git a/uikit-custom-sample/build.gradle b/uikit-custom-sample/build.gradle index 9071dd3a..e9c0d939 100644 --- a/uikit-custom-sample/build.gradle +++ b/uikit-custom-sample/build.gradle @@ -2,7 +2,7 @@ apply plugin: 'com.android.application' apply plugin: 'com.google.gms.google-services' android { - compileSdkVersion 30 + compileSdkVersion 31 buildToolsVersion "29.0.3" defaultConfig { @@ -35,8 +35,8 @@ android { dependencies { implementation fileTree(dir: "libs", include: ["*.jar"]) -// implementation project(":uikit") - implementation "com.sendbird.sdk:uikit:2.2.5" + implementation project(":uikit") +// implementation "com.sendbird.sdk:uikit:2.2.5" implementation "androidx.multidex:multidex:2.0.1" implementation 'com.google.firebase:firebase-messaging:21.0.0' diff --git a/uikit-custom-sample/src/main/java/com/sendbird/uikit/customsample/BaseApplication.java b/uikit-custom-sample/src/main/java/com/sendbird/uikit/customsample/BaseApplication.java index 251043ab..b76af7b7 100644 --- a/uikit-custom-sample/src/main/java/com/sendbird/uikit/customsample/BaseApplication.java +++ b/uikit-custom-sample/src/main/java/com/sendbird/uikit/customsample/BaseApplication.java @@ -26,13 +26,14 @@ import com.sendbird.uikit.interfaces.CustomUserListQueryHandler; import com.sendbird.uikit.interfaces.UserInfo; import com.sendbird.uikit.interfaces.UserListResultHandler; +import com.sendbird.uikit.widgets.AudioPlayer; import java.util.ArrayList; import java.util.List; public class BaseApplication extends MultiDexApplication { - private static final String APP_ID = "2D7B4CDB-932F-4082-9B09-A1153792DC8D"; + private static final String APP_ID = "033D0C2B-1B69-4592-90E5-2B6D8D58A86B"; private static final MutableLiveData initState = new MutableLiveData<>(); @Override @@ -128,6 +129,9 @@ public void onBeforeUpdateOpenChannel(@NonNull OpenChannelParams openChannelPara // You can set OpenChannelParams globally before updating a channel. } }); + + AudioPlayer.getInstance().init(this); + } public static LiveData initStateChanges() { diff --git a/uikit-custom-sample/src/main/java/com/sendbird/uikit/customsample/groupchannel/GroupChannelMainActivity.java b/uikit-custom-sample/src/main/java/com/sendbird/uikit/customsample/groupchannel/GroupChannelMainActivity.java index b06e095e..870902e7 100644 --- a/uikit-custom-sample/src/main/java/com/sendbird/uikit/customsample/groupchannel/GroupChannelMainActivity.java +++ b/uikit-custom-sample/src/main/java/com/sendbird/uikit/customsample/groupchannel/GroupChannelMainActivity.java @@ -136,7 +136,7 @@ private void redirectChannelIfNeeded(Intent intent) { } private void showCustomChannelActivity(String channelUrl) { - Intent intent = CustomChannelActivity.newIntentFromCustomActivity(GroupChannelMainActivity.this, CustomChannelActivity.class, channelUrl); + Intent intent = CustomChannelActivity.newIntentFromCustomActivity(GroupChannelMainActivity.this, CustomChannelActivity.class, channelUrl, null); startActivity(intent); } diff --git a/uikit-custom-sample/src/main/java/com/sendbird/uikit/customsample/groupchannel/activities/CustomChannelActivity.java b/uikit-custom-sample/src/main/java/com/sendbird/uikit/customsample/groupchannel/activities/CustomChannelActivity.java index f5cca7bb..93e173d2 100644 --- a/uikit-custom-sample/src/main/java/com/sendbird/uikit/customsample/groupchannel/activities/CustomChannelActivity.java +++ b/uikit-custom-sample/src/main/java/com/sendbird/uikit/customsample/groupchannel/activities/CustomChannelActivity.java @@ -17,8 +17,8 @@ public class CustomChannelActivity extends ChannelActivity { private final CustomChannelFragment customChannelFragment = new CustomChannelFragment(); @Override - protected ChannelFragment createChannelFragment(@NonNull String channelUrl) { - final boolean useMessageGroupUI = false; + protected ChannelFragment createChannelFragment(@NonNull String channelUrl, String channelName) { + final boolean useMessageGroupUI = true; return new ChannelFragment.Builder(channelUrl, R.style.CustomMessageListStyle) .setCustomChannelFragment(customChannelFragment) .setUseHeader(true) diff --git a/uikit-custom-sample/src/main/java/com/sendbird/uikit/customsample/groupchannel/fragments/CustomCreateChannelFragment.java b/uikit-custom-sample/src/main/java/com/sendbird/uikit/customsample/groupchannel/fragments/CustomCreateChannelFragment.java index 07cc867d..2080044b 100644 --- a/uikit-custom-sample/src/main/java/com/sendbird/uikit/customsample/groupchannel/fragments/CustomCreateChannelFragment.java +++ b/uikit-custom-sample/src/main/java/com/sendbird/uikit/customsample/groupchannel/fragments/CustomCreateChannelFragment.java @@ -69,7 +69,7 @@ private CustomUserListAdapter createCustomUserListAdapter() { private void showCustomChannelActivity(String channelUrl) { if (getActivity() != null && getContext() != null) { - Intent intent = CustomChannelActivity.newIntentFromCustomActivity(getActivity(), CustomChannelActivity.class, channelUrl); + Intent intent = CustomChannelActivity.newIntentFromCustomActivity(getActivity(), CustomChannelActivity.class, channelUrl, null); startActivity(intent); getActivity().finish(); } diff --git a/uikit-custom-sample/src/main/java/com/sendbird/uikit/customsample/groupchannel/fragments/CustomInviteChannelFragment.java b/uikit-custom-sample/src/main/java/com/sendbird/uikit/customsample/groupchannel/fragments/CustomInviteChannelFragment.java index c9e19bc9..6702d128 100644 --- a/uikit-custom-sample/src/main/java/com/sendbird/uikit/customsample/groupchannel/fragments/CustomInviteChannelFragment.java +++ b/uikit-custom-sample/src/main/java/com/sendbird/uikit/customsample/groupchannel/fragments/CustomInviteChannelFragment.java @@ -70,7 +70,7 @@ private CustomUserListAdapter createCustomAdapter() { private void showCustomChannelActivity() { if (getContext() != null) { - Intent intent = ChannelActivity.newIntentFromCustomActivity(getContext(), CustomChannelActivity.class, channel.getUrl()); + Intent intent = ChannelActivity.newIntentFromCustomActivity(getContext(), CustomChannelActivity.class, channel.getUrl(), null); intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); startActivity(intent); } diff --git a/uikit/src/main/java/com/sendbird/uikit/activities/ChannelActivity.java b/uikit/src/main/java/com/sendbird/uikit/activities/ChannelActivity.java index 8f735be9..26aad95a 100644 --- a/uikit/src/main/java/com/sendbird/uikit/activities/ChannelActivity.java +++ b/uikit/src/main/java/com/sendbird/uikit/activities/ChannelActivity.java @@ -8,6 +8,7 @@ import androidx.annotation.NonNull; import androidx.annotation.Nullable; import androidx.appcompat.app.AppCompatActivity; +import androidx.appcompat.content.res.AppCompatResources; import androidx.fragment.app.FragmentManager; import com.sendbird.android.Member; @@ -91,6 +92,7 @@ protected void onCreate(Bundle savedInstanceState) { AudioManager.getInstance().attachLifecycle(getLifecycle()); } + public int getLayoutId() { return R.layout.sb_activity; } diff --git a/uikit/src/main/java/com/sendbird/uikit/model/admin/AdminChannelChange.java b/uikit/src/main/java/com/sendbird/uikit/model/admin/AdminChannelChange.java new file mode 100644 index 00000000..8c8449d5 --- /dev/null +++ b/uikit/src/main/java/com/sendbird/uikit/model/admin/AdminChannelChange.java @@ -0,0 +1,41 @@ +package com.sendbird.uikit.model.admin; + +import androidx.annotation.Keep; + +import com.sendbird.android.shadow.com.google.gson.annotations.SerializedName; + +@Keep +public class AdminChannelChange { + @SerializedName("new") + private String newChange; + + @SerializedName("old") + private String oldChange; + + @SerializedName("key") + private String key; + + public String getNewChange() { + return newChange; + } + + public void setNewChange(String newChange) { + this.newChange = newChange; + } + + public String getOldChange() { + return oldChange; + } + + public void setOldChange(String oldChange) { + this.oldChange = oldChange; + } + + public String getKey() { + return key; + } + + public void setKey(String key) { + this.key = key; + } +} diff --git a/uikit/src/main/java/com/sendbird/uikit/model/admin/AdminChannelChangeType.java b/uikit/src/main/java/com/sendbird/uikit/model/admin/AdminChannelChangeType.java new file mode 100644 index 00000000..7966bc74 --- /dev/null +++ b/uikit/src/main/java/com/sendbird/uikit/model/admin/AdminChannelChangeType.java @@ -0,0 +1,5 @@ +package com.sendbird.uikit.model.admin; + +public class AdminChannelChangeType { + public static final String CHANNEL_CHANGE_COVER_URL = "cover_url"; +} diff --git a/uikit/src/main/java/com/sendbird/uikit/model/admin/AdminMessageData.java b/uikit/src/main/java/com/sendbird/uikit/model/admin/AdminMessageData.java index 013cf9bd..b946f978 100644 --- a/uikit/src/main/java/com/sendbird/uikit/model/admin/AdminMessageData.java +++ b/uikit/src/main/java/com/sendbird/uikit/model/admin/AdminMessageData.java @@ -16,6 +16,9 @@ public class AdminMessageData { @SerializedName("users") private List users; + @SerializedName("changes") + private List changes; + public String getType() { return type; } @@ -32,9 +35,31 @@ public void setUsers(List users) { this.users = users; } + public List getChanges() { + return changes; + } + + public void setChanges(List changes) { + this.changes = changes; + } + public String getContent() { if (type.equalsIgnoreCase(AdminMessageType.USER_JOINED)) { - return joinUserNames() + " joined"; + String joinedName = joinUserNames(); + return android.text.TextUtils.isEmpty(joinedName) ? "" : joinedName + " joined"; + } else if (type.equalsIgnoreCase(AdminMessageType.USER_LEAVE)) { + String joinedName = joinUserNames(); + return android.text.TextUtils.isEmpty(joinedName) ? "" : joinedName + " left"; + } else if (type.equalsIgnoreCase(AdminMessageType.CHANNEL_CHANGE)) { + if (changes != null && !changes.isEmpty()) { + return "The channel " + + joinChannelChanges() + + " " + + (changes.size() == 1 ? "was" : "were") + + " updated"; + } else { + return ""; + } } return ""; } @@ -54,6 +79,21 @@ public String joinUserNames() { return builder.toString(); } + public String joinChannelChanges() { + StringBuilder builder = new StringBuilder(); + for (int i = 0; i < changes.size(); i++) { + AdminChannelChange channelChange = changes.get(i); + if (!TextUtils.isEmpty(channelChange.getKey())) { + String key = channelChange.getKey().replace("cover_url", "image"); + builder.append(key); + if (i < changes.size() - 1) { + builder.append(", "); + } + } + } + return builder.toString(); + } + public List getUserNames() { List names = new ArrayList<>(); for (AdminMessageUser user : users) { diff --git a/uikit/src/main/java/com/sendbird/uikit/model/admin/AdminMessageType.java b/uikit/src/main/java/com/sendbird/uikit/model/admin/AdminMessageType.java index 6667294e..1221dbc9 100644 --- a/uikit/src/main/java/com/sendbird/uikit/model/admin/AdminMessageType.java +++ b/uikit/src/main/java/com/sendbird/uikit/model/admin/AdminMessageType.java @@ -2,4 +2,6 @@ public class AdminMessageType { public static final String USER_JOINED = "USER_JOIN"; + public static final String USER_LEAVE = "USER_LEAVE"; + public static final String CHANNEL_CHANGE = "CHANNEL_CHANGE"; } diff --git a/uikit/src/main/java/com/sendbird/uikit/widgets/AdminMessageView.java b/uikit/src/main/java/com/sendbird/uikit/widgets/AdminMessageView.java index 74700693..179e5422 100644 --- a/uikit/src/main/java/com/sendbird/uikit/widgets/AdminMessageView.java +++ b/uikit/src/main/java/com/sendbird/uikit/widgets/AdminMessageView.java @@ -3,6 +3,7 @@ import android.content.Context; import android.content.res.TypedArray; import android.util.AttributeSet; +import android.util.Log; import android.view.LayoutInflater; import android.view.View; @@ -60,6 +61,7 @@ private void init(Context context, AttributeSet attrs, int defStyle) { public void drawMessage(BaseMessage message) { try { String data = message.getData(); + Log.d("nt.dung", "Admin Message: " + data); AdminMessageData adminMessageData = new Gson().fromJson(data, AdminMessageData.class); String adminMessageContent = adminMessageData.getContent();