aboutsummaryrefslogtreecommitdiffstats
path: root/src/de/gultsch/chat/ui/ConversationActivity.java
diff options
context:
space:
mode:
authorDaniel Gultsch <daniel.gultsch@rwth-aachen.de>2014-01-25 19:33:12 +0100
committerDaniel Gultsch <daniel.gultsch@rwth-aachen.de>2014-01-25 19:33:12 +0100
commit665ef7511f5dcccb349228baa2aa6f02281d3c07 (patch)
tree461ffa268dc16b299c68e764a3ae55ad912075c4 /src/de/gultsch/chat/ui/ConversationActivity.java
parentdf9dcb1060d44a719e2892446b62cde884a880cf (diff)
all access to the persistance layer is now done via the new xmppservice
Diffstat (limited to '')
-rw-r--r--src/de/gultsch/chat/ui/ConversationActivity.java153
1 files changed, 77 insertions, 76 deletions
diff --git a/src/de/gultsch/chat/ui/ConversationActivity.java b/src/de/gultsch/chat/ui/ConversationActivity.java
index f26d8982..97b937c3 100644
--- a/src/de/gultsch/chat/ui/ConversationActivity.java
+++ b/src/de/gultsch/chat/ui/ConversationActivity.java
@@ -1,20 +1,15 @@
package de.gultsch.chat.ui;
-import java.util.HashMap;
+import java.util.ArrayList;
import java.util.List;
-import de.gultsch.chat.ConversationCursor;
-import de.gultsch.chat.ConversationList;
import de.gultsch.chat.R;
import de.gultsch.chat.R.id;
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 android.net.Uri;
import android.os.Bundle;
-import android.app.Activity;
-import android.app.FragmentManager;
import android.app.FragmentTransaction;
import android.content.Context;
import android.content.Intent;
@@ -35,59 +30,52 @@ import android.widget.ListView;
import android.widget.TextView;
import android.widget.ImageView;
-public class ConversationActivity extends Activity {
+public class ConversationActivity extends XmppActivity {
- public static final String START_CONVERSATION = "startconversation";
- public static final String CONVERSATION_CONTACT = "conversationcontact";
+ public static final String VIEW_CONVERSATION = "viewConversation";
+ private static final String LOGTAG = "secureconversation";
+ protected static final String CONVERSATION = "conversationUuid";
protected SlidingPaneLayout spl;
- protected HashMap<Conversation, ConversationFragment> conversationFragments = new HashMap<Conversation, ConversationFragment>();
- private DatabaseBackend dbb;
+ final List<Conversation> conversationList = new ArrayList<Conversation>();
@Override
protected void onCreate(Bundle savedInstanceState) {
-
- dbb = DatabaseBackend.getInstance(this);
-
- super.onCreate(savedInstanceState);
-
- final List<Conversation> conversationList = dbb.getConversations(Conversation.STATUS_AVAILABLE);
- if (getIntent().getAction().equals(Intent.ACTION_MAIN)) {
- if (conversationList.size() < 0) {
- Log.d("gultsch",
- "no conversations detected. redirect to new conversation activity");
- startActivity(new Intent(this, NewConversationActivity.class));
- finish();
- }
- }
+ super.onCreate(savedInstanceState);
setContentView(R.layout.fragment_conversations_overview);
final ListView listView = (ListView) findViewById(R.id.list);
-
- listView.setAdapter(new ArrayAdapter<Conversation>(this, R.layout.conversation_list_row, conversationList) {
+
+ listView.setAdapter(new ArrayAdapter<Conversation>(this,
+ R.layout.conversation_list_row, conversationList) {
@Override
- public View getView (int position, View view, ViewGroup parent) {
+ public View getView(int position, View view, ViewGroup parent) {
if (view == null) {
- LayoutInflater inflater = (LayoutInflater)getSystemService(Context.LAYOUT_INFLATER_SERVICE);
- view = (View) inflater.inflate(R.layout.conversation_list_row,null);
- ((TextView) view.findViewById(R.id.conversation_name)).setText(getItem(position).getName());
- ((ImageView) view.findViewById(R.id.conversation_image)).setImageURI(getItem(position).getProfilePhotoUri());
+ LayoutInflater inflater = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE);
+ view = (View) inflater.inflate(
+ R.layout.conversation_list_row, null);
}
+ ((TextView) view.findViewById(R.id.conversation_name))
+ .setText(getItem(position).getName());
+ ((ImageView) view.findViewById(R.id.conversation_image))
+ .setImageURI(getItem(position).getProfilePhotoUri());
return view;
}
-
+
});
-
+
listView.setOnItemClickListener(new OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> arg0, View clickedView,
int position, long arg3) {
+ Log.d(LOGTAG, "List view was klicked on position " + position);
swapConversationFragment(conversationList.get(position));
- getActionBar().setTitle(conversationList.get(position).getName());
+ getActionBar().setTitle(
+ conversationList.get(position).getName());
spl.closePane();
}
});
@@ -121,8 +109,14 @@ public class ConversationActivity extends Activity {
public void onPanelClosed(View arg0) {
if (conversationList.size() > 0) {
getActionBar().setDisplayHomeAsUpEnabled(true);
- ConversationFragment convFrag = (ConversationFragment) getFragmentManager().findFragmentById(R.id.selected_conversation);
- getActionBar().setTitle(convFrag.getConversation().getName());
+ ConversationFragment convFrag = (ConversationFragment) getFragmentManager()
+ .findFragmentById(R.id.selected_conversation);
+ if (convFrag == null) {
+ Log.d(LOGTAG, "conversation fragment was not found.");
+ return; // just do nothing. at least dont crash
+ }
+ getActionBar().setTitle(
+ convFrag.getConversation().getName());
invalidateOptionsMenu();
}
}
@@ -133,36 +127,6 @@ public class ConversationActivity extends Activity {
}
});
-
- if (getIntent().getAction().equals(Intent.ACTION_VIEW)) {
- if (getIntent().getType().equals(
- ConversationActivity.START_CONVERSATION)) {
- Contact contact = (Contact) getIntent().getExtras().get(
- ConversationActivity.CONVERSATION_CONTACT);
- Log.d("gultsch",
- "start conversation with " + contact.getDisplayName());
-
- // start new conversation
- Conversation conversation = new Conversation(
- contact.getDisplayName(), contact.getProfilePhoto(),
- new Account(), contact.getJid());
-
- //@TODO don't write to database here; always go through service
- dbb.addConversation(conversation);
- conversationList.add(0, conversation);
- swapConversationFragment(conversationList.get(0));
- spl.closePane();
-
- // why do i even need this
- getActionBar().setDisplayHomeAsUpEnabled(true);
- getActionBar().setTitle(conversationList.get(0).getName());
- }
- } else {
- // normal startup
- if (conversationList.size() >= 1) {
- swapConversationFragment(conversationList.get(0));
- }
- }
}
@Override
@@ -195,7 +159,8 @@ public class ConversationActivity extends Activity {
case R.id.action_add:
startActivity(new Intent(this, NewConversationActivity.class));
case R.id.action_archive:
-
+
+ break;
default:
break;
}
@@ -203,14 +168,9 @@ public class ConversationActivity extends Activity {
}
protected void swapConversationFragment(Conversation conv) {
- ConversationFragment selectedFragment;
- if (conversationFragments.containsKey(conv)) {
- selectedFragment = conversationFragments.get(conv);
- } else {
- selectedFragment = new ConversationFragment();
- selectedFragment.setConversation(conv);
- conversationFragments.put(conv,selectedFragment);
- }
+ Log.d(LOGTAG, "swap conversation fragment to " + conv.getName());
+ ConversationFragment selectedFragment = new ConversationFragment();
+ selectedFragment.setConversation(conv);
FragmentTransaction transaction = getFragmentManager()
.beginTransaction();
transaction.replace(R.id.selected_conversation, selectedFragment);
@@ -228,4 +188,45 @@ public class ConversationActivity extends Activity {
return super.onKeyDown(keyCode, event);
}
+ @Override
+ public void onStart() {
+ super.onStart();
+ if (xmppConnectionServiceBound) {
+ conversationList.clear();
+ conversationList.addAll(xmppConnectionService
+ .getConversations(Conversation.STATUS_AVAILABLE));
+ }
+ }
+
+ @Override
+ void servConnected() {
+ conversationList.clear();
+ conversationList.addAll(xmppConnectionService
+ .getConversations(Conversation.STATUS_AVAILABLE));
+
+ //spl.openPane();
+
+ if ((getIntent().getAction().equals(Intent.ACTION_VIEW) && (!handledViewIntent))) {
+ if (getIntent().getType().equals(
+ ConversationActivity.VIEW_CONVERSATION)) {
+ handledViewIntent = true;
+
+ swapConversationFragment(conversationList.get(0));
+ spl.closePane();
+
+ // why do i even need this
+ getActionBar().setDisplayHomeAsUpEnabled(true);
+ getActionBar().setTitle(conversationList.get(0).getName());
+
+ }
+ } else {
+ if (conversationList.size() <= 0) {
+ //add no history
+ startActivity(new Intent(this, NewConversationActivity.class));
+ finish();
+ } else {
+ swapConversationFragment(conversationList.get(0));
+ }
+ }
+ }
}