extract blink method, move server notification app hint to gplay block

Signed-off-by: Marcel Hibbe <dev@mhibbe.de>
This commit is contained in:
Marcel Hibbe 2024-11-26 12:35:06 +01:00
parent 6f6c1896ed
commit 8e6072bbc7
No known key found for this signature in database
GPG key ID: C793F8B59F43CE7B
3 changed files with 56 additions and 49 deletions

View file

@ -21,8 +21,6 @@ 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
@ -73,6 +71,7 @@ import com.nextcloud.talk.utils.ApiUtils
import com.nextcloud.talk.utils.CapabilitiesUtil import com.nextcloud.talk.utils.CapabilitiesUtil
import com.nextcloud.talk.utils.ClosedInterfaceImpl import com.nextcloud.talk.utils.ClosedInterfaceImpl
import com.nextcloud.talk.utils.DisplayUtils import com.nextcloud.talk.utils.DisplayUtils
import com.nextcloud.talk.utils.DrawableUtils
import com.nextcloud.talk.utils.LoggingUtils.sendMailWithAttachment import com.nextcloud.talk.utils.LoggingUtils.sendMailWithAttachment
import com.nextcloud.talk.utils.NotificationUtils import com.nextcloud.talk.utils.NotificationUtils
import com.nextcloud.talk.utils.NotificationUtils.getCallRingtoneUri import com.nextcloud.talk.utils.NotificationUtils.getCallRingtoneUri
@ -91,7 +90,6 @@ 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
@ -307,7 +305,7 @@ class SettingsActivity : BaseActivity(), SetPhoneNumberDialogFragment.SetPhoneNu
binding.batteryOptimizationIgnored.setTextColor(resources.getColor(R.color.nc_darkRed, null)) binding.batteryOptimizationIgnored.setTextColor(resources.getColor(R.color.nc_darkRed, null))
if (openedByNotificationWarning) { if (openedByNotificationWarning) {
blinkRipple(binding.settingsBatteryOptimizationWrapper.background) DrawableUtils.blinkDrawable(binding.settingsBatteryOptimizationWrapper.background)
} }
binding.settingsBatteryOptimizationWrapper.setOnClickListener { binding.settingsBatteryOptimizationWrapper.setOnClickListener {
@ -354,7 +352,7 @@ class SettingsActivity : BaseActivity(), SetPhoneNumberDialogFragment.SetPhoneNu
) )
if (openedByNotificationWarning){ if (openedByNotificationWarning){
blinkRipple(binding.settingsNotificationsPermissionWrapper.background) DrawableUtils.blinkDrawable(binding.settingsNotificationsPermissionWrapper.background)
} }
binding.settingsCallSound.isEnabled = false binding.settingsCallSound.isEnabled = false
@ -391,7 +389,7 @@ class SettingsActivity : BaseActivity(), SetPhoneNumberDialogFragment.SetPhoneNu
binding.callsRingtone.text = resources!!.getString(R.string.nc_common_disabled) binding.callsRingtone.text = resources!!.getString(R.string.nc_common_disabled)
if (openedByNotificationWarning){ if (openedByNotificationWarning){
blinkRipple(binding.settingsCallSound.background) DrawableUtils.blinkDrawable(binding.settingsCallSound.background)
} }
} }
@ -406,7 +404,7 @@ class SettingsActivity : BaseActivity(), SetPhoneNumberDialogFragment.SetPhoneNu
binding.messagesRingtone.text = resources!!.getString(R.string.nc_common_disabled) binding.messagesRingtone.text = resources!!.getString(R.string.nc_common_disabled)
if (openedByNotificationWarning){ if (openedByNotificationWarning){
blinkRipple(binding.settingsMessageSound.background) DrawableUtils.blinkDrawable(binding.settingsMessageSound.background)
} }
} }
@ -488,7 +486,7 @@ class SettingsActivity : BaseActivity(), SetPhoneNumberDialogFragment.SetPhoneNu
binding.settingsServerNotificationAppDescription.text = description binding.settingsServerNotificationAppDescription.text = description
if (openedByNotificationWarning) { if (openedByNotificationWarning) {
blinkRipple(binding.settingsServerNotificationAppWrapper.background) DrawableUtils.blinkDrawable(binding.settingsServerNotificationAppWrapper.background)
} }
} else { } else {
binding.settingsServerNotificationAppWrapper.visibility = View.GONE binding.settingsServerNotificationAppWrapper.visibility = View.GONE
@ -1419,21 +1417,6 @@ 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

View file

@ -6,14 +6,22 @@
*/ */
package com.nextcloud.talk.utils package com.nextcloud.talk.utils
import android.graphics.drawable.Drawable
import android.graphics.drawable.RippleDrawable
import android.util.Log
import com.nextcloud.talk.R import com.nextcloud.talk.R
import com.nextcloud.talk.utils.Mimetype.AUDIO_PREFIX import com.nextcloud.talk.utils.Mimetype.AUDIO_PREFIX
import com.nextcloud.talk.utils.Mimetype.FOLDER import com.nextcloud.talk.utils.Mimetype.FOLDER
import com.nextcloud.talk.utils.Mimetype.IMAGE_PREFIX import com.nextcloud.talk.utils.Mimetype.IMAGE_PREFIX
import com.nextcloud.talk.utils.Mimetype.TEXT_PREFIX import com.nextcloud.talk.utils.Mimetype.TEXT_PREFIX
import com.nextcloud.talk.utils.Mimetype.VIDEO_PREFIX import com.nextcloud.talk.utils.Mimetype.VIDEO_PREFIX
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.delay
import kotlinx.coroutines.launch
object DrawableUtils { object DrawableUtils {
private val TAG = DrawableUtils::class.java.simpleName
@Suppress("Detekt.LongMethod") @Suppress("Detekt.LongMethod")
fun getDrawableResourceIdForMimeType(mimetype: String?): Int { fun getDrawableResourceIdForMimeType(mimetype: String?): Int {
@ -153,4 +161,23 @@ object DrawableUtils {
drawableMap["unknown"]!! drawableMap["unknown"]!!
} }
} }
@Suppress("MagicNumber")
fun blinkDrawable(rippleView: Drawable) {
try {
(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
}
}
}
} catch (e: Exception){
Log.e(TAG, "Failed to blink Drawable", e)
}
}
} }

View file

@ -185,7 +185,6 @@
android:text="" android:text=""
tools:ignore="SpeakableTextPresentCheck" /> tools:ignore="SpeakableTextPresentCheck" />
</com.google.android.material.textfield.TextInputLayout> </com.google.android.material.textfield.TextInputLayout>
</LinearLayout> </LinearLayout>
@ -246,6 +245,28 @@
android:gravity="center_vertical"/> android:gravity="center_vertical"/>
</LinearLayout> </LinearLayout>
<LinearLayout
android:id="@+id/settings_server_notification_app_wrapper"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="?android:attr/selectableItemBackground"
android:orientation="vertical"
android:padding="@dimen/standard_padding">
<com.google.android.material.textview.MaterialTextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/nc_settings_server_notification_app_not_installed_title"
android:textSize="@dimen/headline_text_size"/>
<com.google.android.material.textview.MaterialTextView
android:id="@+id/settings_server_notification_app_description"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="@color/nc_darkRed"
android:textSize="@dimen/supporting_text_text_size"
tools:text="Please contact the admin of www.example.com"/>
</LinearLayout>
<LinearLayout <LinearLayout
android:id="@+id/settings_notifications_permission_wrapper" android:id="@+id/settings_notifications_permission_wrapper"
@ -349,30 +370,6 @@
android:text="@string/nc_settings_default_ringtone" android:text="@string/nc_settings_default_ringtone"
android:textSize="@dimen/supporting_text_text_size"/> android:textSize="@dimen/supporting_text_text_size"/>
</LinearLayout> </LinearLayout>
<LinearLayout
android:id="@+id/settings_server_notification_app_wrapper"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="?android:attr/selectableItemBackground"
android:orientation="vertical"
android:padding="@dimen/standard_padding">
<com.google.android.material.textview.MaterialTextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/nc_settings_server_notification_app_not_installed_title"
android:textSize="@dimen/headline_text_size"/>
<com.google.android.material.textview.MaterialTextView
android:id="@+id/settings_server_notification_app_description"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="@color/nc_darkRed"
android:textSize="@dimen/supporting_text_text_size"
tools:text="Please contact the admin of www.example.com"/>
</LinearLayout>
</LinearLayout> </LinearLayout>
<LinearLayout <LinearLayout