Skip to content

Commit

Permalink
custom channel Data
Browse files Browse the repository at this point in the history
  • Loading branch information
adrian09h committed Jul 15, 2019
1 parent 5385eee commit b43ed7b
Show file tree
Hide file tree
Showing 7 changed files with 46 additions and 10 deletions.
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ buildscript {
}

dependencies {
classpath 'com.android.tools.build:gradle:3.4.1'
classpath 'com.android.tools.build:gradle:3.4.2'
// classpath 'com.jfrog.bintray.gradle:gradle-bintray-plugin:1.8.1'
classpath 'com.github.dcendents:android-maven-gradle-plugin:2.1'
classpath 'com.google.gms:google-services:4.2.0'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
import com.google.gson.annotations.Expose;
import com.google.gson.annotations.SerializedName;

import java.util.Map;

public class Channel{
@SerializedName("id")
@Expose
Expand Down Expand Up @@ -46,6 +48,9 @@ public class Channel{
@Expose
private int example;

private Map<String, Object> additionalFields;


public String getId() {
return id;
}
Expand Down Expand Up @@ -130,12 +135,22 @@ public Channel(){

}

public Channel(String type, String id, String name, String image){
public Map<String, Object> getAdditionalFields() {
return additionalFields;
}

public void setAdditionalFields(Map<String, Object> additionalFields) {
this.additionalFields = additionalFields;
}

public Channel(String type, String id, String name, String image, Map<String, Object>additionalFields){
this.type = type;
this.id = id;
this.name = name;
this.imageURL = image;
this.additionalFields = additionalFields;
}

public String getInitials() {
String name = this.name;
if (name == null){
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public void setupURLSession(Channel channel_) {
String channelName = channel_.getName();
String channelImage = channel_.getImageURL();

Channel channel = new Channel(ModelType.channel_messaging, channelId, channelName, channelImage);
Channel channel = new Channel(ModelType.channel_messaging, channelId, channelName, channelImage, null);

Map<String, Object> messages = new HashMap<>();
messages.put("limit", Constant.DEFAULT_LIMIT);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ public PaginationRequest(int limit, String messageId, Channel channel) {
this.channel.remove("frozen");
this.channel.remove("config");
this.channel.remove("example");
this.channel.remove("additionalFields");

this.state = true;
this.watch = true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ public void setClientID(String clientID) {
}

// region Customize Components
public void setChannel(String channelType, String channelId, String channelName, String channelImage) {
public void setChannel(String channelType, String channelId, String channelName, String channelImage, HashMap<String, Object>additionalFields) {
if (channelId == null) {
this.channel = null;
return;
Expand All @@ -104,6 +104,7 @@ public void setChannel(String channelType, String channelId, String channelName,
channel_.setId(channelId);
channel_.setName(channelName);
channel_.setImageURL(channelImage);

this.channel = channel_;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Set;

public class ChatActivity extends AppCompatActivity implements EventHandler, WSResponseHandler {

Expand Down Expand Up @@ -182,16 +183,17 @@ public void onBackPressed() {
void init() {
try {
Fresco.initialize(getApplicationContext());
} catch (Exception e) {}
} catch (Exception e) {
}

// set viewModel
String channelId = null;
Bundle b = getIntent().getExtras();
if(b!=null){
if (b != null) {
channelId = (String) b.get(Constant.TAG_CHANNEL_RESPONSE_ID);
}
Log.d(TAG, "Channel ID: " + channelId);
if (channelId != null){
if (channelId != null) {
channelResponse = Global.getChannelResponseById(channelId);
}

Expand Down Expand Up @@ -358,7 +360,17 @@ private void getChannel() {
channel_.setType(ModelType.channel_messaging);
Map<String, Object> messages = new HashMap<>();
messages.put("limit", Constant.DEFAULT_LIMIT);

// Additional Field
Map<String, Object> data = new HashMap<>();
if (channel_.getAdditionalFields() != null) {
Set<String> keys = channel_.getAdditionalFields().keySet();
for (String key : keys) {
Object value = channel_.getAdditionalFields().get(key);
if (value != null)
data.put(key, value);
}
}
Log.d(TAG, "Channel Connecting...");

ChannelDetailRequest request = new ChannelDetailRequest(messages, data, true, true);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@
import java.util.List;
import java.util.Map;
import java.util.Random;
import java.util.Set;

public class UsersActivity extends AppCompatActivity {

Expand Down Expand Up @@ -278,21 +279,27 @@ private void getChannel(List<User> users) {


Log.d(TAG, "Channel ID: " + channelId);
Channel channel = new Channel(ModelType.channel_messaging, channelId, isPrivateChannel ? null : binding.tvGroupName.getText().toString(), null);
/**
* Add additional fields - you can add additional info of user
* @param {HashMap} additionalFields User Additional fields
* @return
*/

Channel channel = new Channel(ModelType.channel_messaging, channelId, isPrivateChannel ? null : binding.tvGroupName.getText().toString(), null, null);

Map<String, Object> messages = new HashMap<>();
messages.put("limit", Constant.DEFAULT_LIMIT);
Map<String, Object> data = new HashMap<>();
data.put("name", channel.getName());
data.put("image", channel.getImageURL());

List members = new ArrayList();
List<String> members = new ArrayList<>();
members.add(Global.streamChat.getUser().getId());
for (User user : users) {
members.add(user.getId());
}
data.put("members", members);

data.put("group","sports");
// if (Component.Channel.invitation) {
// data.put("invites", Arrays.asList(user.getId()));
// }
Expand Down

0 comments on commit b43ed7b

Please sign in to comment.