blink items when opened by notification warning

Signed-off-by: Marcel Hibbe <dev@mhibbe.de>
This commit is contained in:
Marcel Hibbe 2024-11-25 22:47:52 +01:00
parent a9ec8c2eed
commit fa70cffd83
No known key found for this signature in database
GPG key ID: C793F8B59F43CE7B

View file

@ -21,6 +21,8 @@ import android.content.Intent
import android.content.pm.PackageManager import android.content.pm.PackageManager
import android.graphics.PorterDuff import android.graphics.PorterDuff
import android.graphics.drawable.ColorDrawable import android.graphics.drawable.ColorDrawable
import android.graphics.drawable.Drawable
import android.graphics.drawable.RippleDrawable
import android.media.RingtoneManager import android.media.RingtoneManager
import android.net.Uri import android.net.Uri
import android.os.Build import android.os.Build
@ -89,6 +91,7 @@ import io.reactivex.schedulers.Schedulers
import kotlinx.coroutines.CoroutineScope import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.ExperimentalCoroutinesApi import kotlinx.coroutines.ExperimentalCoroutinesApi
import kotlinx.coroutines.delay
import kotlinx.coroutines.flow.Flow import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.launch import kotlinx.coroutines.launch
import kotlinx.coroutines.withContext import kotlinx.coroutines.withContext
@ -130,7 +133,7 @@ class SettingsActivity : BaseActivity(), SetPhoneNumberDialogFragment.SetPhoneNu
private lateinit var phoneBookIntegrationFlow: Flow<Boolean> private lateinit var phoneBookIntegrationFlow: Flow<Boolean>
private var profileQueryDisposable: Disposable? = null private var profileQueryDisposable: Disposable? = null
private var dbQueryDisposable: Disposable? = null private var dbQueryDisposable: Disposable? = null
private var scrollToNotificationCategory: Boolean? = false private var openedByNotificationWarning: Boolean = false
@SuppressLint("StringFormatInvalid") @SuppressLint("StringFormatInvalid")
override fun onCreate(savedInstanceState: Bundle?) { override fun onCreate(savedInstanceState: Bundle?) {
@ -167,7 +170,7 @@ class SettingsActivity : BaseActivity(), SetPhoneNumberDialogFragment.SetPhoneNu
private fun handleIntent(intent: Intent) { private fun handleIntent(intent: Intent) {
val extras: Bundle? = intent.extras 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() { override fun onResume() {
@ -219,11 +222,12 @@ class SettingsActivity : BaseActivity(), SetPhoneNumberDialogFragment.SetPhoneNu
themeTitles() themeTitles()
themeSwitchPreferences() themeSwitchPreferences()
if (scrollToNotificationCategory == true) { if (openedByNotificationWarning) {
scrollToNotificationCategory() scrollToNotificationCategory()
} }
} }
@Suppress("MagicNumber")
private fun scrollToNotificationCategory() { private fun scrollToNotificationCategory() {
binding.scrollView.post { binding.scrollView.post {
val scrollViewLocation = IntArray(2) val scrollViewLocation = IntArray(2)
@ -231,7 +235,7 @@ class SettingsActivity : BaseActivity(), SetPhoneNumberDialogFragment.SetPhoneNu
binding.scrollView.getLocationOnScreen(scrollViewLocation) binding.scrollView.getLocationOnScreen(scrollViewLocation)
binding.settingsNotificationsCategory.getLocationOnScreen(targetLocation) binding.settingsNotificationsCategory.getLocationOnScreen(targetLocation)
val offset = targetLocation[1] - scrollViewLocation[1] 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) resources!!.getString(R.string.nc_diagnose_battery_optimization_not_ignored)
binding.batteryOptimizationIgnored.setTextColor(resources.getColor(R.color.nc_darkRed, null)) binding.batteryOptimizationIgnored.setTextColor(resources.getColor(R.color.nc_darkRed, null))
if (openedByNotificationWarning){
blinkRipple(binding.settingsBatteryOptimizationWrapper.background)
}
binding.settingsBatteryOptimizationWrapper.setOnClickListener { binding.settingsBatteryOptimizationWrapper.setOnClickListener {
val dialogText = String.format( val dialogText = String.format(
context.resources.getString(R.string.nc_ignore_battery_optimization_dialog_text), 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) resources.getColor(R.color.nc_darkRed, null)
) )
if (openedByNotificationWarning){
blinkRipple(binding.settingsNotificationsPermissionWrapper.background)
}
binding.settingsCallSound.isEnabled = false binding.settingsCallSound.isEnabled = false
binding.settingsCallSound.alpha = DISABLED_ALPHA binding.settingsCallSound.alpha = DISABLED_ALPHA
binding.settingsMessageSound.isEnabled = false 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 { companion object {
private val TAG = SettingsActivity::class.java.simpleName private val TAG = SettingsActivity::class.java.simpleName
private const val DURATION: Long = 2500 private const val DURATION: Long = 2500