mirror of
https://github.com/SimpleMobileTools/Simple-Contacts.git
synced 2025-02-17 03:51:03 +01:00
allow sharing private contacts with Simple Dialer and SMS Messenger
This commit is contained in:
parent
7d7293959f
commit
e8b83801f4
@ -57,7 +57,7 @@ android {
|
||||
}
|
||||
|
||||
dependencies {
|
||||
implementation 'com.simplemobiletools:commons:5.28.2'
|
||||
implementation 'com.simplemobiletools:commons:5.28.10'
|
||||
implementation 'joda-time:joda-time:2.10.1'
|
||||
implementation 'com.googlecode.ez-vcard:ez-vcard:0.10.5'
|
||||
implementation 'com.github.tibbi:IndicatorFastScroll:08f512858a'
|
||||
|
@ -299,6 +299,11 @@
|
||||
android:resource="@xml/provider_paths"/>
|
||||
</provider>
|
||||
|
||||
<provider
|
||||
android:name=".contentproviders.MyContactsContentProvider"
|
||||
android:authorities="com.simplemobiletools.commons.contactsprovider"
|
||||
android:exported="true"/>
|
||||
|
||||
<activity-alias
|
||||
android:name=".activities.SplashActivity.Red"
|
||||
android:enabled="false"
|
||||
|
@ -36,7 +36,6 @@ import com.simplemobiletools.contacts.pro.extensions.getTempFile
|
||||
import com.simplemobiletools.contacts.pro.extensions.handleGenericContactClick
|
||||
import com.simplemobiletools.contacts.pro.fragments.MyViewPagerFragment
|
||||
import com.simplemobiletools.contacts.pro.helpers.*
|
||||
import com.simplemobiletools.contacts.pro.helpers.ContactsHelper
|
||||
import com.simplemobiletools.contacts.pro.interfaces.RefreshContactsListener
|
||||
import com.simplemobiletools.contacts.pro.models.Contact
|
||||
import kotlinx.android.synthetic.main.activity_main.*
|
||||
|
@ -45,6 +45,7 @@ class SettingsActivity : SimpleActivity() {
|
||||
setupShowCallConfirmation()
|
||||
setupShowDialpadButton()
|
||||
setupShowDialpadLetters()
|
||||
setupShowPrivateContacts()
|
||||
setupOnContactClick()
|
||||
updateTextColors(settings_holder)
|
||||
invalidateOptionsMenu()
|
||||
@ -162,6 +163,14 @@ class SettingsActivity : SimpleActivity() {
|
||||
}
|
||||
}
|
||||
|
||||
private fun setupShowPrivateContacts() {
|
||||
settings_show_private_contacts.isChecked = config.showPrivateContacts
|
||||
settings_show_private_contacts_holder.setOnClickListener {
|
||||
settings_show_private_contacts.toggle()
|
||||
config.showPrivateContacts = settings_show_private_contacts.isChecked
|
||||
}
|
||||
}
|
||||
|
||||
private fun setupOnContactClick() {
|
||||
settings_on_contact_click.text = getOnContactClickText()
|
||||
settings_on_contact_click_holder.setOnClickListener {
|
||||
|
@ -0,0 +1,47 @@
|
||||
package com.simplemobiletools.contacts.pro.contentproviders
|
||||
|
||||
import android.content.ContentProvider
|
||||
import android.content.ContentValues
|
||||
import android.database.Cursor
|
||||
import android.database.MatrixCursor
|
||||
import android.net.Uri
|
||||
import com.simplemobiletools.commons.helpers.MyContactsContentProvider
|
||||
import com.simplemobiletools.contacts.pro.extensions.config
|
||||
import com.simplemobiletools.contacts.pro.helpers.LocalContactsHelper
|
||||
|
||||
class MyContactsContentProvider : ContentProvider() {
|
||||
override fun insert(uri: Uri, contentValues: ContentValues?) = null
|
||||
|
||||
override fun query(uri: Uri, projection: Array<out String>?, selection: String?, selectionArgs: Array<out String>?, sortOrder: String?): Cursor? {
|
||||
if (context == null || !context!!.config.showPrivateContacts) {
|
||||
return null
|
||||
} else {
|
||||
val matrixCursor = MatrixCursor(arrayOf(
|
||||
MyContactsContentProvider.COL_RAW_ID,
|
||||
MyContactsContentProvider.COL_CONTACT_ID,
|
||||
MyContactsContentProvider.COL_NAME,
|
||||
MyContactsContentProvider.COL_PHOTO_URI,
|
||||
MyContactsContentProvider.COL_PHONE_NUMBER)
|
||||
)
|
||||
|
||||
LocalContactsHelper(context!!).getPrivateSimpleContactsSync().forEach {
|
||||
matrixCursor.newRow()
|
||||
.add(MyContactsContentProvider.COL_RAW_ID, it.rawId)
|
||||
.add(MyContactsContentProvider.COL_CONTACT_ID, it.contactId)
|
||||
.add(MyContactsContentProvider.COL_NAME, it.name)
|
||||
.add(MyContactsContentProvider.COL_PHOTO_URI, it.photoUri)
|
||||
.add(MyContactsContentProvider.COL_PHONE_NUMBER, it.phoneNumber)
|
||||
}
|
||||
|
||||
return matrixCursor
|
||||
}
|
||||
}
|
||||
|
||||
override fun onCreate() = true
|
||||
|
||||
override fun update(uri: Uri, values: ContentValues?, selection: String?, selectionArgs: Array<out String>?) = 1
|
||||
|
||||
override fun delete(uri: Uri, selection: String?, selectionArgs: Array<out String>?): Int = 0
|
||||
|
||||
override fun getType(uri: Uri) = ""
|
||||
}
|
@ -73,6 +73,10 @@ class Config(context: Context) : BaseConfig(context) {
|
||||
get() = prefs.getString(SPEED_DIAL, "")!!
|
||||
set(speedDial) = prefs.edit().putString(SPEED_DIAL, speedDial).apply()
|
||||
|
||||
var showPrivateContacts: Boolean
|
||||
get() = prefs.getBoolean(SHOW_PRIVATE_CONTACTS, true)
|
||||
set(showPrivateContacts) = prefs.edit().putBoolean(SHOW_PRIVATE_CONTACTS, showPrivateContacts).apply()
|
||||
|
||||
fun saveCustomSIM(number: String, SIMlabel: String) {
|
||||
prefs.edit().putString(REMEMBER_SIM_PREFIX + number, Uri.encode(SIMlabel)).apply()
|
||||
}
|
||||
|
@ -21,6 +21,7 @@ const val SPEED_DIAL = "speed_dial"
|
||||
const val LAST_EXPORT_PATH = "last_export_path"
|
||||
const val WAS_LOCAL_ACCOUNT_INITIALIZED = "was_local_account_initialized"
|
||||
const val REMEMBER_SIM_PREFIX = "remember_sim_"
|
||||
const val SHOW_PRIVATE_CONTACTS = "show_private_contacts"
|
||||
|
||||
const val CONTACT_ID = "contact_id"
|
||||
const val SMT_PRIVATE = "smt_private" // used at the contact source of local contacts hidden from other apps
|
||||
|
@ -6,6 +6,7 @@ import android.graphics.BitmapFactory
|
||||
import android.net.Uri
|
||||
import android.provider.MediaStore
|
||||
import com.simplemobiletools.commons.extensions.getChoppedList
|
||||
import com.simplemobiletools.commons.models.SimpleContact
|
||||
import com.simplemobiletools.contacts.pro.extensions.contactsDB
|
||||
import com.simplemobiletools.contacts.pro.extensions.getByteArray
|
||||
import com.simplemobiletools.contacts.pro.extensions.getEmptyContact
|
||||
@ -104,7 +105,6 @@ class LocalContactsHelper(val context: Context) {
|
||||
surname = localContact.surname
|
||||
suffix = localContact.suffix
|
||||
nickname = localContact.nickname
|
||||
photoUri = ""
|
||||
phoneNumbers = localContact.phoneNumbers
|
||||
emails = localContact.emails
|
||||
addresses = localContact.addresses
|
||||
@ -152,4 +152,14 @@ class LocalContactsHelper(val context: Context) {
|
||||
IMs = contact.IMs
|
||||
}
|
||||
}
|
||||
|
||||
private fun convertContactToSimpleContact(contact: Contact?): SimpleContact? {
|
||||
return if (contact == null || contact.phoneNumbers.isEmpty()) {
|
||||
null
|
||||
} else {
|
||||
SimpleContact(contact.id, 0, contact.getNameToDisplay(), contact.photoUri, contact.phoneNumbers.first().value)
|
||||
}
|
||||
}
|
||||
|
||||
fun getPrivateSimpleContactsSync() = getAllContacts().mapNotNull { convertContactToSimpleContact(it) }
|
||||
}
|
||||
|
@ -1,6 +1,5 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<ScrollView
|
||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||
android:id="@+id/settings_scrollview"
|
||||
android:layout_width="match_parent"
|
||||
@ -29,7 +28,7 @@
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_centerVertical="true"
|
||||
android:paddingStart="@dimen/medium_margin"
|
||||
android:text="@string/customize_colors"/>
|
||||
android:text="@string/customize_colors" />
|
||||
|
||||
</RelativeLayout>
|
||||
|
||||
@ -52,7 +51,7 @@
|
||||
android:clickable="false"
|
||||
android:paddingStart="@dimen/medium_margin"
|
||||
android:text="@string/use_english_language"
|
||||
app:switchPadding="@dimen/medium_margin"/>
|
||||
app:switchPadding="@dimen/medium_margin" />
|
||||
|
||||
</RelativeLayout>
|
||||
|
||||
@ -73,7 +72,7 @@
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_centerVertical="true"
|
||||
android:paddingStart="@dimen/medium_margin"
|
||||
android:text="@string/manage_shown_contact_fields"/>
|
||||
android:text="@string/manage_shown_contact_fields" />
|
||||
|
||||
</RelativeLayout>
|
||||
|
||||
@ -94,7 +93,7 @@
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_centerVertical="true"
|
||||
android:paddingStart="@dimen/medium_margin"
|
||||
android:text="@string/manage_shown_tabs"/>
|
||||
android:text="@string/manage_shown_tabs" />
|
||||
|
||||
</RelativeLayout>
|
||||
|
||||
@ -115,7 +114,7 @@
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_centerVertical="true"
|
||||
android:paddingStart="@dimen/medium_margin"
|
||||
android:text="@string/manage_blocked_numbers"/>
|
||||
android:text="@string/manage_blocked_numbers" />
|
||||
|
||||
</RelativeLayout>
|
||||
|
||||
@ -136,7 +135,7 @@
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_centerVertical="true"
|
||||
android:paddingStart="@dimen/medium_margin"
|
||||
android:text="@string/manage_speed_dial"/>
|
||||
android:text="@string/manage_speed_dial" />
|
||||
|
||||
</RelativeLayout>
|
||||
|
||||
@ -159,7 +158,7 @@
|
||||
android:layout_toStartOf="@+id/settings_font_size"
|
||||
android:paddingLeft="@dimen/medium_margin"
|
||||
android:paddingRight="@dimen/medium_margin"
|
||||
android:text="@string/font_size"/>
|
||||
android:text="@string/font_size" />
|
||||
|
||||
<com.simplemobiletools.commons.views.MyTextView
|
||||
android:id="@+id/settings_font_size"
|
||||
@ -168,7 +167,7 @@
|
||||
android:layout_alignParentEnd="true"
|
||||
android:layout_marginEnd="@dimen/medium_margin"
|
||||
android:background="@null"
|
||||
android:clickable="false"/>
|
||||
android:clickable="false" />
|
||||
|
||||
</RelativeLayout>
|
||||
|
||||
@ -191,7 +190,7 @@
|
||||
android:clickable="false"
|
||||
android:paddingStart="@dimen/medium_margin"
|
||||
android:text="@string/show_contact_thumbnails"
|
||||
app:switchPadding="@dimen/medium_margin"/>
|
||||
app:switchPadding="@dimen/medium_margin" />
|
||||
|
||||
</RelativeLayout>
|
||||
|
||||
@ -214,7 +213,7 @@
|
||||
android:clickable="false"
|
||||
android:paddingStart="@dimen/medium_margin"
|
||||
android:text="@string/show_phone_numbers"
|
||||
app:switchPadding="@dimen/medium_margin"/>
|
||||
app:switchPadding="@dimen/medium_margin" />
|
||||
|
||||
</RelativeLayout>
|
||||
|
||||
@ -237,7 +236,7 @@
|
||||
android:clickable="false"
|
||||
android:paddingStart="@dimen/medium_margin"
|
||||
android:text="@string/show_only_contacts_with_numbers"
|
||||
app:switchPadding="@dimen/medium_margin"/>
|
||||
app:switchPadding="@dimen/medium_margin" />
|
||||
|
||||
</RelativeLayout>
|
||||
|
||||
@ -260,7 +259,7 @@
|
||||
android:clickable="false"
|
||||
android:paddingStart="@dimen/medium_margin"
|
||||
android:text="@string/start_name_with_surname"
|
||||
app:switchPadding="@dimen/medium_margin"/>
|
||||
app:switchPadding="@dimen/medium_margin" />
|
||||
|
||||
</RelativeLayout>
|
||||
|
||||
@ -283,7 +282,7 @@
|
||||
android:clickable="false"
|
||||
android:paddingStart="@dimen/medium_margin"
|
||||
android:text="@string/show_call_confirmation_dialog"
|
||||
app:switchPadding="@dimen/medium_margin"/>
|
||||
app:switchPadding="@dimen/medium_margin" />
|
||||
|
||||
</RelativeLayout>
|
||||
|
||||
@ -306,7 +305,7 @@
|
||||
android:clickable="false"
|
||||
android:paddingStart="@dimen/medium_margin"
|
||||
android:text="@string/show_dialpad_button"
|
||||
app:switchPadding="@dimen/medium_margin"/>
|
||||
app:switchPadding="@dimen/medium_margin" />
|
||||
|
||||
</RelativeLayout>
|
||||
|
||||
@ -329,7 +328,30 @@
|
||||
android:clickable="false"
|
||||
android:paddingStart="@dimen/medium_margin"
|
||||
android:text="@string/show_dialpad_letters"
|
||||
app:switchPadding="@dimen/medium_margin"/>
|
||||
app:switchPadding="@dimen/medium_margin" />
|
||||
|
||||
</RelativeLayout>
|
||||
|
||||
<RelativeLayout
|
||||
android:id="@+id/settings_show_private_contacts_holder"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginTop="@dimen/medium_margin"
|
||||
android:background="?attr/selectableItemBackground"
|
||||
android:paddingStart="@dimen/normal_margin"
|
||||
android:paddingTop="@dimen/activity_margin"
|
||||
android:paddingEnd="@dimen/normal_margin"
|
||||
android:paddingBottom="@dimen/activity_margin">
|
||||
|
||||
<com.simplemobiletools.commons.views.MySwitchCompat
|
||||
android:id="@+id/settings_show_private_contacts"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:background="@null"
|
||||
android:clickable="false"
|
||||
android:paddingStart="@dimen/medium_margin"
|
||||
android:text="@string/show_private_contacts"
|
||||
app:switchPadding="@dimen/medium_margin" />
|
||||
|
||||
</RelativeLayout>
|
||||
|
||||
@ -352,7 +374,7 @@
|
||||
android:layout_toStartOf="@+id/settings_on_contact_click"
|
||||
android:paddingStart="@dimen/medium_margin"
|
||||
android:paddingEnd="@dimen/medium_margin"
|
||||
android:text="@string/on_contact_click"/>
|
||||
android:text="@string/on_contact_click" />
|
||||
|
||||
<com.simplemobiletools.commons.views.MyTextView
|
||||
android:id="@+id/settings_on_contact_click"
|
||||
@ -361,7 +383,7 @@
|
||||
android:layout_alignParentEnd="true"
|
||||
android:layout_marginEnd="@dimen/small_margin"
|
||||
android:background="@null"
|
||||
android:clickable="false"/>
|
||||
android:clickable="false" />
|
||||
|
||||
</RelativeLayout>
|
||||
</LinearLayout>
|
||||
|
Loading…
x
Reference in New Issue
Block a user