aboutsummaryrefslogtreecommitdiffstats
path: root/src/de/gultsch/chat/ui
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
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
-rw-r--r--src/de/gultsch/chat/ui/NewConversationActivity.java56
-rw-r--r--src/de/gultsch/chat/ui/XmppActivity.java51
3 files changed, 176 insertions, 84 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));
+ }
+ }
+ }
}
diff --git a/src/de/gultsch/chat/ui/NewConversationActivity.java b/src/de/gultsch/chat/ui/NewConversationActivity.java
index 9dc385a4..917b4c62 100644
--- a/src/de/gultsch/chat/ui/NewConversationActivity.java
+++ b/src/de/gultsch/chat/ui/NewConversationActivity.java
@@ -6,7 +6,9 @@ import java.util.regex.Matcher;
import java.util.regex.Pattern;
import de.gultsch.chat.R;
+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.os.Bundle;
import android.provider.ContactsContract;
@@ -14,12 +16,13 @@ import android.text.Editable;
import android.text.TextWatcher;
import android.util.Log;
import android.view.LayoutInflater;
+import android.view.Menu;
+import android.view.MenuItem;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.LinearLayout;
import android.widget.TextView;
import android.widget.ImageView;
-import android.app.Activity;
import android.content.Context;
import android.content.CursorLoader;
import android.content.Intent;
@@ -27,7 +30,7 @@ import android.content.Loader;
import android.content.Loader.OnLoadCompleteListener;
import android.database.Cursor;
-public class NewConversationActivity extends Activity {
+public class NewConversationActivity extends XmppActivity {
final protected LinkedHashMap<Contact, View> availablePhoneContacts = new LinkedHashMap<Contact, View>();
final protected LinkedHashMap<Contact, View> availableJabberContacts = new LinkedHashMap<Contact, View>();
@@ -78,12 +81,20 @@ public class NewConversationActivity extends Activity {
clickedContact = newContact;
}
Log.d("gultsch","clicked on "+clickedContact.getDisplayName());
- Intent startConversationIntent = new Intent(v.getContext(),ConversationActivity.class);
- startConversationIntent.setAction(Intent.ACTION_VIEW);
- startConversationIntent.putExtra(ConversationActivity.CONVERSATION_CONTACT, clickedContact);
- startConversationIntent.setType(ConversationActivity.START_CONVERSATION);
- startConversationIntent.setFlags(startConversationIntent.getFlags() | Intent.FLAG_ACTIVITY_CLEAR_TOP);
- startActivity(startConversationIntent);
+
+
+ Account account = new Account();
+
+ Conversation conversation = new Conversation(clickedContact.getDisplayName(), clickedContact.getProfilePhoto(), account, clickedContact.getJid());
+
+ xmppConnectionService.addConversation(conversation);
+
+ Intent viewConversationIntent = new Intent(v.getContext(),ConversationActivity.class);
+ viewConversationIntent.setAction(Intent.ACTION_VIEW);
+ viewConversationIntent.putExtra(ConversationActivity.CONVERSATION, conversation.getUuid());
+ viewConversationIntent.setType(ConversationActivity.VIEW_CONVERSATION);
+ viewConversationIntent.setFlags(viewConversationIntent.getFlags() | Intent.FLAG_ACTIVITY_CLEAR_TOP);
+ startActivity(viewConversationIntent);
}
});
return view;
@@ -205,4 +216,33 @@ public class NewConversationActivity extends Activity {
lastContact.findViewById(R.id.contact_divider).setVisibility(View.GONE);
}
}
+
+ @Override
+ void servConnected() {
+ // TODO Auto-generated method stub
+
+ }
+
+ @Override
+ public boolean onCreateOptionsMenu(Menu menu) {
+ // Inflate the menu; this adds items to the action bar if it is present.
+ getMenuInflater().inflate(R.menu.newconversation, menu);
+ return true;
+ }
+
+ @Override
+ public boolean onOptionsItemSelected(MenuItem item) {
+ switch (item.getItemId()) {
+ case R.id.action_settings:
+ startActivity(new Intent(this, SettingsActivity.class));
+ break;
+ case R.id.action_accounts:
+ startActivity(new Intent(this, ManageAccountActivity.class));
+ break;
+ default:
+ break;
+ }
+ return super.onOptionsItemSelected(item);
+ }
+
}
diff --git a/src/de/gultsch/chat/ui/XmppActivity.java b/src/de/gultsch/chat/ui/XmppActivity.java
new file mode 100644
index 00000000..99173041
--- /dev/null
+++ b/src/de/gultsch/chat/ui/XmppActivity.java
@@ -0,0 +1,51 @@
+package de.gultsch.chat.ui;
+
+import de.gultsch.chat.services.XmppConnectionService;
+import de.gultsch.chat.services.XmppConnectionService.XmppConnectionBinder;
+import android.app.Activity;
+import android.content.ComponentName;
+import android.content.Context;
+import android.content.Intent;
+import android.content.ServiceConnection;
+import android.os.IBinder;
+
+public abstract class XmppActivity extends Activity {
+ protected XmppConnectionService xmppConnectionService;
+ protected boolean xmppConnectionServiceBound = false;
+ protected boolean handledViewIntent = false;
+ protected ServiceConnection mConnection = new ServiceConnection() {
+
+ @Override
+ public void onServiceConnected(ComponentName className, IBinder service) {
+ XmppConnectionBinder binder = (XmppConnectionBinder) service;
+ xmppConnectionService = binder.getService();
+ xmppConnectionServiceBound = true;
+ servConnected();
+ }
+
+ @Override
+ public void onServiceDisconnected(ComponentName arg0) {
+ xmppConnectionServiceBound = false;
+ }
+ };
+
+ @Override
+ protected void onStart() {
+ super.onStart();
+ if (!xmppConnectionServiceBound) {
+ Intent intent = new Intent(this, XmppConnectionService.class);
+ bindService(intent, mConnection, Context.BIND_AUTO_CREATE);
+ }
+ }
+
+ @Override
+ protected void onStop() {
+ super.onStop();
+ if (xmppConnectionServiceBound) {
+ unbindService(mConnection);
+ xmppConnectionServiceBound = false;
+ }
+ }
+
+ abstract void servConnected();
+}