Skip to content
Snippets Groups Projects
Commit 3c4ae5b8 authored by priagungs's avatar priagungs
Browse files

Merge branch 'master' of github.com:Ilhamfp31/chatman

parents 1d3b66d6 2f2be2f7
No related merge requests found
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ProjectRootManager" version="2" languageLevel="JDK_1_7" project-jdk-name="1.8" project-jdk-type="JavaSDK">
<component name="ProjectRootManager" version="2" languageLevel="JDK_1_7" project-jdk-name="1.8 (1)" project-jdk-type="JavaSDK">
<output url="file://$PROJECT_DIR$/build/classes" />
</component>
<component name="ProjectType">
......
......@@ -87,7 +87,7 @@ public class ChatRoomActivity extends AppCompatActivity {
chatRv.setLayoutManager(linearLayoutManager);
adapter = new ChatAdapter(chatList);
chatRv.setAdapter(adapter);
chatRv.scrollToPosition(chatList.size() - 1);
initializeListener();
}
......@@ -138,6 +138,7 @@ public class ChatRoomActivity extends AppCompatActivity {
public void onDataChange(@NonNull DataSnapshot dataSnapshot) {
chatList.add(dataSnapshot.getValue(Chat.class));
adapter.notifyDataSetChanged();
chatRv.scrollToPosition(chatList.size() - 1);
}
@Override
......
......@@ -47,7 +47,7 @@ public class BotFragment extends Fragment {
private RecyclerView recycler;
private ChatAdapter adapter;
private List<Chat> chatList;
private static final String BOT_KEY = "BOT_KEY";
private static final String BOT_TOKEN = "BOT_TOKEN";
public BotFragment() {
// Required empty public constructor
......@@ -79,12 +79,12 @@ public class BotFragment extends Fragment {
public void onClick(View view) {
if (!message.getText().toString().equals("")){
Toast.makeText(context, "Send: "+message.getText().toString(), Toast.LENGTH_SHORT).show();
Chat sendMessage = new Chat(PreferencesHelper.getToken(context), PreferencesHelper.getUserName(context), BOT_KEY, Calendar.getInstance().getTime(), message.getText().toString());
Chat sendMessage = new Chat(PreferencesHelper.getToken(context), PreferencesHelper.getUserName(context), BOT_TOKEN, Calendar.getInstance().getTime(), message.getText().toString());
String key = FirebaseHelper.dbMessage.push().getKey();
FirebaseHelper.dbMessage.child(key).setValue(sendMessage);
message.setText("");
// BALASAN DARI BOT
Chat botMessage = new Chat(BOT_KEY, "ChatMan Bot", PreferencesHelper.getUserFirebaseKey(context), Calendar.getInstance().getTime(), "Halo! Selamat datang di ChatMan");
Chat botMessage = new Chat(BOT_TOKEN, "ChatMan Bot", PreferencesHelper.getToken(context), Calendar.getInstance().getTime(), "Halo! Selamat datang di ChatMan");
String botKey = FirebaseHelper.dbMessage.push().getKey();
FirebaseHelper.dbMessage.child(botKey).setValue(botMessage);
......@@ -113,6 +113,7 @@ public class BotFragment extends Fragment {
public void onDataChange(@NonNull DataSnapshot dataSnapshot) {
getAllChat(dataSnapshot);
adapter.notifyDataSetChanged();
recycler.scrollToPosition(chatList.size() - 1);
}
@Override
......@@ -125,7 +126,7 @@ public class BotFragment extends Fragment {
private void getAllChat(DataSnapshot dataSnapshot) {
chatList = new ArrayList<>();
for (DataSnapshot ds : dataSnapshot.getChildren()) {
if (ds.getValue(Chat.class).getIdSender().equals(PreferencesHelper.getUserFirebaseKey(context)) || ds.getValue(Chat.class).getIdReceiver().equals(PreferencesHelper.getUserFirebaseKey(context))) {
if ( (ds.getValue(Chat.class).getIdSender().equals(PreferencesHelper.getToken(context)) && ds.getValue(Chat.class).getIdReceiver().equals(BOT_TOKEN)) || (ds.getValue(Chat.class).getIdReceiver().equals(PreferencesHelper.getToken(context)) && ds.getValue(Chat.class).getIdSender().equals(BOT_TOKEN))) {
chatList.add(ds.getValue(Chat.class));
}
}
......
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment