aboutsummaryrefslogtreecommitdiffstats
path: root/src/de/gultsch/chat/ui
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--src/de/gultsch/chat/ui/ConversationActivity.java16
-rw-r--r--src/de/gultsch/chat/ui/ConversationFragment.java34
-rw-r--r--src/de/gultsch/chat/ui/ManageAccountActivity.java4
-rw-r--r--src/de/gultsch/chat/ui/NewConversationActivity.java130
4 files changed, 74 insertions, 110 deletions
diff --git a/src/de/gultsch/chat/ui/ConversationActivity.java b/src/de/gultsch/chat/ui/ConversationActivity.java
index ca9bedf7..d9c497f8 100644
--- a/src/de/gultsch/chat/ui/ConversationActivity.java
+++ b/src/de/gultsch/chat/ui/ConversationActivity.java
@@ -283,17 +283,28 @@ public class ConversationActivity extends XmppActivity {
super.onStart();
NotificationManager nm = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
nm.cancelAll();
+ if (conversationList.size()>=1) {
+ onConvChanged.onConversationListChanged();
+ }
}
- @Override
+ /*@Override
protected void onPause() {
super.onPause();
if (xmppConnectionServiceBound) {
- Log.d("xmppService","called on stop. remove listener");
xmppConnectionService.removeOnConversationListChangedListener();
unbindService(mConnection);
xmppConnectionServiceBound = false;
}
+ }*/
+
+ @Override
+ protected void onStop() {
+ Log.d("gultsch","called on stop in conversation activity");
+ if (xmppConnectionServiceBound) {
+ xmppConnectionService.removeOnConversationListChangedListener();
+ }
+ super.onStop();
}
@Override
@@ -302,7 +313,6 @@ public class ConversationActivity extends XmppActivity {
xmppConnectionService.setOnConversationListChangedListener(this.onConvChanged);
if (conversationList.size()==0) {
- Log.d("gultsch","conversation list is empty fetch new");
conversationList.clear();
conversationList.addAll(xmppConnectionService
.getConversations());
diff --git a/src/de/gultsch/chat/ui/ConversationFragment.java b/src/de/gultsch/chat/ui/ConversationFragment.java
index 1b8edbb5..f2726945 100644
--- a/src/de/gultsch/chat/ui/ConversationFragment.java
+++ b/src/de/gultsch/chat/ui/ConversationFragment.java
@@ -115,11 +115,19 @@ public class ConversationFragment extends Fragment {
}
ImageView imageView = (ImageView) view.findViewById(R.id.message_photo);
if (type == RECIEVED) {
- Uri uri = item.getConversation().getProfilePhotoUri();
- if (uri!=null) {
- imageView.setImageURI(uri);
- } else {
- imageView.setImageBitmap(UIHelper.getUnknownContactPicture(item.getConversation().getName(), 200));
+ if(item.getConversation().getMode()==Conversation.MODE_SINGLE) {
+ Uri uri = item.getConversation().getProfilePhotoUri();
+ if (uri!=null) {
+ imageView.setImageURI(uri);
+ } else {
+ imageView.setImageBitmap(UIHelper.getUnknownContactPicture(item.getConversation().getName(), 200));
+ }
+ } else if (item.getConversation().getMode()==Conversation.MODE_MULTI) {
+ if (item.getCounterpart()!=null) {
+ imageView.setImageBitmap(UIHelper.getUnknownContactPicture(item.getCounterpart(), 200));
+ } else {
+ imageView.setImageBitmap(UIHelper.getUnknownContactPicture(item.getConversation().getName(), 200));
+ }
}
} else {
imageView.setImageURI(profilePicture);
@@ -152,12 +160,9 @@ public class ConversationFragment extends Fragment {
final ConversationActivity activity = (ConversationActivity) getActivity();
- // TODO check if bond and get data back
-
if (activity.xmppConnectionServiceBound) {
this.conversation = activity.getConversationList().get(activity.getSelectedConversation());
- this.messageList.clear();
- this.messageList.addAll(this.conversation.getMessages());
+ updateMessages();
// rendering complete. now go tell activity to close pane
if (!activity.shouldPaneBeOpen()) {
activity.getSlidingPaneLayout().closePane();
@@ -165,18 +170,14 @@ public class ConversationFragment extends Fragment {
activity.getActionBar().setTitle(conversation.getName());
activity.invalidateOptionsMenu();
}
-
- int size = this.messageList.size();
- if (size >= 1)
- messagesView.setSelection(size - 1);
}
}
public void onBackendConnected() {
+ Log.d("gultsch","calling on backend connected in conversation fragment");
final ConversationActivity activity = (ConversationActivity) getActivity();
this.conversation = activity.getConversationList().get(activity.getSelectedConversation());
- this.messageList.clear();
- this.messageList.addAll(this.conversation.getMessages());
+ updateMessages();
// rendering complete. now go tell activity to close pane
if (!activity.shouldPaneBeOpen()) {
activity.getSlidingPaneLayout().closePane();
@@ -190,5 +191,8 @@ public class ConversationFragment extends Fragment {
this.messageList.clear();
this.messageList.addAll(this.conversation.getMessages());
this.messageListAdapter.notifyDataSetChanged();
+ int size = this.messageList.size();
+ if (size >= 1)
+ messagesView.setSelection(size - 1);
}
}
diff --git a/src/de/gultsch/chat/ui/ManageAccountActivity.java b/src/de/gultsch/chat/ui/ManageAccountActivity.java
index 2f0bb1a0..66a40782 100644
--- a/src/de/gultsch/chat/ui/ManageAccountActivity.java
+++ b/src/de/gultsch/chat/ui/ManageAccountActivity.java
@@ -152,12 +152,10 @@ public class ManageAccountActivity extends XmppActivity implements ActionMode.Ca
@Override
protected void onStop() {
- super.onStop();
if (xmppConnectionServiceBound) {
xmppConnectionService.removeOnAccountListChangedListener();
- unbindService(mConnection);
- xmppConnectionServiceBound = false;
}
+ super.onStop();
}
@Override
diff --git a/src/de/gultsch/chat/ui/NewConversationActivity.java b/src/de/gultsch/chat/ui/NewConversationActivity.java
index 3bfb4e2a..cbd68def 100644
--- a/src/de/gultsch/chat/ui/NewConversationActivity.java
+++ b/src/de/gultsch/chat/ui/NewConversationActivity.java
@@ -57,10 +57,6 @@ public class NewConversationActivity extends XmppActivity {
protected void updateAggregatedContacts() {
aggregatedContacts.clear();
- for (Contact contact : phoneContacts) {
- if (contact.match(searchString))
- aggregatedContacts.add(contact);
- }
for (Contact contact : rosterContacts) {
if (contact.match(searchString))
aggregatedContacts.add(contact);
@@ -71,7 +67,8 @@ public class NewConversationActivity extends XmppActivity {
@SuppressLint("DefaultLocale")
@Override
public int compare(Contact lhs, Contact rhs) {
- return lhs.getDisplayName().toLowerCase().compareTo(rhs.getDisplayName().toLowerCase());
+ return lhs.getDisplayName().toLowerCase()
+ .compareTo(rhs.getDisplayName().toLowerCase());
}
});
@@ -79,7 +76,7 @@ public class NewConversationActivity extends XmppActivity {
if (Validator.isValidJid(searchString)) {
String name = searchString.split("@")[0];
- Contact newContact = new Contact(null,name, searchString,null);
+ Contact newContact = new Contact(null, name, searchString, null);
aggregatedContacts.add(newContact);
contactsHeader.setText("Create new contact");
} else {
@@ -93,19 +90,6 @@ public class NewConversationActivity extends XmppActivity {
contactsView.setScrollX(0);
}
- static final String[] PROJECTION = new String[] {
- ContactsContract.Data.CONTACT_ID,
- ContactsContract.Data.DISPLAY_NAME,
- ContactsContract.Data.PHOTO_THUMBNAIL_URI,
- ContactsContract.CommonDataKinds.Im.DATA };
-
- // This is the select criteria
- static final String SELECTION = "(" + ContactsContract.Data.MIMETYPE
- + "=\"" + ContactsContract.CommonDataKinds.Im.CONTENT_ITEM_TYPE
- + "\") AND (" + ContactsContract.CommonDataKinds.Im.PROTOCOL
- + "=\"" + ContactsContract.CommonDataKinds.Im.PROTOCOL_JABBER
- + "\")";
-
@Override
protected void onCreate(Bundle savedInstanceState) {
@@ -154,11 +138,13 @@ public class NewConversationActivity extends XmppActivity {
((TextView) view.findViewById(R.id.contact_jid))
.setText(getItem(position).getJid());
String profilePhoto = getItem(position).getProfilePhoto();
- ImageView imageView = (ImageView) view.findViewById(R.id.contact_photo);
- if (profilePhoto!=null) {
+ ImageView imageView = (ImageView) view
+ .findViewById(R.id.contact_photo);
+ if (profilePhoto != null) {
imageView.setImageURI(Uri.parse(profilePhoto));
} else {
- imageView.setImageBitmap(UIHelper.getUnknownContactPicture(getItem(position).getDisplayName(),90));
+ imageView.setImageBitmap(UIHelper.getUnknownContactPicture(
+ getItem(position).getDisplayName(), 90));
}
return view;
}
@@ -168,25 +154,27 @@ public class NewConversationActivity extends XmppActivity {
contactsView.setOnItemClickListener(new OnItemClickListener() {
@Override
- public void onItemClick(AdapterView<?> arg0, final View view, int pos,
- long arg3) {
+ public void onItemClick(AdapterView<?> arg0, final View view,
+ int pos, long arg3) {
final Contact clickedContact = aggregatedContacts.get(pos);
Log.d("gultsch",
"clicked on " + clickedContact.getDisplayName());
-
- final List<Account> accounts = xmppConnectionService.getAccounts();
+
+ final List<Account> accounts = xmppConnectionService
+ .getAccounts();
if (accounts.size() == 1) {
startConversation(clickedContact, accounts.get(0));
} else {
String[] accountList = new String[accounts.size()];
- for(int i = 0; i < accounts.size(); ++i) {
+ for (int i = 0; i < accounts.size(); ++i) {
accountList[i] = accounts.get(i).getJid();
}
-
- AlertDialog.Builder builder = new AlertDialog.Builder(activity);
+
+ AlertDialog.Builder builder = new AlertDialog.Builder(
+ activity);
builder.setTitle("Choose account");
- builder.setItems(accountList,new OnClickListener() {
-
+ builder.setItems(accountList, new OnClickListener() {
+
@Override
public void onClick(DialogInterface dialog, int which) {
Account account = accounts.get(which);
@@ -198,57 +186,23 @@ public class NewConversationActivity extends XmppActivity {
}
});
}
-
+
public void startConversation(Contact contact, Account account) {
Conversation conversation = xmppConnectionService
.findOrCreateConversation(account, contact);
- Intent viewConversationIntent = new Intent(this,ConversationActivity.class);
+ Intent viewConversationIntent = new Intent(this,
+ ConversationActivity.class);
viewConversationIntent.setAction(Intent.ACTION_VIEW);
- viewConversationIntent.putExtra(
- ConversationActivity.CONVERSATION,
+ viewConversationIntent.putExtra(ConversationActivity.CONVERSATION,
conversation.getUuid());
- viewConversationIntent
- .setType(ConversationActivity.VIEW_CONVERSATION);
- viewConversationIntent.setFlags(viewConversationIntent
- .getFlags() | Intent.FLAG_ACTIVITY_CLEAR_TOP);
+ viewConversationIntent.setType(ConversationActivity.VIEW_CONVERSATION);
+ viewConversationIntent.setFlags(viewConversationIntent.getFlags()
+ | Intent.FLAG_ACTIVITY_CLEAR_TOP);
startActivity(viewConversationIntent);
}
@Override
- public void onStart() {
- super.onStart();
-
- CursorLoader mCursorLoader = new CursorLoader(this,
- ContactsContract.Data.CONTENT_URI, PROJECTION, SELECTION, null,
- null);
- mCursorLoader.registerListener(0, new OnLoadCompleteListener<Cursor>() {
-
- @Override
- public void onLoadComplete(Loader<Cursor> arg0, Cursor cursor) {
- phoneContacts.clear();
- while (cursor.moveToNext()) {
- String profilePhoto = cursor.getString(cursor
- .getColumnIndex(ContactsContract.Data.PHOTO_THUMBNAIL_URI));
- /*if (profilePhoto == null) {
- profilePhoto = DEFAULT_PROFILE_PHOTO;
- }*/
- Contact contact = new Contact(null,
- cursor.getString(cursor
- .getColumnIndex(ContactsContract.Data.DISPLAY_NAME)),
- cursor.getString(cursor
- .getColumnIndex(ContactsContract.CommonDataKinds.Im.DATA)),
- profilePhoto);
- phoneContacts.add(contact);
- }
- updateAggregatedContacts();
- }
- });
- mCursorLoader.startLoading();
-
- }
-
- @Override
void onBackendConnected() {
if (xmppConnectionService.getConversationCount() == 0) {
getActionBar().setDisplayHomeAsUpEnabled(false);
@@ -256,23 +210,21 @@ public class NewConversationActivity extends XmppActivity {
}
this.accounts = xmppConnectionService.getAccounts();
this.rosterContacts.clear();
- for(Account account : this.accounts) {
- xmppConnectionService.getRoster(account, new OnRosterFetchedListener() {
-
- @Override
- public void onRosterFetched(List<Contact> roster) {
- rosterContacts.addAll(roster);
- runOnUiThread(new Runnable() {
-
- @Override
- public void run() {
- updateAggregatedContacts();
- }
- });
-
- }
- });
- }
+ xmppConnectionService.getRoster(new OnRosterFetchedListener() {
+
+ @Override
+ public void onRosterFetched(List<Contact> roster) {
+ rosterContacts.addAll(roster);
+ runOnUiThread(new Runnable() {
+
+ @Override
+ public void run() {
+ updateAggregatedContacts();
+ }
+ });
+
+ }
+ });
}
@Override