Skip to content

Commit

Permalink
Update Admin messages
Browse files Browse the repository at this point in the history
  • Loading branch information
tien-awair committed May 29, 2022
1 parent aa06eca commit 8669b0d
Show file tree
Hide file tree
Showing 12 changed files with 106 additions and 10 deletions.
6 changes: 3 additions & 3 deletions uikit-custom-sample/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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> initState = new MutableLiveData<>();

@Override
Expand Down Expand Up @@ -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<InitState> initStateChanges() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -91,6 +92,7 @@ protected void onCreate(Bundle savedInstanceState) {
AudioManager.getInstance().attachLifecycle(getLifecycle());
}


public int getLayoutId() {
return R.layout.sb_activity;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package com.sendbird.uikit.model.admin;

public class AdminChannelChangeType {
public static final String CHANNEL_CHANGE_COVER_URL = "cover_url";
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@ public class AdminMessageData {
@SerializedName("users")
private List<AdminMessageUser> users;

@SerializedName("changes")
private List<AdminChannelChange> changes;

public String getType() {
return type;
}
Expand All @@ -32,9 +35,31 @@ public void setUsers(List<AdminMessageUser> users) {
this.users = users;
}

public List<AdminChannelChange> getChanges() {
return changes;
}

public void setChanges(List<AdminChannelChange> 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 "";
}
Expand All @@ -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<String> getUserNames() {
List<String> names = new ArrayList<>();
for (AdminMessageUser user : users) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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";
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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();

Expand Down

0 comments on commit 8669b0d

Please sign in to comment.