basic last seen feature. no peristancy just yet. no polish

This commit is contained in:
iNPUTmice 2014-06-06 11:39:17 +02:00
parent a583471af8
commit 5fe926b645
9 changed files with 552 additions and 376 deletions

View File

@ -3,32 +3,33 @@
xmlns:tools="http://schemas.android.com/tools" xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent" android:layout_height="match_parent"
android:background="#e5e5e5"> android:background="#e5e5e5" >
<RelativeLayout <RelativeLayout
android:background="#eee"
android:id="@+id/textsend" android:id="@+id/textsend"
android:layout_width="fill_parent" android:layout_width="fill_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_alignParentBottom="true" android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"> android:layout_alignParentLeft="true"
android:background="#eee" >
<EditText <EditText
android:id="@+id/textinput" android:id="@+id/textinput"
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:minHeight="48dp"
android:layout_alignParentLeft="true" android:layout_alignParentLeft="true"
android:paddingBottom="12dp"
android:paddingLeft="8dp"
android:paddingRight="8dp"
android:paddingTop="12dp"
android:layout_toLeftOf="@+id/textSendButton" android:layout_toLeftOf="@+id/textSendButton"
android:background="#eee" android:background="#eee"
android:ems="10" android:ems="10"
android:inputType="textShortMessage|textMultiLine|textCapSentences" android:inputType="textShortMessage|textMultiLine|textCapSentences"
android:minLines="1" > android:minHeight="48dp"
<requestFocus /> android:minLines="1"
android:paddingBottom="12dp"
android:paddingLeft="8dp"
android:paddingRight="8dp"
android:paddingTop="12dp" >
<requestFocus />
</EditText> </EditText>
<ImageButton <ImageButton
@ -52,101 +53,118 @@
android:divider="@null" android:divider="@null"
android:dividerHeight="0dp" android:dividerHeight="0dp"
android:listSelector="@android:color/transparent" android:listSelector="@android:color/transparent"
android:stackFromBottom="true"
android:transcriptMode="alwaysScroll" android:transcriptMode="alwaysScroll"
tools:listitem="@layout/message_sent" tools:listitem="@layout/message_sent" >
android:stackFromBottom="true">
</ListView> </ListView>
<LinearLayout <LinearLayout
android:id="@+id/info_box" android:id="@+id/info_box"
android:layout_height="wrap_content" android:layout_width="fill_parent"
android:layout_width="fill_parent" android:layout_height="wrap_content"
android:orientation="vertical" android:orientation="vertical" >
>
<LinearLayout <LinearLayout
android:id="@+id/muc_error" android:id="@+id/muc_error"
android:layout_width="fill_parent" android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="@drawable/redbackground"
android:orientation="vertical"
android:visibility="gone"
>
<TextView
android:id="@+id/muc_error_msg"
android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:textColor="#eee" android:background="@drawable/redbackground"
android:textStyle="bold" android:orientation="vertical"
android:padding="8dp" android:visibility="gone" >
android:textSize="20sp"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Click to edit conference details"
android:textColor="#eee"
android:paddingLeft="8dp"
android:paddingBottom="8dp"
android:textSize="14sp"/>
<TextView
android:id="@+id/muc_error_msg"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:padding="8dp"
android:textColor="#eee"
android:textSize="20sp"
android:textStyle="bold" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingBottom="8dp"
android:paddingLeft="8dp"
android:text="Click to edit conference details"
android:textColor="#eee"
android:textSize="14sp" />
</LinearLayout>
<LinearLayout
android:id="@+id/new_fingerprint"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="@drawable/redbackground"
android:orientation="vertical"
android:visibility="gone" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:padding="8dp"
android:text="Unknown OTR Fingerprint"
android:textColor="#eee"
android:textSize="20sp"
android:textStyle="bold" />
<TextView
android:id="@+id/otr_fingerprint"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingBottom="8dp"
android:paddingLeft="8dp"
android:textColor="#eee"
android:textSize="14sp"
android:typeface="monospace" />
</LinearLayout>
<LinearLayout
android:id="@+id/pgp_keyentry"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="@drawable/bluebackground"
android:orientation="vertical"
android:visibility="gone" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:padding="8dp"
android:text="OpenPGP encrypted messages found"
android:textColor="#eee"
android:textSize="20sp"
android:textStyle="bold" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingBottom="8dp"
android:paddingLeft="8dp"
android:text="Click here to enter passphrase and decrypt messages"
android:textColor="#eee"
android:textSize="14sp" />
</LinearLayout>
</LinearLayout> </LinearLayout>
<LinearLayout <LinearLayout
android:id="@+id/new_fingerprint" android:id="@+id/last_seen"
android:layout_width="fill_parent" android:layout_width="fill_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:background="@drawable/redbackground" android:background="#7f333333"
android:orientation="vertical" android:orientation="vertical"
android:visibility="gone" android:visibility="gone"
> android:layout_below="@+id/info_box">
<TextView <TextView
android:id="@+id/last_seen_text"
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:text="Unknown OTR Fingerprint" android:layout_gravity="center"
android:textColor="#eee" android:padding="4dp"
android:textStyle="bold" android:text="@string/last_seen"
android:padding="8dp" android:textColor="#e5e5e5"
android:textSize="20sp"/> android:textSize="14sp" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/otr_fingerprint"
android:textColor="#eee"
android:paddingLeft="8dp"
android:paddingBottom="8dp"
android:textSize="14sp"
android:typeface="monospace"/>
</LinearLayout> </LinearLayout>
<LinearLayout
android:id="@+id/pgp_keyentry"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="@drawable/bluebackground"
android:orientation="vertical"
android:visibility="gone"
>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="OpenPGP encrypted messages found"
android:textColor="#eee"
android:textStyle="bold"
android:padding="8dp"
android:textSize="20sp"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="#eee"
android:text="Click here to enter passphrase and decrypt messages"
android:paddingLeft="8dp"
android:paddingBottom="8dp"
android:textSize="14sp"/>
</LinearLayout>
</LinearLayout>
</RelativeLayout> </RelativeLayout>

View File

@ -147,6 +147,8 @@
<string name="pref_never_send_crash_summary">By sending in stack traces you are helping the ongoing development of Conversations</string> <string name="pref_never_send_crash_summary">By sending in stack traces you are helping the ongoing development of Conversations</string>
<string name="pref_confirm_messages">Confirm Messages</string> <string name="pref_confirm_messages">Confirm Messages</string>
<string name="pref_confirm_messages_summary">Let your contact know when you have received and read a message</string> <string name="pref_confirm_messages_summary">Let your contact know when you have received and read a message</string>
<string name="pref_show_last_seen">Display last seen</string>
<string name="pref_show_last_seen_summary">Display the latest time a contact has been seen online</string>
<string name="openpgp_error">OpenKeychain reporeted an error</string> <string name="openpgp_error">OpenKeychain reporeted an error</string>
<string name="error_decrypting_file">I/O Error decrypting file</string> <string name="error_decrypting_file">I/O Error decrypting file</string>
<string name="error_copying_image_file">Error copying image file.</string> <string name="error_copying_image_file">Error copying image file.</string>
@ -234,4 +236,6 @@
<string name="hours">hours</string> <string name="hours">hours</string>
<string name="mins">mins</string> <string name="mins">mins</string>
<string name="missing_public_keys">Missing public key announcements</string> <string name="missing_public_keys">Missing public key announcements</string>
<string name="last_seen">last seen %1$s ago on %2$s</string>
<string name="never_seen">never seen</string>
</resources> </resources>

View File

@ -72,6 +72,11 @@
android:title="@string/pref_conference_name" android:title="@string/pref_conference_name"
android:summary="@string/pref_conference_name_summary" android:summary="@string/pref_conference_name_summary"
android:defaultValue="true"/> android:defaultValue="true"/>
<CheckBoxPreference
android:key="show_last_seen"
android:title="@string/pref_show_last_seen"
android:summary="@string/pref_show_last_seen_summary"
android:defaultValue="false"/>
</PreferenceCategory> </PreferenceCategory>
<PreferenceCategory <PreferenceCategory
android:title="@string/pref_advanced_options"> android:title="@string/pref_advanced_options">

View File

@ -11,7 +11,6 @@ import org.json.JSONObject;
import eu.siacs.conversations.xml.Element; import eu.siacs.conversations.xml.Element;
import android.content.ContentValues; import android.content.ContentValues;
import android.database.Cursor; import android.database.Cursor;
import android.util.Log;
public class Contact { public class Contact {
public static final String TABLENAME = "contacts"; public static final String TABLENAME = "contacts";
@ -39,6 +38,8 @@ public class Contact {
protected boolean inRoster = true; protected boolean inRoster = true;
public Lastseen lastseen = new Lastseen();
public Contact(String account, String systemName, String serverName, public Contact(String account, String systemName, String serverName,
String jid, int subscription, String photoUri, String jid, int subscription, String photoUri,
String systemAccount, String keys) { String systemAccount, String keys) {
@ -305,4 +306,9 @@ public class Contact {
public static final int DIRTY_PUSH = 6; public static final int DIRTY_PUSH = 6;
public static final int DIRTY_DELETE = 7; public static final int DIRTY_DELETE = 7;
} }
public class Lastseen {
public long time = 0;
public String presence = null;
}
} }

View File

@ -203,6 +203,15 @@ public class Message extends AbstractEntity {
this.counterpart = this.counterpart.split("/")[0] + "/" + presence; this.counterpart = this.counterpart.split("/")[0] + "/" + presence;
} }
public String getPresence() {
String[] counterparts = this.counterpart.split("/");
if (counterparts.length == 2) {
return counterparts[1];
} else {
return null;
}
}
public void setJingleConnection(JingleConnection connection) { public void setJingleConnection(JingleConnection connection) {
this.jingleConnection = connection; this.jingleConnection = connection;
} }

View File

@ -6,6 +6,7 @@ import net.java.otr4j.session.Session;
import net.java.otr4j.session.SessionStatus; import net.java.otr4j.session.SessionStatus;
import android.util.Log; import android.util.Log;
import eu.siacs.conversations.entities.Account; import eu.siacs.conversations.entities.Account;
import eu.siacs.conversations.entities.Contact;
import eu.siacs.conversations.entities.Conversation; import eu.siacs.conversations.entities.Conversation;
import eu.siacs.conversations.entities.Message; import eu.siacs.conversations.entities.Message;
import eu.siacs.conversations.services.XmppConnectionService; import eu.siacs.conversations.services.XmppConnectionService;
@ -26,6 +27,7 @@ public class MessageParser {
Conversation conversation = mXmppConnectionService Conversation conversation = mXmppConnectionService
.findOrCreateConversation(account, fromParts[0], false); .findOrCreateConversation(account, fromParts[0], false);
conversation.setLatestMarkableMessageId(getMarkableMessageId(packet)); conversation.setLatestMarkableMessageId(getMarkableMessageId(packet));
updateLastseen(packet, account);
String pgpBody = getPgpBody(packet); String pgpBody = getPgpBody(packet);
if (pgpBody != null) { if (pgpBody != null) {
return new Message(conversation, packet.getFrom(), pgpBody, return new Message(conversation, packet.getFrom(), pgpBody,
@ -43,6 +45,7 @@ public class MessageParser {
String[] fromParts = packet.getFrom().split("/"); String[] fromParts = packet.getFrom().split("/");
Conversation conversation = mXmppConnectionService Conversation conversation = mXmppConnectionService
.findOrCreateConversation(account, fromParts[0], false); .findOrCreateConversation(account, fromParts[0], false);
updateLastseen(packet, account);
String body = packet.getBody(); String body = packet.getBody();
if (!conversation.hasValidOtrSession()) { if (!conversation.hasValidOtrSession()) {
if (properlyAddressed) { if (properlyAddressed) {
@ -171,6 +174,7 @@ public class MessageParser {
return null; // either malformed or boring return null; // either malformed or boring
if (status == Message.STATUS_RECIEVED) { if (status == Message.STATUS_RECIEVED) {
fullJid = message.getAttribute("from"); fullJid = message.getAttribute("from");
updateLastseen(message, account);
} else { } else {
fullJid = message.getAttribute("to"); fullJid = message.getAttribute("to");
} }
@ -211,4 +215,23 @@ public class MessageParser {
return null; return null;
} }
} }
private void updateLastseen(Element message, Account account) {
String[] fromParts = message.getAttribute("from").split("/");
String from = fromParts[0];
String presence = null;
if (fromParts.length >= 2) {
presence = fromParts[1];
}
Contact contact = account.getRoster().getContact(from);
if (presence!=null) {
contact.lastseen.presence = presence;
contact.lastseen.time = System.currentTimeMillis();
} else if ((contact.getPresences().size() == 1)&&(contact.getPresences().containsKey(contact.lastseen.presence))) {
contact.lastseen.time = System.currentTimeMillis();
} else {
contact.lastseen.presence = null;
contact.lastseen.time = System.currentTimeMillis();
}
}
} }

View File

@ -82,6 +82,7 @@ public class ConversationActivity extends XmppActivity {
private boolean paneShouldBeOpen = true; private boolean paneShouldBeOpen = true;
private boolean useSubject = true; private boolean useSubject = true;
private boolean showLastseen = false;
private ArrayAdapter<Conversation> listAdapter; private ArrayAdapter<Conversation> listAdapter;
public Message pendingMessage = null; public Message pendingMessage = null;
@ -182,15 +183,18 @@ public class ConversationActivity extends XmppActivity {
convName.setText(conv.getName(useSubject)); convName.setText(conv.getName(useSubject));
TextView convLastMsg = (TextView) view TextView convLastMsg = (TextView) view
.findViewById(R.id.conversation_lastmsg); .findViewById(R.id.conversation_lastmsg);
ImageView imagePreview = (ImageView) view.findViewById(R.id.conversation_lastimage); ImageView imagePreview = (ImageView) view
.findViewById(R.id.conversation_lastimage);
Message latestMessage = conv.getLatestMessage(); Message latestMessage = conv.getLatestMessage();
if (latestMessage.getType() == Message.TYPE_TEXT) { if (latestMessage.getType() == Message.TYPE_TEXT) {
if ((latestMessage.getEncryption() != Message.ENCRYPTION_PGP)&&(latestMessage.getEncryption() != Message.ENCRYPTION_DECRYPTION_FAILED)) { if ((latestMessage.getEncryption() != Message.ENCRYPTION_PGP)
&& (latestMessage.getEncryption() != Message.ENCRYPTION_DECRYPTION_FAILED)) {
convLastMsg.setText(conv.getLatestMessage().getBody()); convLastMsg.setText(conv.getLatestMessage().getBody());
} else { } else {
convLastMsg.setText(getText(R.string.encrypted_message_received)); convLastMsg
.setText(getText(R.string.encrypted_message_received));
} }
convLastMsg.setVisibility(View.VISIBLE); convLastMsg.setVisibility(View.VISIBLE);
imagePreview.setVisibility(View.GONE); imagePreview.setVisibility(View.GONE);
@ -203,17 +207,17 @@ public class ConversationActivity extends XmppActivity {
convLastMsg.setVisibility(View.VISIBLE); convLastMsg.setVisibility(View.VISIBLE);
imagePreview.setVisibility(View.GONE); imagePreview.setVisibility(View.GONE);
if (latestMessage.getStatus() == Message.STATUS_RECEIVED_OFFER) { if (latestMessage.getStatus() == Message.STATUS_RECEIVED_OFFER) {
convLastMsg.setText(getText(R.string.image_offered_for_download)); convLastMsg
.setText(getText(R.string.image_offered_for_download));
} else if (latestMessage.getStatus() == Message.STATUS_RECIEVING) { } else if (latestMessage.getStatus() == Message.STATUS_RECIEVING) {
convLastMsg.setText(getText(R.string.receiving_image)); convLastMsg
.setText(getText(R.string.receiving_image));
} else { } else {
convLastMsg.setText(""); convLastMsg.setText("");
} }
} }
} }
if (!conv.isRead()) { if (!conv.isRead()) {
convName.setTypeface(null, Typeface.BOLD); convName.setTypeface(null, Typeface.BOLD);
convLastMsg.setTypeface(null, Typeface.BOLD); convLastMsg.setTypeface(null, Typeface.BOLD);
@ -223,13 +227,13 @@ public class ConversationActivity extends XmppActivity {
} }
((TextView) view.findViewById(R.id.conversation_lastupdate)) ((TextView) view.findViewById(R.id.conversation_lastupdate))
.setText(UIHelper.readableTimeDifference(getContext(), conv .setText(UIHelper.readableTimeDifference(getContext(),
.getLatestMessage().getTimeSent())); conv.getLatestMessage().getTimeSent()));
ImageView profilePicture = (ImageView) view ImageView profilePicture = (ImageView) view
.findViewById(R.id.conversation_image); .findViewById(R.id.conversation_image);
profilePicture.setImageBitmap(UIHelper.getContactPicture( profilePicture.setImageBitmap(UIHelper.getContactPicture(conv,
conv, 56, activity.getApplicationContext(), false)); 56, activity.getApplicationContext(), false));
return view; return view;
} }
@ -266,6 +270,11 @@ public class ConversationActivity extends XmppActivity {
getActionBar().setTitle(R.string.app_name); getActionBar().setTitle(R.string.app_name);
invalidateOptionsMenu(); invalidateOptionsMenu();
hideKeyboard(); hideKeyboard();
ConversationFragment selectedFragment = (ConversationFragment) getFragmentManager()
.findFragmentByTag("conversation");
if (selectedFragment != null) {
selectedFragment.lastSeen.setVisibility(View.GONE);
}
} }
@Override @Override
@ -279,11 +288,17 @@ public class ConversationActivity extends XmppActivity {
getSelectedConversation().getName(useSubject)); getSelectedConversation().getName(useSubject));
invalidateOptionsMenu(); invalidateOptionsMenu();
if (!getSelectedConversation().isRead()) { if (!getSelectedConversation().isRead()) {
xmppConnectionService.markRead(getSelectedConversation()); xmppConnectionService
.markRead(getSelectedConversation());
UIHelper.updateNotification(getApplicationContext(), UIHelper.updateNotification(getApplicationContext(),
getConversationList(), null, false); getConversationList(), null, false);
listView.invalidateViews(); listView.invalidateViews();
} }
ConversationFragment selectedFragment = (ConversationFragment) getFragmentManager()
.findFragmentByTag("conversation");
if ((selectedFragment != null) && (showLastseen())) {
selectedFragment.lastSeen.setVisibility(View.VISIBLE);
}
} }
} }
@ -307,7 +322,8 @@ public class ConversationActivity extends XmppActivity {
MenuItem menuInviteContacts = (MenuItem) menu MenuItem menuInviteContacts = (MenuItem) menu
.findItem(R.id.action_invite); .findItem(R.id.action_invite);
MenuItem menuAttach = (MenuItem) menu.findItem(R.id.action_attach_file); MenuItem menuAttach = (MenuItem) menu.findItem(R.id.action_attach_file);
MenuItem menuClearHistory = (MenuItem) menu.findItem(R.id.action_clear_history); MenuItem menuClearHistory = (MenuItem) menu
.findItem(R.id.action_clear_history);
if ((spl.isOpen() && (spl.isSlideable()))) { if ((spl.isOpen() && (spl.isSlideable()))) {
menuArchive.setVisible(false); menuArchive.setVisible(false);
@ -343,20 +359,27 @@ public class ConversationActivity extends XmppActivity {
@Override @Override
public void onPresenceSelected(boolean success, String presence) { public void onPresenceSelected(boolean success, String presence) {
if (success) { if (success) {
if (attachmentChoice==ATTACHMENT_CHOICE_TAKE_PHOTO) { if (attachmentChoice == ATTACHMENT_CHOICE_TAKE_PHOTO) {
Intent takePictureIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE); Intent takePictureIntent = new Intent(
takePictureIntent.putExtra(MediaStore.EXTRA_OUTPUT, ImageProvider.getIncomingContentUri()); MediaStore.ACTION_IMAGE_CAPTURE);
if (takePictureIntent.resolveActivity(getPackageManager()) != null) { takePictureIntent.putExtra(MediaStore.EXTRA_OUTPUT,
startActivityForResult(takePictureIntent, REQUEST_IMAGE_CAPTURE); ImageProvider.getIncomingContentUri());
if (takePictureIntent
.resolveActivity(getPackageManager()) != null) {
startActivityForResult(takePictureIntent,
REQUEST_IMAGE_CAPTURE);
} }
} else if (attachmentChoice==ATTACHMENT_CHOICE_CHOOSE_IMAGE) { } else if (attachmentChoice == ATTACHMENT_CHOICE_CHOOSE_IMAGE) {
Intent attachFileIntent = new Intent(); Intent attachFileIntent = new Intent();
attachFileIntent.setType("image/*"); attachFileIntent.setType("image/*");
attachFileIntent.setAction(Intent.ACTION_GET_CONTENT); attachFileIntent.setAction(Intent.ACTION_GET_CONTENT);
Intent chooser = Intent.createChooser(attachFileIntent, getString(R.string.attach_file)); Intent chooser = Intent.createChooser(attachFileIntent,
startActivityForResult(chooser, REQUEST_ATTACH_FILE_DIALOG); getString(R.string.attach_file));
} else if (attachmentChoice==ATTACHMENT_CHOICE_RECORD_VOICE) { startActivityForResult(chooser,
Intent intent = new Intent(MediaStore.Audio.Media.RECORD_SOUND_ACTION); REQUEST_ATTACH_FILE_DIALOG);
} else if (attachmentChoice == ATTACHMENT_CHOICE_RECORD_VOICE) {
Intent intent = new Intent(
MediaStore.Audio.Media.RECORD_SOUND_ACTION);
startActivityForResult(intent, REQUEST_RECORD_AUDIO); startActivityForResult(intent, REQUEST_RECORD_AUDIO);
} }
} }
@ -367,43 +390,48 @@ public class ConversationActivity extends XmppActivity {
// TODO Auto-generated method stub // TODO Auto-generated method stub
} }
},"file"); }, "file");
} }
private void attachFile(final int attachmentChoice) { private void attachFile(final int attachmentChoice) {
final Conversation conversation = getSelectedConversation(); final Conversation conversation = getSelectedConversation();
if (conversation.getNextEncryption() == Message.ENCRYPTION_PGP) { if (conversation.getNextEncryption() == Message.ENCRYPTION_PGP) {
if (hasPgp()) { if (hasPgp()) {
if (conversation.getContact().getPgpKeyId()!=0) { if (conversation.getContact().getPgpKeyId() != 0) {
xmppConnectionService.getPgpEngine().hasKey(conversation.getContact(), new UiCallback() { xmppConnectionService.getPgpEngine().hasKey(
conversation.getContact(), new UiCallback() {
@Override @Override
public void userInputRequried(PendingIntent pi) { public void userInputRequried(PendingIntent pi) {
ConversationActivity.this.runIntent(pi, attachmentChoice); ConversationActivity.this.runIntent(pi,
} attachmentChoice);
}
@Override @Override
public void success() { public void success() {
selectPresenceToAttachFile(attachmentChoice); selectPresenceToAttachFile(attachmentChoice);
} }
@Override @Override
public void error(int error) { public void error(int error) {
displayErrorDialog(error); displayErrorDialog(error);
} }
}); });
} else { } else {
final ConversationFragment fragment = (ConversationFragment) getFragmentManager() final ConversationFragment fragment = (ConversationFragment) getFragmentManager()
.findFragmentByTag("conversation"); .findFragmentByTag("conversation");
if (fragment != null) { if (fragment != null) {
fragment.showNoPGPKeyDialog(false,new OnClickListener() { fragment.showNoPGPKeyDialog(false,
new OnClickListener() {
@Override @Override
public void onClick(DialogInterface dialog, int which) { public void onClick(DialogInterface dialog,
conversation.setNextEncryption(Message.ENCRYPTION_NONE); int which) {
selectPresenceToAttachFile(attachmentChoice); conversation
} .setNextEncryption(Message.ENCRYPTION_NONE);
}); selectPresenceToAttachFile(attachmentChoice);
}
});
} }
} }
} }
@ -414,24 +442,31 @@ public class ConversationActivity extends XmppActivity {
builder.setTitle(getString(R.string.otr_file_transfer)); builder.setTitle(getString(R.string.otr_file_transfer));
builder.setMessage(getString(R.string.otr_file_transfer_msg)); builder.setMessage(getString(R.string.otr_file_transfer_msg));
builder.setNegativeButton(getString(R.string.cancel), null); builder.setNegativeButton(getString(R.string.cancel), null);
if (conversation.getContact().getPgpKeyId()==0) { if (conversation.getContact().getPgpKeyId() == 0) {
builder.setPositiveButton(getString(R.string.send_unencrypted), new OnClickListener() { builder.setPositiveButton(getString(R.string.send_unencrypted),
new OnClickListener() {
@Override @Override
public void onClick(DialogInterface dialog, int which) { public void onClick(DialogInterface dialog,
conversation.setNextEncryption(Message.ENCRYPTION_NONE); int which) {
attachFile(attachmentChoice); conversation
} .setNextEncryption(Message.ENCRYPTION_NONE);
}); attachFile(attachmentChoice);
}
});
} else { } else {
builder.setPositiveButton(getString(R.string.use_pgp_encryption), new OnClickListener() { builder.setPositiveButton(
getString(R.string.use_pgp_encryption),
new OnClickListener() {
@Override @Override
public void onClick(DialogInterface dialog, int which) { public void onClick(DialogInterface dialog,
conversation.setNextEncryption(Message.ENCRYPTION_PGP); int which) {
attachFile(attachmentChoice); conversation
} .setNextEncryption(Message.ENCRYPTION_PGP);
}); attachFile(attachmentChoice);
}
});
} }
builder.create().show(); builder.create().show();
} }
@ -447,24 +482,25 @@ public class ConversationActivity extends XmppActivity {
View menuAttachFile = findViewById(R.id.action_attach_file); View menuAttachFile = findViewById(R.id.action_attach_file);
PopupMenu attachFilePopup = new PopupMenu(this, menuAttachFile); PopupMenu attachFilePopup = new PopupMenu(this, menuAttachFile);
attachFilePopup.inflate(R.menu.attachment_choices); attachFilePopup.inflate(R.menu.attachment_choices);
attachFilePopup.setOnMenuItemClickListener(new OnMenuItemClickListener() { attachFilePopup
.setOnMenuItemClickListener(new OnMenuItemClickListener() {
@Override @Override
public boolean onMenuItemClick(MenuItem item) { public boolean onMenuItemClick(MenuItem item) {
switch (item.getItemId()) { switch (item.getItemId()) {
case R.id.attach_choose_picture: case R.id.attach_choose_picture:
attachFile(ATTACHMENT_CHOICE_CHOOSE_IMAGE); attachFile(ATTACHMENT_CHOICE_CHOOSE_IMAGE);
break; break;
case R.id.attach_take_picture: case R.id.attach_take_picture:
attachFile(ATTACHMENT_CHOICE_TAKE_PHOTO); attachFile(ATTACHMENT_CHOICE_TAKE_PHOTO);
break; break;
case R.id.attach_record_voice: case R.id.attach_record_voice:
attachFile(ATTACHMENT_CHOICE_RECORD_VOICE); attachFile(ATTACHMENT_CHOICE_RECORD_VOICE);
break; break;
} }
return false; return false;
} }
}); });
attachFilePopup.show(); attachFilePopup.show();
break; break;
case R.id.action_add: case R.id.action_add:
@ -478,8 +514,9 @@ public class ConversationActivity extends XmppActivity {
if (contact.showInRoster()) { if (contact.showInRoster()) {
Intent intent = new Intent(this, ContactDetailsActivity.class); Intent intent = new Intent(this, ContactDetailsActivity.class);
intent.setAction(ContactDetailsActivity.ACTION_VIEW_CONTACT); intent.setAction(ContactDetailsActivity.ACTION_VIEW_CONTACT);
intent.putExtra("account", this.getSelectedConversation().getAccount().getJid()); intent.putExtra("account", this.getSelectedConversation()
intent.putExtra("contact",contact.getJid()); .getAccount().getJid());
intent.putExtra("contact", contact.getJid());
startActivity(intent); startActivity(intent);
} else { } else {
showAddToRosterDialog(getSelectedConversation()); showAddToRosterDialog(getSelectedConversation());
@ -511,25 +548,31 @@ public class ConversationActivity extends XmppActivity {
public boolean onMenuItemClick(MenuItem item) { public boolean onMenuItemClick(MenuItem item) {
switch (item.getItemId()) { switch (item.getItemId()) {
case R.id.encryption_choice_none: case R.id.encryption_choice_none:
conversation.setNextEncryption(Message.ENCRYPTION_NONE); conversation
.setNextEncryption(Message.ENCRYPTION_NONE);
item.setChecked(true); item.setChecked(true);
break; break;
case R.id.encryption_choice_otr: case R.id.encryption_choice_otr:
conversation.setNextEncryption(Message.ENCRYPTION_OTR); conversation
.setNextEncryption(Message.ENCRYPTION_OTR);
item.setChecked(true); item.setChecked(true);
break; break;
case R.id.encryption_choice_pgp: case R.id.encryption_choice_pgp:
if (hasPgp()) { if (hasPgp()) {
if (conversation.getAccount().getKeys().has("pgp_signature")) { if (conversation.getAccount().getKeys()
conversation.setNextEncryption(Message.ENCRYPTION_PGP); .has("pgp_signature")) {
conversation
.setNextEncryption(Message.ENCRYPTION_PGP);
item.setChecked(true); item.setChecked(true);
} else { } else {
announcePgp(conversation.getAccount(),conversation); announcePgp(conversation.getAccount(),
conversation);
} }
} }
break; break;
default: default:
conversation.setNextEncryption(Message.ENCRYPTION_NONE); conversation
.setNextEncryption(Message.ENCRYPTION_NONE);
break; break;
} }
fragment.updateChatMsgHint(); fragment.updateChatMsgHint();
@ -537,7 +580,8 @@ public class ConversationActivity extends XmppActivity {
} }
}); });
popup.inflate(R.menu.encryption_choices); popup.inflate(R.menu.encryption_choices);
MenuItem otr = popup.getMenu().findItem(R.id.encryption_choice_otr); MenuItem otr = popup.getMenu().findItem(
R.id.encryption_choice_otr);
if (conversation.getMode() == Conversation.MODE_MULTI) { if (conversation.getMode() == Conversation.MODE_MULTI) {
otr.setEnabled(false); otr.setEnabled(false);
} }
@ -586,20 +630,24 @@ public class ConversationActivity extends XmppActivity {
protected void clearHistoryDialog(final Conversation conversation) { protected void clearHistoryDialog(final Conversation conversation) {
AlertDialog.Builder builder = new AlertDialog.Builder(this); AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder.setTitle(getString(R.string.clear_conversation_history)); builder.setTitle(getString(R.string.clear_conversation_history));
View dialogView = getLayoutInflater().inflate(R.layout.dialog_clear_history, null); View dialogView = getLayoutInflater().inflate(
final CheckBox endConversationCheckBox = (CheckBox) dialogView.findViewById(R.id.end_conversation_checkbox); R.layout.dialog_clear_history, null);
final CheckBox endConversationCheckBox = (CheckBox) dialogView
.findViewById(R.id.end_conversation_checkbox);
builder.setView(dialogView); builder.setView(dialogView);
builder.setNegativeButton(getString(R.string.cancel), null); builder.setNegativeButton(getString(R.string.cancel), null);
builder.setPositiveButton(getString(R.string.delete_messages), new OnClickListener() { builder.setPositiveButton(getString(R.string.delete_messages),
new OnClickListener() {
@Override @Override
public void onClick(DialogInterface dialog, int which) { public void onClick(DialogInterface dialog, int which) {
activity.xmppConnectionService.clearConversationHistory(conversation); activity.xmppConnectionService
if (endConversationCheckBox.isChecked()) { .clearConversationHistory(conversation);
endConversation(conversation); if (endConversationCheckBox.isChecked()) {
} endConversation(conversation);
} }
}); }
});
builder.create().show(); builder.create().show();
} }
@ -626,10 +674,10 @@ public class ConversationActivity extends XmppActivity {
} }
@Override @Override
protected void onNewIntent (Intent intent) { protected void onNewIntent(Intent intent) {
if ((Intent.ACTION_VIEW.equals(intent.getAction())&&(VIEW_CONVERSATION.equals(intent.getType())))) { if ((Intent.ACTION_VIEW.equals(intent.getAction()) && (VIEW_CONVERSATION
String convToView = (String) intent.getExtras().get( .equals(intent.getType())))) {
CONVERSATION); String convToView = (String) intent.getExtras().get(CONVERSATION);
updateConversationList(); updateConversationList();
for (int i = 0; i < conversationList.size(); ++i) { for (int i = 0; i < conversationList.size(); ++i) {
if (conversationList.get(i).getUuid().equals(convToView)) { if (conversationList.get(i).getUuid().equals(convToView)) {
@ -649,6 +697,7 @@ public class ConversationActivity extends XmppActivity {
SharedPreferences preferences = PreferenceManager SharedPreferences preferences = PreferenceManager
.getDefaultSharedPreferences(this); .getDefaultSharedPreferences(this);
this.useSubject = preferences.getBoolean("use_subject_in_muc", true); this.useSubject = preferences.getBoolean("use_subject_in_muc", true);
this.showLastseen = preferences.getBoolean("show_last_seen", false);
if (this.xmppConnectionServiceBound) { if (this.xmppConnectionServiceBound) {
this.onBackendConnected(); this.onBackendConnected();
} }
@ -722,7 +771,8 @@ public class ConversationActivity extends XmppActivity {
} }
@Override @Override
protected void onActivityResult(int requestCode, int resultCode, final Intent data) { protected void onActivityResult(int requestCode, int resultCode,
final Intent data) {
super.onActivityResult(requestCode, resultCode, data); super.onActivityResult(requestCode, resultCode, data);
if (resultCode == RESULT_OK) { if (resultCode == RESULT_OK) {
if (requestCode == REQUEST_DECRYPT_PGP) { if (requestCode == REQUEST_DECRYPT_PGP) {
@ -732,7 +782,8 @@ public class ConversationActivity extends XmppActivity {
selectedFragment.hidePgpPassphraseBox(); selectedFragment.hidePgpPassphraseBox();
} }
} else if (requestCode == REQUEST_ATTACH_FILE_DIALOG) { } else if (requestCode == REQUEST_ATTACH_FILE_DIALOG) {
attachImageToConversation(getSelectedConversation(),data.getData()); attachImageToConversation(getSelectedConversation(),
data.getData());
} else if (requestCode == REQUEST_SEND_PGP_IMAGE) { } else if (requestCode == REQUEST_SEND_PGP_IMAGE) {
} else if (requestCode == ATTACHMENT_CHOICE_CHOOSE_IMAGE) { } else if (requestCode == ATTACHMENT_CHOICE_CHOOSE_IMAGE) {
@ -740,16 +791,18 @@ public class ConversationActivity extends XmppActivity {
} else if (requestCode == ATTACHMENT_CHOICE_TAKE_PHOTO) { } else if (requestCode == ATTACHMENT_CHOICE_TAKE_PHOTO) {
attachFile(ATTACHMENT_CHOICE_TAKE_PHOTO); attachFile(ATTACHMENT_CHOICE_TAKE_PHOTO);
} else if (requestCode == REQUEST_ANNOUNCE_PGP) { } else if (requestCode == REQUEST_ANNOUNCE_PGP) {
announcePgp(getSelectedConversation().getAccount(),getSelectedConversation()); announcePgp(getSelectedConversation().getAccount(),
getSelectedConversation());
} else if (requestCode == REQUEST_ENCRYPT_MESSAGE) { } else if (requestCode == REQUEST_ENCRYPT_MESSAGE) {
encryptTextMessage(); encryptTextMessage();
} else if (requestCode == REQUEST_IMAGE_CAPTURE) { } else if (requestCode == REQUEST_IMAGE_CAPTURE) {
attachImageToConversation(getSelectedConversation(), null); attachImageToConversation(getSelectedConversation(), null);
} else if (requestCode == REQUEST_RECORD_AUDIO) { } else if (requestCode == REQUEST_RECORD_AUDIO) {
Log.d("xmppService",data.getData().toString()); Log.d("xmppService", data.getData().toString());
attachAudioToConversation(getSelectedConversation(),data.getData()); attachAudioToConversation(getSelectedConversation(),
data.getData());
} else { } else {
Log.d(LOGTAG,"unknown result code:"+requestCode); Log.d(LOGTAG, "unknown result code:" + requestCode);
} }
} }
} }
@ -759,33 +812,36 @@ public class ConversationActivity extends XmppActivity {
} }
private void attachImageToConversation(Conversation conversation, Uri uri) { private void attachImageToConversation(Conversation conversation, Uri uri) {
prepareImageToast = Toast.makeText(getApplicationContext(), getText(R.string.preparing_image), Toast.LENGTH_LONG); prepareImageToast = Toast.makeText(getApplicationContext(),
getText(R.string.preparing_image), Toast.LENGTH_LONG);
prepareImageToast.show(); prepareImageToast.show();
pendingMessage = xmppConnectionService.attachImageToConversation(conversation, uri, new UiCallback() { pendingMessage = xmppConnectionService.attachImageToConversation(
conversation, uri, new UiCallback() {
@Override @Override
public void userInputRequried(PendingIntent pi) { public void userInputRequried(PendingIntent pi) {
hidePrepareImageToast(); hidePrepareImageToast();
ConversationActivity.this.runIntent(pi, ConversationActivity.REQUEST_SEND_PGP_IMAGE); ConversationActivity.this.runIntent(pi,
} ConversationActivity.REQUEST_SEND_PGP_IMAGE);
}
@Override @Override
public void success() { public void success() {
sendPendingImageMessage(); sendPendingImageMessage();
hidePrepareImageToast(); hidePrepareImageToast();
} }
@Override @Override
public void error(int error) { public void error(int error) {
hidePrepareImageToast(); hidePrepareImageToast();
pendingMessage = null; pendingMessage = null;
displayErrorDialog(error); displayErrorDialog(error);
} }
}); });
} }
private void hidePrepareImageToast() { private void hidePrepareImageToast() {
if (prepareImageToast!=null) { if (prepareImageToast != null) {
runOnUiThread(new Runnable() { runOnUiThread(new Runnable() {
@Override @Override
@ -810,34 +866,39 @@ public class ConversationActivity extends XmppActivity {
listView.invalidateViews(); listView.invalidateViews();
} }
public void selectPresence(final Conversation conversation, final OnPresenceSelected listener, String reason) { public void selectPresence(final Conversation conversation,
final OnPresenceSelected listener, String reason) {
Account account = conversation.getAccount(); Account account = conversation.getAccount();
if (account.getStatus() != Account.STATUS_ONLINE) { if (account.getStatus() != Account.STATUS_ONLINE) {
AlertDialog.Builder builder = new AlertDialog.Builder(this); AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder.setTitle(getString(R.string.not_connected)); builder.setTitle(getString(R.string.not_connected));
builder.setIconAttribute(android.R.attr.alertDialogIcon); builder.setIconAttribute(android.R.attr.alertDialogIcon);
if ("otr".equals(reason)) { if ("otr".equals(reason)) {
builder.setMessage(getString(R.string.you_are_offline,getString(R.string.otr_messages))); builder.setMessage(getString(R.string.you_are_offline,
getString(R.string.otr_messages)));
} else if ("file".equals(reason)) { } else if ("file".equals(reason)) {
builder.setMessage(getString(R.string.you_are_offline,getString(R.string.files))); builder.setMessage(getString(R.string.you_are_offline,
getString(R.string.files)));
} else { } else {
builder.setMessage(getString(R.string.you_are_offline_blank)); builder.setMessage(getString(R.string.you_are_offline_blank));
} }
builder.setNegativeButton(getString(R.string.cancel), null); builder.setNegativeButton(getString(R.string.cancel), null);
builder.setPositiveButton(getString(R.string.manage_account), new OnClickListener() { builder.setPositiveButton(getString(R.string.manage_account),
new OnClickListener() {
@Override @Override
public void onClick(DialogInterface dialog, int which) { public void onClick(DialogInterface dialog, int which) {
startActivity(new Intent(activity, ManageAccountActivity.class)); startActivity(new Intent(activity,
} ManageAccountActivity.class));
}); }
});
builder.create().show(); builder.create().show();
listener.onPresenceSelected(false, null); listener.onPresenceSelected(false, null);
} else { } else {
Contact contact = conversation.getContact(); Contact contact = conversation.getContact();
if (contact==null) { if (contact == null) {
showAddToRosterDialog(conversation); showAddToRosterDialog(conversation);
listener.onPresenceSelected(false,null); listener.onPresenceSelected(false, null);
} else { } else {
Hashtable<String, Integer> presences = contact.getPresences(); Hashtable<String, Integer> presences = contact.getPresences();
if (presences.size() == 0) { if (presences.size() == 0) {
@ -845,13 +906,16 @@ public class ConversationActivity extends XmppActivity {
builder.setTitle(getString(R.string.contact_offline)); builder.setTitle(getString(R.string.contact_offline));
if ("otr".equals(reason)) { if ("otr".equals(reason)) {
builder.setMessage(getString(R.string.contact_offline_otr)); builder.setMessage(getString(R.string.contact_offline_otr));
builder.setPositiveButton(getString(R.string.send_unencrypted), new OnClickListener() { builder.setPositiveButton(
getString(R.string.send_unencrypted),
new OnClickListener() {
@Override @Override
public void onClick(DialogInterface dialog, int which) { public void onClick(DialogInterface dialog,
listener.onSendPlainTextInstead(); int which) {
} listener.onSendPlainTextInstead();
}); }
});
} else if ("file".equals(reason)) { } else if ("file".equals(reason)) {
builder.setMessage(getString(R.string.contact_offline_file)); builder.setMessage(getString(R.string.contact_offline_file));
} }
@ -876,7 +940,7 @@ public class ConversationActivity extends XmppActivity {
int which) { int which) {
String presence = presencesArray[which]; String presence = presencesArray[which];
conversation.setNextPresence(presence); conversation.setNextPresence(presence);
listener.onPresenceSelected(true,presence); listener.onPresenceSelected(true, presence);
} }
}); });
builder.create().show(); builder.create().show();
@ -885,136 +949,148 @@ public class ConversationActivity extends XmppActivity {
} }
} }
public boolean showLastseen() {
if (getSelectedConversation() == null) {
return false;
} else {
return this.showLastseen
&& getSelectedConversation().getMode() == Conversation.MODE_SINGLE;
}
}
private void showAddToRosterDialog(final Conversation conversation) { private void showAddToRosterDialog(final Conversation conversation) {
String jid = conversation.getContactJid(); String jid = conversation.getContactJid();
AlertDialog.Builder builder = new AlertDialog.Builder(this); AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder.setTitle(jid); builder.setTitle(jid);
builder.setMessage(getString(R.string.not_in_roster)); builder.setMessage(getString(R.string.not_in_roster));
builder.setNegativeButton(getString(R.string.cancel), null); builder.setNegativeButton(getString(R.string.cancel), null);
builder.setPositiveButton(getString(R.string.add_contact), new DialogInterface.OnClickListener() { builder.setPositiveButton(getString(R.string.add_contact),
new DialogInterface.OnClickListener() {
@Override @Override
public void onClick(DialogInterface dialog, int which) { public void onClick(DialogInterface dialog, int which) {
String jid = conversation.getContactJid(); String jid = conversation.getContactJid();
Account account = getSelectedConversation().getAccount(); Account account = getSelectedConversation()
Contact contact = account.getRoster().getContact(jid); .getAccount();
xmppConnectionService.createContact(contact); Contact contact = account.getRoster().getContact(jid);
} xmppConnectionService.createContact(contact);
}); }
});
builder.create().show(); builder.create().show();
} }
public void runIntent(PendingIntent pi, int requestCode) { public void runIntent(PendingIntent pi, int requestCode) {
try { try {
this.startIntentSenderForResult(pi.getIntentSender(),requestCode, null, 0, this.startIntentSenderForResult(pi.getIntentSender(), requestCode,
0, 0); null, 0, 0, 0);
} catch (SendIntentException e1) { } catch (SendIntentException e1) {
Log.d("xmppService","failed to start intent to send message"); Log.d("xmppService", "failed to start intent to send message");
} }
} }
class BitmapWorkerTask extends AsyncTask<Message, Void, Bitmap> { class BitmapWorkerTask extends AsyncTask<Message, Void, Bitmap> {
private final WeakReference<ImageView> imageViewReference; private final WeakReference<ImageView> imageViewReference;
private Message message = null; private Message message = null;
public BitmapWorkerTask(ImageView imageView) { public BitmapWorkerTask(ImageView imageView) {
imageViewReference = new WeakReference<ImageView>(imageView); imageViewReference = new WeakReference<ImageView>(imageView);
} }
@Override @Override
protected Bitmap doInBackground(Message... params) { protected Bitmap doInBackground(Message... params) {
message = params[0]; message = params[0];
try { try {
return xmppConnectionService.getFileBackend().getThumbnail(message, (int) (metrics.density * 288),false); return xmppConnectionService.getFileBackend().getThumbnail(
message, (int) (metrics.density * 288), false);
} catch (FileNotFoundException e) { } catch (FileNotFoundException e) {
Log.d("xmppService","file not found!"); Log.d("xmppService", "file not found!");
return null; return null;
} }
} }
@Override @Override
protected void onPostExecute(Bitmap bitmap) { protected void onPostExecute(Bitmap bitmap) {
if (imageViewReference != null && bitmap != null) { if (imageViewReference != null && bitmap != null) {
final ImageView imageView = imageViewReference.get(); final ImageView imageView = imageViewReference.get();
if (imageView != null) { if (imageView != null) {
imageView.setImageBitmap(bitmap); imageView.setImageBitmap(bitmap);
imageView.setBackgroundColor(0x00000000); imageView.setBackgroundColor(0x00000000);
} }
} }
} }
} }
public void loadBitmap(Message message, ImageView imageView) { public void loadBitmap(Message message, ImageView imageView) {
Bitmap bm; Bitmap bm;
try { try {
bm = xmppConnectionService.getFileBackend().getThumbnail(message, (int) (metrics.density * 288), true); bm = xmppConnectionService.getFileBackend().getThumbnail(message,
(int) (metrics.density * 288), true);
} catch (FileNotFoundException e) { } catch (FileNotFoundException e) {
bm = null; bm = null;
} }
if (bm!=null) { if (bm != null) {
imageView.setImageBitmap(bm); imageView.setImageBitmap(bm);
imageView.setBackgroundColor(0x00000000); imageView.setBackgroundColor(0x00000000);
} else { } else {
if (cancelPotentialWork(message, imageView)) { if (cancelPotentialWork(message, imageView)) {
imageView.setBackgroundColor(0xff333333); imageView.setBackgroundColor(0xff333333);
final BitmapWorkerTask task = new BitmapWorkerTask(imageView); final BitmapWorkerTask task = new BitmapWorkerTask(imageView);
final AsyncDrawable asyncDrawable = final AsyncDrawable asyncDrawable = new AsyncDrawable(
new AsyncDrawable(getResources(), null, task); getResources(), null, task);
imageView.setImageDrawable(asyncDrawable); imageView.setImageDrawable(asyncDrawable);
task.execute(message); task.execute(message);
} }
} }
} }
public static boolean cancelPotentialWork(Message message, ImageView imageView) { public static boolean cancelPotentialWork(Message message,
final BitmapWorkerTask bitmapWorkerTask = getBitmapWorkerTask(imageView); ImageView imageView) {
final BitmapWorkerTask bitmapWorkerTask = getBitmapWorkerTask(imageView);
if (bitmapWorkerTask != null) { if (bitmapWorkerTask != null) {
final Message oldMessage = bitmapWorkerTask.message; final Message oldMessage = bitmapWorkerTask.message;
if (oldMessage == null || message != oldMessage) { if (oldMessage == null || message != oldMessage) {
bitmapWorkerTask.cancel(true); bitmapWorkerTask.cancel(true);
} else { } else {
return false; return false;
} }
} }
return true; return true;
} }
private static BitmapWorkerTask getBitmapWorkerTask(ImageView imageView) { private static BitmapWorkerTask getBitmapWorkerTask(ImageView imageView) {
if (imageView != null) { if (imageView != null) {
final Drawable drawable = imageView.getDrawable(); final Drawable drawable = imageView.getDrawable();
if (drawable instanceof AsyncDrawable) { if (drawable instanceof AsyncDrawable) {
final AsyncDrawable asyncDrawable = (AsyncDrawable) drawable; final AsyncDrawable asyncDrawable = (AsyncDrawable) drawable;
return asyncDrawable.getBitmapWorkerTask(); return asyncDrawable.getBitmapWorkerTask();
} }
} }
return null; return null;
} }
static class AsyncDrawable extends BitmapDrawable { static class AsyncDrawable extends BitmapDrawable {
private final WeakReference<BitmapWorkerTask> bitmapWorkerTaskReference; private final WeakReference<BitmapWorkerTask> bitmapWorkerTaskReference;
public AsyncDrawable(Resources res, Bitmap bitmap, public AsyncDrawable(Resources res, Bitmap bitmap,
BitmapWorkerTask bitmapWorkerTask) { BitmapWorkerTask bitmapWorkerTask) {
super(res, bitmap); super(res, bitmap);
bitmapWorkerTaskReference = bitmapWorkerTaskReference = new WeakReference<BitmapWorkerTask>(
new WeakReference<BitmapWorkerTask>(bitmapWorkerTask); bitmapWorkerTask);
} }
public BitmapWorkerTask getBitmapWorkerTask() { public BitmapWorkerTask getBitmapWorkerTask() {
return bitmapWorkerTaskReference.get(); return bitmapWorkerTaskReference.get();
} }
} }
public void encryptTextMessage() { public void encryptTextMessage() {
xmppConnectionService.getPgpEngine().encrypt(this.pendingMessage, new UiCallback() { xmppConnectionService.getPgpEngine().encrypt(this.pendingMessage,
new UiCallback() {
@Override @Override
public void userInputRequried( public void userInputRequried(PendingIntent pi) {
PendingIntent pi) { activity.runIntent(pi,
activity.runIntent(
pi,
ConversationActivity.REQUEST_SEND_MESSAGE); ConversationActivity.REQUEST_SEND_MESSAGE);
} }

View File

@ -107,7 +107,9 @@ public class ConversationFragment extends Fragment {
private LinearLayout pgpInfo; private LinearLayout pgpInfo;
private LinearLayout mucError; private LinearLayout mucError;
public LinearLayout lastSeen;
private TextView mucErrorText; private TextView mucErrorText;
private TextView lastSeenText;
private OnClickListener clickToMuc = new OnClickListener() { private OnClickListener clickToMuc = new OnClickListener() {
@Override @Override
@ -161,6 +163,8 @@ public class ConversationFragment extends Fragment {
mucError = (LinearLayout) view.findViewById(R.id.muc_error); mucError = (LinearLayout) view.findViewById(R.id.muc_error);
mucError.setOnClickListener(clickToMuc); mucError.setOnClickListener(clickToMuc);
mucErrorText = (TextView) view.findViewById(R.id.muc_error_msg); mucErrorText = (TextView) view.findViewById(R.id.muc_error_msg);
lastSeen = (LinearLayout) view.findViewById(R.id.last_seen);
lastSeenText = (TextView) view.findViewById(R.id.last_seen_text);
messagesView = (ListView) view.findViewById(R.id.messages_view); messagesView = (ListView) view.findViewById(R.id.messages_view);
@ -181,7 +185,7 @@ public class ConversationFragment extends Fragment {
public int getItemViewType(int position) { public int getItemViewType(int position) {
if (getItem(position).getType() == Message.TYPE_STATUS) { if (getItem(position).getType() == Message.TYPE_STATUS) {
return STATUS; return STATUS;
} else if (getItem(position).getStatus() <= Message.STATUS_RECIEVED) { } else if (getItem(position).getStatus() <= Message.STATUS_RECIEVED) {
return RECIEVED; return RECIEVED;
} else { } else {
return SENT; return SENT;
@ -335,18 +339,21 @@ public class ConversationFragment extends Fragment {
startActivity(intent); startActivity(intent);
} }
}); });
viewHolder.image.setOnLongClickListener(new OnLongClickListener() { viewHolder.image
.setOnLongClickListener(new OnLongClickListener() {
@Override @Override
public boolean onLongClick(View v) { public boolean onLongClick(View v) {
Intent shareIntent = new Intent(); Intent shareIntent = new Intent();
shareIntent.setAction(Intent.ACTION_SEND); shareIntent.setAction(Intent.ACTION_SEND);
shareIntent.putExtra(Intent.EXTRA_STREAM, ImageProvider.getContentUri(message)); shareIntent.putExtra(Intent.EXTRA_STREAM,
shareIntent.setType("image/webp"); ImageProvider.getContentUri(message));
startActivity(Intent.createChooser(shareIntent, getText(R.string.share_with))); shareIntent.setType("image/webp");
return true; startActivity(Intent.createChooser(shareIntent,
} getText(R.string.share_with)));
}); return true;
}
});
} }
@Override @Override
@ -405,8 +412,8 @@ public class ConversationFragment extends Fragment {
view.setTag(viewHolder); view.setTag(viewHolder);
break; break;
case STATUS: case STATUS:
view = (View) inflater.inflate( view = (View) inflater.inflate(R.layout.message_status,
R.layout.message_status, null); null);
viewHolder.contact_picture = (ImageView) view viewHolder.contact_picture = (ImageView) view
.findViewById(R.id.message_photo); .findViewById(R.id.message_photo);
if (item.getConversation().getMode() == Conversation.MODE_SINGLE) { if (item.getConversation().getMode() == Conversation.MODE_SINGLE) {
@ -577,7 +584,11 @@ public class ConversationFragment extends Fragment {
activity.getActionBar().setTitle( activity.getActionBar().setTitle(
conversation.getName(useSubject)); conversation.getName(useSubject));
activity.invalidateOptionsMenu(); activity.invalidateOptionsMenu();
if (activity.showLastseen()) {
lastSeen.setVisibility(View.VISIBLE);
}
} else {
lastSeen.setVisibility(View.GONE);
} }
} }
if (conversation.getMode() == Conversation.MODE_MULTI) { if (conversation.getMode() == Conversation.MODE_MULTI) {
@ -653,6 +664,16 @@ public class ConversationFragment extends Fragment {
break; break;
} }
} }
if (activity.showLastseen()) {
Contact contact = conversation.getContact();
if ((contact.lastseen.presence != null)&&(contact.lastseen.time != 0)) {
lastSeenText.setText(getString(R.string.last_seen,
UIHelper.lastseen(getActivity(), contact.lastseen.time),
contact.lastseen.presence));
} else {
lastSeenText.setText(R.string.never_seen);
}
}
this.messageList.clear(); this.messageList.clear();
this.messageList.addAll(this.conversation.getMessages()); this.messageList.addAll(this.conversation.getMessages());
updateStatusMessages(); updateStatusMessages();
@ -688,12 +709,13 @@ public class ConversationFragment extends Fragment {
protected void updateStatusMessages() { protected void updateStatusMessages() {
if (conversation.getMode() == Conversation.MODE_SINGLE) { if (conversation.getMode() == Conversation.MODE_SINGLE) {
for(int i = this.messageList.size() - 1; i >= 0; --i) { for (int i = this.messageList.size() - 1; i >= 0; --i) {
if (this.messageList.get(i).getStatus() == Message.STATUS_RECIEVED) { if (this.messageList.get(i).getStatus() == Message.STATUS_RECIEVED) {
return; return;
} else { } else {
if (this.messageList.get(i).getStatus() == Message.STATUS_SEND_DISPLAYED) { if (this.messageList.get(i).getStatus() == Message.STATUS_SEND_DISPLAYED) {
this.messageList.add(i+1, Message.createStatusMessage(conversation)); this.messageList.add(i + 1,
Message.createStatusMessage(conversation));
return; return;
} }
} }

View File

@ -71,6 +71,19 @@ public class UIHelper {
} }
} }
public static String lastseen(Context context, long time) {
long difference = (System.currentTimeMillis() - time) / 1000;
if (difference < 60) {
return context.getString(R.string.just_now);
} else if (difference < 60 * 60) {
return difference / 60 + " " + context.getString(R.string.mins);
} else if (difference < 60 * 60 * 24) {
return difference / (60 * 60)+ " " + context.getString(R.string.hours);
} else {
return "days";
}
}
public static int getRealPx(int dp, Context context) { public static int getRealPx(int dp, Context context) {
final DisplayMetrics metrics = context.getResources().getDisplayMetrics(); final DisplayMetrics metrics = context.getResources().getDisplayMetrics();
return ((int) (dp * metrics.density)); return ((int) (dp * metrics.density));