Merge pull request #50 from trubitsyn/feature-48

Add an option to show/hide contact thumbnails
This commit is contained in:
Tibor Kaputa 2018-01-28 09:03:46 +01:00 committed by GitHub
commit ff395278ff
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
12 changed files with 62 additions and 15 deletions

View File

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

View File

@ -21,6 +21,7 @@ class SettingsActivity : SimpleActivity() {
setupCustomizeColors()
setupUseEnglish()
setupShowInfoBubble()
setupShowContactThumbnails()
setupShowPhoneNumbers()
setupCallContactOnClick()
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() {
settings_show_phone_numbers.isChecked = config.showPhoneNumbers
settings_show_phone_numbers_holder.setOnClickListener {

View File

@ -11,6 +11,7 @@ import com.bumptech.glide.request.RequestOptions
import com.bumptech.glide.signature.ObjectKey
import com.simplemobiletools.commons.adapters.MyRecyclerViewAdapter
import com.simplemobiletools.commons.dialogs.ConfirmationDialog
import com.simplemobiletools.commons.extensions.beVisibleIf
import com.simplemobiletools.commons.extensions.getColoredDrawableWithColor
import com.simplemobiletools.commons.extensions.isActivityDestroyed
import com.simplemobiletools.commons.views.FastScroller
@ -33,10 +34,12 @@ class ContactsAdapter(activity: SimpleActivity, var contactItems: MutableList<Co
lateinit private var contactDrawable: Drawable
var config = activity.config
var startNameWithSurname: Boolean
var showContactThumbnails: Boolean
var showPhoneNumbers: Boolean
init {
initDrawables()
showContactThumbnails = config.showContactThumbnails
showPhoneNumbers = config.showPhoneNumbers
startNameWithSurname = config.startNameWithSurname
}
@ -189,17 +192,20 @@ class ContactsAdapter(activity: SimpleActivity, var contactItems: MutableList<Co
contact_name.setTextColor(textColor)
contact_number?.text = contact.phoneNumbers.firstOrNull()?.value ?: ""
contact_number?.setTextColor(textColor)
contact_tmb.beVisibleIf(showContactThumbnails)
if (contact.photoUri.isNotEmpty()) {
val options = RequestOptions()
.signature(ObjectKey(contact.photoUri))
.diskCacheStrategy(DiskCacheStrategy.RESOURCE)
.error(contactDrawable)
.centerCrop()
if (showContactThumbnails) {
if (contact.photoUri.isNotEmpty()) {
val options = RequestOptions()
.signature(ObjectKey(contact.photoUri))
.diskCacheStrategy(DiskCacheStrategy.RESOURCE)
.error(contactDrawable)
.centerCrop()
Glide.with(activity).load(contact.photoUri).transition(DrawableTransitionOptions.withCrossFade()).apply(options).into(contact_tmb)
} else {
contact_tmb.setImageDrawable(contactDrawable)
Glide.with(activity).load(contact.photoUri).transition(DrawableTransitionOptions.withCrossFade()).apply(options).into(contact_tmb)
} else {
contact_tmb.setImageDrawable(contactDrawable)
}
}
}
}

View File

@ -24,6 +24,10 @@ class Config(context: Context) : BaseConfig(context) {
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
get() = prefs.getBoolean(SHOW_PHONE_NUMBERS, false)
set(showPhoneNumbers) = prefs.edit().putBoolean(SHOW_PHONE_NUMBERS, showPhoneNumbers).apply()

View File

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

View File

@ -70,6 +70,26 @@
</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_thumbnails"/>
</RelativeLayout>
<RelativeLayout
android:id="@+id/settings_show_phone_numbers_holder"
android:layout_width="match_parent"

View File

@ -23,7 +23,7 @@
<string name="call_contact_on_click">Kontakt bei Klick anrufen</string>
<string name="start_name_with_surname">Namen mit Nachnamen beginnen</string>
<string name="show_phone_numbers">Zeige Telefonnummern im Hauptmenü</string>
<string name="show_contact_avatars">Show contact avatars</string>
<string name="show_contact_thumbnails">Show contact thumbnails</string>
<!-- Emails -->
<string name="email">Email</string>

View File

@ -23,7 +23,7 @@
<string name="call_contact_on_click">클릭으로 전화걸기</string>
<string name="start_name_with_surname">성을 먼저 표시</string>
<string name="show_phone_numbers">메인 스크린에 전화번호 표시</string>
<string name="show_contact_avatars">Show contact avatars</string>
<string name="show_contact_thumbnails">Show contact thumbnails</string>
<!-- Emails -->
<string name="email">이메일</string>

View File

@ -23,7 +23,7 @@
<string name="call_contact_on_click">Call contact on click</string>
<string name="start_name_with_surname">Start name with surname</string>
<string name="show_phone_numbers">Show phone numbers on the main screen</string>
<string name="show_contact_avatars">Show contact avatars</string>
<string name="show_contact_thumbnails">Show contact thumbnails</string>
<!-- Emails -->
<string name="email">E-mail</string>

View File

@ -23,7 +23,7 @@
<string name="call_contact_on_click">Zavolať kontakt po kliknutí</string>
<string name="start_name_with_surname">Začať meno priezviskom</string>
<string name="show_phone_numbers">Zobraziť telefónne čísla na hlavnej obrazovke</string>
<string name="show_contact_avatars">Zobraziť obrázky kontaktov</string>
<string name="show_contact_thumbnails">Zobraziť obrázky kontaktov</string>
<!-- Emails -->
<string name="email">Email</string>

View File

@ -23,7 +23,7 @@
<string name="call_contact_on_click">Ring kontakter när jag trycker på dem</string>
<string name="start_name_with_surname">Visa efternamn först</string>
<string name="show_phone_numbers">Visa telefonnummer i huvudvyn</string>
<string name="show_contact_avatars">Show contact avatars</string>
<string name="show_contact_thumbnails">Show contact thumbnails</string>
<!-- Emails -->
<string name="email">E-post</string>

View File

@ -23,7 +23,7 @@
<string name="call_contact_on_click">Call contact on click</string>
<string name="start_name_with_surname">Start name with surname</string>
<string name="show_phone_numbers">Show phone numbers on the main screen</string>
<string name="show_contact_avatars">Show contact avatars</string>
<string name="show_contact_thumbnails">Show contact thumbnails</string>
<!-- Emails -->
<string name="email">Email</string>