mirror of
https://github.com/SimpleMobileTools/Simple-Contacts.git
synced 2025-06-05 21:59:27 +02:00
store the local account type in shared prefs
This commit is contained in:
@ -51,6 +51,7 @@ class MainActivity : SimpleActivity(), RefreshContactsListener {
|
|||||||
setContentView(R.layout.activity_main)
|
setContentView(R.layout.activity_main)
|
||||||
appLaunched()
|
appLaunched()
|
||||||
setupTabColors()
|
setupTabColors()
|
||||||
|
storeLocalAccountType()
|
||||||
|
|
||||||
handlePermission(PERMISSION_READ_CONTACTS) {
|
handlePermission(PERMISSION_READ_CONTACTS) {
|
||||||
if (it) {
|
if (it) {
|
||||||
@ -214,6 +215,30 @@ class MainActivity : SimpleActivity(), RefreshContactsListener {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private fun storeLocalAccountType() {
|
||||||
|
if (config.localAccountType == "-1") {
|
||||||
|
// some manufacturer contact account types from https://stackoverflow.com/a/44802016/1967672
|
||||||
|
val localAccountTypes = arrayListOf("vnd.sec.contact.phone",
|
||||||
|
"com.htc.android.pcsc",
|
||||||
|
"com.sonyericsson.localcontacts",
|
||||||
|
"com.lge.sync",
|
||||||
|
"com.lge.phone",
|
||||||
|
"vnd.tmobileus.contact.phone",
|
||||||
|
"com.android.huawei.phone",
|
||||||
|
"Local Phone Account")
|
||||||
|
|
||||||
|
ContactsHelper(this).getContactTypes {
|
||||||
|
var localAccountType = ""
|
||||||
|
it.forEach {
|
||||||
|
if (localAccountTypes.contains(it)) {
|
||||||
|
localAccountType = it
|
||||||
|
}
|
||||||
|
}
|
||||||
|
config.localAccountType = localAccountType
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private fun getOtherViewPagerItem(used: Int) = if (used == 1) 0 else 1
|
private fun getOtherViewPagerItem(used: Int) = if (used == 1) 0 else 1
|
||||||
|
|
||||||
private fun initFragments() {
|
private fun initFragments() {
|
||||||
|
@ -43,4 +43,8 @@ class Config(context: Context) : BaseConfig(context) {
|
|||||||
var lastUsedViewPagerPage: Int
|
var lastUsedViewPagerPage: Int
|
||||||
get() = prefs.getInt(LAST_USED_VIEW_PAGER_PAGE, 0)
|
get() = prefs.getInt(LAST_USED_VIEW_PAGER_PAGE, 0)
|
||||||
set(lastUsedViewPagerPage) = prefs.edit().putInt(LAST_USED_VIEW_PAGER_PAGE, lastUsedViewPagerPage).apply()
|
set(lastUsedViewPagerPage) = prefs.edit().putInt(LAST_USED_VIEW_PAGER_PAGE, lastUsedViewPagerPage).apply()
|
||||||
|
|
||||||
|
var localAccountType: String
|
||||||
|
get() = prefs.getString(LOCAL_ACCOUNT_TYPE, "-1")
|
||||||
|
set(localAccountType) = prefs.edit().putString(LOCAL_ACCOUNT_TYPE, localAccountType).apply()
|
||||||
}
|
}
|
||||||
|
@ -10,6 +10,7 @@ const val DISPLAY_CONTACT_SOURCES = "display_contact_sources"
|
|||||||
const val START_NAME_WITH_SURNAME = "start_name_with_surname"
|
const val START_NAME_WITH_SURNAME = "start_name_with_surname"
|
||||||
const val LAST_USED_CONTACT_SOURCE = "last_used_contact_source"
|
const val LAST_USED_CONTACT_SOURCE = "last_used_contact_source"
|
||||||
const val LAST_USED_VIEW_PAGER_PAGE = "last_used_view_pager_page"
|
const val LAST_USED_VIEW_PAGER_PAGE = "last_used_view_pager_page"
|
||||||
|
const val LOCAL_ACCOUNT_TYPE = "local_account_type"
|
||||||
|
|
||||||
const val CONTACT_ID = "contact_id"
|
const val CONTACT_ID = "contact_id"
|
||||||
|
|
||||||
|
@ -252,6 +252,29 @@ class ContactsHelper(val activity: BaseSimpleActivity) {
|
|||||||
}.start()
|
}.start()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fun getContactTypes(callback: (ArrayList<String>) -> Unit) {
|
||||||
|
val accounts = HashSet<String>()
|
||||||
|
Thread {
|
||||||
|
val uri = ContactsContract.RawContacts.CONTENT_URI
|
||||||
|
val projection = arrayOf(ContactsContract.RawContacts.ACCOUNT_TYPE)
|
||||||
|
|
||||||
|
var cursor: Cursor? = null
|
||||||
|
try {
|
||||||
|
cursor = activity.contentResolver.query(uri, projection, null, null, null)
|
||||||
|
if (cursor?.moveToFirst() == true) {
|
||||||
|
do {
|
||||||
|
val type = cursor.getStringValue(ContactsContract.RawContacts.ACCOUNT_TYPE) ?: continue
|
||||||
|
accounts.add(type)
|
||||||
|
} while (cursor.moveToNext())
|
||||||
|
}
|
||||||
|
} finally {
|
||||||
|
cursor?.close()
|
||||||
|
}
|
||||||
|
|
||||||
|
callback(ArrayList(accounts))
|
||||||
|
}.start()
|
||||||
|
}
|
||||||
|
|
||||||
private fun getContactSourceType(accountName: String): String {
|
private fun getContactSourceType(accountName: String): String {
|
||||||
if (accountName.isEmpty()) {
|
if (accountName.isEmpty()) {
|
||||||
return ""
|
return ""
|
||||||
|
Reference in New Issue
Block a user