Add Notification profiles.

This commit is contained in:
Cody Henthorne
2021-12-08 13:22:36 -05:00
parent 31e0696395
commit 6c608e955e
106 changed files with 5692 additions and 238 deletions

View File

@@ -0,0 +1,45 @@
package org.thoughtcrime.securesms.util
import java.time.Instant
import java.time.LocalDateTime
import java.time.LocalTime
import java.time.ZoneId
import java.time.ZoneOffset
import java.time.format.DateTimeFormatter
import java.time.format.FormatStyle
import java.util.concurrent.TimeUnit
/**
* Convert [LocalDateTime] to be same as [System.currentTimeMillis]
*/
fun LocalDateTime.toMillis(): Long {
return TimeUnit.SECONDS.toMillis(toEpochSecond(ZoneOffset.UTC))
}
/**
* Return true if the [LocalDateTime] is within [start] and [end] inclusive.
*/
fun LocalDateTime.isBetween(start: LocalDateTime, end: LocalDateTime): Boolean {
return (isEqual(start) || isAfter(start)) && (isEqual(end) || isBefore(end))
}
/**
* Convert milliseconds to local date time with provided [zoneId].
*/
fun Long.toLocalDateTime(zoneId: ZoneId = ZoneId.systemDefault()): LocalDateTime {
return LocalDateTime.ofInstant(Instant.ofEpochMilli(this), zoneId)
}
/**
* Converts milliseconds to local time with provided [zoneId].
*/
fun Long.toLocalTime(zoneId: ZoneId = ZoneId.systemDefault()): LocalTime {
return LocalDateTime.ofInstant(Instant.ofEpochMilli(this), zoneId).toLocalTime()
}
/**
* Formats [LocalTime] as localized time. For example, "8:00 AM"
*/
fun LocalTime.formatHours(): String {
return DateTimeFormatter.ofLocalizedTime(FormatStyle.SHORT).format(this)
}

View File

@@ -0,0 +1,59 @@
package org.thoughtcrime.securesms.util
import android.os.Build
import android.view.Gravity
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.ImageView
import android.widget.PopupWindow
import android.widget.TextView
import org.thoughtcrime.securesms.R
import java.util.concurrent.TimeUnit
/**
* Show a "toast" like message with text and icon that animates in from the top and then animates out to the top.
*/
class TopToastPopup private constructor(parent: ViewGroup, iconResource: Int, descriptionText: String) : PopupWindow(
LayoutInflater.from(parent.context).inflate(R.layout.top_toast_popup, parent, false),
ViewGroup.LayoutParams.MATCH_PARENT,
ViewUtil.dpToPx(86)
) {
private val icon: ImageView = contentView.findViewById(R.id.top_toast_popup_icon)
private val description: TextView = contentView.findViewById(R.id.top_toast_popup_description)
init {
if (Build.VERSION.SDK_INT >= 21) {
elevation = ViewUtil.dpToPx(8).toFloat()
}
animationStyle = R.style.PopupAnimation
icon.setImageResource(iconResource)
description.text = descriptionText
}
private fun show(parent: ViewGroup) {
showAtLocation(parent, Gravity.TOP or Gravity.START, 0, 0)
measureChild()
update()
contentView.postDelayed({ dismiss() }, DURATION)
}
private fun measureChild() {
contentView.measure(
View.MeasureSpec.makeMeasureSpec(0, View.MeasureSpec.UNSPECIFIED),
View.MeasureSpec.makeMeasureSpec(0, View.MeasureSpec.UNSPECIFIED)
)
}
companion object {
private val DURATION = TimeUnit.SECONDS.toMillis(2)
@JvmStatic
fun show(parent: ViewGroup, icon: Int, description: String): TopToastPopup {
val topToast = TopToastPopup(parent, icon, description)
topToast.show(parent)
return topToast
}
}
}