Some modifications
author"Vincent Veronis"
Sun, 15 May 2011 18:51:00 +0200
changeset 891 37e794524cac
parent 890 7a2978972b49
child 892 b9e58686cae3
Some modifications
AndroidManifest.xml
src/com/beem/project/beem/BeemService.java
src/com/beem/project/beem/account/SyncAdapter.java
src/com/beem/project/beem/account/SyncAdapterService.java
src/com/beem/project/beem/service/ChatAdapter.java
src/com/beem/project/beem/ui/Chat.java
src/com/beem/project/beem/ui/ContactList.java
--- a/AndroidManifest.xml	Sun May 15 18:50:01 2011 +0200
+++ b/AndroidManifest.xml	Sun May 15 18:51:00 2011 +0200
@@ -158,8 +158,12 @@
 			android:name=".providers.AvatarProvider"
 			android:label="Avatar Provider"
 			android:authorities="com.beem.project.beem.providers.avatarprovider"
-			android:syncable="true"
-			android:exported="true" />
+			android:exported="false"  />
+		<provider
+			android:name=".providers.MessageProvider"
+			android:label="Message Provider"
+			android:authorities="com.beem.project.beem.providers.messageprovider"
+			android:exported="false"  />
 		<service
 			android:name=".account.AuthenticatorService"
 			android:exported="true"
--- a/src/com/beem/project/beem/BeemService.java	Sun May 15 18:50:01 2011 +0200
+++ b/src/com/beem/project/beem/BeemService.java	Sun May 15 18:51:00 2011 +0200
@@ -176,7 +176,6 @@
 	configure(ProviderManager.getInstance());
 	mNotificationManager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
 	Roster.setDefaultSubscriptionMode(SubscriptionMode.manual);
-
 	Log.d(TAG, "ONCREATE");
     }
 
--- a/src/com/beem/project/beem/account/SyncAdapter.java	Sun May 15 18:50:01 2011 +0200
+++ b/src/com/beem/project/beem/account/SyncAdapter.java	Sun May 15 18:51:00 2011 +0200
@@ -86,4 +86,10 @@
 
     }
 
+    @Override
+    public void onSyncCanceled() {
+	super.onSyncCanceled();
+	Log.e(TAG, "SYNCCANCELED");
+    }
+
 }
--- a/src/com/beem/project/beem/account/SyncAdapterService.java	Sun May 15 18:50:01 2011 +0200
+++ b/src/com/beem/project/beem/account/SyncAdapterService.java	Sun May 15 18:51:00 2011 +0200
@@ -73,6 +73,7 @@
 import android.util.Log;
 
 import com.beem.project.beem.BeemConnection;
+import com.beem.project.beem.BeemService;
 import com.beem.project.beem.R;
 import com.beem.project.beem.utils.Status;
 
@@ -139,25 +140,25 @@
 	Log.i(TAG, "performSync: " + account.toString());
 
 	//TODO: Get BeemService connectino support
+	//TODO: Get resource information
 	BeemConnection beemco = new BeemConnection(mContext.getSharedPreferences(account.name, MODE_PRIVATE), null);
+	//if (!BeemService.getIsLaunch())
 	//beemco.setNoPresence();
 	XMPPConnection con = new XMPPConnection(beemco.getConnectionConfiguration());
 	Roster roster = null;
 	try {
 	    con.connect();
-	    //TODO: BEEM_SYNC_ADAPTER -> GetSharedPreferences()
-	    con.login(beemco.getLogin(), beemco.getPassword(), "BEEM_SYNC_ADAPTER");
+	    //SharedPreferences sp = context.getSharedPreferences(account.name, MODE_PRIVATE);	    
+	    con.login(beemco.getLogin(), beemco.getPassword(), "beem sync adapter");
 	    roster = con.getRoster();
 	} catch (XMPPException e) {
 	    Log.e(TAG, "Error while connecting with syncAdapter", e);
 	} catch (IllegalStateException e) {
 	    Log.e(TAG, "Not connected to server", e);
 	}
-	if (roster != null) {
+	if (roster != null)
 	    manageRoster(roster, account);
-	}
-	//TODO: Dont disco ?!
-	//con.disconnect();
+	con.disconnect();
     }
 
     /**
@@ -213,7 +214,7 @@
 	    values.clear();
 	    ContentProviderOperation.Builder builder = addUpdateStructuredName(entry, rawContactID, true);
 	    ops.add(builder.build());
-	    builder = addUpdateIm(entry, rawContactID, account, true);
+	    builder = createProfile(entry, rawContactID, account);
 	    ops.add(builder.build());
 	} else { // Found, update
 	    ContentProviderOperation.Builder builder = addUpdateStructuredName(entry, rawContactID, false);
@@ -259,21 +260,16 @@
      * @param isInsert Insert boolean
      * @return
      */
-    private static ContentProviderOperation.Builder addUpdateIm(RosterEntry entry, long rawContactID, Account account,
-	boolean isInsert) {
+    private static ContentProviderOperation.Builder createProfile(RosterEntry entry, long rawContactID, Account account) {
 	String displayName = entry.getName() != null ? entry.getName() : entry.getUser();
 	ContentProviderOperation.Builder builder;
-	if (isInsert) {
-	    builder = ContentProviderOperation.newInsert(ContactsContract.Data.CONTENT_URI);
-	    builder.withValue(ContactsContract.Data.RAW_CONTACT_ID, rawContactID);
-	    builder.withValue(ContactsContract.Data.MIMETYPE, ContactsContract.CommonDataKinds.Im.CONTENT_ITEM_TYPE);
-	    builder.withValue(ContactsContract.CommonDataKinds.Im.RAW_CONTACT_ID, rawContactID);
-	    builder.withValue(ContactsContract.CommonDataKinds.Im.DATA1, displayName);
-	    builder.withValue(ContactsContract.CommonDataKinds.Im.PROTOCOL,
-		ContactsContract.CommonDataKinds.Im.PROTOCOL_JABBER);
-	} else {
-	    builder = ContentProviderOperation.newUpdate(ContactsContract.Data.CONTENT_URI);
-	}
+	builder = ContentProviderOperation.newInsert(ContactsContract.Data.CONTENT_URI);
+	builder.withValue(ContactsContract.Data.RAW_CONTACT_ID, rawContactID);
+	builder.withValue(ContactsContract.Data.MIMETYPE, ContactsContract.CommonDataKinds.Im.CONTENT_ITEM_TYPE);
+	builder.withValue(ContactsContract.CommonDataKinds.Im.RAW_CONTACT_ID, rawContactID);
+	builder.withValue(ContactsContract.CommonDataKinds.Im.DATA1, displayName);
+	builder.withValue(ContactsContract.CommonDataKinds.Im.PROTOCOL,
+	    ContactsContract.CommonDataKinds.Im.PROTOCOL_JABBER);
 	return builder;
     }
 
@@ -287,9 +283,10 @@
     private static void addUpdateStatus(ArrayList<ContentProviderOperation> ops, RosterEntry entry, Presence p,
 	long rawContactID) {
 	String displayName = entry.getName() != null ? entry.getName() : entry.getUser();
-	Log.i(TAG + "UPDATESTATUS", "Contact : " + displayName + " Presence status : " + p.getStatus() + " Presence status state : " + Status.getStatusFromPresence(p));
+	Log.i(TAG + "UPDATESTATUS", "Contact : " + displayName + " Presence status : " + p.getStatus()
+	    + " Presence status state : " + Status.getStatusFromPresence(p));
 	ContentProviderOperation.Builder builder;
-	builder = ContentProviderOperation.newInsert(ContactsContract.StatusUpdates.CONTENT_URI);	
+	builder = ContentProviderOperation.newInsert(ContactsContract.StatusUpdates.CONTENT_URI);
 	builder.withValue(ContactsContract.StatusUpdates.PROTOCOL, ContactsContract.CommonDataKinds.Im.PROTOCOL_JABBER);
 	builder.withValue(ContactsContract.StatusUpdates.IM_HANDLE, displayName);
 	builder.withValue(ContactsContract.StatusUpdates.IM_ACCOUNT, "beem@elyzion.net");
--- a/src/com/beem/project/beem/service/ChatAdapter.java	Sun May 15 18:50:01 2011 +0200
+++ b/src/com/beem/project/beem/service/ChatAdapter.java	Sun May 15 18:51:00 2011 +0200
@@ -293,6 +293,7 @@
 	@Override
 	public void processMessage(Chat chat, org.jivesoftware.smack.packet.Message message) {
 	    Message msg = new Message(message);
+	    Log.i(TAG, "MESSAGE " + msg.getFrom());
 	    //TODO add que les message pas de type errors
 	    ChatAdapter.this.addMessage(msg);
 	    final int n = mRemoteListeners.beginBroadcast();
--- a/src/com/beem/project/beem/ui/Chat.java	Sun May 15 18:50:01 2011 +0200
+++ b/src/com/beem/project/beem/ui/Chat.java	Sun May 15 18:51:00 2011 +0200
@@ -202,13 +202,15 @@
     protected void onResume() {
 	super.onResume();
 	// When coming from account contact
+	//TODO : get account from jid
+	//TODO : if multi account propose select
 	Uri contactURI = getIntent().getData();
 	String jid = contactURI.getPathSegments().get(0);
 	mContact = new Contact(jid);
-//	if (!mBinded) {
-//	    bindService(SERVICE_INTENT, mConn, BIND_AUTO_CREATE);
-//	    mBinded = true;
-//	}
+	if (!mBinded) {
+	    bindService(SERVICE_INTENT, mConn, BIND_AUTO_CREATE);
+	    mBinded = true;
+	}
     }
 
     /**
--- a/src/com/beem/project/beem/ui/ContactList.java	Sun May 15 18:50:01 2011 +0200
+++ b/src/com/beem/project/beem/ui/ContactList.java	Sun May 15 18:51:00 2011 +0200
@@ -665,7 +665,7 @@
 		ImageView img = (ImageView) view.findViewById(R.id.avatar);
 		String avatarId = curContact.getAvatarId();
 		int contactStatus = curContact.getStatus();
-		Drawable avatar = getAvatarStatusDrawable(curContact.getAvatarId());
+		Drawable avatar = getAvatarStatusDrawable(avatarId);
 		img.setImageDrawable(avatar);
 		img.setImageLevel(contactStatus);
 	    }