@ -178,19 +178,29 @@ public class ConversationActivity extends PassphraseRequiredActionBarActivity
getSupportActionBar ( ) . setDisplayHomeAsUpEnabled ( true ) ;
initializeReceivers ( ) ;
initializeViews ( ) ;
initializeResources ( ) ;
initializeDraft ( ) ;
}
@Override
protected void onStart ( ) {
super . onStart ( ) ;
protected void onNewIntent ( Intent intent ) {
if ( ! Util . isEmpty ( composeText ) | | attachmentManager . isAttachmentPresent ( ) ) {
saveDraft ( ) ;
attachmentManager . clear ( ) ;
composeText . setText ( "" ) ;
}
setIntent ( intent ) ;
initializeResources ( ) ;
initializeDraft ( ) ;
}
@Override
protected void onStop ( ) {
super . onStop ( ) ;
saveDraft ( ) ;
ConversationFragment fragment = getFragment ( ) ;
if ( fragment ! = null ) {
fragment . onNewIntent ( ) ;
}
}
@Override
@ -220,6 +230,7 @@ public class ConversationActivity extends PassphraseRequiredActionBarActivity
@Override
protected void onDestroy ( ) {
saveDraft ( ) ;
unregisterReceiver ( securityUpdateReceiver ) ;
unregisterReceiver ( groupUpdateReceiver ) ;
MemoryCleaner . clean ( masterSecret ) ;
@ -718,24 +729,19 @@ public class ConversationActivity extends PassphraseRequiredActionBarActivity
}
}
private void initializeResources ( ) {
recipients = RecipientFactory . getRecipientsForIds ( this , getIntent ( ) . getLongArrayExtra ( RECIPIENTS_EXTRA ) , true ) ;
threadId = getIntent ( ) . getLongExtra ( THREAD_ID_EXTRA , - 1 ) ;
distributionType = getIntent ( ) . getIntExtra ( DISTRIBUTION_TYPE_EXTRA ,
ThreadDatabase . DistributionTypes . DEFAULT ) ;
sendButton = ( SendButton ) findViewById ( R . id . send_button ) ;
composeText = ( EditText ) findViewById ( R . id . embedded_text_editor ) ;
masterSecret = getIntent ( ) . getParcelableExtra ( MASTER_SECRET_EXTRA ) ;
charactersLeft = ( TextView ) findViewById ( R . id . space_left ) ;
emojiDrawer = ( EmojiDrawer ) findViewById ( R . id . emoji_drawer ) ;
emojiToggle = ( EmojiToggle ) findViewById ( R . id . emoji_toggle ) ;
private void initializeViews ( ) {
sendButton = ( SendButton ) findViewById ( R . id . send_button ) ;
composeText = ( EditText ) findViewById ( R . id . embedded_text_editor ) ;
charactersLeft = ( TextView ) findViewById ( R . id . space_left ) ;
emojiDrawer = ( EmojiDrawer ) findViewById ( R . id . emoji_drawer ) ;
emojiToggle = ( EmojiToggle ) findViewById ( R . id . emoji_toggle ) ;
if ( Build . VERSION . SDK_INT > = Build . VERSION_CODES . KITKAT ) {
emojiToggle . setVisibility ( View . GONE ) ;
}
attachmentAdapter = new AttachmentTypeSelectorAdapter ( this ) ;
attachmentManager = new AttachmentManager ( this , this ) ;
attachmentAdapter = new AttachmentTypeSelectorAdapter ( this ) ;
attachmentManager = new AttachmentManager ( this , this ) ;
SendButtonListener sendButtonListener = new SendButtonListener ( ) ;
ComposeKeyPressedListener composeKeyPressedListener = new ComposeKeyPressedListener ( ) ;
@ -750,6 +756,13 @@ public class ConversationActivity extends PassphraseRequiredActionBarActivity
composeText . setOnFocusChangeListener ( composeKeyPressedListener ) ;
emojiDrawer . setComposeEditText ( composeText ) ;
emojiToggle . setOnClickListener ( new EmojiToggleListener ( ) ) ;
}
private void initializeResources ( ) {
recipients = RecipientFactory . getRecipientsForIds ( this , getIntent ( ) . getLongArrayExtra ( RECIPIENTS_EXTRA ) , true ) ;
threadId = getIntent ( ) . getLongExtra ( THREAD_ID_EXTRA , - 1 ) ;
distributionType = getIntent ( ) . getIntExtra ( DISTRIBUTION_TYPE_EXTRA , ThreadDatabase . DistributionTypes . DEFAULT ) ;
masterSecret = getIntent ( ) . getParcelableExtra ( MASTER_SECRET_EXTRA ) ;
recipients . addListener ( new RecipientModifiedListener ( ) {
@Override
@ -906,9 +919,8 @@ public class ConversationActivity extends PassphraseRequiredActionBarActivity
if ( this . threadId < = 0 | | this . recipients = = null | | this . recipients . isEmpty ( ) )
return ;
final Drafts drafts = getDraftsForCurrentState ( ) ;
final long thisThreadId = this . threadId ;
final Drafts drafts = getDraftsForCurrentState ( ) ;
final long thisThreadId = this . threadId ;
final MasterSecret thisMasterSecret = this . masterSecret . parcelClone ( ) ;
new AsyncTask < Void , Void , Void > ( ) {
@ -1001,8 +1013,7 @@ public class ConversationActivity extends PassphraseRequiredActionBarActivity
boolean refreshFragment = ( threadId ! = this . threadId ) ;
this . threadId = threadId ;
ConversationFragment fragment = ( ConversationFragment ) getSupportFragmentManager ( )
. findFragmentById ( R . id . fragment_content ) ;
ConversationFragment fragment = getFragment ( ) ;
if ( fragment = = null ) {
return ;
@ -1018,6 +1029,10 @@ public class ConversationActivity extends PassphraseRequiredActionBarActivity
fragment . scrollToBottom ( ) ;
}
private ConversationFragment getFragment ( ) {
return ( ConversationFragment ) getSupportFragmentManager ( ) . findFragmentById ( R . id . fragment_content ) ;
}
private void sendMessage ( ) {
try {
final Recipients recipients = getRecipients ( ) ;