From b8b0db75349196ffa23a176ad6ce6058516f5ff3 Mon Sep 17 00:00:00 2001 From: tibbi Date: Tue, 29 Mar 2022 12:02:58 +0200 Subject: [PATCH] lets replace Adjusted primary color with Proper primary color --- .../commons/activities/FAQActivity.kt | 2 +- .../activities/ManageBlockedNumbersActivity.kt | 2 +- .../commons/adapters/MyRecyclerViewAdapter.kt | 11 +++++------ .../commons/adapters/MyRecyclerViewListAdapter.kt | 11 +++++------ .../commons/dialogs/FilePickerDialog.kt | 7 +++---- .../commons/dialogs/RateStarsDialog.kt | 4 ++-- .../commons/dialogs/RenameDialog.kt | 3 +-- .../commons/dialogs/SecurityDialog.kt | 2 +- .../commons/dialogs/SelectAlarmSoundDialog.kt | 7 +++---- .../commons/extensions/Activity.kt | 8 ++++---- .../commons/extensions/Context-styling.kt | 14 +++++--------- .../simplemobiletools/commons/extensions/String.kt | 4 ++-- .../simplemobiletools/commons/views/PatternTab.kt | 4 ++-- 13 files changed, 35 insertions(+), 44 deletions(-) diff --git a/commons/src/main/kotlin/com/simplemobiletools/commons/activities/FAQActivity.kt b/commons/src/main/kotlin/com/simplemobiletools/commons/activities/FAQActivity.kt index 9cfae9051..bb0aea0c2 100644 --- a/commons/src/main/kotlin/com/simplemobiletools/commons/activities/FAQActivity.kt +++ b/commons/src/main/kotlin/com/simplemobiletools/commons/activities/FAQActivity.kt @@ -26,7 +26,7 @@ class FAQActivity : BaseSimpleActivity() { setContentView(R.layout.activity_faq) val dividerMargin = resources.getDimension(R.dimen.medium_margin).toInt() - val titleColor = getAdjustedPrimaryColor() + val titleColor = getProperPrimaryColor() val backgroundColor = getProperBackgroundColor() val textColor = getProperTextColor() diff --git a/commons/src/main/kotlin/com/simplemobiletools/commons/activities/ManageBlockedNumbersActivity.kt b/commons/src/main/kotlin/com/simplemobiletools/commons/activities/ManageBlockedNumbersActivity.kt index 0560b04cf..4ff460a99 100644 --- a/commons/src/main/kotlin/com/simplemobiletools/commons/activities/ManageBlockedNumbersActivity.kt +++ b/commons/src/main/kotlin/com/simplemobiletools/commons/activities/ManageBlockedNumbersActivity.kt @@ -38,7 +38,7 @@ class ManageBlockedNumbersActivity : BaseSimpleActivity(), RefreshRecyclerViewLi manage_blocked_numbers_placeholder_2.apply { underlineText() - setTextColor(getAdjustedPrimaryColor()) + setTextColor(getProperPrimaryColor()) setOnClickListener { if (isDefaultDialer()) { addOrEditBlockedNumber() diff --git a/commons/src/main/kotlin/com/simplemobiletools/commons/adapters/MyRecyclerViewAdapter.kt b/commons/src/main/kotlin/com/simplemobiletools/commons/adapters/MyRecyclerViewAdapter.kt index af42c188a..454161b5c 100644 --- a/commons/src/main/kotlin/com/simplemobiletools/commons/adapters/MyRecyclerViewAdapter.kt +++ b/commons/src/main/kotlin/com/simplemobiletools/commons/adapters/MyRecyclerViewAdapter.kt @@ -9,11 +9,10 @@ import androidx.recyclerview.widget.RecyclerView import com.simplemobiletools.commons.R import com.simplemobiletools.commons.activities.BaseSimpleActivity import com.simplemobiletools.commons.extensions.baseConfig -import com.simplemobiletools.commons.extensions.getAdjustedPrimaryColor import com.simplemobiletools.commons.extensions.getContrastColor +import com.simplemobiletools.commons.extensions.getProperPrimaryColor import com.simplemobiletools.commons.interfaces.MyActionModeCallback import com.simplemobiletools.commons.views.MyRecyclerView -import java.util.* abstract class MyRecyclerViewAdapter(val activity: BaseSimpleActivity, val recyclerView: MyRecyclerView, val itemClick: (Any) -> Unit) : RecyclerView.Adapter() { @@ -21,8 +20,8 @@ abstract class MyRecyclerViewAdapter(val activity: BaseSimpleActivity, val recyc protected val resources = activity.resources!! protected val layoutInflater = activity.layoutInflater protected var primaryColor = baseConfig.primaryColor - protected var adjustedPrimaryColor = activity.getAdjustedPrimaryColor() - protected var contrastColor = adjustedPrimaryColor.getContrastColor() + protected var properPrimaryColor = activity.getProperPrimaryColor() + protected var contrastColor = properPrimaryColor.getContrastColor() protected var textColor = baseConfig.textColor protected var backgroundColor = baseConfig.backgroundColor protected var actModeCallback: MyActionModeCallback @@ -273,8 +272,8 @@ abstract class MyRecyclerViewAdapter(val activity: BaseSimpleActivity, val recyc fun updatePrimaryColor(primaryColor: Int) { this.primaryColor = primaryColor - adjustedPrimaryColor = activity.getAdjustedPrimaryColor() - contrastColor = adjustedPrimaryColor.getContrastColor() + properPrimaryColor = activity.getProperPrimaryColor() + contrastColor = properPrimaryColor.getContrastColor() } fun updateBackgroundColor(backgroundColor: Int) { diff --git a/commons/src/main/kotlin/com/simplemobiletools/commons/adapters/MyRecyclerViewListAdapter.kt b/commons/src/main/kotlin/com/simplemobiletools/commons/adapters/MyRecyclerViewListAdapter.kt index 3778ab458..10dd33f3f 100644 --- a/commons/src/main/kotlin/com/simplemobiletools/commons/adapters/MyRecyclerViewListAdapter.kt +++ b/commons/src/main/kotlin/com/simplemobiletools/commons/adapters/MyRecyclerViewListAdapter.kt @@ -10,11 +10,10 @@ import androidx.recyclerview.widget.RecyclerView import com.simplemobiletools.commons.R import com.simplemobiletools.commons.activities.BaseSimpleActivity import com.simplemobiletools.commons.extensions.baseConfig -import com.simplemobiletools.commons.extensions.getAdjustedPrimaryColor import com.simplemobiletools.commons.extensions.getContrastColor +import com.simplemobiletools.commons.extensions.getProperPrimaryColor import com.simplemobiletools.commons.interfaces.MyActionModeCallback import com.simplemobiletools.commons.views.MyRecyclerView -import java.util.* abstract class MyRecyclerViewListAdapter( val activity: BaseSimpleActivity, @@ -27,8 +26,8 @@ abstract class MyRecyclerViewListAdapter( protected val resources = activity.resources!! protected val layoutInflater = activity.layoutInflater protected var primaryColor = baseConfig.primaryColor - protected var adjustedPrimaryColor = activity.getAdjustedPrimaryColor() - protected var contrastColor = adjustedPrimaryColor.getContrastColor() + protected var primaryPrimaryColor = activity.getProperPrimaryColor() + protected var contrastColor = primaryPrimaryColor.getContrastColor() protected var textColor = baseConfig.textColor protected var backgroundColor = baseConfig.backgroundColor protected var actModeCallback: MyActionModeCallback @@ -278,8 +277,8 @@ abstract class MyRecyclerViewListAdapter( fun updatePrimaryColor(primaryColor: Int) { this.primaryColor = primaryColor - adjustedPrimaryColor = activity.getAdjustedPrimaryColor() - contrastColor = adjustedPrimaryColor.getContrastColor() + primaryPrimaryColor = activity.getProperPrimaryColor() + contrastColor = primaryPrimaryColor.getContrastColor() } fun updateBackgroundColor(backgroundColor: Int) { diff --git a/commons/src/main/kotlin/com/simplemobiletools/commons/dialogs/FilePickerDialog.kt b/commons/src/main/kotlin/com/simplemobiletools/commons/dialogs/FilePickerDialog.kt index 451d54a78..3972d9cb7 100644 --- a/commons/src/main/kotlin/com/simplemobiletools/commons/dialogs/FilePickerDialog.kt +++ b/commons/src/main/kotlin/com/simplemobiletools/commons/dialogs/FilePickerDialog.kt @@ -16,7 +16,6 @@ import com.simplemobiletools.commons.models.FileDirItem import com.simplemobiletools.commons.views.Breadcrumbs import kotlinx.android.synthetic.main.dialog_filepicker.view.* import java.io.File -import java.util.* /** * The only filepicker constructor with a couple optional parameters @@ -102,7 +101,7 @@ class FilePickerDialog( } mDialogView.filepicker_placeholder.setTextColor(activity.baseConfig.textColor) - mDialogView.filepicker_fastscroller.updateColors(activity.getAdjustedPrimaryColor()) + mDialogView.filepicker_fastscroller.updateColors(activity.getProperPrimaryColor()) mDialogView.filepicker_fab_show_hidden.apply { beVisibleIf(!showHidden && canAddShowHiddenButton) setOnClickListener { @@ -295,7 +294,7 @@ class FilePickerDialog( mDialogView.apply { filepicker_favorites_holder.beVisible() filepicker_files_holder.beGone() - val drawable = activity.resources.getColoredDrawableWithColor(R.drawable.ic_folder_vector, activity.getAdjustedPrimaryColor().getContrastColor()) + val drawable = activity.resources.getColoredDrawableWithColor(R.drawable.ic_folder_vector, activity.getProperPrimaryColor().getContrastColor()) filepicker_fab_show_favorites.setImageDrawable(drawable) } } @@ -304,7 +303,7 @@ class FilePickerDialog( mDialogView.apply { filepicker_favorites_holder.beGone() filepicker_files_holder.beVisible() - val drawable = activity.resources.getColoredDrawableWithColor(R.drawable.ic_star_vector, activity.getAdjustedPrimaryColor().getContrastColor()) + val drawable = activity.resources.getColoredDrawableWithColor(R.drawable.ic_star_vector, activity.getProperPrimaryColor().getContrastColor()) filepicker_fab_show_favorites.setImageDrawable(drawable) } } diff --git a/commons/src/main/kotlin/com/simplemobiletools/commons/dialogs/RateStarsDialog.kt b/commons/src/main/kotlin/com/simplemobiletools/commons/dialogs/RateStarsDialog.kt index e96cbb4d8..4e174c852 100644 --- a/commons/src/main/kotlin/com/simplemobiletools/commons/dialogs/RateStarsDialog.kt +++ b/commons/src/main/kotlin/com/simplemobiletools/commons/dialogs/RateStarsDialog.kt @@ -11,9 +11,9 @@ class RateStarsDialog(val activity: Activity) { init { val view = activity.layoutInflater.inflate(R.layout.dialog_rate_stars, null).apply { - val textColor = activity.baseConfig.textColor + val primaryColor = activity.getProperPrimaryColor() arrayOf(rate_star_1, rate_star_2, rate_star_3, rate_star_4, rate_star_5).forEach { - it.applyColorFilter(textColor) + it.applyColorFilter(primaryColor) } rate_star_1.setOnClickListener { dialogCancelled(true) } diff --git a/commons/src/main/kotlin/com/simplemobiletools/commons/dialogs/RenameDialog.kt b/commons/src/main/kotlin/com/simplemobiletools/commons/dialogs/RenameDialog.kt index bb7720d87..d4ef91309 100644 --- a/commons/src/main/kotlin/com/simplemobiletools/commons/dialogs/RenameDialog.kt +++ b/commons/src/main/kotlin/com/simplemobiletools/commons/dialogs/RenameDialog.kt @@ -11,7 +11,6 @@ import com.simplemobiletools.commons.helpers.RENAME_PATTERN import com.simplemobiletools.commons.helpers.RENAME_SIMPLE import com.simplemobiletools.commons.views.MyViewPager import kotlinx.android.synthetic.main.dialog_rename.view.* -import java.util.* class RenameDialog(val activity: BaseSimpleActivity, val paths: ArrayList, val useMediaFileExtension: Boolean, val callback: () -> Unit) { var dialog: AlertDialog? = null @@ -31,7 +30,7 @@ class RenameDialog(val activity: BaseSimpleActivity, val paths: ArrayList PROTECTION_PATTERN diff --git a/commons/src/main/kotlin/com/simplemobiletools/commons/dialogs/SelectAlarmSoundDialog.kt b/commons/src/main/kotlin/com/simplemobiletools/commons/dialogs/SelectAlarmSoundDialog.kt index 44a5bce84..1961983d0 100644 --- a/commons/src/main/kotlin/com/simplemobiletools/commons/dialogs/SelectAlarmSoundDialog.kt +++ b/commons/src/main/kotlin/com/simplemobiletools/commons/dialogs/SelectAlarmSoundDialog.kt @@ -17,7 +17,6 @@ import com.simplemobiletools.commons.models.AlarmSound import com.simplemobiletools.commons.models.RadioItem import com.simplemobiletools.commons.views.MyCompatRadioButton import kotlinx.android.synthetic.main.dialog_select_alarm_sound.view.* -import java.util.* class SelectAlarmSoundDialog( val activity: BaseSimpleActivity, val currentUri: String, val audioStream: Int, val pickAudioIntentId: Int, @@ -39,8 +38,8 @@ class SelectAlarmSoundDialog( gotSystemAlarms() } - view.dialog_select_alarm_your_label.setTextColor(activity.getAdjustedPrimaryColor()) - view.dialog_select_alarm_system_label.setTextColor(activity.getAdjustedPrimaryColor()) + view.dialog_select_alarm_your_label.setTextColor(activity.getProperPrimaryColor()) + view.dialog_select_alarm_system_label.setTextColor(activity.getProperPrimaryColor()) addYourAlarms() @@ -75,7 +74,7 @@ class SelectAlarmSoundDialog( text = alarmSound.title isChecked = alarmSound.uri == currentUri id = alarmSound.id - setColors(config.textColor, activity.getAdjustedPrimaryColor(), config.backgroundColor) + setColors(config.textColor, activity.getProperPrimaryColor(), config.backgroundColor) setOnClickListener { alarmClicked(alarmSound) diff --git a/commons/src/main/kotlin/com/simplemobiletools/commons/extensions/Activity.kt b/commons/src/main/kotlin/com/simplemobiletools/commons/extensions/Activity.kt index 77224e12d..c39fde2cd 100644 --- a/commons/src/main/kotlin/com/simplemobiletools/commons/extensions/Activity.kt +++ b/commons/src/main/kotlin/com/simplemobiletools/commons/extensions/Activity.kt @@ -1357,11 +1357,11 @@ fun Activity.setupDialogStuff( val textColor = getProperTextColor() val backgroundColor = getProperBackgroundColor() - val adjustedPrimaryColor = getAdjustedPrimaryColor() + val primaryColor = getProperPrimaryColor() if (view is ViewGroup) { updateTextColors(view) } else if (view is MyTextView) { - view.setColors(textColor, adjustedPrimaryColor, backgroundColor) + view.setColors(textColor, primaryColor, backgroundColor) } var title: TextView? = null @@ -1378,10 +1378,10 @@ fun Activity.setupDialogStuff( } // if we use the same primary and background color, use the text color for dialog confirmation buttons - val dialogButtonColor = if (adjustedPrimaryColor == baseConfig.backgroundColor) { + val dialogButtonColor = if (primaryColor == baseConfig.backgroundColor) { textColor } else { - adjustedPrimaryColor + primaryColor } dialog.apply { diff --git a/commons/src/main/kotlin/com/simplemobiletools/commons/extensions/Context-styling.kt b/commons/src/main/kotlin/com/simplemobiletools/commons/extensions/Context-styling.kt index 742147fc4..9f00e0504 100644 --- a/commons/src/main/kotlin/com/simplemobiletools/commons/extensions/Context-styling.kt +++ b/commons/src/main/kotlin/com/simplemobiletools/commons/extensions/Context-styling.kt @@ -12,6 +12,7 @@ import com.simplemobiletools.commons.helpers.* import com.simplemobiletools.commons.models.SharedTheme import com.simplemobiletools.commons.views.* +// handle system default theme (Material You) specially as the color is taken from the system, not hardcoded by us fun Context.getProperTextColor() = if (baseConfig.isUsingSystemTheme) { resources.getColor(R.color.you_neutral_text_color) } else { @@ -24,10 +25,10 @@ fun Context.getProperBackgroundColor() = if (baseConfig.isUsingSystemTheme) { baseConfig.backgroundColor } -fun Context.getProperPrimaryColor() = if (baseConfig.isUsingSystemTheme) { - resources.getColor(R.color.you_primary_color) -} else { - baseConfig.primaryColor +fun Context.getProperPrimaryColor() = when { + baseConfig.isUsingSystemTheme -> resources.getColor(R.color.you_primary_color) + isWhiteTheme() || isBlackAndWhiteTheme() -> baseConfig.accentColor + else -> baseConfig.primaryColor } fun Context.updateTextColors(viewGroup: ViewGroup) { @@ -76,11 +77,6 @@ fun Context.isWhiteTheme() = baseConfig.textColor == DARK_GREY && baseConfig.pri fun Context.isUsingSystemDarkTheme() = resources.configuration.uiMode and Configuration.UI_MODE_NIGHT_YES != 0 -fun Context.getAdjustedPrimaryColor() = when { - isWhiteTheme() || isBlackAndWhiteTheme() -> baseConfig.accentColor - else -> getProperPrimaryColor() -} - fun Context.getDialogTheme() = if (baseConfig.backgroundColor.getContrastColor() == Color.WHITE) R.style.MyDialogTheme_Dark else R.style.MyDialogTheme fun Context.getSharedTheme(callback: (sharedTheme: SharedTheme?) -> Unit) { diff --git a/commons/src/main/kotlin/com/simplemobiletools/commons/extensions/String.kt b/commons/src/main/kotlin/com/simplemobiletools/commons/extensions/String.kt index 1f99f5323..f4df20640 100644 --- a/commons/src/main/kotlin/com/simplemobiletools/commons/extensions/String.kt +++ b/commons/src/main/kotlin/com/simplemobiletools/commons/extensions/String.kt @@ -262,14 +262,14 @@ fun String.getNameLetter() = normalizeString().toCharArray().getOrNull(0)?.toStr fun String.normalizePhoneNumber() = PhoneNumberUtils.normalizeNumber(this) -fun String.highlightTextFromNumbers(textToHighlight: String, adjustedPrimaryColor: Int): SpannableString { +fun String.highlightTextFromNumbers(textToHighlight: String, primaryColor: Int): SpannableString { val spannableString = SpannableString(this) val digits = PhoneNumberUtils.convertKeypadLettersToDigits(this) if (digits.contains(textToHighlight)) { val startIndex = digits.indexOf(textToHighlight, 0, true) val endIndex = Math.min(startIndex + textToHighlight.length, length) try { - spannableString.setSpan(ForegroundColorSpan(adjustedPrimaryColor), startIndex, endIndex, Spannable.SPAN_EXCLUSIVE_INCLUSIVE) + spannableString.setSpan(ForegroundColorSpan(primaryColor), startIndex, endIndex, Spannable.SPAN_EXCLUSIVE_INCLUSIVE) } catch (ignored: IndexOutOfBoundsException) { } } diff --git a/commons/src/main/kotlin/com/simplemobiletools/commons/views/PatternTab.kt b/commons/src/main/kotlin/com/simplemobiletools/commons/views/PatternTab.kt index d54c49c34..79738eb38 100644 --- a/commons/src/main/kotlin/com/simplemobiletools/commons/views/PatternTab.kt +++ b/commons/src/main/kotlin/com/simplemobiletools/commons/views/PatternTab.kt @@ -11,7 +11,7 @@ import com.andrognito.patternlockview.listener.PatternLockViewListener import com.andrognito.patternlockview.utils.PatternLockUtils import com.simplemobiletools.commons.R import com.simplemobiletools.commons.extensions.baseConfig -import com.simplemobiletools.commons.extensions.getAdjustedPrimaryColor +import com.simplemobiletools.commons.extensions.getProperPrimaryColor import com.simplemobiletools.commons.extensions.toast import com.simplemobiletools.commons.extensions.updateTextColors import com.simplemobiletools.commons.helpers.PROTECTION_PATTERN @@ -38,7 +38,7 @@ class PatternTab(context: Context, attrs: AttributeSet) : RelativeLayout(context false } - pattern_lock_view.correctStateColor = context.getAdjustedPrimaryColor() + pattern_lock_view.correctStateColor = context.getProperPrimaryColor() pattern_lock_view.normalStateColor = textColor pattern_lock_view.addPatternLockListener(object : PatternLockViewListener { override fun onComplete(pattern: MutableList?) {