Add an option to show/hide contact thumbnails

This commit is contained in:
Nikola Trubitsyn 2018-01-27 23:58:49 +03:00
parent 4ffcfcd2f4
commit 0a86ce2856
6 changed files with 55 additions and 8 deletions

View File

@ -42,6 +42,7 @@ class MainActivity : SimpleActivity(), RefreshContactsListener {
private var storedTextColor = 0 private var storedTextColor = 0
private var storedBackgroundColor = 0 private var storedBackgroundColor = 0
private var storedPrimaryColor = 0 private var storedPrimaryColor = 0
private var storedShowContactThumbnails = false
private var storedShowPhoneNumbers = false private var storedShowPhoneNumbers = false
private var storedStartNameWithSurname = false private var storedStartNameWithSurname = false
@ -76,6 +77,11 @@ class MainActivity : SimpleActivity(), RefreshContactsListener {
return return
} }
if (storedShowContactThumbnails != config.showContactThumbnails) {
restartActivity()
return
}
if (storedShowPhoneNumbers != config.showPhoneNumbers) { if (storedShowPhoneNumbers != config.showPhoneNumbers) {
restartActivity() restartActivity()
return return
@ -154,6 +160,7 @@ class MainActivity : SimpleActivity(), RefreshContactsListener {
storedTextColor = textColor storedTextColor = textColor
storedBackgroundColor = backgroundColor storedBackgroundColor = backgroundColor
storedPrimaryColor = primaryColor storedPrimaryColor = primaryColor
storedShowContactThumbnails = showContactThumbnails
storedShowPhoneNumbers = showPhoneNumbers storedShowPhoneNumbers = showPhoneNumbers
storedStartNameWithSurname = startNameWithSurname storedStartNameWithSurname = startNameWithSurname
} }

View File

@ -21,6 +21,7 @@ class SettingsActivity : SimpleActivity() {
setupCustomizeColors() setupCustomizeColors()
setupUseEnglish() setupUseEnglish()
setupShowInfoBubble() setupShowInfoBubble()
setupShowContactThumbnails()
setupShowPhoneNumbers() setupShowPhoneNumbers()
setupCallContactOnClick() setupCallContactOnClick()
setupStartNameWithSurname() setupStartNameWithSurname()
@ -51,6 +52,14 @@ class SettingsActivity : SimpleActivity() {
} }
} }
private fun setupShowContactThumbnails() {
settings_show_contact_thumbnails.isChecked = config.showContactThumbnails
settings_show_contact_thumbnails_holder.setOnClickListener {
settings_show_contact_thumbnails.toggle()
config.showContactThumbnails = settings_show_contact_thumbnails.isChecked
}
}
private fun setupShowPhoneNumbers() { private fun setupShowPhoneNumbers() {
settings_show_phone_numbers.isChecked = config.showPhoneNumbers settings_show_phone_numbers.isChecked = config.showPhoneNumbers
settings_show_phone_numbers_holder.setOnClickListener { settings_show_phone_numbers_holder.setOnClickListener {

View File

@ -33,10 +33,12 @@ class ContactsAdapter(activity: SimpleActivity, var contactItems: MutableList<Co
lateinit private var contactDrawable: Drawable lateinit private var contactDrawable: Drawable
var config = activity.config var config = activity.config
var startNameWithSurname: Boolean var startNameWithSurname: Boolean
var showContactThumbnails: Boolean
var showPhoneNumbers: Boolean var showPhoneNumbers: Boolean
init { init {
initDrawables() initDrawables()
showContactThumbnails = config.showContactThumbnails
showPhoneNumbers = config.showPhoneNumbers showPhoneNumbers = config.showPhoneNumbers
startNameWithSurname = config.startNameWithSurname startNameWithSurname = config.startNameWithSurname
} }
@ -190,16 +192,20 @@ class ContactsAdapter(activity: SimpleActivity, var contactItems: MutableList<Co
contact_number?.text = contact.phoneNumbers.firstOrNull()?.value ?: "" contact_number?.text = contact.phoneNumbers.firstOrNull()?.value ?: ""
contact_number?.setTextColor(textColor) contact_number?.setTextColor(textColor)
if (contact.photoUri.isNotEmpty()) { if (showContactThumbnails) {
val options = RequestOptions() if (contact.photoUri.isNotEmpty()) {
.signature(ObjectKey(contact.photoUri)) val options = RequestOptions()
.diskCacheStrategy(DiskCacheStrategy.RESOURCE) .signature(ObjectKey(contact.photoUri))
.error(contactDrawable) .diskCacheStrategy(DiskCacheStrategy.RESOURCE)
.centerCrop() .error(contactDrawable)
.centerCrop()
Glide.with(activity).load(contact.photoUri).transition(DrawableTransitionOptions.withCrossFade()).apply(options).into(contact_tmb) Glide.with(activity).load(contact.photoUri).transition(DrawableTransitionOptions.withCrossFade()).apply(options).into(contact_tmb)
} else {
contact_tmb.setImageDrawable(contactDrawable)
}
} else { } else {
contact_tmb.setImageDrawable(contactDrawable) contact_tmb.visibility = View.GONE
} }
} }
} }

View File

@ -24,6 +24,10 @@ class Config(context: Context) : BaseConfig(context) {
fun showAllContacts() = displayContactSources.size == 1 && displayContactSources.first() == "-1" fun showAllContacts() = displayContactSources.size == 1 && displayContactSources.first() == "-1"
var showContactThumbnails : Boolean
get() = prefs.getBoolean(SHOW_CONTACT_THUMBNAILS, true)
set(showContactThumbnails) = prefs.edit().putBoolean(SHOW_CONTACT_THUMBNAILS, showContactThumbnails).apply()
var showPhoneNumbers: Boolean var showPhoneNumbers: Boolean
get() = prefs.getBoolean(SHOW_PHONE_NUMBERS, false) get() = prefs.getBoolean(SHOW_PHONE_NUMBERS, false)
set(showPhoneNumbers) = prefs.edit().putBoolean(SHOW_PHONE_NUMBERS, showPhoneNumbers).apply() set(showPhoneNumbers) = prefs.edit().putBoolean(SHOW_PHONE_NUMBERS, showPhoneNumbers).apply()

View File

@ -4,6 +4,7 @@ import android.provider.ContactsContract.CommonDataKinds
// shared prefs // shared prefs
val CALL_CONTACT_ON_CLICK = "call_contact_on_click" val CALL_CONTACT_ON_CLICK = "call_contact_on_click"
val SHOW_CONTACT_THUMBNAILS = "show_contact_thumbnails"
val SHOW_PHONE_NUMBERS = "show_phone_numbers" val SHOW_PHONE_NUMBERS = "show_phone_numbers"
val DISPLAY_CONTACT_SOURCES = "display_contact_sources" val DISPLAY_CONTACT_SOURCES = "display_contact_sources"
val START_NAME_WITH_SURNAME = "start_name_with_surname" val START_NAME_WITH_SURNAME = "start_name_with_surname"

View File

@ -70,6 +70,26 @@
</RelativeLayout> </RelativeLayout>
<RelativeLayout
android:id="@+id/settings_show_contact_thumbnails_holder"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="@dimen/medium_margin"
android:background="?attr/selectableItemBackground"
android:padding="@dimen/activity_margin">
<com.simplemobiletools.commons.views.MySwitchCompat
android:id="@+id/settings_show_contact_thumbnails"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@null"
android:clickable="false"
android:paddingLeft="@dimen/medium_margin"
android:paddingStart="@dimen/medium_margin"
android:text="@string/show_contact_avatars"/>
</RelativeLayout>
<RelativeLayout <RelativeLayout
android:id="@+id/settings_show_phone_numbers_holder" android:id="@+id/settings_show_phone_numbers_holder"
android:layout_width="match_parent" android:layout_width="match_parent"