From fa70cffd8324fb78825b6db0022496e473597cdd Mon Sep 17 00:00:00 2001 From: Marcel Hibbe Date: Mon, 25 Nov 2024 22:47:52 +0100 Subject: [PATCH] blink items when opened by notification warning Signed-off-by: Marcel Hibbe --- .../talk/settings/SettingsActivity.kt | 35 ++++++++++++++++--- 1 file changed, 31 insertions(+), 4 deletions(-) diff --git a/app/src/main/java/com/nextcloud/talk/settings/SettingsActivity.kt b/app/src/main/java/com/nextcloud/talk/settings/SettingsActivity.kt index 558133cb4..c33fff0ea 100644 --- a/app/src/main/java/com/nextcloud/talk/settings/SettingsActivity.kt +++ b/app/src/main/java/com/nextcloud/talk/settings/SettingsActivity.kt @@ -21,6 +21,8 @@ import android.content.Intent import android.content.pm.PackageManager import android.graphics.PorterDuff import android.graphics.drawable.ColorDrawable +import android.graphics.drawable.Drawable +import android.graphics.drawable.RippleDrawable import android.media.RingtoneManager import android.net.Uri import android.os.Build @@ -89,6 +91,7 @@ import io.reactivex.schedulers.Schedulers import kotlinx.coroutines.CoroutineScope import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.ExperimentalCoroutinesApi +import kotlinx.coroutines.delay import kotlinx.coroutines.flow.Flow import kotlinx.coroutines.launch import kotlinx.coroutines.withContext @@ -130,7 +133,7 @@ class SettingsActivity : BaseActivity(), SetPhoneNumberDialogFragment.SetPhoneNu private lateinit var phoneBookIntegrationFlow: Flow private var profileQueryDisposable: Disposable? = null private var dbQueryDisposable: Disposable? = null - private var scrollToNotificationCategory: Boolean? = false + private var openedByNotificationWarning: Boolean = false @SuppressLint("StringFormatInvalid") override fun onCreate(savedInstanceState: Bundle?) { @@ -167,7 +170,7 @@ class SettingsActivity : BaseActivity(), SetPhoneNumberDialogFragment.SetPhoneNu private fun handleIntent(intent: Intent) { val extras: Bundle? = intent.extras - scrollToNotificationCategory = extras?.getBoolean(KEY_SCROLL_TO_NOTIFICATION_CATEGORY) + openedByNotificationWarning = extras?.getBoolean(KEY_SCROLL_TO_NOTIFICATION_CATEGORY) ?: false } override fun onResume() { @@ -219,11 +222,12 @@ class SettingsActivity : BaseActivity(), SetPhoneNumberDialogFragment.SetPhoneNu themeTitles() themeSwitchPreferences() - if (scrollToNotificationCategory == true) { + if (openedByNotificationWarning) { scrollToNotificationCategory() } } + @Suppress("MagicNumber") private fun scrollToNotificationCategory() { binding.scrollView.post { val scrollViewLocation = IntArray(2) @@ -231,7 +235,7 @@ class SettingsActivity : BaseActivity(), SetPhoneNumberDialogFragment.SetPhoneNu binding.scrollView.getLocationOnScreen(scrollViewLocation) binding.settingsNotificationsCategory.getLocationOnScreen(targetLocation) val offset = targetLocation[1] - scrollViewLocation[1] - binding.scrollView.smoothScrollBy(0, offset) + binding.scrollView.scrollBy(0, offset) } } @@ -301,6 +305,10 @@ class SettingsActivity : BaseActivity(), SetPhoneNumberDialogFragment.SetPhoneNu resources!!.getString(R.string.nc_diagnose_battery_optimization_not_ignored) binding.batteryOptimizationIgnored.setTextColor(resources.getColor(R.color.nc_darkRed, null)) + if (openedByNotificationWarning){ + blinkRipple(binding.settingsBatteryOptimizationWrapper.background) + } + binding.settingsBatteryOptimizationWrapper.setOnClickListener { val dialogText = String.format( context.resources.getString(R.string.nc_ignore_battery_optimization_dialog_text), @@ -344,6 +352,10 @@ class SettingsActivity : BaseActivity(), SetPhoneNumberDialogFragment.SetPhoneNu resources.getColor(R.color.nc_darkRed, null) ) + if (openedByNotificationWarning){ + blinkRipple(binding.settingsNotificationsPermissionWrapper.background) + } + binding.settingsCallSound.isEnabled = false binding.settingsCallSound.alpha = DISABLED_ALPHA binding.settingsMessageSound.isEnabled = false @@ -1380,6 +1392,21 @@ class SettingsActivity : BaseActivity(), SetPhoneNumberDialogFragment.SetPhoneNu } } + @Suppress("MagicNumber") + private fun blinkRipple(rippleView: Drawable) { + (rippleView as RippleDrawable).let { rippleDrawable -> + CoroutineScope(Dispatchers.Main).launch { + delay(1000L) // Wait 2 seconds before starting + repeat(3) { + rippleDrawable.state = intArrayOf(android.R.attr.state_pressed, android.R.attr.state_enabled) + delay(250L) // Ripple active duration + rippleDrawable.state = intArrayOf() // Reset state + delay(250L) // Time between blinks + } + } + } + } + companion object { private val TAG = SettingsActivity::class.java.simpleName private const val DURATION: Long = 2500