Add device-specific support configs.

This commit is contained in:
Michelle Tang
2024-06-21 10:45:22 -07:00
committed by Greyson Parrelli
parent c0da0bd272
commit b806952430
10 changed files with 203 additions and 15 deletions

View File

@@ -10,6 +10,7 @@ import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.annotation.RequiresApi
import androidx.core.content.ContextCompat
import androidx.core.os.bundleOf
import androidx.fragment.app.FragmentManager
import org.signal.core.util.concurrent.LifecycleDisposable
@@ -17,6 +18,7 @@ import org.signal.core.util.logging.Log
import org.thoughtcrime.securesms.R
import org.thoughtcrime.securesms.databinding.PromptBatterySaverBottomSheetBinding
import org.thoughtcrime.securesms.keyvalue.SignalStore
import org.thoughtcrime.securesms.notifications.DelayedNotificationConfig
import org.thoughtcrime.securesms.util.BottomSheetUtil
import org.thoughtcrime.securesms.util.LocalMetrics
import org.thoughtcrime.securesms.util.PowerManagerCompat
@@ -26,12 +28,15 @@ class PromptBatterySaverDialogFragment : FixedRoundedCornerBottomSheetDialogFrag
companion object {
private val TAG = Log.tag(PromptBatterySaverDialogFragment::class.java)
private const val ARG_LEARN_MORE_LINK = "arg.learn.more.link"
@JvmStatic
fun show(fragmentManager: FragmentManager) {
if (fragmentManager.findFragmentByTag(BottomSheetUtil.STANDARD_BOTTOM_SHEET_FRAGMENT_TAG) == null) {
PromptBatterySaverDialogFragment().apply {
arguments = bundleOf()
arguments = bundleOf(
ARG_LEARN_MORE_LINK to DelayedNotificationConfig.currentConfig.link
)
}.show(fragmentManager, BottomSheetUtil.STANDARD_BOTTOM_SHEET_FRAGMENT_TAG)
SignalStore.uiHints.lastBatterySaverPrompt = System.currentTimeMillis()
}
@@ -52,6 +57,11 @@ class PromptBatterySaverDialogFragment : FixedRoundedCornerBottomSheetDialogFrag
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
disposables.bindTo(viewLifecycleOwner)
val learnMoreLink = arguments?.getString(ARG_LEARN_MORE_LINK) ?: getString(R.string.PromptBatterySaverBottomSheet__learn_more_url)
binding.message.setLearnMoreVisible(true)
binding.message.setLinkColor(ContextCompat.getColor(requireContext(), R.color.signal_colorPrimary))
binding.message.setLink(learnMoreLink)
binding.continueButton.setOnClickListener {
PowerManagerCompat.requestIgnoreBatteryOptimizations(requireContext())
Log.i(TAG, "Requested to ignore battery optimizations, clearing local metrics.")

View File

@@ -120,7 +120,7 @@ class NotificationsSettingsViewModel(private val sharedPreferences: SharedPrefer
messagePrivacy = SignalStore.settings.messageNotificationsPrivacy.toString(),
priority = TextSecurePreferences.getNotificationPriority(AppDependencies.application),
troubleshootNotifications = if (calculateSlowNotifications) {
SlowNotificationHeuristics.isPotentiallyCausedByBatteryOptimizations() && SlowNotificationHeuristics.isHavingDelayedNotifications()
SlowNotificationHeuristics.isPotentiallyCausedByBatteryOptimizations() && (SlowNotificationHeuristics.isHavingDelayedNotifications() || SlowNotificationHeuristics.showPreemptively())
} else if (currentState != null) {
currentState.messageNotificationsState.troubleshootNotifications
} else {