mirror of
https://github.com/SimpleMobileTools/Simple-Contacts.git
synced 2025-06-05 21:59:27 +02:00
This commit is contained in:
@ -60,6 +60,10 @@ class Config(context: Context) : BaseConfig(context) {
|
|||||||
get() = prefs.getBoolean(SHOW_DIALPAD_LETTERS, true)
|
get() = prefs.getBoolean(SHOW_DIALPAD_LETTERS, true)
|
||||||
set(showDialpadLetters) = prefs.edit().putBoolean(SHOW_DIALPAD_LETTERS, showDialpadLetters).apply()
|
set(showDialpadLetters) = prefs.edit().putBoolean(SHOW_DIALPAD_LETTERS, showDialpadLetters).apply()
|
||||||
|
|
||||||
|
var wasLocalAccountInitialized: Boolean
|
||||||
|
get() = prefs.getBoolean(WAS_LOCAL_ACCOUNT_INITIALIZED, false)
|
||||||
|
set(wasLocalAccountInitialized) = prefs.edit().putBoolean(WAS_LOCAL_ACCOUNT_INITIALIZED, wasLocalAccountInitialized).apply()
|
||||||
|
|
||||||
var lastExportPath: String
|
var lastExportPath: String
|
||||||
get() = prefs.getString(LAST_EXPORT_PATH, "")!!
|
get() = prefs.getString(LAST_EXPORT_PATH, "")!!
|
||||||
set(lastExportPath) = prefs.edit().putString(LAST_EXPORT_PATH, lastExportPath).apply()
|
set(lastExportPath) = prefs.edit().putString(LAST_EXPORT_PATH, lastExportPath).apply()
|
||||||
|
@ -23,6 +23,7 @@ const val SHOW_DIALPAD_BUTTON = "show_dialpad_button"
|
|||||||
const val SHOW_DIALPAD_LETTERS = "show_dialpad_letters"
|
const val SHOW_DIALPAD_LETTERS = "show_dialpad_letters"
|
||||||
const val SPEED_DIAL = "speed_dial"
|
const val SPEED_DIAL = "speed_dial"
|
||||||
const val LAST_EXPORT_PATH = "last_export_path"
|
const val LAST_EXPORT_PATH = "last_export_path"
|
||||||
|
const val WAS_LOCAL_ACCOUNT_INITIALIZED = "was_local_account_initialized"
|
||||||
|
|
||||||
const val CONTACT_ID = "contact_id"
|
const val CONTACT_ID = "contact_id"
|
||||||
const val SMT_PRIVATE = "smt_private" // used at the contact source of local contacts hidden from other apps
|
const val SMT_PRIVATE = "smt_private" // used at the contact source of local contacts hidden from other apps
|
||||||
|
@ -746,6 +746,11 @@ class ContactsHelper(val context: Context) {
|
|||||||
return sources
|
return sources
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!context.config.wasLocalAccountInitialized) {
|
||||||
|
initializeLocalPhoneAccount()
|
||||||
|
context.config.wasLocalAccountInitialized = true
|
||||||
|
}
|
||||||
|
|
||||||
val accounts = AccountManager.get(context).accounts
|
val accounts = AccountManager.get(context).accounts
|
||||||
accounts.forEach {
|
accounts.forEach {
|
||||||
if (ContentResolver.getIsSyncable(it, AUTHORITY) == 1) {
|
if (ContentResolver.getIsSyncable(it, AUTHORITY) == 1) {
|
||||||
@ -766,6 +771,24 @@ class ContactsHelper(val context: Context) {
|
|||||||
return sources
|
return sources
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// make sure the local Phone contact source is initialized and available
|
||||||
|
// https://stackoverflow.com/a/6096508/1967672
|
||||||
|
private fun initializeLocalPhoneAccount() {
|
||||||
|
try {
|
||||||
|
val operations = ArrayList<ContentProviderOperation>()
|
||||||
|
ContentProviderOperation.newInsert(RawContacts.CONTENT_URI).apply {
|
||||||
|
withValue(RawContacts.ACCOUNT_NAME, null)
|
||||||
|
withValue(RawContacts.ACCOUNT_TYPE, null)
|
||||||
|
operations.add(build())
|
||||||
|
}
|
||||||
|
|
||||||
|
val results = context.contentResolver.applyBatch(AUTHORITY, operations)
|
||||||
|
val rawContactUri = results.firstOrNull()?.uri ?: return
|
||||||
|
context.contentResolver.delete(rawContactUri, null, null)
|
||||||
|
} catch (ignored: Exception) {
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private fun getContactSourceType(accountName: String) = getDeviceContactSources().firstOrNull { it.name == accountName }?.type ?: ""
|
private fun getContactSourceType(accountName: String) = getDeviceContactSources().firstOrNull { it.name == accountName }?.type ?: ""
|
||||||
|
|
||||||
private fun getContactProjection() = arrayOf(
|
private fun getContactProjection() = arrayOf(
|
||||||
|
Reference in New Issue
Block a user