|
|
|
@ -1,6 +1,8 @@
|
|
|
|
|
package org.thoughtcrime.securesms.conversation.v2.messages
|
|
|
|
|
|
|
|
|
|
import android.Manifest
|
|
|
|
|
import android.content.Context
|
|
|
|
|
import android.content.Intent
|
|
|
|
|
import android.util.AttributeSet
|
|
|
|
|
import android.util.Log
|
|
|
|
|
import android.view.LayoutInflater
|
|
|
|
@ -11,7 +13,6 @@ import androidx.core.view.isVisible
|
|
|
|
|
import androidx.recyclerview.widget.RecyclerView
|
|
|
|
|
import com.squareup.phrase.Phrase
|
|
|
|
|
import dagger.hilt.android.AndroidEntryPoint
|
|
|
|
|
import javax.inject.Inject
|
|
|
|
|
import network.loki.messenger.R
|
|
|
|
|
import network.loki.messenger.databinding.ViewControlMessageBinding
|
|
|
|
|
import network.loki.messenger.libsession_util.util.ExpiryMode
|
|
|
|
@ -19,11 +20,19 @@ import org.session.libsession.messaging.MessagingModuleConfiguration
|
|
|
|
|
import org.session.libsession.messaging.messages.ExpirationConfiguration
|
|
|
|
|
import org.session.libsession.utilities.StringSubstitutionConstants.NAME_KEY
|
|
|
|
|
import org.session.libsession.utilities.TextSecurePreferences
|
|
|
|
|
import org.session.libsession.utilities.getColorFromAttr
|
|
|
|
|
import org.thoughtcrime.securesms.MissingMicrophonePermissionDialog
|
|
|
|
|
import org.thoughtcrime.securesms.conversation.disappearingmessages.DisappearingMessages
|
|
|
|
|
import org.thoughtcrime.securesms.conversation.disappearingmessages.expiryMode
|
|
|
|
|
import org.thoughtcrime.securesms.database.model.MessageRecord
|
|
|
|
|
import org.thoughtcrime.securesms.dependencies.DatabaseComponent
|
|
|
|
|
import org.thoughtcrime.securesms.permissions.Permissions
|
|
|
|
|
import org.thoughtcrime.securesms.preferences.PrivacySettingsActivity
|
|
|
|
|
import org.thoughtcrime.securesms.showSessionDialog
|
|
|
|
|
import org.thoughtcrime.securesms.ui.getSubbedCharSequence
|
|
|
|
|
import org.thoughtcrime.securesms.ui.getSubbedString
|
|
|
|
|
import javax.inject.Inject
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@AndroidEntryPoint
|
|
|
|
|
class ControlMessageView : LinearLayout {
|
|
|
|
@ -32,6 +41,12 @@ class ControlMessageView : LinearLayout {
|
|
|
|
|
|
|
|
|
|
private val binding = ViewControlMessageBinding.inflate(LayoutInflater.from(context), this, true)
|
|
|
|
|
|
|
|
|
|
private val infoDrawable by lazy {
|
|
|
|
|
val d = ResourcesCompat.getDrawable(resources, R.drawable.ic_info_outline_white_24dp, context.theme)
|
|
|
|
|
d?.setTint(context.getColorFromAttr(R.attr.message_received_text_color))
|
|
|
|
|
d
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
constructor(context: Context) : super(context)
|
|
|
|
|
constructor(context: Context, attrs: AttributeSet) : super(context, attrs)
|
|
|
|
|
constructor(context: Context, attrs: AttributeSet, defStyleAttr: Int) : super(context, attrs, defStyleAttr)
|
|
|
|
@ -98,17 +113,63 @@ class ControlMessageView : LinearLayout {
|
|
|
|
|
val drawable = when {
|
|
|
|
|
message.isIncomingCall -> R.drawable.ic_incoming_call
|
|
|
|
|
message.isOutgoingCall -> R.drawable.ic_outgoing_call
|
|
|
|
|
message.isFirstMissedCall -> R.drawable.ic_info_outline_light
|
|
|
|
|
else -> R.drawable.ic_missed_call
|
|
|
|
|
}
|
|
|
|
|
binding.textView.isVisible = false
|
|
|
|
|
binding.callTextView.setCompoundDrawablesRelativeWithIntrinsicBounds(ResourcesCompat.getDrawable(resources, drawable, context.theme), null, null, null)
|
|
|
|
|
binding.callTextView.setCompoundDrawablesRelativeWithIntrinsicBounds(
|
|
|
|
|
ResourcesCompat.getDrawable(resources, drawable, context.theme),
|
|
|
|
|
null, null, null)
|
|
|
|
|
binding.callTextView.text = messageBody
|
|
|
|
|
|
|
|
|
|
if (message.expireStarted > 0 && message.expiresIn > 0) {
|
|
|
|
|
binding.expirationTimerView.isVisible = true
|
|
|
|
|
binding.expirationTimerView.setExpirationTime(message.expireStarted, message.expiresIn)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// remove clicks by default
|
|
|
|
|
setOnClickListener(null)
|
|
|
|
|
hideInfo()
|
|
|
|
|
|
|
|
|
|
// handle click behaviour depending on criteria
|
|
|
|
|
if (message.isMissedCall || message.isFirstMissedCall) {
|
|
|
|
|
when {
|
|
|
|
|
// if we're currently missing the audio/microphone permission,
|
|
|
|
|
// show a dedicated permission dialog
|
|
|
|
|
!Permissions.hasAll(context, Manifest.permission.RECORD_AUDIO) -> {
|
|
|
|
|
showInfo()
|
|
|
|
|
setOnClickListener {
|
|
|
|
|
MissingMicrophonePermissionDialog.show(context)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// when the call toggle is disabled in the privacy screen,
|
|
|
|
|
// show a dedicated privacy dialog
|
|
|
|
|
!TextSecurePreferences.isCallNotificationsEnabled(context) -> {
|
|
|
|
|
showInfo()
|
|
|
|
|
setOnClickListener {
|
|
|
|
|
context.showSessionDialog {
|
|
|
|
|
val titleTxt = context.getSubbedString(
|
|
|
|
|
R.string.callsMissedCallFrom,
|
|
|
|
|
NAME_KEY to message.individualRecipient.name!!
|
|
|
|
|
)
|
|
|
|
|
title(titleTxt)
|
|
|
|
|
|
|
|
|
|
val bodyTxt = context.getSubbedCharSequence(
|
|
|
|
|
R.string.callsYouMissedCallPermissions,
|
|
|
|
|
NAME_KEY to message.individualRecipient.name!!
|
|
|
|
|
)
|
|
|
|
|
text(bodyTxt)
|
|
|
|
|
|
|
|
|
|
button(R.string.sessionSettings) {
|
|
|
|
|
Intent(context, PrivacySettingsActivity::class.java)
|
|
|
|
|
.let(context::startActivity)
|
|
|
|
|
}
|
|
|
|
|
cancelButton()
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -116,6 +177,24 @@ class ControlMessageView : LinearLayout {
|
|
|
|
|
binding.callView.isVisible = message.isCallLog
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
fun showInfo(){
|
|
|
|
|
binding.callTextView.setCompoundDrawablesRelativeWithIntrinsicBounds(
|
|
|
|
|
binding.callTextView.compoundDrawablesRelative.first(),
|
|
|
|
|
null,
|
|
|
|
|
infoDrawable,
|
|
|
|
|
null
|
|
|
|
|
)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
fun hideInfo(){
|
|
|
|
|
binding.callTextView.setCompoundDrawablesRelativeWithIntrinsicBounds(
|
|
|
|
|
binding.callTextView.compoundDrawablesRelative.first(),
|
|
|
|
|
null,
|
|
|
|
|
null,
|
|
|
|
|
null
|
|
|
|
|
)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
fun recycle() {
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|