diff --git a/app/build.gradle b/app/build.gradle index 92b6ece5..ab8a2dea 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -47,6 +47,8 @@ ext { dependencies { implementation 'com.simplemobiletools:commons:3.11.3' implementation 'joda-time:joda-time:2.9.9' + implementation 'com.facebook.stetho:stetho:1.5.0' + implementation 'com.google.code.gson:gson:2.8.2' debugImplementation "com.squareup.leakcanary:leakcanary-android:$leakCanaryVersion" releaseImplementation "com.squareup.leakcanary:leakcanary-android-no-op:$leakCanaryVersion" diff --git a/app/src/main/kotlin/com/simplemobiletools/contacts/App.kt b/app/src/main/kotlin/com/simplemobiletools/contacts/App.kt index 4507f7c8..12e6ca36 100644 --- a/app/src/main/kotlin/com/simplemobiletools/contacts/App.kt +++ b/app/src/main/kotlin/com/simplemobiletools/contacts/App.kt @@ -12,6 +12,7 @@ class App : Application() { return } LeakCanary.install(this) + Stetho.initializeWithDefaults(this) } checkUseEnglish() diff --git a/app/src/main/kotlin/com/simplemobiletools/contacts/activities/MainActivity.kt b/app/src/main/kotlin/com/simplemobiletools/contacts/activities/MainActivity.kt index 6fc48b2c..56b3bf4e 100644 --- a/app/src/main/kotlin/com/simplemobiletools/contacts/activities/MainActivity.kt +++ b/app/src/main/kotlin/com/simplemobiletools/contacts/activities/MainActivity.kt @@ -372,7 +372,8 @@ class MainActivity : SimpleActivity(), RefreshContactsListener { } private fun launchAbout() { - startAboutActivity(R.string.app_name, LICENSE_KOTLIN or LICENSE_MULTISELECT or LICENSE_JODA or LICENSE_GLIDE, BuildConfig.VERSION_NAME) + startAboutActivity(R.string.app_name, LICENSE_KOTLIN or LICENSE_MULTISELECT or LICENSE_JODA or LICENSE_GLIDE or LICENSE_GSON or LICENSE_STETHO, + BuildConfig.VERSION_NAME) } override fun refreshContacts() { diff --git a/app/src/main/kotlin/com/simplemobiletools/contacts/extensions/Context.kt b/app/src/main/kotlin/com/simplemobiletools/contacts/extensions/Context.kt index 9d5b9aa0..3e1f947f 100644 --- a/app/src/main/kotlin/com/simplemobiletools/contacts/extensions/Context.kt +++ b/app/src/main/kotlin/com/simplemobiletools/contacts/extensions/Context.kt @@ -17,11 +17,14 @@ import com.simplemobiletools.contacts.activities.EditContactActivity import com.simplemobiletools.contacts.activities.ViewContactActivity import com.simplemobiletools.contacts.helpers.CONTACT_ID import com.simplemobiletools.contacts.helpers.Config +import com.simplemobiletools.contacts.helpers.DBHelper import com.simplemobiletools.contacts.models.Contact import java.io.File val Context.config: Config get() = Config.newInstance(applicationContext) +val Context.dbHelper: DBHelper get() = DBHelper.newInstance(applicationContext) + fun Context.viewContact(contact: Contact) { Intent(applicationContext, ViewContactActivity::class.java).apply { putExtra(CONTACT_ID, contact.id) diff --git a/app/src/main/kotlin/com/simplemobiletools/contacts/helpers/DBHelper.kt b/app/src/main/kotlin/com/simplemobiletools/contacts/helpers/DBHelper.kt new file mode 100644 index 00000000..c9d4bba2 --- /dev/null +++ b/app/src/main/kotlin/com/simplemobiletools/contacts/helpers/DBHelper.kt @@ -0,0 +1,42 @@ +package com.simplemobiletools.contacts.helpers + +import android.content.Context +import android.database.sqlite.SQLiteDatabase +import android.database.sqlite.SQLiteOpenHelper + +class DBHelper private constructor(val context: Context) : SQLiteOpenHelper(context, DB_NAME, null, DB_VERSION) { + private val MAIN_TABLE_NAME = "contacts" + private val COL_ID = "id" + private val COL_FIRST_NAME = "first_name" + private val COL_MIDDLE_NAME = "middle_name" + private val COL_SURNAME = "surname" + private val COL_PHOTO = "photo" + private val COL_PHONE_NUMBERS = "phone_numbers" + private val COL_EMAILS = "emails" + private val COL_EVENTS = "events" + private val COL_STARRED = "starred" + + private val mDb: SQLiteDatabase = writableDatabase + + companion object { + private const val DB_VERSION = 1 + const val DB_NAME = "contacts.db" + var dbInstance: DBHelper? = null + + fun newInstance(context: Context): DBHelper { + if (dbInstance == null) + dbInstance = DBHelper(context) + + return dbInstance!! + } + } + + override fun onCreate(db: SQLiteDatabase) { + db.execSQL("CREATE TABLE $MAIN_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)") + } + + override fun onUpgrade(db: SQLiteDatabase, oldVersion: Int, newVersion: Int) { + + } +}