Skip to content

Commit

Permalink
dos clientes chatean con server mock en el medio
Browse files Browse the repository at this point in the history
  • Loading branch information
fernandocortes1990 committed May 4, 2015
1 parent 0a07432 commit b940fd4
Show file tree
Hide file tree
Showing 12 changed files with 32 additions and 129 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,16 @@
import com.example.fernando.myapplication.R;
import com.example.fernando.myapplication.Threads.SendMessagePostAsyncTask;

import java.util.Calendar;

/**
* Created by fernando on 10/04/15.
*/
public class ChatActivity extends ActionBarActivity implements View.OnClickListener {

public static RefreshChatAsyncTask refreshChat;
public static SendMessagePostAsyncTask sendMessage;
private Calendar calendar = Calendar.getInstance();

@Override
protected void onCreate(Bundle savedInstanceState) {
Expand Down Expand Up @@ -64,7 +67,7 @@ public void onClick(View v) {

while (Constants.sendMessageOk.compareTo("") == 0) {
try {
Thread.sleep(1000);
Thread.sleep(1);
} catch (InterruptedException e) {
e.printStackTrace();
}
Expand All @@ -77,8 +80,8 @@ public void onClick(View v) {
Message newMessage = new Message(
Constants.user.username,
message,
"date",
"hour");
calendar.getTime().toString(),
"");
Constants.chatEditor.getChat().messages.add(newMessage);
// Constants.chatEditor.renderNewMessage(newMessage);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,8 @@ public boolean onOptionsItemSelected(MenuItem item) {

Constants.logInOk = "";
Constants.currentChatsOk = "";
Constants.currentChatsSize = 0;
// Constants.currentChatsSize = 0;
Constants.chatListView = null;
Constants.chatsAdapter = null;
Constants.usersListView = null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,7 @@
import android.widget.Toast;

import com.example.fernando.myapplication.Common.Constants;
import com.example.fernando.myapplication.Common.User;
import com.example.fernando.myapplication.Threads.ConfigPostAsyncTask;
import com.example.fernando.myapplication.Threads.ServletPostAsyncTask;
import com.example.fernando.myapplication.R;

import java.io.File;
Expand Down Expand Up @@ -54,6 +52,8 @@ protected void onCreate(Bundle savedInstanceState) {
out.setOnClickListener(this);
online.setOnClickListener(this);

configPost = new ConfigPostAsyncTask();

// PARA AGARRAR LA FOTO DEL FILE SYSTEM !!
// loadFileList();
// onCreateDialog(1000);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
import android.widget.EditText;
import android.widget.Toast;
import com.example.fernando.myapplication.Common.Constants;
import com.example.fernando.myapplication.Threads.ServletPostAsyncTask;
import com.example.fernando.myapplication.Common.User;
import com.example.fernando.myapplication.R;
import com.example.fernando.myapplication.Threads.SignUpPostAsyncTask;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,6 @@ public String somethingForMe (String userPackage) {
JSONObject userP = Constants.packager.unwrap(userPackage);

try {

String username = userP.getString("username");

JSONObject response = new JSONObject();
Expand Down Expand Up @@ -181,6 +180,7 @@ public String currentChats (String userPackage) {
}

public String sendMessage (String userPackage) {
boolean founded = false;
JSONObject userP = Constants.packager.unwrap(userPackage);

try {
Expand All @@ -194,11 +194,16 @@ public String sendMessage (String userPackage) {
c.getTime().toString(), "" );

for (int user = 0; user < newMessages.size(); user++) {
if (newMessages.get(user).first.compareTo(username) == 0) {
if (newMessages.get(user).first.compareTo(msg_to) == 0) {
newMessages.get(user).second.add(newMessage);
founded = true;
break;
}
}
if (!founded) {
newMessages.add(new Pair<>(msg_to, new ArrayList<Message>()));
newMessages.get(newMessages.size()-1).second.add(newMessage);
}

JSONObject response = new JSONObject();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ protected void onProgressUpdate(String... values) {
if (values[0].compareTo("serverError") == 0)
Toast.makeText(context, "Could't connect with server", Toast.LENGTH_LONG).show();
else {
Toast.makeText(context, "new user thread", Toast.LENGTH_LONG).show();
// Toast.makeText(context, "new user thread", Toast.LENGTH_LONG).show();
ChatsHallActivity.usersPost = new GetUsersPostAsyncTask();
ChatsHallActivity.usersPost.execute(new Pair<>(context, values[1]),
new Pair<>(context, values[2]),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ protected String doInBackground(Pair<Context, Chat>... params) {
// Constants.messagesSize = chatToUpdate.messages.size();

try {
Thread.sleep(2000);
Thread.sleep(200);

if (chatToUpdate.messages.size() > Constants.messagesSize) {

Expand All @@ -70,7 +70,7 @@ protected void onProgressUpdate(String... values) {
super.onProgressUpdate(values);

if (values[0].compareTo("run again") == 0) {
Toast.makeText(context, "new refresh chat", Toast.LENGTH_LONG).show();
// Toast.makeText(context, "new refresh chat", Toast.LENGTH_LONG).show();
ChatActivity.refreshChat = new RefreshChatAsyncTask();
ChatActivity.refreshChat.execute(new Pair<>(context, chatToUpdate));
this.cancel(true);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,15 @@ protected String doInBackground(Pair<Context, String>... params) {
//Constants.currentChatsSize = Constants.user.chats.size();
context = params[0].first;
try {
Thread.sleep(5000);
Thread.sleep(200);

if (Constants.user.chats.size() > Constants.currentChatsSize) {

for (int chat = Constants.currentChatsSize;
chat < Constants.user.chats.size();
chat++) {

publishProgress(Constants.user.chats.get(chat).otherUser);
publishProgress("refresh", Constants.user.chats.get(chat).otherUser);
}
Constants.currentChatsSize = Constants.user.chats.size();
}
Expand All @@ -46,14 +46,14 @@ protected void onProgressUpdate(String... values) {
super.onProgressUpdate(values);

if (values[0].compareTo("run again") == 0) {
Toast.makeText(context, "new refresh", Toast.LENGTH_LONG).show();
// Toast.makeText(context, "new refresh", Toast.LENGTH_LONG).show();
ChatsHallActivity.refreshChats = new RefreshChatsHallAsyncTask();
ChatsHallActivity.refreshChats.execute(new Pair<>(context, values[1]),
new Pair<>(context, values[2]),
new Pair<>(context, values[3]));
this.cancel(true);
} else {
Constants.chatsAdapter.add(values[0]);
} else if (values[0].compareTo("refresh") == 0){
Constants.chatsAdapter.add(values[1]);
Constants.chatListView.setAdapter(Constants.chatsAdapter);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ protected String doInBackground(Pair<Context, String>... params) {
Constants.currentUsersSize = Constants.otherUsers.size();
context = params[0].first;
try {
Thread.sleep(2000);
Thread.sleep(200);

if (Constants.otherUsers.size() > Constants.currentUsersSize) {

Expand All @@ -49,7 +49,7 @@ protected void onProgressUpdate(String... values) {
super.onProgressUpdate(values);

if (values[0].compareTo("run again") == 0) {
Toast.makeText(context, "new refresh users", Toast.LENGTH_LONG).show();
// Toast.makeText(context, "new refresh users", Toast.LENGTH_LONG).show();
UsersActivity.refreshUsers = new RefreshUsersAsyncTask();
UsersActivity.refreshUsers.execute(new Pair<>(context, values[1]),
new Pair<>(context, values[2]),
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public class SomethingForMePostAsyncTask extends AsyncTask<Pair<Context, String>
protected String doInBackground(Pair<Context, String>... params) {

try {
Thread.sleep(2000);
Thread.sleep(200);
context = params[0].first;

if ( Constants.server != null ) {
Expand Down Expand Up @@ -131,12 +131,12 @@ protected void onProgressUpdate(String... values) {
if (values[0].compareTo("serverError") == 0)
Toast.makeText(context, "Could't connect with server", Toast.LENGTH_LONG).show();
else {
Toast.makeText(context, "new hilo", Toast.LENGTH_LONG).show();
// Toast.makeText(context, "new hilo", Toast.LENGTH_LONG).show();
ChatsHallActivity.somethingForMePost = new SomethingForMePostAsyncTask();
ChatsHallActivity.somethingForMePost.execute(new Pair<>(context, values[1]),
new Pair<>(context, values[2]),
new Pair<>(context, values[3]));
Toast.makeText(context, "new hilo ds", Toast.LENGTH_LONG).show();
// Toast.makeText(context, "new hilo ds", Toast.LENGTH_LONG).show();
this.cancel(true);
}
}
Expand Down
5 changes: 2 additions & 3 deletions src/client/mensajerO/app/src/main/res/layout/signup.xml
Original file line number Diff line number Diff line change
Expand Up @@ -45,16 +45,15 @@
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/b.back"
android:layout_marginTop="31dp"
android:layout_below="@+id/txtPassword"
android:layout_alignTop="@+id/button2"
android:layout_toRightOf="@+id/button2"
android:layout_toEndOf="@+id/button2" />
<Button
android:id="@+id/button2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/b.Confirm"
android:layout_alignTop="@+id/button1"
android:layout_below="@+id/txtPassword"
android:layout_centerHorizontal="true" />

</RelativeLayout>

0 comments on commit b940fd4

Please sign in to comment.