From c2b92f46f6e99dafd04d2e9f3719118ac4b3a164 Mon Sep 17 00:00:00 2001 From: tibbi Date: Thu, 22 Feb 2018 15:25:36 +0100 Subject: [PATCH] add Notes field at our local database too --- .../contacts/activities/EditContactActivity.kt | 2 +- .../simplemobiletools/contacts/helpers/DBHelper.kt | 13 +++++++++---- 2 files changed, 10 insertions(+), 5 deletions(-) diff --git a/app/src/main/kotlin/com/simplemobiletools/contacts/activities/EditContactActivity.kt b/app/src/main/kotlin/com/simplemobiletools/contacts/activities/EditContactActivity.kt index f13c21b0..38b30572 100644 --- a/app/src/main/kotlin/com/simplemobiletools/contacts/activities/EditContactActivity.kt +++ b/app/src/main/kotlin/com/simplemobiletools/contacts/activities/EditContactActivity.kt @@ -507,7 +507,7 @@ class EditContactActivity : ContactActivity() { events = getFilledEvents() source = contact!!.source starred = if (isContactStarred()) 1 else 0 - notes = contact_notes.value.replace("\n", "\\n") + notes = contact_notes.value Thread { config.lastUsedContactSource = source diff --git a/app/src/main/kotlin/com/simplemobiletools/contacts/helpers/DBHelper.kt b/app/src/main/kotlin/com/simplemobiletools/contacts/helpers/DBHelper.kt index 6229ec79..2703ffa8 100644 --- a/app/src/main/kotlin/com/simplemobiletools/contacts/helpers/DBHelper.kt +++ b/app/src/main/kotlin/com/simplemobiletools/contacts/helpers/DBHelper.kt @@ -30,6 +30,7 @@ class DBHelper private constructor(val context: Context) : SQLiteOpenHelper(cont private val COL_EVENTS = "events" private val COL_STARRED = "starred" private val COL_ADDRESSES = "addresses" + private val COL_NOTES = "notes" private val FIRST_CONTACT_ID = 1000000 @@ -50,7 +51,8 @@ class DBHelper private constructor(val context: Context) : SQLiteOpenHelper(cont override fun onCreate(db: SQLiteDatabase) { db.execSQL("CREATE TABLE $CONTACTS_TABLE_NAME ($COL_ID INTEGER PRIMARY KEY AUTOINCREMENT, $COL_FIRST_NAME TEXT, $COL_MIDDLE_NAME TEXT, " + - "$COL_SURNAME TEXT, $COL_PHOTO BLOB, $COL_PHONE_NUMBERS TEXT, $COL_EMAILS TEXT, $COL_EVENTS TEXT, $COL_STARRED INTEGER, $COL_ADDRESSES TEXT)") + "$COL_SURNAME TEXT, $COL_PHOTO BLOB, $COL_PHONE_NUMBERS TEXT, $COL_EMAILS TEXT, $COL_EVENTS TEXT, $COL_STARRED INTEGER, " + + "$COL_ADDRESSES TEXT, $COL_NOTES TEXT)") // start autoincrement ID from FIRST_CONTACT_ID to avoid conflicts db.execSQL("REPLACE INTO sqlite_sequence (name, seq) VALUES ('$CONTACTS_TABLE_NAME', $FIRST_CONTACT_ID)") @@ -59,6 +61,7 @@ class DBHelper private constructor(val context: Context) : SQLiteOpenHelper(cont override fun onUpgrade(db: SQLiteDatabase, oldVersion: Int, newVersion: Int) { if (oldVersion == 1) { db.execSQL("ALTER TABLE $CONTACTS_TABLE_NAME ADD COLUMN $COL_ADDRESSES TEXT DEFAULT ''") + db.execSQL("ALTER TABLE $CONTACTS_TABLE_NAME ADD COLUMN $COL_NOTES TEXT DEFAULT ''") } } @@ -93,6 +96,7 @@ class DBHelper private constructor(val context: Context) : SQLiteOpenHelper(cont put(COL_ADDRESSES, Gson().toJson(contact.addresses)) put(COL_EVENTS, Gson().toJson(contact.events)) put(COL_STARRED, contact.starred) + put(COL_NOTES, contact.notes) if (contact.photoUri.isNotEmpty()) { put(COL_PHOTO, getPhotoByteArray(contact.photoUri)) @@ -124,7 +128,8 @@ class DBHelper private constructor(val context: Context) : SQLiteOpenHelper(cont fun getContacts(selection: String? = null, selectionArgs: Array? = null): ArrayList { val contacts = ArrayList() - val projection = arrayOf(COL_ID, COL_FIRST_NAME, COL_MIDDLE_NAME, COL_SURNAME, COL_PHONE_NUMBERS, COL_EMAILS, COL_EVENTS, COL_STARRED, COL_PHOTO, COL_ADDRESSES) + val projection = arrayOf(COL_ID, COL_FIRST_NAME, COL_MIDDLE_NAME, COL_SURNAME, COL_PHONE_NUMBERS, COL_EMAILS, COL_EVENTS, COL_STARRED, + COL_PHOTO, COL_ADDRESSES, COL_NOTES) val cursor = mDb.query(CONTACTS_TABLE_NAME, projection, selection, selectionArgs, null, null, null) cursor.use { while (cursor.moveToNext()) { @@ -156,9 +161,9 @@ class DBHelper private constructor(val context: Context) : SQLiteOpenHelper(cont null } - val notes = "" - + val notes = cursor.getStringValue(COL_NOTES) val starred = cursor.getIntValue(COL_STARRED) + val contact = Contact(id, firstName, middleName, surname, "", phoneNumbers, emails, addresses, events, SMT_PRIVATE, starred, id, "", photo, notes) contacts.add(contact) }