From ea16415503b7d7ce10dde7f87308fe988f4b9b58 Mon Sep 17 00:00:00 2001 From: tibbi Date: Wed, 17 Jun 2020 22:28:32 +0200 Subject: [PATCH] allow customizing the text size --- .../activities/SettingsActivity.kt | 21 +++++++++++- .../smsmessenger/adapters/ContactsAdapter.kt | 17 +++++++--- .../adapters/ConversationsAdapter.kt | 20 ++++++++++-- .../smsmessenger/adapters/ThreadAdapter.kt | 13 ++++++-- app/src/main/res/layout/activity_settings.xml | 32 +++++++++++++++++++ 5 files changed, 92 insertions(+), 11 deletions(-) diff --git a/app/src/main/kotlin/com/simplemobiletools/smsmessenger/activities/SettingsActivity.kt b/app/src/main/kotlin/com/simplemobiletools/smsmessenger/activities/SettingsActivity.kt index 885e3f69..c9a3d38d 100644 --- a/app/src/main/kotlin/com/simplemobiletools/smsmessenger/activities/SettingsActivity.kt +++ b/app/src/main/kotlin/com/simplemobiletools/smsmessenger/activities/SettingsActivity.kt @@ -7,8 +7,10 @@ import android.os.Bundle import android.view.Menu import com.simplemobiletools.commons.activities.ManageBlockedNumbersActivity import com.simplemobiletools.commons.dialogs.ChangeDateTimeFormatDialog +import com.simplemobiletools.commons.dialogs.RadioGroupDialog import com.simplemobiletools.commons.extensions.* -import com.simplemobiletools.commons.helpers.isNougatPlus +import com.simplemobiletools.commons.helpers.* +import com.simplemobiletools.commons.models.RadioItem import com.simplemobiletools.smsmessenger.R import com.simplemobiletools.smsmessenger.extensions.config import com.simplemobiletools.smsmessenger.helpers.refreshMessages @@ -31,6 +33,7 @@ class SettingsActivity : SimpleActivity() { setupUseEnglish() setupManageBlockedNumbers() setupChangeDateTimeFormat() + setupFontSize() updateTextColors(settings_scrollview) if (blockedNumbersAtPause != -1 && blockedNumbersAtPause != getBlockedNumbers().hashCode()) { @@ -87,4 +90,20 @@ class SettingsActivity : SimpleActivity() { } } } + + private fun setupFontSize() { + settings_font_size.text = getFontSizeText() + settings_font_size_holder.setOnClickListener { + val items = arrayListOf( + RadioItem(FONT_SIZE_SMALL, getString(R.string.small)), + RadioItem(FONT_SIZE_MEDIUM, getString(R.string.medium)), + RadioItem(FONT_SIZE_LARGE, getString(R.string.large)), + RadioItem(FONT_SIZE_EXTRA_LARGE, getString(R.string.extra_large))) + + RadioGroupDialog(this@SettingsActivity, items, config.fontSize) { + config.fontSize = it as Int + settings_font_size.text = getFontSizeText() + } + } + } } diff --git a/app/src/main/kotlin/com/simplemobiletools/smsmessenger/adapters/ContactsAdapter.kt b/app/src/main/kotlin/com/simplemobiletools/smsmessenger/adapters/ContactsAdapter.kt index c08be665..a7ed2248 100644 --- a/app/src/main/kotlin/com/simplemobiletools/smsmessenger/adapters/ContactsAdapter.kt +++ b/app/src/main/kotlin/com/simplemobiletools/smsmessenger/adapters/ContactsAdapter.kt @@ -1,5 +1,6 @@ package com.simplemobiletools.smsmessenger.adapters +import android.util.TypedValue import android.view.Menu import android.view.View import android.view.ViewGroup @@ -7,6 +8,7 @@ import android.widget.ImageView import android.widget.TextView import com.bumptech.glide.Glide import com.simplemobiletools.commons.adapters.MyRecyclerViewAdapter +import com.simplemobiletools.commons.extensions.getTextSize import com.simplemobiletools.commons.helpers.SimpleContactsHelper import com.simplemobiletools.commons.models.SimpleContact import com.simplemobiletools.commons.views.FastScroller @@ -17,6 +19,7 @@ import java.util.* class ContactsAdapter(activity: SimpleActivity, var contacts: ArrayList, recyclerView: MyRecyclerView, fastScroller: FastScroller?, itemClick: (Any) -> Unit) : MyRecyclerViewAdapter(activity, recyclerView, fastScroller, itemClick) { + private var fontSize = activity.getTextSize() override fun getActionMenuId() = 0 @@ -57,11 +60,17 @@ class ContactsAdapter(activity: SimpleActivity, var contacts: ArrayList(R.id.item_contact_name).text = contact.name - findViewById(R.id.item_contact_name).setTextColor(textColor) + findViewById(R.id.item_contact_name).apply { + text = contact.name + setTextColor(textColor) + setTextSize(TypedValue.COMPLEX_UNIT_PX, fontSize * 1.2f) + } - findViewById(R.id.item_contact_number).text = contact.phoneNumber - findViewById(R.id.item_contact_number).setTextColor(textColor) + findViewById(R.id.item_contact_number).apply { + text = contact.phoneNumber + setTextColor(textColor) + setTextSize(TypedValue.COMPLEX_UNIT_PX, fontSize) + } SimpleContactsHelper(context).loadContactImage(contact.photoUri, findViewById(R.id.item_contact_image), contact.name) } diff --git a/app/src/main/kotlin/com/simplemobiletools/smsmessenger/adapters/ConversationsAdapter.kt b/app/src/main/kotlin/com/simplemobiletools/smsmessenger/adapters/ConversationsAdapter.kt index 4d294124..442aabba 100644 --- a/app/src/main/kotlin/com/simplemobiletools/smsmessenger/adapters/ConversationsAdapter.kt +++ b/app/src/main/kotlin/com/simplemobiletools/smsmessenger/adapters/ConversationsAdapter.kt @@ -3,6 +3,7 @@ package com.simplemobiletools.smsmessenger.adapters import android.content.Intent import android.graphics.Typeface import android.text.TextUtils +import android.util.TypedValue import android.view.Menu import android.view.View import android.view.ViewGroup @@ -12,6 +13,7 @@ import com.simplemobiletools.commons.adapters.MyRecyclerViewAdapter import com.simplemobiletools.commons.dialogs.ConfirmationDialog import com.simplemobiletools.commons.extensions.addBlockedNumber import com.simplemobiletools.commons.extensions.formatDateOrTime +import com.simplemobiletools.commons.extensions.getTextSize import com.simplemobiletools.commons.extensions.toast import com.simplemobiletools.commons.helpers.KEY_PHONE import com.simplemobiletools.commons.helpers.SimpleContactsHelper @@ -28,6 +30,7 @@ import kotlinx.android.synthetic.main.item_conversation.view.* class ConversationsAdapter(activity: SimpleActivity, var conversations: ArrayList, recyclerView: MyRecyclerView, fastScroller: FastScroller, itemClick: (Any) -> Unit) : MyRecyclerViewAdapter(activity, recyclerView, fastScroller, itemClick) { + private var fontSize = activity.getTextSize() init { setupDragListener(true) @@ -186,9 +189,20 @@ class ConversationsAdapter(activity: SimpleActivity, var conversations: ArrayLis view.apply { conversation_frame.isSelected = selectedKeys.contains(conversation.thread_id) - conversation_address.text = conversation.title - conversation_body_short.text = conversation.snippet - conversation_date.text = conversation.date.formatDateOrTime(context, true) + conversation_address.apply { + text = conversation.title + setTextSize(TypedValue.COMPLEX_UNIT_PX, fontSize * 1.2f) + } + + conversation_body_short.apply { + text = conversation.snippet + setTextSize(TypedValue.COMPLEX_UNIT_PX, fontSize) + } + + conversation_date.apply { + text = conversation.date.formatDateOrTime(context, true) + setTextSize(TypedValue.COMPLEX_UNIT_PX, fontSize * 0.8f) + } if (conversation.read) { conversation_address.setTypeface(null, Typeface.NORMAL) diff --git a/app/src/main/kotlin/com/simplemobiletools/smsmessenger/adapters/ThreadAdapter.kt b/app/src/main/kotlin/com/simplemobiletools/smsmessenger/adapters/ThreadAdapter.kt index 337452f9..a01ac1c3 100644 --- a/app/src/main/kotlin/com/simplemobiletools/smsmessenger/adapters/ThreadAdapter.kt +++ b/app/src/main/kotlin/com/simplemobiletools/smsmessenger/adapters/ThreadAdapter.kt @@ -5,6 +5,7 @@ import android.content.Intent import android.graphics.drawable.Drawable import android.net.Uri import android.telephony.SubscriptionManager +import android.util.TypedValue import android.view.Menu import android.view.View import android.view.ViewGroup @@ -42,8 +43,8 @@ import kotlinx.android.synthetic.main.item_thread_date_time.view.* class ThreadAdapter(activity: SimpleActivity, var messages: ArrayList, recyclerView: MyRecyclerView, fastScroller: FastScroller, itemClick: (Any) -> Unit) : MyRecyclerViewAdapter(activity, recyclerView, fastScroller, itemClick) { - private val roundedCornersRadius = resources.getDimension(R.dimen.normal_margin).toInt() + private var fontSize = activity.getTextSize() @SuppressLint("MissingPermission") private val hasMultipleSIMCards = SubscriptionManager.from(activity).activeSubscriptionInfoList?.size ?: 0 > 1 @@ -181,7 +182,10 @@ class ThreadAdapter(activity: SimpleActivity, var messages: ArrayList + + + + + + + +