# HG changeset patch
# User "Vincent Veronis"
# Date 1307730384 -7200
# Node ID c36af805487d92389d40267989fd6e081368e020
# Parent 4200af89661d9ee1cb0fcc6d8b9f8dc1224cbb5b
ContactList UI - Sync group with android provider
diff -r 4200af89661d -r c36af805487d res/layout/contactlist_group.xml
--- a/res/layout/contactlist_group.xml Sun Jun 05 19:41:19 2011 +0200
+++ b/res/layout/contactlist_group.xml Fri Jun 10 20:26:24 2011 +0200
@@ -1,5 +1,11 @@
-
\ No newline at end of file
diff -r 4200af89661d -r c36af805487d src/com/beem/project/beem/account/SyncAdapterService.java
--- a/src/com/beem/project/beem/account/SyncAdapterService.java Sun Jun 05 19:41:19 2011 +0200
+++ b/src/com/beem/project/beem/account/SyncAdapterService.java Fri Jun 10 20:26:24 2011 +0200
@@ -374,7 +374,7 @@
+ ContactsContract.Groups.TITLE + "=?", new String[] { account, group }, null);
try {
if (c.moveToFirst())
- authorId = c.getInt(c.getColumnIndex(ContactsContract.RawContacts._ID));
+ authorId = c.getInt(c.getColumnIndex(ContactsContract.Groups._ID));
} finally {
if (c != null)
c.close();
diff -r 4200af89661d -r c36af805487d src/com/beem/project/beem/providers/MessageProvider.java
--- a/src/com/beem/project/beem/providers/MessageProvider.java Sun Jun 05 19:41:19 2011 +0200
+++ b/src/com/beem/project/beem/providers/MessageProvider.java Fri Jun 10 20:26:24 2011 +0200
@@ -75,13 +75,16 @@
public static final String AUTHORITY = "com.beem.project.beem.providers.messageprovider";
private static HashMap messagesProjectionMap;
- private DatabaseHelper dbHelper;
+ private DatabaseHelper dbHelper = null;
/**
* Constructor.
*/
public MessageProvider() {
-
+ Log.e(TAG, "MessageProvider");
+ if (dbHelper == null)
+ dbHelper = new DatabaseHelper(getContext());
+ Log.e(TAG, "MessageProvider" + dbHelper.toString());
}
@Override
@@ -113,17 +116,18 @@
@Override
public Uri insert(Uri uri, ContentValues initialValues) {
+ Log.e(TAG, "INSERT");
if (sUriMatcher.match(uri) != MESSAGES) {
throw new IllegalArgumentException("Unknown URI " + uri);
}
-
+ Log.e(TAG, "INSERT");
ContentValues values;
if (initialValues != null) {
values = new ContentValues(initialValues);
} else {
values = new ContentValues();
}
-
+ Log.e(TAG, "INSERT");
SQLiteDatabase db = dbHelper.getWritableDatabase();
long rowId = db.insert(MESSAGES_TABLE_NAME, Messages.BODY, values);
if (rowId > 0) {
@@ -131,11 +135,13 @@
getContext().getContentResolver().notifyChange(messageUri, null);
return messageUri;
}
+ Log.e(TAG, "INSERT");
throw new SQLException("Failed to insert row into " + uri);
}
@Override
public boolean onCreate() {
+ Log.e(TAG, "ONCREATE");
dbHelper = new DatabaseHelper(getContext());
return true;
}
@@ -182,13 +188,31 @@
DatabaseHelper(Context context) {
super(context, DATABASE_NAME, null, DATABASE_VERSION);
+ Log.e(TAG, "Constructor");
}
@Override
public void onCreate(SQLiteDatabase db) {
- db.execSQL("CREATE TABLE " + MESSAGES_TABLE_NAME + " (" + Messages._ID
- + " INTEGER PRIMARY KEY AUTOINCREMENT," + Messages.FROM + " VARCHAR(255)," + Messages.MESSAGE_ID
- + " VARCHAR(255)," + Messages.TO + " VARCHAR(255)," + Messages.BODY + " LONGTEXT" + ");");
+ Log.e(TAG, "onCreate");
+ String createDatabase = "CREATE TABLE " + MESSAGES_TABLE_NAME + " (";
+ createDatabase += Messages._ID + " INTEGER PRIMARY KEY AUTOINCREMENT,";
+ createDatabase += Messages.FROM + " VARCHAR(255),";
+ createDatabase += Messages.MESSAGE_ID + " VARCHAR(255),";
+ createDatabase += Messages.TO + " VARCHAR(255),";
+ createDatabase += Messages.TYPE + " VARCHAR(255),";
+ createDatabase += Messages.SUBJECT + " VARCHAR(255),";
+ createDatabase += Messages.BODY + " LONGTEXT,";
+ createDatabase += Messages.THREAD + " VARCHAR(255),";
+ createDatabase += Messages.EXTRAS + " VARCHAR(255),";
+ createDatabase += Messages.IS_RECEIVE + " BOOLEAN,";
+ createDatabase += Messages.DATE_RECEIVE + " DATE,";
+ createDatabase += Messages.DATE_READ + "DATE";
+ createDatabase += ");";
+ try {
+ db.execSQL(createDatabase);
+ } catch (SQLException e) {
+ Log.e(TAG, "CREATE DB PROBLEM");
+ }
}
@Override
@@ -209,7 +233,14 @@
messagesProjectionMap.put(Messages.FROM, Messages.FROM);
messagesProjectionMap.put(Messages.MESSAGE_ID, Messages.MESSAGE_ID);
messagesProjectionMap.put(Messages.TO, Messages.TO);
+ messagesProjectionMap.put(Messages.TYPE, Messages.TYPE);
+ messagesProjectionMap.put(Messages.SUBJECT, Messages.SUBJECT);
messagesProjectionMap.put(Messages.BODY, Messages.BODY);
+ messagesProjectionMap.put(Messages.THREAD, Messages.THREAD);
+ messagesProjectionMap.put(Messages.EXTRAS, Messages.EXTRAS);
+ messagesProjectionMap.put(Messages.IS_RECEIVE, Messages.IS_RECEIVE);
+ messagesProjectionMap.put(Messages.DATE_RECEIVE, Messages.IS_RECEIVE);
+ messagesProjectionMap.put(Messages.DATE_READ, Messages.DATE_READ);
}
}
diff -r 4200af89661d -r c36af805487d src/com/beem/project/beem/providers/Messages.java
--- a/src/com/beem/project/beem/providers/Messages.java Sun Jun 05 19:41:19 2011 +0200
+++ b/src/com/beem/project/beem/providers/Messages.java Fri Jun 10 20:26:24 2011 +0200
@@ -15,7 +15,7 @@
public static final Uri CONTENT_URI = Uri.parse("content://" + MessageProvider.AUTHORITY + "/messages");
public static final String CONTENT_TYPE = "vnd.android.cursor.dir/vnd.com.beem.project.beem.provider.messages";
- public static final String _ID = "_ID";
+ public static final String _ID = "_id";
public static final String FROM = "FROM";
public static final String MESSAGE_ID = "MESSAGE_ID";
public static final String TO = "TO";
diff -r 4200af89661d -r c36af805487d src/com/beem/project/beem/service/ChatAdapter.java
--- a/src/com/beem/project/beem/service/ChatAdapter.java Sun Jun 05 19:41:19 2011 +0200
+++ b/src/com/beem/project/beem/service/ChatAdapter.java Fri Jun 10 20:26:24 2011 +0200
@@ -56,11 +56,14 @@
import org.jivesoftware.smackx.ChatState;
import org.jivesoftware.smackx.ChatStateListener;
+import android.content.ContentValues;
import android.os.Environment;
import android.os.RemoteCallbackList;
import android.os.RemoteException;
import android.util.Log;
+import com.beem.project.beem.providers.MessageProvider;
+import com.beem.project.beem.providers.Messages;
import com.beem.project.beem.service.aidl.IChat;
import com.beem.project.beem.service.aidl.IMessageListener;
@@ -200,6 +203,13 @@
void addMessage(Message msg) {
if (mMessages.size() == HISTORY_MAX_SIZE)
mMessages.remove(0);
+ MessageProvider mp = new MessageProvider();
+ ContentValues contentValue = new ContentValues();
+ // note that we don't have to add an id as our table set id as autoincrement
+ //contentValue.put(Messages.FROM, msg.getFrom());
+ Log.e(TAG, "xxxxxxxxxxxxxxMESSAGExxxxxxxxxxxxxxxxxxx");
+ contentValue.put(Messages.BODY, msg.getBody());
+ mp.insert(Messages.CONTENT_URI, contentValue);
mMessages.add(msg);
if (!"".equals(msg.getBody()) && msg.getBody() != null) {
String state = Environment.getExternalStorageState();
@@ -293,7 +303,6 @@
@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();
diff -r 4200af89661d -r c36af805487d src/com/beem/project/beem/ui/ContactList.java
--- a/src/com/beem/project/beem/ui/ContactList.java Sun Jun 05 19:41:19 2011 +0200
+++ b/src/com/beem/project/beem/ui/ContactList.java Fri Jun 10 20:26:24 2011 +0200
@@ -45,7 +45,6 @@
import java.io.IOException;
import java.io.InputStream;
import java.util.ArrayList;
-import java.util.Collections;
import java.util.Comparator;
import java.util.HashMap;
import java.util.LinkedList;
@@ -57,10 +56,12 @@
import android.app.Activity;
import android.app.Dialog;
import android.content.ComponentName;
+import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.content.ServiceConnection;
import android.content.SharedPreferences;
+import android.database.Cursor;
import android.graphics.drawable.Drawable;
import android.graphics.drawable.LayerDrawable;
import android.net.Uri;
@@ -69,6 +70,7 @@
import android.os.IBinder;
import android.os.RemoteException;
import android.preference.PreferenceManager;
+import android.provider.ContactsContract;
import android.util.Log;
import android.view.ContextMenu;
import android.view.LayoutInflater;
@@ -80,12 +82,14 @@
import android.view.ViewStub;
import android.widget.AdapterView;
import android.widget.BaseAdapter;
+import android.widget.CursorAdapter;
import android.widget.Filter;
import android.widget.Filterable;
import android.widget.Gallery;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.ListView;
+import android.widget.SimpleCursorAdapter;
import android.widget.TextView;
import android.widget.AdapterView.AdapterContextMenuInfo;
import android.widget.AdapterView.OnItemClickListener;
@@ -287,7 +291,13 @@
this.registerReceiver(mReceiver, new IntentFilter(BeemBroadcastReceiver.BEEM_CONNECTION_CLOSED));
mInflater = getLayoutInflater();
- mAdapterBanner = new BeemBanner(mInflater, mListGroup);
+
+ final Cursor c = getContentResolver().query(ContactsContract.Groups.CONTENT_URI,
+ new String[] { ContactsContract.Groups._ID, ContactsContract.Groups.TITLE }, null, null, null);
+
+ mAdapterBanner = new BeemBanner(this, R.layout.contactlist_group, c,
+ new String[] { ContactsContract.Groups.TITLE }, new int[] { R.id.contactlist_group });
+
mListContact = new ArrayList();
ListView listView = (ListView) findViewById(R.id.contactlist);
listView.setOnItemClickListener(mOnContactClick);
@@ -743,43 +753,40 @@
/**
* Adapter banner list.
*/
- private static class BeemBanner extends BaseAdapter {
- private List mGroups;
- private LayoutInflater mInflater;
+ private static class BeemBanner extends SimpleCursorAdapter {
+
+ private Context mContext;
+ private int mLayout;
- /**
- * Constructor.
- * @param inflater the inflater use to create the view for the banner
- * @param groups list of the differents groups to adapt
- */
- public BeemBanner(final LayoutInflater inflater, final List groups) {
- mGroups = groups;
- mInflater = inflater;
+ public BeemBanner(Context context, int layout, Cursor c, String[] from, int[] to) {
+ super(context, layout, c, from, to);
+ mContext = context;
+ mLayout = layout;
}
@Override
- public int getCount() {
- return mGroups.size();
- }
+ public View newView(Context context, Cursor cursor, ViewGroup parent) {
+ Cursor c = getCursor();
+
+ final LayoutInflater inflater = LayoutInflater.from(mContext);
+ View v = inflater.inflate(mLayout, parent, false);
+ String name = c.getString(c.getColumnIndex(ContactsContract.Groups.TITLE));
- @Override
- public Object getItem(int position) {
- return mGroups.get(position);
+ TextView nameText = (TextView) v.findViewById(R.id.GroupListText);
+ if (nameText != null) {
+ nameText.setText(name);
+ }
+
+ return v;
}
@Override
- public long getItemId(int position) {
- return position;
- }
-
- @Override
- public View getView(int position, View convertView, ViewGroup parent) {
- View v = convertView;
- if (convertView == null) {
- v = mInflater.inflate(R.layout.contactlist_group, null);
+ public void bindView(View view, Context context, Cursor cursor) {
+ String name = cursor.getString(cursor.getColumnIndex(ContactsContract.Groups.TITLE));
+ TextView nameText = (TextView) view.findViewById(R.id.contactlist_group);
+ if (nameText != null) {
+ nameText.setText(name);
}
- ((TextView) v).setText(mGroups.get(position));
- return v;
}
}
@@ -800,27 +807,27 @@
try {
mRoster = mXmppFacade.getRoster();
//if (mRoster != null) {
-
- List tmpGroupList = mRoster.getGroupsNames();
- for (String string : tmpGroupList) {
- Log.e(TAG, string);
- }
- Collections.sort(tmpGroupList);
- mListGroup.clear();
- mListGroup.add(getString(R.string.contact_list_all_contact));
- mListGroup.addAll(tmpGroupList);
- mListGroup.add(getString(R.string.contact_list_no_group));
- assignContactToGroups(mRoster.getContactList(), tmpGroupList);
- makeSortedList(mContactOnGroup);
- if (!mSettings.getBoolean("settings_key_hide_groups", false))
- showGroups();
- else
- hideGroups();
- String group = getString(R.string.contact_list_all_contact);
- buildContactList(group);
- mRoster.addRosterListener(mBeemRosterListener);
- Log.d(TAG, "add roster listener");
- mChatManager = mXmppFacade.getChatManager();
+ //
+ // List tmpGroupList = mRoster.getGroupsNames();
+ // for (String string : tmpGroupList) {
+ // Log.e(TAG, string);
+ // }
+ // Collections.sort(tmpGroupList);
+ // mListGroup.clear();
+ // mListGroup.add(getString(R.string.contact_list_all_contact));
+ // mListGroup.addAll(tmpGroupList);
+ // mListGroup.add(getString(R.string.contact_list_no_group));
+ // assignContactToGroups(mRoster.getContactList(), tmpGroupList);
+ // makeSortedList(mContactOnGroup);
+ // if (!mSettings.getBoolean("settings_key_hide_groups", false))
+ showGroups();
+ // else
+ // hideGroups();
+ // String group = getString(R.string.contact_list_all_contact);
+ // buildContactList(group);
+ // mRoster.addRosterListener(mBeemRosterListener);
+ // Log.d(TAG, "add roster listener");
+ // mChatManager = mXmppFacade.getChatManager();
//}
} catch (RemoteException e) {
e.printStackTrace();
@@ -945,8 +952,8 @@
@Override
public void onItemClick(AdapterView> arg0, View v, int i, long l) {
- String group = mListGroup.get(i);
- buildContactList(group);
+// String group = mListGroup.get(i);
+// buildContactList(group);
}
}
diff -r 4200af89661d -r c36af805487d src/com/beem/project/beem/ui/CreateAccount.java
--- a/src/com/beem/project/beem/ui/CreateAccount.java Sun Jun 05 19:41:19 2011 +0200
+++ b/src/com/beem/project/beem/ui/CreateAccount.java Fri Jun 10 20:26:24 2011 +0200
@@ -121,7 +121,7 @@
try {
xmppConnection.connect();
AccountManager accountManager = new AccountManager(xmppConnection);
- accountManager.createAccount(username, password);
+ accountManager.createAccount(username, password);
Toast toast = Toast.makeText(getApplicationContext(), String.format(
getString(R.string.create_account_successfull_after), username), NOTIFICATION_DURATION);
toast.show();