@ -5,6 +5,7 @@ import android.os.Parcelable
import android.util.SparseArray
import android.util.SparseArray
import androidx.activity.viewModels
import androidx.activity.viewModels
import androidx.core.content.ContextCompat
import androidx.core.content.ContextCompat
import androidx.core.text.HtmlCompat
import androidx.core.view.isVisible
import androidx.core.view.isVisible
import androidx.lifecycle.lifecycleScope
import androidx.lifecycle.lifecycleScope
import androidx.recyclerview.widget.DividerItemDecoration
import androidx.recyclerview.widget.DividerItemDecoration
@ -35,16 +36,12 @@ class ExpirationSettingsActivity: PassphraseRequiredActionBarActivity() {
intent . getLongExtra ( THREAD _ID , - 1 )
intent . getLongExtra ( THREAD _ID , - 1 )
}
}
private val expirationType : ExpirationType ? by lazy {
ExpirationType . valueOf ( intent . getIntExtra ( EXPIRATION _TYPE , - 1 ) )
}
private val viewModel : ExpirationSettingsViewModel by viewModels {
private val viewModel : ExpirationSettingsViewModel by viewModels {
val afterReadOptions = resources . getIntArray ( R . array . read _expiration _time _values ) . map ( Int :: toString )
val afterReadOptions = resources . getIntArray ( R . array . read _expiration _time _values ) . map ( Int :: toString )
. zip ( resources . getStringArray ( R . array . read _expiration _time _names ) ) { value , name -> RadioOption ( value , name ) }
. zip ( resources . getStringArray ( R . array . read _expiration _time _names ) ) { value , name -> RadioOption ( value , name ) }
val afterSendOptions = resources . getIntArray ( R . array . send _expiration _time _values ) . map ( Int :: toString )
val afterSendOptions = resources . getIntArray ( R . array . send _expiration _time _values ) . map ( Int :: toString )
. zip ( resources . getStringArray ( R . array . send _expiration _time _names ) ) { value , name -> RadioOption ( value , name ) }
. zip ( resources . getStringArray ( R . array . send _expiration _time _names ) ) { value , name -> RadioOption ( value , name ) }
viewModelFactory . create ( threadId , expirationType, afterReadOptions, afterSendOptions )
viewModelFactory . create ( threadId , afterReadOptions, afterSendOptions )
}
}
override fun onSaveInstanceState ( outState : Bundle ) {
override fun onSaveInstanceState ( outState : Bundle ) {
@ -84,8 +81,6 @@ class ExpirationSettingsActivity: PassphraseRequiredActionBarActivity() {
val deleteTypeOptionAdapter = RadioOptionAdapter {
val deleteTypeOptionAdapter = RadioOptionAdapter {
viewModel . onExpirationTypeSelected ( it )
viewModel . onExpirationTypeSelected ( it )
}
}
binding . textViewDeleteType . isVisible = expirationType == null
binding . layoutDeleteTypes . isVisible = expirationType == null
binding . recyclerViewDeleteTypes . apply {
binding . recyclerViewDeleteTypes . apply {
adapter = deleteTypeOptionAdapter
adapter = deleteTypeOptionAdapter
addItemDecoration ( ContextCompat . getDrawable ( this @ExpirationSettingsActivity , R . drawable . conversation _menu _divider ) !! . let {
addItemDecoration ( ContextCompat . getDrawable ( this @ExpirationSettingsActivity , R . drawable . conversation _menu _divider ) !! . let {
@ -117,11 +112,19 @@ class ExpirationSettingsActivity: PassphraseRequiredActionBarActivity() {
}
}
launch {
launch {
viewModel . expirationTimerOptions . collect { options ->
viewModel . expirationTimerOptions . collect { options ->
binding . textViewTimer . isVisible = options . isNotEmpty ( ) && expirationType == null
binding . textViewTimer . isVisible = options . isNotEmpty ( ) && viewModel. showExpirationTypeSelector
binding . layoutTimer . isVisible = options . isNotEmpty ( )
binding . layoutTimer . isVisible = options . isNotEmpty ( )
timerOptionAdapter . submitList ( options )
timerOptionAdapter . submitList ( options )
}
}
}
}
launch {
viewModel . recipient . collect {
binding . textViewDeleteType . isVisible = viewModel . showExpirationTypeSelector
binding . layoutDeleteTypes . isVisible = viewModel . showExpirationTypeSelector
binding . textViewFooter . isVisible = it ?. isClosedGroupRecipient == true
binding . textViewFooter . text = HtmlCompat . fromHtml ( getString ( R . string . activity _expiration _settings _group _footer ) , HtmlCompat . FROM _HTML _MODE _COMPACT )
}
}
}
}
}
}
@ -130,7 +133,7 @@ class ExpirationSettingsActivity: PassphraseRequiredActionBarActivity() {
setSupportActionBar ( binding . toolbar )
setSupportActionBar ( binding . toolbar )
val actionBar = supportActionBar ?: return
val actionBar = supportActionBar ?: return
actionBar . title = getString ( R . string . activity _expiration _settings _title )
actionBar . title = getString ( R . string . activity _expiration _settings _title )
actionBar . subtitle = if ( expirationType == ExpirationType . DELETE _AFTER _SEND ) {
actionBar . subtitle = if ( vi ewModel. selectedE xpirationType. valu e == ExpirationType . DELETE _AFTER _SEND ) {
getString ( R . string . activity _expiration _settings _subtitle _sent )
getString ( R . string . activity _expiration _settings _subtitle _sent )
} else {
} else {
getString ( R . string . activity _expiration _settings _subtitle )
getString ( R . string . activity _expiration _settings _subtitle )
@ -142,8 +145,6 @@ class ExpirationSettingsActivity: PassphraseRequiredActionBarActivity() {
companion object {
companion object {
private const val SCROLL _PARCEL = " scroll_parcel "
private const val SCROLL _PARCEL = " scroll_parcel "
const val THREAD _ID = " thread_id "
const val THREAD _ID = " thread_id "
const val EXPIRATION _TYPE = " expiration_type "
const val READ _ONLY = " read_only "
}
}
}
}