public void addContact(Contact contact) { if (TextUtils.isEmpty(contact.getContactNumber())) { contact.setContactNumber(contact.getUserId()); } ContentValues contentValues = prepareContactValues(contact); dbHelper.getWritableDatabase().insert(CONTACT, null, contentValues); dbHelper.close(); }
public List<Contact> getAllContact() { SQLiteDatabase db = dbHelper.getWritableDatabase(); Cursor cursor = db.query(CONTACT, null, null, null, null, null, MobiComDatabaseHelper.FULL_NAME + " asc"); List<Contact> contactList = getContactList(cursor); cursor.close(); dbHelper.close(); return contactList; }
public void updateContact(Contact contact) { ContentValues contentValues = prepareContactValues(contact); dbHelper .getWritableDatabase() .update( CONTACT, contentValues, MobiComDatabaseHelper.USERID + "=?", new String[] {contact.getUserId()}); dbHelper.close(); }
public void updateLastSeenTimeAt(String userId, long lastSeenTime) { try { ContentValues contentValues = new ContentValues(); contentValues.put(MobiComDatabaseHelper.LAST_SEEN_AT_TIME, lastSeenTime); dbHelper .getWritableDatabase() .update( CONTACT, contentValues, MobiComDatabaseHelper.USERID + "=?", new String[] {userId}); } catch (Exception e) { e.printStackTrace(); } finally { dbHelper.close(); } }
public Contact getContactById(String id) { String structuredNameWhere = MobiComDatabaseHelper.USERID + " =?"; SQLiteDatabase db = dbHelper.getWritableDatabase(); Cursor cursor = db.query(CONTACT, null, structuredNameWhere, new String[] {id}, null, null, null); Contact contact = null; if (cursor != null) { if (cursor.getCount() > 0) { cursor.moveToFirst(); contact = getContact(cursor); } cursor.close(); } dbHelper.close(); return contact; }
public void updateConnectedOrDisconnectedStatus(String userId, Date date, boolean connected) { ContentValues contentValues = new ContentValues(); contentValues.put(MobiComDatabaseHelper.CONNECTED, connected ? 1 : 0); contentValues.put(MobiComDatabaseHelper.LAST_SEEN_AT_TIME, date.getTime()); try { dbHelper .getWritableDatabase() .update( CONTACT, contentValues, MobiComDatabaseHelper.USERID + "=?", new String[] {userId}); } catch (Exception e) { e.printStackTrace(); } finally { dbHelper.close(); } }
public void deleteContactById(String id) { SQLiteDatabase db = dbHelper.getWritableDatabase(); db.delete(CONTACT, "userId=?", new String[] {id}); dbHelper.close(); }