@ -17,70 +17,67 @@
package org.thoughtcrime.securesms.notifications ;
package org.thoughtcrime.securesms.notifications ;
import android.app.NotificationManager ;
import android.content.BroadcastReceiver ;
import android.content.Context ;
import android.content.Context ;
import android.content.Intent ;
import android.content.Intent ;
import android.os.AsyncTask ;
import android.os.AsyncTask ;
import android.os.Bundle ;
import android.os.Bundle ;
import android.support.annotation.Nullable ;
import android.support.v4.app.RemoteInput ;
import android.support.v4.app.RemoteInput ;
import android.util.Log ;
import org.thoughtcrime.securesms.crypto.MasterSecret ;
import org.thoughtcrime.securesms.crypto.MasterSecret ;
import org.thoughtcrime.securesms.database.DatabaseFactory ;
import org.thoughtcrime.securesms.database.DatabaseFactory ;
import org.thoughtcrime.securesms. recipients.Recipient ;
import org.thoughtcrime.securesms. mms.OutgoingMediaMessage ;
import org.thoughtcrime.securesms.recipients.RecipientFactory ;
import org.thoughtcrime.securesms.recipients.RecipientFactory ;
import org.thoughtcrime.securesms.recipients.RecipientProvider ;
import org.thoughtcrime.securesms.recipients.Recipients ;
import org.thoughtcrime.securesms.recipients.Recipients ;
import org.thoughtcrime.securesms.sms.MessageSender ;
import org.thoughtcrime.securesms.sms.MessageSender ;
import org.thoughtcrime.securesms.sms.OutgoingTextMessage ;
import org.thoughtcrime.securesms.sms.OutgoingTextMessage ;
import ws.com.google.android.mms.pdu.PduBody ;
/ * *
/ * *
* Get the response text from the Wearable Device and sends an message as a reply
* Get the response text from the Wearable Device and sends an message as a reply
*
* @author Alix Ducros ( Ported to TextSecure - Codebase by Christoph Haefner )
* /
* /
public class WearReplyReceiver extends BroadcastReceiver {
public class WearReplyReceiver extends MasterSecretBroadcastReceiver {
public static final String TAG = WearReplyReceiver . class . getSimpleName ( ) ;
public static final String TAG = WearReplyReceiver . class . getSimpleName ( ) ;
public static final String REPLY_ACTION = "org.thoughtcrime.securesms.notifications.WEAR_REPLY" ;
public static final String REPLY_ACTION = "org.thoughtcrime.securesms.notifications.WEAR_REPLY" ;
public static final String RECIPIENT_IDS_EXTRA = "recipient_ids" ;
@Override
@Override
public void onReceive ( final Context context , Intent intent ) {
protected void onReceive ( final Context context , Intent intent ,
if ( ! intent . getAction ( ) . equals ( REPLY_ACTION ) )
final @Nullable MasterSecret masterSecret )
return ;
{
if ( ! REPLY_ACTION . equals ( intent . getAction ( ) ) ) return ;
Bundle remoteInput = RemoteInput . getResultsFromIntent ( intent ) ;
Bundle remoteInput = RemoteInput . getResultsFromIntent ( intent ) ;
if ( remoteInput = = null )
return ;
final long [ ] threadIds = intent . getLongArrayExtra ( "thread_ids" ) ;
final MasterSecret masterSecret = intent . getParcelableExtra ( "master_secret" ) ;
final long recipientId = intent . getLongExtra ( "recipient_id" , - 1 ) ;
final CharSequence responseText = remoteInput . getCharSequence ( MessageNotifier . EXTRA_VOICE_REPLY ) ;
final Recipients recipients = RecipientFactory . getRecipientsForIds ( context , new long [ ] { recipientId } , false ) ;
if ( threadIds ! = null & & masterSecret ! = null ) {
if ( remoteInput = = null ) return ;
( ( NotificationManager ) context . getSystemService ( Context . NOTIFICATION_SERVICE ) )
final long [ ] recipientIds = intent . getLongArrayExtra ( RECIPIENT_IDS_EXTRA ) ;
. cancel ( MessageNotifier . NOTIFICATION_ID ) ;
final CharSequence responseText = remoteInput . getCharSequence ( MessageNotifier . EXTRA_VOICE_REPLY ) ;
final Recipients recipients = RecipientFactory . getRecipientsForIds ( context , recipientIds , false ) ;
if ( masterSecret ! = null & & responseText ! = null ) {
new AsyncTask < Void , Void , Void > ( ) {
new AsyncTask < Void , Void , Void > ( ) {
@Override
@Override
protected Void doInBackground ( Void . . . params ) {
protected Void doInBackground ( Void . . . params ) {
for ( long threadId : threadIds ) {
long threadId ;
Log . w ( TAG , "Marking as read: " + threadId ) ;
DatabaseFactory . getThreadDatabase ( context ) . setRead ( threadId ) ;
}
if ( recipients . isGroupRecipient ( ) ) {
OutgoingMediaMessage reply = new OutgoingMediaMessage ( context , recipients , new PduBody ( ) , responseText . toString ( ) , 0 ) ;
threadId = MessageSender . send ( context , masterSecret , reply , - 1 , false ) ;
} else {
OutgoingTextMessage reply = new OutgoingTextMessage ( recipients , responseText . toString ( ) ) ;
OutgoingTextMessage reply = new OutgoingTextMessage ( recipients , responseText . toString ( ) ) ;
MessageSender . send ( context , masterSecret , reply , threadIds [ 0 ] , false ) ;
threadId = MessageSender . send ( context , masterSecret , reply , - 1 , false ) ;
}
DatabaseFactory . getThreadDatabase ( context ) . setRead ( threadId ) ;
MessageNotifier . updateNotification ( context , masterSecret ) ;
MessageNotifier . updateNotification ( context , masterSecret ) ;
return null ;
return null ;
}
}
} . execute ( ) ;
} . execute ( ) ;
}
}
}
}
}
}