aboutsummaryrefslogtreecommitdiffstats
path: root/src/main/java/eu/siacs/conversations/ui
diff options
context:
space:
mode:
Diffstat (limited to 'src/main/java/eu/siacs/conversations/ui')
-rw-r--r--src/main/java/eu/siacs/conversations/ui/ConferenceDetailsActivity.java314
-rw-r--r--src/main/java/eu/siacs/conversations/ui/ContactDetailsActivity.java122
-rw-r--r--src/main/java/eu/siacs/conversations/ui/ConversationActivity.java161
-rw-r--r--src/main/java/eu/siacs/conversations/ui/ConversationFragment.java90
-rw-r--r--src/main/java/eu/siacs/conversations/ui/EditMessage.java9
-rw-r--r--src/main/java/eu/siacs/conversations/ui/PublishProfilePictureActivity.java26
-rw-r--r--src/main/java/eu/siacs/conversations/ui/SettingsActivity.java9
-rw-r--r--src/main/java/eu/siacs/conversations/ui/ShareWithActivity.java21
-rw-r--r--src/main/java/eu/siacs/conversations/ui/StartConversationActivity.java28
-rw-r--r--src/main/java/eu/siacs/conversations/ui/XmppActivity.java38
-rw-r--r--src/main/java/eu/siacs/conversations/ui/adapter/AccountAdapter.java2
-rw-r--r--src/main/java/eu/siacs/conversations/ui/adapter/ConversationAdapter.java134
-rw-r--r--src/main/java/eu/siacs/conversations/ui/adapter/MessageAdapter.java334
13 files changed, 741 insertions, 547 deletions
diff --git a/src/main/java/eu/siacs/conversations/ui/ConferenceDetailsActivity.java b/src/main/java/eu/siacs/conversations/ui/ConferenceDetailsActivity.java
index eeb015f3..399d9fdf 100644
--- a/src/main/java/eu/siacs/conversations/ui/ConferenceDetailsActivity.java
+++ b/src/main/java/eu/siacs/conversations/ui/ConferenceDetailsActivity.java
@@ -1,8 +1,10 @@
package eu.siacs.conversations.ui;
import android.annotation.TargetApi;
+import android.app.AlertDialog;
import android.app.PendingIntent;
import android.content.Context;
+import android.content.DialogInterface;
import android.content.IntentSender.SendIntentException;
import android.graphics.Bitmap;
import android.os.Build;
@@ -31,12 +33,14 @@ import eu.siacs.conversations.entities.Account;
import eu.siacs.conversations.entities.Bookmark;
import eu.siacs.conversations.entities.Contact;
import eu.siacs.conversations.entities.Conversation;
+import eu.siacs.conversations.entities.MucOptions;
import eu.siacs.conversations.entities.MucOptions.User;
+import eu.siacs.conversations.services.XmppConnectionService;
import eu.siacs.conversations.services.XmppConnectionService.OnMucRosterUpdate;
import eu.siacs.conversations.services.XmppConnectionService.OnConversationUpdate;
-import eu.siacs.conversations.xmpp.stanzas.MessagePacket;
+import eu.siacs.conversations.xmpp.jid.Jid;
-public class ConferenceDetailsActivity extends XmppActivity implements OnConversationUpdate, OnMucRosterUpdate {
+public class ConferenceDetailsActivity extends XmppActivity implements OnConversationUpdate, OnMucRosterUpdate, XmppConnectionService.OnAffiliationChanged, XmppConnectionService.OnRoleChanged, XmppConnectionService.OnConferenceOptionsPushed {
public static final String ACTION_VIEW_MUC = "view_muc";
private Conversation mConversation;
private OnClickListener inviteListener = new OnClickListener() {
@@ -54,11 +58,14 @@ public class ConferenceDetailsActivity extends XmppActivity implements OnConvers
private TextView mAccountJid;
private LinearLayout membersView;
private LinearLayout mMoreDetails;
+ private TextView mConferenceType;
+ private ImageButton mChangeConferenceSettingsButton;
private Button mInviteButton;
private String uuid = null;
- private List<User> users = new ArrayList<>();
private User mSelectedUser = null;
+ private boolean mAdvancedMode = false;
+
private UiCallback<Conversation> renameCallback = new UiCallback<Conversation>() {
@Override
public void success(Conversation object) {
@@ -66,7 +73,7 @@ public class ConferenceDetailsActivity extends XmppActivity implements OnConvers
@Override
public void run() {
Toast.makeText(ConferenceDetailsActivity.this,getString(R.string.your_nick_has_been_changed),Toast.LENGTH_SHORT).show();
- populateView();
+ updateView();
}
});
@@ -87,6 +94,51 @@ public class ConferenceDetailsActivity extends XmppActivity implements OnConvers
}
};
+ private OnClickListener mChangeConferenceSettings = new OnClickListener() {
+ @Override
+ public void onClick(View v) {
+ final MucOptions mucOptions = mConversation.getMucOptions();
+ AlertDialog.Builder builder = new AlertDialog.Builder(ConferenceDetailsActivity.this);
+ builder.setTitle(R.string.conference_options);
+ String[] options = {getString(R.string.members_only),
+ getString(R.string.non_anonymous)};
+ final boolean[] values = new boolean[options.length];
+ values[0] = mucOptions.membersOnly();
+ values[1] = mucOptions.nonanonymous();
+ builder.setMultiChoiceItems(options,values,new DialogInterface.OnMultiChoiceClickListener() {
+ @Override
+ public void onClick(DialogInterface dialog, int which, boolean isChecked) {
+ values[which] = isChecked;
+ }
+ });
+ builder.setNegativeButton(R.string.cancel, null);
+ builder.setPositiveButton(R.string.confirm,new DialogInterface.OnClickListener() {
+ @Override
+ public void onClick(DialogInterface dialog, int which) {
+ if (!mucOptions.membersOnly() && values[0]) {
+ xmppConnectionService.changeAffiliationsInConference(mConversation,
+ MucOptions.Affiliation.NONE,
+ MucOptions.Affiliation.MEMBER);
+ }
+ Bundle options = new Bundle();
+ options.putString("muc#roomconfig_membersonly", values[0] ? "1" : "0");
+ options.putString("muc#roomconfig_whois", values[1] ? "anyone" : "moderators");
+ options.putString("muc#roomconfig_persistentroom", "1");
+ xmppConnectionService.pushConferenceConfiguration(mConversation,
+ options,
+ ConferenceDetailsActivity.this);
+ }
+ });
+ builder.create().show();
+ }
+ };
+ private OnValueEdited onSubjectEdited = new OnValueEdited() {
+
+ @Override
+ public void onValueEdited(String value) {
+ xmppConnectionService.pushSubjectToConference(mConversation,value);
+ }
+ };
@Override
public void onConversationUpdate() {
@@ -94,7 +146,7 @@ public class ConferenceDetailsActivity extends XmppActivity implements OnConvers
@Override
public void run() {
- populateView();
+ updateView();
}
});
}
@@ -105,7 +157,7 @@ public class ConferenceDetailsActivity extends XmppActivity implements OnConvers
@Override
public void run() {
- populateView();
+ updateView();
}
});
}
@@ -122,8 +174,12 @@ public class ConferenceDetailsActivity extends XmppActivity implements OnConvers
mAccountJid = (TextView) findViewById(R.id.details_account);
mMoreDetails = (LinearLayout) findViewById(R.id.muc_more_details);
mMoreDetails.setVisibility(View.GONE);
+ mChangeConferenceSettingsButton = (ImageButton) findViewById(R.id.change_conference_button);
+ mChangeConferenceSettingsButton.setOnClickListener(this.mChangeConferenceSettings);
+ mConferenceType = (TextView) findViewById(R.id.muc_conference_type);
mInviteButton = (Button) findViewById(R.id.invite);
mInviteButton.setOnClickListener(inviteListener);
+ mConferenceType = (TextView) findViewById(R.id.muc_conference_type);
if (getActionBar() != null) {
getActionBar().setHomeButtonEnabled(true);
getActionBar().setDisplayHomeAsUpEnabled(true);
@@ -152,17 +208,7 @@ public class ConferenceDetailsActivity extends XmppActivity implements OnConvers
break;
case R.id.action_edit_subject:
if (mConversation != null) {
- quickEdit(mConversation.getName(), new OnValueEdited() {
-
- @Override
- public void onValueEdited(String value) {
- MessagePacket packet = xmppConnectionService
- .getMessageGenerator().conferenceSubject(
- mConversation, value);
- xmppConnectionService.sendMessagePacket(
- mConversation.getAccount(), packet);
- }
- });
+ quickEdit(mConversation.getName(),this.onSubjectEdited);
}
break;
case R.id.action_save_as_bookmark:
@@ -171,23 +217,16 @@ public class ConferenceDetailsActivity extends XmppActivity implements OnConvers
case R.id.action_delete_bookmark:
deleteBookmark();
break;
+ case R.id.action_advanced_mode:
+ this.mAdvancedMode = !menuItem.isChecked();
+ menuItem.setChecked(this.mAdvancedMode);
+ invalidateOptionsMenu();
+ updateView();
+ break;
}
return super.onOptionsItemSelected(menuItem);
}
- public String getReadableRole(int role) {
- switch (role) {
- case User.ROLE_MODERATOR:
- return getString(R.string.moderator);
- case User.ROLE_PARTICIPANT:
- return getString(R.string.participant);
- case User.ROLE_VISITOR:
- return getString(R.string.visitor);
- default:
- return "";
- }
- }
-
@Override
protected String getShareableUri() {
if (mConversation != null) {
@@ -201,6 +240,8 @@ public class ConferenceDetailsActivity extends XmppActivity implements OnConvers
public boolean onPrepareOptionsMenu(Menu menu) {
MenuItem menuItemSaveBookmark = menu.findItem(R.id.action_save_as_bookmark);
MenuItem menuItemDeleteBookmark = menu.findItem(R.id.action_delete_bookmark);
+ MenuItem menuItemAdvancedMode = menu.findItem(R.id.action_advanced_mode);
+ menuItemAdvancedMode.setChecked(mAdvancedMode);
Account account = mConversation.getAccount();
if (account.hasBookmarkFor(mConversation.getJid().toBareJid())) {
menuItemSaveBookmark.setVisible(false);
@@ -224,21 +265,45 @@ public class ConferenceDetailsActivity extends XmppActivity implements OnConvers
if (tag instanceof User) {
getMenuInflater().inflate(R.menu.muc_details_context,menu);
final User user = (User) tag;
+ final User self = mConversation.getMucOptions().getSelf();
this.mSelectedUser = user;
String name;
- final Contact contact = user.getContact();
- if (contact != null) {
- name = contact.getDisplayName();
- } else if (user.getJid() != null) {
- name = user.getJid().toBareJid().toString();
- } else {
- name = user.getName();
- }
- menu.setHeaderTitle(name);
- MenuItem startConversation = menu.findItem(R.id.start_conversation);
- if (user.getJid() == null) {
- startConversation.setVisible(false);
+ if (user.getJid() != null) {
+ final Contact contact = user.getContact();
+ if (contact != null) {
+ name = contact.getDisplayName();
+ } else {
+ name = user.getJid().toBareJid().toString();
+ }
+ menu.setHeaderTitle(name);
+ MenuItem startConversation = menu.findItem(R.id.start_conversation);
+ MenuItem giveMembership = menu.findItem(R.id.give_membership);
+ MenuItem removeMembership = menu.findItem(R.id.remove_membership);
+ MenuItem giveAdminPrivileges = menu.findItem(R.id.give_admin_privileges);
+ MenuItem removeAdminPrivileges = menu.findItem(R.id.remove_admin_privileges);
+ MenuItem removeFromRoom = menu.findItem(R.id.remove_from_room);
+ MenuItem banFromConference = menu.findItem(R.id.ban_from_conference);
+ startConversation.setVisible(true);
+ if (self.getAffiliation().ranks(MucOptions.Affiliation.ADMIN) &&
+ self.getAffiliation().outranks(user.getAffiliation())) {
+ if (mAdvancedMode) {
+ if (user.getAffiliation() == MucOptions.Affiliation.NONE) {
+ giveMembership.setVisible(true);
+ } else {
+ removeMembership.setVisible(true);
+ }
+ banFromConference.setVisible(true);
+ } else {
+ removeFromRoom.setVisible(true);
+ }
+ if (user.getAffiliation() != MucOptions.Affiliation.ADMIN) {
+ giveAdminPrivileges.setVisible(true);
+ } else {
+ removeAdminPrivileges.setVisible(true);
+ }
+ }
}
+
}
super.onCreateContextMenu(menu,v,menuInfo);
}
@@ -249,11 +314,50 @@ public class ConferenceDetailsActivity extends XmppActivity implements OnConvers
case R.id.start_conversation:
startConversation(mSelectedUser);
return true;
+ case R.id.give_admin_privileges:
+ xmppConnectionService.changeAffiliationInConference(mConversation,mSelectedUser.getJid(), MucOptions.Affiliation.ADMIN,this);
+ return true;
+ case R.id.give_membership:
+ xmppConnectionService.changeAffiliationInConference(mConversation,mSelectedUser.getJid(), MucOptions.Affiliation.MEMBER,this);
+ return true;
+ case R.id.remove_membership:
+ xmppConnectionService.changeAffiliationInConference(mConversation,mSelectedUser.getJid(), MucOptions.Affiliation.NONE,this);
+ return true;
+ case R.id.remove_admin_privileges:
+ xmppConnectionService.changeAffiliationInConference(mConversation,mSelectedUser.getJid(), MucOptions.Affiliation.MEMBER,this);
+ return true;
+ case R.id.remove_from_room:
+ removeFromRoom(mSelectedUser);
+ return true;
+ case R.id.ban_from_conference:
+ xmppConnectionService.changeAffiliationInConference(mConversation,mSelectedUser.getJid(), MucOptions.Affiliation.OUTCAST,this);
+ xmppConnectionService.changeRoleInConference(mConversation,mSelectedUser.getName(), MucOptions.Role.NONE,this);
+ return true;
default:
return super.onContextItemSelected(item);
}
}
+ private void removeFromRoom(final User user) {
+ if (mConversation.getMucOptions().membersOnly()) {
+ xmppConnectionService.changeAffiliationInConference(mConversation,user.getJid(), MucOptions.Affiliation.NONE,this);
+ xmppConnectionService.changeRoleInConference(mConversation,mSelectedUser.getName(), MucOptions.Role.NONE,ConferenceDetailsActivity.this);
+ } else {
+ AlertDialog.Builder builder = new AlertDialog.Builder(this);
+ builder.setTitle(R.string.ban_from_conference);
+ builder.setMessage(getString(R.string.removing_from_public_conference,user.getName()));
+ builder.setNegativeButton(R.string.cancel,null);
+ builder.setPositiveButton(R.string.ban_now,new DialogInterface.OnClickListener() {
+ @Override
+ public void onClick(DialogInterface dialog, int which) {
+ xmppConnectionService.changeAffiliationInConference(mConversation,user.getJid(), MucOptions.Affiliation.OUTCAST,ConferenceDetailsActivity.this);
+ xmppConnectionService.changeRoleInConference(mConversation,mSelectedUser.getName(), MucOptions.Role.NONE,ConferenceDetailsActivity.this);
+ }
+ });
+ builder.create().show();
+ }
+ }
+
protected void startConversation(User user) {
if (user.getJid() != null) {
Conversation conversation = xmppConnectionService.findOrCreateConversation(this.mConversation.getAccount(),user.getJid().toBareJid(),false);
@@ -290,39 +394,41 @@ public class ConferenceDetailsActivity extends XmppActivity implements OnConvers
this.mConversation = xmppConnectionService
.findConversationByUuid(uuid);
if (this.mConversation != null) {
- populateView();
+ updateView();
}
}
}
- private void populateView() {
+ private void updateView() {
+ final MucOptions mucOptions = mConversation.getMucOptions();
+ final User self = mucOptions.getSelf();
mAccountJid.setText(getString(R.string.using_account, mConversation
.getAccount().getJid().toBareJid()));
- mYourPhoto.setImageBitmap(avatarService().get(
- mConversation.getAccount(), getPixel(48)));
+ mYourPhoto.setImageBitmap(avatarService().get(mConversation.getAccount(), getPixel(48)));
setTitle(mConversation.getName());
mFullJid.setText(mConversation.getJid().toBareJid().toString());
- mYourNick.setText(mConversation.getMucOptions().getActualNick());
+ mYourNick.setText(mucOptions.getActualNick());
mRoleAffiliaton = (TextView) findViewById(R.id.muc_role);
- if (mConversation.getMucOptions().online()) {
+ if (mucOptions.online()) {
mMoreDetails.setVisibility(View.VISIBLE);
- User self = mConversation.getMucOptions().getSelf();
- switch (self.getAffiliation()) {
- case User.AFFILIATION_ADMIN:
- mRoleAffiliaton.setText(getReadableRole(self.getRole()) + " ("
- + getString(R.string.admin) + ")");
- break;
- case User.AFFILIATION_OWNER:
- mRoleAffiliaton.setText(getReadableRole(self.getRole()) + " ("
- + getString(R.string.owner) + ")");
- break;
- default:
- mRoleAffiliaton.setText(getReadableRole(self.getRole()));
- break;
+ final String status = getStatus(self);
+ if (status != null) {
+ mRoleAffiliaton.setVisibility(View.VISIBLE);
+ mRoleAffiliaton.setText(status);
+ } else {
+ mRoleAffiliaton.setVisibility(View.GONE);
+ }
+ if (mucOptions.membersOnly()) {
+ mConferenceType.setText(R.string.private_conference);
+ } else {
+ mConferenceType.setText(R.string.public_conference);
+ }
+ if (self.getAffiliation().ranks(MucOptions.Affiliation.OWNER)) {
+ mChangeConferenceSettingsButton.setVisibility(View.VISIBLE);
+ } else {
+ mChangeConferenceSettingsButton.setVisibility(View.GONE);
}
}
- this.users.clear();
- this.users.addAll(mConversation.getMucOptions().getUsers());
LayoutInflater inflater = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE);
membersView.removeAllViews();
for (final User user : mConversation.getMucOptions().getUsers()) {
@@ -337,36 +443,53 @@ public class ConferenceDetailsActivity extends XmppActivity implements OnConvers
});
registerForContextMenu(view);
view.setTag(user);
- TextView name = (TextView) view
- .findViewById(R.id.contact_display_name);
- TextView key = (TextView) view.findViewById(R.id.key);
- TextView role = (TextView) view.findViewById(R.id.contact_jid);
- if (user.getPgpKeyId() != 0) {
- key.setVisibility(View.VISIBLE);
- key.setOnClickListener(new OnClickListener() {
+ TextView tvDisplayName = (TextView) view.findViewById(R.id.contact_display_name);
+ TextView tvKey = (TextView) view.findViewById(R.id.key);
+ TextView tvStatus = (TextView) view.findViewById(R.id.contact_jid);
+ if (mAdvancedMode && user.getPgpKeyId() != 0) {
+ tvKey.setVisibility(View.VISIBLE);
+ tvKey.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
viewPgpKey(user);
}
});
- key.setText(OpenPgpUtils.convertKeyIdToHex(user.getPgpKeyId()));
+ tvKey.setText(OpenPgpUtils.convertKeyIdToHex(user.getPgpKeyId()));
}
Bitmap bm;
Contact contact = user.getContact();
if (contact != null) {
bm = avatarService().get(contact, getPixel(48));
- name.setText(contact.getDisplayName());
- role.setText(user.getName() + " \u2022 "
- + getReadableRole(user.getRole()));
+ tvDisplayName.setText(contact.getDisplayName());
+ tvStatus.setText(user.getName() + " \u2022 " + getStatus(user));
} else {
bm = avatarService().get(user.getName(), getPixel(48));
- name.setText(user.getName());
- role.setText(getReadableRole(user.getRole()));
+ tvDisplayName.setText(user.getName());
+ tvStatus.setText(getStatus(user));
+
}
ImageView iv = (ImageView) view.findViewById(R.id.contact_photo);
iv.setImageBitmap(bm);
membersView.addView(view);
+ if (mConversation.getMucOptions().canInvite()) {
+ mInviteButton.setVisibility(View.VISIBLE);
+ } else {
+ mInviteButton.setVisibility(View.GONE);
+ }
+ }
+ }
+
+ private String getStatus(User user) {
+ if (mAdvancedMode) {
+ StringBuilder builder = new StringBuilder();
+ builder.append(getString(user.getAffiliation().getResId()));
+ builder.append(" (");
+ builder.append(getString(user.getRole().getResId()));
+ builder.append(')');
+ return builder.toString();
+ } else {
+ return getString(user.getAffiliation().getResId());
}
}
@@ -396,4 +519,43 @@ public class ConferenceDetailsActivity extends XmppActivity implements OnConvers
}
}
}
+
+ @Override
+ public void onAffiliationChangedSuccessful(Jid jid) {
+
+ }
+
+ @Override
+ public void onAffiliationChangeFailed(Jid jid, int resId) {
+ displayToast(getString(resId,jid.toBareJid().toString()));
+ }
+
+ @Override
+ public void onRoleChangedSuccessful(String nick) {
+
+ }
+
+ @Override
+ public void onRoleChangeFailed(String nick, int resId) {
+ displayToast(getString(resId,nick));
+ }
+
+ @Override
+ public void onPushSucceeded() {
+ displayToast(getString(R.string.modified_conference_options));
+ }
+
+ @Override
+ public void onPushFailed() {
+ displayToast(getString(R.string.could_not_modify_conference_options));
+ }
+
+ private void displayToast(final String msg) {
+ runOnUiThread(new Runnable() {
+ @Override
+ public void run() {
+ Toast.makeText(ConferenceDetailsActivity.this,msg,Toast.LENGTH_SHORT).show();
+ }
+ });
+ }
}
diff --git a/src/main/java/eu/siacs/conversations/ui/ContactDetailsActivity.java b/src/main/java/eu/siacs/conversations/ui/ContactDetailsActivity.java
index 657ae75b..fda0c617 100644
--- a/src/main/java/eu/siacs/conversations/ui/ContactDetailsActivity.java
+++ b/src/main/java/eu/siacs/conversations/ui/ContactDetailsActivity.java
@@ -18,6 +18,7 @@ import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.view.View.OnClickListener;
+import android.widget.Button;
import android.widget.CheckBox;
import android.widget.CompoundButton;
import android.widget.CompoundButton.OnCheckedChangeListener;
@@ -40,6 +41,7 @@ import eu.siacs.conversations.services.XmppConnectionService.OnRosterUpdate;
import eu.siacs.conversations.utils.CryptoHelper;
import eu.siacs.conversations.utils.UIHelper;
import eu.siacs.conversations.xmpp.OnUpdateBlocklist;
+import eu.siacs.conversations.xmpp.XmppConnection;
import eu.siacs.conversations.xmpp.jid.InvalidJidException;
import eu.siacs.conversations.xmpp.jid.Jid;
@@ -51,9 +53,7 @@ public class ContactDetailsActivity extends XmppActivity implements OnAccountUpd
@Override
public void onClick(DialogInterface dialog, int which) {
- ContactDetailsActivity.this.xmppConnectionService
- .deleteContactOnServer(contact);
- ContactDetailsActivity.this.finish();
+ xmppConnectionService.deleteContactOnServer(contact);
}
};
private OnCheckedChangeListener mOnSendCheckedChange = new OnCheckedChangeListener() {
@@ -102,6 +102,7 @@ public class ContactDetailsActivity extends XmppActivity implements OnAccountUpd
private TextView lastseen;
private CheckBox send;
private CheckBox receive;
+ private Button addContactButton;
private QuickContactBadge badge;
private LinearLayout keys;
private LinearLayout tags;
@@ -142,6 +143,7 @@ public class ContactDetailsActivity extends XmppActivity implements OnAccountUpd
@Override
public void run() {
+ invalidateOptionsMenu();
populateView();
}
});
@@ -153,6 +155,7 @@ public class ContactDetailsActivity extends XmppActivity implements OnAccountUpd
@Override
public void run() {
+ invalidateOptionsMenu();
populateView();
}
});
@@ -188,6 +191,13 @@ public class ContactDetailsActivity extends XmppActivity implements OnAccountUpd
send = (CheckBox) findViewById(R.id.details_send_presence);
receive = (CheckBox) findViewById(R.id.details_receive_presence);
badge = (QuickContactBadge) findViewById(R.id.details_contact_badge);
+ addContactButton = (Button) findViewById(R.id.add_contact_button);
+ addContactButton.setOnClickListener(new OnClickListener() {
+ @Override
+ public void onClick(View view) {
+ showAddToRosterDialog(contact);
+ }
+ });
keys = (LinearLayout) findViewById(R.id.details_contact_keys);
tags = (LinearLayout) findViewById(R.id.tags);
if (getActionBar() != null) {
@@ -201,7 +211,7 @@ public class ContactDetailsActivity extends XmppActivity implements OnAccountUpd
@Override
public boolean onOptionsItemSelected(final MenuItem menuItem) {
- AlertDialog.Builder builder = new AlertDialog.Builder(this);
+ final AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder.setNegativeButton(getString(R.string.cancel), null);
switch (menuItem.getItemId()) {
case android.R.id.home:
@@ -237,59 +247,96 @@ public class ContactDetailsActivity extends XmppActivity implements OnAccountUpd
startActivity(intent);
}
break;
+ case R.id.action_block:
+ BlockContactDialog.show(this, xmppConnectionService, contact);
+ break;
+ case R.id.action_unblock:
+ BlockContactDialog.show(this, xmppConnectionService, contact);
+ break;
}
return super.onOptionsItemSelected(menuItem);
}
@Override
- public boolean onCreateOptionsMenu(Menu menu) {
+ public boolean onCreateOptionsMenu(final Menu menu) {
getMenuInflater().inflate(R.menu.contact_details, menu);
+ MenuItem block = menu.findItem(R.id.action_block);
+ MenuItem unblock = menu.findItem(R.id.action_unblock);
+ MenuItem edit = menu.findItem(R.id.action_edit_contact);
+ MenuItem delete = menu.findItem(R.id.action_delete_contact);
+ final XmppConnection connection = contact.getAccount().getXmppConnection();
+ if (connection != null && connection.getFeatures().blocking()) {
+ if (this.contact.isBlocked()) {
+ menu.findItem(R.id.action_block).setVisible(false);
+ } else {
+ menu.findItem(R.id.action_unblock).setVisible(false);
+ }
+ } else {
+ menu.findItem(R.id.action_unblock).setVisible(false);
+ menu.findItem(R.id.action_block).setVisible(false);
+ }
+ if (!contact.showInRoster()) {
+ edit.setVisible(false);
+ delete.setVisible(false);
+ }
return true;
}
private void populateView() {
- send.setOnCheckedChangeListener(null);
- receive.setOnCheckedChangeListener(null);
setTitle(contact.getDisplayName());
- if (contact.getOption(Contact.Options.FROM)) {
- send.setText(R.string.send_presence_updates);
- send.setChecked(true);
- } else if (contact
- .getOption(Contact.Options.PENDING_SUBSCRIPTION_REQUEST)) {
- send.setChecked(false);
- send.setText(R.string.send_presence_updates);
- } else {
- send.setText(R.string.preemptively_grant);
- if (contact.getOption(Contact.Options.PREEMPTIVE_GRANT)) {
+ if (contact.showInRoster()) {
+ send.setVisibility(View.VISIBLE);
+ receive.setVisibility(View.VISIBLE);
+ addContactButton.setVisibility(View.GONE);
+ send.setOnCheckedChangeListener(null);
+ receive.setOnCheckedChangeListener(null);
+
+ if (contact.getOption(Contact.Options.FROM)) {
+ send.setText(R.string.send_presence_updates);
send.setChecked(true);
- } else {
+ } else if (contact.getOption(Contact.Options.PENDING_SUBSCRIPTION_REQUEST)) {
send.setChecked(false);
+ send.setText(R.string.send_presence_updates);
+ } else {
+ send.setText(R.string.preemptively_grant);
+ if (contact.getOption(Contact.Options.PREEMPTIVE_GRANT)) {
+ send.setChecked(true);
+ } else {
+ send.setChecked(false);
+ }
}
- }
- if (contact.getOption(Contact.Options.TO)) {
- receive.setText(R.string.receive_presence_updates);
- receive.setChecked(true);
- } else {
- receive.setText(R.string.ask_for_presence_updates);
- if (contact.getOption(Contact.Options.ASKING)) {
+ if (contact.getOption(Contact.Options.TO)) {
+ receive.setText(R.string.receive_presence_updates);
receive.setChecked(true);
} else {
- receive.setChecked(false);
+ receive.setText(R.string.ask_for_presence_updates);
+ if (contact.getOption(Contact.Options.ASKING)) {
+ receive.setChecked(true);
+ } else {
+ receive.setChecked(false);
+ }
}
- }
- if (contact.getAccount().getStatus() == Account.State.ONLINE) {
- receive.setEnabled(true);
- send.setEnabled(true);
+ if (contact.getAccount().isOnlineAndConnected()) {
+ receive.setEnabled(true);
+ send.setEnabled(true);
+ } else {
+ receive.setEnabled(false);
+ send.setEnabled(false);
+ }
+
+ send.setOnCheckedChangeListener(this.mOnSendCheckedChange);
+ receive.setOnCheckedChangeListener(this.mOnReceiveCheckedChange);
} else {
- receive.setEnabled(false);
- send.setEnabled(false);
+ addContactButton.setVisibility(View.VISIBLE);
+ send.setVisibility(View.GONE);
+ receive.setVisibility(View.GONE);
}
- send.setOnCheckedChangeListener(this.mOnSendCheckedChange);
- receive.setOnCheckedChangeListener(this.mOnReceiveCheckedChange);
-
- lastseen.setText(UIHelper.lastseen(getApplicationContext(),
- contact.lastseen.time));
+ if (contact.isBlocked() && !this.showDynamicTags) {
+ lastseen.setText(R.string.contact_blocked);
+ } else {
+ lastseen.setText(UIHelper.lastseen(getApplicationContext(), contact.lastseen.time));
+ }
if (contact.getPresences().size() > 1) {
contactJidTv.setText(contact.getJid() + " ("
@@ -424,6 +471,7 @@ public class ContactDetailsActivity extends XmppActivity implements OnAccountUpd
@Override
public void run() {
+ invalidateOptionsMenu();
populateView();
}
});
diff --git a/src/main/java/eu/siacs/conversations/ui/ConversationActivity.java b/src/main/java/eu/siacs/conversations/ui/ConversationActivity.java
index 5cfc1116..0a55c6b5 100644
--- a/src/main/java/eu/siacs/conversations/ui/ConversationActivity.java
+++ b/src/main/java/eu/siacs/conversations/ui/ConversationActivity.java
@@ -9,8 +9,8 @@ import android.content.DialogInterface;
import android.content.DialogInterface.OnClickListener;
import android.content.Intent;
import android.content.IntentSender.SendIntentException;
-import android.media.MediaActionSound;
import android.net.Uri;
+import android.os.Build;
import android.os.Bundle;
import android.os.SystemClock;
import android.provider.MediaStore;
@@ -49,8 +49,11 @@ import eu.siacs.conversations.xmpp.OnUpdateBlocklist;
public class ConversationActivity extends XmppActivity
implements OnAccountUpdate, OnConversationUpdate, OnRosterUpdate, OnUpdateBlocklist {
+ public static final String ACTION_DOWNLOAD = "eu.siacs.conversations.action.DOWNLOAD";
+
public static final String VIEW_CONVERSATION = "viewConversation";
public static final String CONVERSATION = "conversationUuid";
+ public static final String MESSAGE = "messageUuid";
public static final String TEXT = "text";
public static final String NICK = "nick";
@@ -83,11 +86,6 @@ public class ConversationActivity extends XmppActivity
private boolean mActivityPaused = false;
-
- public List<Conversation> getConversationList() {
- return this.conversationList;
- }
-
public Conversation getSelectedConversation() {
return this.mSelectedConversation;
}
@@ -139,7 +137,7 @@ public class ConversationActivity extends XmppActivity
}
@Override
- protected void onCreate(Bundle savedInstanceState) {
+ protected void onCreate(final Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
if (savedInstanceState != null) {mOpenConverstaion = savedInstanceState.getString(
STATE_OPEN_CONVERSATION, null);
@@ -176,6 +174,7 @@ public class ConversationActivity extends XmppActivity
ConversationActivity.this.mConversationFragment.reInit(getSelectedConversation());
}
hideConversationsOverview();
+ openConversation();
}
});
mContentView = findViewById(R.id.content_view_spl);
@@ -260,11 +259,16 @@ public class ConversationActivity extends XmppActivity
xmppConnectionService.getNotificationService().setOpenConversation(conversation);
sendReadMarkerIfNecessary(conversation);
}
+ listAdapter.notifyDataSetChanged();
}
public void sendReadMarkerIfNecessary(final Conversation conversation) {
- if (!mActivityPaused && !conversation.isRead()) {
- xmppConnectionService.sendReadMarker(conversation);
+ if (!mActivityPaused && conversation != null) {
+ if (!conversation.isRead()) {
+ xmppConnectionService.sendReadMarker(conversation);
+ } else {
+ xmppConnectionService.markRead(conversation);
+ }
}
}
@@ -281,11 +285,8 @@ public class ConversationActivity extends XmppActivity
final MenuItem menuInviteContact = menu.findItem(R.id.action_invite);
final MenuItem menuMute = menu.findItem(R.id.action_mute);
final MenuItem menuUnmute = menu.findItem(R.id.action_unmute);
- final MenuItem menuBlock = menu.findItem(R.id.action_block);
- final MenuItem menuUnblock = menu.findItem(R.id.action_unblock);
- if (isConversationsOverviewVisable()
- && isConversationsOverviewHideable()) {
+ if (isConversationsOverviewVisable() && isConversationsOverviewHideable()) {
menuArchive.setVisible(false);
menuMucDetails.setVisible(false);
menuContactDetails.setVisible(false);
@@ -295,33 +296,24 @@ public class ConversationActivity extends XmppActivity
menuClearHistory.setVisible(false);
menuMute.setVisible(false);
menuUnmute.setVisible(false);
- menuBlock.setVisible(false);
- menuUnblock.setVisible(false);
} else {
menuAdd.setVisible(!isConversationsOverviewHideable());
if (this.getSelectedConversation() != null) {
if (this.getSelectedConversation().getLatestMessage()
.getEncryption() != Message.ENCRYPTION_NONE) {
- menuSecure.setIcon(R.drawable.ic_action_secure);
- }
+ if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
+ menuSecure.setIcon(R.drawable.ic_lock_outline_white_48dp);
+ } else {
+ menuSecure.setIcon(R.drawable.ic_action_secure);
+ }
+ }
if (this.getSelectedConversation().getMode() == Conversation.MODE_MULTI) {
menuContactDetails.setVisible(false);
menuAttach.setVisible(false);
- menuBlock.setVisible(false);
- menuUnblock.setVisible(false);
+ menuInviteContact.setVisible(getSelectedConversation().getMucOptions().canInvite());
} else {
menuMucDetails.setVisible(false);
- menuInviteContact.setTitle(R.string.conference_with);
- if (this.getSelectedConversation().isBlocked()) {
- menuBlock.setVisible(false);
- } else {
- menuUnblock.setVisible(false);
- }
final Account account = this.getSelectedConversation().getAccount();
- if (!(account.isOnlineAndConnected() && account.getXmppConnection().getFeatures().blocking())) {
- menuBlock.setVisible(false);
- menuUnblock.setVisible(false);
- }
}
if (this.getSelectedConversation().isMuted()) {
menuMute.setVisible(false);
@@ -447,12 +439,7 @@ public class ConversationActivity extends XmppActivity
this.endConversation(getSelectedConversation());
break;
case R.id.action_contact_details:
- Contact contact = this.getSelectedConversation().getContact();
- if (contact.showInRoster()) {
- switchToContactDetails(contact);
- } else {
- showAddToRosterDialog(getSelectedConversation());
- }
+ switchToContactDetails(getSelectedConversation().getContact());
break;
case R.id.action_muc_details:
Intent intent = new Intent(this,
@@ -492,7 +479,6 @@ public class ConversationActivity extends XmppActivity
}
public void endConversation(Conversation conversation) {
- conversation.setStatus(Conversation.STATUS_ARCHIVED);
showConversationsOverview();
xmppConnectionService.archiveConversation(conversation);
if (conversationList.size() > 0) {
@@ -542,25 +528,25 @@ public class ConversationActivity extends XmppActivity
}
attachFilePopup.setOnMenuItemClickListener(new OnMenuItemClickListener() {
- @Override
- public boolean onMenuItemClick(MenuItem item) {
- switch (item.getItemId()) {
- case R.id.attach_choose_picture:
- attachFile(ATTACHMENT_CHOICE_CHOOSE_IMAGE);
- break;
- case R.id.attach_take_picture:
- attachFile(ATTACHMENT_CHOICE_TAKE_PHOTO);
- break;
- case R.id.attach_choose_file:
- attachFile(ATTACHMENT_CHOICE_CHOOSE_FILE);
- break;
- case R.id.attach_record_voice:
- attachFile(ATTACHMENT_CHOICE_RECORD_VOICE);
- break;
- }
- return false;
+ @Override
+ public boolean onMenuItemClick(MenuItem item) {
+ switch (item.getItemId()) {
+ case R.id.attach_choose_picture:
+ attachFile(ATTACHMENT_CHOICE_CHOOSE_IMAGE);
+ break;
+ case R.id.attach_take_picture:
+ attachFile(ATTACHMENT_CHOICE_TAKE_PHOTO);
+ break;
+ case R.id.attach_choose_file:
+ attachFile(ATTACHMENT_CHOICE_CHOOSE_FILE);
+ break;
+ case R.id.attach_record_voice:
+ attachFile(ATTACHMENT_CHOICE_RECORD_VOICE);
+ break;
}
- });
+ return false;
+ }
+ });
attachFilePopup.show();
}
@@ -756,14 +742,20 @@ public class ConversationActivity extends XmppActivity
@Override
public void onResume() {
super.onResume();
- int theme = findTheme();
- if (this.mTheme != theme) {
+ final int theme = findTheme();
+ final boolean usingEnterKey = usingEnterKey();
+ if (this.mTheme != theme || usingEnterKey != mUsingEnterKey) {
recreate();
}
this.mActivityPaused = false;
if (this.xmppConnectionServiceBound) {
this.xmppConnectionService.getNotificationService().setIsInForeground(true);
}
+
+ if (!isConversationsOverviewVisable() || !isConversationsOverviewHideable()) {
+ sendReadMarkerIfNecessary(getSelectedConversation());
+ }
+
}
@Override
@@ -790,11 +782,9 @@ public class ConversationActivity extends XmppActivity
} else if (conversationList.size() <= 0) {
startActivity(new Intent(this, StartConversationActivity.class));
finish();
- } else if (getIntent() != null
- && VIEW_CONVERSATION.equals(getIntent().getType())) {
+ } else if (getIntent() != null && VIEW_CONVERSATION.equals(getIntent().getType())) {
handleViewConversationIntent(getIntent());
- } else if (mOpenConverstaion != null) {
- selectConversationByUuid(mOpenConverstaion);
+ } else if (selectConversationByUuid(mOpenConverstaion)) {
if (mPanelOpen) {
showConversationsOverview();
} else {
@@ -825,30 +815,43 @@ public class ConversationActivity extends XmppActivity
setIntent(new Intent());
}
- private void handleViewConversationIntent(Intent intent) {
- String uuid = (String) intent.getExtras().get(CONVERSATION);
- String text = intent.getExtras().getString(TEXT, "");
- String nick = intent.getExtras().getString(NICK,null);
- selectConversationByUuid(uuid);
- this.mConversationFragment.reInit(getSelectedConversation());
- if (nick!=null) {
- this.mConversationFragment.highlightInConference(nick);
- } else {
- this.mConversationFragment.appendText(text);
- }
- hideConversationsOverview();
- openConversation();
- if (mContentView instanceof SlidingPaneLayout) {
- updateActionBarTitle(true); //fixes bug where slp isn't properly closed yet
+ private void handleViewConversationIntent(final Intent intent) {
+ final String uuid = (String) intent.getExtras().get(CONVERSATION);
+ final String downloadUuid = (String) intent.getExtras().get(MESSAGE);
+ final String text = intent.getExtras().getString(TEXT, "");
+ final String nick = intent.getExtras().getString(NICK, null);
+ if (selectConversationByUuid(uuid)) {
+ this.mConversationFragment.reInit(getSelectedConversation());
+ if (nick != null) {
+ this.mConversationFragment.highlightInConference(nick);
+ } else {
+ this.mConversationFragment.appendText(text);
+ }
+ hideConversationsOverview();
+ openConversation();
+ if (mContentView instanceof SlidingPaneLayout) {
+ updateActionBarTitle(true); //fixes bug where slp isn't properly closed yet
+ }
+ if (downloadUuid != null) {
+ final Message message = mSelectedConversation.findMessageWithFileAndUuid(downloadUuid);
+ if (message != null) {
+ mConversationFragment.messageListAdapter.startDownloadable(message);
+ }
+ }
}
}
- private void selectConversationByUuid(String uuid) {
+ private boolean selectConversationByUuid(String uuid) {
+ if (uuid == null) {
+ return false;
+ }
for (Conversation aConversationList : conversationList) {
if (aConversationList.getUuid().equals(uuid)) {
setSelectedConversation(aConversationList);
+ return true;
}
}
+ return false;
}
@Override
@@ -1050,10 +1053,10 @@ public class ConversationActivity extends XmppActivity
@Override
public void OnUpdateBlocklist(Status status) {
- invalidateOptionsMenu();
runOnUiThread(new Runnable() {
@Override
public void run() {
+ invalidateOptionsMenu();
ConversationActivity.this.mConversationFragment.updateMessages();
}
});
@@ -1063,7 +1066,7 @@ public class ConversationActivity extends XmppActivity
xmppConnectionService.sendUnblockRequest(conversation);
}
- public void blockConversation(final Blockable conversation) {
- xmppConnectionService.sendBlockRequest(conversation);
+ public boolean enterIsSend() {
+ return getPreferences().getBoolean("enter_is_send",false);
}
}
diff --git a/src/main/java/eu/siacs/conversations/ui/ConversationFragment.java b/src/main/java/eu/siacs/conversations/ui/ConversationFragment.java
index 93a4cc7e..80ac9da1 100644
--- a/src/main/java/eu/siacs/conversations/ui/ConversationFragment.java
+++ b/src/main/java/eu/siacs/conversations/ui/ConversationFragment.java
@@ -9,6 +9,7 @@ import android.content.Intent;
import android.content.IntentSender;
import android.content.IntentSender.SendIntentException;
import android.os.Bundle;
+import android.text.InputType;
import android.view.ContextMenu;
import android.view.ContextMenu.ContextMenuInfo;
import android.view.Gravity;
@@ -33,6 +34,7 @@ import android.widget.Toast;
import net.java.otr4j.session.SessionStatus;
+import java.net.URLConnection;
import java.util.ArrayList;
import java.util.List;
import java.util.NoSuchElementException;
@@ -296,6 +298,15 @@ public class ConversationFragment extends Fragment {
default:
break;
}
+ getActivity().invalidateOptionsMenu();
+ }
+ }
+
+ private void setupIme() {
+ if (((ConversationActivity)getActivity()).usingEnterKey()) {
+ mEditMessage.setInputType(mEditMessage.getInputType() & (~InputType.TYPE_TEXT_VARIATION_SHORT_MESSAGE));
+ } else {
+ mEditMessage.setInputType(mEditMessage.getInputType() | InputType.TYPE_TEXT_VARIATION_SHORT_MESSAGE);
}
}
@@ -305,6 +316,7 @@ public class ConversationFragment extends Fragment {
final View view = inflater.inflate(R.layout.fragment_conversation,
container, false);
mEditMessage = (EditMessage) view.findViewById(R.id.textinput);
+ setupIme();
mEditMessage.setOnClickListener(new OnClickListener() {
@Override
@@ -316,8 +328,13 @@ public class ConversationFragment extends Fragment {
mEditMessage.setOnEnterPressedListener(new OnEnterPressed() {
@Override
- public void onEnterPressed() {
- sendMessage();
+ public boolean onEnterPressed() {
+ if (activity.enterIsSend()) {
+ sendMessage();
+ return true;
+ } else {
+ return false;
+ }
}
});
@@ -346,14 +363,7 @@ public class ConversationFragment extends Fragment {
}
}
} else {
- Contact contact = message.getConversation()
- .getContact();
- if (contact.showInRoster()) {
- activity.switchToContactDetails(contact);
- } else {
- activity.showAddToRosterDialog(message
- .getConversation());
- }
+ activity.switchToContactDetails(message.getContact());
}
} else {
Account account = message.getConversation().getAccount();
@@ -403,7 +413,7 @@ public class ConversationFragment extends Fragment {
activity.getMenuInflater().inflate(R.menu.message_context, menu);
menu.setHeaderTitle(R.string.message_options);
MenuItem copyText = menu.findItem(R.id.copy_text);
- MenuItem shareImage = menu.findItem(R.id.share_image);
+ MenuItem shareWith = menu.findItem(R.id.share_with);
MenuItem sendAgain = menu.findItem(R.id.send_again);
MenuItem copyUrl = menu.findItem(R.id.copy_url);
MenuItem downloadImage = menu.findItem(R.id.download_image);
@@ -411,33 +421,36 @@ public class ConversationFragment extends Fragment {
if (m.getType() != Message.TYPE_TEXT || m.getDownloadable() != null) {
copyText.setVisible(false);
}
- if (m.getType() != Message.TYPE_IMAGE || m.getDownloadable() != null) {
- shareImage.setVisible(false);
- }
+ if (m.getType() == Message.TYPE_TEXT
+ || m.getType() == Message.TYPE_PRIVATE
+ || m.getDownloadable() != null) {
+ shareWith.setVisible(false);
+ }
if (m.getStatus() != Message.STATUS_SEND_FAILED) {
sendAgain.setVisible(false);
}
if ((m.getType() != Message.TYPE_IMAGE && m.getDownloadable() == null)
|| m.getImageParams().url == null) {
copyUrl.setVisible(false);
- }
+ }
if (m.getType() != Message.TYPE_TEXT
|| m.getDownloadable() != null
|| !m.bodyContainsDownloadable()) {
downloadImage.setVisible(false);
- }
+ }
if (!((m.getDownloadable() != null && !(m.getDownloadable() instanceof DownloadablePlaceholder))
- || (m.isFileOrImage() && m.getStatus() == Message.STATUS_WAITING))) {
+ || (m.isFileOrImage() && (m.getStatus() == Message.STATUS_WAITING
+ || m.getStatus() == Message.STATUS_OFFERED)))) {
cancelTransmission.setVisible(false);
- }
+ }
}
}
@Override
public boolean onContextItemSelected(MenuItem item) {
switch (item.getItemId()) {
- case R.id.share_image:
- shareImage(selectedMessage);
+ case R.id.share_with:
+ shareWith(selectedMessage);
return true;
case R.id.copy_text:
copyText(selectedMessage);
@@ -459,16 +472,20 @@ public class ConversationFragment extends Fragment {
}
}
- private void shareImage(Message message) {
+ private void shareWith(Message message) {
Intent shareIntent = new Intent();
shareIntent.setAction(Intent.ACTION_SEND);
shareIntent.putExtra(Intent.EXTRA_STREAM,
activity.xmppConnectionService.getFileBackend()
.getJingleFileUri(message));
shareIntent.setFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
- shareIntent.setType("image/webp");
- activity.startActivity(Intent.createChooser(shareIntent,
- getText(R.string.share_with)));
+ String path = message.getRelativeFilePath();
+ String mime = path == null ? null :URLConnection.guessContentTypeFromName(path);
+ if (mime == null) {
+ mime = "image/webp";
+ }
+ shareIntent.setType(mime);
+ activity.startActivity(Intent.createChooser(shareIntent,getText(R.string.share_with)));
}
private void copyText(Message message) {
@@ -595,15 +612,6 @@ public class ConversationFragment extends Fragment {
}
}
});
- } else if (this.conversation.isMuted()) {
- showSnackbar(R.string.notifications_disabled, R.string.enable,
- new OnClickListener() {
-
- @Override
- public void onClick(final View v) {
- activity.unmuteConversation(conversation);
- }
- });
} else if (!contact.showInRoster()
&& contact
.getOption(Contact.Options.PENDING_SUBSCRIPTION_REQUEST)) {
@@ -650,9 +658,18 @@ public class ConversationFragment extends Fragment {
default:
break;
}
- }
+ } else if (this.conversation.isMuted()) {
+ showSnackbar(R.string.notifications_disabled, R.string.enable,
+ new OnClickListener() {
+
+ @Override
+ public void onClick(final View v) {
+ activity.unmuteConversation(conversation);
+ }
+ });
+ }
conversation.populateWithMessages(ConversationFragment.this.messageList);
- for (Message message : this.messageList) {
+ for (final Message message : this.messageList) {
if (message.getEncryption() == Message.ENCRYPTION_PGP
&& (message.getStatus() == Message.STATUS_RECEIVED || message
.getStatus() >= Message.STATUS_SEND)
@@ -951,7 +968,4 @@ public class ConversationFragment extends Fragment {
this.mEditMessage.append(text);
}
- public void clearInputField() {
- this.mEditMessage.setText("");
- }
}
diff --git a/src/main/java/eu/siacs/conversations/ui/EditMessage.java b/src/main/java/eu/siacs/conversations/ui/EditMessage.java
index f8302050..5090bbf5 100644
--- a/src/main/java/eu/siacs/conversations/ui/EditMessage.java
+++ b/src/main/java/eu/siacs/conversations/ui/EditMessage.java
@@ -21,9 +21,12 @@ public class EditMessage extends EditText {
public boolean onKeyDown(int keyCode, KeyEvent event) {
if (keyCode == KeyEvent.KEYCODE_ENTER) {
if (mOnEnterPressed != null) {
- mOnEnterPressed.onEnterPressed();
+ if (mOnEnterPressed.onEnterPressed()) {
+ return true;
+ } else {
+ return super.onKeyDown(keyCode, event);
+ }
}
- return true;
}
return super.onKeyDown(keyCode, event);
}
@@ -33,7 +36,7 @@ public class EditMessage extends EditText {
}
public interface OnEnterPressed {
- public void onEnterPressed();
+ public boolean onEnterPressed();
}
}
diff --git a/src/main/java/eu/siacs/conversations/ui/PublishProfilePictureActivity.java b/src/main/java/eu/siacs/conversations/ui/PublishProfilePictureActivity.java
index 10ee0cd5..2ba0b090 100644
--- a/src/main/java/eu/siacs/conversations/ui/PublishProfilePictureActivity.java
+++ b/src/main/java/eu/siacs/conversations/ui/PublishProfilePictureActivity.java
@@ -11,6 +11,8 @@ import android.view.View.OnLongClickListener;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.TextView;
+import android.widget.Toast;
+
import eu.siacs.conversations.R;
import eu.siacs.conversations.entities.Account;
import eu.siacs.conversations.utils.PhoneHelper;
@@ -31,13 +33,18 @@ public class PublishProfilePictureActivity extends XmppActivity {
private Uri avatarUri;
private Uri defaultUri;
+ private OnLongClickListener backToDefaultListener = new OnLongClickListener() {
+ @Override
+ public boolean onLongClick(View v) {
+ avatarUri = defaultUri;
+ loadImageIntoPreview(defaultUri);
+ return true;
+ }
+ };
private Account account;
-
private boolean support = false;
-
private boolean mInitialAccountSetup;
-
private UiCallback<Avatar> avatarPublication = new UiCallback<Avatar>() {
@Override
@@ -50,6 +57,9 @@ public class PublishProfilePictureActivity extends XmppActivity {
startActivity(new Intent(getApplicationContext(),
StartConversationActivity.class));
}
+ Toast.makeText(PublishProfilePictureActivity.this,
+ R.string.avatar_has_been_published,
+ Toast.LENGTH_SHORT).show();
finish();
}
});
@@ -75,16 +85,6 @@ public class PublishProfilePictureActivity extends XmppActivity {
}
};
- private OnLongClickListener backToDefaultListener = new OnLongClickListener() {
-
- @Override
- public boolean onLongClick(View v) {
- avatarUri = defaultUri;
- loadImageIntoPreview(defaultUri);
- return true;
- }
- };
-
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
diff --git a/src/main/java/eu/siacs/conversations/ui/SettingsActivity.java b/src/main/java/eu/siacs/conversations/ui/SettingsActivity.java
index 352652de..136108ef 100644
--- a/src/main/java/eu/siacs/conversations/ui/SettingsActivity.java
+++ b/src/main/java/eu/siacs/conversations/ui/SettingsActivity.java
@@ -75,6 +75,15 @@ public class SettingsActivity extends XmppActivity implements
case "keep_foreground_service":
xmppConnectionService.toggleForegroundService();
break;
+ case "confirm_messages":
+ if (xmppConnectionServiceBound) {
+ for (Account account : xmppConnectionService.getAccounts()) {
+ if (!account.isOptionSet(Account.OPTION_DISABLED)) {
+ xmppConnectionService.sendPresence(account);
+ }
+ }
+ }
+ break;
}
Settings.synchronizeSettingsClassWithPreferences(getPreferences(), name);
}
diff --git a/src/main/java/eu/siacs/conversations/ui/ShareWithActivity.java b/src/main/java/eu/siacs/conversations/ui/ShareWithActivity.java
index 5e770376..6be238dc 100644
--- a/src/main/java/eu/siacs/conversations/ui/ShareWithActivity.java
+++ b/src/main/java/eu/siacs/conversations/ui/ShareWithActivity.java
@@ -134,14 +134,10 @@ public class ShareWithActivity extends XmppActivity {
@Override
public void onStart() {
final String type = getIntent().getType();
- if (type != null && !type.startsWith("text/")) {
- this.share.uri = (Uri) getIntent().getParcelableExtra(Intent.EXTRA_STREAM);
- try {
- this.share.image = type.startsWith("image/")
- || URLConnection.guessContentTypeFromName(this.share.uri.toString()).startsWith("image/");
- } catch (final StringIndexOutOfBoundsException ignored) {
- this.share.image = false;
- }
+ final Uri uri = getIntent().getParcelableExtra(Intent.EXTRA_STREAM);
+ if (type != null && uri != null && !type.equalsIgnoreCase("text/plain")) {
+ this.share.uri = uri;
+ this.share.image = type.startsWith("image/") || isImage(uri);
} else {
this.share.text = getIntent().getStringExtra(Intent.EXTRA_TEXT);
}
@@ -151,6 +147,15 @@ public class ShareWithActivity extends XmppActivity {
super.onStart();
}
+ protected boolean isImage(Uri uri) {
+ try {
+ String guess = URLConnection.guessContentTypeFromName(uri.toString());
+ return (guess != null && guess.startsWith("image/"));
+ } catch (final StringIndexOutOfBoundsException ignored) {
+ return false;
+ }
+ }
+
@Override
void onBackendConnected() {
if (xmppConnectionServiceBound && share != null
diff --git a/src/main/java/eu/siacs/conversations/ui/StartConversationActivity.java b/src/main/java/eu/siacs/conversations/ui/StartConversationActivity.java
index 209c0a7b..ff46ffd8 100644
--- a/src/main/java/eu/siacs/conversations/ui/StartConversationActivity.java
+++ b/src/main/java/eu/siacs/conversations/ui/StartConversationActivity.java
@@ -59,6 +59,7 @@ import eu.siacs.conversations.entities.Bookmark;
import eu.siacs.conversations.entities.Contact;
import eu.siacs.conversations.entities.Conversation;
import eu.siacs.conversations.entities.ListItem;
+import eu.siacs.conversations.entities.Presences;
import eu.siacs.conversations.services.XmppConnectionService.OnRosterUpdate;
import eu.siacs.conversations.ui.adapter.KnownHostsAdapter;
import eu.siacs.conversations.ui.adapter.ListItemAdapter;
@@ -114,6 +115,7 @@ public class StartConversationActivity extends XmppActivity implements OnRosterU
return true;
}
};
+ private boolean mHideOfflineContacts = false;
private TabListener mTabListener = new TabListener() {
@Override
@@ -159,7 +161,6 @@ public class StartConversationActivity extends XmppActivity implements OnRosterU
}
};
private MenuItem mMenuSearchView;
- private String mInitialJid;
private ListItemAdapter.OnTagClickedListener mOnTagClickedListener = new ListItemAdapter.OnTagClickedListener() {
@Override
public void onTagClicked(String tag) {
@@ -171,6 +172,7 @@ public class StartConversationActivity extends XmppActivity implements OnRosterU
}
}
};
+ private String mInitialJid;
@Override
public void onRosterUpdate() {
@@ -245,6 +247,8 @@ public class StartConversationActivity extends XmppActivity implements OnRosterU
}
});
+ this.mHideOfflineContacts = getPreferences().getBoolean("hide_offline", false);
+
}
protected void openConversationForContact(int position) {
@@ -448,8 +452,7 @@ public class StartConversationActivity extends XmppActivity implements OnRosterU
if (account.hasBookmarkFor(conferenceJid)) {
jid.setError(getString(R.string.bookmark_already_exists));
} else {
- final Bookmark bookmark = new Bookmark(account,
- conferenceJid);
+ final Bookmark bookmark = new Bookmark(account,conferenceJid.toBareJid());
bookmark.setAutojoin(true);
account.getBookmarks().add(bookmark);
xmppConnectionService
@@ -497,10 +500,10 @@ public class StartConversationActivity extends XmppActivity implements OnRosterU
public boolean onCreateOptionsMenu(Menu menu) {
this.mOptionsMenu = menu;
getMenuInflater().inflate(R.menu.start_conversation, menu);
- MenuItem menuCreateContact = menu
- .findItem(R.id.action_create_contact);
- MenuItem menuCreateConference = menu
- .findItem(R.id.action_join_conference);
+ MenuItem menuCreateContact = menu.findItem(R.id.action_create_contact);
+ MenuItem menuCreateConference = menu.findItem(R.id.action_join_conference);
+ MenuItem menuHideOffline = menu.findItem(R.id.action_hide_offline);
+ menuHideOffline.setChecked(this.mHideOfflineContacts);
mMenuSearchView = menu.findItem(R.id.action_search);
mMenuSearchView.setOnActionExpandListener(mOnActionExpandListener);
View mSearchView = mMenuSearchView.getActionView();
@@ -532,6 +535,13 @@ public class StartConversationActivity extends XmppActivity implements OnRosterU
case R.id.action_scan_qr_code:
new IntentIntegrator(this).initiateScan();
return true;
+ case R.id.action_hide_offline:
+ mHideOfflineContacts = !item.isChecked();
+ getPreferences().edit().putBoolean("hide_offline", mHideOfflineContacts).commit();
+ if (mSearchEditText != null) {
+ filter(mSearchEditText.getText().toString());
+ }
+ invalidateOptionsMenu();
}
return super.onOptionsItemSelected(item);
}
@@ -668,7 +678,9 @@ public class StartConversationActivity extends XmppActivity implements OnRosterU
for (Account account : xmppConnectionService.getAccounts()) {
if (account.getStatus() != Account.State.DISABLED) {
for (Contact contact : account.getRoster().getContacts()) {
- if (contact.showInRoster() && contact.match(needle)) {
+ if (contact.showInRoster() && contact.match(needle)
+ && (!this.mHideOfflineContacts
+ || contact.getPresences().getMostAvailableStatus() < Presences.OFFLINE)) {
this.contacts.add(contact);
}
}
diff --git a/src/main/java/eu/siacs/conversations/ui/XmppActivity.java b/src/main/java/eu/siacs/conversations/ui/XmppActivity.java
index 535aa6a5..1f1af09c 100644
--- a/src/main/java/eu/siacs/conversations/ui/XmppActivity.java
+++ b/src/main/java/eu/siacs/conversations/ui/XmppActivity.java
@@ -2,6 +2,7 @@ package eu.siacs.conversations.ui;
import android.annotation.SuppressLint;
import android.annotation.TargetApi;
+import android.app.ActionBar;
import android.app.Activity;
import android.app.AlertDialog;
import android.app.AlertDialog.Builder;
@@ -97,6 +98,7 @@ public abstract class XmppActivity extends Activity {
private DisplayMetrics metrics;
protected int mTheme;
+ protected boolean mUsingEnterKey = false;
protected interface OnValueEdited {
public void onValueEdited(String value);
@@ -300,13 +302,23 @@ public abstract class XmppActivity extends Activity {
mColorOrange = getResources().getColor(R.color.orange);
mColorGreen = getResources().getColor(R.color.green);
mPrimaryColor = getResources().getColor(R.color.primary);
- mSecondaryBackgroundColor = getResources().getColor(
- R.color.secondarybackground);
+ mSecondaryBackgroundColor = getResources().getColor(R.color.secondarybackground);
this.mTheme = findTheme();
setTheme(this.mTheme);
+ this.mUsingEnterKey = usingEnterKey();
mUseSubject = getPreferences().getBoolean("use_subject", true);
+
Settings.initSettingsClassWithPreferences(getPreferences());
- }
+
+ final ActionBar ab = getActionBar();
+ if (ab!=null) {
+ ab.setDisplayHomeAsUpEnabled(true);
+ }
+ }
+
+ protected boolean usingEnterKey() {
+ return getPreferences().getBoolean("display_enter_key", false);
+ }
protected SharedPreferences getPreferences() {
return PreferenceManager
@@ -394,9 +406,7 @@ public abstract class XmppActivity extends Activity {
public void success(Account account) {
xmppConnectionService.databaseBackend
.updateAccount(account);
- xmppConnectionService.sendPresencePacket(account,
- xmppConnectionService.getPresenceGenerator()
- .sendPresence(account));
+ xmppConnectionService.sendPresence(account);
if (conversation != null) {
conversation
.setNextEncryption(Message.ENCRYPTION_PGP);
@@ -430,9 +440,12 @@ public abstract class XmppActivity extends Activity {
}
protected void showAddToRosterDialog(final Conversation conversation) {
- final Jid jid = conversation.getJid();
+ showAddToRosterDialog(conversation.getContact());
+ }
+
+ protected void showAddToRosterDialog(final Contact contact) {
AlertDialog.Builder builder = new AlertDialog.Builder(this);
- builder.setTitle(jid.toString());
+ builder.setTitle(contact.getJid().toString());
builder.setMessage(getString(R.string.not_in_roster));
builder.setNegativeButton(getString(R.string.cancel), null);
builder.setPositiveButton(getString(R.string.add_contact),
@@ -440,11 +453,10 @@ public abstract class XmppActivity extends Activity {
@Override
public void onClick(DialogInterface dialog, int which) {
- final Jid jid = conversation.getJid();
- Account account = conversation.getAccount();
+ final Jid jid = contact.getJid();
+ Account account = contact.getAccount();
Contact contact = account.getRoster().getContact(jid);
xmppConnectionService.createContact(contact);
- switchToContactDetails(contact);
}
});
builder.create().show();
@@ -677,6 +689,10 @@ public abstract class XmppActivity extends Activity {
return this.mPrimaryColor;
}
+ public int getOnlineColor() {
+ return this.mColorGreen;
+ }
+
public int getSecondaryBackgroundColor() {
return this.mSecondaryBackgroundColor;
}
diff --git a/src/main/java/eu/siacs/conversations/ui/adapter/AccountAdapter.java b/src/main/java/eu/siacs/conversations/ui/adapter/AccountAdapter.java
index 139f3657..29730914 100644
--- a/src/main/java/eu/siacs/conversations/ui/adapter/AccountAdapter.java
+++ b/src/main/java/eu/siacs/conversations/ui/adapter/AccountAdapter.java
@@ -39,7 +39,7 @@ public class AccountAdapter extends ArrayAdapter<Account> {
statusView.setText(getContext().getString(account.getStatus().getReadableId()));
switch (account.getStatus()) {
case ONLINE:
- statusView.setTextColor(activity.getPrimaryColor());
+ statusView.setTextColor(activity.getOnlineColor());
break;
case DISABLED:
case CONNECTING:
diff --git a/src/main/java/eu/siacs/conversations/ui/adapter/ConversationAdapter.java b/src/main/java/eu/siacs/conversations/ui/adapter/ConversationAdapter.java
index 22f6b662..e62aaf96 100644
--- a/src/main/java/eu/siacs/conversations/ui/adapter/ConversationAdapter.java
+++ b/src/main/java/eu/siacs/conversations/ui/adapter/ConversationAdapter.java
@@ -1,5 +1,16 @@
package eu.siacs.conversations.ui.adapter;
+import android.content.Context;
+import android.graphics.Color;
+import android.graphics.Typeface;
+import android.util.Pair;
+import android.view.LayoutInflater;
+import android.view.View;
+import android.view.ViewGroup;
+import android.widget.ArrayAdapter;
+import android.widget.ImageView;
+import android.widget.TextView;
+
import java.util.List;
import de.tzur.conversations.Settings;
@@ -38,10 +49,8 @@ public class ConversationAdapter extends ArrayAdapter<Conversation> {
@Override
public View getView(int position, View view, ViewGroup parent) {
if (view == null) {
- LayoutInflater inflater = (LayoutInflater) activity
- .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
- view = inflater.inflate(R.layout.conversation_list_row,
- parent, false);
+ LayoutInflater inflater = (LayoutInflater) activity.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
+ view = inflater.inflate(R.layout.conversation_list_row,parent, false);
}
Conversation conversation = getItem(position);
if (this.activity instanceof ConversationActivity) {
@@ -57,20 +66,15 @@ public class ConversationAdapter extends ArrayAdapter<Conversation> {
view.setBackgroundColor(Color.TRANSPARENT);
}
}
- TextView convName = (TextView) view
- .findViewById(R.id.conversation_name);
- if (conversation.getMode() == Conversation.MODE_SINGLE
- || activity.useSubjectToIdentifyConference()) {
+ TextView convName = (TextView) view.findViewById(R.id.conversation_name);
+ if (conversation.getMode() == Conversation.MODE_SINGLE || activity.useSubjectToIdentifyConference()) {
convName.setText(conversation.getName());
} else {
convName.setText(conversation.getJid().toBareJid().toString());
}
- TextView mLastMessage = (TextView) view
- .findViewById(R.id.conversation_lastmsg);
- TextView mTimestamp = (TextView) view
- .findViewById(R.id.conversation_lastupdate);
- ImageView imagePreview = (ImageView) view
- .findViewById(R.id.conversation_lastimage);
+ TextView mLastMessage = (TextView) view.findViewById(R.id.conversation_lastmsg);
+ TextView mTimestamp = (TextView) view.findViewById(R.id.conversation_lastupdate);
+ ImageView imagePreview = (ImageView) view.findViewById(R.id.conversation_lastimage);
if (Settings.SHOW_ONLINE_STATUS) {
TextView status = (TextView) view.findViewById(R.id.status);
@@ -100,91 +104,35 @@ public class ConversationAdapter extends ArrayAdapter<Conversation> {
convName.setTypeface(null, Typeface.NORMAL);
}
- if (message.getType() == Message.TYPE_IMAGE || message.getType() == Message.TYPE_FILE
- || message.getDownloadable() != null) {
- Downloadable d = message.getDownloadable();
- if (conversation.isRead()) {
- mLastMessage.setTypeface(null, Typeface.ITALIC);
- } else {
- mLastMessage.setTypeface(null, Typeface.BOLD_ITALIC);
- }
- if (d != null) {
- mLastMessage.setVisibility(View.VISIBLE);
- imagePreview.setVisibility(View.GONE);
- if (d.getStatus() == Downloadable.STATUS_CHECKING) {
- mLastMessage.setText(R.string.checking_image);
- } else if (d.getStatus() == Downloadable.STATUS_DOWNLOADING) {
- if (message.getType() == Message.TYPE_FILE) {
- mLastMessage.setText(getContext().getString(R.string.receiving_file,d.getMimeType(), d.getProgress()));
- } else {
- mLastMessage.setText(getContext().getString(R.string.receiving_image, d.getProgress()));
- }
- } else if (d.getStatus() == Downloadable.STATUS_OFFER) {
- if (message.getType() == Message.TYPE_FILE) {
- mLastMessage.setText(R.string.file_offered_for_download);
- } else {
- mLastMessage.setText(R.string.image_offered_for_download);
- }
- } else if (d.getStatus() == Downloadable.STATUS_OFFER_CHECK_FILESIZE) {
- mLastMessage.setText(R.string.image_offered_for_download);
- } else if (d.getStatus() == Downloadable.STATUS_DELETED) {
- if (message.getType() == Message.TYPE_FILE) {
- mLastMessage.setText(R.string.file_deleted);
- } else {
- mLastMessage.setText(R.string.image_file_deleted);
- }
- } else if (d.getStatus() == Downloadable.STATUS_FAILED) {
- if (message.getType() == Message.TYPE_FILE) {
- mLastMessage.setText(R.string.file_transmission_failed);
- } else {
- mLastMessage.setText(R.string.image_transmission_failed);
- }
- } else if (message.getImageParams().width > 0) {
- mLastMessage.setVisibility(View.GONE);
- imagePreview.setVisibility(View.VISIBLE);
- activity.loadBitmap(message, imagePreview);
+ if (message.getImageParams().width > 0
+ && (message.getDownloadable() == null
+ || message.getDownloadable().getStatus() != Downloadable.STATUS_DELETED)) {
+ mLastMessage.setVisibility(View.GONE);
+ imagePreview.setVisibility(View.VISIBLE);
+ activity.loadBitmap(message, imagePreview);
+ } else {
+ Pair<String,Boolean> preview = UIHelper.getMessagePreview(activity,message);
+ mLastMessage.setVisibility(View.VISIBLE);
+ imagePreview.setVisibility(View.GONE);
+ mLastMessage.setText(preview.first);
+ if (preview.second) {
+ if (conversation.isRead()) {
+ mLastMessage.setTypeface(null, Typeface.ITALIC);
} else {
- mLastMessage.setText("");
+ mLastMessage.setTypeface(null,Typeface.BOLD_ITALIC);
}
- } else if (message.getEncryption() == Message.ENCRYPTION_PGP) {
- imagePreview.setVisibility(View.GONE);
- mLastMessage.setVisibility(View.VISIBLE);
- mLastMessage.setText(R.string.encrypted_message_received);
- } else if (message.getType() == Message.TYPE_FILE && message.getImageParams().width <= 0) {
- DownloadableFile file = activity.xmppConnectionService.getFileBackend().getFile(message);
- mLastMessage.setVisibility(View.VISIBLE);
- imagePreview.setVisibility(View.GONE);
- mLastMessage.setText(getContext().getString(R.string.file,file.getMimeType()));
- } else {
- mLastMessage.setVisibility(View.GONE);
- imagePreview.setVisibility(View.VISIBLE);
- activity.loadBitmap(message, imagePreview);
- }
- } else {
- if ((message.getEncryption() != Message.ENCRYPTION_PGP)
- && (message.getEncryption() != Message.ENCRYPTION_DECRYPTION_FAILED)) {
- boolean parseEmoticons = Settings.PARSE_EMOTICONS;
- mLastMessage.setText(parseEmoticons ? UIHelper
- .transformAsciiEmoticons(getContext(), message.getBody()) : message
- .getBody());
} else {
- mLastMessage.setText(R.string.encrypted_message_received);
- }
- if (!conversation.isRead()) {
- mLastMessage.setTypeface(null, Typeface.BOLD);
- } else {
- mLastMessage.setTypeface(null, Typeface.NORMAL);
+ if (conversation.isRead()) {
+ mLastMessage.setTypeface(null,Typeface.NORMAL);
+ } else {
+ mLastMessage.setTypeface(null,Typeface.BOLD);
+ }
}
- mLastMessage.setVisibility(View.VISIBLE);
- imagePreview.setVisibility(View.GONE);
}
- mTimestamp.setText(UIHelper.readableTimeDifference(getContext(),
- conversation.getLatestMessage().getTimeSent()));
- ImageView profilePicture = (ImageView) view
- .findViewById(R.id.conversation_image);
- profilePicture.setImageBitmap(activity.avatarService().get(
- conversation, activity.getPixel(56)));
+ mTimestamp.setText(UIHelper.readableTimeDifference(activity,conversation.getLatestMessage().getTimeSent()));
+ ImageView profilePicture = (ImageView) view.findViewById(R.id.conversation_image);
+ profilePicture.setImageBitmap(activity.avatarService().get(conversation, activity.getPixel(56)));
return view;
}
diff --git a/src/main/java/eu/siacs/conversations/ui/adapter/MessageAdapter.java b/src/main/java/eu/siacs/conversations/ui/adapter/MessageAdapter.java
index 2771c4de..7fa05050 100644
--- a/src/main/java/eu/siacs/conversations/ui/adapter/MessageAdapter.java
+++ b/src/main/java/eu/siacs/conversations/ui/adapter/MessageAdapter.java
@@ -11,6 +11,7 @@ import android.text.SpannableString;
import android.text.style.ForegroundColorSpan;
import android.text.style.StyleSpan;
import android.util.DisplayMetrics;
+import android.util.Log;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.View.OnLongClickListener;
@@ -36,7 +37,6 @@ import eu.siacs.conversations.entities.Message;
import eu.siacs.conversations.entities.Message.ImageParams;
import eu.siacs.conversations.ui.ConversationActivity;
import eu.siacs.conversations.utils.UIHelper;
-import eu.siacs.conversations.xmpp.jid.Jid;
public class MessageAdapter extends ArrayAdapter<Message> {
@@ -53,14 +53,14 @@ public class MessageAdapter extends ArrayAdapter<Message> {
private OnContactPictureLongClicked mOnContactPictureLongClickedListener;
private OnLongClickListener openContextMenu = new OnLongClickListener() {
-
+
@Override
public boolean onLongClick(View v) {
v.showContextMenu();
return true;
}
};
-
+
public MessageAdapter(ConversationActivity activity, List<Message> messages) {
super(activity, 0, messages);
this.activity = activity;
@@ -74,7 +74,7 @@ public class MessageAdapter extends ArrayAdapter<Message> {
public void setOnContactPictureLongClicked(
OnContactPictureLongClicked listener) {
this.mOnContactPictureLongClickedListener = listener;
- }
+ }
@Override
public int getViewTypeCount() {
@@ -102,57 +102,52 @@ public class MessageAdapter extends ArrayAdapter<Message> {
viewHolder.indicatorReceived.setVisibility(View.GONE);
}
boolean multiReceived = message.getConversation().getMode() == Conversation.MODE_MULTI
- && message.getMergedStatus() <= Message.STATUS_RECEIVED;
+ && message.getMergedStatus() <= Message.STATUS_RECEIVED;
if (message.getType() == Message.TYPE_IMAGE || message.getType() == Message.TYPE_FILE || message.getDownloadable() != null) {
ImageParams params = message.getImageParams();
if (params.size > (1.5 * 1024 * 1024)) {
- filesize = params.size / (1024 * 1024)+ " MB";
+ filesize = params.size / (1024 * 1024)+ " MiB";
} else if (params.size > 0) {
- filesize = params.size / 1024 + " KB";
+ filesize = params.size / 1024 + " KiB";
}
if (message.getDownloadable() != null && message.getDownloadable().getStatus() == Downloadable.STATUS_FAILED) {
error = true;
}
}
switch (message.getMergedStatus()) {
- case Message.STATUS_WAITING:
- info = getContext().getString(R.string.waiting);
- break;
- case Message.STATUS_UNSEND:
- Downloadable d = message.getDownloadable();
- if (d!=null) {
- info = getContext().getString(R.string.sending_file,d.getProgress());
- } else {
- info = getContext().getString(R.string.sending);
- }
- break;
- case Message.STATUS_OFFERED:
- info = getContext().getString(R.string.offering);
- break;
- case Message.STATUS_SEND_RECEIVED:
- if (activity.indicateReceived()) {
- viewHolder.indicatorReceived.setVisibility(View.VISIBLE);
- }
- break;
- case Message.STATUS_SEND_DISPLAYED:
- if (activity.indicateReceived()) {
- viewHolder.indicatorReceived.setVisibility(View.VISIBLE);
- }
- break;
- case Message.STATUS_SEND_FAILED:
- info = getContext().getString(R.string.send_failed);
- error = true;
- break;
- default:
- if (multiReceived) {
- Contact contact = message.getContact();
- if (contact != null) {
- info = contact.getDisplayName();
+ case Message.STATUS_WAITING:
+ info = getContext().getString(R.string.waiting);
+ break;
+ case Message.STATUS_UNSEND:
+ Downloadable d = message.getDownloadable();
+ if (d!=null) {
+ info = getContext().getString(R.string.sending_file,d.getProgress());
} else {
- info = getDisplayedMucCounterpart(message.getCounterpart());
+ info = getContext().getString(R.string.sending);
}
- }
- break;
+ break;
+ case Message.STATUS_OFFERED:
+ info = getContext().getString(R.string.offering);
+ break;
+ case Message.STATUS_SEND_RECEIVED:
+ if (activity.indicateReceived()) {
+ viewHolder.indicatorReceived.setVisibility(View.VISIBLE);
+ }
+ break;
+ case Message.STATUS_SEND_DISPLAYED:
+ if (activity.indicateReceived()) {
+ viewHolder.indicatorReceived.setVisibility(View.VISIBLE);
+ }
+ break;
+ case Message.STATUS_SEND_FAILED:
+ info = getContext().getString(R.string.send_failed);
+ error = true;
+ break;
+ default:
+ if (multiReceived) {
+ info = UIHelper.getMessageDisplayName(message);
+ }
+ break;
}
if (error) {
viewHolder.time.setTextColor(activity.getWarningTextColor());
@@ -213,29 +208,40 @@ public class MessageAdapter extends ArrayAdapter<Message> {
viewHolder.image.setVisibility(View.GONE);
viewHolder.messageBody.setVisibility(View.VISIBLE);
viewHolder.messageBody.setText(getContext().getString(
- R.string.decryption_failed));
+ R.string.decryption_failed));
viewHolder.messageBody.setTextColor(activity.getWarningTextColor());
viewHolder.messageBody.setTypeface(null, Typeface.NORMAL);
viewHolder.messageBody.setTextIsSelectable(false);
}
- private void displayTextMessage(ViewHolder viewHolder, Message message) {
+ private void displayTextMessage(final ViewHolder viewHolder, final Message message) {
if (viewHolder.download_button != null) {
viewHolder.download_button.setVisibility(View.GONE);
}
viewHolder.image.setVisibility(View.GONE);
viewHolder.messageBody.setVisibility(View.VISIBLE);
if (message.getBody() != null) {
+ final String nick = UIHelper.getMessageDisplayName(message);
+ final String formattedBody = message.getMergedBody().replaceAll("^" + Message.ME_COMMAND,
+ nick + " ");
if (message.getType() != Message.TYPE_PRIVATE) {
boolean parseEmoticons = Settings.PARSE_EMOTICONS;
viewHolder.messageBody.setText(parseEmoticons ? UIHelper
.transformAsciiEmoticons(getContext(), message.getMergedBody())
: message.getMergedBody());
+ if (message.hasMeCommand()) {
+ final Spannable span = new SpannableString(formattedBody);
+ span.setSpan(new StyleSpan(Typeface.BOLD_ITALIC), 0, nick.length(),
+ Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
+ viewHolder.messageBody.setText(span);
+ } else {
+ viewHolder.messageBody.setText(message.getMergedBody());
+ }
} else {
String privateMarker;
if (message.getStatus() <= Message.STATUS_RECEIVED) {
privateMarker = activity
- .getString(R.string.private_message);
+ .getString(R.string.private_message);
} else {
final String to;
if (message.getCounterpart() != null) {
@@ -245,15 +251,19 @@ public class MessageAdapter extends ArrayAdapter<Message> {
}
privateMarker = activity.getString(R.string.private_message_to, to);
}
- SpannableString span = new SpannableString(privateMarker + " "
- + message.getBody());
- span.setSpan(
- new ForegroundColorSpan(activity
- .getSecondaryTextColor()), 0, privateMarker
- .length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
- span.setSpan(new StyleSpan(android.graphics.Typeface.BOLD), 0,
+ final Spannable span = new SpannableString(privateMarker + " "
+ + formattedBody);
+ span.setSpan(new ForegroundColorSpan(activity
+ .getSecondaryTextColor()), 0, privateMarker
+ .length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
+ span.setSpan(new StyleSpan(Typeface.BOLD), 0,
privateMarker.length(),
Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
+ if (message.hasMeCommand()) {
+ span.setSpan(new StyleSpan(Typeface.BOLD_ITALIC), privateMarker.length() + 1,
+ privateMarker.length() + 1 + nick.length(),
+ Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
+ }
viewHolder.messageBody.setText(span);
}
} else {
@@ -281,16 +291,15 @@ public class MessageAdapter extends ArrayAdapter<Message> {
}
private void displayOpenableMessage(ViewHolder viewHolder,final Message message) {
- final DownloadableFile file = activity.xmppConnectionService.getFileBackend().getFile(message);
viewHolder.image.setVisibility(View.GONE);
viewHolder.messageBody.setVisibility(View.GONE);
viewHolder.download_button.setVisibility(View.VISIBLE);
- viewHolder.download_button.setText(activity.getString(R.string.open_file,file.getMimeType()));
+ viewHolder.download_button.setText(activity.getString(R.string.open_x_file, UIHelper.getFileDescriptionString(activity,message)));
viewHolder.download_button.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
- openDownloadable(file);
+ openDownloadable(message);
}
});
viewHolder.download_button.setOnLongClickListener(openContextMenu);
@@ -315,7 +324,7 @@ public class MessageAdapter extends ArrayAdapter<Message> {
scalledH = (int) (params.height / ((double) params.width / target));
}
viewHolder.image.setLayoutParams(new LinearLayout.LayoutParams(
- scalledW, scalledH));
+ scalledW, scalledH));
activity.loadBitmap(message, viewHolder.image);
viewHolder.image.setOnClickListener(new OnClickListener() {
@@ -330,16 +339,6 @@ public class MessageAdapter extends ArrayAdapter<Message> {
viewHolder.image.setOnLongClickListener(openContextMenu);
}
- private String getDisplayedMucCounterpart(final Jid counterpart) {
- if (counterpart==null) {
- return "";
- } else if (!counterpart.isBareJid()) {
- return counterpart.getResourcepart();
- } else {
- return counterpart.toString();
- }
- }
-
@Override
public View getView(int position, View view, ViewGroup parent) {
final Message message = getItem(position);
@@ -350,59 +349,58 @@ public class MessageAdapter extends ArrayAdapter<Message> {
if (view == null) {
viewHolder = new ViewHolder();
switch (type) {
- case NULL:
- view = activity.getLayoutInflater().inflate(
- R.layout.message_null, parent, false);
- break;
- case SENT:
- view = activity.getLayoutInflater().inflate(
- R.layout.message_sent, parent, false);
- viewHolder.message_box = (LinearLayout) view
+ case NULL:
+ view = activity.getLayoutInflater().inflate(
+ R.layout.message_null, parent, false);
+ break;
+ case SENT:
+ view = activity.getLayoutInflater().inflate(
+ R.layout.message_sent, parent, false);
+ viewHolder.message_box = (LinearLayout) view
.findViewById(R.id.message_box);
- viewHolder.contact_picture = (ImageView) view
+ viewHolder.contact_picture = (ImageView) view
.findViewById(R.id.message_photo);
- viewHolder.download_button = (Button) view
+ viewHolder.download_button = (Button) view
.findViewById(R.id.download_button);
- viewHolder.indicator = (ImageView) view
+ viewHolder.indicator = (ImageView) view
.findViewById(R.id.security_indicator);
- viewHolder.image = (ImageView) view
+ viewHolder.image = (ImageView) view
.findViewById(R.id.message_image);
- viewHolder.messageBody = (TextView) view
+ viewHolder.messageBody = (TextView) view
.findViewById(R.id.message_body);
- viewHolder.time = (TextView) view
+ viewHolder.time = (TextView) view
.findViewById(R.id.message_time);
- viewHolder.indicatorReceived = (ImageView) view
+ viewHolder.indicatorReceived = (ImageView) view
.findViewById(R.id.indicator_received);
- break;
- case RECEIVED:
- view = activity.getLayoutInflater().inflate(
- R.layout.message_received, parent, false);
- viewHolder.message_box = (LinearLayout) view
+ break;
+ case RECEIVED:
+ view = activity.getLayoutInflater().inflate(
+ R.layout.message_received, parent, false);
+ viewHolder.message_box = (LinearLayout) view
.findViewById(R.id.message_box);
- viewHolder.contact_picture = (ImageView) view
+ viewHolder.contact_picture = (ImageView) view
.findViewById(R.id.message_photo);
- viewHolder.download_button = (Button) view
+ viewHolder.download_button = (Button) view
.findViewById(R.id.download_button);
- viewHolder.indicator = (ImageView) view
+ viewHolder.indicator = (ImageView) view
.findViewById(R.id.security_indicator);
- viewHolder.image = (ImageView) view
+ viewHolder.image = (ImageView) view
.findViewById(R.id.message_image);
- viewHolder.messageBody = (TextView) view
+ viewHolder.messageBody = (TextView) view
.findViewById(R.id.message_body);
- viewHolder.time = (TextView) view
+ viewHolder.time = (TextView) view
.findViewById(R.id.message_time);
- viewHolder.indicatorReceived = (ImageView) view
+ viewHolder.indicatorReceived = (ImageView) view
.findViewById(R.id.indicator_received);
- break;
- case STATUS:
- view = activity.getLayoutInflater().inflate(
- R.layout.message_status, parent, false);
- viewHolder.contact_picture = (ImageView) view
- .findViewById(R.id.message_photo);
- break;
- default:
- viewHolder = null;
- break;
+ break;
+ case STATUS:
+ view = activity.getLayoutInflater().inflate(R.layout.message_status, parent, false);
+ viewHolder.contact_picture = (ImageView) view.findViewById(R.id.message_photo);
+ viewHolder.status_message = (TextView) view.findViewById(R.id.status_message);
+ break;
+ default:
+ viewHolder = null;
+ break;
}
view.setTag(viewHolder);
} else {
@@ -416,26 +414,19 @@ public class MessageAdapter extends ArrayAdapter<Message> {
if (conversation.getMode() == Conversation.MODE_SINGLE) {
viewHolder.contact_picture.setImageBitmap(activity
.avatarService().get(conversation.getContact(),
- activity.getPixel(32)));
+ activity.getPixel(32)));
viewHolder.contact_picture.setAlpha(0.5f);
- viewHolder.contact_picture
- .setOnClickListener(new OnClickListener() {
-
- @Override
- public void onClick(View v) {
- String name = conversation.getName();
- String read = getContext()
- .getString(
- R.string.contact_has_read_up_to_this_point,
- name);
- Toast.makeText(getContext(), read,
- Toast.LENGTH_SHORT).show();
- }
- });
+ viewHolder.status_message.setText(
+ activity.getString(R.string.contact_has_read_up_to_this_point, conversation.getName()));
}
return view;
} else if (type == NULL) {
+ if (viewHolder.message_box != null) {
+ Log.e(Config.LOGTAG, "detected type=NULL but with wrong cached view");
+ view = activity.getLayoutInflater().inflate(R.layout.message_null, parent, false);
+ view.setTag(new ViewHolder());
+ }
if (position == getCount() - 1) {
view.getLayoutParams().height = 1;
} else {
@@ -444,6 +435,9 @@ public class MessageAdapter extends ArrayAdapter<Message> {
}
view.setLayoutParams(view.getLayoutParams());
return view;
+ } else if (message.wasMergedIntoPrevious()) {
+ Log.e(Config.LOGTAG,"detected wasMergedIntoPrevious with wrong type");
+ return view;
} else if (viewHolder.messageBody == null || viewHolder.image == null) {
return view; //avoiding weird platform bugs
} else if (type == RECEIVED) {
@@ -451,70 +445,49 @@ public class MessageAdapter extends ArrayAdapter<Message> {
if (contact != null) {
viewHolder.contact_picture.setImageBitmap(activity.avatarService().get(contact, activity.getPixel(48)));
} else if (conversation.getMode() == Conversation.MODE_MULTI) {
- viewHolder.contact_picture.setImageBitmap(activity.avatarService().get(getDisplayedMucCounterpart(message.getCounterpart()),
- activity.getPixel(48)));
+ viewHolder.contact_picture.setImageBitmap(activity.avatarService().get(
+ UIHelper.getMessageDisplayName(message),
+ activity.getPixel(48)));
}
} else if (type == SENT) {
viewHolder.contact_picture.setImageBitmap(activity.avatarService().get(account, activity.getPixel(48)));
}
viewHolder.contact_picture
- .setOnClickListener(new OnClickListener() {
+ .setOnClickListener(new OnClickListener() {
- @Override
- public void onClick(View v) {
- if (MessageAdapter.this.mOnContactPictureClickedListener != null) {
- MessageAdapter.this.mOnContactPictureClickedListener
- .onContactPictureClicked(message);
- }
-
- }
- });
- viewHolder.contact_picture
- .setOnLongClickListener(new OnLongClickListener() {
-
- @Override
- public boolean onLongClick(View v) {
- if (MessageAdapter.this.mOnContactPictureLongClickedListener != null) {
- MessageAdapter.this.mOnContactPictureLongClickedListener
- .onContactPictureLongClicked(message);
- return true;
- } else {
- return false;
- }
+ @Override
+ public void onClick(View v) {
+ if (MessageAdapter.this.mOnContactPictureClickedListener != null) {
+ MessageAdapter.this.mOnContactPictureClickedListener
+ .onContactPictureClicked(message);
}
- });
- if (message.getDownloadable() != null && message.getDownloadable().getStatus() != Downloadable.STATUS_UPLOADING) {
- Downloadable d = message.getDownloadable();
- if (d.getStatus() == Downloadable.STATUS_DOWNLOADING) {
- if (message.getType() == Message.TYPE_FILE) {
- displayInfoMessage(viewHolder,activity.getString(R.string.receiving_file,d.getMimeType(),d.getProgress()));
- } else {
- displayInfoMessage(viewHolder,activity.getString(R.string.receiving_image,d.getProgress()));
}
- } else if (d.getStatus() == Downloadable.STATUS_CHECKING) {
- displayInfoMessage(viewHolder,activity.getString(R.string.checking_image));
- } else if (d.getStatus() == Downloadable.STATUS_DELETED) {
- if (message.getType() == Message.TYPE_FILE) {
- displayInfoMessage(viewHolder, activity.getString(R.string.file_deleted));
- } else {
- displayInfoMessage(viewHolder, activity.getString(R.string.image_file_deleted));
- }
- } else if (d.getStatus() == Downloadable.STATUS_OFFER) {
- if (message.getType() == Message.TYPE_FILE) {
- displayDownloadableMessage(viewHolder,message,activity.getString(R.string.download_file,d.getMimeType()));
- } else {
- displayDownloadableMessage(viewHolder, message,activity.getString(R.string.download_image));
- }
- } else if (d.getStatus() == Downloadable.STATUS_OFFER_CHECK_FILESIZE) {
- displayDownloadableMessage(viewHolder, message,activity.getString(R.string.check_image_filesize));
- } else if (d.getStatus() == Downloadable.STATUS_FAILED) {
- if (message.getType() == Message.TYPE_FILE) {
- displayInfoMessage(viewHolder, activity.getString(R.string.file_transmission_failed));
- } else {
- displayInfoMessage(viewHolder, activity.getString(R.string.image_transmission_failed));
+ });
+ viewHolder.contact_picture
+ .setOnLongClickListener(new OnLongClickListener() {
+
+ @Override
+ public boolean onLongClick(View v) {
+ if (MessageAdapter.this.mOnContactPictureLongClickedListener != null) {
+ MessageAdapter.this.mOnContactPictureLongClickedListener
+ .onContactPictureLongClicked(message);
+ return true;
+ } else {
+ return false;
+ }
}
+ });
+
+ final Downloadable downloadable = message.getDownloadable();
+ if (downloadable != null && downloadable.getStatus() != Downloadable.STATUS_UPLOADING) {
+ if (downloadable.getStatus() == Downloadable.STATUS_OFFER) {
+ displayDownloadableMessage(viewHolder,message,activity.getString(R.string.download_x_file, UIHelper.getFileDescriptionString(activity, message)));
+ } else if (downloadable.getStatus() == Downloadable.STATUS_OFFER_CHECK_FILESIZE) {
+ displayDownloadableMessage(viewHolder, message, activity.getString(R.string.check_image_filesize));
+ } else {
+ displayInfoMessage(viewHolder, UIHelper.getMessagePreview(activity, message).first);
}
} else if (message.getType() == Message.TYPE_IMAGE && message.getEncryption() != Message.ENCRYPTION_PGP && message.getEncryption() != Message.ENCRYPTION_DECRYPTION_FAILED) {
displayImageMessage(viewHolder, message);
@@ -532,13 +505,13 @@ public class MessageAdapter extends ArrayAdapter<Message> {
activity.getString(R.string.install_openkeychain));
if (viewHolder != null) {
viewHolder.message_box
- .setOnClickListener(new OnClickListener() {
+ .setOnClickListener(new OnClickListener() {
- @Override
- public void onClick(View v) {
- activity.showInstallPgpDialog();
- }
- });
+ @Override
+ public void onClick(View v) {
+ activity.showInstallPgpDialog();
+ }
+ });
}
}
} else if (message.getEncryption() == Message.ENCRYPTION_DECRYPTION_FAILED) {
@@ -562,7 +535,8 @@ public class MessageAdapter extends ArrayAdapter<Message> {
}
}
- public void openDownloadable(DownloadableFile file) {
+ public void openDownloadable(Message message) {
+ DownloadableFile file = activity.xmppConnectionService.getFileBackend().getFile(message);
if (!file.exists()) {
Toast.makeText(activity,R.string.file_deleted,Toast.LENGTH_SHORT).show();
return;
@@ -596,6 +570,6 @@ public class MessageAdapter extends ArrayAdapter<Message> {
protected TextView time;
protected TextView messageBody;
protected ImageView contact_picture;
-
+ protected TextView status_message;
}
}