Commit 68031446 by Kunj Gupta

Removed unused classes.

parent 458beb8c
package com.vsoft.servicenow.chat;
package com.vsoft.servicenow.adapters;
import android.content.Context;
import android.support.v7.widget.RecyclerView;
......@@ -9,19 +9,20 @@ import android.view.ViewGroup;
import android.widget.TextView;
import com.vsoft.servicenow.R;
import com.vsoft.servicenow.db.models.ChatBotHistory;
import com.vsoft.servicenow.utils.PrefManager;
import com.vsoft.servicenow.utils.Util;
import java.util.List;
public class MessageAdapter extends RecyclerView.Adapter<MessageAdapter.ViewHolder> {
public class ChatMessageAdapter extends RecyclerView.Adapter<ChatMessageAdapter.ViewHolder> {
private List<Message> mMessages;
private List<ChatBotHistory> mMessages;
private int[] mUsernameColors;
private Context mContext;
public MessageAdapter(Context context, List<Message> messages) {
public ChatMessageAdapter(Context context, List<ChatBotHistory> messages) {
mMessages = messages;
mContext = context;
mUsernameColors = context.getResources().getIntArray(R.array.username_colors);
......@@ -37,10 +38,10 @@ public class MessageAdapter extends RecyclerView.Adapter<MessageAdapter.ViewHold
@Override
public void onBindViewHolder(ViewHolder viewHolder, int position) {
Message message = mMessages.get(position);
viewHolder.setMessage(message.getUsername(), message.getMessage());
if(message.getUsername() != null) {
viewHolder.setUsername(message.getUsername());
ChatBotHistory chatBotHistory = mMessages.get(position);
viewHolder.setMessage(chatBotHistory.getUserName(), chatBotHistory.getMessage());
if(chatBotHistory.getUserName() != null) {
viewHolder.setUsername(chatBotHistory.getUserName());
}
}
......@@ -51,7 +52,7 @@ public class MessageAdapter extends RecyclerView.Adapter<MessageAdapter.ViewHold
@Override
public int getItemViewType(int position) {
return mMessages.get(position).getType();
return -1;
}
public class ViewHolder extends RecyclerView.ViewHolder {
......
package com.vsoft.servicenow.chat;
public class Message {
public static final int TYPE_MESSAGE = 0;
public static final int TYPE_LOG = 1;
public static final int TYPE_ACTION = 2;
private int mType;
private String mMessage;
private String mUsername;
private Message() {}
public int getType() {
return mType;
};
public String getMessage() {
return mMessage;
};
public String getUsername() {
return mUsername;
};
public static class Builder {
private final int mType;
private String mUsername;
private String mMessage;
public Builder(int type) {
mType = type;
}
public Builder username(String username) {
mUsername = username;
return this;
}
public Builder message(String message) {
mMessage = message;
return this;
}
public Message build() {
Message message = new Message();
message.mType = mType;
message.mUsername = mUsername;
message.mMessage = mMessage;
return message;
}
}
}
......@@ -54,6 +54,7 @@ public class ChatBotHistory {
public static final class ChatBotBuilder {
private long id = -1;
private long userId;
private String userName;
private String message;
private long timestamp;
......@@ -74,6 +75,11 @@ public class ChatBotHistory {
return this;
}
public ChatBotBuilder setUserName(String val) {
userName = val;
return this;
}
public ChatBotBuilder setMessage(String val) {
message = val;
return this;
......@@ -85,13 +91,14 @@ public class ChatBotHistory {
}
public ChatBotBuilder but() {
return aChatBotHistory().setId(id).setUserId(userId).setMessage(message).setTimestamp(timestamp);
return aChatBotHistory().setId(id).setUserId(userId).setUserName(userName).setMessage(message).setTimestamp(timestamp);
}
public ChatBotHistory build() {
ChatBotHistory chatBotHistory = new ChatBotHistory();
chatBotHistory.setId(id);
chatBotHistory.setUserId(userId);
chatBotHistory.setUserName(userName);
chatBotHistory.setMessage(message);
chatBotHistory.setTimestamp(timestamp);
return chatBotHistory;
......
......@@ -25,8 +25,7 @@ import com.github.nkzawa.socketio.client.Socket;
import com.vsoft.servicenow.CatalogueApplication;
import com.vsoft.servicenow.R;
import com.vsoft.servicenow.api.managers.LoginApiManager;
import com.vsoft.servicenow.chat.Message;
import com.vsoft.servicenow.chat.MessageAdapter;
import com.vsoft.servicenow.adapters.ChatMessageAdapter;
import com.vsoft.servicenow.chat.Speaker;
import com.vsoft.servicenow.db.managers.ChatBotHistoryManager;
import com.vsoft.servicenow.db.managers.ChatBotUserManager;
......@@ -66,7 +65,7 @@ public class ChatActivity extends HandleNotificationActivity implements OnDSList
private RecyclerView mMessagesView;
private EditText mInputMessageView;
private List<Message> mMessages = new ArrayList<>();
private List<ChatBotHistory> mMessages = new ArrayList<>();
private RecyclerView.Adapter mAdapter;
private String mLoggedInUsername;
private String mLoggedInUserSysId;
......@@ -139,14 +138,9 @@ public class ChatActivity extends HandleNotificationActivity implements OnDSList
mMessagesView = (RecyclerView) findViewById(R.id.messages);
mMessagesView.setLayoutManager(new LinearLayoutManager(this));
List<ChatBotHistory> chatBotHistoryList = ChatBotHistoryManager.getAllChatBotHistory();
for (int i = 0; i < chatBotHistoryList.size(); i++) {
ChatBotHistory chatBotHistory = chatBotHistoryList.get(i);
mMessages.add(new Message.Builder(Message.TYPE_MESSAGE)
.username(chatBotHistory.getUserName()).message(chatBotHistory.getMessage()).build());
}
mAdapter = new MessageAdapter(this, mMessages);
/*Get all chats from local DB.*/
mMessages = ChatBotHistoryManager.getAllChatBotHistory();
mAdapter = new ChatMessageAdapter(this, mMessages);
mMessagesView.setAdapter(mAdapter);
scrollToBottom();
......@@ -213,6 +207,7 @@ public class ChatActivity extends HandleNotificationActivity implements OnDSList
ChatBotHistory chatBotHistory = ChatBotHistory.ChatBotBuilder.aChatBotHistory()
.setMessage(message)
.setUserId(userLocalId)
.setUserName(username)
.setTimestamp(System.currentTimeMillis()).build();
ChatBotHistoryManager.save(chatBotHistory);
......@@ -224,9 +219,8 @@ public class ChatActivity extends HandleNotificationActivity implements OnDSList
speaker.allow(true);
speaker.speak(message);
}
mMessages.add(new Message.Builder(Message.TYPE_MESSAGE)
.username(username).message(message).build());
mMessages.add(chatBotHistory);
mAdapter.notifyItemInserted(mMessages.size() - 1);
scrollToBottom();
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment