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