From 898b0ca8c485888e06e2b5b1c798eebce1a6dabc Mon Sep 17 00:00:00 2001 From: Daniel Gultsch Date: Sun, 26 Jan 2014 03:27:55 +0100 Subject: chat bubbles. yeah --- src/de/gultsch/chat/ui/ConversationActivity.java | 3 + src/de/gultsch/chat/ui/ConversationFragment.java | 96 ++++++++++++++++++++++-- src/de/gultsch/chat/ui/XmppActivity.java | 4 +- 3 files changed, 95 insertions(+), 8 deletions(-) (limited to 'src/de/gultsch/chat/ui') diff --git a/src/de/gultsch/chat/ui/ConversationActivity.java b/src/de/gultsch/chat/ui/ConversationActivity.java index 97b937c3..4f76e9c1 100644 --- a/src/de/gultsch/chat/ui/ConversationActivity.java +++ b/src/de/gultsch/chat/ui/ConversationActivity.java @@ -9,6 +9,7 @@ import de.gultsch.chat.entities.Account; import de.gultsch.chat.entities.Contact; import de.gultsch.chat.entities.Conversation; import de.gultsch.chat.persistance.DatabaseBackend; +import de.gultsch.chat.utils.Beautifier; import android.os.Bundle; import android.app.FragmentTransaction; import android.content.Context; @@ -60,6 +61,8 @@ public class ConversationActivity extends XmppActivity { } ((TextView) view.findViewById(R.id.conversation_name)) .setText(getItem(position).getName()); + ((TextView) view.findViewById(R.id.conversation_lastupdate)) + .setText(Beautifier.readableTimeDifference(getItem(position).getCreated())); ((ImageView) view.findViewById(R.id.conversation_image)) .setImageURI(getItem(position).getProfilePhotoUri()); return view; diff --git a/src/de/gultsch/chat/ui/ConversationFragment.java b/src/de/gultsch/chat/ui/ConversationFragment.java index 70ceb07c..fca5202a 100644 --- a/src/de/gultsch/chat/ui/ConversationFragment.java +++ b/src/de/gultsch/chat/ui/ConversationFragment.java @@ -2,24 +2,108 @@ package de.gultsch.chat.ui; import de.gultsch.chat.R; import de.gultsch.chat.entities.Conversation; +import de.gultsch.chat.entities.Message; +import de.gultsch.chat.utils.Beautifier; import android.app.Fragment; +import android.content.Context; +import android.database.Cursor; +import android.graphics.Typeface; +import android.net.Uri; import android.os.Bundle; +import android.provider.ContactsContract.Profile; +import android.util.Log; import android.view.LayoutInflater; import android.view.View; +import android.view.View.OnClickListener; import android.view.ViewGroup; +import android.widget.ArrayAdapter; +import android.widget.EditText; +import android.widget.ListAdapter; +import android.widget.ListView; +import android.widget.ImageButton; +import android.widget.ImageView; +import android.widget.TextView; public class ConversationFragment extends Fragment { - + Conversation conversation; - + public void setConversation(Conversation conv) { this.conversation = conv; } - + @Override - public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { - return inflater.inflate(R.layout.fragment_conversation, container, false); - } + public View onCreateView(final LayoutInflater inflater, ViewGroup container, + Bundle savedInstanceState) { + + String[] mProjection = new String[] + { + Profile._ID, + Profile.PHOTO_THUMBNAIL_URI + }; + Cursor mProfileCursor = getActivity().getContentResolver().query( + Profile.CONTENT_URI, + mProjection , + null, + null, + null); + + mProfileCursor.moveToFirst(); + final Uri profilePicture = Uri.parse(mProfileCursor.getString(1)); + + Log.d("gultsch","found user profile pic "+profilePicture.toString()); + + final View view = inflater.inflate(R.layout.fragment_conversation, container, + false); + ((ImageButton) view.findViewById(R.id.textSendButton)) + .setOnClickListener(new OnClickListener() { + + @Override + public void onClick(View v) { + EditText chatMsg = (EditText) view.findViewById(R.id.textinput); + if (chatMsg.getText().length() < 1) return; + Message message = new Message(conversation,chatMsg.getText().toString(), + Message.ENCRYPTION_NONE); + XmppActivity activity = (XmppActivity) getActivity(); + activity.xmppConnectionService.sendMessage(message); + conversation.getMessages().add(message); + chatMsg.setText(""); + + ListView messagesView = (ListView) view.findViewById(R.id.messages_view); + ArrayAdapter adapter = (ArrayAdapter) messagesView.getAdapter(); + adapter.notifyDataSetChanged(); + + messagesView.setSelection(conversation.getMessages().size() -1); + } + }); + + ListView messagesView = (ListView) view + .findViewById(R.id.messages_view); + messagesView.setAdapter(new ArrayAdapter(this.getActivity() + .getApplicationContext(), R.layout.message_sent, + this.conversation.getMessages()) { + + @Override + public View getView(int position, View view, ViewGroup parent) { + Message item = getItem(position); + if ((item.getStatus() != Message.STATUS_RECIEVED) + || (item.getStatus() == Message.STATUS_SEND)) { + view = (View) inflater.inflate(R.layout.message_sent, null); + ((ImageView) view.findViewById(R.id.message_photo)).setImageURI(profilePicture); + } + ((TextView) view.findViewById(R.id.message_body)).setText(item.getBody()); + TextView time = (TextView) view.findViewById(R.id.message_time); + if (item.getStatus() == Message.STATUS_UNSEND) { + time.setTypeface(null, Typeface.ITALIC); + } else { + time.setText(Beautifier.readableTimeDifference(item.getTimeSent())); + } + return view; + } + }); + + return view; + } public Conversation getConversation() { return conversation; diff --git a/src/de/gultsch/chat/ui/XmppActivity.java b/src/de/gultsch/chat/ui/XmppActivity.java index 99173041..c15482ac 100644 --- a/src/de/gultsch/chat/ui/XmppActivity.java +++ b/src/de/gultsch/chat/ui/XmppActivity.java @@ -10,8 +10,8 @@ import android.content.ServiceConnection; import android.os.IBinder; public abstract class XmppActivity extends Activity { - protected XmppConnectionService xmppConnectionService; - protected boolean xmppConnectionServiceBound = false; + public XmppConnectionService xmppConnectionService; + public boolean xmppConnectionServiceBound = false; protected boolean handledViewIntent = false; protected ServiceConnection mConnection = new ServiceConnection() { -- cgit v1.2.3