<commit_before>package com.example.student.fitabs;

import android.content.Intent;
import android.os.AsyncTask;
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.design.widget.BottomNavigationView;
import android.support.v7.app.AppCompatActivity;
import android.util.Log;
import android.view.MenuItem;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ListView;
import android.widget.TextView;

import java.io.BufferedReader;
import java.io.DataOutputStream;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.io.OutputStreamWriter;
import java.io.PrintWriter;
import java.net.Socket;
import java.util.ArrayList;

import static com.example.student.fitabs.ContactsActivity.selectedContactName;
import static com.example.student.fitabs.ContactsActivity.selectedContactNumber;


/**
 * Created by student on 17.11.7.
 */

public class ChatActivity extends AppCompatActivity implements Runnable {
    public ArrayList<String> chatMessages = new ArrayList<String>();
    private TextView nameTo;
    private ListView chatWindow;
    private EditText editMessage;
    private Client client;
    private ClientListAdapter mAdapter;

    private static int port = 9999;
    private String host = "192.168.8.117";
    static private Socket socket;
    private BufferedReader in;
    static private DataOutputStream os;
    Thread t;

    DBHandler dbHandler;
    User user;
    Button delete;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_chat); // initialization of variables and creating activity view

        nameTo = (TextView) findViewById(R.id.contact);
        nameTo.setText(ContactsActivity.selectedContactName);

        editMessage = (EditText) findViewById(R.id.editMessage);
        chatWindow = (ListView) findViewById(R.id.chat);

        mAdapter = new ClientListAdapter(this, chatMessages);
        chatWindow.setAdapter(mAdapter);

        //Define bottom navigation view (thats why design library in gradle was imported)
        BottomNavigationView bottomNavigationView = (BottomNavigationView) findViewById(R.id.bottom_navigation);
        //Display right icon
        bottomNavigationView.getMenu().getItem(0).setChecked(true);
        //Define Bottom navigation view listener
        bottomNavigationView.setOnNavigationItemSelectedListener(new BottomNavigationView.OnNavigationItemSelectedListener() {
            //Selected icon(item) - changes to the appropriate view
            @Override
            public boolean onNavigationItemSelected(@NonNull MenuItem item) {
                switch (item.getItemId()) {
                    //Contacts
                    case R.id.action_contacts:
                        startActivity(new Intent(ChatActivity.this, ContactsActivity.class));
                        break;
                    //Exercise
                    case R.id.action_exercise:
                        startActivity(new Intent(ChatActivity.this, GroupsOfExercisesActivity.class));
                        break;
                    //Calendar
                    case R.id.action_calendar:
                        startActivity(new Intent(ChatActivity.this, MyCalendarActivity.class));
                        break;
                    //Settings
                    case R.id.action_settings:
                        startActivity(new Intent(ChatActivity.this, UserSettingsActivity.class));
                        break;
                }
                return true;
            }
        });

        //finds and selects  deleteButton view
        delete = (Button) findViewById(R.id.deleteButton);
        delete.setOnClickListener(new View.OnClickListener(){
            @Override
            public void onClick (View v) {
                dbHandler.deleteContact(selectedContactName);
                startActivity(new Intent(ChatActivity.this, ContactsActivity.class));
            }
        });

        dbHandler = new DBHandler(this);
        user = dbHandler.getUser(1);

        t = new Thread(this);
        t.start();
        mAdapter.notifyDataSetChanged();

        dbHandler.close();
    }

    public void sendMsg(View view) {
        dbHandler = new DBHandler(this);
        user = dbHandler.getUser(1);
        String msg = editMessage.getText().toString();
        chatMessages.add(user.getName() + ": " + msg);
        mAdapter.notifyDataSetChanged();

        client = new Client();
        client.execute(host, user.getName() + ": " + msg);

        editMessage.setText("");
        dbHandler.close();
<commit_msg>ChatActivity readMesssages added<commit_after>package com.example.student.fitabs;

import android.content.Intent;
import android.os.AsyncTask;
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.design.widget.BottomNavigationView;
import android.support.v7.app.AppCompatActivity;
import android.util.Log;
import android.view.MenuItem;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ListView;
import android.widget.TextView;

import java.io.BufferedReader;
import java.io.DataOutputStream;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.io.OutputStreamWriter;
import java.io.PrintWriter;
import java.net.Socket;
import java.util.ArrayList;
import java.util.List;

import static android.media.CamcorderProfile.get;
import static com.example.student.fitabs.ContactsActivity.selectedContactName;
import static com.example.student.fitabs.ContactsActivity.selectedContactNumber;


/**
 * Created by student on 17.11.7.
 */

public class ChatActivity extends AppCompatActivity implements Runnable {
    public ArrayList<String> chatMessages = new ArrayList<String>();
    private TextView nameTo;
    private ListView chatWindow;
    private EditText editMessage;
    private Client client;
    private ClientListAdapter mAdapter;

    private static int port = 9999;
    private String host = "192.168.8.117";
    static private Socket socket;
    private BufferedReader in;
    static private DataOutputStream os;
    Thread t;

    DBHandler dbHandler;
    User user;
    Button delete;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_chat); // initialization of variables and creating activity view

        nameTo = (TextView) findViewById(R.id.contact);
        nameTo.setText(ContactsActivity.selectedContactName);

        editMessage = (EditText) findViewById(R.id.editMessage);
        chatWindow = (ListView) findViewById(R.id.chat);

        mAdapter = new ClientListAdapter(this, chatMessages);
        chatWindow.setAdapter(mAdapter);

        readMsg();

        //Define bottom navigation view (thats why design library in gradle was imported)
        BottomNavigationView bottomNavigationView = (BottomNavigationView) findViewById(R.id.bottom_navigation);
        //Display right icon
        bottomNavigationView.getMenu().getItem(0).setChecked(true);
        //Define Bottom navigation view listener
        bottomNavigationView.setOnNavigationItemSelectedListener(new BottomNavigationView.OnNavigationItemSelectedListener() {
            //Selected icon(item) - changes to the appropriate view
            @Override
            public boolean onNavigationItemSelected(@NonNull MenuItem item) {
                switch (item.getItemId()) {
                    //Contacts
                    case R.id.action_contacts:
                        startActivity(new Intent(ChatActivity.this, ContactsActivity.class));
                        break;
                    //Exercise
                    case R.id.action_exercise:
                        startActivity(new Intent(ChatActivity.this, GroupsOfExercisesActivity.class));
                        break;
                    //Calendar
                    case R.id.action_calendar:
                        startActivity(new Intent(ChatActivity.this, MyCalendarActivity.class));
                        break;
                    //Settings
                    case R.id.action_settings:
                        startActivity(new Intent(ChatActivity.this, UserSettingsActivity.class));
                        break;
                }
                return true;
            }
        });

        //finds and selects  deleteButton view
        delete = (Button) findViewById(R.id.deleteButton);
        delete.setOnClickListener(new View.OnClickListener(){
            @Override
            public void onClick (View v) {
                dbHandler.deleteContact(selectedContactName);
                startActivity(new Intent(ChatActivity.this, ContactsActivity.class));
            }
        });

        dbHandler = new DBHandler(this);
        user = dbHandler.getUser(1);

        t = new Thread(this);
        t.start();
        mAdapter.notifyDataSetChanged();

        dbHandler.close();
    }

    public void sendMsg(View view) {
        dbHandler = new DBHandler(this);
        user = dbHandler.getUser(1);
        String msg = editMessage.getText().toString();
        chatMessages.add(user.getName() + ": " + msg);
        mAdapter.notifyDataSetChanged();

        client = new Client();
        client.execute(host, user.getName() + ": " + msg);

        

        editMessage.setText("");
        dbHandler.close();

    }

    public void readMsg(){
        dbHandler = new DBHandler(this);
       ArrayList<ChatMessage > msg;
        String m;
        msg = (ArrayList<ChatMessage>)dbHandler.getAllChatMessages(selectedContactNumber);
        for (int iter = 0; iter > msg.size() + 1 ; iter++) {
           ChatMessage selectedMsg =  msg.get(iter);
            m = selectedMsg.getMessage().toString();
            chatMessages.set(iter, m);
        }
{'fraction_non_alphanumeric': 0.08939605341837752, 'fraction_numerical': 0.004783735299980068, 'mean_word_length': 2.5111966410076976, 'pattern_counts': {'":': 4, '<': 9, '<?xml version=': 0, '>': 10, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 2, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '979988', 'n_tokens_mistral': 2551, 'n_tokens_neox': 2422, 'n_words': 569}