Database
[pullquote align="normal"]
[/pullquote]
https://acadgild.com/blog/how-to-draw-a-path-on-google-maps-in-android/ package com.app.forgotcha.sqlite.db; import android.app.Activity; import android.content.ContentValues; import android.content.Context; import android.database.Cursor; import android.database.SQLException; import android.database.sqlite.SQLiteDatabase; import android.database.sqlite.SQLiteOpenHelper; import android.text.TextUtils; import android.util.Log; import com.app.forgotcha.ForgotchaAplication; import com.app.forgotcha.R; import com.app.forgotcha.model.ContactModel; import com.app.forgotcha.model.UserModel; import com.app.forgotcha.util.Constans; import com.app.forgotcha.util.SortBasedOnName; import java.text.ParseException; import java.text.SimpleDateFormat; import java.util.ArrayList; import java.util.Calendar; import java.util.Collections; import java.util.Comparator; import java.util.Date; import java.util.GregorianCalendar; import java.util.Hashtable; import java.util.Locale; /**************************************************************************** * @ClassdName:DatabaseHelper * @CreatedDate: * @ModifiedBy: not yet * @ModifiedDate: not yet * @purpose:This Class is use to Create database with Table and insert,update,delete Method with functionlity. ***************************************************************************/ public class DatabaseHelper extends SQLiteOpenHelper { private static Context mContext; // DATABASE NAME private static String DATABASE_NAME = "FORGOTCHA"; private static String TABLE_NAME = ""; private SQLiteDatabase DataBase; // LIST TABLE NAME private String TABLE_NAME_CONTACTS = "contacts"; private String TABLE_NAME_CONTACTS_LOGBOOK = "contacts_logbook"; private String TABLE_NAME_USER = "user"; private String TABLE_NAME_UPDATE_CONATCTS = "update_contacts"; public DatabaseHelper(Context context, String data_name, String tab_name, Hashtable column_pairs) {
super(context, data_name, null, Constans.SQLITE_VERSION);
mContext = context;
TABLE_NAME = tab_name;
}
public DatabaseHelper(Context context) {
super(context, DATABASE_NAME, null, Constans.SQLITE_VERSION);
mContext = context;
}
/**
* Open Databases
* *
*/
public void openDataBase() throws SQLException {
this.getWritableDatabase();
}
@Override
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
if (oldVersion != newVersion) {
try {
ForgotchaAplication.getmInstance().savePreferenceDataBoolean("isLogin", false);
ForgotchaAplication.getmInstance().clearePreferenceData();
db.execSQL("DROP TABLE IF EXISTS " + TABLE_NAME_CONTACTS);
} catch (Exception e) {
e.printStackTrace();
}
}
onCreate(db);
}
@Override
public void onCreate(SQLiteDatabase database) {
create_table_user(database);
create_table_contacs(database);
create_table_contacs_logbook(database);
create_table_update_contacts(database);
}
// Create Table user
public void create_table_user(SQLiteDatabase database) {
try {
Hashtable tmp_contacts = new Hashtable();
tmp_contacts.put(UserKey.ID, "INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL");
tmp_contacts.put(UserKey.USER_ID, "TEXT");
tmp_contacts.put(UserKey.FIRST_NAME, "TEXT");
tmp_contacts.put(UserKey.LAST_NAME, "TEXT");
tmp_contacts.put(UserKey.COMPANY, "TEXT");
tmp_contacts.put(UserKey.TITLE, "TEXT");
tmp_contacts.put(UserKey.EMAIl, "TEXT");
tmp_contacts.put(UserKey.PROFILE_IMAGE, "TEXT");
tmp_contacts.put(UserKey.PHONE, "TEXT");
tmp_contacts.put(UserKey.ADDRESS, "TEXT");
tmp_contacts.put(UserKey.COUNTRY, "TEXT");
tmp_contacts.put(UserKey.CITY, "TEXT");
tmp_contacts.put(UserKey.STATE, "TEXT");
tmp_contacts.put(UserKey.ZIPCODE, "TEXT");
tmp_contacts.put(UserKey.ADDRESS2, "TEXT");
tmp_contacts.put(UserKey.COUNTRY2, "TEXT");
tmp_contacts.put(UserKey.CITY2, "TEXT");
tmp_contacts.put(UserKey.STATE2, "TEXT");
tmp_contacts.put(UserKey.ZIPCODE2, "TEXT");
tmp_contacts.put(UserKey.TOKENID, "TEXT");
tmp_contacts.put(UserKey.PROFILE_IMAGE, "TEXT");
tmp_contacts.put(UserKey.NEW_PHONES, "TEXT");
tmp_contacts.put(UserKey.NEW_EMAILS, "TEXT");
tmp_contacts.put(UserKey.NEW_ADDRESS, "TEXT");
createtable(database, TABLE_NAME_USER, tmp_contacts);
} catch (Exception e) {
e.printStackTrace();
}
}
// Create Table Conatcts
public void create_table_contacs(SQLiteDatabase database) {
try {
Hashtable tmp_contacts = new Hashtable();
tmp_contacts.put(ContactKey.ID, "INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL");
tmp_contacts.put(ContactKey.USER_ID, "TEXT");
tmp_contacts.put(ContactKey.CONTACT_ID, "TEXT");
tmp_contacts.put(ContactKey.FIRST_NAME, "TEXT");
tmp_contacts.put(ContactKey.LAST_UPDATE_DATE, "TEXT");
tmp_contacts.put(ContactKey.LAST_NAME, "TEXT");
tmp_contacts.put(ContactKey.FULL_NAME, "TEXT");
tmp_contacts.put(ContactKey.LATLONG, "TEXT");
tmp_contacts.put(ContactKey.ADDRESS, "TEXT");
tmp_contacts.put(ContactKey.ZIPCODE, "INTEGER");
tmp_contacts.put(ContactKey.COUNTRY, "TEXT");
tmp_contacts.put(ContactKey.STATE, "TEXT");
tmp_contacts.put(ContactKey.CITY, "TEXT");
tmp_contacts.put(ContactKey.IMAGE_URI, "TEXT");
tmp_contacts.put(ContactKey.CREATED_DATE, "TEXT");
tmp_contacts.put(ContactKey.MOBILE_NUMBER, "TEXT");
tmp_contacts.put(ContactKey.WORK_MOBILE_NUMBER, "TEXT");
tmp_contacts.put(ContactKey.WORK_FAX_MOBILE_NUMBER, "TEXT");
tmp_contacts.put(ContactKey.CUSTOME_MOBILE_NUMBER, "TEXT");
tmp_contacts.put(ContactKey.FAX_HOME_MOBILE_NUMBER, "TEXT");
tmp_contacts.put(ContactKey.MAIN_MOBILE_NUMBER, "TEXT");
tmp_contacts.put(ContactKey.OTHERS_MOBILE_NUMBER, "TEXT");
tmp_contacts.put(ContactKey.PAGER_MOBILE_NUMBER, "TEXT");
tmp_contacts.put(ContactKey.HOME_MOBILE_NUMBER, "TEXT");
tmp_contacts.put(ContactKey.HOME_EMAIL_ID, "TEXT");
tmp_contacts.put(ContactKey.WORK_EMAIL_ID, "TEXT");
tmp_contacts.put(ContactKey.CUSTOME_EMAIL_ID, "TEXT");
tmp_contacts.put(ContactKey.OTHERS_EMAIL_ID, "TEXT");
tmp_contacts.put(ContactKey.EMAGE_URI, "TEXT");
tmp_contacts.put(ContactKey.ADDRESS_HOME, "TEXT");
tmp_contacts.put(ContactKey.ADDRESS_WORK, "TEXT");
tmp_contacts.put(ContactKey.ADDRESS_OTHER, "TEXT");
tmp_contacts.put(ContactKey.ADDRESS_CUSTOME, "TEXT");
tmp_contacts.put(ContactKey.NOTES, "TEXT");
tmp_contacts.put(ContactKey.EVENT_BIRTHDATE, "TEXT");
tmp_contacts.put(ContactKey.EVENT_ANNIVERSARYDATE, "TEXT");
tmp_contacts.put(ContactKey.EVENT_OTHERSDATE, "TEXT");
tmp_contacts.put(ContactKey.EVENT_CUSTOMEDATE, "TEXT");
tmp_contacts.put(ContactKey.IM_YAHOO, "TEXT");
tmp_contacts.put(ContactKey.IM_SKYPE, "TEXT");
tmp_contacts.put(ContactKey.IM_QQ, "TEXT");
tmp_contacts.put(ContactKey.IM_GTALK, "TEXT");
tmp_contacts.put(ContactKey.IM_ICQ, "TEXT");
tmp_contacts.put(ContactKey.IM_JABBER, "TEXT");
tmp_contacts.put(ContactKey.IM_CUSTOME, "TEXT");
tmp_contacts.put(ContactKey.IM_MSN, "TEXT");
tmp_contacts.put(ContactKey.IM_AIM, "TEXT");
tmp_contacts.put(ContactKey.IM_NETMEETING, "TEXT");
tmp_contacts.put(ContactKey.NIKNAME, "TEXT");
tmp_contacts.put(ContactKey.WEBSITE, "TEXT");
tmp_contacts.put(ContactKey.PHONETIC_NAME, "TEXT");
tmp_contacts.put(ContactKey.SIP, "TEXT");
tmp_contacts.put(ContactKey.RELATION_BROTHER, "TEXT");
tmp_contacts.put(ContactKey.RELATION_ASSISTNT, "TEXT");
tmp_contacts.put(ContactKey.RELATION_CHILD, "TEXT");
tmp_contacts.put(ContactKey.RELATION_DOM_PARTNER, "TEXT");
tmp_contacts.put(ContactKey.RELATION_FATHER, "TEXT");
tmp_contacts.put(ContactKey.RELATION_FRIEND, "TEXT");
tmp_contacts.put(ContactKey.RELATION_MANAGER, "TEXT");
tmp_contacts.put(ContactKey.RELATION_MOTHER, "TEXT");
tmp_contacts.put(ContactKey.RELATION_PARENT, "TEXT");
tmp_contacts.put(ContactKey.RELATION_PARTNER, "TEXT");
tmp_contacts.put(ContactKey.RELATION_REFEREDBY, "TEXT");
tmp_contacts.put(ContactKey.RELATION_RELATIVE, "TEXT");
tmp_contacts.put(ContactKey.RELATION_SISTER, "TEXT");
tmp_contacts.put(ContactKey.RELATION_SPOISE, "TEXT");
tmp_contacts.put(ContactKey.RELATION_CUSTOME, "TEXT");
tmp_contacts.put(ContactKey.STATUS, "TEXT");
tmp_contacts.put(ContactKey.LOCATIONNAME, "TEXT");
tmp_contacts.put(ContactKey.COMPANY, "TEXT");
tmp_contacts.put(ContactKey.EDITED_FIELD, "TEXT");
createtable(database, TABLE_NAME_CONTACTS, tmp_contacts);
} catch (Exception e) {
e.printStackTrace();
}
}
// Create Table Conatcts logbook
public void create_table_contacs_logbook(SQLiteDatabase database) {
try {
final Hashtable tmp_contacts = new Hashtable();
tmp_contacts.put(ContactKey.ID, "INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL");
tmp_contacts.put(ContactKey.USER_ID, "TEXT");
tmp_contacts.put(ContactKey.CONTACT_ID, "TEXT");
tmp_contacts.put(ContactKey.FIRST_NAME, "TEXT");
tmp_contacts.put(ContactKey.FULL_NAME, "TEXT");
tmp_contacts.put(ContactKey.LAST_UPDATE_DATE, "TEXT");
tmp_contacts.put(ContactKey.LAST_NAME, "TEXT");
tmp_contacts.put(ContactKey.LATLONG, "TEXT");
tmp_contacts.put(ContactKey.ADDRESS, "TEXT");
tmp_contacts.put(ContactKey.ZIPCODE, "INTEGER");
tmp_contacts.put(ContactKey.COUNTRY, "TEXT");
tmp_contacts.put(ContactKey.STATE, "TEXT");
tmp_contacts.put(ContactKey.CITY, "TEXT");
tmp_contacts.put(ContactKey.IMAGE_URI, "TEXT");
tmp_contacts.put(ContactKey.CREATED_DATE, "TEXT");
tmp_contacts.put(ContactKey.MOBILE_NUMBER, "TEXT");
tmp_contacts.put(ContactKey.WORK_MOBILE_NUMBER, "TEXT");
tmp_contacts.put(ContactKey.WORK_FAX_MOBILE_NUMBER, "TEXT");
tmp_contacts.put(ContactKey.CUSTOME_MOBILE_NUMBER, "TEXT");
tmp_contacts.put(ContactKey.FAX_HOME_MOBILE_NUMBER, "TEXT");
tmp_contacts.put(ContactKey.MAIN_MOBILE_NUMBER, "TEXT");
tmp_contacts.put(ContactKey.OTHERS_MOBILE_NUMBER, "TEXT");
tmp_contacts.put(ContactKey.PAGER_MOBILE_NUMBER, "TEXT");
tmp_contacts.put(ContactKey.HOME_MOBILE_NUMBER, "TEXT");
tmp_contacts.put(ContactKey.HOME_EMAIL_ID, "TEXT");
tmp_contacts.put(ContactKey.WORK_EMAIL_ID, "TEXT");
tmp_contacts.put(ContactKey.CUSTOME_EMAIL_ID, "TEXT");
tmp_contacts.put(ContactKey.OTHERS_EMAIL_ID, "TEXT");
tmp_contacts.put(ContactKey.EMAGE_URI, "TEXT");
tmp_contacts.put(ContactKey.ADDRESS_HOME, "TEXT");
tmp_contacts.put(ContactKey.ADDRESS_WORK, "TEXT");
tmp_contacts.put(ContactKey.ADDRESS_OTHER, "TEXT");
tmp_contacts.put(ContactKey.ADDRESS_CUSTOME, "TEXT");
tmp_contacts.put(ContactKey.NOTES, "TEXT");
tmp_contacts.put(ContactKey.EVENT_BIRTHDATE, "TEXT");
tmp_contacts.put(ContactKey.EVENT_ANNIVERSARYDATE, "TEXT");
tmp_contacts.put(ContactKey.EVENT_OTHERSDATE, "TEXT");
tmp_contacts.put(ContactKey.EVENT_CUSTOMEDATE, "TEXT");
tmp_contacts.put(ContactKey.IM_YAHOO, "TEXT");
tmp_contacts.put(ContactKey.IM_SKYPE, "TEXT");
tmp_contacts.put(ContactKey.IM_QQ, "TEXT");
tmp_contacts.put(ContactKey.IM_GTALK, "TEXT");
tmp_contacts.put(ContactKey.IM_ICQ, "TEXT");
tmp_contacts.put(ContactKey.IM_JABBER, "TEXT");
tmp_contacts.put(ContactKey.IM_CUSTOME, "TEXT");
tmp_contacts.put(ContactKey.IM_MSN, "TEXT");
tmp_contacts.put(ContactKey.IM_AIM, "TEXT");
tmp_contacts.put(ContactKey.IM_NETMEETING, "TEXT");
tmp_contacts.put(ContactKey.NIKNAME, "TEXT");
tmp_contacts.put(ContactKey.WEBSITE, "TEXT");
tmp_contacts.put(ContactKey.PHONETIC_NAME, "TEXT");
tmp_contacts.put(ContactKey.SIP, "TEXT");
tmp_contacts.put(ContactKey.RELATION_BROTHER, "TEXT");
tmp_contacts.put(ContactKey.RELATION_ASSISTNT, "TEXT");
tmp_contacts.put(ContactKey.RELATION_CHILD, "TEXT");
tmp_contacts.put(ContactKey.RELATION_DOM_PARTNER, "TEXT");
tmp_contacts.put(ContactKey.RELATION_FATHER, "TEXT");
tmp_contacts.put(ContactKey.RELATION_FRIEND, "TEXT");
tmp_contacts.put(ContactKey.RELATION_MANAGER, "TEXT");
tmp_contacts.put(ContactKey.RELATION_MOTHER, "TEXT");
tmp_contacts.put(ContactKey.RELATION_PARENT, "TEXT");
tmp_contacts.put(ContactKey.RELATION_PARTNER, "TEXT");
tmp_contacts.put(ContactKey.RELATION_REFEREDBY, "TEXT");
tmp_contacts.put(ContactKey.RELATION_RELATIVE, "TEXT");
tmp_contacts.put(ContactKey.RELATION_SISTER, "TEXT");
tmp_contacts.put(ContactKey.RELATION_SPOISE, "TEXT");
tmp_contacts.put(ContactKey.RELATION_CUSTOME, "TEXT");
tmp_contacts.put(ContactKey.STATUS, "TEXT");
tmp_contacts.put(ContactKey.LOCATIONNAME, "TEXT");
tmp_contacts.put(ContactKey.COMPANY, "TEXT");
tmp_contacts.put(ContactKey.EDITED_FIELD, "TEXT");
createtable(database, TABLE_NAME_CONTACTS_LOGBOOK, tmp_contacts);
} catch (Exception e) {
e.printStackTrace();
}
}
// Create Table update contacts
public void create_table_update_contacts(SQLiteDatabase database) {
try {
Hashtable tmp_contacts = new Hashtable();
tmp_contacts.put(UserKey.ID, "INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL");
tmp_contacts.put(ContactKey.USER_ID, "TEXT");
tmp_contacts.put(ContactKey.CONTACT_ID, "TEXT");
tmp_contacts.put(ContactKey.LAST_UPDATE_DATE, "TEXT");
createtable(database, TABLE_NAME_UPDATE_CONATCTS, tmp_contacts);
} catch (Exception e) {
e.printStackTrace();
}
}
public ArrayList selectAllContacts() {
ArrayList arrContactModelList = new ArrayList();
Cursor cursor = null;
SQLiteDatabase db = this.getWritableDatabase();
cursor = db.query(TABLE_NAME_CONTACTS, null, null, null, null, null, ContactKey.FIRST_NAME + " COLLATE NOCASE ASC;");
if (cursor.moveToFirst()) {
do {
ContactModel mContactModel = new ContactModel();
mContactModel.setId(cursor.getString(cursor.getColumnIndex(ContactKey.ID)));
mContactModel.setContactsId(cursor.getString(cursor.getColumnIndex(ContactKey.CONTACT_ID)));
//mContactModel.setFistname(firstCharUprt(cursor.getString(cursor.getColumnIndex(ContactKey.FIRST_NAME))));
mContactModel.setFistname(cursor.getString(cursor.getColumnIndex(ContactKey.FIRST_NAME)));
mContactModel.setLastname(cursor.getString(cursor.getColumnIndex(ContactKey.LAST_NAME)));
mContactModel.setCreatedDate(cursor.getString(cursor.getColumnIndex(ContactKey.CREATED_DATE)));
mContactModel.setMobileNumber(cursor.getString(cursor.getColumnIndex(ContactKey.MOBILE_NUMBER)));
mContactModel.setCity(cursor.getString(cursor.getColumnIndex(ContactKey.CITY)));
mContactModel.setState(cursor.getString(cursor.getColumnIndex(ContactKey.STATE)));
mContactModel.setLocationName(cursor.getString(cursor.getColumnIndex(ContactKey.LOCATIONNAME)));
mContactModel.setWebSite(cursor.getString(cursor.getColumnIndex(ContactKey.WEBSITE)));
mContactModel.setImageUri(cursor.getString(cursor.getColumnIndex(ContactKey.IMAGE_URI)));
mContactModel.setSip(cursor.getString(cursor.getColumnIndex(ContactKey.SIP)));
mContactModel.setEventAnnivesaryDate(cursor.getString(cursor.getColumnIndex(ContactKey.EVENT_ANNIVERSARYDATE)));
mContactModel.setEmailHome(cursor.getString(cursor.getColumnIndex(ContactKey.HOME_EMAIL_ID)));
mContactModel.setEmailWork(cursor.getString(cursor.getColumnIndex(ContactKey.WORK_EMAIL_ID)));
mContactModel.setEmailOther(cursor.getString(cursor.getColumnIndex(ContactKey.OTHERS_EMAIL_ID)));
mContactModel.setLatlong(cursor.getString(cursor.getColumnIndex(ContactKey.LATLONG)));
mContactModel.setEventBirthDate(cursor.getString(cursor.getColumnIndex(ContactKey.EVENT_BIRTHDATE)));
mContactModel.setCompany(cursor.getString(cursor.getColumnIndex(ContactKey.COMPANY)));
mContactModel.setImAim(cursor.getString(cursor.getColumnIndex(ContactKey.IM_AIM)));
mContactModel.setAddressHome(cursor.getString(cursor.getColumnIndex(ContactKey.ADDRESS_HOME)));
mContactModel.setStatus(cursor.getString(cursor.getColumnIndex(ContactKey.STATUS)));
mContactModel.setUpdatedDate(cursor.getString(cursor.getColumnIndex(ContactKey.LAST_UPDATE_DATE)));
mContactModel.setRelationAssistant(cursor.getString(cursor.getColumnIndex(ContactKey.RELATION_ASSISTNT)));
mContactModel.setNotes(cursor.getString(cursor.getColumnIndex(ContactKey.NOTES)));
mContactModel.setHomeMobileNumber(cursor.getString(cursor.getColumnIndex(ContactKey.HOME_MOBILE_NUMBER)));
mContactModel.setCustmeMobileNumber(cursor.getString(cursor.getColumnIndex(ContactKey.CUSTOME_MOBILE_NUMBER)));
mContactModel.setFaxHomeMobileNumber(cursor.getString(cursor.getColumnIndex(ContactKey.FAX_HOME_MOBILE_NUMBER)));
mContactModel.setWorkFaxMobileNumber(cursor.getString(cursor.getColumnIndex(ContactKey.WORK_FAX_MOBILE_NUMBER)));
mContactModel.setWorkMobileNumber(cursor.getString(cursor.getColumnIndex(ContactKey.WORK_MOBILE_NUMBER)));
mContactModel.setMainMobileNumber(cursor.getString(cursor.getColumnIndex(ContactKey.MAIN_MOBILE_NUMBER)));
mContactModel.setOthersMobileNumber(cursor.getString(cursor.getColumnIndex(ContactKey.OTHERS_MOBILE_NUMBER)));
mContactModel.setPagerMobileNumber(cursor.getString(cursor.getColumnIndex(ContactKey.PAGER_MOBILE_NUMBER)));
mContactModel.setAddressCustome(cursor.getString(cursor.getColumnIndex(ContactKey.ADDRESS_CUSTOME)));
mContactModel.setAddressWork(cursor.getString(cursor.getColumnIndex(ContactKey.ADDRESS_WORK)));
mContactModel.setAddressOther(cursor.getString(cursor.getColumnIndex(ContactKey.ADDRESS_OTHER)));
mContactModel.setVisible(false);
if (cursor.getString(cursor.getColumnIndex(ContactKey.FIRST_NAME)) != null && !TextUtils.isEmpty(cursor.getString(cursor.getColumnIndex(ContactKey.FIRST_NAME)))) {
arrContactModelList.add(mContactModel);
}
} while (cursor.moveToNext());
}
cursor.close();
db.close();
return arrContactModelList;
}
public ArrayList selectAllContactsWithPhoneInvite() {
ArrayList arrContactModelList = new ArrayList();
Cursor cursor = null;
SQLiteDatabase db = this.getWritableDatabase();
cursor = db.query(TABLE_NAME_CONTACTS, null, null, null, null, null, ContactKey.FIRST_NAME + " COLLATE NOCASE ASC;");
if (cursor.moveToFirst()) {
do {
ContactModel mContactModel = new ContactModel();
mContactModel.setId(cursor.getString(cursor.getColumnIndex(ContactKey.ID)));
mContactModel.setContactsId(cursor.getString(cursor.getColumnIndex(ContactKey.CONTACT_ID)));
mContactModel.setFistname(firstCharUprt(cursor.getString(cursor.getColumnIndex(ContactKey.FIRST_NAME))));
mContactModel.setLastname(cursor.getString(cursor.getColumnIndex(ContactKey.LAST_NAME)));
mContactModel.setEmailHome(cursor.getString(cursor.getColumnIndex(ContactKey.HOME_EMAIL_ID)));
mContactModel.setEmailWork(cursor.getString(cursor.getColumnIndex(ContactKey.WORK_EMAIL_ID)));
mContactModel.setEmailOther(cursor.getString(cursor.getColumnIndex(ContactKey.OTHERS_EMAIL_ID)));
mContactModel.setNotes(cursor.getString(cursor.getColumnIndex(ContactKey.NOTES)));
mContactModel.setVisible(false);
arrContactModelList.add(mContactModel);
String mobileNumber = cursor.getString(cursor.getColumnIndex(ContactKey.MOBILE_NUMBER));
if (mobileNumber != null && !mobileNumber.equals("")) {
mContactModel.setMobileNumber(cursor.getString(cursor.getColumnIndex(ContactKey.MOBILE_NUMBER)));
} else {
mContactModel.setMobileNumber(cursor.getString(cursor.getColumnIndex(ContactKey.CUSTOME_MOBILE_NUMBER)));
}
} while (cursor.moveToNext());
}
cursor.close();
db.close();
return arrContactModelList;
}
public ArrayList selectAllContactsWithEmailInvite() {
ArrayList arrContactModelList = new ArrayList();
Cursor cursor = null;
SQLiteDatabase db = this.getWritableDatabase();
cursor = db.query(TABLE_NAME_CONTACTS, null, null, null, ContactKey.HOME_EMAIL_ID, null, ContactKey.FIRST_NAME + " COLLATE NOCASE ASC;");
if (cursor.moveToFirst()) {
do {
ContactModel mContactModel = new ContactModel();
mContactModel.setId(cursor.getString(cursor.getColumnIndex(ContactKey.ID)));
mContactModel.setContactsId(cursor.getString(cursor.getColumnIndex(ContactKey.CONTACT_ID)));
mContactModel.setFistname(firstCharUprt(cursor.getString(cursor.getColumnIndex(ContactKey.FIRST_NAME))));
mContactModel.setLastname(cursor.getString(cursor.getColumnIndex(ContactKey.LAST_NAME)));
mContactModel.setMobileNumber(cursor.getString(cursor.getColumnIndex(ContactKey.HOME_EMAIL_ID)));
mContactModel.setNotes(cursor.getString(cursor.getColumnIndex(ContactKey.NOTES)));
mContactModel.setVisible(false);
if (cursor.getString(cursor.getColumnIndex(ContactKey.HOME_EMAIL_ID)) != null && !cursor.getString(cursor.getColumnIndex(ContactKey.HOME_EMAIL_ID)).equals(""))
arrContactModelList.add(mContactModel);
} while (cursor.moveToNext());
}
cursor.close();
db.close();
return arrContactModelList;
}
public ArrayList selectAllLogContactsByID(String conatctsId) {
final ArrayList arrContactModelList = new ArrayList();
Cursor cursor = null;
SQLiteDatabase db = this.getWritableDatabase();
cursor = db.query(TABLE_NAME_CONTACTS_LOGBOOK, null, ContactKey.CONTACT_ID + "=?", new String[]{conatctsId}, null, null, null, null);
if (cursor.moveToFirst()) {
do {
ContactModel mContactModel = new ContactModel();
mContactModel.setId(cursor.getString(cursor.getColumnIndex(ContactKey.ID)));
mContactModel.setContactsId(cursor.getString(cursor.getColumnIndex(ContactKey.CONTACT_ID)));
mContactModel.setFistname(cursor.getString(cursor.getColumnIndex(ContactKey.FIRST_NAME)));
mContactModel.setLastname(cursor.getString(cursor.getColumnIndex(ContactKey.LAST_NAME)));
mContactModel.setCreatedDate(cursor.getString(cursor.getColumnIndex(ContactKey.CREATED_DATE)));
mContactModel.setMobileNumber(cursor.getString(cursor.getColumnIndex(ContactKey.MOBILE_NUMBER)));
mContactModel.setCity(cursor.getString(cursor.getColumnIndex(ContactKey.CITY)));
mContactModel.setState(cursor.getString(cursor.getColumnIndex(ContactKey.STATE)));
mContactModel.setCountry(cursor.getString(cursor.getColumnIndex(ContactKey.COUNTRY)));
mContactModel.setLocationName(cursor.getString(cursor.getColumnIndex(ContactKey.LOCATIONNAME)));
mContactModel.setWebSite(cursor.getString(cursor.getColumnIndex(ContactKey.WEBSITE)));
mContactModel.setImageUri(cursor.getString(cursor.getColumnIndex(ContactKey.IMAGE_URI)));
mContactModel.setSip(cursor.getString(cursor.getColumnIndex(ContactKey.SIP)));
mContactModel.setEventAnnivesaryDate(cursor.getString(cursor.getColumnIndex(ContactKey.EVENT_ANNIVERSARYDATE)));
mContactModel.setEmailHome(cursor.getString(cursor.getColumnIndex(ContactKey.HOME_EMAIL_ID)));
mContactModel.setEmailWork(cursor.getString(cursor.getColumnIndex(ContactKey.WORK_EMAIL_ID)));
mContactModel.setEmailOther(cursor.getString(cursor.getColumnIndex(ContactKey.OTHERS_EMAIL_ID)));
mContactModel.setLatlong(cursor.getString(cursor.getColumnIndex(ContactKey.LATLONG)));
mContactModel.setEventBirthDate(cursor.getString(cursor.getColumnIndex(ContactKey.EVENT_BIRTHDATE)));
mContactModel.setCompany(cursor.getString(cursor.getColumnIndex(ContactKey.COMPANY)));
mContactModel.setImAim(cursor.getString(cursor.getColumnIndex(ContactKey.IM_AIM)));
mContactModel.setAddressHome(cursor.getString(cursor.getColumnIndex(ContactKey.ADDRESS_HOME)));
mContactModel.setStatus(cursor.getString(cursor.getColumnIndex(ContactKey.STATUS)));
mContactModel.setRelationAssistant(cursor.getString(cursor.getColumnIndex(ContactKey.RELATION_ASSISTNT)));
mContactModel.setNotes(cursor.getString(cursor.getColumnIndex(ContactKey.NOTES)));
mContactModel.setUpdatedDate(cursor.getString(cursor.getColumnIndex(ContactKey.LAST_UPDATE_DATE)));
mContactModel.setEditedField(cursor.getString(cursor.getColumnIndex(ContactKey.EDITED_FIELD)));
arrContactModelList.add(mContactModel);
} while (cursor.moveToNext());
}
Collections.sort(arrContactModelList, new LastUpdateDateComparator());
cursor.close();
db.close();
return arrContactModelList;
}
public ArrayList selectAllOfflineUpdateContacts() {
ArrayList arrContactModelList = new ArrayList();
Cursor cursor = null;
SQLiteDatabase db = this.getWritableDatabase();
cursor = db.query(TABLE_NAME_UPDATE_CONATCTS, null, null, null, null, null, null);
if (cursor != null && cursor.getCount() > 0) {
if (cursor.moveToFirst()) {
do {
ContactModel mContactModel = new ContactModel();
mContactModel.setId(cursor.getString(cursor.getColumnIndex(ContactKey.ID)));
mContactModel.setContactsId(cursor.getString(cursor.getColumnIndex(ContactKey.CONTACT_ID)));
mContactModel.setUpdatedDate(cursor.getString(cursor.getColumnIndex(ContactKey.LAST_UPDATE_DATE)));
arrContactModelList.add(mContactModel);
} while (cursor.moveToNext());
}
cursor.close();
}
db.close();
return arrContactModelList;
}
public ArrayList selectAllLogContactsWithStatusAndId(final boolean isDeleted, final String contactId, Context mContext) {
ArrayList arrContactModelList = new ArrayList();
Cursor cursor = null;
SQLiteDatabase db = this.getWritableDatabase();
if (isDeleted) {
cursor = db.query(TABLE_NAME_CONTACTS_LOGBOOK, null, ContactKey.STATUS + "=? ", new String[]{mContext.getString(R.string.deleted)}, null, null, null, null);
} else {
cursor = db.query(TABLE_NAME_CONTACTS_LOGBOOK, null, ContactKey.CONTACT_ID + "=? AND " + ContactKey.STATUS + "!=? ", new String[]{contactId, mContext.getString(R.string.deleted)}, null, null, null, null);
}
if (cursor.moveToFirst()) {
do {
ContactModel mContactModel = new ContactModel();
mContactModel.setId(cursor.getString(cursor.getColumnIndex(ContactKey.ID)));
mContactModel.setContactsId(cursor.getString(cursor.getColumnIndex(ContactKey.CONTACT_ID)));
mContactModel.setFistname(cursor.getString(cursor.getColumnIndex(ContactKey.FIRST_NAME)));
mContactModel.setLastname(cursor.getString(cursor.getColumnIndex(ContactKey.LAST_NAME)));
mContactModel.setCreatedDate(cursor.getString(cursor.getColumnIndex(ContactKey.CREATED_DATE)));
mContactModel.setMobileNumber(cursor.getString(cursor.getColumnIndex(ContactKey.MOBILE_NUMBER)));
mContactModel.setCity(cursor.getString(cursor.getColumnIndex(ContactKey.CITY)));
mContactModel.setState(cursor.getString(cursor.getColumnIndex(ContactKey.STATE)));
mContactModel.setCountry(cursor.getString(cursor.getColumnIndex(ContactKey.COUNTRY)));
mContactModel.setLocationName(cursor.getString(cursor.getColumnIndex(ContactKey.LOCATIONNAME)));
mContactModel.setWebSite(cursor.getString(cursor.getColumnIndex(ContactKey.WEBSITE)));
mContactModel.setImageUri(cursor.getString(cursor.getColumnIndex(ContactKey.IMAGE_URI)));
mContactModel.setSip(cursor.getString(cursor.getColumnIndex(ContactKey.SIP)));
mContactModel.setEventAnnivesaryDate(cursor.getString(cursor.getColumnIndex(ContactKey.EVENT_ANNIVERSARYDATE)));
mContactModel.setEmailHome(cursor.getString(cursor.getColumnIndex(ContactKey.HOME_EMAIL_ID)));
mContactModel.setEmailWork(cursor.getString(cursor.getColumnIndex(ContactKey.WORK_EMAIL_ID)));
mContactModel.setEmailOther(cursor.getString(cursor.getColumnIndex(ContactKey.OTHERS_EMAIL_ID)));
mContactModel.setLatlong(cursor.getString(cursor.getColumnIndex(ContactKey.LATLONG)));
mContactModel.setEventBirthDate(cursor.getString(cursor.getColumnIndex(ContactKey.EVENT_BIRTHDATE)));
mContactModel.setCompany(cursor.getString(cursor.getColumnIndex(ContactKey.COMPANY)));
mContactModel.setImAim(cursor.getString(cursor.getColumnIndex(ContactKey.IM_AIM)));
mContactModel.setAddressHome(cursor.getString(cursor.getColumnIndex(ContactKey.ADDRESS_HOME)));
mContactModel.setStatus(cursor.getString(cursor.getColumnIndex(ContactKey.STATUS)));
mContactModel.setRelationAssistant(cursor.getString(cursor.getColumnIndex(ContactKey.RELATION_ASSISTNT)));
mContactModel.setNotes(cursor.getString(cursor.getColumnIndex(ContactKey.NOTES)));
mContactModel.setUpdatedDate(cursor.getString(cursor.getColumnIndex(ContactKey.LAST_UPDATE_DATE)));
mContactModel.setEditedField(cursor.getString(cursor.getColumnIndex(ContactKey.EDITED_FIELD)));
arrContactModelList.add(mContactModel);
} while (cursor.moveToNext());
}
Collections.sort(arrContactModelList, new LastUpdateDateComparator());
cursor.close();
db.close();
return arrContactModelList;
}
public ArrayList selectAllLogContactsWithStatusNewEdit(boolean isDeleted, Activity activity) {
ArrayList arrContactModelList = new ArrayList<>();
Cursor cursor = null;
Cursor cursorDel = null;
SQLiteDatabase db = this.getWritableDatabase();
String deletedIds = "";
cursorDel = db.query(TABLE_NAME_CONTACTS_LOGBOOK, null, ContactKey.STATUS + "=? ", new String[]{"Deleted"}, null, null, ContactKey.LAST_UPDATE_DATE + " DESC");
//cursorDel = db.query(TABLE_NAME_CONTACTS_LOGBOOK, null, ContactKey.STATUS + "=? ", new String[]{"Deleted"}, null, null, null, null);
if (cursorDel.getCount() > 0) {
if (cursorDel.moveToFirst()) {
do {
//Log.d("deletedIds","deletedIds=="+cursorDel.getString(cursorDel.getColumnIndex(ContactKey.CONTACT_ID)));
if (deletedIds.isEmpty()) {
deletedIds = cursorDel.getString(cursorDel.getColumnIndex(ContactKey.CONTACT_ID));
} else {
deletedIds = deletedIds + "," + cursorDel.getString(cursorDel.getColumnIndex(ContactKey.CONTACT_ID));
}
} while (cursorDel.moveToNext());
}
cursorDel.close();
}
if (isDeleted) {
cursor = db.query(TABLE_NAME_CONTACTS_LOGBOOK, null, ContactKey.STATUS + "=? ", new String[]{activity.getString(R.string.deleted)}, null, null, null, null);
} else {
if (deletedIds.isEmpty()) {
cursor = db.query(TABLE_NAME_CONTACTS_LOGBOOK, null, ContactKey.STATUS + "=? OR " + ContactKey.STATUS + "=? OR " + ContactKey.STATUS + "=?", new String[]{activity.getString(R.string.added), activity.getString(R.string.modified), activity.getString(R.string.recovered)}, null, null, null, null);
} else {
cursor = db.query(TABLE_NAME_CONTACTS_LOGBOOK, null, ContactKey.CONTACT_ID + " NOT IN(" + deletedIds + ")", null, null, null, null);
}
}
if (cursor.moveToFirst()) {
do {
ContactModel mContactModel = new ContactModel();
mContactModel.setId(cursor.getString(cursor.getColumnIndex(ContactKey.ID)));
mContactModel.setContactsId(cursor.getString(cursor.getColumnIndex(ContactKey.CONTACT_ID)));
mContactModel.setFistname(cursor.getString(cursor.getColumnIndex(ContactKey.FIRST_NAME)));
mContactModel.setLastname(cursor.getString(cursor.getColumnIndex(ContactKey.LAST_NAME)));
mContactModel.setCreatedDate(cursor.getString(cursor.getColumnIndex(ContactKey.CREATED_DATE)));
mContactModel.setMobileNumber(cursor.getString(cursor.getColumnIndex(ContactKey.MOBILE_NUMBER)));
mContactModel.setCity(cursor.getString(cursor.getColumnIndex(ContactKey.CITY)));
mContactModel.setState(cursor.getString(cursor.getColumnIndex(ContactKey.STATE)));
mContactModel.setLocationName(cursor.getString(cursor.getColumnIndex(ContactKey.LOCATIONNAME)));
mContactModel.setWebSite(cursor.getString(cursor.getColumnIndex(ContactKey.WEBSITE)));
mContactModel.setImageUri(cursor.getString(cursor.getColumnIndex(ContactKey.IMAGE_URI)));
mContactModel.setSip(cursor.getString(cursor.getColumnIndex(ContactKey.SIP)));
mContactModel.setEventAnnivesaryDate(cursor.getString(cursor.getColumnIndex(ContactKey.EVENT_ANNIVERSARYDATE)));
mContactModel.setEmailHome(cursor.getString(cursor.getColumnIndex(ContactKey.HOME_EMAIL_ID)));
mContactModel.setEmailWork(cursor.getString(cursor.getColumnIndex(ContactKey.WORK_EMAIL_ID)));
mContactModel.setEmailOther(cursor.getString(cursor.getColumnIndex(ContactKey.OTHERS_EMAIL_ID)));
mContactModel.setLatlong(cursor.getString(cursor.getColumnIndex(ContactKey.LATLONG)));
mContactModel.setEventBirthDate(cursor.getString(cursor.getColumnIndex(ContactKey.EVENT_BIRTHDATE)));
mContactModel.setCompany(cursor.getString(cursor.getColumnIndex(ContactKey.COMPANY)));
mContactModel.setImAim(cursor.getString(cursor.getColumnIndex(ContactKey.IM_AIM)));
mContactModel.setAddressHome(cursor.getString(cursor.getColumnIndex(ContactKey.ADDRESS_HOME)));
mContactModel.setStatus(cursor.getString(cursor.getColumnIndex(ContactKey.STATUS)));
mContactModel.setRelationAssistant(cursor.getString(cursor.getColumnIndex(ContactKey.RELATION_ASSISTNT)));
mContactModel.setNotes(cursor.getString(cursor.getColumnIndex(ContactKey.NOTES)));
mContactModel.setUpdatedDate(cursor.getString(cursor.getColumnIndex(ContactKey.LAST_UPDATE_DATE)));
mContactModel.setEditedField(cursor.getString(cursor.getColumnIndex(ContactKey.EDITED_FIELD)));
arrContactModelList.add(mContactModel);
} while (cursor.moveToNext());
}
if (arrContactModelList.size() > 0)
Collections.sort(arrContactModelList, new LastUpdateDateComparator());
cursor.close();
db.close();
return arrContactModelList;
}
public ArrayList selectAllLogContactsWithStatus(boolean isDeleted, Activity activity) {
ArrayList arrContactModelList = new ArrayList();
Cursor cursor = null;
SQLiteDatabase db = this.getWritableDatabase();
//Log.d("isDeleted", "isDeleted==" + isDeleted);
if (isDeleted) {
cursor = db.query(TABLE_NAME_CONTACTS_LOGBOOK, null, ContactKey.STATUS + "=? ", new String[]{activity.getString(R.string.deleted)}, null, null, null, null);
} else {
// cursor = db.query(TABLE_NAME_CONTACTS_LOGBOOK, null, ContactKey.STATUS + "=? OR " + ContactKey.STATUS + "=? ", new String[]{activity.getString(R.string.added), activity.getString(R.string.modified)}, null, null, null, null);
final String query = "SELECT * FROM " + TABLE_NAME_CONTACTS_LOGBOOK + " WHERE " + ContactKey.STATUS + "!='Deleted'";
cursor = db.rawQuery(query, null);
}
if (cursor.moveToFirst()) {
do {
ContactModel mContactModel = new ContactModel();
mContactModel.setId(cursor.getString(cursor.getColumnIndex(ContactKey.ID)));
mContactModel.setContactsId(cursor.getString(cursor.getColumnIndex(ContactKey.CONTACT_ID)));
mContactModel.setFistname(cursor.getString(cursor.getColumnIndex(ContactKey.FIRST_NAME)));
mContactModel.setLastname(cursor.getString(cursor.getColumnIndex(ContactKey.LAST_NAME)));
mContactModel.setCreatedDate(cursor.getString(cursor.getColumnIndex(ContactKey.CREATED_DATE)));
mContactModel.setMobileNumber(cursor.getString(cursor.getColumnIndex(ContactKey.MOBILE_NUMBER)));
mContactModel.setCity(cursor.getString(cursor.getColumnIndex(ContactKey.CITY)));
mContactModel.setState(cursor.getString(cursor.getColumnIndex(ContactKey.STATE)));
mContactModel.setLocationName(cursor.getString(cursor.getColumnIndex(ContactKey.LOCATIONNAME)));
mContactModel.setWebSite(cursor.getString(cursor.getColumnIndex(ContactKey.WEBSITE)));
mContactModel.setImageUri(cursor.getString(cursor.getColumnIndex(ContactKey.IMAGE_URI)));
mContactModel.setSip(cursor.getString(cursor.getColumnIndex(ContactKey.SIP)));
mContactModel.setEventAnnivesaryDate(cursor.getString(cursor.getColumnIndex(ContactKey.EVENT_ANNIVERSARYDATE)));
mContactModel.setEmailHome(cursor.getString(cursor.getColumnIndex(ContactKey.HOME_EMAIL_ID)));
mContactModel.setEmailWork(cursor.getString(cursor.getColumnIndex(ContactKey.WORK_EMAIL_ID)));
mContactModel.setEmailOther(cursor.getString(cursor.getColumnIndex(ContactKey.OTHERS_EMAIL_ID)));
mContactModel.setLatlong(cursor.getString(cursor.getColumnIndex(ContactKey.LATLONG)));
mContactModel.setEventBirthDate(cursor.getString(cursor.getColumnIndex(ContactKey.EVENT_BIRTHDATE)));
mContactModel.setCompany(cursor.getString(cursor.getColumnIndex(ContactKey.COMPANY)));
mContactModel.setImAim(cursor.getString(cursor.getColumnIndex(ContactKey.IM_AIM)));
mContactModel.setAddressHome(cursor.getString(cursor.getColumnIndex(ContactKey.ADDRESS_HOME)));
mContactModel.setStatus(cursor.getString(cursor.getColumnIndex(ContactKey.STATUS)));
mContactModel.setRelationAssistant(cursor.getString(cursor.getColumnIndex(ContactKey.RELATION_ASSISTNT)));
mContactModel.setNotes(cursor.getString(cursor.getColumnIndex(ContactKey.NOTES)));
mContactModel.setUpdatedDate(cursor.getString(cursor.getColumnIndex(ContactKey.LAST_UPDATE_DATE)));
mContactModel.setEditedField(cursor.getString(cursor.getColumnIndex(ContactKey.EDITED_FIELD)));
arrContactModelList.add(mContactModel);
} while (cursor.moveToNext());
}
if (arrContactModelList.size() > 0)
Collections.sort(arrContactModelList, new LastUpdateDateComparator());
cursor.close();
db.close();
return arrContactModelList;
}
public ArrayList selectAllLogContactsWithStatus(String delStatus) {
ArrayList arrContactModelList = new ArrayList();
Cursor cursor = null;
SQLiteDatabase db = this.getWritableDatabase();
cursor = db.query(TABLE_NAME_CONTACTS_LOGBOOK, null, ContactKey.STATUS + "=? ", new String[]{delStatus}, null, null, ContactKey.LAST_UPDATE_DATE + " DESC");
if (cursor.moveToFirst()) {
do {
ContactModel mContactModel = new ContactModel();
mContactModel.setId(cursor.getString(cursor.getColumnIndex(ContactKey.ID)));
mContactModel.setContactsId(cursor.getString(cursor.getColumnIndex(ContactKey.CONTACT_ID)));
mContactModel.setFistname(cursor.getString(cursor.getColumnIndex(ContactKey.FIRST_NAME)));
mContactModel.setLastname(cursor.getString(cursor.getColumnIndex(ContactKey.LAST_NAME)));
mContactModel.setCreatedDate(cursor.getString(cursor.getColumnIndex(ContactKey.CREATED_DATE)));
mContactModel.setMobileNumber(cursor.getString(cursor.getColumnIndex(ContactKey.MOBILE_NUMBER)));
mContactModel.setCity(cursor.getString(cursor.getColumnIndex(ContactKey.CITY)));
mContactModel.setState(cursor.getString(cursor.getColumnIndex(ContactKey.STATE)));
mContactModel.setLocationName(cursor.getString(cursor.getColumnIndex(ContactKey.LOCATIONNAME)));
mContactModel.setWebSite(cursor.getString(cursor.getColumnIndex(ContactKey.WEBSITE)));
mContactModel.setImageUri(cursor.getString(cursor.getColumnIndex(ContactKey.IMAGE_URI)));
mContactModel.setSip(cursor.getString(cursor.getColumnIndex(ContactKey.SIP)));
mContactModel.setEventAnnivesaryDate(cursor.getString(cursor.getColumnIndex(ContactKey.EVENT_ANNIVERSARYDATE)));
mContactModel.setEmailHome(cursor.getString(cursor.getColumnIndex(ContactKey.HOME_EMAIL_ID)));
mContactModel.setEmailWork(cursor.getString(cursor.getColumnIndex(ContactKey.WORK_EMAIL_ID)));
mContactModel.setEmailOther(cursor.getString(cursor.getColumnIndex(ContactKey.OTHERS_EMAIL_ID)));
mContactModel.setLatlong(cursor.getString(cursor.getColumnIndex(ContactKey.LATLONG)));
mContactModel.setEventBirthDate(cursor.getString(cursor.getColumnIndex(ContactKey.EVENT_BIRTHDATE)));
mContactModel.setCompany(cursor.getString(cursor.getColumnIndex(ContactKey.COMPANY)));
mContactModel.setImAim(cursor.getString(cursor.getColumnIndex(ContactKey.IM_AIM)));
mContactModel.setAddressHome(cursor.getString(cursor.getColumnIndex(ContactKey.ADDRESS_HOME)));
mContactModel.setStatus(cursor.getString(cursor.getColumnIndex(ContactKey.STATUS)));
mContactModel.setRelationAssistant(cursor.getString(cursor.getColumnIndex(ContactKey.RELATION_ASSISTNT)));
mContactModel.setNotes(cursor.getString(cursor.getColumnIndex(ContactKey.NOTES)));
mContactModel.setUpdatedDate(cursor.getString(cursor.getColumnIndex(ContactKey.LAST_UPDATE_DATE)));
mContactModel.setEditedField(cursor.getString(cursor.getColumnIndex(ContactKey.EDITED_FIELD)));
arrContactModelList.add(mContactModel);
} while (cursor.moveToNext());
}
cursor.close();
db.close();
return arrContactModelList;
}
public ArrayList selectAllLogContactsByContactIdAndMdate(final String contactId, final String mdate) {
ArrayList arrConatacsLogModelList = new ArrayList<>();
Cursor cursor = null;
SQLiteDatabase db = this.getWritableDatabase();
cursor = db.query(TABLE_NAME_CONTACTS_LOGBOOK, null, ContactKey.CONTACT_ID + "=? AND " + ContactKey.LAST_UPDATE_DATE + "=? ", new String[]{contactId, mdate}, null, null, null);
if (cursor.moveToFirst()) {
do {
ContactModel mContactModel = new ContactModel();
mContactModel.setId(cursor.getString(cursor.getColumnIndex(ContactKey.ID)));
mContactModel.setContactsId(cursor.getString(cursor.getColumnIndex(ContactKey.CONTACT_ID)));
mContactModel.setFistname(cursor.getString(cursor.getColumnIndex(ContactKey.FIRST_NAME)));
mContactModel.setLastname(cursor.getString(cursor.getColumnIndex(ContactKey.LAST_NAME)));
mContactModel.setCreatedDate(cursor.getString(cursor.getColumnIndex(ContactKey.CREATED_DATE)));
mContactModel.setMobileNumber(cursor.getString(cursor.getColumnIndex(ContactKey.MOBILE_NUMBER)));
mContactModel.setHomeMobileNumber(cursor.getString(cursor.getColumnIndex(ContactKey.HOME_MOBILE_NUMBER)));
mContactModel.setCustmeMobileNumber(cursor.getString(cursor.getColumnIndex(ContactKey.CUSTOME_MOBILE_NUMBER)));
mContactModel.setFaxHomeMobileNumber(cursor.getString(cursor.getColumnIndex(ContactKey.FAX_HOME_MOBILE_NUMBER)));
mContactModel.setWorkFaxMobileNumber(cursor.getString(cursor.getColumnIndex(ContactKey.WORK_FAX_MOBILE_NUMBER)));
mContactModel.setWorkMobileNumber(cursor.getString(cursor.getColumnIndex(ContactKey.WORK_MOBILE_NUMBER)));
mContactModel.setMainMobileNumber(cursor.getString(cursor.getColumnIndex(ContactKey.MAIN_MOBILE_NUMBER)));
mContactModel.setOthersMobileNumber(cursor.getString(cursor.getColumnIndex(ContactKey.OTHERS_MOBILE_NUMBER)));
mContactModel.setPagerMobileNumber(cursor.getString(cursor.getColumnIndex(ContactKey.PAGER_MOBILE_NUMBER)));
mContactModel.setCity(cursor.getString(cursor.getColumnIndex(ContactKey.CITY)));
mContactModel.setState(cursor.getString(cursor.getColumnIndex(ContactKey.STATE)));
mContactModel.setLocationName(cursor.getString(cursor.getColumnIndex(ContactKey.LOCATIONNAME)));
mContactModel.setWebSite(cursor.getString(cursor.getColumnIndex(ContactKey.WEBSITE)));
mContactModel.setImageUri(cursor.getString(cursor.getColumnIndex(ContactKey.IMAGE_URI)));
mContactModel.setSip(cursor.getString(cursor.getColumnIndex(ContactKey.SIP)));
mContactModel.setEventAnnivesaryDate(cursor.getString(cursor.getColumnIndex(ContactKey.EVENT_ANNIVERSARYDATE)));
mContactModel.setEmailHome(cursor.getString(cursor.getColumnIndex(ContactKey.HOME_EMAIL_ID)));
mContactModel.setEmailWork(cursor.getString(cursor.getColumnIndex(ContactKey.WORK_EMAIL_ID)));
mContactModel.setEmailOther(cursor.getString(cursor.getColumnIndex(ContactKey.OTHERS_EMAIL_ID)));
mContactModel.setLatlong(cursor.getString(cursor.getColumnIndex(ContactKey.LATLONG)));
mContactModel.setEventBirthDate(cursor.getString(cursor.getColumnIndex(ContactKey.EVENT_BIRTHDATE)));
mContactModel.setCompany(cursor.getString(cursor.getColumnIndex(ContactKey.COMPANY)));
mContactModel.setImAim(cursor.getString(cursor.getColumnIndex(ContactKey.IM_AIM)));
mContactModel.setAddressHome(cursor.getString(cursor.getColumnIndex(ContactKey.ADDRESS_HOME)));
mContactModel.setAddressCustome(cursor.getString(cursor.getColumnIndex(ContactKey.ADDRESS_CUSTOME)));
mContactModel.setAddressWork(cursor.getString(cursor.getColumnIndex(ContactKey.ADDRESS_WORK)));
mContactModel.setAddressOther(cursor.getString(cursor.getColumnIndex(ContactKey.ADDRESS_OTHER)));
mContactModel.setStatus(cursor.getString(cursor.getColumnIndex(ContactKey.STATUS)));
mContactModel.setRelationAssistant(cursor.getString(cursor.getColumnIndex(ContactKey.RELATION_ASSISTNT)));
mContactModel.setUpdatedDate(cursor.getString(cursor.getColumnIndex(ContactKey.LAST_UPDATE_DATE)));
mContactModel.setNotes(cursor.getString(cursor.getColumnIndex(ContactKey.NOTES)));
mContactModel.setEditedField(cursor.getString(cursor.getColumnIndex(ContactKey.EDITED_FIELD)));
arrConatacsLogModelList.add(mContactModel);
} while (cursor.moveToNext());
}
cursor.close();
return arrConatacsLogModelList;
}
public ContactModel selectLogContactsByContactIdAndMdate(final String contactId, final String mdate) {
ContactModel mContactModel = new ContactModel();
Cursor cursor = null;
SQLiteDatabase db = this.getWritableDatabase();
cursor = db.query(TABLE_NAME_CONTACTS_LOGBOOK, null, ContactKey.CONTACT_ID + "=? AND " + ContactKey.LAST_UPDATE_DATE + "=? ", new String[]{contactId, mdate}, null, null, null);
if (cursor.moveToFirst()) {
do {
mContactModel.setId(cursor.getString(cursor.getColumnIndex(ContactKey.ID)));
mContactModel.setContactsId(cursor.getString(cursor.getColumnIndex(ContactKey.CONTACT_ID)));
mContactModel.setFistname(cursor.getString(cursor.getColumnIndex(ContactKey.FIRST_NAME)));
mContactModel.setLastname(cursor.getString(cursor.getColumnIndex(ContactKey.LAST_NAME)));
mContactModel.setCreatedDate(cursor.getString(cursor.getColumnIndex(ContactKey.CREATED_DATE)));
mContactModel.setMobileNumber(cursor.getString(cursor.getColumnIndex(ContactKey.MOBILE_NUMBER)));
mContactModel.setHomeMobileNumber(cursor.getString(cursor.getColumnIndex(ContactKey.HOME_MOBILE_NUMBER)));
mContactModel.setCustmeMobileNumber(cursor.getString(cursor.getColumnIndex(ContactKey.CUSTOME_MOBILE_NUMBER)));
mContactModel.setFaxHomeMobileNumber(cursor.getString(cursor.getColumnIndex(ContactKey.FAX_HOME_MOBILE_NUMBER)));
mContactModel.setWorkFaxMobileNumber(cursor.getString(cursor.getColumnIndex(ContactKey.WORK_FAX_MOBILE_NUMBER)));
mContactModel.setWorkMobileNumber(cursor.getString(cursor.getColumnIndex(ContactKey.WORK_MOBILE_NUMBER)));
mContactModel.setMainMobileNumber(cursor.getString(cursor.getColumnIndex(ContactKey.MAIN_MOBILE_NUMBER)));
mContactModel.setOthersMobileNumber(cursor.getString(cursor.getColumnIndex(ContactKey.OTHERS_MOBILE_NUMBER)));
mContactModel.setPagerMobileNumber(cursor.getString(cursor.getColumnIndex(ContactKey.PAGER_MOBILE_NUMBER)));
mContactModel.setCity(cursor.getString(cursor.getColumnIndex(ContactKey.CITY)));
mContactModel.setState(cursor.getString(cursor.getColumnIndex(ContactKey.STATE)));
mContactModel.setLocationName(cursor.getString(cursor.getColumnIndex(ContactKey.LOCATIONNAME)));
mContactModel.setWebSite(cursor.getString(cursor.getColumnIndex(ContactKey.WEBSITE)));
mContactModel.setImageUri(cursor.getString(cursor.getColumnIndex(ContactKey.IMAGE_URI)));
mContactModel.setSip(cursor.getString(cursor.getColumnIndex(ContactKey.SIP)));
mContactModel.setEventAnnivesaryDate(cursor.getString(cursor.getColumnIndex(ContactKey.EVENT_ANNIVERSARYDATE)));
mContactModel.setEmailHome(cursor.getString(cursor.getColumnIndex(ContactKey.HOME_EMAIL_ID)));
mContactModel.setEmailWork(cursor.getString(cursor.getColumnIndex(ContactKey.WORK_EMAIL_ID)));
mContactModel.setEmailOther(cursor.getString(cursor.getColumnIndex(ContactKey.OTHERS_EMAIL_ID)));
mContactModel.setLatlong(cursor.getString(cursor.getColumnIndex(ContactKey.LATLONG)));
mContactModel.setEventBirthDate(cursor.getString(cursor.getColumnIndex(ContactKey.EVENT_BIRTHDATE)));
mContactModel.setCompany(cursor.getString(cursor.getColumnIndex(ContactKey.COMPANY)));
mContactModel.setImAim(cursor.getString(cursor.getColumnIndex(ContactKey.IM_AIM)));
mContactModel.setAddressHome(cursor.getString(cursor.getColumnIndex(ContactKey.ADDRESS_HOME)));
mContactModel.setAddressCustome(cursor.getString(cursor.getColumnIndex(ContactKey.ADDRESS_CUSTOME)));
mContactModel.setAddressWork(cursor.getString(cursor.getColumnIndex(ContactKey.ADDRESS_WORK)));
mContactModel.setAddressOther(cursor.getString(cursor.getColumnIndex(ContactKey.ADDRESS_OTHER)));
mContactModel.setStatus(cursor.getString(cursor.getColumnIndex(ContactKey.STATUS)));
mContactModel.setRelationAssistant(cursor.getString(cursor.getColumnIndex(ContactKey.RELATION_ASSISTNT)));
mContactModel.setUpdatedDate(cursor.getString(cursor.getColumnIndex(ContactKey.LAST_UPDATE_DATE)));
mContactModel.setNotes(cursor.getString(cursor.getColumnIndex(ContactKey.NOTES)));
mContactModel.setEditedField(cursor.getString(cursor.getColumnIndex(ContactKey.EDITED_FIELD)));
} while (cursor.moveToNext());
}
cursor.close();
db.close();
return mContactModel;
}
public ContactModel selectAllLogContactsByContactId(final String contactId, final String Id) {
ContactModel mContactModel = new ContactModel();
Cursor cursor = null;
SQLiteDatabase db = this.getWritableDatabase();
cursor = db.query(TABLE_NAME_CONTACTS_LOGBOOK, null, ContactKey.CONTACT_ID + "=? AND " + ContactKey.ID + "=? ", new String[]{contactId, Id}, null, null, null);
if (cursor.moveToFirst()) {
do {
mContactModel.setId(cursor.getString(cursor.getColumnIndex(ContactKey.ID)));
mContactModel.setContactsId(cursor.getString(cursor.getColumnIndex(ContactKey.CONTACT_ID)));
mContactModel.setFistname(cursor.getString(cursor.getColumnIndex(ContactKey.FIRST_NAME)));
mContactModel.setLastname(cursor.getString(cursor.getColumnIndex(ContactKey.LAST_NAME)));
mContactModel.setCreatedDate(cursor.getString(cursor.getColumnIndex(ContactKey.CREATED_DATE)));
mContactModel.setMobileNumber(cursor.getString(cursor.getColumnIndex(ContactKey.MOBILE_NUMBER)));
mContactModel.setHomeMobileNumber(cursor.getString(cursor.getColumnIndex(ContactKey.HOME_MOBILE_NUMBER)));
mContactModel.setCustmeMobileNumber(cursor.getString(cursor.getColumnIndex(ContactKey.CUSTOME_MOBILE_NUMBER)));
mContactModel.setFaxHomeMobileNumber(cursor.getString(cursor.getColumnIndex(ContactKey.FAX_HOME_MOBILE_NUMBER)));
mContactModel.setWorkFaxMobileNumber(cursor.getString(cursor.getColumnIndex(ContactKey.WORK_FAX_MOBILE_NUMBER)));
mContactModel.setWorkMobileNumber(cursor.getString(cursor.getColumnIndex(ContactKey.WORK_MOBILE_NUMBER)));
mContactModel.setMainMobileNumber(cursor.getString(cursor.getColumnIndex(ContactKey.MAIN_MOBILE_NUMBER)));
mContactModel.setOthersMobileNumber(cursor.getString(cursor.getColumnIndex(ContactKey.OTHERS_MOBILE_NUMBER)));
mContactModel.setPagerMobileNumber(cursor.getString(cursor.getColumnIndex(ContactKey.PAGER_MOBILE_NUMBER)));
mContactModel.setCity(cursor.getString(cursor.getColumnIndex(ContactKey.CITY)));
mContactModel.setState(cursor.getString(cursor.getColumnIndex(ContactKey.STATE)));
mContactModel.setLocationName(cursor.getString(cursor.getColumnIndex(ContactKey.LOCATIONNAME)));
mContactModel.setWebSite(cursor.getString(cursor.getColumnIndex(ContactKey.WEBSITE)));
mContactModel.setImageUri(cursor.getString(cursor.getColumnIndex(ContactKey.IMAGE_URI)));
mContactModel.setSip(cursor.getString(cursor.getColumnIndex(ContactKey.SIP)));
mContactModel.setEventAnnivesaryDate(cursor.getString(cursor.getColumnIndex(ContactKey.EVENT_ANNIVERSARYDATE)));
mContactModel.setEmailHome(cursor.getString(cursor.getColumnIndex(ContactKey.HOME_EMAIL_ID)));
mContactModel.setEmailWork(cursor.getString(cursor.getColumnIndex(ContactKey.WORK_EMAIL_ID)));
mContactModel.setEmailOther(cursor.getString(cursor.getColumnIndex(ContactKey.OTHERS_EMAIL_ID)));
mContactModel.setLatlong(cursor.getString(cursor.getColumnIndex(ContactKey.LATLONG)));
mContactModel.setEventBirthDate(cursor.getString(cursor.getColumnIndex(ContactKey.EVENT_BIRTHDATE)));
mContactModel.setCompany(cursor.getString(cursor.getColumnIndex(ContactKey.COMPANY)));
mContactModel.setImAim(cursor.getString(cursor.getColumnIndex(ContactKey.IM_AIM)));
mContactModel.setAddressHome(cursor.getString(cursor.getColumnIndex(ContactKey.ADDRESS_HOME)));
mContactModel.setAddressCustome(cursor.getString(cursor.getColumnIndex(ContactKey.ADDRESS_CUSTOME)));
mContactModel.setAddressWork(cursor.getString(cursor.getColumnIndex(ContactKey.ADDRESS_WORK)));
mContactModel.setAddressOther(cursor.getString(cursor.getColumnIndex(ContactKey.ADDRESS_OTHER)));
mContactModel.setStatus(cursor.getString(cursor.getColumnIndex(ContactKey.STATUS)));
mContactModel.setRelationAssistant(cursor.getString(cursor.getColumnIndex(ContactKey.RELATION_ASSISTNT)));
mContactModel.setUpdatedDate(cursor.getString(cursor.getColumnIndex(ContactKey.LAST_UPDATE_DATE)));
mContactModel.setNotes(cursor.getString(cursor.getColumnIndex(ContactKey.NOTES)));
} while (cursor.moveToNext());
}
cursor.close();
db.close();
return mContactModel;
}
public ContactModel selectAllContactsByContactId(String contactId) {
ContactModel mContactModel = new ContactModel();
Cursor cursor = null;
SQLiteDatabase db = this.getWritableDatabase();
cursor = db.query(TABLE_NAME_CONTACTS, null, ContactKey.CONTACT_ID + "=?", new String[]{contactId}, null, null, null);
if (cursor.moveToFirst()) {
do {
mContactModel.setId(cursor.getString(cursor.getColumnIndex(ContactKey.ID)));
mContactModel.setContactsId(cursor.getString(cursor.getColumnIndex(ContactKey.CONTACT_ID)));
mContactModel.setFistname(cursor.getString(cursor.getColumnIndex(ContactKey.FIRST_NAME)));
mContactModel.setLastname(cursor.getString(cursor.getColumnIndex(ContactKey.LAST_NAME)));
mContactModel.setCreatedDate(cursor.getString(cursor.getColumnIndex(ContactKey.CREATED_DATE)));
mContactModel.setMobileNumber(cursor.getString(cursor.getColumnIndex(ContactKey.MOBILE_NUMBER)));
mContactModel.setHomeMobileNumber(cursor.getString(cursor.getColumnIndex(ContactKey.HOME_MOBILE_NUMBER)));
mContactModel.setCustmeMobileNumber(cursor.getString(cursor.getColumnIndex(ContactKey.CUSTOME_MOBILE_NUMBER)));
mContactModel.setFaxHomeMobileNumber(cursor.getString(cursor.getColumnIndex(ContactKey.FAX_HOME_MOBILE_NUMBER)));
mContactModel.setWorkFaxMobileNumber(cursor.getString(cursor.getColumnIndex(ContactKey.WORK_FAX_MOBILE_NUMBER)));
mContactModel.setWorkMobileNumber(cursor.getString(cursor.getColumnIndex(ContactKey.WORK_MOBILE_NUMBER)));
mContactModel.setMainMobileNumber(cursor.getString(cursor.getColumnIndex(ContactKey.MAIN_MOBILE_NUMBER)));
mContactModel.setOthersMobileNumber(cursor.getString(cursor.getColumnIndex(ContactKey.OTHERS_MOBILE_NUMBER)));
mContactModel.setPagerMobileNumber(cursor.getString(cursor.getColumnIndex(ContactKey.PAGER_MOBILE_NUMBER)));
mContactModel.setCity(cursor.getString(cursor.getColumnIndex(ContactKey.CITY)));
mContactModel.setState(cursor.getString(cursor.getColumnIndex(ContactKey.STATE)));
mContactModel.setLocationName(cursor.getString(cursor.getColumnIndex(ContactKey.LOCATIONNAME)));
mContactModel.setWebSite(cursor.getString(cursor.getColumnIndex(ContactKey.WEBSITE)));
mContactModel.setImageUri(cursor.getString(cursor.getColumnIndex(ContactKey.IMAGE_URI)));
mContactModel.setSip(cursor.getString(cursor.getColumnIndex(ContactKey.SIP)));
mContactModel.setEventAnnivesaryDate(cursor.getString(cursor.getColumnIndex(ContactKey.EVENT_ANNIVERSARYDATE)));
mContactModel.setEmailHome(cursor.getString(cursor.getColumnIndex(ContactKey.HOME_EMAIL_ID)));
mContactModel.setEmailWork(cursor.getString(cursor.getColumnIndex(ContactKey.WORK_EMAIL_ID)));
mContactModel.setEmailOther(cursor.getString(cursor.getColumnIndex(ContactKey.OTHERS_EMAIL_ID)));
mContactModel.setLatlong(cursor.getString(cursor.getColumnIndex(ContactKey.LATLONG)));
mContactModel.setEventBirthDate(cursor.getString(cursor.getColumnIndex(ContactKey.EVENT_BIRTHDATE)));
mContactModel.setCompany(cursor.getString(cursor.getColumnIndex(ContactKey.COMPANY)));
mContactModel.setImAim(cursor.getString(cursor.getColumnIndex(ContactKey.IM_AIM)));
mContactModel.setAddressHome(cursor.getString(cursor.getColumnIndex(ContactKey.ADDRESS_HOME)));
mContactModel.setAddressCustome(cursor.getString(cursor.getColumnIndex(ContactKey.ADDRESS_CUSTOME)));
mContactModel.setAddressWork(cursor.getString(cursor.getColumnIndex(ContactKey.ADDRESS_WORK)));
mContactModel.setAddressOther(cursor.getString(cursor.getColumnIndex(ContactKey.ADDRESS_OTHER)));
mContactModel.setStatus(cursor.getString(cursor.getColumnIndex(ContactKey.STATUS)));
mContactModel.setRelationAssistant(cursor.getString(cursor.getColumnIndex(ContactKey.RELATION_ASSISTNT)));
mContactModel.setUpdatedDate(cursor.getString(cursor.getColumnIndex(ContactKey.LAST_UPDATE_DATE)));
mContactModel.setNotes(cursor.getString(cursor.getColumnIndex(ContactKey.NOTES)));
} while (cursor.moveToNext());
}
cursor.close();
db.close();
return mContactModel;
}
public ArrayList searchAllDetails(String searchKey) {
ArrayList arrContactList = new ArrayList<>();
Cursor cursor = null;
SQLiteDatabase db = this.getWritableDatabase();
String search = "";
search = "%" + searchKey + "%";
if (searchKey.contains("(") || searchKey.contains(")") || searchKey.contains("-")) {
searchKey = searchKey.replace("(", "");
searchKey = searchKey.replace(")", "");
searchKey = searchKey.replace("-", "");
}
if (searchKey.matches("[0-9 $]+")) {
search = "%" + searchKey.replace(" ", "") + "%";
}
String selectQuery = " select * from " + TABLE_NAME_CONTACTS + " where " +
ContactKey.FIRST_NAME + " like '" + search + "' or " +
ContactKey.LAST_NAME + " like '" + search + "' or " +
"REPLACE(" + ContactKey.FULL_NAME + ",' ','')" + " like '" + search + "' or " +
"REPLACE(REPLACE(REPLACE(REPLACE(" + ContactKey.MOBILE_NUMBER + ",' ',''),'-',''),'(',''),')','')" + " like '" + search + "' or " +
"REPLACE(REPLACE(REPLACE(REPLACE(" + ContactKey.OTHERS_MOBILE_NUMBER + ",' ',''),'-',''),'(',''),')','')" + " like '" + search + "' or " +
"REPLACE(REPLACE(REPLACE(REPLACE(" + ContactKey.HOME_MOBILE_NUMBER + ",' ',''),'-',''),'(',''),')','')" + " like '" + search + "' or " +
"REPLACE(REPLACE(REPLACE(REPLACE(" + ContactKey.CUSTOME_MOBILE_NUMBER + ",' ',''),'-',''),'(',''),')','')" + " like '" + search + "' or " +
"REPLACE(REPLACE(REPLACE(REPLACE(" + ContactKey.PAGER_MOBILE_NUMBER + ",' ',''),'-',''),'(',''),')','')" + " like '" + search + "' or " +
"REPLACE(REPLACE(REPLACE(REPLACE(" + ContactKey.MAIN_MOBILE_NUMBER + ",' ',''),'-',''),'(',''),')','')" + " like '" + search + "' or " +
"REPLACE(REPLACE(REPLACE(REPLACE(" + ContactKey.FAX_HOME_MOBILE_NUMBER + ",' ',''),'-',''),'(',''),')','')" + " like '" + search + "' or " +
"REPLACE(REPLACE(REPLACE(REPLACE(" + ContactKey.WORK_MOBILE_NUMBER + ",' ',''),'-',''),'(',''),')','')" + " like '" + search + "' or " +
"REPLACE(REPLACE(REPLACE(REPLACE(" + ContactKey.WORK_FAX_MOBILE_NUMBER + ",' ',''),'-',''),'(',''),')','')" + " like '" + search + "' or " +
"REPLACE(REPLACE(REPLACE(REPLACE(" + ContactKey.FULL_NAME + ",' ',''),'-',''),'(',''),')','')" + " like '" + search + "' or " +
ContactKey.FULL_NAME + " like '" + search + "' or " +
ContactKey.MOBILE_NUMBER + " like '" + search + "' or " +
ContactKey.OTHERS_MOBILE_NUMBER + " like '" + search + "' or " +
ContactKey.HOME_MOBILE_NUMBER + " like '" + search + "' or " +
ContactKey.CUSTOME_MOBILE_NUMBER + " like '" + search + "' or " +
ContactKey.PAGER_MOBILE_NUMBER + " like '" + search + "' or " +
ContactKey.MAIN_MOBILE_NUMBER + " like '" + search + "' or " +
ContactKey.FAX_HOME_MOBILE_NUMBER + " like '" + search + "' or " +
ContactKey.WORK_MOBILE_NUMBER + " like '" + search + "' or " +
ContactKey.WORK_FAX_MOBILE_NUMBER + " like '" + search + "' or " +
ContactKey.LOCATIONNAME + " like '" + search + "' or " +
"REPLACE(" + ContactKey.CITY + ",' ','')" + " like '" + search + "' or " +
"REPLACE(" + ContactKey.ADDRESS_HOME + ",' ','')" + " like '" + search + "' or " +
"REPLACE(" + ContactKey.ADDRESS_OTHER + ",' ','')" + " like '" + search + "' or " +
"REPLACE(" + ContactKey.ADDRESS_WORK + ",' ','')" + " like '" + search + "' or " +
"REPLACE(" + ContactKey.ADDRESS_CUSTOME + ",' ','')" + " like '" + search + "' or " +
"REPLACE(" + ContactKey.STATE + ",' ','')" + " like '" + search + "' or " +
"REPLACE(" + ContactKey.WEBSITE + ",' ','')" + " like '" + search + "' or " +
"REPLACE(" + ContactKey.SIP + ",' ','')" + " like '" + search + "' or " +
"REPLACE(" + ContactKey.HOME_EMAIL_ID + ",' ','')" + " like '" + search + "' or " +
"REPLACE(" + ContactKey.WORK_EMAIL_ID + ",' ','')" + " like '" + search + "' or " +
"REPLACE(" + ContactKey.OTHERS_EMAIL_ID + ",' ','')" + " like '" + search + "' or " +
"REPLACE(" + ContactKey.COMPANY + ",' ','')" + " like '" + search + "' or " +
"REPLACE(" + ContactKey.COUNTRY + ",' ','')" + " like '" + search + "' or " +
ContactKey.COUNTRY + " like '" + search + "' or " +
ContactKey.CITY + " like '" + search + "' or " +
ContactKey.ADDRESS_HOME + " like '" + search + "' or " +
ContactKey.ADDRESS_OTHER + " like '" + search + "' or " +
ContactKey.ADDRESS_WORK + " like '" + search + "' or " +
ContactKey.ADDRESS_CUSTOME + " like '" + search + "' or " +
ContactKey.STATE + " like '" + search + "' or " +
ContactKey.WEBSITE + " like '" + search + "' or " +
ContactKey.SIP + " like '" + search + "' or " +
ContactKey.HOME_EMAIL_ID + " like '" + search + "' or " +
ContactKey.WORK_EMAIL_ID + " like '" + search + "' or " +
ContactKey.OTHERS_EMAIL_ID + " like '" + search + "' or " +
ContactKey.COMPANY + " like '" + search + "' or " +
ContactKey.IM_AIM + " like '" + search + "' or " +
"REPLACE(" + ContactKey.ADDRESS_HOME + ",' ','')" + " like '" + search + "' or " +
ContactKey.ADDRESS_HOME + " like '" + search + "' or " +
ContactKey.RELATION_ASSISTNT + " like '" + search + "' or " +
ContactKey.CREATED_DATE + " like '" + search + "' or " +
ContactKey.LAST_UPDATE_DATE + " like '" + search + "' or " +
ContactKey.NOTES + " like '" + search + "' or " +
"REPLACE(" + ContactKey.NOTES + ",' ','')" + " like '" + search + "'" + "Order By " + ContactKey.FIRST_NAME;
;
//cursor = db.query(TABLE_NAME_CONTACTS, null,name + " LIKE ?", new String[] {"%" + searchKey + "%"},null, null, null);
Log.e("TAG", selectQuery);
cursor = db.rawQuery(selectQuery, null);
if (cursor.moveToFirst()) {
do {
ContactModel mContactModel = new ContactModel();
mContactModel.setId(cursor.getString(cursor.getColumnIndex(ContactKey.ID)));
mContactModel.setContactsId(cursor.getString(cursor.getColumnIndex(ContactKey.CONTACT_ID)));
mContactModel.setFistname(cursor.getString(cursor.getColumnIndex(ContactKey.FIRST_NAME)));
mContactModel.setLastname(cursor.getString(cursor.getColumnIndex(ContactKey.LAST_NAME)));
mContactModel.setCreatedDate(cursor.getString(cursor.getColumnIndex(ContactKey.CREATED_DATE)));
arrContactList.add(mContactModel);
// Log.d("searchKey","FIRST_NAME==="+cursor.getString(cursor.getColumnIndex(ContactKey.FIRST_NAME)));
} while (cursor.moveToNext());
}
cursor.close();
db.close();
Collections.sort(arrContactList, new SortBasedOnName());
return arrContactList;
}
public ArrayList searchAllDetailsForPhoneBook(String searchKey) {
ArrayList arrContactList = new ArrayList<>();
Cursor cursor = null;
SQLiteDatabase db = this.getWritableDatabase();
// Log.d("searchKey","searchKey==="+searchKey);
//String name=ContactKey.FIRST_NAME+" AND "+ContactKey.LAST_NAME;
// String search = "%" + searchKey.replaceAll("\\s", "") + "%";
String search = "%" + searchKey + "%";
// if (searchKey.contains(")") && !searchKey.contains(") ")) {
// search = "%" + searchKey.replace(")", ") ") + "%";
// }
if (searchKey.contains("(") || searchKey.contains(")") || searchKey.contains("-")) {
searchKey = searchKey.replace("(", "");
searchKey = searchKey.replace(")", "");
searchKey = searchKey.replace("-", "");
}
if (searchKey.matches("[0-9 *$]+")) {
searchKey = searchKey.replaceAll("\\D+", "");
search = "%" + searchKey.replace(" ", "") + "%";
}
String selectQuery = " select * from " + TABLE_NAME_CONTACTS + " where " +
ContactKey.FIRST_NAME + " like '" + search + "' or " +
ContactKey.LAST_NAME + " like '" + search + "' or " +
"REPLACE(" + ContactKey.FULL_NAME + ",' ','')" + " like '" + search + "' or " +
"REPLACE(REPLACE(REPLACE(REPLACE(" + ContactKey.MOBILE_NUMBER + ",' ',''),'-',''),'(',''),')','')" + " like '" + search + "' or " +
"REPLACE(REPLACE(REPLACE(REPLACE(" + ContactKey.OTHERS_MOBILE_NUMBER + ",' ',''),'-',''),'(',''),')','')" + " like '" + search + "' or " +
"REPLACE(REPLACE(REPLACE(REPLACE(" + ContactKey.HOME_MOBILE_NUMBER + ",' ',''),'-',''),'(',''),')','')" + " like '" + search + "' or " +
"REPLACE(REPLACE(REPLACE(REPLACE(" + ContactKey.CUSTOME_MOBILE_NUMBER + ",' ',''),'-',''),'(',''),')','')" + " like '" + search + "' or " +
"REPLACE(REPLACE(REPLACE(REPLACE(" + ContactKey.PAGER_MOBILE_NUMBER + ",' ',''),'-',''),'(',''),')','')" + " like '" + search + "' or " +
"REPLACE(REPLACE(REPLACE(REPLACE(" + ContactKey.MAIN_MOBILE_NUMBER + ",' ',''),'-',''),'(',''),')','')" + " like '" + search + "' or " +
"REPLACE(REPLACE(REPLACE(REPLACE(" + ContactKey.FAX_HOME_MOBILE_NUMBER + ",' ',''),'-',''),'(',''),')','')" + " like '" + search + "' or " +
"REPLACE(REPLACE(REPLACE(REPLACE(" + ContactKey.WORK_MOBILE_NUMBER + ",' ',''),'-',''),'(',''),')','')" + " like '" + search + "' or " +
"REPLACE(REPLACE(REPLACE(REPLACE(" + ContactKey.WORK_FAX_MOBILE_NUMBER + ",' ',''),'-',''),'(',''),')','')" + " like '" + search + "' or " +
"REPLACE(REPLACE(REPLACE(REPLACE(" + ContactKey.FULL_NAME + ",' ',''),'-',''),'(',''),')','')" + " like '" + search + "' or " +
ContactKey.FULL_NAME + " like '" + search + "' or " +
ContactKey.MOBILE_NUMBER + " like '" + search + "' or " +
ContactKey.OTHERS_MOBILE_NUMBER + " like '" + search + "' or " +
ContactKey.HOME_MOBILE_NUMBER + " like '" + search + "' or " +
ContactKey.CUSTOME_MOBILE_NUMBER + " like '" + search + "' or " +
ContactKey.PAGER_MOBILE_NUMBER + " like '" + search + "' or " +
ContactKey.MAIN_MOBILE_NUMBER + " like '" + search + "' or " +
ContactKey.FAX_HOME_MOBILE_NUMBER + " like '" + search + "' or " +
ContactKey.WORK_MOBILE_NUMBER + " like '" + search + "' or " +
ContactKey.WORK_FAX_MOBILE_NUMBER + " like '" + search + "' or " +
ContactKey.LOCATIONNAME + " like '" + search + "' or " +
"REPLACE(" + ContactKey.CITY + ",' ','')" + " like '" + search + "' or " +
"REPLACE(" + ContactKey.ADDRESS_HOME + ",' ','')" + " like '" + search + "' or " +
"REPLACE(" + ContactKey.ADDRESS_OTHER + ",' ','')" + " like '" + search + "' or " +
"REPLACE(" + ContactKey.ADDRESS_WORK + ",' ','')" + " like '" + search + "' or " +
"REPLACE(" + ContactKey.ADDRESS_CUSTOME + ",' ','')" + " like '" + search + "' or " +
"REPLACE(" + ContactKey.STATE + ",' ','')" + " like '" + search + "' or " +
"REPLACE(" + ContactKey.WEBSITE + ",' ','')" + " like '" + search + "' or " +
"REPLACE(" + ContactKey.SIP + ",' ','')" + " like '" + search + "' or " +
"REPLACE(" + ContactKey.HOME_EMAIL_ID + ",' ','')" + " like '" + search + "' or " +
"REPLACE(" + ContactKey.WORK_EMAIL_ID + ",' ','')" + " like '" + search + "' or " +
"REPLACE(" + ContactKey.OTHERS_EMAIL_ID + ",' ','')" + " like '" + search + "' or " +
"REPLACE(" + ContactKey.COMPANY + ",' ','')" + " like '" + search + "' or " +
"REPLACE(" + ContactKey.COUNTRY + ",' ','')" + " like '" + search + "' or " +
ContactKey.COUNTRY + " like '" + search + "' or " +
ContactKey.CITY + " like '" + search + "' or " +
ContactKey.ADDRESS_HOME + " like '" + search + "' or " +
ContactKey.ADDRESS_OTHER + " like '" + search + "' or " +
ContactKey.ADDRESS_WORK + " like '" + search + "' or " +
ContactKey.ADDRESS_CUSTOME + " like '" + search + "' or " +
ContactKey.STATE + " like '" + search + "' or " +
ContactKey.WEBSITE + " like '" + search + "' or " +
ContactKey.SIP + " like '" + search + "' or " +
ContactKey.HOME_EMAIL_ID + " like '" + search + "' or " +
ContactKey.WORK_EMAIL_ID + " like '" + search + "' or " +
ContactKey.OTHERS_EMAIL_ID + " like '" + search + "' or " +
ContactKey.COMPANY + " like '" + search + "' or " +
ContactKey.IM_AIM + " like '" + search + "' or " +
"REPLACE(" + ContactKey.ADDRESS_HOME + ",' ','')" + " like '" + search + "' or " +
ContactKey.ADDRESS_HOME + " like '" + search + "' or " +
ContactKey.RELATION_ASSISTNT + " like '" + search + "' or " +
ContactKey.CREATED_DATE + " like '" + search + "' or " +
ContactKey.LAST_UPDATE_DATE + " like '" + search + "' or " +
ContactKey.NOTES + " like '" + search + "' or " +
"REPLACE(" + ContactKey.NOTES + ",' ','')" + " like '" + search + "'" + "Order By " + ContactKey.FIRST_NAME;
cursor = db.rawQuery(selectQuery, null);
if (cursor.moveToFirst()) {
do {
ContactModel mContactModel = new ContactModel();
mContactModel.setId(cursor.getString(cursor.getColumnIndex(ContactKey.ID)));
mContactModel.setContactsId(cursor.getString(cursor.getColumnIndex(ContactKey.CONTACT_ID)));
mContactModel.setFistname(cursor.getString(cursor.getColumnIndex(ContactKey.FIRST_NAME)));
mContactModel.setLastname(cursor.getString(cursor.getColumnIndex(ContactKey.LAST_NAME)));
mContactModel.setCreatedDate(cursor.getString(cursor.getColumnIndex(ContactKey.CREATED_DATE)));
mContactModel.setStatus(cursor.getString(cursor.getColumnIndex(ContactKey.STATUS)));
arrContactList.add(mContactModel);
} while (cursor.moveToNext());
}
cursor.close();
db.close();
Collections.sort(arrContactList, new SortBasedOnName());
return arrContactList;
}
public UserModel selectUserDetailsId(String userID) {
UserModel mContactModel = new UserModel();
Cursor cursor = null;
SQLiteDatabase db = this.getWritableDatabase();
cursor = db.query(TABLE_NAME_USER, null, null, null, null, null, null);
if (cursor.moveToFirst()) {
do {
mContactModel.setId(cursor.getString(cursor.getColumnIndex(UserKey.ID)));
mContactModel.setfName(cursor.getString(cursor.getColumnIndex(UserKey.FIRST_NAME)));
mContactModel.setLname(cursor.getString(cursor.getColumnIndex(UserKey.LAST_NAME)));
mContactModel.setCompany(cursor.getString(cursor.getColumnIndex(UserKey.COMPANY)));
mContactModel.setTitle(cursor.getString(cursor.getColumnIndex(UserKey.TITLE)));
mContactModel.setCity(cursor.getString(cursor.getColumnIndex(UserKey.CITY)));
mContactModel.setState(cursor.getString(cursor.getColumnIndex(UserKey.STATE)));
mContactModel.setCountry(cursor.getString(cursor.getColumnIndex(UserKey.COUNTRY)));
mContactModel.setZipcode(cursor.getString(cursor.getColumnIndex(UserKey.ZIPCODE)));
mContactModel.setAddress(cursor.getString(cursor.getColumnIndex(UserKey.ADDRESS)));
mContactModel.setCity2(cursor.getString(cursor.getColumnIndex(UserKey.CITY2)));
mContactModel.setState2(cursor.getString(cursor.getColumnIndex(UserKey.STATE2)));
mContactModel.setCountry2(cursor.getString(cursor.getColumnIndex(UserKey.COUNTRY2)));
mContactModel.setZipcode2(cursor.getString(cursor.getColumnIndex(UserKey.ZIPCODE2)));
mContactModel.setAddress2(cursor.getString(cursor.getColumnIndex(UserKey.ADDRESS2)));
mContactModel.setEmail(cursor.getString(cursor.getColumnIndex(UserKey.EMAIl)));
mContactModel.setPhone(cursor.getString(cursor.getColumnIndex(UserKey.PHONE)));
mContactModel.setProfileImage(cursor.getString(cursor.getColumnIndex(UserKey.PROFILE_IMAGE)));
mContactModel.setNew_address(cursor.getString(cursor.getColumnIndex(UserKey.NEW_ADDRESS)));
mContactModel.setNew_emails(cursor.getString(cursor.getColumnIndex(UserKey.NEW_EMAILS)));
mContactModel.setNew_phones(cursor.getString(cursor.getColumnIndex(UserKey.NEW_PHONES)));
} while (cursor.moveToNext());
}
cursor.close();
db.close();
return mContactModel;
}
public void selectConatctsIdStatusIsUpdated() {
//ArrayList mIdArr = new ArrayList<>();
Cursor cursor = null;
Cursor cursorInner = null;
SQLiteDatabase db = this.getWritableDatabase();
String query = "SELECT *, MAX(" + ContactKey.LAST_UPDATE_DATE + ") FROM " + TABLE_NAME_CONTACTS_LOGBOOK + " GROUP BY " + ContactKey.CONTACT_ID;
cursor = db.rawQuery(query, null);
if (cursor.moveToFirst()) {
do {
final String contactId = cursor.getString(cursor.getColumnIndex(ContactKey.CONTACT_ID));
final String status = cursor.getString(cursor.getColumnIndex(ContactKey.STATUS));
cursorInner = db.query(TABLE_NAME_CONTACTS, null, ContactKey.CONTACT_ID + "=?", new String[]{contactId}, null, null, null);
if (cursorInner.getCount() > 0) {
Hashtable tmp_mapFolder = new Hashtable();
tmp_mapFolder.clear();
tmp_mapFolder.put(ContactKey.STATUS, status);
edit(tmp_mapFolder, ContactKey.CONTACT_ID, contactId, TABLE_NAME_CONTACTS);
} else {
ContentValues values = new ContentValues();
values.put(ContactKey.CONTACT_ID, contactId);
values.put(ContactKey.LAST_UPDATE_DATE, cursor.getString(cursor.getColumnIndex(ContactKey.LAST_UPDATE_DATE)));
values.put(ContactKey.CREATED_DATE, cursor.getString(cursor.getColumnIndex(ContactKey.CREATED_DATE)));
values.put(ContactKey.FIRST_NAME, cursor.getString(cursor.getColumnIndex(ContactKey.FIRST_NAME)));
values.put(ContactKey.LAST_NAME, "");
values.put(ContactKey.MOBILE_NUMBER, cursor.getString(cursor.getColumnIndex(ContactKey.MOBILE_NUMBER)));
values.put(ContactKey.WORK_MOBILE_NUMBER, cursor.getString(cursor.getColumnIndex(ContactKey.WORK_MOBILE_NUMBER)));
values.put(ContactKey.WORK_FAX_MOBILE_NUMBER, cursor.getString(cursor.getColumnIndex(ContactKey.WORK_FAX_MOBILE_NUMBER)));
values.put(ContactKey.CUSTOME_MOBILE_NUMBER, cursor.getString(cursor.getColumnIndex(ContactKey.CUSTOME_MOBILE_NUMBER)));
values.put(ContactKey.FAX_HOME_MOBILE_NUMBER, cursor.getString(cursor.getColumnIndex(ContactKey.FAX_HOME_MOBILE_NUMBER)));
values.put(ContactKey.MAIN_MOBILE_NUMBER, cursor.getString(cursor.getColumnIndex(ContactKey.MAIN_MOBILE_NUMBER)));
values.put(ContactKey.OTHERS_MOBILE_NUMBER, cursor.getString(cursor.getColumnIndex(ContactKey.OTHERS_MOBILE_NUMBER)));
values.put(ContactKey.PAGER_MOBILE_NUMBER, cursor.getString(cursor.getColumnIndex(ContactKey.PAGER_MOBILE_NUMBER)));
values.put(ContactKey.HOME_MOBILE_NUMBER, cursor.getString(cursor.getColumnIndex(ContactKey.HOME_MOBILE_NUMBER)));
values.put(ContactKey.HOME_EMAIL_ID, cursor.getString(cursor.getColumnIndex(ContactKey.HOME_EMAIL_ID)));
values.put(ContactKey.ADDRESS_HOME, cursor.getString(cursor.getColumnIndex(ContactKey.ADDRESS_HOME)));
values.put(ContactKey.ADDRESS_WORK, cursor.getString(cursor.getColumnIndex(ContactKey.ADDRESS_WORK)));
values.put(ContactKey.ADDRESS_OTHER, cursor.getString(cursor.getColumnIndex(ContactKey.ADDRESS_OTHER)));
values.put(ContactKey.ADDRESS_CUSTOME, cursor.getString(cursor.getColumnIndex(ContactKey.ADDRESS_CUSTOME)));
values.put(ContactKey.NOTES, cursor.getString(cursor.getColumnIndex(ContactKey.NOTES)));
values.put(ContactKey.EVENT_BIRTHDATE, cursor.getString(cursor.getColumnIndex(ContactKey.EVENT_BIRTHDATE)));
values.put(ContactKey.EVENT_ANNIVERSARYDATE, cursor.getString(cursor.getColumnIndex(ContactKey.EVENT_ANNIVERSARYDATE)));
values.put(ContactKey.IM_AIM, cursor.getString(cursor.getColumnIndex(ContactKey.IM_AIM)));
values.put(ContactKey.RELATION_ASSISTNT, cursor.getString(cursor.getColumnIndex(ContactKey.RELATION_ASSISTNT)));
values.put(ContactKey.NIKNAME, cursor.getString(cursor.getColumnIndex(ContactKey.NIKNAME)));
values.put(ContactKey.WEBSITE, cursor.getString(cursor.getColumnIndex(ContactKey.WEBSITE)));
values.put(ContactKey.PHONETIC_NAME, cursor.getString(cursor.getColumnIndex(ContactKey.PHONETIC_NAME)));
values.put(ContactKey.SIP, cursor.getString(cursor.getColumnIndex(ContactKey.SIP)));
values.put(ContactKey.STATUS, cursor.getString(cursor.getColumnIndex(ContactKey.STATUS)));
values.put(ContactKey.COMPANY, cursor.getString(cursor.getColumnIndex(ContactKey.COMPANY)));
values.put(ContactKey.STATE, cursor.getString(cursor.getColumnIndex(ContactKey.STATE)));
values.put(ContactKey.CITY, cursor.getString(cursor.getColumnIndex(ContactKey.CITY)));
values.put(ContactKey.COUNTRY, cursor.getString(cursor.getColumnIndex(ContactKey.COUNTRY)));
values.put(ContactKey.LATLONG, cursor.getString(cursor.getColumnIndex(ContactKey.LATLONG)));
values.put(ContactKey.EDITED_FIELD, cursor.getString(cursor.getColumnIndex(ContactKey.EDITED_FIELD)));
values.put(ContactKey.LOCATIONNAME, cursor.getString(cursor.getColumnIndex(ContactKey.LOCATIONNAME)));
db.insert(TABLE_NAME_CONTACTS, null, values);
}
} while (cursor.moveToNext());
}
cursor.close();
cursorInner.close();
/*
* get All ConatctsId and check on Conatcts table with check all id available or not
*/
// if(mIdArr.size() > 0)
// {
// for (int i=0; i < mIdArr.size(); i++)
// {
// cursor = db.query(TABLE_NAME_CONTACTS, null, ContactKey.CONTACT_ID + "=?", new String[]{mIdArr.get(i)}, null, null, null);
//
// if(cursor.getCount() <= 0)
// {
// Log.d("DELETED","DELETED ID==="+mIdArr.get(i));
// }
// }
//
// }
db.close();
}
public void TruncateAllTables() {
deleteAll(TABLE_NAME_CONTACTS);
deleteAll(TABLE_NAME_USER);
deleteAll(TABLE_NAME_CONTACTS_LOGBOOK);
deleteAll(TABLE_NAME_UPDATE_CONATCTS);
}
public void deleteAll(String TableName) {
try {
SQLiteDatabase db = this.getWritableDatabase();
db.delete(TableName, null, null);
db.close();
} catch (Exception e) {
e.printStackTrace();
}
}
public void createtable(SQLiteDatabase database, String tableName, Hashtable tmp1) {
String CREATE_TABLE = "create table " + tableName + "(";
for (String key : tmp1.keySet()) {
CREATE_TABLE = CREATE_TABLE + key + " " + tmp1.get(key) + ",";
}
int len = CREATE_TABLE.length();
CREATE_TABLE = CREATE_TABLE.substring(0, len - 1) + ")";
database.execSQL(CREATE_TABLE);
}
public void dropCreatetable(SQLiteDatabase database, String tableName, Hashtable tmp1) {
database.execSQL("DROP TABLE IF EXISTS '" + tableName + "'");
String CREATE_TABLE = "create table " + tableName + "(";
for (String key : tmp1.keySet()) {
CREATE_TABLE = CREATE_TABLE + key + " " + tmp1.get(key) + ",";
}
int len = CREATE_TABLE.length();
CREATE_TABLE = CREATE_TABLE.substring(0, len - 1) + ")";
database.execSQL(CREATE_TABLE);
}
public void insertRecord(Hashtable queryValues, String TableName) {
SQLiteDatabase database = this.getWritableDatabase();
ContentValues values = new ContentValues();
for (String key : queryValues.keySet()) {
values.put(key, queryValues.get(key));
}
database.insert(TableName, null, values);
database.close();
}
public void insertUpdateRecord(Hashtable queryValues, String tableName, String rowName, String Id) {
SQLiteDatabase database = this.getWritableDatabase();
Cursor cursor = null;
ContentValues values = new ContentValues();
cursor = database.query(tableName, null, rowName + "=?", new String[]{Id}, null, null, null);
//database.beginTransaction();
database.beginTransactionNonExclusive();
if (cursor.getCount() > 0) {
for (String key : queryValues.keySet()) {
values.put(key, queryValues.get(key));
}
database.update(tableName, values, rowName + "='" + Id + "'", null);
} else {
for (String key : queryValues.keySet()) {
values.put(key, queryValues.get(key));
}
database.insert(tableName, null, values);
}
cursor.close();
database.setTransactionSuccessful();
database.endTransaction();
database.close();
}
public void insertUpdateRecordTwoRow(Hashtable queryValues, final String tableName, final String rowName, final String Id, final String rowName1, final String mdate) {
SQLiteDatabase database = this.getWritableDatabase();
Cursor cursor = null;
ContentValues values = new ContentValues();
// cursor = db.query(TABLE_NAME_CONTACTS_LOGBOOK, null, ContactKey.CONTACT_ID + "=? AND " + ContactKey.ID + "=? ", new String[]{contactId, Id}, null, null, null);
cursor = database.query(tableName, null, rowName + "=? AND " + rowName1 + " =? ", new String[]{Id, mdate}, null, null, null);
//Log.d("UpdateRecordTwoRow","getCount"+cursor.getCount());
//database.beginTransaction();
database.beginTransactionNonExclusive();
if (cursor.getCount() > 0) {
for (String key : queryValues.keySet()) {
values.put(key, queryValues.get(key));
}
database.update(tableName, values, rowName + "='" + Id + "'", null);
} else {
for (String key : queryValues.keySet()) {
values.put(key, queryValues.get(key));
}
database.insert(tableName, null, values);
}
database.setTransactionSuccessful();
database.endTransaction();
cursor.close();
database.close();
}
public void insertRecordTable(Hashtable queryValues, String tableName) {
SQLiteDatabase database = this.getWritableDatabase();
ContentValues values = new ContentValues();
//database.beginTransaction();
database.beginTransactionNonExclusive();
for (String key : queryValues.keySet()) {
values.put(key, queryValues.get(key));
}
database.insert(tableName, null, values);
database.setTransactionSuccessful();
database.endTransaction();
database.close();
}
public void insertRecordTableBunch(ArrayList> queryValues, String tableName) {
SQLiteDatabase database = this.getWritableDatabase();
ContentValues values = new ContentValues();
//database.beginTransaction();
database.beginTransactionNonExclusive();
for (int i = 0; i < queryValues.size(); i++) {
for (String key : queryValues.get(i).keySet()) {
values.put(key, queryValues.get(i).get(key));
}
database.insert(tableName, null, values);
}
database.setTransactionSuccessful();
database.endTransaction();
database.close();
}
public void insertRecordTableBunchWithWhere(ArrayList> queryValues, String tableName, final String contactId) {
SQLiteDatabase database = this.getWritableDatabase();
Cursor cursor = database.query(tableName, null, ContactKey.CONTACT_ID + "=?", new String[]{contactId}, null, null, null);
ContentValues values = new ContentValues();
database.beginTransactionNonExclusive();
if (cursor.getCount() > 0) {
for (int i = 0; i < queryValues.size(); i++) {
for (String key : queryValues.get(i).keySet()) {
values.put(key, queryValues.get(i).get(key));
}
database.update(tableName, values, ContactKey.CONTACT_ID + "='" + contactId + "'", null);
}
} else {
for (int i = 0; i < queryValues.size(); i++) {
for (String key : queryValues.get(i).keySet()) {
values.put(key, queryValues.get(i).get(key));
}
database.insert(tableName, null, values);
}
}
cursor.close();
database.setTransactionSuccessful();
database.endTransaction();
database.close();
}
public String deleteRecordWithIdsNotInIds(String logIds) {
String deleteId = "";
logIds = logIds.replace("[", "");
logIds = logIds.replace("]", "");
SQLiteDatabase database = this.getWritableDatabase();
Cursor cursor = null;
String query;
Log.e("logIds", "logIds:" + logIds);
query = "SELECT * FROM " + TABLE_NAME_CONTACTS + " WHERE " + ContactKey.CONTACT_ID + " NOT IN(" + logIds + ") AND " + ContactKey.STATUS + "!='Deleted'";
cursor = database.rawQuery(query, null);
if (cursor.getCount() > 0) {
if (cursor.moveToFirst()) {
do {
deleteId = cursor.getString(cursor.getColumnIndex(ContactKey.CONTACT_ID));
} while (cursor.moveToNext());
}
}
cursor.close();
database.close();
return deleteId;
}
public void delete(String Column, String key) {
SQLiteDatabase db = this.getWritableDatabase();
try {
db.delete(TABLE_NAME, Column + "=?", new String[]{key});
} catch (Exception e) {
e.printStackTrace();
} finally {
db.close();
}
}
public void deleteById(String tablename, String Column, String key) {
SQLiteDatabase db = this.getWritableDatabase();
try {
db.delete(tablename, Column + "=?", new String[]{key});
} catch (Exception e) {
e.printStackTrace();
} finally {
db.close();
}
}
public void deleteByTwoId(String tablename, String ColumnGroup, String keyGroup, String ColumnChild, String keyChild) {
SQLiteDatabase db = this.getWritableDatabase();
try {
//db.delete(tablename, ColumnGroup + "=?", new String[]{keyGroup});
db.delete(tablename, ColumnGroup + " = ? AND " + ColumnChild + " = ?", new String[]{keyGroup, keyChild + ""});
} catch (Exception e) {
e.printStackTrace();
} finally {
db.close();
}
}
public void edit(Hashtable queryValues, String Key, String value, String TABLE_NAME) {
SQLiteDatabase database = this.getWritableDatabase();
ContentValues values = new ContentValues();
for (String key : queryValues.keySet()) {
values.put(key, queryValues.get(key));
}
database.update(TABLE_NAME, values, Key + "='" + value + "'", null);
}
/**
* *************************************************************************
*
* @ClassdName:FirstNameComparator
* @CreatedDate:
* @ModifiedBy: not yet
* @ModifiedDate: not yet
* @purpose:This class is use to get Sorting order ContactName
*
* ************************************************************************* */ // public class FirstNameComparator implements Comparator {
// @Override
// public int compare(GLCContactsModel lhs, GLCContactsModel rhs) {
// return lhs.getFistname().compareToIgnoreCase(rhs.getFistname());
// }
// }
public String firstCharUprt(String name) {
String output = "";
if (name != null && !name.isEmpty()) {
output = name.substring(0, 1).toUpperCase() + name.substring(1);
} else {
output = name;
}
return output;
}
public String getTimestamp(String dateTime) {
Date dateFrom = null;
String dateTimeStamp = "";
try {
dateFrom = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss", Locale.ENGLISH).parse(dateTime);
} catch (ParseException e) {
e.printStackTrace();
}
Calendar calFrom = Calendar.getInstance();
calFrom.setTime(dateFrom);
GregorianCalendar calFromDate = new GregorianCalendar();
calFromDate.set(calFrom.get(Calendar.YEAR), calFrom.get(Calendar.MONTH), calFrom.get(Calendar.DAY_OF_MONTH), calFrom.get(Calendar.HOUR), calFrom.get(Calendar.MINUTE), calFrom.get(Calendar.SECOND));
dateTimeStamp = String.valueOf(calFromDate.getTimeInMillis() / 1000);
return dateTimeStamp;
}
public String getTimestampTo(String dateTime) {
Date dateFrom = null;
String dateTimeStamp = "";
try {
dateFrom = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss", Locale.ENGLISH).parse(dateTime);
} catch (ParseException e) {
e.printStackTrace();
}
Calendar calFrom = Calendar.getInstance();
calFrom.setTime(dateFrom);
calFrom.add(calFrom.DATE, +1);
GregorianCalendar calFromDate = new GregorianCalendar();
calFromDate.set(calFrom.get(Calendar.YEAR), calFrom.get(Calendar.MONTH), calFrom.get(Calendar.DAY_OF_MONTH), calFrom.get(Calendar.HOUR), calFrom.get(Calendar.MINUTE), calFrom.get(Calendar.SECOND));
dateTimeStamp = String.valueOf(calFromDate.getTimeInMillis() / 1000);
return dateTimeStamp;
}
/**
* This method close database connection and released occupied memory
**/
@Override
public synchronized void close() {
if (DataBase != null) {
DataBase.close();
}
SQLiteDatabase.releaseMemory();
super.close();
}
public ArrayList getDeletedIds(String allIds) {
ArrayList deleteIdArr = new ArrayList<>();
allIds = allIds.replace("[", "");
allIds = allIds.replace("]", "");
SQLiteDatabase database = this.getWritableDatabase();
Cursor cursor = null;
String query;
Log.e("allIds", "allIds:" + allIds);
query = "SELECT * FROM " + TABLE_NAME_CONTACTS + " WHERE " + ContactKey.CONTACT_ID + " NOT IN(" + allIds + ")";
cursor = database.rawQuery(query, null);
if (cursor.getCount() > 0) {
if (cursor.moveToFirst()) {
do {
final String deleteId = cursor.getString(cursor.getColumnIndex(ContactKey.CONTACT_ID));
deleteIdArr.add(deleteId);
} while (cursor.moveToNext());
}
}
cursor.close();
database.close();
return deleteIdArr;
}
public void updateRecoveredData(final String newID, final String oldID, final String city, final String state, final String country, final String latLong, final String location, final String upadtedTimeStamp) {
final SQLiteDatabase database = this.getWritableDatabase();
final String queryContact = "UPDATE " + TABLE_NAME_CONTACTS + " SET " + ContactKey.CONTACT_ID + " = '" + newID + "', " + ContactKey.STATUS + " = '" + mContext.getString(R.string.recovered) + "'," + ContactKey.LAST_UPDATE_DATE + " = '" + upadtedTimeStamp + "' WHERE " + ContactKey.CONTACT_ID + " = '" + oldID + "'";
final String queryLogBook = "UPDATE " + TABLE_NAME_CONTACTS_LOGBOOK + " SET " + ContactKey.CONTACT_ID + " = '" + newID + "' WHERE " + ContactKey.CONTACT_ID + " = '" + oldID + "' AND " + ContactKey.STATUS + " != '" + mContext.getString(R.string.deleted) + "'";
final String queryLogBook2 = "UPDATE " + TABLE_NAME_CONTACTS_LOGBOOK + " SET " + ContactKey.CONTACT_ID + " = '" + newID + "'," + ContactKey.STATUS + " = '" + mContext.getString(R.string.recovered) + "'," + ContactKey.CITY + " = '" + city + "'," + ContactKey.STATE + " = '" + state + "'," + ContactKey.COUNTRY + " = '" + country + "'," + ContactKey.LATLONG + " = '" + latLong + "'," + ContactKey.LOCATIONNAME + " = '" + location + "'," + ContactKey.LAST_UPDATE_DATE + " = '" + upadtedTimeStamp + "' WHERE " + ContactKey.CONTACT_ID + " = '" + oldID + "' AND " + ContactKey.STATUS + " = '" + mContext.getString(R.string.deleted) + "'";
database.execSQL(queryContact);
database.execSQL(queryLogBook);
database.execSQL(queryLogBook2);
}
public Cursor getContactByID(final String contactID) {
Cursor cursor = null;
final SQLiteDatabase db = this.getWritableDatabase();
cursor = db.query(TABLE_NAME_CONTACTS, null, ContactKey.CONTACT_ID + "=?", new String[]{contactID}, null, null, null);
return cursor;
}
public class LastUpdateDateComparator implements Comparator {
@Override
public int compare(ContactModel lhs, ContactModel rhs) {
return rhs.getUpdatedDate().compareToIgnoreCase(lhs.getUpdatedDate());
}
}
}
https://acadgild.com/blog/how-to-draw-a-path-on-google-maps-in-android/ package com.app.forgotcha.sqlite.db; import android.app.Activity; import android.content.ContentValues; import android.content.Context; import android.database.Cursor; import android.database.SQLException; import android.database.sqlite.SQLiteDatabase; import android.database.sqlite.SQLiteOpenHelper; import android.text.TextUtils; import android.util.Log; import com.app.forgotcha.ForgotchaAplication; import com.app.forgotcha.R; import com.app.forgotcha.model.ContactModel; import com.app.forgotcha.model.UserModel; import com.app.forgotcha.util.Constans; import com.app.forgotcha.util.SortBasedOnName; import java.text.ParseException; import java.text.SimpleDateFormat; import java.util.ArrayList; import java.util.Calendar; import java.util.Collections; import java.util.Comparator; import java.util.Date; import java.util.GregorianCalendar; import java.util.Hashtable; import java.util.Locale; /**************************************************************************** * @ClassdName:DatabaseHelper * @CreatedDate: * @ModifiedBy: not yet * @ModifiedDate: not yet * @purpose:This Class is use to Create database with Table and insert,update,delete Method with functionlity. ***************************************************************************/ public class DatabaseHelper extends SQLiteOpenHelper { private static Context mContext; // DATABASE NAME private static String DATABASE_NAME = "FORGOTCHA"; private static String TABLE_NAME = ""; private SQLiteDatabase DataBase; // LIST TABLE NAME private String TABLE_NAME_CONTACTS = "contacts"; private String TABLE_NAME_CONTACTS_LOGBOOK = "contacts_logbook"; private String TABLE_NAME_USER = "user"; private String TABLE_NAME_UPDATE_CONATCTS = "update_contacts"; public DatabaseHelper(Context context, String data_name, String tab_name, Hashtable
* ************************************************************************* */ // public class FirstNameComparator implements Comparator
Comments
Post a Comment
Welcome To Android