aboutsummaryrefslogtreecommitdiffstats
path: root/src/main/java/de/thedevstack/conversationsplus/ui
diff options
context:
space:
mode:
Diffstat (limited to 'src/main/java/de/thedevstack/conversationsplus/ui')
-rw-r--r--src/main/java/de/thedevstack/conversationsplus/ui/BlocklistActivity.java17
-rw-r--r--src/main/java/de/thedevstack/conversationsplus/ui/ChangePasswordActivity.java15
-rw-r--r--src/main/java/de/thedevstack/conversationsplus/ui/ChooseContactActivity.java81
-rw-r--r--src/main/java/de/thedevstack/conversationsplus/ui/ConferenceDetailsActivity.java179
-rw-r--r--src/main/java/de/thedevstack/conversationsplus/ui/ContactDetailsActivity.java95
-rw-r--r--src/main/java/de/thedevstack/conversationsplus/ui/ConversationActivity.java768
-rw-r--r--src/main/java/de/thedevstack/conversationsplus/ui/ConversationFragment.java626
-rw-r--r--src/main/java/de/thedevstack/conversationsplus/ui/EditAccountActivity.java625
-rw-r--r--src/main/java/de/thedevstack/conversationsplus/ui/EditMessage.java26
-rw-r--r--src/main/java/de/thedevstack/conversationsplus/ui/EnterJidDialog.java134
-rw-r--r--src/main/java/de/thedevstack/conversationsplus/ui/ExportLogsPreference.java29
-rw-r--r--src/main/java/de/thedevstack/conversationsplus/ui/ManageAccountActivity.java191
-rw-r--r--src/main/java/de/thedevstack/conversationsplus/ui/PublishProfilePictureActivity.java167
-rw-r--r--src/main/java/de/thedevstack/conversationsplus/ui/SettingsActivity.java213
-rw-r--r--src/main/java/de/thedevstack/conversationsplus/ui/ShareWithActivity.java103
-rw-r--r--src/main/java/de/thedevstack/conversationsplus/ui/StartConversationActivity.java251
-rw-r--r--src/main/java/de/thedevstack/conversationsplus/ui/TrustKeysActivity.java301
-rw-r--r--src/main/java/de/thedevstack/conversationsplus/ui/UiCallback.java6
-rw-r--r--src/main/java/de/thedevstack/conversationsplus/ui/VerifyOTRActivity.java5
-rw-r--r--src/main/java/de/thedevstack/conversationsplus/ui/XmppActivity.java356
-rw-r--r--src/main/java/de/thedevstack/conversationsplus/ui/adapter/AccountAdapter.java27
-rw-r--r--src/main/java/de/thedevstack/conversationsplus/ui/adapter/ConversationAdapter.java42
-rw-r--r--src/main/java/de/thedevstack/conversationsplus/ui/adapter/KnownHostsAdapter.java15
-rw-r--r--src/main/java/de/thedevstack/conversationsplus/ui/adapter/ListItemAdapter.java34
-rw-r--r--src/main/java/de/thedevstack/conversationsplus/ui/adapter/MessageAdapter.java336
-rw-r--r--src/main/java/de/thedevstack/conversationsplus/ui/adapter/PresencesArrayAdapter.java7
-rw-r--r--src/main/java/de/thedevstack/conversationsplus/ui/dialogs/UserDecisionDialog.java2
-rw-r--r--src/main/java/de/thedevstack/conversationsplus/ui/forms/FormBooleanFieldWrapper.java80
-rw-r--r--src/main/java/de/thedevstack/conversationsplus/ui/forms/FormFieldFactory.java30
-rw-r--r--src/main/java/de/thedevstack/conversationsplus/ui/forms/FormFieldWrapper.java93
-rw-r--r--src/main/java/de/thedevstack/conversationsplus/ui/forms/FormJidSingleFieldWrapper.java44
-rw-r--r--src/main/java/de/thedevstack/conversationsplus/ui/forms/FormTextFieldWrapper.java97
-rw-r--r--src/main/java/de/thedevstack/conversationsplus/ui/forms/FormWrapper.java72
-rw-r--r--src/main/java/de/thedevstack/conversationsplus/ui/listeners/ConversationSwipeRefreshListener.java4
-rw-r--r--src/main/java/de/thedevstack/conversationsplus/ui/listeners/ResizePictureUserDecisionListener.java23
-rw-r--r--src/main/java/de/thedevstack/conversationsplus/ui/listeners/ShowResourcesListDialogListener.java4
-rw-r--r--src/main/java/de/thedevstack/conversationsplus/ui/widget/Switch.java68
37 files changed, 3965 insertions, 1201 deletions
diff --git a/src/main/java/de/thedevstack/conversationsplus/ui/BlocklistActivity.java b/src/main/java/de/thedevstack/conversationsplus/ui/BlocklistActivity.java
index 4e6d7701..377d0e02 100644
--- a/src/main/java/de/thedevstack/conversationsplus/ui/BlocklistActivity.java
+++ b/src/main/java/de/thedevstack/conversationsplus/ui/BlocklistActivity.java
@@ -35,7 +35,7 @@ public class BlocklistActivity extends AbstractSearchableListItemActivity implem
@Override
public void onBackendConnected() {
for (final Account account : xmppConnectionService.getAccounts()) {
- if (account.getJid().toString().equals(getIntent().getStringExtra("account"))) {
+ if (account.getJid().toString().equals(getIntent().getStringExtra(EXTRA_ACCOUNT))) {
this.account = account;
break;
}
@@ -55,16 +55,10 @@ public class BlocklistActivity extends AbstractSearchableListItemActivity implem
}
Collections.sort(getListItems());
}
- runOnUiThread(new Runnable() {
- @Override
- public void run() {
- getListItemAdapter().notifyDataSetChanged();
- }
- });
+ getListItemAdapter().notifyDataSetChanged();
}
- @Override
- public void OnUpdateBlocklist(final OnUpdateBlocklist.Status status) {
+ protected void refreshUiReal() {
final Editable editable = getSearchEditText().getText();
if (editable != null) {
filterContacts(editable.toString());
@@ -72,4 +66,9 @@ public class BlocklistActivity extends AbstractSearchableListItemActivity implem
filterContacts();
}
}
+
+ @Override
+ public void OnUpdateBlocklist(final OnUpdateBlocklist.Status status) {
+ refreshUi();
+ }
}
diff --git a/src/main/java/de/thedevstack/conversationsplus/ui/ChangePasswordActivity.java b/src/main/java/de/thedevstack/conversationsplus/ui/ChangePasswordActivity.java
index 9d6b50fc..1eb9fa05 100644
--- a/src/main/java/de/thedevstack/conversationsplus/ui/ChangePasswordActivity.java
+++ b/src/main/java/de/thedevstack/conversationsplus/ui/ChangePasswordActivity.java
@@ -9,8 +9,6 @@ import android.widget.Toast;
import de.thedevstack.conversationsplus.R;
import de.thedevstack.conversationsplus.entities.Account;
import de.thedevstack.conversationsplus.services.XmppConnectionService;
-import de.thedevstack.conversationsplus.xmpp.jid.InvalidJidException;
-import de.thedevstack.conversationsplus.xmpp.jid.Jid;
public class ChangePasswordActivity extends XmppActivity implements XmppConnectionService.OnAccountPasswordChanged {
@@ -53,14 +51,7 @@ public class ChangePasswordActivity extends XmppActivity implements XmppConnecti
@Override
void onBackendConnected() {
- try {
- final String jid = getIntent() == null ? null : getIntent().getStringExtra("account");
- if (jid != null) {
- this.mAccount = xmppConnectionService.findAccountByJid(Jid.fromString(jid));
- }
- } catch (final InvalidJidException ignored) {
-
- }
+ this.mAccount = extractAccount(getIntent());
}
@@ -106,4 +97,8 @@ public class ChangePasswordActivity extends XmppActivity implements XmppConnecti
});
}
+
+ public void refreshUiReal() {
+
+ }
}
diff --git a/src/main/java/de/thedevstack/conversationsplus/ui/ChooseContactActivity.java b/src/main/java/de/thedevstack/conversationsplus/ui/ChooseContactActivity.java
index d51d23e1..29860434 100644
--- a/src/main/java/de/thedevstack/conversationsplus/ui/ChooseContactActivity.java
+++ b/src/main/java/de/thedevstack/conversationsplus/ui/ChooseContactActivity.java
@@ -13,18 +13,22 @@ import android.widget.AbsListView.MultiChoiceModeListener;
import android.widget.AdapterView;
import android.widget.ListView;
-import java.util.Set;
-import java.util.HashSet;
+import java.util.ArrayList;
import java.util.Collections;
+import java.util.HashSet;
import java.util.List;
-import java.util.ArrayList;
+import java.util.Set;
+import de.thedevstack.conversationsplus.Config;
import de.thedevstack.conversationsplus.R;
import de.thedevstack.conversationsplus.entities.Account;
import de.thedevstack.conversationsplus.entities.Contact;
import de.thedevstack.conversationsplus.entities.ListItem;
+import de.thedevstack.conversationsplus.xmpp.jid.Jid;
public class ChooseContactActivity extends AbstractSearchableListItemActivity {
+ private List<String> mActivatedAccounts = new ArrayList<String>();
+ private List<String> mKnownHosts;
private Set<Contact> selected;
private Set<String> filterContacts;
@@ -109,11 +113,11 @@ public class ChooseContactActivity extends AbstractSearchableListItemActivity {
final Intent data = new Intent();
final ListItem mListItem = getListItems().get(position);
data.putExtra("contact", mListItem.getJid().toString());
- String account = request.getStringExtra("account");
+ String account = request.getStringExtra(EXTRA_ACCOUNT);
if (account == null && mListItem instanceof Contact) {
account = ((Contact) mListItem).getAccount().getJid().toBareJid().toString();
}
- data.putExtra("account", account);
+ data.putExtra(EXTRA_ACCOUNT, account);
data.putExtra("conversation",
request.getStringExtra("conversation"));
data.putExtra("multiple", false);
@@ -124,6 +128,15 @@ public class ChooseContactActivity extends AbstractSearchableListItemActivity {
}
+ @Override
+ public boolean onCreateOptionsMenu(final Menu menu) {
+ super.onCreateOptionsMenu(menu);
+ final Intent i = getIntent();
+ boolean showEnterJid = i != null && i.getBooleanExtra("show_enter_jid", false);
+ menu.findItem(R.id.action_create_contact).setVisible(showEnterJid);
+ return true;
+ }
+
protected void filterContacts(final String needle) {
getListItems().clear();
for (final Account account : xmppConnectionService.getAccounts()) {
@@ -149,4 +162,62 @@ public class ChooseContactActivity extends AbstractSearchableListItemActivity {
return result.toArray(new String[result.size()]);
}
+
+ public void refreshUiReal() {
+ //nothing to do. This Activity doesn't implement any listeners
+ }
+
+ @Override
+ public boolean onOptionsItemSelected(MenuItem item) {
+ switch (item.getItemId()) {
+ case R.id.action_create_contact:
+ showEnterJidDialog();
+ return true;
+ }
+ return super.onOptionsItemSelected(item);
+ }
+
+ protected void showEnterJidDialog() {
+ EnterJidDialog dialog = new EnterJidDialog(
+ this, mKnownHosts, mActivatedAccounts,
+ getString(R.string.enter_contact), getString(R.string.select),
+ null, getIntent().getStringExtra(EXTRA_ACCOUNT), true
+ );
+
+ dialog.setOnEnterJidDialogPositiveListener(new EnterJidDialog.OnEnterJidDialogPositiveListener() {
+ @Override
+ public boolean onEnterJidDialogPositive(Jid accountJid, Jid contactJid) throws EnterJidDialog.JidError {
+ final Intent request = getIntent();
+ final Intent data = new Intent();
+ data.putExtra("contact", contactJid.toString());
+ data.putExtra(EXTRA_ACCOUNT, accountJid.toString());
+ data.putExtra("conversation",
+ request.getStringExtra("conversation"));
+ data.putExtra("multiple", false);
+ setResult(RESULT_OK, data);
+ finish();
+
+ return true;
+ }
+ });
+
+ dialog.show();
+ }
+
+ @Override
+ void onBackendConnected() {
+ filterContacts();
+
+ this.mActivatedAccounts.clear();
+ for (Account account : xmppConnectionService.getAccounts()) {
+ if (account.getStatus() != Account.State.DISABLED) {
+ if (Config.DOMAIN_LOCK != null) {
+ this.mActivatedAccounts.add(account.getJid().getLocalpart());
+ } else {
+ this.mActivatedAccounts.add(account.getJid().toBareJid().toString());
+ }
+ }
+ }
+ this.mKnownHosts = xmppConnectionService.getKnownHosts();
+ }
}
diff --git a/src/main/java/de/thedevstack/conversationsplus/ui/ConferenceDetailsActivity.java b/src/main/java/de/thedevstack/conversationsplus/ui/ConferenceDetailsActivity.java
index 518041f2..c1b5ccc6 100644
--- a/src/main/java/de/thedevstack/conversationsplus/ui/ConferenceDetailsActivity.java
+++ b/src/main/java/de/thedevstack/conversationsplus/ui/ConferenceDetailsActivity.java
@@ -6,7 +6,6 @@ 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;
import android.os.Bundle;
import android.view.ContextMenu;
@@ -19,6 +18,7 @@ import android.widget.Button;
import android.widget.ImageButton;
import android.widget.ImageView;
import android.widget.LinearLayout;
+import android.widget.TableLayout;
import android.widget.TextView;
import android.widget.Toast;
@@ -27,7 +27,9 @@ import org.openintents.openpgp.util.OpenPgpUtils;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
+import java.util.concurrent.atomic.AtomicInteger;
+import de.thedevstack.conversationsplus.Config;
import de.thedevstack.conversationsplus.R;
import de.thedevstack.conversationsplus.crypto.PgpEngine;
import de.thedevstack.conversationsplus.entities.Account;
@@ -38,8 +40,8 @@ import de.thedevstack.conversationsplus.entities.MucOptions;
import de.thedevstack.conversationsplus.entities.MucOptions.User;
import de.thedevstack.conversationsplus.services.AvatarService;
import de.thedevstack.conversationsplus.services.XmppConnectionService;
-import de.thedevstack.conversationsplus.services.XmppConnectionService.OnMucRosterUpdate;
import de.thedevstack.conversationsplus.services.XmppConnectionService.OnConversationUpdate;
+import de.thedevstack.conversationsplus.services.XmppConnectionService.OnMucRosterUpdate;
import de.thedevstack.conversationsplus.xmpp.jid.Jid;
public class ConferenceDetailsActivity extends XmppActivity implements OnConversationUpdate, OnMucRosterUpdate, XmppConnectionService.OnAffiliationChanged, XmppConnectionService.OnRoleChanged, XmppConnectionService.OnConferenceOptionsPushed {
@@ -61,7 +63,11 @@ public class ConferenceDetailsActivity extends XmppActivity implements OnConvers
private LinearLayout membersView;
private LinearLayout mMoreDetails;
private TextView mConferenceType;
+ private TableLayout mConferenceInfoTable;
+ private TextView mConferenceInfoMam;
+ private TextView mNotifyStatusText;
private ImageButton mChangeConferenceSettingsButton;
+ private ImageButton mNotifyStatusButton;
private Button mInviteButton;
private String uuid = null;
private User mSelectedUser = null;
@@ -96,17 +102,76 @@ public class ConferenceDetailsActivity extends XmppActivity implements OnConvers
}
};
+
+ private OnClickListener mNotifyStatusClickListener = new OnClickListener() {
+ @Override
+ public void onClick(View v) {
+ AlertDialog.Builder builder = new AlertDialog.Builder(ConferenceDetailsActivity.this);
+ builder.setTitle(R.string.pref_notification_settings);
+ String[] choices = {
+ getString(R.string.notify_on_all_messages),
+ getString(R.string.notify_only_when_highlighted),
+ getString(R.string.notify_never)
+ };
+ final AtomicInteger choice;
+ if (mConversation.getLongAttribute(Conversation.ATTRIBUTE_MUTED_TILL,0) == Long.MAX_VALUE) {
+ choice = new AtomicInteger(2);
+ } else {
+ choice = new AtomicInteger(mConversation.alwaysNotify() ? 0 : 1);
+ }
+ builder.setSingleChoiceItems(choices, choice.get(), new DialogInterface.OnClickListener() {
+ @Override
+ public void onClick(DialogInterface dialog, int which) {
+ choice.set(which);
+ }
+ });
+ builder.setNegativeButton(R.string.cancel, null);
+ builder.setPositiveButton(R.string.ok, new DialogInterface.OnClickListener() {
+ @Override
+ public void onClick(DialogInterface dialog, int which) {
+ if (choice.get() == 2) {
+ mConversation.setMutedTill(Long.MAX_VALUE);
+ } else {
+ mConversation.setMutedTill(0);
+ mConversation.setAttribute(Conversation.ATTRIBUTE_ALWAYS_NOTIFY,String.valueOf(choice.get() == 0));
+ }
+ xmppConnectionService.updateConversation(mConversation);
+ updateView();
+ }
+ });
+ builder.create().show();
+ }
+ };
+
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();
+ final String[] options;
+ final boolean[] values;
+ if (mAdvancedMode) {
+ options = new String[]{
+ getString(R.string.members_only),
+ getString(R.string.moderated),
+ getString(R.string.non_anonymous)
+ };
+ values = new boolean[]{
+ mucOptions.membersOnly(),
+ mucOptions.moderated(),
+ mucOptions.nonanonymous()
+ };
+ } else {
+ options = new String[]{
+ getString(R.string.members_only),
+ getString(R.string.non_anonymous)
+ };
+ values = new boolean[]{
+ mucOptions.membersOnly(),
+ mucOptions.nonanonymous()
+ };
+ }
builder.setMultiChoiceItems(options,values,new DialogInterface.OnMultiChoiceClickListener() {
@Override
public void onClick(DialogInterface dialog, int which, boolean isChecked) {
@@ -124,7 +189,12 @@ public class ConferenceDetailsActivity extends XmppActivity implements OnConvers
}
Bundle options = new Bundle();
options.putString("muc#roomconfig_membersonly", values[0] ? "1" : "0");
- options.putString("muc#roomconfig_whois", values[1] ? "anyone" : "moderators");
+ if (values.length == 2) {
+ options.putString("muc#roomconfig_whois", values[1] ? "anyone" : "moderators");
+ } else if (values.length == 3) {
+ options.putString("muc#roomconfig_moderatedroom", values[1] ? "1" : "0");
+ options.putString("muc#roomconfig_whois", values[2] ? "anyone" : "moderators");
+ }
options.putString("muc#roomconfig_persistentroom", "1");
xmppConnectionService.pushConferenceConfiguration(mConversation,
options,
@@ -171,7 +241,6 @@ public class ConferenceDetailsActivity extends XmppActivity implements OnConvers
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);
@@ -193,6 +262,13 @@ public class ConferenceDetailsActivity extends XmppActivity implements OnConvers
});
}
});
+ this.mAdvancedMode = getPreferences().getBoolean("advanced_muc_mode", false);
+ this.mConferenceInfoTable = (TableLayout) findViewById(R.id.muc_info_more);
+ mConferenceInfoTable.setVisibility(this.mAdvancedMode ? View.VISIBLE : View.GONE);
+ this.mConferenceInfoMam = (TextView) findViewById(R.id.muc_info_mam);
+ this.mNotifyStatusButton = (ImageButton) findViewById(R.id.notification_status_button);
+ this.mNotifyStatusButton.setOnClickListener(this.mNotifyStatusClickListener);
+ this.mNotifyStatusText = (TextView) findViewById(R.id.notification_status_text);
}
@Override
@@ -215,6 +291,8 @@ public class ConferenceDetailsActivity extends XmppActivity implements OnConvers
case R.id.action_advanced_mode:
this.mAdvancedMode = !menuItem.isChecked();
menuItem.setChecked(this.mAdvancedMode);
+ getPreferences().edit().putBoolean("advanced_muc_mode", mAdvancedMode).commit();
+ mConferenceInfoTable.setVisibility(this.mAdvancedMode ? View.VISIBLE : View.GONE);
invalidateOptionsMenu();
updateView();
break;
@@ -236,6 +314,7 @@ public class ConferenceDetailsActivity extends XmppActivity implements OnConvers
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);
+ MenuItem menuItemChangeSubject = menu.findItem(R.id.action_edit_subject);
menuItemAdvancedMode.setChecked(mAdvancedMode);
if (mConversation == null) {
return true;
@@ -248,6 +327,7 @@ public class ConferenceDetailsActivity extends XmppActivity implements OnConvers
menuItemDeleteBookmark.setVisible(false);
menuItemSaveBookmark.setVisible(true);
}
+ menuItemChangeSubject.setVisible(mConversation.getMucOptions().canChangeSubject());
return true;
}
@@ -266,14 +346,17 @@ public class ConferenceDetailsActivity extends XmppActivity implements OnConvers
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);
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 showContactDetails = menu.findItem(R.id.action_contact_details);
MenuItem startConversation = menu.findItem(R.id.start_conversation);
MenuItem giveMembership = menu.findItem(R.id.give_membership);
MenuItem removeMembership = menu.findItem(R.id.remove_membership);
@@ -282,6 +365,9 @@ public class ConferenceDetailsActivity extends XmppActivity implements OnConvers
MenuItem removeFromRoom = menu.findItem(R.id.remove_from_room);
MenuItem banFromConference = menu.findItem(R.id.ban_from_conference);
startConversation.setVisible(true);
+ if (contact != null) {
+ showContactDetails.setVisible(true);
+ }
if (self.getAffiliation().ranks(MucOptions.Affiliation.ADMIN) &&
self.getAffiliation().outranks(user.getAffiliation())) {
if (mAdvancedMode) {
@@ -300,15 +386,24 @@ public class ConferenceDetailsActivity extends XmppActivity implements OnConvers
removeAdminPrivileges.setVisible(true);
}
}
+ } else {
+ MenuItem sendPrivateMessage = menu.findItem(R.id.send_private_message);
+ sendPrivateMessage.setVisible(true);
}
}
- super.onCreateContextMenu(menu,v,menuInfo);
+ super.onCreateContextMenu(menu, v, menuInfo);
}
@Override
public boolean onContextItemSelected(MenuItem item) {
switch (item.getItemId()) {
+ case R.id.action_contact_details:
+ Contact contact = mSelectedUser.getContact();
+ if (contact != null) {
+ switchToContactDetails(contact);
+ }
+ return true;
case R.id.start_conversation:
startConversation(mSelectedUser);
return true;
@@ -331,6 +426,9 @@ public class ConferenceDetailsActivity extends XmppActivity implements OnConvers
xmppConnectionService.changeAffiliationInConference(mConversation,mSelectedUser.getJid(), MucOptions.Affiliation.OUTCAST,this);
xmppConnectionService.changeRoleInConference(mConversation,mSelectedUser.getName(), MucOptions.Role.NONE,this);
return true;
+ case R.id.send_private_message:
+ privateMsgInMuc(mConversation,mSelectedUser.getName());
+ return true;
default:
return super.onContextItemSelected(item);
}
@@ -369,7 +467,8 @@ public class ConferenceDetailsActivity extends XmppActivity implements OnConvers
if (!mConversation.getJid().isBareJid()) {
bookmark.setNick(mConversation.getJid().getResourcepart());
}
- bookmark.setAutojoin(true);
+ bookmark.setBookmarkName(mConversation.getMucOptions().getSubject());
+ bookmark.setAutojoin(getPreferences().getBoolean("autojoin",true));
account.getBookmarks().add(bookmark);
xmppConnectionService.pushBookmarks(account);
mConversation.setBookmark(bookmark);
@@ -404,11 +503,20 @@ public class ConferenceDetailsActivity extends XmppActivity implements OnConvers
private void updateView() {
final MucOptions mucOptions = mConversation.getMucOptions();
final User self = mucOptions.getSelf();
- mAccountJid.setText(getString(R.string.using_account, mConversation
- .getAccount().getJid().toBareJid()));
+ String account;
+ if (Config.DOMAIN_LOCK != null) {
+ account = mConversation.getAccount().getJid().getLocalpart();
+ } else {
+ account = mConversation.getAccount().getJid().toBareJid().toString();
+ }
+ mAccountJid.setText(getString(R.string.using_account, account));
mYourPhoto.setImageBitmap(AvatarService.getInstance().get(mConversation.getAccount(), getPixel(48)));
setTitle(mConversation.getName());
- mFullJid.setText(mConversation.getJid().toBareJid().toString());
+ if (Config.LOCK_DOMAINS_IN_CONVERSATIONS && mConversation.getJid().getDomainpart().equals(Config.CONFERENCE_DOMAIN_LOCK)) {
+ mFullJid.setText(mConversation.getJid().getLocalpart());
+ } else {
+ mFullJid.setText(mConversation.getJid().toBareJid().toString());
+ }
mYourNick.setText(mucOptions.getActualNick());
mRoleAffiliaton = (TextView) findViewById(R.id.muc_role);
if (mucOptions.online()) {
@@ -425,16 +533,36 @@ public class ConferenceDetailsActivity extends XmppActivity implements OnConvers
} else {
mConferenceType.setText(R.string.public_conference);
}
+ if (mucOptions.mamSupport()) {
+ mConferenceInfoMam.setText(R.string.server_info_available);
+ } else {
+ mConferenceInfoMam.setText(R.string.server_info_unavailable);
+ }
if (self.getAffiliation().ranks(MucOptions.Affiliation.OWNER)) {
mChangeConferenceSettingsButton.setVisibility(View.VISIBLE);
} else {
mChangeConferenceSettingsButton.setVisibility(View.GONE);
}
}
+
+ long mutedTill = mConversation.getLongAttribute(Conversation.ATTRIBUTE_MUTED_TILL,0);
+ if (mutedTill == Long.MAX_VALUE) {
+ mNotifyStatusText.setText(R.string.notify_never);
+ mNotifyStatusButton.setImageResource(R.drawable.ic_notifications_off_grey600_24dp);
+ } else if (System.currentTimeMillis() < mutedTill) {
+ mNotifyStatusText.setText(R.string.notify_paused);
+ mNotifyStatusButton.setImageResource(R.drawable.ic_notifications_paused_grey600_24dp);
+ } else if (mConversation.alwaysNotify()) {
+ mNotifyStatusButton.setImageResource(R.drawable.ic_notifications_grey600_24dp);
+ mNotifyStatusText.setText(R.string.notify_on_all_messages);
+ } else {
+ mNotifyStatusButton.setImageResource(R.drawable.ic_notifications_none_grey600_24dp);
+ mNotifyStatusText.setText(R.string.notify_only_when_highlighted);
+ }
+
LayoutInflater inflater = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE);
membersView.removeAllViews();
- final ArrayList<User> users = new ArrayList<>();
- users.addAll(mConversation.getMucOptions().getUsers());
+ final ArrayList<User> users = mucOptions.getUsers();
Collections.sort(users,new Comparator<User>() {
@Override
public int compare(User lhs, User rhs) {
@@ -466,20 +594,17 @@ public class ConferenceDetailsActivity extends XmppActivity implements OnConvers
});
tvKey.setText(OpenPgpUtils.convertKeyIdToHex(user.getPgpKeyId()));
}
- Bitmap bm;
Contact contact = user.getContact();
if (contact != null) {
- bm = AvatarService.getInstance().get(contact, getPixel(48));
tvDisplayName.setText(contact.getDisplayName());
tvStatus.setText(user.getName() + " \u2022 " + getStatus(user));
} else {
- bm = AvatarService.getInstance().get(user.getName(), getPixel(48));
tvDisplayName.setText(user.getName());
tvStatus.setText(getStatus(user));
}
ImageView iv = (ImageView) view.findViewById(R.id.contact_photo);
- iv.setImageBitmap(bm);
+ iv.setImageBitmap(AvatarService.getInstance().get(user, getPixel(48), false));
membersView.addView(view);
if (mConversation.getMucOptions().canInvite()) {
mInviteButton.setVisibility(View.VISIBLE);
diff --git a/src/main/java/de/thedevstack/conversationsplus/ui/ContactDetailsActivity.java b/src/main/java/de/thedevstack/conversationsplus/ui/ContactDetailsActivity.java
index a61d0b4b..aaa19fc5 100644
--- a/src/main/java/de/thedevstack/conversationsplus/ui/ContactDetailsActivity.java
+++ b/src/main/java/de/thedevstack/conversationsplus/ui/ContactDetailsActivity.java
@@ -25,29 +25,35 @@ import android.widget.ImageButton;
import android.widget.LinearLayout;
import android.widget.QuickContactBadge;
import android.widget.TextView;
+import android.widget.Toast;
import org.openintents.openpgp.util.OpenPgpUtils;
+import java.security.cert.X509Certificate;
import java.util.List;
import de.thedevstack.conversationsplus.ConversationsPlusPreferences;
+import de.thedevstack.conversationsplus.ui.listeners.ShowResourcesListDialogListener;
+import de.thedevstack.conversationsplus.Config;
import de.thedevstack.conversationsplus.R;
import de.thedevstack.conversationsplus.crypto.PgpEngine;
+import de.thedevstack.conversationsplus.crypto.axolotl.AxolotlService;
+import de.thedevstack.conversationsplus.crypto.axolotl.XmppAxolotlSession;
import de.thedevstack.conversationsplus.entities.Account;
import de.thedevstack.conversationsplus.entities.Contact;
import de.thedevstack.conversationsplus.entities.ListItem;
import de.thedevstack.conversationsplus.services.AvatarService;
import de.thedevstack.conversationsplus.services.XmppConnectionService.OnAccountUpdate;
import de.thedevstack.conversationsplus.services.XmppConnectionService.OnRosterUpdate;
-import de.thedevstack.conversationsplus.ui.listeners.ShowResourcesListDialogListener;
import de.thedevstack.conversationsplus.utils.CryptoHelper;
import de.thedevstack.conversationsplus.utils.UIHelper;
+import de.thedevstack.conversationsplus.xmpp.OnKeyStatusUpdated;
import de.thedevstack.conversationsplus.xmpp.OnUpdateBlocklist;
import de.thedevstack.conversationsplus.xmpp.XmppConnection;
import de.thedevstack.conversationsplus.xmpp.jid.InvalidJidException;
import de.thedevstack.conversationsplus.xmpp.jid.Jid;
-public class ContactDetailsActivity extends XmppActivity implements OnAccountUpdate, OnRosterUpdate, OnUpdateBlocklist {
+public class ContactDetailsActivity extends XmppActivity implements OnAccountUpdate, OnRosterUpdate, OnUpdateBlocklist, OnKeyStatusUpdated {
public static final String ACTION_VIEW_CONTACT = "view_contact";
private Contact contact;
@@ -109,6 +115,7 @@ public class ContactDetailsActivity extends XmppActivity implements OnAccountUpd
private LinearLayout keys;
private LinearLayout tags;
private boolean showDynamicTags;
+ private String messageFingerprint;
private DialogInterface.OnClickListener addToPhonebook = new DialogInterface.OnClickListener() {
@@ -133,7 +140,7 @@ public class ContactDetailsActivity extends XmppActivity implements OnAccountUpd
ContactDetailsActivity.this);
builder.setTitle(getString(R.string.action_add_phone_book));
builder.setMessage(getString(R.string.add_phone_book_text,
- contact.getJid()));
+ contact.getDisplayJid()));
builder.setNegativeButton(getString(R.string.cancel), null);
builder.setPositiveButton(getString(R.string.add), addToPhonebook);
builder.create().show();
@@ -159,6 +166,11 @@ public class ContactDetailsActivity extends XmppActivity implements OnAccountUpd
}
@Override
+ public void OnUpdateBlocklist(final Status status) {
+ refreshUi();
+ }
+
+ @Override
protected void refreshUiReal() {
invalidateOptionsMenu();
populateView();
@@ -178,7 +190,7 @@ public class ContactDetailsActivity extends XmppActivity implements OnAccountUpd
super.onCreate(savedInstanceState);
if (getIntent().getAction().equals(ACTION_VIEW_CONTACT)) {
try {
- this.accountJid = Jid.fromString(getIntent().getExtras().getString("account"));
+ this.accountJid = Jid.fromString(getIntent().getExtras().getString(EXTRA_ACCOUNT));
} catch (final InvalidJidException ignored) {
}
try {
@@ -186,6 +198,7 @@ public class ContactDetailsActivity extends XmppActivity implements OnAccountUpd
} catch (final InvalidJidException ignored) {
}
}
+ this.messageFingerprint = getIntent().getStringExtra("fingerprint");
setContentView(R.layout.activity_contact_details);
contactJidTv = (TextView) findViewById(R.id.details_contactjid);
@@ -223,7 +236,7 @@ public class ContactDetailsActivity extends XmppActivity implements OnAccountUpd
builder.setTitle(getString(R.string.action_delete_contact))
.setMessage(
getString(R.string.remove_contact_text,
- contact.getJid()))
+ contact.getDisplayJid()))
.setPositiveButton(getString(R.string.delete),
removeFromRoster).create().show();
break;
@@ -345,13 +358,19 @@ public class ContactDetailsActivity extends XmppActivity implements OnAccountUpd
}
if (contact.getPresences().size() > 1) {
- contactJidTv.setText(contact.getJid() + " ("
+ contactJidTv.setText(contact.getDisplayJid() + " ("
+ contact.getPresences().size() + ")");
} else {
- contactJidTv.setText(contact.getJid().toString());
+ contactJidTv.setText(contact.getDisplayJid());
+ }
+ String account;
+ if (Config.DOMAIN_LOCK != null) {
+ account = contact.getAccount().getJid().getLocalpart();
+ } else {
+ account = contact.getAccount().getJid().toBareJid().toString();
}
contactJidTv.setOnClickListener(new ShowResourcesListDialogListener(ContactDetailsActivity.this, contact));
- accountJidTv.setText(getString(R.string.using_account, contact.getAccount().getJid().toBareJid()));
+ accountJidTv.setText(getString(R.string.using_account, account));
badge.setImageBitmap(AvatarService.getInstance().get(contact, getPixel(72)));
badge.setOnClickListener(this.onBadgeClick);
@@ -363,13 +382,13 @@ public class ContactDetailsActivity extends XmppActivity implements OnAccountUpd
View view = inflater.inflate(R.layout.contact_key, keys, false);
TextView key = (TextView) view.findViewById(R.id.key);
TextView keyType = (TextView) view.findViewById(R.id.key_type);
- ImageButton remove = (ImageButton) view
+ ImageButton removeButton = (ImageButton) view
.findViewById(R.id.button_remove);
- remove.setVisibility(View.VISIBLE);
+ removeButton.setVisibility(View.VISIBLE);
keyType.setText("OTR Fingerprint");
key.setText(CryptoHelper.prettifyFingerprint(otrFingerprint));
keys.addView(view);
- remove.setOnClickListener(new OnClickListener() {
+ removeButton.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
@@ -377,6 +396,15 @@ public class ContactDetailsActivity extends XmppActivity implements OnAccountUpd
}
});
}
+ for (final String fingerprint : contact.getAccount().getAxolotlService().getFingerprintsForContact(contact)) {
+ boolean highlight = fingerprint.equals(messageFingerprint);
+ hasKeys |= addFingerprintRow(keys, contact.getAccount(), fingerprint, highlight, new OnClickListener() {
+ @Override
+ public void onClick(View v) {
+ onOmemoKeyClicked(contact.getAccount(), fingerprint);
+ }
+ });
+ }
if (contact.getPgpKeyId() != 0) {
hasKeys = true;
View view = inflater.inflate(R.layout.contact_key, keys, false);
@@ -427,6 +455,40 @@ public class ContactDetailsActivity extends XmppActivity implements OnAccountUpd
}
}
+ private void onOmemoKeyClicked(Account account, String fingerprint) {
+ final XmppAxolotlSession.Trust trust = account.getAxolotlService().getFingerprintTrust(fingerprint);
+ if (trust != null && trust == XmppAxolotlSession.Trust.TRUSTED_X509) {
+ X509Certificate x509Certificate = account.getAxolotlService().getFingerprintCertificate(fingerprint);
+ if (x509Certificate != null) {
+ showCertificateInformationDialog(CryptoHelper.extractCertificateInformation(x509Certificate));
+ } else {
+ Toast.makeText(this,R.string.certificate_not_found, Toast.LENGTH_SHORT).show();
+ }
+ }
+ }
+
+ private void showCertificateInformationDialog(Bundle bundle) {
+ View view = getLayoutInflater().inflate(R.layout.certificate_information, null);
+ final String not_available = getString(R.string.certicate_info_not_available);
+ TextView subject_cn = (TextView) view.findViewById(R.id.subject_cn);
+ TextView subject_o = (TextView) view.findViewById(R.id.subject_o);
+ TextView issuer_cn = (TextView) view.findViewById(R.id.issuer_cn);
+ TextView issuer_o = (TextView) view.findViewById(R.id.issuer_o);
+ TextView sha1 = (TextView) view.findViewById(R.id.sha1);
+
+ subject_cn.setText(bundle.getString("subject_cn", not_available));
+ subject_o.setText(bundle.getString("subject_o", not_available));
+ issuer_cn.setText(bundle.getString("issuer_cn", not_available));
+ issuer_o.setText(bundle.getString("issuer_o", not_available));
+ sha1.setText(bundle.getString("sha1", not_available));
+
+ AlertDialog.Builder builder = new AlertDialog.Builder(this);
+ builder.setTitle(R.string.certificate_information);
+ builder.setView(view);
+ builder.setPositiveButton(R.string.ok, null);
+ builder.create().show();
+ }
+
protected void confirmToDeleteFingerprint(final String fingerprint) {
AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder.setTitle(R.string.delete_fingerprint);
@@ -461,14 +523,7 @@ public class ContactDetailsActivity extends XmppActivity implements OnAccountUpd
}
@Override
- public void OnUpdateBlocklist(final Status status) {
- runOnUiThread(new Runnable() {
-
- @Override
- public void run() {
- invalidateOptionsMenu();
- populateView();
- }
- });
+ public void onKeyStatusUpdated(AxolotlService.FetchStatus report) {
+ refreshUi();
}
}
diff --git a/src/main/java/de/thedevstack/conversationsplus/ui/ConversationActivity.java b/src/main/java/de/thedevstack/conversationsplus/ui/ConversationActivity.java
index 94d1e2ea..1a4ccb8c 100644
--- a/src/main/java/de/thedevstack/conversationsplus/ui/ConversationActivity.java
+++ b/src/main/java/de/thedevstack/conversationsplus/ui/ConversationActivity.java
@@ -10,14 +10,21 @@ import android.content.DialogInterface;
import android.content.DialogInterface.OnClickListener;
import android.content.Intent;
import android.content.IntentSender.SendIntentException;
+import android.content.pm.PackageManager;
import android.net.Uri;
import android.os.Build;
import android.os.Bundle;
import android.provider.MediaStore;
+import android.provider.Settings;
import android.support.v4.widget.SlidingPaneLayout;
import android.support.v4.widget.SlidingPaneLayout.PanelSlideListener;
+import android.util.Log;
+import android.util.Pair;
+import android.view.Gravity;
+import android.view.KeyEvent;
import android.view.Menu;
import android.view.MenuItem;
+import android.view.Surface;
import android.view.View;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
@@ -29,22 +36,29 @@ import android.widget.Toast;
import net.java.otr4j.session.SessionStatus;
-import de.thedevstack.conversationsplus.ConversationsPlusPreferences;
-import de.thedevstack.conversationsplus.persistance.FileBackend;
-import de.thedevstack.conversationsplus.ui.dialogs.UserDecisionDialog;
-import de.thedevstack.conversationsplus.ui.listeners.ResizePictureUserDecisionListener;
-import de.timroes.android.listview.EnhancedListView;
+import org.openintents.openpgp.util.OpenPgpApi;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
+import java.util.concurrent.atomic.AtomicBoolean;
+import de.thedevstack.conversationsplus.ConversationsPlusPreferences;
+import de.thedevstack.conversationsplus.ui.dialogs.UserDecisionDialog;
+import de.thedevstack.conversationsplus.ui.listeners.ResizePictureUserDecisionListener;
+import de.timroes.android.listview.EnhancedListView;
+import de.thedevstack.conversationsplus.Config;
import de.thedevstack.conversationsplus.R;
+import de.thedevstack.conversationsplus.crypto.axolotl.AxolotlService;
+import de.thedevstack.conversationsplus.crypto.axolotl.AxolotlServiceImpl;
+import de.thedevstack.conversationsplus.crypto.axolotl.XmppAxolotlSession;
import de.thedevstack.conversationsplus.entities.Account;
import de.thedevstack.conversationsplus.entities.Blockable;
import de.thedevstack.conversationsplus.entities.Contact;
import de.thedevstack.conversationsplus.entities.Conversation;
import de.thedevstack.conversationsplus.entities.Message;
+import de.thedevstack.conversationsplus.entities.Transferable;
+import de.thedevstack.conversationsplus.persistance.FileBackend;
import de.thedevstack.conversationsplus.services.XmppConnectionService;
import de.thedevstack.conversationsplus.services.XmppConnectionService.OnAccountUpdate;
import de.thedevstack.conversationsplus.services.XmppConnectionService.OnConversationUpdate;
@@ -52,26 +66,33 @@ import de.thedevstack.conversationsplus.services.XmppConnectionService.OnRosterU
import de.thedevstack.conversationsplus.ui.adapter.ConversationAdapter;
import de.thedevstack.conversationsplus.utils.ExceptionHelper;
import de.thedevstack.conversationsplus.xmpp.OnUpdateBlocklist;
+import de.thedevstack.conversationsplus.xmpp.jid.InvalidJidException;
+import de.thedevstack.conversationsplus.xmpp.jid.Jid;
public class ConversationActivity extends XmppActivity
implements OnAccountUpdate, OnConversationUpdate, OnRosterUpdate, OnUpdateBlocklist, XmppConnectionService.OnShowErrorToast {
- public static final String ACTION_DOWNLOAD = "de.thedevstack.conversationsplus.action.DOWNLOAD";
+ 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";
+ public static final String PRIVATE_MESSAGE = "pm";
public static final int REQUEST_SEND_MESSAGE = 0x0201;
public static final int REQUEST_DECRYPT_PGP = 0x0202;
public static final int REQUEST_ENCRYPT_MESSAGE = 0x0207;
+ public static final int REQUEST_TRUST_KEYS_TEXT = 0x0208;
+ public static final int REQUEST_TRUST_KEYS_MENU = 0x0209;
+ public static final int REQUEST_START_DOWNLOAD = 0x0210;
public static final int ATTACHMENT_CHOICE_CHOOSE_IMAGE = 0x0301;
public static final int ATTACHMENT_CHOICE_TAKE_PHOTO = 0x0302;
public static final int ATTACHMENT_CHOICE_CHOOSE_FILE = 0x0303;
public static final int ATTACHMENT_CHOICE_RECORD_VOICE = 0x0304;
public static final int ATTACHMENT_CHOICE_LOCATION = 0x0305;
+ public static final int ATTACHMENT_CHOICE_INVALID = 0x0306;
private static final String STATE_OPEN_CONVERSATION = "state_open_conversation";
private static final String STATE_PANEL_OPEN = "state_panel_open";
private static final String STATE_PENDING_URI = "state_pending_uri";
@@ -81,6 +102,10 @@ public class ConversationActivity extends XmppActivity
final private List<Uri> mPendingImageUris = new ArrayList<>();
final private List<Uri> mPendingFileUris = new ArrayList<>();
private Uri mPendingGeoUri = null;
+ private boolean forbidProcessingPendings = false;
+ private Message mPendingDownloadableMessage = null;
+
+ private boolean conversationWasSelectedByKeyboard = false;
private View mContentView;
@@ -92,10 +117,9 @@ public class ConversationActivity extends XmppActivity
private ArrayAdapter<Conversation> listAdapter;
- private Toast prepareFileToast;
-
private boolean mActivityPaused = false;
- private boolean mRedirected = true;
+ private AtomicBoolean mRedirected = new AtomicBoolean(false);
+ private Pair<Integer, Intent> mPostponedActivityResult;
public Conversation getSelectedConversation() {
return this.mSelectedConversation;
@@ -131,8 +155,7 @@ public class ConversationActivity extends XmppActivity
public boolean isConversationsOverviewHideable() {
if (mContentView instanceof SlidingPaneLayout) {
- SlidingPaneLayout mSlidingPaneLayout = (SlidingPaneLayout) mContentView;
- return mSlidingPaneLayout.isSlideable();
+ return true;
} else {
return false;
}
@@ -180,10 +203,11 @@ public class ConversationActivity extends XmppActivity
@Override
public void onItemClick(AdapterView<?> arg0, View clickedView,
- int position, long arg3) {
+ int position, long arg3) {
if (getSelectedConversation() != conversationList.get(position)) {
setSelectedConversation(conversationList.get(position));
ConversationActivity.this.mConversationFragment.reInit(getSelectedConversation());
+ conversationWasSelectedByKeyboard = false;
}
hideConversationsOverview();
openConversation();
@@ -192,64 +216,67 @@ public class ConversationActivity extends XmppActivity
listView.setDismissCallback(new EnhancedListView.OnDismissCallback() {
- @Override
- public EnhancedListView.Undoable onDismiss(final EnhancedListView enhancedListView, final int position) {
-
- final int index = listView.getFirstVisiblePosition();
- View v = listView.getChildAt(0);
- final int top = (v == null) ? 0 : (v.getTop() - listView.getPaddingTop());
-
- swipedConversation = listAdapter.getItem(position);
- listAdapter.remove(swipedConversation);
- swipedConversation.markRead();
- xmppConnectionService.getNotificationService().clear(swipedConversation);
-
- final boolean formerlySelected = (getSelectedConversation() == swipedConversation);
- if (position == 0 && listAdapter.getCount() == 0) {
- endConversation(swipedConversation, false, true);
- return null;
- } else if (formerlySelected) {
- setSelectedConversation(listAdapter.getItem(0));
- ConversationActivity.this.mConversationFragment
- .reInit(getSelectedConversation());
- }
+ @Override
+ public EnhancedListView.Undoable onDismiss(final EnhancedListView enhancedListView, final int position) {
- return new EnhancedListView.Undoable() {
+ final int index = listView.getFirstVisiblePosition();
+ View v = listView.getChildAt(0);
+ final int top = (v == null) ? 0 : (v.getTop() - listView.getPaddingTop());
- @Override
- public void undo() {
- listAdapter.insert(swipedConversation, position);
- if (formerlySelected) {
- setSelectedConversation(swipedConversation);
- ConversationActivity.this.mConversationFragment
- .reInit(getSelectedConversation());
- }
- swipedConversation = null;
- listView.setSelectionFromTop(index + (listView.getChildCount() < position ? 1 : 0), top);
- }
+ try {
+ swipedConversation = listAdapter.getItem(position);
+ } catch (IndexOutOfBoundsException e) {
+ return null;
+ }
+ listAdapter.remove(swipedConversation);
+ xmppConnectionService.markRead(swipedConversation);
+
+ final boolean formerlySelected = (getSelectedConversation() == swipedConversation);
+ if (position == 0 && listAdapter.getCount() == 0) {
+ endConversation(swipedConversation, false, true);
+ return null;
+ } else if (formerlySelected) {
+ setSelectedConversation(listAdapter.getItem(0));
+ ConversationActivity.this.mConversationFragment
+ .reInit(getSelectedConversation());
+ }
- @Override
- public void discard() {
- if (!swipedConversation.isRead()
- && swipedConversation.getMode() == Conversation.MODE_SINGLE) {
- swipedConversation = null;
- return;
- }
- endConversation(swipedConversation, false, false);
- swipedConversation = null;
- }
+ return new EnhancedListView.Undoable() {
- @Override
- public String getTitle() {
- if (swipedConversation.getMode() == Conversation.MODE_MULTI) {
- return getResources().getString(R.string.title_undo_swipe_out_muc);
- } else {
- return getResources().getString(R.string.title_undo_swipe_out_conversation);
- }
- }
- };
- }
- });
+ @Override
+ public void undo() {
+ listAdapter.insert(swipedConversation, position);
+ if (formerlySelected) {
+ setSelectedConversation(swipedConversation);
+ ConversationActivity.this.mConversationFragment
+ .reInit(getSelectedConversation());
+ }
+ swipedConversation = null;
+ listView.setSelectionFromTop(index + (listView.getChildCount() < position ? 1 : 0), top);
+ }
+
+ @Override
+ public void discard() {
+ if (!swipedConversation.isRead()
+ && swipedConversation.getMode() == Conversation.MODE_SINGLE) {
+ swipedConversation = null;
+ return;
+ }
+ endConversation(swipedConversation, false, false);
+ swipedConversation = null;
+ }
+
+ @Override
+ public String getTitle() {
+ if (swipedConversation.getMode() == Conversation.MODE_MULTI) {
+ return getResources().getString(R.string.title_undo_swipe_out_muc);
+ } else {
+ return getResources().getString(R.string.title_undo_swipe_out_conversation);
+ }
+ }
+ };
+ }
+ });
listView.enableSwipeToDismiss();
listView.setSwipeDirection(EnhancedListView.SwipeDirection.START);
listView.setSwipingLayout(R.id.swipeable_item);
@@ -277,7 +304,7 @@ public class ConversationActivity extends XmppActivity
hideKeyboard();
if (xmppConnectionServiceBound) {
xmppConnectionService.getNotificationService()
- .setOpenConversation(null);
+ .setOpenConversation(null);
}
closeContextMenu();
}
@@ -301,12 +328,12 @@ public class ConversationActivity extends XmppActivity
public void switchToConversation(Conversation conversation) {
setSelectedConversation(conversation);
runOnUiThread(new Runnable() {
- @Override
- public void run() {
- ConversationActivity.this.mConversationFragment.reInit(getSelectedConversation());
- openConversation();
- }
- });
+ @Override
+ public void run() {
+ ConversationActivity.this.mConversationFragment.reInit(getSelectedConversation());
+ openConversation();
+ }
+ });
}
private void updateActionBarTitle() {
@@ -346,11 +373,7 @@ public class ConversationActivity extends XmppActivity
public void sendReadMarkerIfNecessary(final Conversation conversation) {
if (!mActivityPaused && conversation != null) {
- if (!conversation.isRead()) {
- xmppConnectionService.sendReadMarker(conversation);
- } else {
- xmppConnectionService.markRead(conversation);
- }
+ xmppConnectionService.sendReadMarker(conversation);
}
}
@@ -381,7 +404,7 @@ public class ConversationActivity extends XmppActivity
} else {
menuAdd.setVisible(!isConversationsOverviewHideable());
if (this.getSelectedConversation() != null) {
- if (this.getSelectedConversation().getNextEncryption(ConversationsPlusPreferences.forceEncryption()) != Message.ENCRYPTION_NONE) {
+ if (this.getSelectedConversation().getNextEncryption() != Message.ENCRYPTION_NONE) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
menuSecure.setIcon(R.drawable.ic_lock_white_24dp);
} else {
@@ -390,10 +413,12 @@ public class ConversationActivity extends XmppActivity
}
if (this.getSelectedConversation().getMode() == Conversation.MODE_MULTI) {
menuContactDetails.setVisible(false);
- menuAttach.setVisible(getSelectedConversation().getAccount().httpUploadAvailable());
+ menuAttach.setVisible(getSelectedConversation().getAccount().httpUploadAvailable() && getSelectedConversation().getMucOptions().participating());
menuInviteContact.setVisible(getSelectedConversation().getMucOptions().canInvite());
+ menuSecure.setVisible(Config.supportOpenPgp() && Config.multipleEncryptionChoices()); //only if pgp is supported we have a choice
} else {
menuMucDetails.setVisible(false);
+ menuSecure.setVisible(Config.multipleEncryptionChoices());
}
if (this.getSelectedConversation().isMuted()) {
menuMute.setVisible(false);
@@ -405,7 +430,7 @@ public class ConversationActivity extends XmppActivity
return true;
}
- private void selectPresenceToAttachFile(final int attachmentChoice, final int encryption) {
+ protected void selectPresenceToAttachFile(final int attachmentChoice, final int encryption) {
final Conversation conversation = getSelectedConversation();
final Account account = conversation.getAccount();
final OnPresenceSelected callback = new OnPresenceSelected() {
@@ -419,7 +444,7 @@ public class ConversationActivity extends XmppActivity
case ATTACHMENT_CHOICE_CHOOSE_IMAGE:
intent.setAction(Intent.ACTION_GET_CONTENT);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR2) {
- intent.putExtra(Intent.EXTRA_ALLOW_MULTIPLE,true);
+ intent.putExtra(Intent.EXTRA_ALLOW_MULTIPLE, true);
}
intent.setType("image/*");
chooser = true;
@@ -439,11 +464,11 @@ public class ConversationActivity extends XmppActivity
break;
case ATTACHMENT_CHOICE_RECORD_VOICE:
intent.setAction(MediaStore.Audio.Media.RECORD_SOUND_ACTION);
- fallbackPackageId = "de.thedevstack.conversationsplus.voicerecorder";
+ fallbackPackageId = "eu.siacs.conversations.voicerecorder";
break;
case ATTACHMENT_CHOICE_LOCATION:
- intent.setAction("de.thedevstack.conversationsplus.location.request");
- fallbackPackageId = "de.thedevstack.conversationsplus.sharelocation";
+ intent.setAction("eu.siacs.conversations.location.request");
+ fallbackPackageId = "eu.siacs.conversations.sharelocation";
break;
}
if (intent.resolveActivity(getPackageManager()) != null) {
@@ -469,7 +494,7 @@ public class ConversationActivity extends XmppActivity
private Intent getInstallApkIntent(final String packageId) {
Intent intent = new Intent(Intent.ACTION_VIEW);
- intent.setData(Uri.parse("market://details?id="+packageId));
+ intent.setData(Uri.parse("market://details?id=" + packageId));
if (intent.resolveActivity(getPackageManager()) != null) {
return intent;
} else {
@@ -479,6 +504,11 @@ public class ConversationActivity extends XmppActivity
}
public void attachFile(final int attachmentChoice) {
+ if (attachmentChoice != ATTACHMENT_CHOICE_LOCATION) {
+ if (!hasStoragePermission(attachmentChoice)) {
+ return;
+ }
+ }
switch (attachmentChoice) {
case ATTACHMENT_CHOICE_LOCATION:
ConversationsPlusPreferences.applyRecentlyUsedQuickAction("location");
@@ -494,23 +524,23 @@ public class ConversationActivity extends XmppActivity
break;
}
final Conversation conversation = getSelectedConversation();
- final int encryption = conversation.getNextEncryption(ConversationsPlusPreferences.forceEncryption());
+ final int encryption = conversation.getNextEncryption();
+ final int mode = conversation.getMode();
if (encryption == Message.ENCRYPTION_PGP) {
if (hasPgp()) {
- if (conversation.getContact().getPgpKeyId() != 0) {
+ if (mode == Conversation.MODE_SINGLE && conversation.getContact().getPgpKeyId() != 0) {
xmppConnectionService.getPgpEngine().hasKey(
conversation.getContact(),
new UiCallback<Contact>() {
@Override
- public void userInputRequried(PendingIntent pi,
- Contact contact) {
- ConversationActivity.this.runIntent(pi,attachmentChoice);
+ public void userInputRequried(PendingIntent pi, Contact contact) {
+ ConversationActivity.this.runIntent(pi, attachmentChoice);
}
@Override
public void success(Contact contact) {
- selectPresenceToAttachFile(attachmentChoice,encryption);
+ selectPresenceToAttachFile(attachmentChoice, encryption);
}
@Override
@@ -518,21 +548,31 @@ public class ConversationActivity extends XmppActivity
displayErrorDialog(error);
}
});
+ } else if (mode == Conversation.MODE_MULTI && conversation.getMucOptions().pgpKeysInUse()) {
+ if (!conversation.getMucOptions().everybodyHasKeys()) {
+ Toast warning = Toast
+ .makeText(this,
+ R.string.missing_public_keys,
+ Toast.LENGTH_LONG);
+ warning.setGravity(Gravity.CENTER_VERTICAL, 0, 0);
+ warning.show();
+ }
+ selectPresenceToAttachFile(attachmentChoice, encryption);
} else {
final ConversationFragment fragment = (ConversationFragment) getFragmentManager()
- .findFragmentByTag("conversation");
+ .findFragmentByTag("conversation");
if (fragment != null) {
fragment.showNoPGPKeyDialog(false,
new OnClickListener() {
@Override
public void onClick(DialogInterface dialog,
- int which) {
+ int which) {
conversation
- .setNextEncryption(Message.ENCRYPTION_NONE);
+ .setNextEncryption(Message.ENCRYPTION_NONE);
xmppConnectionService.databaseBackend
- .updateConversation(conversation);
- selectPresenceToAttachFile(attachmentChoice,Message.ENCRYPTION_NONE);
+ .updateConversation(conversation);
+ selectPresenceToAttachFile(attachmentChoice, Message.ENCRYPTION_NONE);
}
});
}
@@ -541,7 +581,40 @@ public class ConversationActivity extends XmppActivity
showInstallPgpDialog();
}
} else {
- selectPresenceToAttachFile(attachmentChoice, encryption);
+ if (encryption != Message.ENCRYPTION_AXOLOTL || !trustKeysIfNeeded(REQUEST_TRUST_KEYS_MENU, attachmentChoice)) {
+ selectPresenceToAttachFile(attachmentChoice, encryption);
+ }
+ }
+ }
+
+ @Override
+ public void onRequestPermissionsResult(int requestCode, String permissions[], int[] grantResults) {
+ if (grantResults.length > 0)
+ if (grantResults[0] == PackageManager.PERMISSION_GRANTED) {
+ if (requestCode == REQUEST_START_DOWNLOAD) {
+ if (this.mPendingDownloadableMessage != null) {
+ startDownloadable(this.mPendingDownloadableMessage);
+ }
+ } else {
+ attachFile(requestCode);
+ }
+ } else {
+ Toast.makeText(this, R.string.no_storage_permission, Toast.LENGTH_SHORT).show();
+ }
+ }
+
+ public void startDownloadable(Message message) {
+ if (!hasStoragePermission(ConversationActivity.REQUEST_START_DOWNLOAD)) {
+ this.mPendingDownloadableMessage = message;
+ return;
+ }
+ Transferable transferable = message.getTransferable();
+ if (transferable != null) {
+ if (!transferable.start()) {
+ Toast.makeText(this, R.string.not_connected_try_again, Toast.LENGTH_SHORT).show();
+ }
+ } else if (message.treatAsDownloadable() != Message.Decision.NEVER) {
+ xmppConnectionService.getHttpConnectionManager().createNewDownloadConnection(message, true);
}
}
@@ -616,6 +689,12 @@ public class ConversationActivity extends XmppActivity
this.mConversationFragment.reInit(getSelectedConversation());
} else {
setSelectedConversation(null);
+ if (mRedirected.compareAndSet(false, true)) {
+ Intent intent = new Intent(this, StartConversationActivity.class);
+ intent.putExtra("init", true);
+ startActivity(intent);
+ finish();
+ }
}
}
}
@@ -627,23 +706,23 @@ public class ConversationActivity extends XmppActivity
View dialogView = getLayoutInflater().inflate(
R.layout.dialog_clear_history, null);
final CheckBox endConversationCheckBox = (CheckBox) dialogView
- .findViewById(R.id.end_conversation_checkbox);
+ .findViewById(R.id.end_conversation_checkbox);
builder.setView(dialogView);
builder.setNegativeButton(getString(R.string.cancel), null);
builder.setPositiveButton(getString(R.string.delete_messages),
- new OnClickListener() {
+ new OnClickListener() {
- @Override
- public void onClick(DialogInterface dialog, int which) {
- ConversationActivity.this.xmppConnectionService.clearConversationHistory(conversation);
- if (endConversationCheckBox.isChecked()) {
- endConversation(conversation);
- } else {
- updateConversationList();
- ConversationActivity.this.mConversationFragment.updateMessages();
- }
- }
- });
+ @Override
+ public void onClick(DialogInterface dialog, int which) {
+ ConversationActivity.this.xmppConnectionService.clearConversationHistory(conversation);
+ if (endConversationCheckBox.isChecked()) {
+ endConversation(conversation);
+ } else {
+ updateConversationList();
+ ConversationActivity.this.mConversationFragment.updateMessages();
+ }
+ }
+ });
builder.create().show();
}
@@ -657,7 +736,7 @@ public class ConversationActivity extends XmppActivity
if (new Intent(MediaStore.Audio.Media.RECORD_SOUND_ACTION).resolveActivity(getPackageManager()) == null) {
attachFilePopup.getMenu().findItem(R.id.attach_record_voice).setVisible(false);
}
- if (new Intent("de.thedevstack.conversationsplus.location.request").resolveActivity(getPackageManager()) == null) {
+ if (new Intent("eu.siacs.conversations.location.request").resolveActivity(getPackageManager()) == null) {
attachFilePopup.getMenu().findItem(R.id.attach_location).setVisible(false);
}
attachFilePopup.setOnMenuItemClickListener(new OnMenuItemClickListener() {
@@ -703,7 +782,7 @@ public class ConversationActivity extends XmppActivity
Intent intent = new Intent(ConversationActivity.this, VerifyOTRActivity.class);
intent.setAction(VerifyOTRActivity.ACTION_VERIFY_CONTACT);
intent.putExtra("contact", conversation.getContact().getJid().toBareJid().toString());
- intent.putExtra("account", conversation.getAccount().getJid().toBareJid().toString());
+ intent.putExtra(EXTRA_ACCOUNT, conversation.getAccount().getJid().toBareJid().toString());
switch (menuItem.getItemId()) {
case R.id.scan_fingerprint:
intent.putExtra("mode", VerifyOTRActivity.MODE_SCAN_FINGERPRINT);
@@ -729,7 +808,7 @@ public class ConversationActivity extends XmppActivity
}
PopupMenu popup = new PopupMenu(this, menuItemView);
final ConversationFragment fragment = (ConversationFragment) getFragmentManager()
- .findFragmentByTag("conversation");
+ .findFragmentByTag("conversation");
if (fragment != null) {
popup.setOnMenuItemClickListener(new OnMenuItemClickListener() {
@@ -746,16 +825,22 @@ public class ConversationActivity extends XmppActivity
break;
case R.id.encryption_choice_pgp:
if (hasPgp()) {
- if (conversation.getAccount().getKeys().has("pgp_signature")) {
+ if (conversation.getAccount().getPgpSignature() != null) {
conversation.setNextEncryption(Message.ENCRYPTION_PGP);
item.setChecked(true);
} else {
- announcePgp(conversation.getAccount(),conversation);
+ announcePgp(conversation.getAccount(), conversation);
}
} else {
showInstallPgpDialog();
}
break;
+ case R.id.encryption_choice_axolotl:
+ Log.d(Config.LOGTAG, AxolotlServiceImpl.getLogprefix(conversation.getAccount())
+ + "Enabled axolotl for Contact " + conversation.getContact().getJid());
+ conversation.setNextEncryption(Message.ENCRYPTION_AXOLOTL);
+ item.setChecked(true);
+ break;
default:
conversation.setNextEncryption(Message.ENCRYPTION_NONE);
break;
@@ -763,6 +848,7 @@ public class ConversationActivity extends XmppActivity
xmppConnectionService.databaseBackend.updateConversation(conversation);
fragment.updateChatMsgHint();
invalidateOptionsMenu();
+ refreshUi();
return true;
}
});
@@ -770,15 +856,18 @@ public class ConversationActivity extends XmppActivity
MenuItem otr = popup.getMenu().findItem(R.id.encryption_choice_otr);
MenuItem none = popup.getMenu().findItem(R.id.encryption_choice_none);
MenuItem pgp = popup.getMenu().findItem(R.id.encryption_choice_pgp);
- boolean forceEncryption = ConversationsPlusPreferences.forceEncryption();
+ MenuItem axolotl = popup.getMenu().findItem(R.id.encryption_choice_axolotl);
+ pgp.setVisible(Config.supportOpenPgp());
+ none.setVisible(Config.supportUnencrypted() || conversation.getMode() == Conversation.MODE_MULTI);
+ otr.setVisible(Config.supportOtr());
+ axolotl.setVisible(Config.supportOmemo());
if (conversation.getMode() == Conversation.MODE_MULTI) {
- otr.setEnabled(false);
- } else {
- if (forceEncryption) {
- none.setVisible(false);
- }
+ otr.setVisible(false);
+ axolotl.setVisible(false);
+ } else if (!conversation.getAccount().getAxolotlService().isContactAxolotlCapable(conversation.getContact())) {
+ axolotl.setEnabled(false);
}
- switch (conversation.getNextEncryption(forceEncryption)) {
+ switch (conversation.getNextEncryption()) {
case Message.ENCRYPTION_NONE:
none.setChecked(true);
break;
@@ -788,6 +877,9 @@ public class ConversationActivity extends XmppActivity
case Message.ENCRYPTION_PGP:
pgp.setChecked(true);
break;
+ case Message.ENCRYPTION_AXOLOTL:
+ axolotl.setChecked(true);
+ break;
default:
none.setChecked(true);
break;
@@ -799,27 +891,26 @@ public class ConversationActivity extends XmppActivity
protected void muteConversationDialog(final Conversation conversation) {
AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder.setTitle(R.string.disable_notifications);
- final int[] durations = getResources().getIntArray(
- R.array.mute_options_durations);
+ final int[] durations = getResources().getIntArray(R.array.mute_options_durations);
builder.setItems(R.array.mute_options_descriptions,
- new OnClickListener() {
+ new OnClickListener() {
- @Override
- public void onClick(final DialogInterface dialog, final int which) {
- final long till;
- if (durations[which] == -1) {
- till = Long.MAX_VALUE;
- } else {
- till = System.currentTimeMillis() + (durations[which] * 1000);
- }
- conversation.setMutedTill(till);
- ConversationActivity.this.xmppConnectionService.databaseBackend
- .updateConversation(conversation);
- updateConversationList();
- ConversationActivity.this.mConversationFragment.updateMessages();
- invalidateOptionsMenu();
- }
- });
+ @Override
+ public void onClick(final DialogInterface dialog, final int which) {
+ final long till;
+ if (durations[which] == -1) {
+ till = Long.MAX_VALUE;
+ } else {
+ till = System.currentTimeMillis() + (durations[which] * 1000);
+ }
+ conversation.setMutedTill(till);
+ ConversationActivity.this.xmppConnectionService.databaseBackend
+ .updateConversation(conversation);
+ updateConversationList();
+ ConversationActivity.this.mConversationFragment.updateMessages();
+ invalidateOptionsMenu();
+ }
+ });
builder.create().show();
}
@@ -841,10 +932,119 @@ public class ConversationActivity extends XmppActivity
}
@Override
+ public boolean onKeyUp(int key, KeyEvent event) {
+ int rotation = getWindowManager().getDefaultDisplay().getRotation();
+ final int upKey;
+ final int downKey;
+ switch (rotation) {
+ case Surface.ROTATION_90:
+ upKey = KeyEvent.KEYCODE_DPAD_LEFT;
+ downKey = KeyEvent.KEYCODE_DPAD_RIGHT;
+ break;
+ case Surface.ROTATION_180:
+ upKey = KeyEvent.KEYCODE_DPAD_DOWN;
+ downKey = KeyEvent.KEYCODE_DPAD_UP;
+ break;
+ case Surface.ROTATION_270:
+ upKey = KeyEvent.KEYCODE_DPAD_RIGHT;
+ downKey = KeyEvent.KEYCODE_DPAD_LEFT;
+ break;
+ default:
+ upKey = KeyEvent.KEYCODE_DPAD_UP;
+ downKey = KeyEvent.KEYCODE_DPAD_DOWN;
+ }
+ final boolean modifier = event.isCtrlPressed() || event.isAltPressed();
+ if (modifier && key == KeyEvent.KEYCODE_TAB && isConversationsOverviewHideable()) {
+ toggleConversationsOverview();
+ return true;
+ } else if (modifier && key == downKey) {
+ if (isConversationsOverviewHideable() && !isConversationsOverviewVisable()) {
+ showConversationsOverview();
+ ;
+ }
+ return selectDownConversation();
+ } else if (modifier && key == upKey) {
+ if (isConversationsOverviewHideable() && !isConversationsOverviewVisable()) {
+ showConversationsOverview();
+ }
+ return selectUpConversation();
+ } else if (modifier && key == KeyEvent.KEYCODE_1) {
+ return openConversationByIndex(0);
+ } else if (modifier && key == KeyEvent.KEYCODE_2) {
+ return openConversationByIndex(1);
+ } else if (modifier && key == KeyEvent.KEYCODE_3) {
+ return openConversationByIndex(2);
+ } else if (modifier && key == KeyEvent.KEYCODE_4) {
+ return openConversationByIndex(3);
+ } else if (modifier && key == KeyEvent.KEYCODE_5) {
+ return openConversationByIndex(4);
+ } else if (modifier && key == KeyEvent.KEYCODE_6) {
+ return openConversationByIndex(5);
+ } else if (modifier && key == KeyEvent.KEYCODE_7) {
+ return openConversationByIndex(6);
+ } else if (modifier && key == KeyEvent.KEYCODE_8) {
+ return openConversationByIndex(7);
+ } else if (modifier && key == KeyEvent.KEYCODE_9) {
+ return openConversationByIndex(8);
+ } else if (modifier && key == KeyEvent.KEYCODE_0) {
+ return openConversationByIndex(9);
+ } else {
+ return super.onKeyUp(key, event);
+ }
+ }
+
+ private void toggleConversationsOverview() {
+ if (isConversationsOverviewVisable()) {
+ hideConversationsOverview();
+ if (mConversationFragment != null) {
+ mConversationFragment.setFocusOnInputField();
+ }
+ } else {
+ showConversationsOverview();
+ }
+ }
+
+ private boolean selectUpConversation() {
+ if (this.mSelectedConversation != null) {
+ int index = this.conversationList.indexOf(this.mSelectedConversation);
+ if (index > 0) {
+ return openConversationByIndex(index - 1);
+ }
+ }
+ return false;
+ }
+
+ private boolean selectDownConversation() {
+ if (this.mSelectedConversation != null) {
+ int index = this.conversationList.indexOf(this.mSelectedConversation);
+ if (index != -1 && index < this.conversationList.size() - 1) {
+ return openConversationByIndex(index + 1);
+ }
+ }
+ return false;
+ }
+
+ private boolean openConversationByIndex(int index) {
+ try {
+ this.conversationWasSelectedByKeyboard = true;
+ setSelectedConversation(this.conversationList.get(index));
+ this.mConversationFragment.reInit(getSelectedConversation());
+ if (index > listView.getLastVisiblePosition() - 1 || index < listView.getFirstVisiblePosition() + 1) {
+ this.listView.setSelection(index);
+ }
+ openConversation();
+ return true;
+ } catch (IndexOutOfBoundsException e) {
+ return false;
+ }
+ }
+
+ @Override
protected void onNewIntent(final Intent intent) {
if (xmppConnectionServiceBound) {
if (intent != null && VIEW_CONVERSATION.equals(intent.getType())) {
handleViewConversationIntent(intent);
+ setIntent(new Intent());
}
} else {
setIntent(intent);
@@ -854,7 +1054,7 @@ public class ConversationActivity extends XmppActivity
@Override
public void onStart() {
super.onStart();
- this.mRedirected = false;
+ this.mRedirected.set(false);
if (this.xmppConnectionServiceBound) {
this.onBackendConnected();
}
@@ -896,17 +1096,26 @@ public class ConversationActivity extends XmppActivity
public void onSaveInstanceState(final Bundle savedInstanceState) {
Conversation conversation = getSelectedConversation();
if (conversation != null) {
- savedInstanceState.putString(STATE_OPEN_CONVERSATION,
- conversation.getUuid());
+ savedInstanceState.putString(STATE_OPEN_CONVERSATION, conversation.getUuid());
+ } else {
+ savedInstanceState.remove(STATE_OPEN_CONVERSATION);
}
- savedInstanceState.putBoolean(STATE_PANEL_OPEN,
- isConversationsOverviewVisable());
+ savedInstanceState.putBoolean(STATE_PANEL_OPEN, isConversationsOverviewVisable());
if (this.mPendingImageUris.size() >= 1) {
savedInstanceState.putString(STATE_PENDING_URI, this.mPendingImageUris.get(0).toString());
+ } else {
+ savedInstanceState.remove(STATE_PENDING_URI);
}
super.onSaveInstanceState(savedInstanceState);
}
+ private void clearPending() {
+ mPendingImageUris.clear();
+ mPendingFileUris.clear();
+ mPendingGeoUri = null;
+ mPostponedActivityResult = null;
+ }
+
@Override
void onBackendConnected() {
this.xmppConnectionService.getNotificationService().setIsInForeground(true);
@@ -918,20 +1127,23 @@ public class ConversationActivity extends XmppActivity
}
if (xmppConnectionService.getAccounts().size() == 0) {
- if (!mRedirected) {
- this.mRedirected = true;
- startActivity(new Intent(this, EditAccountActivity.class));
+ if (mRedirected.compareAndSet(false, true)) {
+ if (Config.X509_VERIFICATION) {
+ startActivity(new Intent(this, ManageAccountActivity.class));
+ } else {
+ startActivity(new Intent(this, EditAccountActivity.class));
+ }
finish();
}
} else if (conversationList.size() <= 0) {
- if (!mRedirected) {
- this.mRedirected = true;
+ if (mRedirected.compareAndSet(false, true)) {
Intent intent = new Intent(this, StartConversationActivity.class);
- intent.putExtra("init",true);
+ intent.putExtra("init", true);
startActivity(intent);
finish();
}
} else if (getIntent() != null && VIEW_CONVERSATION.equals(getIntent().getType())) {
+ clearPending();
handleViewConversationIntent(getIntent());
} else if (selectConversationByUuid(mOpenConverstaion)) {
if (mPanelOpen) {
@@ -939,32 +1151,45 @@ public class ConversationActivity extends XmppActivity
} else {
if (isConversationsOverviewHideable()) {
openConversation();
+ updateActionBarTitle(true);
}
}
this.mConversationFragment.reInit(getSelectedConversation());
mOpenConverstaion = null;
} else if (getSelectedConversation() == null) {
showConversationsOverview();
- mPendingImageUris.clear();
- mPendingFileUris.clear();
- mPendingGeoUri = null;
+ clearPending();
setSelectedConversation(conversationList.get(0));
this.mConversationFragment.reInit(getSelectedConversation());
+ } else {
+ this.mConversationFragment.messagesView.invalidateViews();
+ this.mConversationFragment.setupIme();
}
- for(Iterator<Uri> i = mPendingImageUris.iterator(); i.hasNext(); i.remove()) {
- attachImageToConversation(getSelectedConversation(),i.next());
+ if (this.mPostponedActivityResult != null) {
+ this.onActivityResult(mPostponedActivityResult.first, RESULT_OK, mPostponedActivityResult.second);
}
- for(Iterator<Uri> i = mPendingFileUris.iterator(); i.hasNext(); i.remove()) {
- attachFileToConversation(getSelectedConversation(),i.next());
+ if (!forbidProcessingPendings) {
+ for (Iterator<Uri> i = mPendingImageUris.iterator(); i.hasNext(); i.remove()) {
+ Uri foo = i.next();
+ attachImageToConversation(getSelectedConversation(), foo);
+ }
+
+ for (Iterator<Uri> i = mPendingFileUris.iterator(); i.hasNext(); i.remove()) {
+ attachFileToConversation(getSelectedConversation(), i.next());
+ }
+
+ if (mPendingGeoUri != null) {
+ attachLocationToConversation(getSelectedConversation(), mPendingGeoUri);
+ mPendingGeoUri = null;
+ }
}
+ forbidProcessingPendings = false;
- if (mPendingGeoUri != null) {
- attachLocationToConversation(getSelectedConversation(), mPendingGeoUri);
- mPendingGeoUri = null;
+ if (!ExceptionHelper.checkForCrash(this, this.xmppConnectionService)) {
+ openBatteryOptimizationDialogIfNeeded();
}
- ExceptionHelper.checkForCrash(this, this.xmppConnectionService);
setIntent(new Intent());
}
@@ -973,10 +1198,21 @@ public class ConversationActivity extends XmppActivity
final String downloadUuid = intent.getStringExtra(MESSAGE);
final String text = intent.getStringExtra(TEXT);
final String nick = intent.getStringExtra(NICK);
+ final boolean pm = intent.getBooleanExtra(PRIVATE_MESSAGE, false);
if (selectConversationByUuid(uuid)) {
this.mConversationFragment.reInit(getSelectedConversation());
if (nick != null) {
- this.mConversationFragment.highlightInConference(nick);
+ if (pm) {
+ Jid jid = getSelectedConversation().getJid();
+ try {
+ Jid next = Jid.fromParts(jid.getLocalpart(), jid.getDomainpart(), nick);
+ this.mConversationFragment.privateMessageWith(next);
+ } catch (final InvalidJidException ignored) {
+ //do nothing
+ }
+ } else {
+ this.mConversationFragment.highlightInConference(nick);
+ }
} else {
this.mConversationFragment.appendText(text);
}
@@ -988,7 +1224,7 @@ public class ConversationActivity extends XmppActivity
if (downloadUuid != null) {
final Message message = mSelectedConversation.findMessageWithFileAndUuid(downloadUuid);
if (message != null) {
- mConversationFragment.messageListAdapter.startDownloadable(message);
+ startDownloadable(message);
}
}
}
@@ -1016,10 +1252,13 @@ public class ConversationActivity extends XmppActivity
@SuppressLint("NewApi")
private static List<Uri> extractUriFromIntent(final Intent intent) {
List<Uri> uris = new ArrayList<>();
+ if (intent == null) {
+ return uris;
+ }
Uri uri = intent.getData();
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR2 && uri == null) {
ClipData clipData = intent.getClipData();
- for(int i = 0; i < clipData.getItemCount(); ++i) {
+ for (int i = 0; i < clipData.getItemCount(); ++i) {
uris.add(clipData.getItemAt(i).getUri());
}
} else {
@@ -1029,26 +1268,46 @@ public class ConversationActivity extends XmppActivity
}
@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);
if (resultCode == RESULT_OK) {
if (requestCode == REQUEST_DECRYPT_PGP) {
- mConversationFragment.hideSnackbar();
- mConversationFragment.updateMessages();
+ mConversationFragment.onActivityResult(requestCode, resultCode, data);
+ } else if (requestCode == REQUEST_CHOOSE_PGP_ID) {
+ // the user chose OpenPGP for encryption and selected his key in the PGP provider
+ if (xmppConnectionServiceBound) {
+ if (data.getExtras().containsKey(OpenPgpApi.EXTRA_SIGN_KEY_ID)) {
+ // associate selected PGP keyId with the account
+ mSelectedConversation.getAccount().setPgpSignId(data.getExtras().getLong(OpenPgpApi.EXTRA_SIGN_KEY_ID));
+ // we need to announce the key as described in XEP-027
+ announcePgp(mSelectedConversation.getAccount(), null);
+ } else {
+ choosePgpSignId(mSelectedConversation.getAccount());
+ }
+ this.mPostponedActivityResult = null;
+ } else {
+ this.mPostponedActivityResult = new Pair<>(requestCode, data);
+ }
+ } else if (requestCode == REQUEST_ANNOUNCE_PGP) {
+ if (xmppConnectionServiceBound) {
+ announcePgp(mSelectedConversation.getAccount(), mSelectedConversation);
+ this.mPostponedActivityResult = null;
+ } else {
+ this.mPostponedActivityResult = new Pair<>(requestCode, data);
+ }
} else if (requestCode == ATTACHMENT_CHOICE_CHOOSE_IMAGE) {
mPendingImageUris.clear();
mPendingImageUris.addAll(extractUriFromIntent(data));
if (xmppConnectionServiceBound) {
- for(Iterator<Uri> i = mPendingImageUris.iterator(); i.hasNext(); i.remove()) {
- attachImageToConversation(getSelectedConversation(),i.next());
+ for (Iterator<Uri> i = mPendingImageUris.iterator(); i.hasNext(); i.remove()) {
+ attachImageToConversation(getSelectedConversation(), i.next());
}
}
} else if (requestCode == ATTACHMENT_CHOICE_CHOOSE_FILE || requestCode == ATTACHMENT_CHOICE_RECORD_VOICE) {
mPendingFileUris.clear();
mPendingFileUris.addAll(extractUriFromIntent(data));
if (xmppConnectionServiceBound) {
- for(Iterator<Uri> i = mPendingFileUris.iterator(); i.hasNext(); i.remove()) {
+ for (Iterator<Uri> i = mPendingFileUris.iterator(); i.hasNext(); i.remove()) {
attachFileToConversation(getSelectedConversation(), i.next());
}
}
@@ -1066,66 +1325,109 @@ public class ConversationActivity extends XmppActivity
mPendingImageUris.clear();
}
} else if (requestCode == ATTACHMENT_CHOICE_LOCATION) {
- double latitude = data.getDoubleExtra("latitude",0);
- double longitude = data.getDoubleExtra("longitude",0);
- this.mPendingGeoUri = Uri.parse("geo:"+String.valueOf(latitude)+","+String.valueOf(longitude));
+ double latitude = data.getDoubleExtra("latitude", 0);
+ double longitude = data.getDoubleExtra("longitude", 0);
+ this.mPendingGeoUri = Uri.parse("geo:" + String.valueOf(latitude) + "," + String.valueOf(longitude));
if (xmppConnectionServiceBound) {
attachLocationToConversation(getSelectedConversation(), mPendingGeoUri);
this.mPendingGeoUri = null;
}
+ } else if (requestCode == REQUEST_TRUST_KEYS_TEXT || requestCode == REQUEST_TRUST_KEYS_MENU) {
+ this.forbidProcessingPendings = !xmppConnectionServiceBound;
+ if (xmppConnectionServiceBound) {
+ mConversationFragment.onActivityResult(requestCode, resultCode, data);
+ this.mPostponedActivityResult = null;
+ } else {
+ this.mPostponedActivityResult = new Pair<>(requestCode, data);
+ }
+
}
} else {
- mPendingImageUris.clear();
- mPendingFileUris.clear();
+ mPendingImageUris.clear();
+ mPendingFileUris.clear();
+ if (requestCode == ConversationActivity.REQUEST_DECRYPT_PGP) {
+ mConversationFragment.onActivityResult(requestCode, resultCode, data);
+ }
+ if (requestCode == REQUEST_BATTERY_OP) {
+ setNeverAskForBatteryOptimizationsAgain();
+ }
}
}
+ private void setNeverAskForBatteryOptimizationsAgain() {
+ getPreferences().edit().putBoolean("show_battery_optimization", false).commit();
+ }
+
+ private void openBatteryOptimizationDialogIfNeeded() {
+ if (showBatteryOptimizationWarning() && getPreferences().getBoolean("show_battery_optimization", true)) {
+ AlertDialog.Builder builder = new AlertDialog.Builder(this);
+ builder.setTitle(R.string.battery_optimizations_enabled);
+ builder.setMessage(R.string.battery_optimizations_enabled_dialog);
+ builder.setPositiveButton(R.string.next, new OnClickListener() {
+ @Override
+ public void onClick(DialogInterface dialog, int which) {
+ Intent intent = new Intent(Settings.ACTION_REQUEST_IGNORE_BATTERY_OPTIMIZATIONS);
+ Uri uri = Uri.parse("package:" + getPackageName());
+ intent.setData(uri);
+ startActivityForResult(intent, REQUEST_BATTERY_OP);
+ }
+ });
+ if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR2) {
+ builder.setOnDismissListener(new DialogInterface.OnDismissListener() {
+ @Override
+ public void onDismiss(DialogInterface dialog) {
+ setNeverAskForBatteryOptimizationsAgain();
+ }
+ });
+ }
+ builder.create().show();
+ }
+ }
+
private void attachLocationToConversation(Conversation conversation, Uri uri) {
- if (conversation == null) {
- return;
- }
xmppConnectionService.attachLocationToConversation(conversation, uri, new UiCallback<Message>() {
- @Override
- public void success(Message message) {
- xmppConnectionService.sendMessage(message);
- }
+ @Override
+ public void success(Message message) {
+ xmppConnectionService.sendMessage(message);
+ }
- @Override
- public void error(int errorCode, Message object) {
+ @Override
+ public void error(int errorCode, Message object) {
- }
+ }
- @Override
- public void userInputRequried(PendingIntent pi, Message object) {
+ @Override
+ public void userInputRequried(PendingIntent pi, Message object) {
- }
- });
+ }
+ });
}
private void attachFileToConversation(Conversation conversation, Uri uri) {
if (conversation == null) {
return;
}
- prepareFileToast = Toast.makeText(getApplicationContext(),getText(R.string.preparing_file), Toast.LENGTH_LONG);
+ final Toast prepareFileToast = Toast.makeText(getApplicationContext(),getText(R.string.preparing_file), Toast.LENGTH_LONG);
prepareFileToast.show();
xmppConnectionService.attachFileToConversation(conversation, uri, new UiCallback<Message>() {
- @Override
- public void success(Message message) {
- hidePrepareFileToast();
- xmppConnectionService.sendMessage(message);
- }
+ @Override
+ public void success(Message message) {
+ hidePrepareFileToast(prepareFileToast);
+ xmppConnectionService.sendMessage(message);
+ }
- @Override
- public void error(int errorCode, Message message) {
- displayErrorDialog(errorCode);
- }
+ @Override
+ public void error(int errorCode, Message message) {
+ hidePrepareFileToast(prepareFileToast);
+ displayErrorDialog(errorCode);
+ }
- @Override
- public void userInputRequried(PendingIntent pi, Message message) {
+ @Override
+ public void userInputRequried(PendingIntent pi, Message message) {
- }
- });
+ }
+ });
}
private void attachImageToConversation(Conversation conversation, Uri uri) {
@@ -1137,7 +1439,7 @@ public class ConversationActivity extends XmppActivity
userDecisionDialog.decide(ConversationsPlusPreferences.resizePicture());
}
- private void hidePrepareFileToast() {
+ private void hidePrepareFileToast(final Toast prepareFileToast) {
if (prepareFileToast != null) {
runOnUiThread(new Runnable() {
@@ -1176,7 +1478,7 @@ public class ConversationActivity extends XmppActivity
@Override
public void userInputRequried(PendingIntent pi,
- Message message) {
+ Message message) {
ConversationActivity.this.runIntent(pi,
ConversationActivity.REQUEST_SEND_MESSAGE);
}
@@ -1194,26 +1496,38 @@ public class ConversationActivity extends XmppActivity
});
}
+ protected boolean trustKeysIfNeeded(int requestCode) {
+ return trustKeysIfNeeded(requestCode, ATTACHMENT_CHOICE_INVALID);
+ }
+
+ protected boolean trustKeysIfNeeded(int requestCode, int attachmentChoice) {
+ AxolotlService axolotlService = mSelectedConversation.getAccount().getAxolotlService();
+ Contact contact = mSelectedConversation.getContact();
+ boolean hasUndecidedOwn = !axolotlService.getKeysWithTrust(XmppAxolotlSession.Trust.UNDECIDED).isEmpty();
+ boolean hasUndecidedContact = !axolotlService.getKeysWithTrust(XmppAxolotlSession.Trust.UNDECIDED,contact).isEmpty();
+ boolean hasPendingKeys = !axolotlService.findDevicesWithoutSession(mSelectedConversation).isEmpty();
+ boolean hasNoTrustedKeys = axolotlService.getNumTrustedKeys(mSelectedConversation.getContact()) == 0;
+ if(hasUndecidedOwn || hasUndecidedContact || hasPendingKeys || hasNoTrustedKeys) {
+ axolotlService.createSessionsIfNeeded(mSelectedConversation);
+ Intent intent = new Intent(getApplicationContext(), TrustKeysActivity.class);
+ intent.putExtra("contact", mSelectedConversation.getContact().getJid().toBareJid().toString());
+ intent.putExtra(EXTRA_ACCOUNT, mSelectedConversation.getAccount().getJid().toBareJid().toString());
+ intent.putExtra("choice", attachmentChoice);
+ intent.putExtra("has_no_trusted", hasNoTrustedKeys);
+ startActivityForResult(intent, requestCode);
+ return true;
+ } else {
+ return false;
+ }
+ }
+
@Override
protected void refreshUiReal() {
updateConversationList();
- if (xmppConnectionService != null && xmppConnectionService.getAccounts().size() == 0) {
- if (!mRedirected) {
- this.mRedirected = true;
- startActivity(new Intent(this, EditAccountActivity.class));
- finish();
- }
- } else if (conversationList.size() == 0) {
- if (!mRedirected) {
- this.mRedirected = true;
- Intent intent = new Intent(this, StartConversationActivity.class);
- intent.putExtra("init",true);
- startActivity(intent);
- finish();
- }
- } else {
+ if (conversationList.size() > 0) {
ConversationActivity.this.mConversationFragment.updateMessages();
updateActionBarTitle();
+ invalidateOptionsMenu();
}
}
@@ -1235,12 +1549,6 @@ public class ConversationActivity extends XmppActivity
@Override
public void OnUpdateBlocklist(Status status) {
this.refreshUi();
- runOnUiThread(new Runnable() {
- @Override
- public void run() {
- invalidateOptionsMenu();
- }
- });
}
public void unblockConversation(final Blockable conversation) {
diff --git a/src/main/java/de/thedevstack/conversationsplus/ui/ConversationFragment.java b/src/main/java/de/thedevstack/conversationsplus/ui/ConversationFragment.java
index 3ee79412..2828e27e 100644
--- a/src/main/java/de/thedevstack/conversationsplus/ui/ConversationFragment.java
+++ b/src/main/java/de/thedevstack/conversationsplus/ui/ConversationFragment.java
@@ -1,5 +1,6 @@
package de.thedevstack.conversationsplus.ui;
+import android.app.Activity;
import android.app.AlertDialog;
import android.app.Fragment;
import android.app.PendingIntent;
@@ -7,9 +8,9 @@ import android.content.ActivityNotFoundException;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
-import android.content.IntentSender;
import android.content.IntentSender.SendIntentException;
import android.os.Bundle;
+import android.support.annotation.Nullable;
import android.text.InputType;
import android.view.ContextMenu;
import android.view.ContextMenu.ContextMenuInfo;
@@ -38,32 +39,31 @@ import com.orangegangsters.github.swipyrefreshlayout.library.SwipyRefreshLayout;
import net.java.otr4j.session.SessionStatus;
import java.util.ArrayList;
+import java.util.Collections;
import java.util.List;
-import java.util.NoSuchElementException;
-import java.util.concurrent.ConcurrentLinkedQueue;
import de.thedevstack.conversationsplus.ConversationsPlusPreferences;
-import de.thedevstack.conversationsplus.persistance.FileBackend;
import de.thedevstack.conversationsplus.ui.dialogs.MessageDetailsDialog;
-import de.thedevstack.conversationsplus.ui.listeners.ConversationSwipeRefreshListener;
import de.thedevstack.conversationsplus.Config;
import de.thedevstack.conversationsplus.R;
-import de.thedevstack.conversationsplus.crypto.PgpEngine;
+import de.thedevstack.conversationsplus.crypto.axolotl.AxolotlService;
import de.thedevstack.conversationsplus.entities.Account;
import de.thedevstack.conversationsplus.entities.Contact;
import de.thedevstack.conversationsplus.entities.Conversation;
-import de.thedevstack.conversationsplus.entities.Transferable;
import de.thedevstack.conversationsplus.entities.DownloadableFile;
-import de.thedevstack.conversationsplus.entities.TransferablePlaceholder;
import de.thedevstack.conversationsplus.entities.Message;
import de.thedevstack.conversationsplus.entities.MucOptions;
-import de.thedevstack.conversationsplus.entities.Presences;
+import de.thedevstack.conversationsplus.entities.Presence;
+import de.thedevstack.conversationsplus.entities.Transferable;
+import de.thedevstack.conversationsplus.entities.TransferablePlaceholder;
+import de.thedevstack.conversationsplus.persistance.FileBackend;
import de.thedevstack.conversationsplus.services.XmppConnectionService;
import de.thedevstack.conversationsplus.ui.XmppActivity.OnPresenceSelected;
import de.thedevstack.conversationsplus.ui.XmppActivity.OnValueEdited;
import de.thedevstack.conversationsplus.ui.adapter.MessageAdapter;
import de.thedevstack.conversationsplus.ui.adapter.MessageAdapter.OnContactPictureClicked;
import de.thedevstack.conversationsplus.ui.adapter.MessageAdapter.OnContactPictureLongClicked;
+import de.thedevstack.conversationsplus.ui.listeners.ConversationSwipeRefreshListener;
import de.thedevstack.conversationsplus.utils.GeoHelper;
import de.thedevstack.conversationsplus.utils.UIHelper;
import de.thedevstack.conversationsplus.xmpp.chatstate.ChatState;
@@ -110,7 +110,7 @@ public class ConversationFragment extends Fragment implements EditMessage.Keyboa
};
protected ListView messagesView;
protected SwipyRefreshLayout swipeLayout;
- final protected List<Message> messageList = new ArrayList<>();
+ final protected List<Message> messageList = new ArrayList<>();
protected MessageAdapter messageListAdapter;
private EditMessage mEditMessage;
private ImageButton mSendButton;
@@ -120,21 +120,49 @@ public class ConversationFragment extends Fragment implements EditMessage.Keyboa
private RelativeLayout snackbar;
private TextView snackbarMessage;
private TextView snackbarAction;
- private IntentSender askForPassphraseIntent = null;
+ private boolean messagesLoaded = true;
+ private Toast messageLoaderToast;
+ private final int KEYCHAIN_UNLOCK_NOT_REQUIRED = 0;
+ private final int KEYCHAIN_UNLOCK_REQUIRED = 1;
+ private final int KEYCHAIN_UNLOCK_PENDING = 2;
+ private int keychainUnlock = KEYCHAIN_UNLOCK_NOT_REQUIRED;
protected OnClickListener clickToDecryptListener = new OnClickListener() {
@Override
public void onClick(View v) {
- if (activity.hasPgp() && askForPassphraseIntent != null) {
- try {
- getActivity().startIntentSenderForResult(
- askForPassphraseIntent,
- ConversationActivity.REQUEST_DECRYPT_PGP, null, 0,
- 0, 0);
- askForPassphraseIntent = null;
- } catch (SendIntentException e) {
- //
+ if (keychainUnlock == KEYCHAIN_UNLOCK_REQUIRED
+ && activity.hasPgp() && !conversation.getAccount().getPgpDecryptionService().isRunning()) {
+ keychainUnlock = KEYCHAIN_UNLOCK_PENDING;
+ updateSnackBar(conversation);
+ Message message = getLastPgpDecryptableMessage();
+ if (message != null) {
+ activity.xmppConnectionService.getPgpEngine().decrypt(message, new UiCallback<Message>() {
+ @Override
+ public void success(Message object) {
+ conversation.getAccount().getPgpDecryptionService().onKeychainUnlocked();
+ keychainUnlock = KEYCHAIN_UNLOCK_NOT_REQUIRED;
+ }
+
+ @Override
+ public void error(int errorCode, Message object) {
+ keychainUnlock = KEYCHAIN_UNLOCK_NOT_REQUIRED;
+ }
+
+ @Override
+ public void userInputRequried(PendingIntent pi, Message object) {
+ try {
+ activity.startIntentSenderForResult(pi.getIntentSender(),
+ ConversationActivity.REQUEST_DECRYPT_PGP, null, 0, 0, 0);
+ } catch (SendIntentException e) {
+ keychainUnlock = KEYCHAIN_UNLOCK_NOT_REQUIRED;
+ updatePgpMessages();
+ }
+ }
+ });
}
+ } else {
+ keychainUnlock = KEYCHAIN_UNLOCK_NOT_REQUIRED;
+ updatePgpMessages();
}
}
};
@@ -145,8 +173,6 @@ public class ConversationFragment extends Fragment implements EditMessage.Keyboa
activity.verifyOtrSessionDialog(conversation, v);
}
};
- private ConcurrentLinkedQueue<Message> mEncryptedMessages = new ConcurrentLinkedQueue<>();
- private boolean mDecryptJobRunning = false;
private OnEditorActionListener mEditorActionListener = new OnEditorActionListener() {
@Override
@@ -154,7 +180,9 @@ public class ConversationFragment extends Fragment implements EditMessage.Keyboa
if (actionId == EditorInfo.IME_ACTION_SEND) {
InputMethodManager imm = (InputMethodManager) v.getContext()
.getSystemService(Context.INPUT_METHOD_SERVICE);
- imm.hideSoftInputFromWindow(v.getWindowToken(), 0);
+ if (imm.isFullscreenMode()) {
+ imm.hideSoftInputFromWindow(v.getWindowToken(), 0);
+ }
sendMessage();
return true;
} else {
@@ -210,43 +238,64 @@ public class ConversationFragment extends Fragment implements EditMessage.Keyboa
private ConversationActivity activity;
private Message selectedMessage;
+ public void setMessagesLoaded() {
+ this.messagesLoaded = true;
+ }
+
private void sendMessage() {
final String body = mEditMessage.getText().toString();
if (body.length() == 0 || this.conversation == null) {
return;
}
- boolean forceEncryption = ConversationsPlusPreferences.forceEncryption();
- Message message = new Message(conversation, body, conversation.getNextEncryption(forceEncryption));
+ Message message = new Message(conversation, body, conversation.getNextEncryption());
if (conversation.getMode() == Conversation.MODE_MULTI) {
if (conversation.getNextCounterpart() != null) {
message.setCounterpart(conversation.getNextCounterpart());
message.setType(Message.TYPE_PRIVATE);
}
}
- if (conversation.getNextEncryption(forceEncryption) == Message.ENCRYPTION_OTR) {
- sendOtrMessage(message);
- } else if (conversation.getNextEncryption(forceEncryption) == Message.ENCRYPTION_PGP) {
- sendPgpMessage(message);
- } else {
- sendPlainTextMessage(message);
+ switch (conversation.getNextEncryption()) {
+ case Message.ENCRYPTION_OTR:
+ sendOtrMessage(message);
+ break;
+ case Message.ENCRYPTION_PGP:
+ sendPgpMessage(message);
+ break;
+ case Message.ENCRYPTION_AXOLOTL:
+ if(!activity.trustKeysIfNeeded(ConversationActivity.REQUEST_TRUST_KEYS_TEXT)) {
+ sendAxolotlMessage(message);
+ }
+ break;
+ default:
+ sendPlainTextMessage(message);
}
}
public void updateChatMsgHint() {
- if (conversation.getMode() == Conversation.MODE_MULTI
- && conversation.getNextCounterpart() != null) {
+ final boolean multi = conversation.getMode() == Conversation.MODE_MULTI;
+ if (multi && conversation.getNextCounterpart() != null) {
this.mEditMessage.setHint(getString(
- R.string.send_private_message_to,
- conversation.getNextCounterpart().getResourcepart()));
+ R.string.send_private_message_to,
+ conversation.getNextCounterpart().getResourcepart()));
+ } else if (multi && !conversation.getMucOptions().participating()) {
+ this.mEditMessage.setHint(R.string.you_are_not_participating);
} else {
- switch (conversation.getNextEncryption(ConversationsPlusPreferences.forceEncryption())) {
+ switch (conversation.getNextEncryption()) {
case Message.ENCRYPTION_NONE:
mEditMessage
- .setHint(getString(R.string.send_plain_text_message));
+ .setHint(getString(R.string.send_unencrypted_message));
break;
case Message.ENCRYPTION_OTR:
mEditMessage.setHint(getString(R.string.send_otr_message));
break;
+ case Message.ENCRYPTION_AXOLOTL:
+ AxolotlService axolotlService = conversation.getAccount().getAxolotlService();
+ if (axolotlService != null && axolotlService.trustedSessionVerified(conversation)) {
+ mEditMessage.setHint(getString(R.string.send_omemo_x509_message));
+ } else {
+ mEditMessage.setHint(getString(R.string.send_omemo_message));
+ }
+ break;
case Message.ENCRYPTION_PGP:
mEditMessage.setHint(getString(R.string.send_pgp_message));
break;
@@ -257,21 +306,26 @@ public class ConversationFragment extends Fragment implements EditMessage.Keyboa
}
}
- private void setupIme() {
- if (ConversationsPlusPreferences.displayEnterKey()) {
+ public void setupIme() {
+ if (activity == null) {
+ return;
+ } else if (activity.usingEnterKey() && ConversationsPlusPreferences.enterIsSend()) {
+ mEditMessage.setInputType(mEditMessage.getInputType() & (~InputType.TYPE_TEXT_FLAG_MULTI_LINE));
+ mEditMessage.setInputType(mEditMessage.getInputType() & (~InputType.TYPE_TEXT_VARIATION_SHORT_MESSAGE));
+ } else if (activity.usingEnterKey()) {
+ mEditMessage.setInputType(mEditMessage.getInputType() | InputType.TYPE_TEXT_FLAG_MULTI_LINE);
mEditMessage.setInputType(mEditMessage.getInputType() & (~InputType.TYPE_TEXT_VARIATION_SHORT_MESSAGE));
} else {
+ mEditMessage.setInputType(mEditMessage.getInputType() | InputType.TYPE_TEXT_FLAG_MULTI_LINE);
mEditMessage.setInputType(mEditMessage.getInputType() | InputType.TYPE_TEXT_VARIATION_SHORT_MESSAGE);
}
}
@Override
- public View onCreateView(final LayoutInflater inflater,
- ViewGroup container, Bundle savedInstanceState) {
+ public View onCreateView(final LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
final View view = inflater.inflate(R.layout.fragment_conversation, container, false);
view.setOnClickListener(null);
mEditMessage = (EditMessage) view.findViewById(R.id.textinput);
- setupIme();
mEditMessage.setOnClickListener(new OnClickListener() {
@Override
@@ -401,19 +455,20 @@ public class ConversationFragment extends Fragment implements EditMessage.Keyboa
if (message.getStatus() <= Message.STATUS_RECEIVED) {
if (message.getConversation().getMode() == Conversation.MODE_MULTI) {
if (message.getCounterpart() != null) {
- if (!message.getCounterpart().isBareJid()) {
- highlightInConference(message.getCounterpart().getResourcepart());
- } else {
- highlightInConference(message.getCounterpart().toString());
+ String user = message.getCounterpart().isBareJid() ? message.getCounterpart().toString() : message.getCounterpart().getResourcepart();
+ if (!message.getConversation().getMucOptions().isUserInRoom(user)) {
+ Toast.makeText(activity,activity.getString(R.string.user_has_left_conference,user),Toast.LENGTH_SHORT).show();
}
+ highlightInConference(user);
}
} else {
- activity.switchToContactDetails(message.getContact());
+ activity.switchToContactDetails(message.getContact(), message.getAxolotlFingerprint());
}
} else {
Account account = message.getConversation().getAccount();
Intent intent = new Intent(activity, EditAccountActivity.class);
intent.putExtra("jid", account.getJid().toBareJid().toString());
+ intent.putExtra("fingerprint", message.getAxolotlFingerprint());
startActivity(intent);
}
}
@@ -426,7 +481,14 @@ public class ConversationFragment extends Fragment implements EditMessage.Keyboa
if (message.getStatus() <= Message.STATUS_RECEIVED) {
if (message.getConversation().getMode() == Conversation.MODE_MULTI) {
if (message.getCounterpart() != null) {
- privateMessageWith(message.getCounterpart());
+ String user = message.getCounterpart().getResourcepart();
+ if (user != null) {
+ if (message.getConversation().getMucOptions().isUserInRoom(user)) {
+ privateMessageWith(message.getCounterpart());
+ } else {
+ Toast.makeText(activity, activity.getString(R.string.user_has_left_conference, user), Toast.LENGTH_SHORT).show();
+ }
+ }
}
}
} else {
@@ -448,8 +510,7 @@ public class ConversationFragment extends Fragment implements EditMessage.Keyboa
}
@Override
- public void onCreateContextMenu(ContextMenu menu, View v,
- ContextMenuInfo menuInfo) {
+ public void onCreateContextMenu(ContextMenu menu, View v, ContextMenuInfo menuInfo) {
synchronized (this.messageList) {
super.onCreateContextMenu(menu, v, menuInfo);
AdapterView.AdapterContextMenuInfo acmi = (AdapterContextMenuInfo) menuInfo;
@@ -464,6 +525,7 @@ public class ConversationFragment extends Fragment implements EditMessage.Keyboa
activity.getMenuInflater().inflate(R.menu.message_context, menu);
menu.setHeaderTitle(R.string.message_options);
MenuItem copyText = menu.findItem(R.id.copy_text);
+ MenuItem retryDecryption = menu.findItem(R.id.retry_decryption);
MenuItem shareWith = menu.findItem(R.id.share_with);
MenuItem sendAgain = menu.findItem(R.id.send_again);
MenuItem copyUrl = menu.findItem(R.id.copy_url);
@@ -475,6 +537,11 @@ public class ConversationFragment extends Fragment implements EditMessage.Keyboa
&& m.treatAsDownloadable() != Message.Decision.MUST) {
copyText.setVisible(true);
}
+
+ if (m.getEncryption() == Message.ENCRYPTION_DECRYPTION_FAILED) {
+ retryDecryption.setVisible(true);
+ }
+
if ((m.getType() != Message.TYPE_TEXT
&& m.getType() != Message.TYPE_PRIVATE
&& m.getTransferable() == null)
@@ -489,7 +556,8 @@ public class ConversationFragment extends Fragment implements EditMessage.Keyboa
|| m.treatAsDownloadable() == Message.Decision.MUST) {
copyUrl.setVisible(true);
}
- if (m.getType() == Message.TYPE_TEXT && m.getTransferable() == null && m.treatAsDownloadable() != Message.Decision.NEVER) {
+ if ((m.getType() == Message.TYPE_TEXT && m.getTransferable() == null && m.treatAsDownloadable() != Message.Decision.NEVER)
+ || (m.isFileOrImage() && m.getTransferable() instanceof TransferablePlaceholder && m.hasFileOnRemoteHost())){
downloadFile.setVisible(true);
downloadFile.setTitle(activity.getString(R.string.download_x_file,UIHelper.getFileDescriptionString(activity, m)));
}
@@ -504,9 +572,9 @@ public class ConversationFragment extends Fragment implements EditMessage.Keyboa
@Override
public boolean onContextItemSelected(MenuItem item) {
switch (item.getItemId()) {
- case R.id.msg_ctx_mnu_details:
+ case R.id.msg_ctx_mnu_details:
new MessageDetailsDialog(getActivity(), selectedMessage).show();
- return true;
+ return true;
case R.id.share_with:
shareWith(selectedMessage);
return true;
@@ -525,6 +593,9 @@ public class ConversationFragment extends Fragment implements EditMessage.Keyboa
case R.id.cancel_transmission:
cancelTransmission(selectedMessage);
return true;
+ case R.id.retry_decryption:
+ retryDecryption(selectedMessage);
+ return true;
default:
return super.onContextItemSelected(item);
}
@@ -537,11 +608,12 @@ public class ConversationFragment extends Fragment implements EditMessage.Keyboa
shareIntent.putExtra(Intent.EXTRA_TEXT, message.getBody());
shareIntent.setType("text/plain");
} else {
- shareIntent.putExtra(Intent.EXTRA_STREAM, FileBackend.getJingleFileUri(message));
+ shareIntent.putExtra(Intent.EXTRA_STREAM,
+ FileBackend.getJingleFileUri(message));
shareIntent.setFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
String mime = message.getMimeType();
if (mime == null) {
- mime = "image/webp";
+ mime = "*/*";
}
shareIntent.setType(mime);
}
@@ -594,7 +666,7 @@ public class ConversationFragment extends Fragment implements EditMessage.Keyboa
private void downloadFile(Message message) {
activity.xmppConnectionService.getHttpConnectionManager()
- .createNewDownloadConnection(message);
+ .createNewDownloadConnection(message,true);
}
private void cancelTransmission(Message message) {
@@ -606,6 +678,12 @@ public class ConversationFragment extends Fragment implements EditMessage.Keyboa
}
}
+ private void retryDecryption(Message message) {
+ message.setEncryption(Message.ENCRYPTION_PGP);
+ activity.xmppConnectionService.updateConversationUi();
+ conversation.getAccount().getPgpDecryptionService().add(message);
+ }
+
protected void privateMessageWith(final Jid counterpart) {
this.mEditMessage.setText("");
this.conversation.setNextCounterpart(counterpart);
@@ -629,7 +707,6 @@ public class ConversationFragment extends Fragment implements EditMessage.Keyboa
@Override
public void onStop() {
- mDecryptJobRunning = false;
super.onStop();
if (this.conversation != null) {
final String msg = mEditMessage.getText().toString();
@@ -650,9 +727,8 @@ public class ConversationFragment extends Fragment implements EditMessage.Keyboa
if (conversation == null) {
return;
}
-
this.activity = (ConversationActivity) getActivity();
-
+ setupIme();
if (this.conversation != null) {
final String msg = mEditMessage.getText().toString();
this.conversation.setNextMessage(msg);
@@ -662,19 +738,18 @@ public class ConversationFragment extends Fragment implements EditMessage.Keyboa
this.conversation.trim();
}
- this.askForPassphraseIntent = null;
+ this.keychainUnlock = KEYCHAIN_UNLOCK_NOT_REQUIRED;
this.conversation = conversation;
- this.mDecryptJobRunning = false;
- this.mEncryptedMessages.clear();
- if (this.conversation.getMode() == Conversation.MODE_MULTI) {
- this.conversation.setNextCounterpart(null);
- }
+ boolean canWrite = this.conversation.getMode() == Conversation.MODE_SINGLE || this.conversation.getMucOptions().participating();
+ this.mEditMessage.setEnabled(canWrite);
+ this.mSendButton.setEnabled(canWrite);
this.mEditMessage.setKeyboardListener(null);
this.mEditMessage.setText("");
this.mEditMessage.append(this.conversation.getNextMessage());
this.mEditMessage.setKeyboardListener(this);
this.messagesView.setAdapter(messageListAdapter);
updateMessages();
+ this.messagesLoaded = true;
int size = this.messageList.size();
if (size > 0) {
messagesView.setSelection(size - 1);
@@ -711,21 +786,13 @@ public class ConversationFragment extends Fragment implements EditMessage.Keyboa
}
};
- private OnClickListener mUnmuteClickListener = new OnClickListener() {
-
- @Override
- public void onClick(final View v) {
- activity.unmuteConversation(conversation);
- }
- };
-
private OnClickListener mAnswerSmpClickListener = new OnClickListener() {
@Override
public void onClick(View view) {
Intent intent = new Intent(activity, VerifyOTRActivity.class);
intent.setAction(VerifyOTRActivity.ACTION_VERIFY_CONTACT);
intent.putExtra("contact", conversation.getContact().getJid().toBareJid().toString());
- intent.putExtra("account", conversation.getAccount().getJid().toBareJid().toString());
+ intent.putExtra(VerifyOTRActivity.EXTRA_ACCOUNT, conversation.getAccount().getJid().toBareJid().toString());
intent.putExtra("mode", VerifyOTRActivity.MODE_ANSWER_QUESTION);
startActivity(intent);
}
@@ -743,28 +810,34 @@ public class ConversationFragment extends Fragment implements EditMessage.Keyboa
&& !conversation.getMucOptions().online()
&& account.getStatus() == Account.State.ONLINE) {
switch (conversation.getMucOptions().getError()) {
- case MucOptions.ERROR_NICK_IN_USE:
+ case NICK_IN_USE:
showSnackbar(R.string.nick_in_use, R.string.edit, clickToMuc);
break;
- case MucOptions.ERROR_UNKNOWN:
- showSnackbar(R.string.conference_not_found, R.string.leave, leaveMuc);
+ case NO_RESPONSE:
+ showSnackbar(R.string.joining_conference, 0, null);
break;
- case MucOptions.ERROR_PASSWORD_REQUIRED:
+ case PASSWORD_REQUIRED:
showSnackbar(R.string.conference_requires_password, R.string.enter_password, enterPassword);
break;
- case MucOptions.ERROR_BANNED:
+ case BANNED:
showSnackbar(R.string.conference_banned, R.string.leave, leaveMuc);
break;
- case MucOptions.ERROR_MEMBERS_ONLY:
+ case MEMBERS_ONLY:
showSnackbar(R.string.conference_members_only, R.string.leave, leaveMuc);
break;
- case MucOptions.KICKED_FROM_ROOM:
+ case KICKED:
showSnackbar(R.string.conference_kicked, R.string.join, joinMuc);
break;
+ case UNKNOWN:
+ showSnackbar(R.string.conference_unknown_error, R.string.join, joinMuc);
+ break;
+ case SHUTDOWN:
+ showSnackbar(R.string.conference_shutdown, R.string.join, joinMuc);
+ break;
default:
break;
}
- } else if (askForPassphraseIntent != null) {
+ } else if (keychainUnlock == KEYCHAIN_UNLOCK_REQUIRED) {
showSnackbar(R.string.openpgp_messages_found, R.string.decrypt, clickToDecryptListener);
} else if (mode == Conversation.MODE_SINGLE
&& conversation.smpRequested()) {
@@ -774,8 +847,6 @@ public class ConversationFragment extends Fragment implements EditMessage.Keyboa
&& (conversation.getOtrSession().getSessionStatus() == SessionStatus.ENCRYPTED)
&& (!conversation.isOtrFingerprintVerified())) {
showSnackbar(R.string.unknown_otr_fingerprint, R.string.verify, clickToVerify);
- } else if (conversation.isMuted()) {
- showSnackbar(R.string.notifications_disabled, R.string.enable, this.mUnmuteClickListener);
} else {
hideSnackbar();
}
@@ -788,19 +859,9 @@ public class ConversationFragment extends Fragment implements EditMessage.Keyboa
}
final ConversationActivity activity = (ConversationActivity) getActivity();
if (this.conversation != null) {
- updateSnackBar(this.conversation);
conversation.populateWithMessages(ConversationFragment.this.messageList);
- for (final Message message : this.messageList) {
- if (message.getEncryption() == Message.ENCRYPTION_PGP
- && (message.getStatus() == Message.STATUS_RECEIVED || message
- .getStatus() >= Message.STATUS_SEND)
- && message.getTransferable() == null) {
- if (!mEncryptedMessages.contains(message)) {
- mEncryptedMessages.add(message);
- }
- }
- }
- decryptNext();
+ updatePgpMessages();
+ updateSnackBar(conversation);
updateStatusMessages();
this.messageListAdapter.notifyDataSetChanged();
updateChatMsgHint();
@@ -812,46 +873,27 @@ public class ConversationFragment extends Fragment implements EditMessage.Keyboa
}
}
- private void decryptNext() {
- Message next = this.mEncryptedMessages.peek();
- PgpEngine engine = activity.xmppConnectionService.getPgpEngine();
-
- if (next != null && engine != null && !mDecryptJobRunning) {
- mDecryptJobRunning = true;
- engine.decrypt(next, new UiCallback<Message>() {
-
- @Override
- public void userInputRequried(PendingIntent pi, Message message) {
- mDecryptJobRunning = false;
- askForPassphraseIntent = pi.getIntentSender();
- updateSnackBar(conversation);
- }
-
- @Override
- public void success(Message message) {
- mDecryptJobRunning = false;
- try {
- mEncryptedMessages.remove();
- } catch (final NoSuchElementException ignored) {
-
- }
- askForPassphraseIntent = null;
- activity.xmppConnectionService.updateMessage(message);
- }
-
- @Override
- public void error(int error, Message message) {
- message.setEncryption(Message.ENCRYPTION_DECRYPTION_FAILED);
- mDecryptJobRunning = false;
- try {
- mEncryptedMessages.remove();
- } catch (final NoSuchElementException ignored) {
+ public void updatePgpMessages() {
+ if (keychainUnlock != KEYCHAIN_UNLOCK_PENDING) {
+ if (getLastPgpDecryptableMessage() != null
+ && !conversation.getAccount().getPgpDecryptionService().isRunning()) {
+ keychainUnlock = KEYCHAIN_UNLOCK_REQUIRED;
+ } else {
+ keychainUnlock = KEYCHAIN_UNLOCK_NOT_REQUIRED;
+ }
+ }
+ }
- }
- activity.xmppConnectionService.updateConversationUi();
- }
- });
+ @Nullable
+ private Message getLastPgpDecryptableMessage() {
+ for (final Message message : this.messageList) {
+ if (message.getEncryption() == Message.ENCRYPTION_PGP
+ && (message.getStatus() == Message.STATUS_RECEIVED || message.getStatus() >= Message.STATUS_SEND)
+ && message.getTransferable() == null) {
+ return message;
+ }
}
+ return null;
}
private void messageSent() {
@@ -861,84 +903,88 @@ public class ConversationFragment extends Fragment implements EditMessage.Keyboa
updateChatMsgHint();
}
+ public void setFocusOnInputField() {
+ mEditMessage.requestFocus();
+ }
+
enum SendButtonAction {TEXT, TAKE_PHOTO, SEND_LOCATION, RECORD_VOICE, CANCEL, CHOOSE_PICTURE}
- private int getSendButtonImageResource(SendButtonAction action, int status) {
+ private int getSendButtonImageResource(SendButtonAction action, Presence.Status status) {
switch (action) {
case TEXT:
switch (status) {
- case Presences.CHAT:
- case Presences.ONLINE:
+ case CHAT:
+ case ONLINE:
return R.drawable.ic_send_text_online;
- case Presences.AWAY:
+ case AWAY:
return R.drawable.ic_send_text_away;
- case Presences.XA:
- case Presences.DND:
+ case XA:
+ case DND:
return R.drawable.ic_send_text_dnd;
default:
return R.drawable.ic_send_text_offline;
}
case TAKE_PHOTO:
switch (status) {
- case Presences.CHAT:
- case Presences.ONLINE:
+ case CHAT:
+ case ONLINE:
return R.drawable.ic_send_photo_online;
- case Presences.AWAY:
+ case AWAY:
return R.drawable.ic_send_photo_away;
- case Presences.XA:
- case Presences.DND:
+ case XA:
+ case DND:
return R.drawable.ic_send_photo_dnd;
default:
return R.drawable.ic_send_photo_offline;
}
case RECORD_VOICE:
switch (status) {
- case Presences.CHAT:
- case Presences.ONLINE:
+ case CHAT:
+ case ONLINE:
return R.drawable.ic_send_voice_online;
- case Presences.AWAY:
+ case AWAY:
return R.drawable.ic_send_voice_away;
- case Presences.XA:
- case Presences.DND:
+ case XA:
+ case DND:
return R.drawable.ic_send_voice_dnd;
default:
return R.drawable.ic_send_voice_offline;
}
case SEND_LOCATION:
switch (status) {
- case Presences.CHAT:
- case Presences.ONLINE:
+ case CHAT:
+ case ONLINE:
return R.drawable.ic_send_location_online;
- case Presences.AWAY:
+ case AWAY:
return R.drawable.ic_send_location_away;
- case Presences.XA:
- case Presences.DND:
+ case XA:
+ case DND:
return R.drawable.ic_send_location_dnd;
default:
return R.drawable.ic_send_location_offline;
}
case CANCEL:
switch (status) {
- case Presences.CHAT:
- case Presences.ONLINE:
+ case CHAT:
+ case ONLINE:
return R.drawable.ic_send_cancel_online;
- case Presences.AWAY:
+ case AWAY:
return R.drawable.ic_send_cancel_away;
- case Presences.XA:
- case Presences.DND:
+ case XA:
+ case DND:
return R.drawable.ic_send_cancel_dnd;
default:
return R.drawable.ic_send_cancel_offline;
}
case CHOOSE_PICTURE:
switch (status) {
- case Presences.CHAT:
- case Presences.ONLINE:
+ case CHAT:
+ case ONLINE:
return R.drawable.ic_send_picture_online;
- case Presences.AWAY:
+ case AWAY:
return R.drawable.ic_send_picture_away;
- case Presences.XA:
- case Presences.DND:
+ case XA:
+ case DND:
return R.drawable.ic_send_picture_dnd;
default:
return R.drawable.ic_send_picture_offline;
@@ -950,8 +996,9 @@ public class ConversationFragment extends Fragment implements EditMessage.Keyboa
public void updateSendButton() {
final Conversation c = this.conversation;
final SendButtonAction action;
- final int status;
- final boolean empty = this.mEditMessage == null || this.mEditMessage.getText().length() == 0;
+ final Presence.Status status;
+ final String text = this.mEditMessage == null ? "" : this.mEditMessage.getText().toString();
+ final boolean empty = text.length() == 0;
final boolean conference = c.getMode() == Conversation.MODE_MULTI;
if (conference && !c.getAccount().httpUploadAvailable()) {
if (empty && c.getNextCounterpart() != null) {
@@ -997,10 +1044,10 @@ public class ConversationFragment extends Fragment implements EditMessage.Keyboa
if (c.getMode() == Conversation.MODE_SINGLE) {
status = c.getContact().getMostAvailableStatus();
} else {
- status = c.getMucOptions().online() ? Presences.ONLINE : Presences.OFFLINE;
+ status = c.getMucOptions().online() ? Presence.Status.ONLINE : Presence.Status.OFFLINE;
}
} else {
- status = Presences.OFFLINE;
+ status = Presence.Status.OFFLINE;
}
this.mSendButton.setTag(action);
this.mSendButton.setImageResource(getSendButtonImageResource(action, status));
@@ -1031,14 +1078,15 @@ public class ConversationFragment extends Fragment implements EditMessage.Keyboa
}
}
- protected void showSnackbar(final int message, final int action,
- final OnClickListener clickListener) {
+ protected void showSnackbar(final int message, final int action, final OnClickListener clickListener) {
snackbar.setVisibility(View.VISIBLE);
snackbar.setOnClickListener(null);
snackbarMessage.setText(message);
snackbarMessage.setOnClickListener(null);
- snackbarAction.setVisibility(View.VISIBLE);
- snackbarAction.setText(action);
+ snackbarAction.setVisibility(clickListener == null ? View.GONE : View.VISIBLE);
+ if (action != 0) {
+ snackbarAction.setText(action);
+ }
snackbarAction.setOnClickListener(clickListener);
}
@@ -1056,81 +1104,85 @@ public class ConversationFragment extends Fragment implements EditMessage.Keyboa
final ConversationActivity activity = (ConversationActivity) getActivity();
final XmppConnectionService xmppService = activity.xmppConnectionService;
final Contact contact = message.getConversation().getContact();
- if (activity.hasPgp()) {
- if (conversation.getMode() == Conversation.MODE_SINGLE) {
- if (contact.getPgpKeyId() != 0) {
- xmppService.getPgpEngine().hasKey(contact,
- new UiCallback<Contact>() {
-
- @Override
- public void userInputRequried(PendingIntent pi,
- Contact contact) {
- activity.runIntent(
- pi,
- ConversationActivity.REQUEST_ENCRYPT_MESSAGE);
- }
-
- @Override
- public void success(Contact contact) {
- messageSent();
- activity.encryptTextMessage(message);
- }
+ if (!activity.hasPgp()) {
+ activity.showInstallPgpDialog();
+ return;
+ }
+ if (conversation.getAccount().getPgpSignature() == null) {
+ activity.announcePgp(conversation.getAccount(), conversation);
+ return;
+ }
+ if (conversation.getMode() == Conversation.MODE_SINGLE) {
+ if (contact.getPgpKeyId() != 0) {
+ xmppService.getPgpEngine().hasKey(contact,
+ new UiCallback<Contact>() {
+
+ @Override
+ public void userInputRequried(PendingIntent pi,
+ Contact contact) {
+ activity.runIntent(
+ pi,
+ ConversationActivity.REQUEST_ENCRYPT_MESSAGE);
+ }
- @Override
- public void error(int error, Contact contact) {
+ @Override
+ public void success(Contact contact) {
+ messageSent();
+ activity.encryptTextMessage(message);
+ }
- }
- });
+ @Override
+ public void error(int error, Contact contact) {
+ System.out.println();
+ }
+ });
- } else {
- showNoPGPKeyDialog(false,
- new DialogInterface.OnClickListener() {
-
- @Override
- public void onClick(DialogInterface dialog,
- int which) {
- conversation
- .setNextEncryption(Message.ENCRYPTION_NONE);
- xmppService.databaseBackend
- .updateConversation(conversation);
- message.setEncryption(Message.ENCRYPTION_NONE);
- xmppService.sendMessage(message);
- messageSent();
- }
- });
- }
} else {
- if (conversation.getMucOptions().pgpKeysInUse()) {
- if (!conversation.getMucOptions().everybodyHasKeys()) {
- Toast warning = Toast
- .makeText(getActivity(),
- R.string.missing_public_keys,
- Toast.LENGTH_LONG);
- warning.setGravity(Gravity.CENTER_VERTICAL, 0, 0);
- warning.show();
- }
- activity.encryptTextMessage(message);
- messageSent();
- } else {
- showNoPGPKeyDialog(true,
- new DialogInterface.OnClickListener() {
-
- @Override
- public void onClick(DialogInterface dialog,
- int which) {
- conversation
- .setNextEncryption(Message.ENCRYPTION_NONE);
- message.setEncryption(Message.ENCRYPTION_NONE);
- xmppService.databaseBackend
- .updateConversation(conversation);
- xmppService.sendMessage(message);
- messageSent();
- }
- });
- }
+ showNoPGPKeyDialog(false,
+ new DialogInterface.OnClickListener() {
+
+ @Override
+ public void onClick(DialogInterface dialog,
+ int which) {
+ conversation
+ .setNextEncryption(Message.ENCRYPTION_NONE);
+ xmppService.databaseBackend
+ .updateConversation(conversation);
+ message.setEncryption(Message.ENCRYPTION_NONE);
+ xmppService.sendMessage(message);
+ messageSent();
+ }
+ });
}
} else {
- activity.showInstallPgpDialog();
+ if (conversation.getMucOptions().pgpKeysInUse()) {
+ if (!conversation.getMucOptions().everybodyHasKeys()) {
+ Toast warning = Toast
+ .makeText(getActivity(),
+ R.string.missing_public_keys,
+ Toast.LENGTH_LONG);
+ warning.setGravity(Gravity.CENTER_VERTICAL, 0, 0);
+ warning.show();
+ }
+ activity.encryptTextMessage(message);
+ messageSent();
+ } else {
+ showNoPGPKeyDialog(true,
+ new DialogInterface.OnClickListener() {
+
+ @Override
+ public void onClick(DialogInterface dialog,
+ int which) {
+ conversation
+ .setNextEncryption(Message.ENCRYPTION_NONE);
+ message.setEncryption(Message.ENCRYPTION_NONE);
+ xmppService.databaseBackend
+ .updateConversation(conversation);
+ xmppService.sendMessage(message);
+ messageSent();
+ }
+ });
+ }
}
}
@@ -1151,19 +1203,26 @@ public class ConversationFragment extends Fragment implements EditMessage.Keyboa
builder.create().show();
}
+ protected void sendAxolotlMessage(final Message message) {
+ final ConversationActivity activity = (ConversationActivity) getActivity();
+ final XmppConnectionService xmppService = activity.xmppConnectionService;
+ xmppService.sendMessage(message);
+ messageSent();
+ }
+
protected void sendOtrMessage(final Message message) {
final ConversationActivity activity = (ConversationActivity) getActivity();
final XmppConnectionService xmppService = activity.xmppConnectionService;
activity.selectPresence(message.getConversation(),
- new OnPresenceSelected() {
+ new OnPresenceSelected() {
- @Override
- public void onPresenceSelected() {
- message.setCounterpart(conversation.getNextCounterpart());
- xmppService.sendMessage(message);
- messageSent();
- }
- });
+ @Override
+ public void onPresenceSelected() {
+ message.setCounterpart(conversation.getNextCounterpart());
+ xmppService.sendMessage(message);
+ messageSent();
+ }
+ });
}
public void appendText(String text) {
@@ -1193,6 +1252,7 @@ public class ConversationFragment extends Fragment implements EditMessage.Keyboa
if (status == Account.State.ONLINE && conversation.setOutgoingChatState(ChatState.COMPOSING)) {
activity.xmppConnectionService.sendChatState(conversation);
}
+ activity.hideConversationsOverview();
updateSendButton();
}
@@ -1213,6 +1273,72 @@ public class ConversationFragment extends Fragment implements EditMessage.Keyboa
updateSendButton();
}
+ private int completionIndex = 0;
+ private int lastCompletionLength = 0;
+ private String incomplete;
+ private int lastCompletionCursor;
+ private boolean firstWord = false;
+
+ @Override
+ public boolean onTabPressed(boolean repeated) {
+ if (conversation == null || conversation.getMode() == Conversation.MODE_SINGLE) {
+ return false;
+ }
+ if (repeated) {
+ completionIndex++;
+ } else {
+ lastCompletionLength = 0;
+ completionIndex = 0;
+ final String content = mEditMessage.getText().toString();
+ lastCompletionCursor = mEditMessage.getSelectionEnd();
+ int start = lastCompletionCursor > 0 ? content.lastIndexOf(" ",lastCompletionCursor-1) + 1 : 0;
+ firstWord = start == 0;
+ incomplete = content.substring(start,lastCompletionCursor);
+ }
+ List<String> completions = new ArrayList<>();
+ for(MucOptions.User user : conversation.getMucOptions().getUsers()) {
+ if (user.getName().startsWith(incomplete)) {
+ completions.add(user.getName()+(firstWord ? ": " : " "));
+ }
+ }
+ Collections.sort(completions);
+ if (completions.size() > completionIndex) {
+ String completion = completions.get(completionIndex).substring(incomplete.length());
+ mEditMessage.getEditableText().delete(lastCompletionCursor,lastCompletionCursor + lastCompletionLength);
+ mEditMessage.getEditableText().insert(lastCompletionCursor, completion);
+ lastCompletionLength = completion.length();
+ } else {
+ completionIndex = -1;
+ mEditMessage.getEditableText().delete(lastCompletionCursor,lastCompletionCursor + lastCompletionLength);
+ lastCompletionLength = 0;
+ }
+ return true;
+ }
+
+ @Override
+ public void onActivityResult(int requestCode, int resultCode,
+ final Intent data) {
+ if (resultCode == Activity.RESULT_OK) {
+ if (requestCode == ConversationActivity.REQUEST_DECRYPT_PGP) {
+ activity.getSelectedConversation().getAccount().getPgpDecryptionService().onKeychainUnlocked();
+ keychainUnlock = KEYCHAIN_UNLOCK_NOT_REQUIRED;
+ updatePgpMessages();
+ } else if (requestCode == ConversationActivity.REQUEST_TRUST_KEYS_TEXT) {
+ final String body = mEditMessage.getText().toString();
+ Message message = new Message(conversation, body, conversation.getNextEncryption());
+ sendAxolotlMessage(message);
+ } else if (requestCode == ConversationActivity.REQUEST_TRUST_KEYS_MENU) {
+ int choice = data.getIntExtra("choice", ConversationActivity.ATTACHMENT_CHOICE_INVALID);
+ activity.selectPresenceToAttachFile(choice, conversation.getNextEncryption());
+ }
+ } else {
+ if (requestCode == ConversationActivity.REQUEST_DECRYPT_PGP) {
+ keychainUnlock = KEYCHAIN_UNLOCK_NOT_REQUIRED;
+ updatePgpMessages();
+ }
+ }
+ }
+
private void changeEmojiKeyboardIcon(ImageView iconToBeChanged, int drawableResourceId){
iconToBeChanged.setImageResource(drawableResourceId);
}
diff --git a/src/main/java/de/thedevstack/conversationsplus/ui/EditAccountActivity.java b/src/main/java/de/thedevstack/conversationsplus/ui/EditAccountActivity.java
index 601ddedc..7da2e889 100644
--- a/src/main/java/de/thedevstack/conversationsplus/ui/EditAccountActivity.java
+++ b/src/main/java/de/thedevstack/conversationsplus/ui/EditAccountActivity.java
@@ -1,8 +1,17 @@
package de.thedevstack.conversationsplus.ui;
+import android.app.AlertDialog;
+import android.app.AlertDialog.Builder;
import android.app.PendingIntent;
+import android.content.DialogInterface;
import android.content.Intent;
+import android.content.SharedPreferences;
+import android.graphics.Bitmap;
+import android.net.Uri;
import android.os.Bundle;
+import android.provider.Settings;
+import android.security.KeyChain;
+import android.security.KeyChainAliasCallback;
import android.text.Editable;
import android.text.TextWatcher;
import android.view.Menu;
@@ -20,23 +29,38 @@ import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.TableLayout;
+import android.widget.TableRow;
import android.widget.TextView;
import android.widget.Toast;
+import java.util.Arrays;
+import java.util.List;
+import java.util.Set;
+import java.util.concurrent.atomic.AtomicInteger;
+
+import de.thedevstack.conversationsplus.ui.listeners.ShowResourcesListDialogListener;
+import de.thedevstack.conversationsplus.Config;
import de.thedevstack.conversationsplus.R;
+import de.thedevstack.conversationsplus.crypto.axolotl.AxolotlService;
import de.thedevstack.conversationsplus.entities.Account;
import de.thedevstack.conversationsplus.services.AvatarService;
+import de.thedevstack.conversationsplus.services.XmppConnectionService;
import de.thedevstack.conversationsplus.services.XmppConnectionService.OnAccountUpdate;
+import de.thedevstack.conversationsplus.services.XmppConnectionService.OnCaptchaRequested;
import de.thedevstack.conversationsplus.ui.adapter.KnownHostsAdapter;
-import de.thedevstack.conversationsplus.ui.listeners.ShowResourcesListDialogListener;
import de.thedevstack.conversationsplus.utils.CryptoHelper;
import de.thedevstack.conversationsplus.utils.UIHelper;
+import de.thedevstack.conversationsplus.xml.Element;
+import de.thedevstack.conversationsplus.xmpp.OnKeyStatusUpdated;
+import de.thedevstack.conversationsplus.xmpp.XmppConnection;
import de.thedevstack.conversationsplus.xmpp.XmppConnection.Features;
+import de.thedevstack.conversationsplus.xmpp.forms.Data;
import de.thedevstack.conversationsplus.xmpp.jid.InvalidJidException;
import de.thedevstack.conversationsplus.xmpp.jid.Jid;
import de.thedevstack.conversationsplus.xmpp.pep.Avatar;
-public class EditAccountActivity extends XmppActivity implements OnAccountUpdate{
+public class EditAccountActivity extends XmppActivity implements OnAccountUpdate,
+ OnKeyStatusUpdated, OnCaptchaRequested, KeyChainAliasCallback, XmppConnectionService.OnShowErrorToast, XmppConnectionService.OnMamPreferencesFetched {
private AutoCompleteTextView mAccountJid;
private EditText mPassword;
@@ -44,9 +68,11 @@ public class EditAccountActivity extends XmppActivity implements OnAccountUpdate
private CheckBox mRegisterNew;
private Button mCancelButton;
private Button mSaveButton;
+ private Button mDisableBatterOptimizations;
private TableLayout mMoreTable;
private LinearLayout mStats;
+ private RelativeLayout mBatteryOptimizations;
private TextView mServerInfoSm;
private TextView mServerInfoRosterVersion;
private TextView mServerInfoCarbons;
@@ -54,14 +80,30 @@ public class EditAccountActivity extends XmppActivity implements OnAccountUpdate
private TextView mServerInfoCSI;
private TextView mServerInfoBlocking;
private TextView mServerInfoPep;
+ private TextView mServerInfoHttpUpload;
+ private TextView mServerInfoPush;
private TextView mSessionEst;
private TextView mOtrFingerprint;
+ private TextView mAxolotlFingerprint;
+ private TextView mAccountJidLabel;
private ImageView mAvatar;
private RelativeLayout mOtrFingerprintBox;
+ private RelativeLayout mAxolotlFingerprintBox;
private ImageButton mOtrFingerprintToClipboardButton;
+ private ImageButton mAxolotlFingerprintToClipboardButton;
+ private ImageButton mRegenerateAxolotlKeyButton;
+ private LinearLayout keys;
+ private LinearLayout keysCard;
+ private LinearLayout mNamePort;
+ private EditText mHostname;
+ private EditText mPort;
+ private AlertDialog mCaptchaDialog = null;
private Jid jidToEdit;
+ private boolean mInitMode = false;
+ private boolean mShowOptions = false;
private Account mAccount;
+ private String messageFingerprint;
private boolean mFetchingAvatar = false;
@@ -69,22 +111,67 @@ public class EditAccountActivity extends XmppActivity implements OnAccountUpdate
@Override
public void onClick(final View v) {
+ if (mInitMode && mAccount != null) {
+ mAccount.setOption(Account.OPTION_DISABLED, false);
+ }
if (mAccount != null && mAccount.getStatus() == Account.State.DISABLED && !accountInfoEdited()) {
mAccount.setOption(Account.OPTION_DISABLED, false);
xmppConnectionService.updateAccount(mAccount);
return;
}
- final boolean registerNewAccount = mRegisterNew.isChecked();
+ final boolean registerNewAccount = mRegisterNew.isChecked() && !Config.DISALLOW_REGISTRATION_IN_UI;
+ if (Config.DOMAIN_LOCK != null && mAccountJid.getText().toString().contains("@")) {
+ mAccountJid.setError(getString(R.string.invalid_username));
+ mAccountJid.requestFocus();
+ return;
+ }
final Jid jid;
try {
- jid = Jid.fromString(mAccountJid.getText().toString());
+ if (Config.DOMAIN_LOCK != null) {
+ jid = Jid.fromParts(mAccountJid.getText().toString(), Config.DOMAIN_LOCK, null);
+ } else {
+ jid = Jid.fromString(mAccountJid.getText().toString());
+ }
} catch (final InvalidJidException e) {
- mAccountJid.setError(getString(R.string.invalid_jid));
+ if (Config.DOMAIN_LOCK != null) {
+ mAccountJid.setError(getString(R.string.invalid_username));
+ } else {
+ mAccountJid.setError(getString(R.string.invalid_jid));
+ }
mAccountJid.requestFocus();
return;
}
+ String hostname = null;
+ int numericPort = 5222;
+ if (mShowOptions) {
+ hostname = mHostname.getText().toString();
+ final String port = mPort.getText().toString();
+ if (hostname.contains(" ")) {
+ mHostname.setError(getString(R.string.not_valid_hostname));
+ mHostname.requestFocus();
+ return;
+ }
+ try {
+ numericPort = Integer.parseInt(port);
+ if (numericPort < 0 || numericPort > 65535) {
+ mPort.setError(getString(R.string.not_a_valid_port));
+ mPort.requestFocus();
+ return;
+ }
+
+ } catch (NumberFormatException e) {
+ mPort.setError(getString(R.string.not_a_valid_port));
+ mPort.requestFocus();
+ return;
+ }
+ }
+
if (jid.isDomainJid()) {
- mAccountJid.setError(getString(R.string.invalid_jid));
+ if (Config.DOMAIN_LOCK != null) {
+ mAccountJid.setError(getString(R.string.invalid_username));
+ } else {
+ mAccountJid.setError(getString(R.string.invalid_jid));
+ }
mAccountJid.requestFocus();
return;
}
@@ -98,34 +185,33 @@ public class EditAccountActivity extends XmppActivity implements OnAccountUpdate
}
}
if (mAccount != null) {
- try {
- mAccount.setUsername(jid.hasLocalpart() ? jid.getLocalpart() : "");
- mAccount.setServer(jid.getDomainpart());
- } catch (final InvalidJidException ignored) {
- return;
- }
+ mAccount.setJid(jid);
+ mAccount.setPort(numericPort);
+ mAccount.setHostname(hostname);
mAccountJid.setError(null);
mPasswordConfirm.setError(null);
mAccount.setPassword(password);
mAccount.setOption(Account.OPTION_REGISTER, registerNewAccount);
xmppConnectionService.updateAccount(mAccount);
} else {
- try {
- if (xmppConnectionService.findAccountByJid(Jid.fromString(mAccountJid.getText().toString())) != null) {
- mAccountJid.setError(getString(R.string.account_already_exists));
- mAccountJid.requestFocus();
- return;
- }
- } catch (final InvalidJidException e) {
+ if (xmppConnectionService.findAccountByJid(jid) != null) {
+ mAccountJid.setError(getString(R.string.account_already_exists));
+ mAccountJid.requestFocus();
return;
}
mAccount = new Account(jid.toBareJid(), password);
+ mAccount.setPort(numericPort);
+ mAccount.setHostname(hostname);
mAccount.setOption(Account.OPTION_USETLS, true);
mAccount.setOption(Account.OPTION_USECOMPRESSION, true);
mAccount.setOption(Account.OPTION_REGISTER, registerNewAccount);
xmppConnectionService.createAccount(mAccount);
}
- if (jidToEdit != null && !mAccount.isOptionSet(Account.OPTION_DISABLED)) {
+ mHostname.setError(null);
+ mPort.setError(null);
+ if (!mAccount.isOptionSet(Account.OPTION_DISABLED)
+ && !registerNewAccount
+ && !mInitMode) {
finish();
} else {
updateSaveButton();
@@ -141,35 +227,35 @@ public class EditAccountActivity extends XmppActivity implements OnAccountUpdate
finish();
}
};
+ private Toast mFetchingMamPrefsToast;
+ private TableRow mPushRow;
+
+ public void refreshUiReal() {
+ invalidateOptionsMenu();
+ if (mAccount != null
+ && mAccount.getStatus() != Account.State.ONLINE
+ && mFetchingAvatar) {
+ startActivity(new Intent(getApplicationContext(),
+ ManageAccountActivity.class));
+ finish();
+ } else if (mInitMode && mAccount != null && mAccount.getStatus() == Account.State.ONLINE) {
+ if (!mFetchingAvatar) {
+ mFetchingAvatar = true;
+ AvatarService.getInstance().checkForAvatar(mAccount, mAvatarFetchCallback);
+ }
+ } else {
+ updateSaveButton();
+ }
+ if (mAccount != null) {
+ updateAccountInformation(false);
+ }
+ }
+
@Override
public void onAccountUpdate() {
- runOnUiThread(new Runnable() {
-
- @Override
- public void run() {
- invalidateOptionsMenu();
- if (mAccount != null
- && mAccount.getStatus() != Account.State.ONLINE
- && mFetchingAvatar) {
- startActivity(new Intent(getApplicationContext(),
- ManageAccountActivity.class));
- finish();
- } else if (jidToEdit == null && mAccount != null
- && mAccount.getStatus() == Account.State.ONLINE) {
- if (!mFetchingAvatar) {
- mFetchingAvatar = true;
- AvatarService.getInstance().checkForAvatar(mAccount,
- mAvatarFetchCallback);
- }
- } else {
- updateSaveButton();
- }
- if (mAccount != null) {
- updateAccountInformation(false);
- }
- }
- });
+ refreshUi();
}
+
private final UiCallback<Avatar> mAvatarFetchCallback = new UiCallback<Avatar>() {
@Override
@@ -208,9 +294,8 @@ public class EditAccountActivity extends XmppActivity implements OnAccountUpdate
@Override
public void onClick(final View view) {
if (mAccount != null) {
- final Intent intent = new Intent(getApplicationContext(),
- PublishProfilePictureActivity.class);
- intent.putExtra("account", mAccount.getJid().toBareJid().toString());
+ final Intent intent = new Intent(getApplicationContext(), PublishProfilePictureActivity.class);
+ intent.putExtra(EXTRA_ACCOUNT, mAccount.getJid().toBareJid().toString());
startActivity(intent);
}
}
@@ -222,16 +307,15 @@ public class EditAccountActivity extends XmppActivity implements OnAccountUpdate
@Override
public void run() {
final Intent intent;
- if (avatar != null) {
- intent = new Intent(getApplicationContext(),
- StartConversationActivity.class);
+ final XmppConnection connection = mAccount.getXmppConnection();
+ if (avatar != null || (connection != null && !connection.getFeatures().pep())) {
+ intent = new Intent(getApplicationContext(), StartConversationActivity.class);
if (xmppConnectionService != null && xmppConnectionService.getAccounts().size() == 1) {
intent.putExtra("init", true);
}
} else {
- intent = new Intent(getApplicationContext(),
- PublishProfilePictureActivity.class);
- intent.putExtra("account", mAccount.getJid().toBareJid().toString());
+ intent = new Intent(getApplicationContext(), PublishProfilePictureActivity.class);
+ intent.putExtra(EXTRA_ACCOUNT, mAccount.getJid().toBareJid().toString());
intent.putExtra("setup", true);
}
startActivity(intent);
@@ -240,8 +324,16 @@ public class EditAccountActivity extends XmppActivity implements OnAccountUpdate
});
}
+ @Override
+ protected void onActivityResult(int requestCode, int resultCode, Intent data) {
+ super.onActivityResult(requestCode, resultCode, data);
+ if (requestCode == REQUEST_BATTERY_OP) {
+ updateAccountInformation(mAccount == null);
+ }
+ }
+
protected void updateSaveButton() {
- if (accountInfoEdited() && jidToEdit != null) {
+ if (accountInfoEdited() && !mInitMode) {
this.mSaveButton.setText(R.string.save);
this.mSaveButton.setEnabled(true);
this.mSaveButton.setTextColor(getPrimaryTextColor());
@@ -249,14 +341,14 @@ public class EditAccountActivity extends XmppActivity implements OnAccountUpdate
this.mSaveButton.setEnabled(false);
this.mSaveButton.setTextColor(getSecondaryTextColor());
this.mSaveButton.setText(R.string.account_status_connecting);
- } else if (mAccount != null && mAccount.getStatus() == Account.State.DISABLED) {
+ } else if (mAccount != null && mAccount.getStatus() == Account.State.DISABLED && !mInitMode) {
this.mSaveButton.setEnabled(true);
this.mSaveButton.setTextColor(getPrimaryTextColor());
this.mSaveButton.setText(R.string.enable);
} else {
this.mSaveButton.setEnabled(true);
this.mSaveButton.setTextColor(getPrimaryTextColor());
- if (jidToEdit != null) {
+ if (!mInitMode) {
if (mAccount != null && mAccount.isOnlineAndConnected()) {
this.mSaveButton.setText(R.string.save);
if (!accountInfoEdited()) {
@@ -273,15 +365,24 @@ public class EditAccountActivity extends XmppActivity implements OnAccountUpdate
}
protected boolean accountInfoEdited() {
- return this.mAccount != null && (!this.mAccount.getJid().toBareJid().toString().equals(
- this.mAccountJid.getText().toString())
- || !this.mAccount.getPassword().equals(
- this.mPassword.getText().toString()));
+ if (this.mAccount == null) {
+ return false;
+ }
+ final String unmodified;
+ if (Config.DOMAIN_LOCK != null) {
+ unmodified = this.mAccount.getJid().getLocalpart();
+ } else {
+ unmodified = this.mAccount.getJid().toBareJid().toString();
+ }
+ return !unmodified.equals(this.mAccountJid.getText().toString()) ||
+ !this.mAccount.getPassword().equals(this.mPassword.getText().toString()) ||
+ !this.mAccount.getHostname().equals(this.mHostname.getText().toString()) ||
+ !String.valueOf(this.mAccount.getPort()).equals(this.mPort.getText().toString());
}
@Override
protected String getShareableUri() {
- if (mAccount!=null) {
+ if (mAccount != null) {
return mAccount.getShareableUri();
} else {
return "";
@@ -294,6 +395,11 @@ public class EditAccountActivity extends XmppActivity implements OnAccountUpdate
setContentView(R.layout.activity_edit_account);
this.mAccountJid = (AutoCompleteTextView) findViewById(R.id.account_jid);
this.mAccountJid.addTextChangedListener(this.mTextWatcher);
+ this.mAccountJidLabel = (TextView) findViewById(R.id.account_jid_label);
+ if (Config.DOMAIN_LOCK != null) {
+ this.mAccountJidLabel.setText(R.string.username);
+ this.mAccountJid.setHint(R.string.username_hint);
+ }
this.mPassword = (EditText) findViewById(R.id.account_password);
this.mPassword.addTextChangedListener(this.mTextWatcher);
this.mPasswordConfirm = (EditText) findViewById(R.id.account_password_confirm);
@@ -301,6 +407,17 @@ public class EditAccountActivity extends XmppActivity implements OnAccountUpdate
this.mAvatar.setOnClickListener(this.mAvatarClickListener);
this.mRegisterNew = (CheckBox) findViewById(R.id.account_register_new);
this.mStats = (LinearLayout) findViewById(R.id.stats);
+ this.mBatteryOptimizations = (RelativeLayout) findViewById(R.id.battery_optimization);
+ this.mDisableBatterOptimizations = (Button) findViewById(R.id.batt_op_disable);
+ this.mDisableBatterOptimizations.setOnClickListener(new OnClickListener() {
+ @Override
+ public void onClick(View v) {
+ Intent intent = new Intent(Settings.ACTION_REQUEST_IGNORE_BATTERY_OPTIMIZATIONS);
+ Uri uri = Uri.parse("package:"+getPackageName());
+ intent.setData(uri);
+ startActivityForResult(intent,REQUEST_BATTERY_OP);
+ }
+ });
this.mSessionEst = (TextView) findViewById(R.id.session_est);
this.mServerInfoRosterVersion = (TextView) findViewById(R.id.server_info_roster_version);
this.mServerInfoCarbons = (TextView) findViewById(R.id.server_info_carbons);
@@ -309,9 +426,24 @@ public class EditAccountActivity extends XmppActivity implements OnAccountUpdate
this.mServerInfoBlocking = (TextView) findViewById(R.id.server_info_blocking);
this.mServerInfoSm = (TextView) findViewById(R.id.server_info_sm);
this.mServerInfoPep = (TextView) findViewById(R.id.server_info_pep);
+ this.mServerInfoHttpUpload = (TextView) findViewById(R.id.server_info_http_upload);
+ this.mPushRow = (TableRow) findViewById(R.id.push_row);
+ this.mServerInfoPush = (TextView) findViewById(R.id.server_info_push);
this.mOtrFingerprint = (TextView) findViewById(R.id.otr_fingerprint);
this.mOtrFingerprintBox = (RelativeLayout) findViewById(R.id.otr_fingerprint_box);
this.mOtrFingerprintToClipboardButton = (ImageButton) findViewById(R.id.action_copy_to_clipboard);
+ this.mAxolotlFingerprint = (TextView) findViewById(R.id.axolotl_fingerprint);
+ this.mAxolotlFingerprintBox = (RelativeLayout) findViewById(R.id.axolotl_fingerprint_box);
+ this.mAxolotlFingerprintToClipboardButton = (ImageButton) findViewById(R.id.action_copy_axolotl_to_clipboard);
+ this.mRegenerateAxolotlKeyButton = (ImageButton) findViewById(R.id.action_regenerate_axolotl_key);
+ this.keysCard = (LinearLayout) findViewById(R.id.other_device_keys_card);
+ this.keys = (LinearLayout) findViewById(R.id.other_device_keys);
+ this.mNamePort = (LinearLayout) findViewById(R.id.name_port);
+ this.mHostname = (EditText) findViewById(R.id.hostname);
+ this.mHostname.addTextChangedListener(mTextWatcher);
+ this.mPort = (EditText) findViewById(R.id.port);
+ this.mPort.setText("5222");
+ this.mPort.addTextChangedListener(mTextWatcher);
this.mSaveButton = (Button) findViewById(R.id.save_button);
this.mCancelButton = (Button) findViewById(R.id.cancel_button);
this.mSaveButton.setOnClickListener(this.mSaveButtonClickListener);
@@ -320,7 +452,7 @@ public class EditAccountActivity extends XmppActivity implements OnAccountUpdate
final OnCheckedChangeListener OnCheckedShowConfirmPassword = new OnCheckedChangeListener() {
@Override
public void onCheckedChanged(final CompoundButton buttonView,
- final boolean isChecked) {
+ final boolean isChecked) {
if (isChecked) {
mPasswordConfirm.setVisibility(View.VISIBLE);
} else {
@@ -330,6 +462,9 @@ public class EditAccountActivity extends XmppActivity implements OnAccountUpdate
}
};
this.mRegisterNew.setOnCheckedChangeListener(OnCheckedShowConfirmPassword);
+ if (Config.DISALLOW_REGISTRATION_IN_UI) {
+ this.mRegisterNew.setVisibility(View.GONE);
+ }
}
@Override
@@ -340,6 +475,12 @@ public class EditAccountActivity extends XmppActivity implements OnAccountUpdate
final MenuItem showBlocklist = menu.findItem(R.id.action_show_block_list);
final MenuItem showMoreInfo = menu.findItem(R.id.action_server_info_show_more);
final MenuItem changePassword = menu.findItem(R.id.action_change_password_on_server);
+ final MenuItem clearDevices = menu.findItem(R.id.action_clear_devices);
+ final MenuItem renewCertificate = menu.findItem(R.id.action_renew_certificate);
+ final MenuItem mamPrefs = menu.findItem(R.id.action_mam_prefs);
+
+ renewCertificate.setVisible(mAccount != null && mAccount.getPrivateKeyAlias() != null);
+
if (mAccount != null && mAccount.isOnlineAndConnected()) {
if (!mAccount.getXmppConnection().getFeatures().blocking()) {
showBlocklist.setVisible(false);
@@ -347,11 +488,18 @@ public class EditAccountActivity extends XmppActivity implements OnAccountUpdate
if (!mAccount.getXmppConnection().getFeatures().register()) {
changePassword.setVisible(false);
}
+ mamPrefs.setVisible(mAccount.getXmppConnection().getFeatures().mam());
+ Set<Integer> otherDevices = mAccount.getAxolotlService().getOwnDeviceIds();
+ if (otherDevices == null || otherDevices.isEmpty()) {
+ clearDevices.setVisible(false);
+ }
} else {
showQrCode.setVisible(false);
showBlocklist.setVisible(false);
showMoreInfo.setVisible(false);
changePassword.setVisible(false);
+ clearDevices.setVisible(false);
+ mamPrefs.setVisible(false);
}
return true;
}
@@ -365,7 +513,9 @@ public class EditAccountActivity extends XmppActivity implements OnAccountUpdate
} catch (final InvalidJidException | NullPointerException ignored) {
this.jidToEdit = null;
}
- if (this.jidToEdit != null) {
+ this.mInitMode = getIntent().getBooleanExtra("init", false) || this.jidToEdit == null;
+ this.messageFingerprint = getIntent().getStringExtra("fingerprint");
+ if (!mInitMode) {
this.mRegisterNew.setVisibility(View.GONE);
if (getActionBar() != null) {
getActionBar().setTitle(getString(R.string.account_details));
@@ -377,16 +527,24 @@ public class EditAccountActivity extends XmppActivity implements OnAccountUpdate
}
}
}
+ SharedPreferences preferences = getPreferences();
+ this.mShowOptions = preferences.getBoolean("show_connection_options", false);
+ this.mNamePort.setVisibility(mShowOptions ? View.VISIBLE : View.GONE);
}
@Override
protected void onBackendConnected() {
- final KnownHostsAdapter mKnownHostsAdapter = new KnownHostsAdapter(this,
- android.R.layout.simple_list_item_1,
- xmppConnectionService.getKnownHosts());
if (this.jidToEdit != null) {
this.mAccount = xmppConnectionService.findAccountByJid(jidToEdit);
- updateAccountInformation(true);
+ if (this.mAccount != null) {
+ if (this.mAccount.getPrivateKeyAlias() != null) {
+ this.mPassword.setHint(R.string.authenticate_with_certificate);
+ if (this.mInitMode) {
+ this.mPassword.requestFocus();
+ }
+ }
+ updateAccountInformation(true);
+ }
} else if (this.xmppConnectionService.getAccounts().size() == 0) {
if (getActionBar() != null) {
getActionBar().setDisplayHomeAsUpEnabled(false);
@@ -396,8 +554,14 @@ public class EditAccountActivity extends XmppActivity implements OnAccountUpdate
this.mCancelButton.setEnabled(false);
this.mCancelButton.setTextColor(getSecondaryTextColor());
}
- this.mAccountJid.setAdapter(mKnownHostsAdapter);
+ if (Config.DOMAIN_LOCK == null) {
+ final KnownHostsAdapter mKnownHostsAdapter = new KnownHostsAdapter(this,
+ android.R.layout.simple_list_item_1,
+ xmppConnectionService.getKnownHosts());
+ this.mAccountJid.setAdapter(mKnownHostsAdapter);
+ }
updateSaveButton();
+ invalidateOptionsMenu();
}
@Override
@@ -405,7 +569,7 @@ public class EditAccountActivity extends XmppActivity implements OnAccountUpdate
switch (item.getItemId()) {
case R.id.action_show_block_list:
final Intent showBlocklistIntent = new Intent(this, BlocklistActivity.class);
- showBlocklistIntent.putExtra("account", mAccount.getJid().toString());
+ showBlocklistIntent.putExtra(EXTRA_ACCOUNT, mAccount.getJid().toString());
startActivity(showBlocklistIntent);
break;
case R.id.action_server_info_show_more:
@@ -414,19 +578,50 @@ public class EditAccountActivity extends XmppActivity implements OnAccountUpdate
break;
case R.id.action_change_password_on_server:
final Intent changePasswordIntent = new Intent(this, ChangePasswordActivity.class);
- changePasswordIntent.putExtra("account", mAccount.getJid().toString());
+ changePasswordIntent.putExtra(EXTRA_ACCOUNT, mAccount.getJid().toString());
startActivity(changePasswordIntent);
break;
+ case R.id.action_mam_prefs:
+ editMamPrefs();
+ break;
+ case R.id.action_clear_devices:
+ showWipePepDialog();
+ break;
+ case R.id.action_renew_certificate:
+ renewCertificate();
+ break;
}
return super.onOptionsItemSelected(item);
}
+ private void renewCertificate() {
+ KeyChain.choosePrivateKeyAlias(this, this, null, null, null, -1, null);
+ }
+
+ @Override
+ public void alias(String alias) {
+ if (alias != null) {
+ xmppConnectionService.updateKeyInAccount(mAccount, alias);
+ }
+ }
+
private void updateAccountInformation(boolean init) {
if (init) {
- this.mAccountJid.setText(this.mAccount.getJid().toBareJid().toString());
+ this.mAccountJid.getEditableText().clear();
+ if (Config.DOMAIN_LOCK != null) {
+ this.mAccountJid.getEditableText().append(this.mAccount.getJid().getLocalpart());
+ } else {
+ this.mAccountJid.getEditableText().append(this.mAccount.getJid().toBareJid().toString());
+ }
this.mPassword.setText(this.mAccount.getPassword());
+ this.mHostname.setText("");
+ this.mHostname.getEditableText().append(this.mAccount.getHostname());
+ this.mPort.setText("");
+ this.mPort.getEditableText().append(String.valueOf(this.mAccount.getPort()));
+ this.mNamePort.setVisibility(mShowOptions ? View.VISIBLE : View.GONE);
+
}
- if (this.jidToEdit != null) {
+ if (!mInitMode) {
this.mAvatar.setVisibility(View.VISIBLE);
this.mAvatar.setImageBitmap(AvatarService.getInstance().get(this.mAccount, getPixel(72)));
}
@@ -449,8 +644,9 @@ public class EditAccountActivity extends XmppActivity implements OnAccountUpdate
detailsAccountJid.setText(this.mAccount.getJid().toBareJid().toString());
}
this.mStats.setVisibility(View.VISIBLE);
+ this.mBatteryOptimizations.setVisibility(showBatteryOptimizationWarning() ? View.VISIBLE : View.GONE);
this.mSessionEst.setText(UIHelper.readableTimeDifferenceFull(this, this.mAccount.getXmppConnection()
- .getLastSessionEstablished()));
+ .getLastSessionEstablished()));
Features features = this.mAccount.getXmppConnection().getFeatures();
if (features.rosterVersioning()) {
this.mServerInfoRosterVersion.setText(R.string.server_info_available);
@@ -461,7 +657,7 @@ public class EditAccountActivity extends XmppActivity implements OnAccountUpdate
this.mServerInfoCarbons.setText(R.string.server_info_available);
} else {
this.mServerInfoCarbons
- .setText(R.string.server_info_unavailable);
+ .setText(R.string.server_info_unavailable);
}
if (features.mam()) {
this.mServerInfoMam.setText(R.string.server_info_available);
@@ -484,43 +680,286 @@ public class EditAccountActivity extends XmppActivity implements OnAccountUpdate
this.mServerInfoSm.setText(R.string.server_info_unavailable);
}
if (features.pep()) {
- this.mServerInfoPep.setText(R.string.server_info_available);
+ AxolotlService axolotlService = this.mAccount.getAxolotlService();
+ if (axolotlService != null && axolotlService.isPepBroken()) {
+ this.mServerInfoPep.setText(R.string.server_info_broken);
+ } else {
+ this.mServerInfoPep.setText(R.string.server_info_available);
+ }
} else {
this.mServerInfoPep.setText(R.string.server_info_unavailable);
}
- final String fingerprint = this.mAccount.getOtrFingerprint();
- if (fingerprint != null) {
+ if (features.httpUpload()) {
+ this.mServerInfoHttpUpload.setText(R.string.server_info_available);
+ } else {
+ this.mServerInfoHttpUpload.setText(R.string.server_info_unavailable);
+ }
+
+ this.mPushRow.setVisibility(xmppConnectionService.getPushManagementService().isStub() ? View.GONE : View.VISIBLE);
+
+ if (xmppConnectionService.getPushManagementService().available(mAccount)) {
+ this.mServerInfoPush.setText(R.string.server_info_available);
+ } else {
+ this.mServerInfoPush.setText(R.string.server_info_unavailable);
+ }
+ final String otrFingerprint = this.mAccount.getOtrFingerprint();
+ if (otrFingerprint != null) {
this.mOtrFingerprintBox.setVisibility(View.VISIBLE);
- this.mOtrFingerprint.setText(CryptoHelper.prettifyFingerprint(fingerprint));
+ this.mOtrFingerprint.setText(CryptoHelper.prettifyFingerprint(otrFingerprint));
this.mOtrFingerprintToClipboardButton
- .setVisibility(View.VISIBLE);
+ .setVisibility(View.VISIBLE);
this.mOtrFingerprintToClipboardButton
- .setOnClickListener(new View.OnClickListener() {
+ .setOnClickListener(new View.OnClickListener() {
- @Override
- public void onClick(final View v) {
+ @Override
+ public void onClick(final View v) {
- if (copyTextToClipboard(fingerprint, R.string.otr_fingerprint)) {
- Toast.makeText(
- EditAccountActivity.this,
- R.string.toast_message_otr_fingerprint,
- Toast.LENGTH_SHORT).show();
+ if (copyTextToClipboard(otrFingerprint, R.string.otr_fingerprint)) {
+ Toast.makeText(
+ EditAccountActivity.this,
+ R.string.toast_message_otr_fingerprint,
+ Toast.LENGTH_SHORT).show();
+ }
}
- }
- });
+ });
} else {
this.mOtrFingerprintBox.setVisibility(View.GONE);
}
+ final String axolotlFingerprint = this.mAccount.getAxolotlService().getOwnFingerprint();
+ if (axolotlFingerprint != null) {
+ this.mAxolotlFingerprintBox.setVisibility(View.VISIBLE);
+ this.mAxolotlFingerprint.setText(CryptoHelper.prettifyFingerprint(axolotlFingerprint.substring(2)));
+ this.mAxolotlFingerprintToClipboardButton
+ .setVisibility(View.VISIBLE);
+ this.mAxolotlFingerprintToClipboardButton
+ .setOnClickListener(new View.OnClickListener() {
+
+ @Override
+ public void onClick(final View v) {
+
+ if (copyTextToClipboard(axolotlFingerprint.substring(2), R.string.omemo_fingerprint)) {
+ Toast.makeText(
+ EditAccountActivity.this,
+ R.string.toast_message_omemo_fingerprint,
+ Toast.LENGTH_SHORT).show();
+ }
+ }
+ });
+ if (Config.SHOW_REGENERATE_AXOLOTL_KEYS_BUTTON) {
+ this.mRegenerateAxolotlKeyButton
+ .setVisibility(View.VISIBLE);
+ this.mRegenerateAxolotlKeyButton
+ .setOnClickListener(new View.OnClickListener() {
+
+ @Override
+ public void onClick(final View v) {
+ showRegenerateAxolotlKeyDialog();
+ }
+ });
+ }
+ } else {
+ this.mAxolotlFingerprintBox.setVisibility(View.GONE);
+ }
+ final String ownFingerprint = mAccount.getAxolotlService().getOwnFingerprint();
+ boolean hasKeys = false;
+ keys.removeAllViews();
+ for (final String fingerprint : mAccount.getAxolotlService().getFingerprintsForOwnSessions()) {
+ if (ownFingerprint.equals(fingerprint)) {
+ continue;
+ }
+ boolean highlight = fingerprint.equals(messageFingerprint);
+ hasKeys |= addFingerprintRow(keys, mAccount, fingerprint, highlight, null);
+ }
+ if (hasKeys) {
+ keysCard.setVisibility(View.VISIBLE);
+ } else {
+ keysCard.setVisibility(View.GONE);
+ }
} else {
if (this.mAccount.errorStatus()) {
- this.mAccountJid.setError(getString(this.mAccount.getStatus().getReadableId()));
+ final EditText errorTextField;
+ if (this.mAccount.getStatus() == Account.State.UNAUTHORIZED) {
+ errorTextField = this.mPassword;
+ } else if (mShowOptions
+ && this.mAccount.getStatus() == Account.State.SERVER_NOT_FOUND
+ && this.mHostname.getText().length() > 0) {
+ errorTextField = this.mHostname;
+ } else {
+ errorTextField = this.mAccountJid;
+ }
+ errorTextField.setError(getString(this.mAccount.getStatus().getReadableId()));
if (init || !accountInfoEdited()) {
- this.mAccountJid.requestFocus();
+ errorTextField.requestFocus();
}
} else {
this.mAccountJid.setError(null);
+ this.mPassword.setError(null);
+ this.mHostname.setError(null);
}
this.mStats.setVisibility(View.GONE);
}
}
+
+ public void showRegenerateAxolotlKeyDialog() {
+ Builder builder = new Builder(this);
+ builder.setTitle("Regenerate Key");
+ builder.setIconAttribute(android.R.attr.alertDialogIcon);
+ builder.setMessage("Are you sure you want to regenerate your Identity Key? (This will also wipe all established sessions and contact Identity Keys)");
+ builder.setNegativeButton(getString(R.string.cancel), null);
+ builder.setPositiveButton("Yes",
+ new DialogInterface.OnClickListener() {
+ @Override
+ public void onClick(DialogInterface dialog, int which) {
+ mAccount.getAxolotlService().regenerateKeys(false);
+ }
+ });
+ builder.create().show();
+ }
+
+ public void showWipePepDialog() {
+ Builder builder = new Builder(this);
+ builder.setTitle(getString(R.string.clear_other_devices));
+ builder.setIconAttribute(android.R.attr.alertDialogIcon);
+ builder.setMessage(getString(R.string.clear_other_devices_desc));
+ builder.setNegativeButton(getString(R.string.cancel), null);
+ builder.setPositiveButton(getString(R.string.accept),
+ new DialogInterface.OnClickListener() {
+ @Override
+ public void onClick(DialogInterface dialog, int which) {
+ mAccount.getAxolotlService().wipeOtherPepDevices();
+ }
+ });
+ builder.create().show();
+ }
+
+ private void editMamPrefs() {
+ this.mFetchingMamPrefsToast = Toast.makeText(this, R.string.fetching_mam_prefs, Toast.LENGTH_LONG);
+ this.mFetchingMamPrefsToast.show();
+ xmppConnectionService.fetchMamPreferences(mAccount, this);
+ }
+
+ @Override
+ public void onKeyStatusUpdated(AxolotlService.FetchStatus report) {
+ refreshUi();
+ }
+
+ @Override
+ public void onCaptchaRequested(final Account account, final String id, final Data data,
+ final Bitmap captcha) {
+ final AlertDialog.Builder builder = new AlertDialog.Builder(this);
+ final ImageView view = new ImageView(this);
+ final LinearLayout layout = new LinearLayout(this);
+ final EditText input = new EditText(this);
+
+ view.setImageBitmap(captcha);
+ view.setScaleType(ImageView.ScaleType.FIT_CENTER);
+
+ input.setHint(getString(R.string.captcha_hint));
+
+ layout.setOrientation(LinearLayout.VERTICAL);
+ layout.addView(view);
+ layout.addView(input);
+
+ builder.setTitle(getString(R.string.captcha_required));
+ builder.setView(layout);
+
+ builder.setPositiveButton(getString(R.string.ok),
+ new DialogInterface.OnClickListener() {
+ @Override
+ public void onClick(DialogInterface dialog, int which) {
+ String rc = input.getText().toString();
+ data.put("username", account.getUsername());
+ data.put("password", account.getPassword());
+ data.put("ocr", rc);
+ data.submit();
+
+ if (xmppConnectionServiceBound) {
+ xmppConnectionService.sendCreateAccountWithCaptchaPacket(
+ account, id, data);
+ }
+ }
+ });
+ builder.setNegativeButton(getString(R.string.cancel), new DialogInterface.OnClickListener() {
+ @Override
+ public void onClick(DialogInterface dialog, int which) {
+ if (xmppConnectionService != null) {
+ xmppConnectionService.sendCreateAccountWithCaptchaPacket(account, null, null);
+ }
+ }
+ });
+
+ builder.setOnCancelListener(new DialogInterface.OnCancelListener() {
+ @Override
+ public void onCancel(DialogInterface dialog) {
+ if (xmppConnectionService != null) {
+ xmppConnectionService.sendCreateAccountWithCaptchaPacket(account, null, null);
+ }
+ }
+ });
+
+ runOnUiThread(new Runnable() {
+ @Override
+ public void run() {
+ if ((mCaptchaDialog != null) && mCaptchaDialog.isShowing()) {
+ mCaptchaDialog.dismiss();
+ }
+ mCaptchaDialog = builder.create();
+ mCaptchaDialog.show();
+ }
+ });
+ }
+
+ public void onShowErrorToast(final int resId) {
+ runOnUiThread(new Runnable() {
+ @Override
+ public void run() {
+ Toast.makeText(EditAccountActivity.this, resId, Toast.LENGTH_SHORT).show();
+ }
+ });
+ }
+
+ @Override
+ public void onPreferencesFetched(final Element prefs) {
+ runOnUiThread(new Runnable() {
+ @Override
+ public void run() {
+ if (mFetchingMamPrefsToast != null) {
+ mFetchingMamPrefsToast.cancel();
+ }
+ AlertDialog.Builder builder = new Builder(EditAccountActivity.this);
+ builder.setTitle(R.string.server_side_mam_prefs);
+ String defaultAttr = prefs.getAttribute("default");
+ final List<String> defaults = Arrays.asList("never", "roster", "always");
+ final AtomicInteger choice = new AtomicInteger(Math.max(0,defaults.indexOf(defaultAttr)));
+ builder.setSingleChoiceItems(R.array.mam_prefs, choice.get(), new DialogInterface.OnClickListener() {
+ @Override
+ public void onClick(DialogInterface dialog, int which) {
+ choice.set(which);
+ }
+ });
+ builder.setNegativeButton(R.string.cancel, null);
+ builder.setPositiveButton(R.string.ok, new DialogInterface.OnClickListener() {
+ @Override
+ public void onClick(DialogInterface dialog, int which) {
+ prefs.setAttribute("default",defaults.get(choice.get()));
+ xmppConnectionService.pushMamPreferences(mAccount, prefs);
+ }
+ });
+ builder.create().show();
+ }
+ });
+ }
+
+ @Override
+ public void onPreferencesFetchFailed() {
+ runOnUiThread(new Runnable() {
+ @Override
+ public void run() {
+ if (mFetchingMamPrefsToast != null) {
+ mFetchingMamPrefsToast.cancel();
+ }
+ Toast.makeText(EditAccountActivity.this,R.string.unable_to_fetch_mam_prefs,Toast.LENGTH_LONG).show();
+ }
+ });
+ }
}
diff --git a/src/main/java/de/thedevstack/conversationsplus/ui/EditMessage.java b/src/main/java/de/thedevstack/conversationsplus/ui/EditMessage.java
index 5c2e6164..5664434f 100644
--- a/src/main/java/de/thedevstack/conversationsplus/ui/EditMessage.java
+++ b/src/main/java/de/thedevstack/conversationsplus/ui/EditMessage.java
@@ -32,21 +32,32 @@ public class EditMessage extends EmojiconEditText {
private boolean isUserTyping = false;
+ private boolean lastInputWasTab = false;
+
protected KeyboardListener keyboardListener;
@Override
- public boolean onKeyDown(int keyCode, KeyEvent event) {
- if (keyCode == KeyEvent.KEYCODE_ENTER) {
+ public boolean onKeyDown(int keyCode, KeyEvent e) {
+ if (keyCode == KeyEvent.KEYCODE_ENTER && !e.isShiftPressed()) {
+ lastInputWasTab = false;
if (keyboardListener != null && keyboardListener.onEnterPressed()) {
return true;
}
+ } else if (keyCode == KeyEvent.KEYCODE_TAB && !e.isAltPressed() && !e.isCtrlPressed()) {
+ if (keyboardListener != null && keyboardListener.onTabPressed(this.lastInputWasTab)) {
+ lastInputWasTab = true;
+ return true;
+ }
+ } else {
+ lastInputWasTab = false;
}
- return super.onKeyDown(keyCode, event);
+ return super.onKeyDown(keyCode, e);
}
@Override
public void onTextChanged(CharSequence text, int start, int lengthBefore, int lengthAfter) {
super.onTextChanged(text,start,lengthBefore,lengthAfter);
+ lastInputWasTab = false;
if (this.mTypingHandler != null && this.keyboardListener != null) {
this.mTypingHandler.removeCallbacks(mTypingTimeout);
this.mTypingHandler.postDelayed(mTypingTimeout, Config.TYPING_TIMEOUT * 1000);
@@ -69,10 +80,11 @@ public class EditMessage extends EmojiconEditText {
}
public interface KeyboardListener {
- public boolean onEnterPressed();
- public void onTypingStarted();
- public void onTypingStopped();
- public void onTextDeleted();
+ boolean onEnterPressed();
+ void onTypingStarted();
+ void onTypingStopped();
+ void onTextDeleted();
+ boolean onTabPressed(boolean repeated);
}
}
diff --git a/src/main/java/de/thedevstack/conversationsplus/ui/EnterJidDialog.java b/src/main/java/de/thedevstack/conversationsplus/ui/EnterJidDialog.java
new file mode 100644
index 00000000..9e52d390
--- /dev/null
+++ b/src/main/java/de/thedevstack/conversationsplus/ui/EnterJidDialog.java
@@ -0,0 +1,134 @@
+package de.thedevstack.conversationsplus.ui;
+
+import android.app.AlertDialog;
+import android.content.Context;
+import android.view.LayoutInflater;
+import android.view.View;
+import android.widget.ArrayAdapter;
+import android.widget.AutoCompleteTextView;
+import android.widget.Spinner;
+import android.widget.TextView;
+
+import java.util.List;
+
+import de.thedevstack.conversationsplus.Config;
+import de.thedevstack.conversationsplus.R;
+import de.thedevstack.conversationsplus.ui.adapter.KnownHostsAdapter;
+import de.thedevstack.conversationsplus.xmpp.jid.InvalidJidException;
+import de.thedevstack.conversationsplus.xmpp.jid.Jid;
+
+public class EnterJidDialog {
+ public interface OnEnterJidDialogPositiveListener {
+ boolean onEnterJidDialogPositive(Jid account, Jid contact) throws EnterJidDialog.JidError;
+ }
+
+ public static class JidError extends Exception {
+ final String msg;
+
+ public JidError(final String msg) {
+ this.msg = msg;
+ }
+
+ public String toString() {
+ return msg;
+ }
+ }
+
+ protected final AlertDialog dialog;
+ protected View.OnClickListener dialogOnClick;
+ protected OnEnterJidDialogPositiveListener listener = null;
+
+ public EnterJidDialog(
+ final Context context, List<String> knownHosts, final List<String> activatedAccounts,
+ final String title, final String positiveButton,
+ final String prefilledJid, final String account, boolean allowEditJid
+ ) {
+ final boolean lock = Config.LOCK_DOMAINS_IN_CONVERSATIONS && Config.DOMAIN_LOCK != null;
+ AlertDialog.Builder builder = new AlertDialog.Builder(context);
+ builder.setTitle(title);
+ View dialogView = LayoutInflater.from(context).inflate(R.layout.enter_jid_dialog, null);
+ final TextView jabberIdDesc = (TextView) dialogView.findViewById(R.id.jabber_id);
+ jabberIdDesc.setText(lock ? R.string.username : R.string.account_settings_jabber_id);
+ final Spinner spinner = (Spinner) dialogView.findViewById(R.id.account);
+ final AutoCompleteTextView jid = (AutoCompleteTextView) dialogView.findViewById(R.id.jid);
+ if (!lock) {
+ jid.setAdapter(new KnownHostsAdapter(context, android.R.layout.simple_list_item_1, knownHosts));
+ }
+ if (prefilledJid != null) {
+ jid.append(prefilledJid);
+ if (!allowEditJid) {
+ jid.setFocusable(false);
+ jid.setFocusableInTouchMode(false);
+ jid.setClickable(false);
+ jid.setCursorVisible(false);
+ }
+ }
+
+ jid.setHint(Config.LOCK_DOMAINS_IN_CONVERSATIONS && Config.DOMAIN_LOCK != null ? R.string.username_hint : R.string.account_settings_example_jabber_id);
+
+ if (account == null) {
+ StartConversationActivity.populateAccountSpinner(context, activatedAccounts, spinner);
+ } else {
+ ArrayAdapter<String> adapter = new ArrayAdapter<>(context,
+ android.R.layout.simple_spinner_item,
+ new String[] { account });
+ spinner.setEnabled(false);
+ adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
+ spinner.setAdapter(adapter);
+ }
+
+ builder.setView(dialogView);
+ builder.setNegativeButton(R.string.cancel, null);
+ builder.setPositiveButton(positiveButton, null);
+ this.dialog = builder.create();
+
+ this.dialogOnClick = new View.OnClickListener() {
+ @Override
+ public void onClick(final View v) {
+ final Jid accountJid;
+ if (!spinner.isEnabled() && account == null) {
+ return;
+ }
+ try {
+ if (Config.DOMAIN_LOCK != null) {
+ accountJid = Jid.fromParts((String) spinner.getSelectedItem(), Config.DOMAIN_LOCK, null);
+ } else {
+ accountJid = Jid.fromString((String) spinner.getSelectedItem());
+ }
+ } catch (final InvalidJidException e) {
+ return;
+ }
+ final Jid contactJid;
+ try {
+ if (lock) {
+ contactJid = Jid.fromParts(jid.getText().toString(), Config.DOMAIN_LOCK, null);
+ } else {
+ contactJid = Jid.fromString(jid.getText().toString());
+ }
+ } catch (final InvalidJidException e) {
+ jid.setError(context.getString(lock ? R.string.invalid_username : R.string.invalid_jid));
+ return;
+ }
+
+ if(listener != null) {
+ try {
+ if(listener.onEnterJidDialogPositive(accountJid, contactJid)) {
+ dialog.dismiss();
+ }
+ } catch(JidError error) {
+ jid.setError(error.toString());
+ }
+ }
+ }
+ };
+ }
+
+ public void setOnEnterJidDialogPositiveListener(OnEnterJidDialogPositiveListener listener) {
+ this.listener = listener;
+ }
+
+ public void show() {
+ this.dialog.show();
+ this.dialog.getButton(AlertDialog.BUTTON_POSITIVE).setOnClickListener(this.dialogOnClick);
+ }
+}
diff --git a/src/main/java/de/thedevstack/conversationsplus/ui/ExportLogsPreference.java b/src/main/java/de/thedevstack/conversationsplus/ui/ExportLogsPreference.java
new file mode 100644
index 00000000..eabb7518
--- /dev/null
+++ b/src/main/java/de/thedevstack/conversationsplus/ui/ExportLogsPreference.java
@@ -0,0 +1,29 @@
+package de.thedevstack.conversationsplus.ui;
+
+import android.content.Context;
+import android.content.Intent;
+import android.preference.Preference;
+import android.util.AttributeSet;
+
+import de.thedevstack.conversationsplus.services.ExportLogsService;
+
+public class ExportLogsPreference extends Preference {
+
+ public ExportLogsPreference(Context context, AttributeSet attrs, int defStyleAttr) {
+ super(context, attrs, defStyleAttr);
+ }
+
+ public ExportLogsPreference(Context context, AttributeSet attrs) {
+ super(context, attrs);
+ }
+
+ public ExportLogsPreference(Context context) {
+ super(context);
+ }
+
+ protected void onClick() {
+ final Intent startIntent = new Intent(getContext(), ExportLogsService.class);
+ getContext().startService(startIntent);
+ super.onClick();
+ }
+} \ No newline at end of file
diff --git a/src/main/java/de/thedevstack/conversationsplus/ui/ManageAccountActivity.java b/src/main/java/de/thedevstack/conversationsplus/ui/ManageAccountActivity.java
index 0820ec8b..431111f5 100644
--- a/src/main/java/de/thedevstack/conversationsplus/ui/ManageAccountActivity.java
+++ b/src/main/java/de/thedevstack/conversationsplus/ui/ManageAccountActivity.java
@@ -1,34 +1,54 @@
package de.thedevstack.conversationsplus.ui;
-import java.util.ArrayList;
-import java.util.List;
-
-import de.thedevstack.conversationsplus.R;
-import de.thedevstack.conversationsplus.entities.Account;
-import de.thedevstack.conversationsplus.services.XmppConnectionService.OnAccountUpdate;
-import de.thedevstack.conversationsplus.ui.adapter.AccountAdapter;
+import android.app.ActionBar;
import android.app.AlertDialog;
+import android.content.ActivityNotFoundException;
import android.content.DialogInterface;
import android.content.DialogInterface.OnClickListener;
import android.content.Intent;
import android.os.Bundle;
+import android.security.KeyChain;
+import android.security.KeyChainAliasCallback;
+import android.util.Pair;
import android.view.ContextMenu;
+import android.view.ContextMenu.ContextMenuInfo;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
-import android.view.ContextMenu.ContextMenuInfo;
import android.widget.AdapterView;
import android.widget.AdapterView.AdapterContextMenuInfo;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.ListView;
+import android.widget.Toast;
+
+import org.openintents.openpgp.util.OpenPgpApi;
+
+import java.util.ArrayList;
+import java.util.List;
+import java.util.concurrent.atomic.AtomicBoolean;
+
+import de.thedevstack.conversationsplus.Config;
+import de.thedevstack.conversationsplus.R;
+import de.thedevstack.conversationsplus.entities.Account;
+import de.thedevstack.conversationsplus.services.XmppConnectionService;
+import de.thedevstack.conversationsplus.services.XmppConnectionService.OnAccountUpdate;
+import de.thedevstack.conversationsplus.ui.adapter.AccountAdapter;
+import de.thedevstack.conversationsplus.xmpp.jid.InvalidJidException;
+import de.thedevstack.conversationsplus.xmpp.jid.Jid;
-public class ManageAccountActivity extends XmppActivity implements OnAccountUpdate {
+public class ManageAccountActivity extends XmppActivity implements OnAccountUpdate, KeyChainAliasCallback, XmppConnectionService.OnAccountCreated {
+
+ private final String STATE_SELECTED_ACCOUNT = "selected_account";
protected Account selectedAccount = null;
+ protected Jid selectedAccountJid = null;
protected final List<Account> accountList = new ArrayList<>();
protected ListView accountListView;
protected AccountAdapter mAccountAdapter;
+ protected AtomicBoolean mInvokedAddAccount = new AtomicBoolean(false);
+
+ protected Pair<Integer, Intent> mPostponedActivityResult = null;
@Override
public void onAccountUpdate() {
@@ -41,6 +61,11 @@ public class ManageAccountActivity extends XmppActivity implements OnAccountUpda
accountList.clear();
accountList.addAll(xmppConnectionService.getAccounts());
}
+ ActionBar actionBar = getActionBar();
+ if (actionBar != null) {
+ actionBar.setHomeButtonEnabled(this.accountList.size() > 0);
+ actionBar.setDisplayHomeAsUpEnabled(this.accountList.size() > 0);
+ }
invalidateOptionsMenu();
mAccountAdapter.notifyDataSetChanged();
}
@@ -52,6 +77,17 @@ public class ManageAccountActivity extends XmppActivity implements OnAccountUpda
setContentView(R.layout.manage_accounts);
+ if (savedInstanceState != null) {
+ String jid = savedInstanceState.getString(STATE_SELECTED_ACCOUNT);
+ if (jid != null) {
+ try {
+ this.selectedAccountJid = Jid.fromString(jid);
+ } catch (InvalidJidException e) {
+ this.selectedAccountJid = null;
+ }
+ }
+ }
+
accountListView = (ListView) findViewById(R.id.account_list);
this.mAccountAdapter = new AccountAdapter(this, accountList);
accountListView.setAdapter(this.mAccountAdapter);
@@ -59,7 +95,7 @@ public class ManageAccountActivity extends XmppActivity implements OnAccountUpda
@Override
public void onItemClick(AdapterView<?> arg0, View view,
- int position, long arg3) {
+ int position, long arg3) {
switchToAccount(accountList.get(position));
}
});
@@ -67,12 +103,19 @@ public class ManageAccountActivity extends XmppActivity implements OnAccountUpda
}
@Override
- public void onCreateContextMenu(ContextMenu menu, View v,
- ContextMenuInfo menuInfo) {
+ public void onSaveInstanceState(final Bundle savedInstanceState) {
+ if (selectedAccount != null) {
+ savedInstanceState.putString(STATE_SELECTED_ACCOUNT, selectedAccount.getJid().toBareJid().toString());
+ }
+ super.onSaveInstanceState(savedInstanceState);
+ }
+
+ @Override
+ public void onCreateContextMenu(ContextMenu menu, View v, ContextMenuInfo menuInfo) {
super.onCreateContextMenu(menu, v, menuInfo);
ManageAccountActivity.this.getMenuInflater().inflate(
R.menu.manageaccounts_context, menu);
- AdapterView.AdapterContextMenuInfo acmi = (AdapterContextMenuInfo) menuInfo;
+ AdapterContextMenuInfo acmi = (AdapterContextMenuInfo) menuInfo;
this.selectedAccount = accountList.get(acmi.position);
if (this.selectedAccount.isOptionSet(Account.OPTION_DISABLED)) {
menu.findItem(R.id.mgmt_account_disable).setVisible(false);
@@ -80,21 +123,42 @@ public class ManageAccountActivity extends XmppActivity implements OnAccountUpda
menu.findItem(R.id.mgmt_account_publish_avatar).setVisible(false);
} else {
menu.findItem(R.id.mgmt_account_enable).setVisible(false);
+ menu.findItem(R.id.mgmt_account_announce_pgp).setVisible(Config.supportOpenPgp());
}
menu.setHeaderTitle(this.selectedAccount.getJid().toBareJid().toString());
}
@Override
void onBackendConnected() {
- this.accountList.clear();
- this.accountList.addAll(xmppConnectionService.getAccounts());
- mAccountAdapter.notifyDataSetChanged();
+ if (selectedAccountJid != null) {
+ this.selectedAccount = xmppConnectionService.findAccountByJid(selectedAccountJid);
+ }
+ refreshUiReal();
+ if (this.mPostponedActivityResult != null) {
+ this.onActivityResult(mPostponedActivityResult.first, RESULT_OK, mPostponedActivityResult.second);
+ }
+ if (Config.X509_VERIFICATION && this.accountList.size() == 0) {
+ if (mInvokedAddAccount.compareAndSet(false, true)) {
+ addAccountFromKey();
+ }
+ }
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.manageaccounts, menu);
MenuItem enableAll = menu.findItem(R.id.action_enable_all);
+ MenuItem addAccount = menu.findItem(R.id.action_add_account);
+ MenuItem addAccountWithCertificate = menu.findItem(R.id.action_add_account_with_cert);
+
+ if (Config.X509_VERIFICATION) {
+ addAccount.setVisible(false);
+ addAccountWithCertificate.setShowAsAction(MenuItem.SHOW_AS_ACTION_ALWAYS);
+ } else {
+ addAccount.setVisible(!Config.SINGLE_ACCOUNT);
+ }
+ addAccountWithCertificate.setVisible(!Config.SINGLE_ACCOUNT);
+
if (!accountsLeftToEnable()) {
enableAll.setVisible(false);
}
@@ -108,23 +172,23 @@ public class ManageAccountActivity extends XmppActivity implements OnAccountUpda
@Override
public boolean onContextItemSelected(MenuItem item) {
switch (item.getItemId()) {
- case R.id.mgmt_account_publish_avatar:
- publishAvatar(selectedAccount);
- return true;
- case R.id.mgmt_account_disable:
- disableAccount(selectedAccount);
- return true;
- case R.id.mgmt_account_enable:
- enableAccount(selectedAccount);
- return true;
- case R.id.mgmt_account_delete:
- deleteAccount(selectedAccount);
- return true;
- case R.id.mgmt_account_announce_pgp:
- publishOpenPGPPublicKey(selectedAccount);
- return true;
- default:
- return super.onContextItemSelected(item);
+ case R.id.mgmt_account_publish_avatar:
+ publishAvatar(selectedAccount);
+ return true;
+ case R.id.mgmt_account_disable:
+ disableAccount(selectedAccount);
+ return true;
+ case R.id.mgmt_account_enable:
+ enableAccount(selectedAccount);
+ return true;
+ case R.id.mgmt_account_delete:
+ deleteAccount(selectedAccount);
+ return true;
+ case R.id.mgmt_account_announce_pgp:
+ publishOpenPGPPublicKey(selectedAccount);
+ return true;
+ default:
+ return super.onContextItemSelected(item);
}
}
@@ -141,6 +205,9 @@ public class ManageAccountActivity extends XmppActivity implements OnAccountUpda
case R.id.action_enable_all:
enableAllAccounts();
break;
+ case R.id.action_add_account_with_cert:
+ addAccountFromKey();
+ break;
default:
break;
}
@@ -153,9 +220,9 @@ public class ManageAccountActivity extends XmppActivity implements OnAccountUpda
Intent contactsIntent = new Intent(this,
StartConversationActivity.class);
contactsIntent.setFlags(
- // if activity exists in stack, pop the stack and go back to it
+ // if activity exists in stack, pop the stack and go back to it
Intent.FLAG_ACTIVITY_CLEAR_TOP |
- // otherwise, make a new task for it
+ // otherwise, make a new task for it
Intent.FLAG_ACTIVITY_NEW_TASK |
// don't use the new activity animation; finish
// animation runs instead
@@ -176,10 +243,18 @@ public class ManageAccountActivity extends XmppActivity implements OnAccountUpda
}
}
+ private void addAccountFromKey() {
+ try {
+ KeyChain.choosePrivateKeyAlias(this, this, null, null, null, -1, null);
+ } catch (ActivityNotFoundException e) {
+ Toast.makeText(this, R.string.device_does_not_support_certificates, Toast.LENGTH_LONG).show();
+ }
+ }
+
private void publishAvatar(Account account) {
Intent intent = new Intent(getApplicationContext(),
PublishProfilePictureActivity.class);
- intent.putExtra("account", account.getJid().toString());
+ intent.putExtra(EXTRA_ACCOUNT, account.getJid().toString());
startActivity(intent);
}
@@ -192,7 +267,7 @@ public class ManageAccountActivity extends XmppActivity implements OnAccountUpda
}
}
}
- for(Account account : list) {
+ for (Account account : list) {
disableAccount(account);
}
}
@@ -228,7 +303,7 @@ public class ManageAccountActivity extends XmppActivity implements OnAccountUpda
}
}
}
- for(Account account : list) {
+ for (Account account : list) {
enableAccount(account);
}
}
@@ -245,7 +320,7 @@ public class ManageAccountActivity extends XmppActivity implements OnAccountUpda
private void publishOpenPGPPublicKey(Account account) {
if (ManageAccountActivity.this.hasPgp()) {
- announcePgp(account, null);
+ choosePgpSignId(selectedAccount);
} else {
this.showInstallPgpDialog();
}
@@ -273,9 +348,43 @@ public class ManageAccountActivity extends XmppActivity implements OnAccountUpda
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if (resultCode == RESULT_OK) {
- if (requestCode == REQUEST_ANNOUNCE_PGP) {
- announcePgp(selectedAccount, null);
+ if (xmppConnectionServiceBound) {
+ if (requestCode == REQUEST_CHOOSE_PGP_ID) {
+ if (data.getExtras().containsKey(OpenPgpApi.EXTRA_SIGN_KEY_ID)) {
+ selectedAccount.setPgpSignId(data.getExtras().getLong(OpenPgpApi.EXTRA_SIGN_KEY_ID));
+ announcePgp(selectedAccount, null);
+ } else {
+ choosePgpSignId(selectedAccount);
+ }
+ } else if (requestCode == REQUEST_ANNOUNCE_PGP) {
+ announcePgp(selectedAccount, null);
+ }
+ this.mPostponedActivityResult = null;
+ } else {
+ this.mPostponedActivityResult = new Pair<>(requestCode, data);
}
}
}
+
+ @Override
+ public void alias(String alias) {
+ if (alias != null) {
+ xmppConnectionService.createAccountFromKey(alias, this);
+ }
+ }
+
+ @Override
+ public void onAccountCreated(Account account) {
+ switchToAccount(account, true);
+ }
+
+ @Override
+ public void informUser(final int r) {
+ runOnUiThread(new Runnable() {
+ @Override
+ public void run() {
+ Toast.makeText(ManageAccountActivity.this, r, Toast.LENGTH_LONG).show();
+ }
+ });
+ }
}
diff --git a/src/main/java/de/thedevstack/conversationsplus/ui/PublishProfilePictureActivity.java b/src/main/java/de/thedevstack/conversationsplus/ui/PublishProfilePictureActivity.java
index 2045f001..9b827861 100644
--- a/src/main/java/de/thedevstack/conversationsplus/ui/PublishProfilePictureActivity.java
+++ b/src/main/java/de/thedevstack/conversationsplus/ui/PublishProfilePictureActivity.java
@@ -2,7 +2,9 @@ package de.thedevstack.conversationsplus.ui;
import android.app.PendingIntent;
import android.content.Intent;
+import android.content.pm.PackageManager;
import android.graphics.Bitmap;
+import android.graphics.BitmapFactory;
import android.net.Uri;
import android.os.Bundle;
import android.view.View;
@@ -13,28 +15,34 @@ import android.widget.ImageView;
import android.widget.TextView;
import android.widget.Toast;
+import com.soundcloud.android.crop.Crop;
+
+import java.io.File;
+import java.io.FileNotFoundException;
+
+import de.thedevstack.conversationsplus.utils.ImageUtil;
+import de.thedevstack.conversationsplus.Config;
import de.thedevstack.conversationsplus.R;
import de.thedevstack.conversationsplus.entities.Account;
import de.thedevstack.conversationsplus.services.AvatarService;
-import de.thedevstack.conversationsplus.utils.ImageUtil;
+import de.thedevstack.conversationsplus.utils.ExifHelper;
+import de.thedevstack.conversationsplus.utils.FileUtils;
import de.thedevstack.conversationsplus.utils.PhoneHelper;
-import de.thedevstack.conversationsplus.xmpp.jid.InvalidJidException;
-import de.thedevstack.conversationsplus.xmpp.jid.Jid;
import de.thedevstack.conversationsplus.xmpp.pep.Avatar;
public class PublishProfilePictureActivity extends XmppActivity {
private static final int REQUEST_CHOOSE_FILE = 0xac23;
-
private ImageView avatar;
private TextView accountTextView;
private TextView hintOrWarning;
private TextView secondaryHint;
private Button cancelButton;
private Button publishButton;
-
private Uri avatarUri;
private Uri defaultUri;
+ private Account account;
+ private boolean support = false;
private OnLongClickListener backToDefaultListener = new OnLongClickListener() {
@Override
@@ -44,8 +52,6 @@ public class PublishProfilePictureActivity extends XmppActivity {
return true;
}
};
- private Account account;
- private boolean support = false;
private boolean mInitialAccountSetup;
private UiCallback<Avatar> avatarPublication = new UiCallback<Avatar>() {
@@ -58,7 +64,7 @@ public class PublishProfilePictureActivity extends XmppActivity {
if (mInitialAccountSetup) {
Intent intent = new Intent(getApplicationContext(),
StartConversationActivity.class);
- intent.putExtra("init",true);
+ intent.putExtra("init", true);
startActivity(intent);
}
Toast.makeText(PublishProfilePictureActivity.this,
@@ -130,26 +136,60 @@ public class PublishProfilePictureActivity extends XmppActivity {
@Override
public void onClick(View v) {
- Intent attachFileIntent = new Intent();
- attachFileIntent.setType("image/*");
- attachFileIntent.setAction(Intent.ACTION_GET_CONTENT);
- Intent chooser = Intent.createChooser(attachFileIntent,
- getString(R.string.attach_file));
- startActivityForResult(chooser, REQUEST_CHOOSE_FILE);
+ if (hasStoragePermission(REQUEST_CHOOSE_FILE)) {
+ chooseAvatar();
+ }
+
}
});
this.defaultUri = PhoneHelper.getSefliUri(getApplicationContext());
}
+ private void chooseAvatar() {
+ Intent attachFileIntent = new Intent();
+ attachFileIntent.setType("image/*");
+ attachFileIntent.setAction(Intent.ACTION_GET_CONTENT);
+ Intent chooser = Intent.createChooser(attachFileIntent, getString(R.string.attach_file));
+ startActivityForResult(chooser, REQUEST_CHOOSE_FILE);
+ }
+
+ @Override
+ public void onRequestPermissionsResult(int requestCode, String permissions[], int[] grantResults) {
+ if (grantResults.length > 0)
+ if (grantResults[0] == PackageManager.PERMISSION_GRANTED) {
+ if (requestCode == REQUEST_CHOOSE_FILE) {
+ chooseAvatar();
+ }
+ } else {
+ Toast.makeText(this, R.string.no_storage_permission, Toast.LENGTH_SHORT).show();
+ }
+ }
+
@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);
if (resultCode == RESULT_OK) {
- if (requestCode == REQUEST_CHOOSE_FILE) {
- this.avatarUri = data.getData();
- if (xmppConnectionServiceBound) {
+ switch (requestCode) {
+ case REQUEST_CHOOSE_FILE:
+ Uri source = data.getData();
+ String original = FileUtils.getPath(this, source);
+ if (original != null) {
+ source = Uri.parse("file://"+original);
+ }
+ Uri destination = Uri.fromFile(new File(getCacheDir(), "croppedAvatar"));
+ final int size = getPixel(192);
+ Crop.of(source, destination).asSquare().withMaxSize(size, size).start(this);
+ break;
+ case Crop.REQUEST_CROP:
+ this.avatarUri = Uri.fromFile(new File(getCacheDir(), "croppedAvatar"));
loadImageIntoPreview(this.avatarUri);
+ break;
+ }
+ } else {
+ if (requestCode == Crop.REQUEST_CROP && data != null) {
+ Throwable throwable = Crop.getError(data);
+ if (throwable != null && throwable instanceof OutOfMemoryError) {
+ Toast.makeText(this,R.string.selection_too_large, Toast.LENGTH_SHORT).show();
}
}
}
@@ -157,63 +197,75 @@ public class PublishProfilePictureActivity extends XmppActivity {
@Override
protected void onBackendConnected() {
- if (getIntent() != null) {
- Jid jid;
- try {
- jid = Jid.fromString(getIntent().getStringExtra("account"));
- } catch (InvalidJidException e) {
- jid = null;
- }
- if (jid != null) {
- this.account = xmppConnectionService.findAccountByJid(jid);
- if (this.account.getXmppConnection() != null) {
- this.support = this.account.getXmppConnection().getFeatures().pep();
- }
- if (this.avatarUri == null) {
- if (this.account.getAvatar() != null
- || this.defaultUri == null) {
- this.avatar.setImageBitmap(AvatarService.getInstance().get(account,
- getPixel(194)));
- if (this.defaultUri != null) {
- this.avatar
- .setOnLongClickListener(this.backToDefaultListener);
- } else {
- this.secondaryHint.setVisibility(View.INVISIBLE);
- }
- if (!support) {
- this.hintOrWarning
- .setTextColor(getWarningTextColor());
- this.hintOrWarning
- .setText(R.string.error_publish_avatar_no_server_support);
- }
+ this.account = extractAccount(getIntent());
+ if (this.account != null) {
+ if (this.account.getXmppConnection() != null) {
+ this.support = this.account.getXmppConnection().getFeatures().pep();
+ }
+ if (this.avatarUri == null) {
+ if (this.account.getAvatar() != null
+ || this.defaultUri == null) {
+ this.avatar.setImageBitmap(AvatarService.getInstance().get(account, getPixel(192)));
+ if (this.defaultUri != null) {
+ this.avatar
+ .setOnLongClickListener(this.backToDefaultListener);
} else {
- this.avatarUri = this.defaultUri;
- loadImageIntoPreview(this.defaultUri);
this.secondaryHint.setVisibility(View.INVISIBLE);
}
+ if (!support) {
+ this.hintOrWarning
+ .setTextColor(getWarningTextColor());
+ this.hintOrWarning
+ .setText(R.string.error_publish_avatar_no_server_support);
+ }
} else {
- loadImageIntoPreview(avatarUri);
+ this.avatarUri = this.defaultUri;
+ loadImageIntoPreview(this.defaultUri);
+ this.secondaryHint.setVisibility(View.INVISIBLE);
}
- this.accountTextView.setText(this.account.getJid().toBareJid().toString());
+ } else {
+ loadImageIntoPreview(avatarUri);
+ }
+ String account;
+ if (Config.DOMAIN_LOCK != null) {
+ account = this.account.getJid().getLocalpart();
+ } else {
+ account = this.account.getJid().toBareJid().toString();
}
+ this.accountTextView.setText(account);
}
-
}
@Override
protected void onStart() {
super.onStart();
if (getIntent() != null) {
- this.mInitialAccountSetup = getIntent().getBooleanExtra("setup",
- false);
+ this.mInitialAccountSetup = getIntent().getBooleanExtra("setup", false);
}
if (this.mInitialAccountSetup) {
this.cancelButton.setText(R.string.skip);
}
}
+ private Bitmap loadScaledBitmap(Uri uri, int reqSize) throws FileNotFoundException {
+ final BitmapFactory.Options options = new BitmapFactory.Options();
+ options.inJustDecodeBounds = true;
+ BitmapFactory.decodeStream(getContentResolver().openInputStream(uri), null, options);
+ int rotation = ExifHelper.getOrientation(getContentResolver().openInputStream(uri));
+ options.inSampleSize = ImageUtil.calcSampleSize(options, reqSize);
+ options.inJustDecodeBounds = false;
+ Bitmap bm = BitmapFactory.decodeStream(getContentResolver().openInputStream(uri), null, options);
+ return ImageUtil.rotate(bm,rotation);
+ }
+
protected void loadImageIntoPreview(Uri uri) {
- Bitmap bm = ImageUtil.cropCenterSquare(uri, 384);
+ Bitmap bm = null;
+ try {
+ bm = loadScaledBitmap(uri, getPixel(192));
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+
if (bm == null) {
disablePublishButton();
this.hintOrWarning.setTextColor(getWarningTextColor());
@@ -252,4 +304,7 @@ public class PublishProfilePictureActivity extends XmppActivity {
this.publishButton.setTextColor(getSecondaryTextColor());
}
+ public void refreshUiReal() {
+ //nothing to do. This Activity doesn't implement any listeners
+ }
}
diff --git a/src/main/java/de/thedevstack/conversationsplus/ui/SettingsActivity.java b/src/main/java/de/thedevstack/conversationsplus/ui/SettingsActivity.java
index c364ff00..e8c9587b 100644
--- a/src/main/java/de/thedevstack/conversationsplus/ui/SettingsActivity.java
+++ b/src/main/java/de/thedevstack/conversationsplus/ui/SettingsActivity.java
@@ -1,20 +1,5 @@
package de.thedevstack.conversationsplus.ui;
-import java.security.KeyStoreException;
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.Collections;
-import java.util.Locale;
-
-import de.thedevstack.conversationsplus.ConversationsPlusPreferences;
-import de.tzur.conversations.Settings;
-import de.duenndns.ssl.MemorizingTrustManager;
-
-import de.thedevstack.conversationsplus.R;
-import de.thedevstack.conversationsplus.entities.Account;
-import de.thedevstack.conversationsplus.xmpp.XmppConnection;
-import github.ankushsachdeva.emojicon.EmojiconHandler;
-
import android.app.AlertDialog;
import android.app.FragmentManager;
import android.content.DialogInterface;
@@ -24,9 +9,23 @@ import android.os.Build;
import android.os.Bundle;
import android.preference.ListPreference;
import android.preference.Preference;
+import android.preference.PreferenceCategory;
import android.preference.PreferenceManager;
import android.widget.Toast;
+import java.security.KeyStoreException;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.Locale;
+
+import de.duenndns.ssl.MemorizingTrustManager;
+import de.tzur.conversations.Settings;
+import de.thedevstack.conversationsplus.R;
+import de.thedevstack.conversationsplus.entities.Account;
+import de.thedevstack.conversationsplus.xmpp.XmppConnection;
+import github.ankushsachdeva.emojicon.EmojiconHandler;
+
public class SettingsActivity extends XmppActivity implements
OnSharedPreferenceChangeListener {
private SettingsFragment mSettingsFragment;
@@ -63,65 +62,71 @@ public class SettingsActivity extends XmppActivity implements
final Preference removeCertsPreference = mSettingsFragment.findPreference("remove_trusted_certificates");
removeCertsPreference.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() {
- @Override
- public boolean onPreferenceClick(Preference preference) {
- final MemorizingTrustManager mtm = xmppConnectionService.getMemorizingTrustManager();
- final ArrayList<String> aliases = Collections.list(mtm.getCertificates());
- if (aliases.size() == 0) {
- displayToast(getString(R.string.toast_no_trusted_certs));
- return true;
- }
- final ArrayList selectedItems = new ArrayList<Integer>();
- final AlertDialog.Builder dialogBuilder = new AlertDialog.Builder(SettingsActivity.this);
- dialogBuilder.setTitle(getResources().getString(R.string.dialog_manage_certs_title));
- dialogBuilder.setMultiChoiceItems(aliases.toArray(new CharSequence[aliases.size()]), null,
- new DialogInterface.OnMultiChoiceClickListener() {
- @Override
- public void onClick(DialogInterface dialog, int indexSelected,
- boolean isChecked) {
- if (isChecked) {
- selectedItems.add(indexSelected);
- } else if (selectedItems.contains(indexSelected)) {
- selectedItems.remove(Integer.valueOf(indexSelected));
- }
- if (selectedItems.size() > 0)
- ((AlertDialog) dialog).getButton(DialogInterface.BUTTON_POSITIVE).setEnabled(true);
- else {
- ((AlertDialog) dialog).getButton(DialogInterface.BUTTON_POSITIVE).setEnabled(false);
- }
- }
- });
-
- dialogBuilder.setPositiveButton(
- getResources().getString(R.string.dialog_manage_certs_positivebutton), new DialogInterface.OnClickListener() {
- @Override
- public void onClick(DialogInterface dialog, int which) {
- int count = selectedItems.size();
- if (count > 0) {
- for (int i = 0; i < count; i++) {
- try {
- Integer item = Integer.valueOf(selectedItems.get(i).toString());
- String alias = aliases.get(item);
- mtm.deleteCertificate(alias);
- } catch (KeyStoreException e) {
- e.printStackTrace();
- displayToast("Error: " + e.getLocalizedMessage());
- }
- }
- if (xmppConnectionServiceBound) {
- reconnectAccounts();
- }
- displayToast(getResources().getQuantityString(R.plurals.toast_delete_certificates, count, count));
- }
- }
- });
- dialogBuilder.setNegativeButton(getResources().getString(R.string.dialog_manage_certs_negativebutton), null);
- AlertDialog removeCertsDialog = dialogBuilder.create();
- removeCertsDialog.show();
- removeCertsDialog.getButton(AlertDialog.BUTTON_POSITIVE).setEnabled(false);
- return true;
- }
- });
+ @Override
+ public boolean onPreferenceClick(Preference preference) {
+ final MemorizingTrustManager mtm = xmppConnectionService.getMemorizingTrustManager();
+ final ArrayList<String> aliases = Collections.list(mtm.getCertificates());
+ if (aliases.size() == 0) {
+ displayToast(getString(R.string.toast_no_trusted_certs));
+ return true;
+ }
+ final ArrayList selectedItems = new ArrayList<Integer>();
+ final AlertDialog.Builder dialogBuilder = new AlertDialog.Builder(SettingsActivity.this);
+ dialogBuilder.setTitle(getResources().getString(R.string.dialog_manage_certs_title));
+ dialogBuilder.setMultiChoiceItems(aliases.toArray(new CharSequence[aliases.size()]), null,
+ new DialogInterface.OnMultiChoiceClickListener() {
+ @Override
+ public void onClick(DialogInterface dialog, int indexSelected,
+ boolean isChecked) {
+ if (isChecked) {
+ selectedItems.add(indexSelected);
+ } else if (selectedItems.contains(indexSelected)) {
+ selectedItems.remove(Integer.valueOf(indexSelected));
+ }
+ if (selectedItems.size() > 0)
+ ((AlertDialog) dialog).getButton(DialogInterface.BUTTON_POSITIVE).setEnabled(true);
+ else {
+ ((AlertDialog) dialog).getButton(DialogInterface.BUTTON_POSITIVE).setEnabled(false);
+ }
+ }
+ });
+
+ dialogBuilder.setPositiveButton(
+ getResources().getString(R.string.dialog_manage_certs_positivebutton), new DialogInterface.OnClickListener() {
+ @Override
+ public void onClick(DialogInterface dialog, int which) {
+ int count = selectedItems.size();
+ if (count > 0) {
+ for (int i = 0; i < count; i++) {
+ try {
+ Integer item = Integer.valueOf(selectedItems.get(i).toString());
+ String alias = aliases.get(item);
+ mtm.deleteCertificate(alias);
+ } catch (KeyStoreException e) {
+ e.printStackTrace();
+ displayToast("Error: " + e.getLocalizedMessage());
+ }
+ }
+ if (xmppConnectionServiceBound) {
+ reconnectAccounts();
+ }
+ displayToast(getResources().getQuantityString(R.plurals.toast_delete_certificates, count, count));
+ }
+ }
+ });
+ dialogBuilder.setNegativeButton(getResources().getString(R.string.dialog_manage_certs_negativebutton), null);
+ AlertDialog removeCertsDialog = dialogBuilder.create();
+ removeCertsDialog.show();
+ removeCertsDialog.getButton(AlertDialog.BUTTON_POSITIVE).setEnabled(false);
+ return true;
+ }
+ });
+ // Avoid appearence of setting to enable or disable omemo in screen
+ Preference omemoEnabledPreference = this.mSettingsFragment.findPreference("omemo_enabled");
+ PreferenceCategory otherExpertSettingsGroup = (PreferenceCategory) this.mSettingsFragment.findPreference("other_expert_settings");
+ if (null != omemoEnabledPreference && null != otherExpertSettingsGroup) {
+ otherExpertSettingsGroup.removePreference(omemoEnabledPreference);
+ }
}
@Override
@@ -136,42 +141,40 @@ public class SettingsActivity extends XmppActivity implements
String name) {
// need to synchronize the settings class first
Settings.synchronizeSettingsClassWithPreferences(preferences, name);
- switch (name) {
- case "resource":
- String resource = ConversationsPlusPreferences.resource().toLowerCase(Locale.US);
- if (xmppConnectionServiceBound) {
- for (Account account : xmppConnectionService.getAccounts()) {
- account.setResource(resource);
- if (!account.isOptionSet(Account.OPTION_DISABLED)) {
+ if (name.equals("resource")) {
+ String resource = preferences.getString("resource", "mobile")
+ .toLowerCase(Locale.US);
+ if (xmppConnectionServiceBound) {
+ for (Account account : xmppConnectionService.getAccounts()) {
+ if (account.setResource(resource)) {
+ if (!account.isOptionSet(Account.OPTION_DISABLED)) {
XmppConnection connection = account.getXmppConnection();
if (connection != null) {
connection.resetStreamId();
}
- xmppConnectionService.reconnectAccountInBackground(account);
- }
- }
- }
- break;
- 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);
+ xmppConnectionService.reconnectAccountInBackground(account);
}
}
}
- break;
- case "dont_trust_system_cas":
- xmppConnectionService.updateMemorizingTrustmanager();
- reconnectAccounts();
- break;
- case "parse_emoticons":
- EmojiconHandler.setParseEmoticons(Settings.PARSE_EMOTICONS);
- break;
- }
+ }
+ } else if (name.equals("keep_foreground_service")) {
+ xmppConnectionService.toggleForegroundService();
+ } else if (name.equals("confirm_messages_list")
+ || name.equals("xa_on_silent_mode")
+ || name.equals("away_when_screen_off")) {
+ if (xmppConnectionServiceBound) {
+ if (name.equals("away_when_screen_off")) {
+ xmppConnectionService.toggleScreenEventReceiver();
+ }
+ xmppConnectionService.refreshAllPresences();
+ }
+ } else if (name.equals("dont_trust_system_cas")) {
+ xmppConnectionService.updateMemorizingTrustmanager();
+ reconnectAccounts();
+ } else if ("parse_emoticons".equals(name)) {
+ EmojiconHandler.setParseEmoticons(Settings.PARSE_EMOTICONS);
+ }
+
}
private void displayToast(final String msg) {
@@ -191,4 +194,8 @@ public class SettingsActivity extends XmppActivity implements
}
}
+ public void refreshUiReal() {
+ //nothing to do. This Activity doesn't implement any listeners
+ }
+
}
diff --git a/src/main/java/de/thedevstack/conversationsplus/ui/ShareWithActivity.java b/src/main/java/de/thedevstack/conversationsplus/ui/ShareWithActivity.java
index e73b7cbe..b0ee32f1 100644
--- a/src/main/java/de/thedevstack/conversationsplus/ui/ShareWithActivity.java
+++ b/src/main/java/de/thedevstack/conversationsplus/ui/ShareWithActivity.java
@@ -4,6 +4,7 @@ import android.app.PendingIntent;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
+import android.util.Log;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
@@ -17,25 +18,27 @@ import java.util.ArrayList;
import java.util.List;
import de.thedevstack.conversationsplus.ConversationsPlusPreferences;
+import de.thedevstack.conversationsplus.ui.dialogs.UserDecisionDialog;
+import de.thedevstack.conversationsplus.ui.listeners.ResizePictureUserDecisionListener;
+import de.thedevstack.conversationsplus.ui.listeners.ShareWithResizePictureUserDecisionListener;
+import de.thedevstack.conversationsplus.Config;
import de.thedevstack.conversationsplus.R;
import de.thedevstack.conversationsplus.entities.Account;
import de.thedevstack.conversationsplus.entities.Conversation;
import de.thedevstack.conversationsplus.entities.Message;
import de.thedevstack.conversationsplus.ui.adapter.ConversationAdapter;
-import de.thedevstack.conversationsplus.ui.dialogs.UserDecisionDialog;
-import de.thedevstack.conversationsplus.ui.listeners.ResizePictureUserDecisionListener;
-import de.thedevstack.conversationsplus.ui.listeners.ShareWithResizePictureUserDecisionListener;
import de.thedevstack.conversationsplus.xmpp.jid.InvalidJidException;
import de.thedevstack.conversationsplus.xmpp.jid.Jid;
public class ShareWithActivity extends XmppActivity {
- public class Share {
+ private class Share {
public List<Uri> uris = new ArrayList<>();
public boolean image;
public String account;
public String contact;
public String text;
+ public String uuid;
}
private Share share;
@@ -43,6 +46,7 @@ public class ShareWithActivity extends XmppActivity {
private static final int REQUEST_START_NEW_CONVERSATION = 0x0501;
private ListView mListView;
private List<Conversation> mConversations = new ArrayList<>();
+ private Toast mToast;
private UiCallback<Message> attachFileCallback = new UiCallback<Message>() {
@@ -53,8 +57,22 @@ public class ShareWithActivity extends XmppActivity {
}
@Override
- public void success(Message message) {
+ public void success(final Message message) {
xmppConnectionService.sendMessage(message);
+ runOnUiThread(new Runnable() {
+ @Override
+ public void run() {
+ if (mToast != null) {
+ mToast.cancel();
+ }
+ if (share.uuid != null) {
+ mToast = Toast.makeText(getApplicationContext(),
+ getString(share.image ? R.string.shared_image_with_x : R.string.shared_file_with_x,message.getConversation().getName()),
+ Toast.LENGTH_SHORT);
+ mToast.show();
+ }
+ }
+ });
}
@Override
@@ -69,7 +87,7 @@ public class ShareWithActivity extends XmppActivity {
if (requestCode == REQUEST_START_NEW_CONVERSATION
&& resultCode == RESULT_OK) {
share.contact = data.getStringExtra("contact");
- share.account = data.getStringExtra("account");
+ share.account = data.getStringExtra(EXTRA_ACCOUNT);
}
if (xmppConnectionServiceBound
&& share != null
@@ -131,9 +149,12 @@ public class ShareWithActivity extends XmppActivity {
return;
}
final String type = intent.getType();
+ Log.d(Config.LOGTAG, "action: "+intent.getAction()+ ", type:"+type);
+ share.uuid = intent.getStringExtra("uuid");
if (Intent.ACTION_SEND.equals(intent.getAction())) {
final Uri uri = getIntent().getParcelableExtra(Intent.EXTRA_STREAM);
if (type != null && uri != null && !type.equalsIgnoreCase("text/plain")) {
+ this.share.uris.clear();
this.share.uris.add(uri);
this.share.image = type.startsWith("image/") || isImage(uri);
} else {
@@ -148,7 +169,11 @@ public class ShareWithActivity extends XmppActivity {
this.share.uris = intent.getParcelableArrayListExtra(Intent.EXTRA_STREAM);
}
if (xmppConnectionServiceBound) {
- xmppConnectionService.populateWithOrderedConversations(mConversations, this.share.uris.size() == 0);
+ if (share.uuid != null) {
+ share();
+ } else {
+ xmppConnectionService.populateWithOrderedConversations(mConversations, this.share.uris.size() == 0);
+ }
}
}
@@ -165,7 +190,7 @@ public class ShareWithActivity extends XmppActivity {
@Override
void onBackendConnected() {
if (xmppConnectionServiceBound && share != null
- && share.contact != null && share.account != null) {
+ && ((share.contact != null && share.account != null) || share.uuid != null)) {
share();
return;
}
@@ -174,26 +199,43 @@ public class ShareWithActivity extends XmppActivity {
}
private void share() {
- Account account;
- try {
- account = xmppConnectionService.findAccountByJid(Jid.fromString(share.account));
- } catch (final InvalidJidException e) {
- account = null;
- }
- if (account == null) {
- return;
- }
final Conversation conversation;
- try {
- conversation = xmppConnectionService
- .findOrCreateConversation(account, Jid.fromString(share.contact), false);
- } catch (final InvalidJidException e) {
- return;
+ if (share.uuid != null) {
+ conversation = xmppConnectionService.findConversationByUuid(share.uuid);
+ if (conversation == null) {
+ return;
+ }
+ }else{
+ Account account;
+ try {
+ account = xmppConnectionService.findAccountByJid(Jid.fromString(share.account));
+ } catch (final InvalidJidException e) {
+ account = null;
+ }
+ if (account == null) {
+ return;
+ }
+
+ try {
+ conversation = xmppConnectionService
+ .findOrCreateConversation(account, Jid.fromString(share.contact), false);
+ } catch (final InvalidJidException e) {
+ return;
+ }
}
share(conversation);
}
private void share(final Conversation conversation) {
+ if (conversation.getNextEncryption() == Message.ENCRYPTION_PGP && !hasPgp()) {
+ if (share.uuid == null) {
+ showInstallPgpDialog();
+ } else {
+ Toast.makeText(this,R.string.openkeychain_not_installed,Toast.LENGTH_SHORT).show();
+ finish();
+ }
+ return;
+ }
if (share.uris.size() != 0) {
OnPresenceSelected callback;
if (this.share.image) {
@@ -209,22 +251,25 @@ public class ShareWithActivity extends XmppActivity {
callback = new OnPresenceSelected() {
@Override
public void onPresenceSelected() {
- Toast.makeText(getApplicationContext(),
+ mToast = Toast.makeText(getApplicationContext(),
getText(R.string.preparing_file),
- Toast.LENGTH_LONG).show();
+ Toast.LENGTH_LONG);
+ mToast.show();
ShareWithActivity.this.xmppConnectionService
.attachFileToConversation(conversation, share.uris.get(0),
attachFileCallback);
- switchToConversation(conversation, null, true);
+ if (share.uuid == null) {
+ switchToConversation(conversation, null, true);
+ }
finish();
}
};
}
if (conversation.getAccount().httpUploadAvailable()) {
- callback.onPresenceSelected();
+ callback.onPresenceSelected();
} else {
- selectPresence(conversation, callback);
+ selectPresence(conversation, callback);
}
} else {
switchToConversation(conversation, this.share.text, true);
@@ -233,4 +278,8 @@ public class ShareWithActivity extends XmppActivity {
}
+ public void refreshUiReal() {
+ //nothing to do. This Activity doesn't implement any listeners
+ }
+
}
diff --git a/src/main/java/de/thedevstack/conversationsplus/ui/StartConversationActivity.java b/src/main/java/de/thedevstack/conversationsplus/ui/StartConversationActivity.java
index 8ad23e6e..f8c624be 100644
--- a/src/main/java/de/thedevstack/conversationsplus/ui/StartConversationActivity.java
+++ b/src/main/java/de/thedevstack/conversationsplus/ui/StartConversationActivity.java
@@ -1,5 +1,6 @@
package de.thedevstack.conversationsplus.ui;
+import android.Manifest;
import android.annotation.SuppressLint;
import android.annotation.TargetApi;
import android.app.ActionBar;
@@ -13,6 +14,7 @@ import android.content.Context;
import android.content.DialogInterface;
import android.content.DialogInterface.OnClickListener;
import android.content.Intent;
+import android.content.pm.PackageManager;
import android.net.Uri;
import android.nfc.NdefMessage;
import android.nfc.NdefRecord;
@@ -41,6 +43,7 @@ import android.widget.Checkable;
import android.widget.EditText;
import android.widget.ListView;
import android.widget.Spinner;
+import android.widget.TextView;
import android.widget.Toast;
import com.google.zxing.integration.android.IntentIntegrator;
@@ -50,10 +53,11 @@ import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
+import java.util.concurrent.atomic.AtomicBoolean;
import de.thedevstack.android.logcat.Logging;
-import de.thedevstack.conversationsplus.Config;
import de.thedevstack.conversationsplus.ConversationsPlusPreferences;
+import de.thedevstack.conversationsplus.Config;
import de.thedevstack.conversationsplus.R;
import de.thedevstack.conversationsplus.entities.Account;
import de.thedevstack.conversationsplus.entities.Blockable;
@@ -61,13 +65,13 @@ import de.thedevstack.conversationsplus.entities.Bookmark;
import de.thedevstack.conversationsplus.entities.Contact;
import de.thedevstack.conversationsplus.entities.Conversation;
import de.thedevstack.conversationsplus.entities.ListItem;
-import de.thedevstack.conversationsplus.entities.Presences;
+import de.thedevstack.conversationsplus.entities.Presence;
import de.thedevstack.conversationsplus.services.XmppConnectionService.OnRosterUpdate;
import de.thedevstack.conversationsplus.ui.adapter.KnownHostsAdapter;
import de.thedevstack.conversationsplus.ui.adapter.ListItemAdapter;
import de.thedevstack.conversationsplus.utils.XmppUri;
-import de.thedevstack.conversationsplus.xmpp.XmppConnection;
import de.thedevstack.conversationsplus.xmpp.OnUpdateBlocklist;
+import de.thedevstack.conversationsplus.xmpp.XmppConnection;
import de.thedevstack.conversationsplus.xmpp.jid.InvalidJidException;
import de.thedevstack.conversationsplus.xmpp.jid.Jid;
@@ -90,6 +94,9 @@ public class StartConversationActivity extends XmppActivity implements OnRosterU
private Invite mPendingInvite = null;
private Menu mOptionsMenu;
private EditText mSearchEditText;
+ private AtomicBoolean mRequestedContactsPermission = new AtomicBoolean(false);
+ private final int REQUEST_SYNC_CONTACTS = 0x3b28cf;
+
private MenuItem.OnActionExpandListener mOnActionExpandListener = new MenuItem.OnActionExpandListener() {
@Override
@@ -246,6 +253,12 @@ public class StartConversationActivity extends XmppActivity implements OnRosterU
}
+ @Override
+ public void onStart() {
+ super.onStart();
+ askForContactsPermissions();
+ }
+
protected void openConversationForContact(int position) {
Contact contact = (Contact) contacts.get(position);
Conversation conversation = xmppConnectionService
@@ -275,7 +288,7 @@ public class StartConversationActivity extends XmppActivity implements OnRosterU
if (!conversation.getMucOptions().online()) {
xmppConnectionService.joinMuc(conversation);
}
- if (!bookmark.autojoin()) {
+ if (!bookmark.autojoin() && getPreferences().getBoolean("autojoin", true)) {
bookmark.setAutojoin(true);
xmppConnectionService.pushBookmarks(bookmark.getAccount());
}
@@ -290,7 +303,7 @@ public class StartConversationActivity extends XmppActivity implements OnRosterU
protected void toggleContactBlock() {
final int position = contact_context_id;
- BlockContactDialog.show(this, xmppConnectionService, (Contact)contacts.get(position));
+ BlockContactDialog.show(this, xmppConnectionService, (Contact) contacts.get(position));
}
protected void deleteContact() {
@@ -300,7 +313,7 @@ public class StartConversationActivity extends XmppActivity implements OnRosterU
builder.setNegativeButton(R.string.cancel, null);
builder.setTitle(R.string.action_delete_contact);
builder.setMessage(getString(R.string.remove_contact_text,
- contact.getJid()));
+ contact.getJid()));
builder.setPositiveButton(R.string.delete, new OnClickListener() {
@Override
@@ -320,7 +333,7 @@ public class StartConversationActivity extends XmppActivity implements OnRosterU
builder.setNegativeButton(R.string.cancel, null);
builder.setTitle(R.string.delete_bookmark);
builder.setMessage(getString(R.string.remove_bookmark_text,
- bookmark.getJid()));
+ bookmark.getJid()));
builder.setPositiveButton(R.string.delete, new OnClickListener() {
@Override
@@ -338,66 +351,37 @@ public class StartConversationActivity extends XmppActivity implements OnRosterU
@SuppressLint("InflateParams")
protected void showCreateContactDialog(final String prefilledJid, final String fingerprint) {
- AlertDialog.Builder builder = new AlertDialog.Builder(this);
- builder.setTitle(R.string.create_contact);
- View dialogView = getLayoutInflater().inflate(R.layout.create_contact_dialog, null);
- final Spinner spinner = (Spinner) dialogView.findViewById(R.id.account);
- final AutoCompleteTextView jid = (AutoCompleteTextView) dialogView.findViewById(R.id.jid);
- jid.setAdapter(new KnownHostsAdapter(this,android.R.layout.simple_list_item_1, mKnownHosts));
- if (prefilledJid != null) {
- jid.append(prefilledJid);
- if (fingerprint!=null) {
- jid.setFocusable(false);
- jid.setFocusableInTouchMode(false);
- jid.setClickable(false);
- jid.setCursorVisible(false);
- }
- }
- populateAccountSpinner(spinner);
- builder.setView(dialogView);
- builder.setNegativeButton(R.string.cancel, null);
- builder.setPositiveButton(R.string.create, null);
- final AlertDialog dialog = builder.create();
- dialog.show();
- dialog.getButton(AlertDialog.BUTTON_POSITIVE).setOnClickListener(
- new View.OnClickListener() {
+ EnterJidDialog dialog = new EnterJidDialog(
+ this, mKnownHosts, mActivatedAccounts,
+ getString(R.string.create_contact), getString(R.string.create),
+ prefilledJid, null, fingerprint == null
+ );
- @Override
- public void onClick(final View v) {
- if (!xmppConnectionServiceBound) {
- return;
- }
- final Jid accountJid;
- try {
- accountJid = Jid.fromString((String) spinner.getSelectedItem());
- } catch (final InvalidJidException e) {
- return;
- }
- final Jid contactJid;
- try {
- contactJid = Jid.fromString(jid.getText().toString());
- } catch (final InvalidJidException e) {
- jid.setError(getString(R.string.invalid_jid));
- return;
- }
- final Account account = xmppConnectionService
- .findAccountByJid(accountJid);
- if (account == null) {
- dialog.dismiss();
- return;
- }
- final Contact contact = account.getRoster().getContact(contactJid);
- if (contact.showInRoster()) {
- jid.setError(getString(R.string.contact_already_exists));
- } else {
- contact.addOtrFingerprint(fingerprint);
- xmppConnectionService.createContact(contact);
- dialog.dismiss();
- switchToConversation(contact);
- }
- }
- });
+ dialog.setOnEnterJidDialogPositiveListener(new EnterJidDialog.OnEnterJidDialogPositiveListener() {
+ @Override
+ public boolean onEnterJidDialogPositive(Jid accountJid, Jid contactJid) throws EnterJidDialog.JidError {
+ if (!xmppConnectionServiceBound) {
+ return false;
+ }
+
+ final Account account = xmppConnectionService.findAccountByJid(accountJid);
+ if (account == null) {
+ return true;
+ }
+ final Contact contact = account.getRoster().getContact(contactJid);
+ if (contact.showInRoster()) {
+ throw new EnterJidDialog.JidError(getString(R.string.contact_already_exists));
+ } else {
+ contact.addOtrFingerprint(fingerprint);
+ xmppConnectionService.createContact(contact);
+ switchToConversation(contact);
+ return true;
+ }
+ }
+ });
+
+ dialog.show();
}
@SuppressLint("InflateParams")
@@ -407,11 +391,17 @@ public class StartConversationActivity extends XmppActivity implements OnRosterU
final View dialogView = getLayoutInflater().inflate(R.layout.join_conference_dialog, null);
final Spinner spinner = (Spinner) dialogView.findViewById(R.id.account);
final AutoCompleteTextView jid = (AutoCompleteTextView) dialogView.findViewById(R.id.jid);
- jid.setAdapter(new KnownHostsAdapter(this,android.R.layout.simple_list_item_1, mKnownConferenceHosts));
+ final boolean lock = Config.LOCK_DOMAINS_IN_CONVERSATIONS && Config.CONFERENCE_DOMAIN_LOCK != null;
+ final TextView jabberIdDesc = (TextView) dialogView.findViewById(R.id.jabber_id);
+ jabberIdDesc.setText(lock ? R.string.conference_name : R.string.conference_address);
+ jid.setHint(lock ? R.string.conference_name : R.string.conference_address_example);
+ if (!lock) {
+ jid.setAdapter(new KnownHostsAdapter(this, android.R.layout.simple_list_item_1, mKnownConferenceHosts));
+ }
if (prefilledJid != null) {
jid.append(prefilledJid);
}
- populateAccountSpinner(spinner);
+ populateAccountSpinner(this, mActivatedAccounts, spinner);
final Checkable bookmarkCheckBox = (CheckBox) dialogView
.findViewById(R.id.bookmark);
builder.setView(dialogView);
@@ -427,49 +417,48 @@ public class StartConversationActivity extends XmppActivity implements OnRosterU
if (!xmppConnectionServiceBound) {
return;
}
- final Jid accountJid;
- try {
- accountJid = Jid.fromString((String) spinner.getSelectedItem());
- } catch (final InvalidJidException e) {
+ final Account account = getSelectedAccount(spinner);
+ if (account == null) {
return;
}
final Jid conferenceJid;
try {
- conferenceJid = Jid.fromString(jid.getText().toString());
+ if (lock) {
+ conferenceJid = Jid.fromParts(jid.getText().toString(),Config.CONFERENCE_DOMAIN_LOCK, null);
+ } else {
+ conferenceJid = Jid.fromString(jid.getText().toString());
+ }
} catch (final InvalidJidException e) {
- jid.setError(getString(R.string.invalid_jid));
- return;
- }
- final Account account = xmppConnectionService
- .findAccountByJid(accountJid);
- if (account == null) {
- dialog.dismiss();
+ jid.setError(getString(lock ? R.string.invalid_conference_name : R.string.invalid_jid));
return;
}
+
if (bookmarkCheckBox.isChecked()) {
if (account.hasBookmarkFor(conferenceJid)) {
jid.setError(getString(R.string.bookmark_already_exists));
} else {
- final Bookmark bookmark = new Bookmark(account,conferenceJid.toBareJid());
- bookmark.setAutojoin(true);
+ final Bookmark bookmark = new Bookmark(account, conferenceJid.toBareJid());
+ bookmark.setAutojoin(getPreferences().getBoolean("autojoin", true));
+ String nick = conferenceJid.getResourcepart();
+ if (nick != null && !nick.isEmpty()) {
+ bookmark.setNick(nick);
+ }
account.getBookmarks().add(bookmark);
- xmppConnectionService
- .pushBookmarks(account);
+ xmppConnectionService.pushBookmarks(account);
final Conversation conversation = xmppConnectionService
- .findOrCreateConversation(account,
- conferenceJid, true);
+ .findOrCreateConversation(account,
+ conferenceJid, true);
conversation.setBookmark(bookmark);
if (!conversation.getMucOptions().online()) {
- xmppConnectionService
- .joinMuc(conversation);
+ xmppConnectionService.joinMuc(conversation);
}
dialog.dismiss();
switchToConversation(conversation);
}
} else {
final Conversation conversation = xmppConnectionService
- .findOrCreateConversation(account,
- conferenceJid, true);
+ .findOrCreateConversation(account,
+ conferenceJid, true);
if (!conversation.getMucOptions().online()) {
xmppConnectionService.joinMuc(conversation);
}
@@ -480,6 +469,23 @@ public class StartConversationActivity extends XmppActivity implements OnRosterU
});
}
+ private Account getSelectedAccount(Spinner spinner) {
+ if (!spinner.isEnabled()) {
+ return null;
+ }
+ Jid jid;
+ try {
+ if (Config.DOMAIN_LOCK != null) {
+ jid = Jid.fromParts((String) spinner.getSelectedItem(), Config.DOMAIN_LOCK, null);
+ } else {
+ jid = Jid.fromString((String) spinner.getSelectedItem());
+ }
+ } catch (final InvalidJidException e) {
+ return null;
+ }
+ return xmppConnectionService.findAccountByJid(jid);
+ }
+
protected void switchToConversation(Contact contact) {
Conversation conversation = xmppConnectionService
.findOrCreateConversation(contact.getAccount(),
@@ -487,11 +493,21 @@ public class StartConversationActivity extends XmppActivity implements OnRosterU
switchToConversation(conversation);
}
- private void populateAccountSpinner(Spinner spinner) {
- ArrayAdapter<String> adapter = new ArrayAdapter<>(this,
- android.R.layout.simple_spinner_item, mActivatedAccounts);
- adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
- spinner.setAdapter(adapter);
+ public static void populateAccountSpinner(Context context, List<String> accounts, Spinner spinner) {
+ if (accounts.size() > 0) {
+ ArrayAdapter<String> adapter = new ArrayAdapter<>(context,
+ android.R.layout.simple_spinner_item, accounts);
+ adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
+ spinner.setAdapter(adapter);
+ spinner.setEnabled(true);
+ } else {
+ ArrayAdapter<String> adapter = new ArrayAdapter<>(context,
+ android.R.layout.simple_spinner_item,
+ Arrays.asList(new String[]{context.getString(R.string.no_accounts)}));
+ adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
+ spinner.setAdapter(adapter);
+ spinner.setEnabled(false);
+ }
}
@Override
@@ -573,12 +589,51 @@ public class StartConversationActivity extends XmppActivity implements OnRosterU
super.onActivityResult(requestCode, requestCode, intent);
}
+ private void askForContactsPermissions() {
+ if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
+ if (checkSelfPermission(Manifest.permission.READ_CONTACTS) != PackageManager.PERMISSION_GRANTED) {
+ if (mRequestedContactsPermission.compareAndSet(false, true)) {
+ if (shouldShowRequestPermissionRationale(Manifest.permission.READ_CONTACTS)) {
+ AlertDialog.Builder builder = new AlertDialog.Builder(this);
+ builder.setTitle(R.string.sync_with_contacts);
+ builder.setMessage(R.string.sync_with_contacts_long);
+ builder.setPositiveButton(R.string.next, new OnClickListener() {
+ @Override
+ public void onClick(DialogInterface dialog, int which) {
+ if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
+ requestPermissions(new String[]{Manifest.permission.READ_CONTACTS}, REQUEST_SYNC_CONTACTS);
+ }
+ }
+ });
+ builder.create().show();
+ } else {
+ requestPermissions(new String[]{Manifest.permission.READ_CONTACTS}, 0);
+ }
+ }
+ }
+ }
+ }
+
+ @Override
+ public void onRequestPermissionsResult(int requestCode, String permissions[], int[] grantResults) {
+ if (grantResults.length > 0)
+ if (grantResults[0] == PackageManager.PERMISSION_GRANTED) {
+ if (requestCode == REQUEST_SYNC_CONTACTS && xmppConnectionServiceBound) {
+ xmppConnectionService.loadPhoneContacts();
+ }
+ }
+ }
+
@Override
protected void onBackendConnected() {
this.mActivatedAccounts.clear();
for (Account account : xmppConnectionService.getAccounts()) {
if (account.getStatus() != Account.State.DISABLED) {
- this.mActivatedAccounts.add(account.getJid().toBareJid().toString());
+ if (Config.DOMAIN_LOCK != null) {
+ this.mActivatedAccounts.add(account.getJid().getLocalpart());
+ } else {
+ this.mActivatedAccounts.add(account.getJid().toBareJid().toString());
+ }
}
}
final Intent intent = getIntent();
@@ -683,9 +738,11 @@ public class StartConversationActivity extends XmppActivity implements OnRosterU
for (Account account : xmppConnectionService.getAccounts()) {
if (account.getStatus() != Account.State.DISABLED) {
for (Contact contact : account.getRoster().getContacts()) {
+ Presence p = contact.getPresences().getMostAvailablePresence();
+ Presence.Status s = p == null ? Presence.Status.OFFLINE : p.getStatus();
if (contact.showInRoster() && contact.match(needle)
&& (!this.mHideOfflineContacts
- || contact.getPresences().getMostAvailableStatus() < Presences.OFFLINE)) {
+ || s.compareTo(Presence.Status.OFFLINE) < 0)) {
this.contacts.add(contact);
}
}
@@ -761,7 +818,7 @@ public class StartConversationActivity extends XmppActivity implements OnRosterU
final AdapterView.AdapterContextMenuInfo acmi = (AdapterContextMenuInfo) menuInfo;
if (mResContextMenu == R.menu.conference_context) {
activity.conference_context_id = acmi.position;
- } else {
+ } else if (mResContextMenu == R.menu.contact_context){
activity.contact_context_id = acmi.position;
final Blockable contact = (Contact) activity.contacts.get(acmi.position);
final MenuItem blockUnblockItem = menu.findItem(R.id.context_contact_block_unblock);
diff --git a/src/main/java/de/thedevstack/conversationsplus/ui/TrustKeysActivity.java b/src/main/java/de/thedevstack/conversationsplus/ui/TrustKeysActivity.java
new file mode 100644
index 00000000..167b207f
--- /dev/null
+++ b/src/main/java/de/thedevstack/conversationsplus/ui/TrustKeysActivity.java
@@ -0,0 +1,301 @@
+package de.thedevstack.conversationsplus.ui;
+
+import android.content.Intent;
+import android.os.Bundle;
+import android.view.View;
+import android.view.View.OnClickListener;
+import android.widget.Button;
+import android.widget.CompoundButton;
+import android.widget.LinearLayout;
+import android.widget.TextView;
+import android.widget.Toast;
+
+import org.whispersystems.libaxolotl.IdentityKey;
+
+import java.util.HashMap;
+import java.util.Map;
+import java.util.Set;
+
+import de.thedevstack.conversationsplus.R;
+import de.thedevstack.conversationsplus.crypto.axolotl.AxolotlService;
+import de.thedevstack.conversationsplus.crypto.axolotl.XmppAxolotlSession;
+import de.thedevstack.conversationsplus.entities.Account;
+import de.thedevstack.conversationsplus.entities.Contact;
+import de.thedevstack.conversationsplus.xmpp.OnKeyStatusUpdated;
+import de.thedevstack.conversationsplus.xmpp.jid.InvalidJidException;
+import de.thedevstack.conversationsplus.xmpp.jid.Jid;
+
+public class TrustKeysActivity extends XmppActivity implements OnKeyStatusUpdated {
+ private Jid accountJid;
+ private Jid contactJid;
+
+ private Contact contact;
+ private Account mAccount;
+ private TextView keyErrorMessage;
+ private LinearLayout keyErrorMessageCard;
+ private TextView ownKeysTitle;
+ private LinearLayout ownKeys;
+ private LinearLayout ownKeysCard;
+ private TextView foreignKeysTitle;
+ private LinearLayout foreignKeys;
+ private LinearLayout foreignKeysCard;
+ private Button mSaveButton;
+ private Button mCancelButton;
+
+ private AxolotlService.FetchStatus lastFetchReport = AxolotlService.FetchStatus.SUCCESS;
+
+ private final Map<String, Boolean> ownKeysToTrust = new HashMap<>();
+ private final Map<String, Boolean> foreignKeysToTrust = new HashMap<>();
+
+ private final OnClickListener mSaveButtonListener = new OnClickListener() {
+ @Override
+ public void onClick(View v) {
+ commitTrusts();
+ finishOk();
+ }
+ };
+
+ private final OnClickListener mCancelButtonListener = new OnClickListener() {
+ @Override
+ public void onClick(View v) {
+ setResult(RESULT_CANCELED);
+ finish();
+ }
+ };
+
+ @Override
+ protected void refreshUiReal() {
+ invalidateOptionsMenu();
+ populateView();
+ }
+
+ @Override
+ protected String getShareableUri() {
+ if (contact != null) {
+ return contact.getShareableUri();
+ } else {
+ return "";
+ }
+ }
+
+ @Override
+ protected void onCreate(final Bundle savedInstanceState) {
+ super.onCreate(savedInstanceState);
+ setContentView(R.layout.activity_trust_keys);
+ try {
+ this.accountJid = Jid.fromString(getIntent().getExtras().getString(EXTRA_ACCOUNT));
+ } catch (final InvalidJidException ignored) {
+ }
+ try {
+ this.contactJid = Jid.fromString(getIntent().getExtras().getString("contact"));
+ } catch (final InvalidJidException ignored) {
+ }
+
+ keyErrorMessageCard = (LinearLayout) findViewById(R.id.key_error_message_card);
+ keyErrorMessage = (TextView) findViewById(R.id.key_error_message);
+ ownKeysTitle = (TextView) findViewById(R.id.own_keys_title);
+ ownKeys = (LinearLayout) findViewById(R.id.own_keys_details);
+ ownKeysCard = (LinearLayout) findViewById(R.id.own_keys_card);
+ foreignKeysTitle = (TextView) findViewById(R.id.foreign_keys_title);
+ foreignKeys = (LinearLayout) findViewById(R.id.foreign_keys_details);
+ foreignKeysCard = (LinearLayout) findViewById(R.id.foreign_keys_card);
+ mCancelButton = (Button) findViewById(R.id.cancel_button);
+ mCancelButton.setOnClickListener(mCancelButtonListener);
+ mSaveButton = (Button) findViewById(R.id.save_button);
+ mSaveButton.setOnClickListener(mSaveButtonListener);
+
+
+ if (getActionBar() != null) {
+ getActionBar().setHomeButtonEnabled(true);
+ getActionBar().setDisplayHomeAsUpEnabled(true);
+ }
+ }
+
+ private void populateView() {
+ setTitle(getString(R.string.trust_omemo_fingerprints));
+ ownKeys.removeAllViews();
+ foreignKeys.removeAllViews();
+ boolean hasOwnKeys = false;
+ boolean hasForeignKeys = false;
+ for(final String fingerprint : ownKeysToTrust.keySet()) {
+ hasOwnKeys = true;
+ addFingerprintRowWithListeners(ownKeys, contact.getAccount(), fingerprint, false,
+ XmppAxolotlSession.Trust.fromBoolean(ownKeysToTrust.get(fingerprint)), false,
+ new CompoundButton.OnCheckedChangeListener() {
+ @Override
+ public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
+ ownKeysToTrust.put(fingerprint, isChecked);
+ // own fingerprints have no impact on locked status.
+ }
+ },
+ null,
+ null
+ );
+ }
+ for(final String fingerprint : foreignKeysToTrust.keySet()) {
+ hasForeignKeys = true;
+ addFingerprintRowWithListeners(foreignKeys, contact.getAccount(), fingerprint, false,
+ XmppAxolotlSession.Trust.fromBoolean(foreignKeysToTrust.get(fingerprint)), false,
+ new CompoundButton.OnCheckedChangeListener() {
+ @Override
+ public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
+ foreignKeysToTrust.put(fingerprint, isChecked);
+ lockOrUnlockAsNeeded();
+ }
+ },
+ null,
+ null
+ );
+ }
+
+ if(hasOwnKeys) {
+ ownKeysTitle.setText(accountJid.toString());
+ ownKeysCard.setVisibility(View.VISIBLE);
+ }
+ if(hasForeignKeys) {
+ foreignKeysTitle.setText(contactJid.toString());
+ foreignKeysCard.setVisibility(View.VISIBLE);
+ }
+ if(hasPendingKeyFetches()) {
+ setFetching();
+ lock();
+ } else {
+ if (!hasForeignKeys && hasNoOtherTrustedKeys()) {
+ keyErrorMessageCard.setVisibility(View.VISIBLE);
+ if (lastFetchReport == AxolotlService.FetchStatus.ERROR
+ || contact.getAccount().getAxolotlService().fetchMapHasErrors(contact)) {
+ keyErrorMessage.setText(R.string.error_no_keys_to_trust_server_error);
+ } else {
+ keyErrorMessage.setText(R.string.error_no_keys_to_trust);
+ }
+ ownKeys.removeAllViews(); ownKeysCard.setVisibility(View.GONE);
+ foreignKeys.removeAllViews(); foreignKeysCard.setVisibility(View.GONE);
+ }
+ lockOrUnlockAsNeeded();
+ setDone();
+ }
+ }
+
+ private boolean reloadFingerprints() {
+ ownKeysToTrust.clear();
+ foreignKeysToTrust.clear();
+ AxolotlService service = this.mAccount.getAxolotlService();
+ Set<IdentityKey> ownKeysSet = service.getKeysWithTrust(XmppAxolotlSession.Trust.UNDECIDED);
+ Set<IdentityKey> foreignKeysSet = service.getKeysWithTrust(XmppAxolotlSession.Trust.UNDECIDED, contact);
+ if (hasNoOtherTrustedKeys() && ownKeysSet.size() == 0) {
+ foreignKeysSet.addAll(service.getKeysWithTrust(XmppAxolotlSession.Trust.UNTRUSTED, contact));
+ }
+ for(final IdentityKey identityKey : ownKeysSet) {
+ if(!ownKeysToTrust.containsKey(identityKey)) {
+ ownKeysToTrust.put(identityKey.getFingerprint().replaceAll("\\s", ""), false);
+ }
+ }
+ for(final IdentityKey identityKey : foreignKeysSet) {
+ if(!foreignKeysToTrust.containsKey(identityKey)) {
+ foreignKeysToTrust.put(identityKey.getFingerprint().replaceAll("\\s", ""), false);
+ }
+ }
+ return ownKeysSet.size() + foreignKeysSet.size() > 0;
+ }
+
+ @Override
+ public void onBackendConnected() {
+ if ((accountJid != null) && (contactJid != null)) {
+ this.mAccount = xmppConnectionService.findAccountByJid(accountJid);
+ if (this.mAccount == null) {
+ return;
+ }
+ this.contact = this.mAccount.getRoster().getContact(contactJid);
+ reloadFingerprints();
+ populateView();
+ }
+ }
+
+ private boolean hasNoOtherTrustedKeys() {
+ return mAccount == null || mAccount.getAxolotlService().getNumTrustedKeys(contact) == 0;
+ }
+
+ private boolean hasPendingKeyFetches() {
+ return mAccount != null && contact != null && mAccount.getAxolotlService().hasPendingKeyFetches(mAccount,contact);
+ }
+
+
+ @Override
+ public void onKeyStatusUpdated(final AxolotlService.FetchStatus report) {
+ if (report != null) {
+ lastFetchReport = report;
+ runOnUiThread(new Runnable() {
+ @Override
+ public void run() {
+ switch (report) {
+ case ERROR:
+ Toast.makeText(TrustKeysActivity.this,R.string.error_fetching_omemo_key,Toast.LENGTH_SHORT).show();
+ break;
+ case SUCCESS_VERIFIED:
+ Toast.makeText(TrustKeysActivity.this,R.string.verified_omemo_key_with_certificate,Toast.LENGTH_LONG).show();
+ break;
+ }
+ }
+ });
+
+ }
+ boolean keysToTrust = reloadFingerprints();
+ if (keysToTrust || hasPendingKeyFetches() || hasNoOtherTrustedKeys()) {
+ refreshUi();
+ } else {
+ runOnUiThread(new Runnable() {
+ @Override
+ public void run() {
+ finishOk();
+ }
+ });
+
+ }
+ }
+
+ private void finishOk() {
+ Intent data = new Intent();
+ data.putExtra("choice", getIntent().getIntExtra("choice", ConversationActivity.ATTACHMENT_CHOICE_INVALID));
+ setResult(RESULT_OK, data);
+ finish();
+ }
+
+ private void commitTrusts() {
+ for(final String fingerprint :ownKeysToTrust.keySet()) {
+ contact.getAccount().getAxolotlService().setFingerprintTrust(
+ fingerprint,
+ XmppAxolotlSession.Trust.fromBoolean(ownKeysToTrust.get(fingerprint)));
+ }
+ for(final String fingerprint:foreignKeysToTrust.keySet()) {
+ contact.getAccount().getAxolotlService().setFingerprintTrust(
+ fingerprint,
+ XmppAxolotlSession.Trust.fromBoolean(foreignKeysToTrust.get(fingerprint)));
+ }
+ }
+
+ private void unlock() {
+ mSaveButton.setEnabled(true);
+ mSaveButton.setTextColor(getPrimaryTextColor());
+ }
+
+ private void lock() {
+ mSaveButton.setEnabled(false);
+ mSaveButton.setTextColor(getSecondaryTextColor());
+ }
+
+ private void lockOrUnlockAsNeeded() {
+ if (hasNoOtherTrustedKeys() && !foreignKeysToTrust.values().contains(true)){
+ lock();
+ } else {
+ unlock();
+ }
+ }
+
+ private void setDone() {
+ mSaveButton.setText(getString(R.string.done));
+ }
+
+ private void setFetching() {
+ mSaveButton.setText(getString(R.string.fetching_keys));
+ }
+}
diff --git a/src/main/java/de/thedevstack/conversationsplus/ui/UiCallback.java b/src/main/java/de/thedevstack/conversationsplus/ui/UiCallback.java
index 0d23d29e..d5291b80 100644
--- a/src/main/java/de/thedevstack/conversationsplus/ui/UiCallback.java
+++ b/src/main/java/de/thedevstack/conversationsplus/ui/UiCallback.java
@@ -3,9 +3,9 @@ package de.thedevstack.conversationsplus.ui;
import android.app.PendingIntent;
public interface UiCallback<T> {
- public void success(T object);
+ void success(T object);
- public void error(int errorCode, T object);
+ void error(int errorCode, T object);
- public void userInputRequried(PendingIntent pi, T object);
+ void userInputRequried(PendingIntent pi, T object);
}
diff --git a/src/main/java/de/thedevstack/conversationsplus/ui/VerifyOTRActivity.java b/src/main/java/de/thedevstack/conversationsplus/ui/VerifyOTRActivity.java
index 9f867dd2..494d4bea 100644
--- a/src/main/java/de/thedevstack/conversationsplus/ui/VerifyOTRActivity.java
+++ b/src/main/java/de/thedevstack/conversationsplus/ui/VerifyOTRActivity.java
@@ -196,9 +196,8 @@ public class VerifyOTRActivity extends XmppActivity implements XmppConnectionSer
protected boolean handleIntent(Intent intent) {
if (intent != null && intent.getAction().equals(ACTION_VERIFY_CONTACT)) {
- try {
- this.mAccount = this.xmppConnectionService.findAccountByJid(Jid.fromString(intent.getExtras().getString("account")));
- } catch (final InvalidJidException ignored) {
+ this.mAccount = extractAccount(intent);
+ if (this.mAccount == null) {
return false;
}
try {
diff --git a/src/main/java/de/thedevstack/conversationsplus/ui/XmppActivity.java b/src/main/java/de/thedevstack/conversationsplus/ui/XmppActivity.java
index 40fbe7c1..1fbb3b1d 100644
--- a/src/main/java/de/thedevstack/conversationsplus/ui/XmppActivity.java
+++ b/src/main/java/de/thedevstack/conversationsplus/ui/XmppActivity.java
@@ -1,5 +1,6 @@
package de.thedevstack.conversationsplus.ui;
+import android.Manifest;
import android.annotation.SuppressLint;
import android.annotation.TargetApi;
import android.app.ActionBar;
@@ -16,6 +17,7 @@ import android.content.DialogInterface.OnClickListener;
import android.content.Intent;
import android.content.IntentSender.SendIntentException;
import android.content.ServiceConnection;
+import android.content.SharedPreferences;
import android.content.pm.PackageManager;
import android.content.pm.ResolveInfo;
import android.content.res.Resources;
@@ -34,15 +36,19 @@ import android.os.Build;
import android.os.Bundle;
import android.os.Handler;
import android.os.IBinder;
+import android.os.PowerManager;
import android.os.SystemClock;
+import android.preference.PreferenceManager;
import android.text.InputType;
import android.util.DisplayMetrics;
import android.view.MenuItem;
import android.view.View;
import android.view.inputmethod.InputMethodManager;
+import android.widget.CompoundButton;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.LinearLayout;
+import android.widget.TextView;
import android.widget.Toast;
import com.google.zxing.BarcodeFormat;
@@ -62,9 +68,11 @@ import java.util.List;
import java.util.concurrent.RejectedExecutionException;
import de.thedevstack.android.logcat.Logging;
-import de.thedevstack.conversationsplus.Config;
import de.thedevstack.conversationsplus.ConversationsPlusPreferences;
+import de.thedevstack.conversationsplus.utils.ImageUtil;
+import de.thedevstack.conversationsplus.Config;
import de.thedevstack.conversationsplus.R;
+import de.thedevstack.conversationsplus.crypto.axolotl.XmppAxolotlSession;
import de.thedevstack.conversationsplus.entities.Account;
import de.thedevstack.conversationsplus.entities.Contact;
import de.thedevstack.conversationsplus.entities.Conversation;
@@ -73,8 +81,10 @@ import de.thedevstack.conversationsplus.entities.MucOptions;
import de.thedevstack.conversationsplus.entities.Presences;
import de.thedevstack.conversationsplus.services.XmppConnectionService;
import de.thedevstack.conversationsplus.services.XmppConnectionService.XmppConnectionBinder;
+import de.thedevstack.conversationsplus.ui.widget.Switch;
+import de.thedevstack.conversationsplus.utils.CryptoHelper;
import de.thedevstack.conversationsplus.utils.ExceptionHelper;
-import de.thedevstack.conversationsplus.utils.ImageUtil;
+import de.thedevstack.conversationsplus.xmpp.OnKeyStatusUpdated;
import de.thedevstack.conversationsplus.xmpp.OnUpdateBlocklist;
import de.thedevstack.conversationsplus.xmpp.jid.InvalidJidException;
import de.thedevstack.conversationsplus.xmpp.jid.Jid;
@@ -83,6 +93,10 @@ public abstract class XmppActivity extends Activity {
protected static final int REQUEST_ANNOUNCE_PGP = 0x0101;
protected static final int REQUEST_INVITE_TO_CONVERSATION = 0x0102;
+ protected static final int REQUEST_CHOOSE_PGP_ID = 0x0103;
+ protected static final int REQUEST_BATTERY_OP = 0x13849ff;
+
+ public static final String EXTRA_ACCOUNT = "account";
public XmppConnectionService xmppConnectionService;
public boolean xmppConnectionServiceBound = false;
@@ -90,6 +104,7 @@ public abstract class XmppActivity extends Activity {
protected int mPrimaryTextColor;
protected int mSecondaryTextColor;
+ protected int mTertiaryTextColor;
protected int mPrimaryBackgroundColor;
protected int mSecondaryBackgroundColor;
protected int mColorRed;
@@ -97,6 +112,8 @@ public abstract class XmppActivity extends Activity {
protected int mColorGreen;
protected int mPrimaryColor;
+ protected boolean mUseSubject = true;
+
private DisplayMetrics metrics;
protected int mTheme;
protected boolean mUsingEnterKey = false;
@@ -114,7 +131,7 @@ public abstract class XmppActivity extends Activity {
protected ConferenceInvite mPendingConferenceInvite = null;
- protected void refreshUi() {
+ protected final void refreshUi() {
final long diff = SystemClock.elapsedRealtime() - mLastUiRefresh;
if (diff > Config.REFRESH_UI_INTERVAL) {
mRefreshUiHandler.removeCallbacks(mRefreshUiRunnable);
@@ -126,9 +143,7 @@ public abstract class XmppActivity extends Activity {
}
}
- protected void refreshUiReal() {
-
- };
+ abstract protected void refreshUiReal();
protected interface OnValueEdited {
public void onValueEdited(String value);
@@ -273,6 +288,9 @@ public abstract class XmppActivity extends Activity {
if (this instanceof XmppConnectionService.OnAccountUpdate) {
this.xmppConnectionService.setOnAccountListChangedListener((XmppConnectionService.OnAccountUpdate) this);
}
+ if (this instanceof XmppConnectionService.OnCaptchaRequested) {
+ this.xmppConnectionService.setOnCaptchaRequestedListener((XmppConnectionService.OnCaptchaRequested) this);
+ }
if (this instanceof XmppConnectionService.OnRosterUpdate) {
this.xmppConnectionService.setOnRosterUpdateListener((XmppConnectionService.OnRosterUpdate) this);
}
@@ -285,6 +303,9 @@ public abstract class XmppActivity extends Activity {
if (this instanceof XmppConnectionService.OnShowErrorToast) {
this.xmppConnectionService.setOnShowErrorToastListener((XmppConnectionService.OnShowErrorToast) this);
}
+ if (this instanceof OnKeyStatusUpdated) {
+ this.xmppConnectionService.setOnKeyStatusUpdatedListener((OnKeyStatusUpdated) this);
+ }
}
protected void unregisterListeners() {
@@ -294,6 +315,9 @@ public abstract class XmppActivity extends Activity {
if (this instanceof XmppConnectionService.OnAccountUpdate) {
this.xmppConnectionService.removeOnAccountListChangedListener();
}
+ if (this instanceof XmppConnectionService.OnCaptchaRequested) {
+ this.xmppConnectionService.removeOnCaptchaRequestedListener();
+ }
if (this instanceof XmppConnectionService.OnRosterUpdate) {
this.xmppConnectionService.removeOnRosterUpdateListener();
}
@@ -306,6 +330,9 @@ public abstract class XmppActivity extends Activity {
if (this instanceof XmppConnectionService.OnShowErrorToast) {
this.xmppConnectionService.removeOnShowErrorToastListener();
}
+ if (this instanceof OnKeyStatusUpdated) {
+ this.xmppConnectionService.removeOnNewKeysAvailableListener();
+ }
}
@Override
@@ -334,34 +361,63 @@ public abstract class XmppActivity extends Activity {
ExceptionHelper.init(getApplicationContext());
mPrimaryTextColor = getResources().getColor(R.color.primaryText);
mSecondaryTextColor = getResources().getColor(R.color.secondaryText);
+ mTertiaryTextColor = getResources().getColor(R.color.black12);
mColorRed = getResources().getColor(R.color.warning);
+ mColorOrange = getResources().getColor(R.color.orange500);
mColorGreen = getResources().getColor(R.color.online);
+ mPrimaryColor = getResources().getColor(R.color.primary);
mPrimaryBackgroundColor = getResources().getColor(R.color.primaryBackground);
mSecondaryBackgroundColor = getResources().getColor(R.color.secondaryBackground);
this.mTheme = findTheme();
setTheme(this.mTheme);
this.mUsingEnterKey = ConversationsPlusPreferences.displayEnterKey();
-
+ mUseSubject = getPreferences().getBoolean("use_subject", true);
final ActionBar ab = getActionBar();
if (ab!=null) {
ab.setDisplayHomeAsUpEnabled(true);
}
}
+ protected boolean showBatteryOptimizationWarning() {
+ if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
+ PowerManager pm = (PowerManager) getSystemService(POWER_SERVICE);
+ return !pm.isIgnoringBatteryOptimizations(getPackageName());
+ } else {
+ return false;
+ }
+ }
+
+ protected boolean usingEnterKey() {
+ return getPreferences().getBoolean("display_enter_key", false);
+ }
+
+ protected SharedPreferences getPreferences() {
+ return PreferenceManager
+ .getDefaultSharedPreferences(getApplicationContext());
+ }
+
+ public boolean useSubjectToIdentifyConference() {
+ return mUseSubject;
+ }
+
public void switchToConversation(Conversation conversation) {
switchToConversation(conversation, null, false);
}
public void switchToConversation(Conversation conversation, String text,
boolean newTask) {
- switchToConversation(conversation,text,null,newTask);
+ switchToConversation(conversation,text,null,false,newTask);
}
public void highlightInMuc(Conversation conversation, String nick) {
- switchToConversation(conversation, null, nick, false);
+ switchToConversation(conversation, null, nick, false, false);
}
- private void switchToConversation(Conversation conversation, String text, String nick, boolean newTask) {
+ public void privateMsgInMuc(Conversation conversation, String nick) {
+ switchToConversation(conversation, null, nick, true, false);
+ }
+
+ private void switchToConversation(Conversation conversation, String text, String nick, boolean pm, boolean newTask) {
Intent viewConversationIntent = new Intent(this,
ConversationActivity.class);
viewConversationIntent.setAction(Intent.ACTION_VIEW);
@@ -372,6 +428,7 @@ public abstract class XmppActivity extends Activity {
}
if (nick != null) {
viewConversationIntent.putExtra(ConversationActivity.NICK, nick);
+ viewConversationIntent.putExtra(ConversationActivity.PRIVATE_MESSAGE,pm);
}
viewConversationIntent.setType(ConversationActivity.VIEW_CONVERSATION);
if (newTask) {
@@ -387,16 +444,26 @@ public abstract class XmppActivity extends Activity {
}
public void switchToContactDetails(Contact contact) {
+ switchToContactDetails(contact, null);
+ }
+
+ public void switchToContactDetails(Contact contact, String messageFingerprint) {
Intent intent = new Intent(this, ContactDetailsActivity.class);
intent.setAction(ContactDetailsActivity.ACTION_VIEW_CONTACT);
- intent.putExtra("account", contact.getAccount().getJid().toBareJid().toString());
+ intent.putExtra(EXTRA_ACCOUNT, contact.getAccount().getJid().toBareJid().toString());
intent.putExtra("contact", contact.getJid().toString());
+ intent.putExtra("fingerprint", messageFingerprint);
startActivity(intent);
}
public void switchToAccount(Account account) {
+ switchToAccount(account, false);
+ }
+
+ public void switchToAccount(Account account, boolean init) {
Intent intent = new Intent(this, EditAccountActivity.class);
intent.putExtra("jid", account.getJid().toBareJid().toString());
+ intent.putExtra("init", init);
startActivity(intent);
}
@@ -417,54 +484,81 @@ public abstract class XmppActivity extends Activity {
intent.putExtra("filter_contacts", contacts.toArray(new String[contacts.size()]));
intent.putExtra("conversation", conversation.getUuid());
intent.putExtra("multiple", true);
+ intent.putExtra("show_enter_jid", true);
+ intent.putExtra(EXTRA_ACCOUNT, conversation.getAccount().getJid().toBareJid().toString());
startActivityForResult(intent, REQUEST_INVITE_TO_CONVERSATION);
}
protected void announcePgp(Account account, final Conversation conversation) {
- xmppConnectionService.getPgpEngine().generateSignature(account,
- "online", new UiCallback<Account>() {
-
- @Override
- public void userInputRequried(PendingIntent pi,
- Account account) {
- try {
- startIntentSenderForResult(pi.getIntentSender(),
- REQUEST_ANNOUNCE_PGP, null, 0, 0, 0);
- } catch (final SendIntentException ignored) {
- }
- }
+ if (account.getPgpId() == -1) {
+ choosePgpSignId(account);
+ } else {
+ xmppConnectionService.getPgpEngine().generateSignature(account, "", new UiCallback<Account>() {
- @Override
- public void success(Account account) {
- xmppConnectionService.databaseBackend.updateAccount(account);
- xmppConnectionService.sendPresence(account);
- if (conversation != null) {
- conversation.setNextEncryption(Message.ENCRYPTION_PGP);
- xmppConnectionService.databaseBackend.updateConversation(conversation);
- }
- }
+ @Override
+ public void userInputRequried(PendingIntent pi,
+ Account account) {
+ try {
+ startIntentSenderForResult(pi.getIntentSender(),
+ REQUEST_ANNOUNCE_PGP, null, 0, 0, 0);
+ } catch (final SendIntentException ignored) {
+ }
+ }
- @Override
- public void error(int error, Account account) {
- displayErrorDialog(error);
- }
- });
+ @Override
+ public void success(Account account) {
+ xmppConnectionService.databaseBackend.updateAccount(account);
+ xmppConnectionService.sendPresence(account);
+ if (conversation != null) {
+ conversation.setNextEncryption(Message.ENCRYPTION_PGP);
+ xmppConnectionService.databaseBackend.updateConversation(conversation);
+ }
+ }
+
+ @Override
+ public void error(int error, Account account) {
+ displayErrorDialog(error);
+ }
+ });
+ }
+ }
+
+ protected void choosePgpSignId(Account account) {
+ xmppConnectionService.getPgpEngine().chooseKey(account, new UiCallback<Account>() {
+ @Override
+ public void success(Account account1) {
+ }
+
+ @Override
+ public void error(int errorCode, Account object) {
+
+ }
+
+ @Override
+ public void userInputRequried(PendingIntent pi, Account object) {
+ try {
+ startIntentSenderForResult(pi.getIntentSender(),
+ REQUEST_CHOOSE_PGP_ID, null, 0, 0, 0);
+ } catch (final SendIntentException ignored) {
+ }
+ }
+ });
}
public void displayErrorDialog(final int errorCode) {
runOnUiThread(new Runnable() {
- @Override
- public void run() {
- AlertDialog.Builder builder = new AlertDialog.Builder(
- XmppActivity.this);
- builder.setIconAttribute(android.R.attr.alertDialogIcon);
- builder.setTitle(getString(R.string.error));
- builder.setMessage(errorCode);
- builder.setNeutralButton(R.string.accept, null);
- builder.create().show();
- }
- });
+ @Override
+ public void run() {
+ AlertDialog.Builder builder = new AlertDialog.Builder(
+ XmppActivity.this);
+ builder.setIconAttribute(android.R.attr.alertDialogIcon);
+ builder.setTitle(getString(R.string.error));
+ builder.setMessage(errorCode);
+ builder.setNeutralButton(R.string.accept, null);
+ builder.create().show();
+ }
+ });
}
@@ -503,9 +597,9 @@ public abstract class XmppActivity extends Activity {
public void onClick(DialogInterface dialog, int which) {
if (xmppConnectionServiceBound) {
xmppConnectionService.sendPresencePacket(contact
- .getAccount(), xmppConnectionService
- .getPresenceGenerator()
- .requestPresenceUpdatesFrom(contact));
+ .getAccount(), xmppConnectionService
+ .getPresenceGenerator()
+ .requestPresenceUpdatesFrom(contact));
}
}
});
@@ -571,6 +665,151 @@ public abstract class XmppActivity extends Activity {
builder.create().show();
}
+ protected boolean addFingerprintRow(LinearLayout keys, final Account account, final String fingerprint, boolean highlight, View.OnClickListener onKeyClickedListener) {
+ final XmppAxolotlSession.Trust trust = account.getAxolotlService()
+ .getFingerprintTrust(fingerprint);
+ if (trust == null) {
+ return false;
+ }
+ return addFingerprintRowWithListeners(keys, account, fingerprint, highlight, trust, true,
+ new CompoundButton.OnCheckedChangeListener() {
+ @Override
+ public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
+ account.getAxolotlService().setFingerprintTrust(fingerprint,
+ (isChecked) ? XmppAxolotlSession.Trust.TRUSTED :
+ XmppAxolotlSession.Trust.UNTRUSTED);
+ }
+ },
+ new View.OnClickListener() {
+ @Override
+ public void onClick(View v) {
+ account.getAxolotlService().setFingerprintTrust(fingerprint,
+ XmppAxolotlSession.Trust.UNTRUSTED);
+ v.setEnabled(true);
+ }
+ },
+ onKeyClickedListener
+
+ );
+ }
+
+ protected boolean addFingerprintRowWithListeners(LinearLayout keys, final Account account,
+ final String fingerprint,
+ boolean highlight,
+ XmppAxolotlSession.Trust trust,
+ boolean showTag,
+ CompoundButton.OnCheckedChangeListener
+ onCheckedChangeListener,
+ View.OnClickListener onClickListener,
+ View.OnClickListener onKeyClickedListener) {
+ if (trust == XmppAxolotlSession.Trust.COMPROMISED) {
+ return false;
+ }
+ View view = getLayoutInflater().inflate(R.layout.contact_key, keys, false);
+ TextView key = (TextView) view.findViewById(R.id.key);
+ key.setOnClickListener(onKeyClickedListener);
+ TextView keyType = (TextView) view.findViewById(R.id.key_type);
+ keyType.setOnClickListener(onKeyClickedListener);
+ Switch trustToggle = (Switch) view.findViewById(R.id.tgl_trust);
+ trustToggle.setVisibility(View.VISIBLE);
+ trustToggle.setOnCheckedChangeListener(onCheckedChangeListener);
+ trustToggle.setOnClickListener(onClickListener);
+ final View.OnLongClickListener purge = new View.OnLongClickListener() {
+ @Override
+ public boolean onLongClick(View v) {
+ showPurgeKeyDialog(account, fingerprint);
+ return true;
+ }
+ };
+ view.setOnLongClickListener(purge);
+ key.setOnLongClickListener(purge);
+ keyType.setOnLongClickListener(purge);
+ boolean x509 = trust == XmppAxolotlSession.Trust.TRUSTED_X509 || trust == XmppAxolotlSession.Trust.INACTIVE_TRUSTED_X509;
+ switch (trust) {
+ case UNTRUSTED:
+ case TRUSTED:
+ case TRUSTED_X509:
+ trustToggle.setChecked(trust.trusted(), false);
+ trustToggle.setEnabled(trust != XmppAxolotlSession.Trust.TRUSTED_X509);
+ if (trust == XmppAxolotlSession.Trust.TRUSTED_X509) {
+ trustToggle.setOnClickListener(null);
+ }
+ key.setTextColor(getPrimaryTextColor());
+ keyType.setTextColor(getSecondaryTextColor());
+ break;
+ case UNDECIDED:
+ trustToggle.setChecked(false, false);
+ trustToggle.setEnabled(false);
+ key.setTextColor(getPrimaryTextColor());
+ keyType.setTextColor(getSecondaryTextColor());
+ break;
+ case INACTIVE_UNTRUSTED:
+ case INACTIVE_UNDECIDED:
+ trustToggle.setOnClickListener(null);
+ trustToggle.setChecked(false, false);
+ trustToggle.setEnabled(false);
+ key.setTextColor(getTertiaryTextColor());
+ keyType.setTextColor(getTertiaryTextColor());
+ break;
+ case INACTIVE_TRUSTED:
+ case INACTIVE_TRUSTED_X509:
+ trustToggle.setOnClickListener(null);
+ trustToggle.setChecked(true, false);
+ trustToggle.setEnabled(false);
+ key.setTextColor(getTertiaryTextColor());
+ keyType.setTextColor(getTertiaryTextColor());
+ break;
+ }
+
+ if (showTag) {
+ keyType.setText(getString(x509 ? R.string.omemo_fingerprint_x509 : R.string.omemo_fingerprint));
+ } else {
+ keyType.setVisibility(View.GONE);
+ }
+ if (highlight) {
+ keyType.setTextColor(getResources().getColor(R.color.accent));
+ keyType.setText(getString(x509 ? R.string.omemo_fingerprint_x509_selected_message : R.string.omemo_fingerprint_selected_message));
+ } else {
+ keyType.setText(getString(x509 ? R.string.omemo_fingerprint_x509 : R.string.omemo_fingerprint));
+ }
+
+ key.setText(CryptoHelper.prettifyFingerprint(fingerprint.substring(2)));
+ keys.addView(view);
+ return true;
+ }
+
+ public void showPurgeKeyDialog(final Account account, final String fingerprint) {
+ Builder builder = new Builder(this);
+ builder.setTitle(getString(R.string.purge_key));
+ builder.setIconAttribute(android.R.attr.alertDialogIcon);
+ builder.setMessage(getString(R.string.purge_key_desc_part1)
+ + "\n\n" + CryptoHelper.prettifyFingerprint(fingerprint.substring(2))
+ + "\n\n" + getString(R.string.purge_key_desc_part2));
+ builder.setNegativeButton(getString(R.string.cancel), null);
+ builder.setPositiveButton(getString(R.string.accept),
+ new DialogInterface.OnClickListener() {
+ @Override
+ public void onClick(DialogInterface dialog, int which) {
+ account.getAxolotlService().purgeKey(fingerprint);
+ refreshUi();
+ }
+ });
+ builder.create().show();
+ }
+
+ public boolean hasStoragePermission(int requestCode) {
+ if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
+ if (checkSelfPermission(Manifest.permission.WRITE_EXTERNAL_STORAGE) != PackageManager.PERMISSION_GRANTED) {
+ requestPermissions(new String[]{Manifest.permission.WRITE_EXTERNAL_STORAGE}, requestCode);
+ return false;
+ } else {
+ return true;
+ }
+ } else {
+ return true;
+ }
+ }
+
public void selectPresence(final Conversation conversation,
final OnPresenceSelected listener) {
final Contact contact = conversation.getContact();
@@ -690,6 +929,10 @@ public abstract class XmppActivity extends Activity {
}
};
+ public int getTertiaryTextColor() {
+ return this.mTertiaryTextColor;
+ }
+
public int getSecondaryTextColor() {
return this.mSecondaryTextColor;
}
@@ -737,7 +980,7 @@ public abstract class XmppActivity extends Activity {
@Override
public NdefMessage createNdefMessage(NfcEvent nfcEvent) {
return new NdefMessage(new NdefRecord[]{
- NdefRecord.createUri(getShareableUri()),
+ NdefRecord.createUri(getShareableUri()),
NdefRecord.createApplicationRecord("de.thedevstack.conversationsplus")
});
}
@@ -818,6 +1061,15 @@ public abstract class XmppActivity extends Activity {
}
}
+ protected Account extractAccount(Intent intent) {
+ String jid = intent != null ? intent.getStringExtra(EXTRA_ACCOUNT) : null;
+ try {
+ return jid != null ? xmppConnectionService.findAccountByJid(Jid.fromString(jid)) : null;
+ } catch (InvalidJidException e) {
+ return null;
+ }
+ }
+
public static class ConferenceInvite {
private String uuid;
private List<Jid> jids = new ArrayList<>();
diff --git a/src/main/java/de/thedevstack/conversationsplus/ui/adapter/AccountAdapter.java b/src/main/java/de/thedevstack/conversationsplus/ui/adapter/AccountAdapter.java
index 6195f47b..eb0344bc 100644
--- a/src/main/java/de/thedevstack/conversationsplus/ui/adapter/AccountAdapter.java
+++ b/src/main/java/de/thedevstack/conversationsplus/ui/adapter/AccountAdapter.java
@@ -1,12 +1,5 @@
package de.thedevstack.conversationsplus.ui.adapter;
-import java.util.List;
-
-import de.thedevstack.conversationsplus.R;
-import de.thedevstack.conversationsplus.entities.Account;
-import de.thedevstack.conversationsplus.services.AvatarService;
-import de.thedevstack.conversationsplus.ui.XmppActivity;
-import de.thedevstack.conversationsplus.ui.ManageAccountActivity;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
@@ -15,7 +8,16 @@ import android.widget.ArrayAdapter;
import android.widget.CompoundButton;
import android.widget.ImageView;
import android.widget.TextView;
-import android.widget.Switch;
+
+import java.util.List;
+
+import de.thedevstack.conversationsplus.Config;
+import de.thedevstack.conversationsplus.R;
+import de.thedevstack.conversationsplus.entities.Account;
+import de.thedevstack.conversationsplus.services.AvatarService;
+import de.thedevstack.conversationsplus.ui.ManageAccountActivity;
+import de.thedevstack.conversationsplus.ui.XmppActivity;
+import de.thedevstack.conversationsplus.ui.widget.Switch;
public class AccountAdapter extends ArrayAdapter<Account> {
@@ -35,7 +37,11 @@ public class AccountAdapter extends ArrayAdapter<Account> {
view = inflater.inflate(R.layout.account_row, parent, false);
}
TextView jid = (TextView) view.findViewById(R.id.account_jid);
- jid.setText(account.getJid().toBareJid().toString());
+ if (Config.DOMAIN_LOCK != null) {
+ jid.setText(account.getJid().getLocalpart());
+ } else {
+ jid.setText(account.getJid().toBareJid().toString());
+ }
TextView statusView = (TextView) view.findViewById(R.id.account_status);
ImageView imageView = (ImageView) view.findViewById(R.id.account_image);
imageView.setImageBitmap(AvatarService.getInstance().get(account, activity.getPixel(48)));
@@ -54,8 +60,7 @@ public class AccountAdapter extends ArrayAdapter<Account> {
}
final Switch tglAccountState = (Switch) view.findViewById(R.id.tgl_account_status);
final boolean isDisabled = (account.getStatus() == Account.State.DISABLED);
- tglAccountState.setOnCheckedChangeListener(null);
- tglAccountState.setChecked(!isDisabled);
+ tglAccountState.setChecked(!isDisabled,false);
tglAccountState.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton compoundButton, boolean b) {
diff --git a/src/main/java/de/thedevstack/conversationsplus/ui/adapter/ConversationAdapter.java b/src/main/java/de/thedevstack/conversationsplus/ui/adapter/ConversationAdapter.java
index 590a6cfd..ab131cd0 100644
--- a/src/main/java/de/thedevstack/conversationsplus/ui/adapter/ConversationAdapter.java
+++ b/src/main/java/de/thedevstack/conversationsplus/ui/adapter/ConversationAdapter.java
@@ -20,20 +20,17 @@ import java.lang.ref.WeakReference;
import java.util.List;
import java.util.concurrent.RejectedExecutionException;
-import de.thedevstack.conversationsplus.ConversationsPlusPreferences;
-import de.thedevstack.conversationsplus.services.AvatarService;
import de.thedevstack.conversationsplus.ui.listeners.ShowResourcesListDialogListener;
import de.tzur.conversations.Settings;
import de.thedevstack.conversationsplus.R;
import de.thedevstack.conversationsplus.entities.Account;
import de.thedevstack.conversationsplus.entities.Conversation;
-import de.thedevstack.conversationsplus.entities.Transferable;
import de.thedevstack.conversationsplus.entities.Message;
-import de.thedevstack.conversationsplus.entities.Presences;
+import de.thedevstack.conversationsplus.entities.Transferable;
+import de.thedevstack.conversationsplus.services.AvatarService;
import de.thedevstack.conversationsplus.ui.ConversationActivity;
import de.thedevstack.conversationsplus.ui.XmppActivity;
import de.thedevstack.conversationsplus.utils.UIHelper;
-import github.ankushsachdeva.emojicon.EmojiconTextView;
public class ConversationAdapter extends ArrayAdapter<Conversation> {
@@ -60,14 +57,15 @@ public class ConversationAdapter extends ArrayAdapter<Conversation> {
view.findViewById(R.id.conversationListRowFrame).setBackgroundColor(c);
}
TextView convName = (TextView) view.findViewById(R.id.conversation_name);
- if (conversation.getMode() == Conversation.MODE_SINGLE || ConversationsPlusPreferences.useSubject()) {
+ if (conversation.getMode() == Conversation.MODE_SINGLE || activity.useSubjectToIdentifyConference()) {
convName.setText(conversation.getName());
} else {
convName.setText(conversation.getJid().toBareJid().toString());
}
- EmojiconTextView mLastMessage = (EmojiconTextView) view.findViewById(R.id.conversation_lastmsg);
+ 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);
+ ImageView notificationStatus = (ImageView) view.findViewById(R.id.notification_status);
if (Settings.SHOW_ONLINE_STATUS && conversation.getAccount().getStatus() == Account.State.ONLINE) {
TextView status = (TextView) view.findViewById(R.id.status);
@@ -75,15 +73,15 @@ public class ConversationAdapter extends ArrayAdapter<Conversation> {
String color = "#000000";
if (conversation.getMode() == Conversation.MODE_SINGLE) {
switch (conversation.getContact().getMostAvailableStatus()) {
- case Presences.ONLINE:
- case Presences.CHAT:
+ case ONLINE:
+ case CHAT:
color = "#259B23";
break;
- case Presences.AWAY:
- case Presences.XA:
+ case AWAY:
+ case XA:
color = "#FF9800";
break;
- case Presences.DND:
+ case DND:
color = "#E51C23";
break;
}
@@ -113,7 +111,7 @@ public class ConversationAdapter extends ArrayAdapter<Conversation> {
imagePreview.setVisibility(View.GONE);
CharSequence msgText = preview.first;
String msgPrefix = null;
- if (message.getStatus() == Message.STATUS_SEND
+ if (message.getStatus() == Message.STATUS_SEND
|| message.getStatus() == Message.STATUS_SEND_DISPLAYED
|| message.getStatus() == Message.STATUS_SEND_FAILED
|| message.getStatus() == Message.STATUS_SEND_RECEIVED) {
@@ -122,7 +120,7 @@ public class ConversationAdapter extends ArrayAdapter<Conversation> {
msgPrefix = UIHelper.getMessageDisplayName(message);
}
String lastMessagePreview = ((null == msgPrefix || msgPrefix.isEmpty()) ? "" : (msgPrefix + ": ")) + msgText;
- mLastMessage.setText(lastMessagePreview);
+ mLastMessage.setText(lastMessagePreview);
if (preview.second) {
if (conversation.isRead()) {
mLastMessage.setTypeface(null, Typeface.ITALIC);
@@ -138,6 +136,20 @@ public class ConversationAdapter extends ArrayAdapter<Conversation> {
}
}
+ long muted_till = conversation.getLongAttribute(Conversation.ATTRIBUTE_MUTED_TILL,0);
+ if (muted_till == Long.MAX_VALUE) {
+ notificationStatus.setVisibility(View.VISIBLE);
+ notificationStatus.setImageResource(R.drawable.ic_notifications_off_grey600_24dp);
+ } else if (muted_till >= System.currentTimeMillis()) {
+ notificationStatus.setVisibility(View.VISIBLE);
+ notificationStatus.setImageResource(R.drawable.ic_notifications_paused_grey600_24dp);
+ } else if (conversation.alwaysNotify()) {
+ notificationStatus.setVisibility(View.GONE);
+ } else {
+ notificationStatus.setVisibility(View.VISIBLE);
+ notificationStatus.setImageResource(R.drawable.ic_notifications_none_grey600_24dp);
+ }
+
mTimestamp.setText(UIHelper.readableTimeDifference(activity, message.getTimeSent()));
ImageView profilePicture = (ImageView) view.findViewById(R.id.conversation_image);
profilePicture.setOnLongClickListener(new ShowResourcesListDialogListener(activity, conversation.getContact()));
@@ -228,4 +240,4 @@ public class ConversationAdapter extends ArrayAdapter<Conversation> {
return bitmapWorkerTaskReference.get();
}
}
-}
+} \ No newline at end of file
diff --git a/src/main/java/de/thedevstack/conversationsplus/ui/adapter/KnownHostsAdapter.java b/src/main/java/de/thedevstack/conversationsplus/ui/adapter/KnownHostsAdapter.java
index 7bca0aa6..41973089 100644
--- a/src/main/java/de/thedevstack/conversationsplus/ui/adapter/KnownHostsAdapter.java
+++ b/src/main/java/de/thedevstack/conversationsplus/ui/adapter/KnownHostsAdapter.java
@@ -1,13 +1,13 @@
package de.thedevstack.conversationsplus.ui.adapter;
-import java.util.ArrayList;
-import java.util.List;
-import java.util.Locale;
-
import android.content.Context;
import android.widget.ArrayAdapter;
import android.widget.Filter;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Locale;
+
public class KnownHostsAdapter extends ArrayAdapter<String> {
private ArrayList<String> domains;
private Filter domainFilter = new Filter() {
@@ -15,7 +15,7 @@ public class KnownHostsAdapter extends ArrayAdapter<String> {
@Override
protected FilterResults performFiltering(CharSequence constraint) {
if (constraint != null) {
- ArrayList<String> suggestions = new ArrayList<String>();
+ ArrayList<String> suggestions = new ArrayList<>();
final String[] split = constraint.toString().split("@");
if (split.length == 1) {
for (String domain : domains) {
@@ -58,10 +58,9 @@ public class KnownHostsAdapter extends ArrayAdapter<String> {
}
};
- public KnownHostsAdapter(Context context, int viewResourceId,
- List<String> mKnownHosts) {
+ public KnownHostsAdapter(Context context, int viewResourceId, List<String> mKnownHosts) {
super(context, viewResourceId, new ArrayList<String>());
- domains = new ArrayList<String>(mKnownHosts);
+ domains = new ArrayList<>(mKnownHosts);
}
@Override
diff --git a/src/main/java/de/thedevstack/conversationsplus/ui/adapter/ListItemAdapter.java b/src/main/java/de/thedevstack/conversationsplus/ui/adapter/ListItemAdapter.java
index 4ecebd84..a67f5bcd 100644
--- a/src/main/java/de/thedevstack/conversationsplus/ui/adapter/ListItemAdapter.java
+++ b/src/main/java/de/thedevstack/conversationsplus/ui/adapter/ListItemAdapter.java
@@ -1,18 +1,5 @@
package de.thedevstack.conversationsplus.ui.adapter;
-import java.lang.ref.WeakReference;
-import java.util.List;
-import java.util.concurrent.RejectedExecutionException;
-
-import de.thedevstack.conversationsplus.ConversationsPlusPreferences;
-import de.thedevstack.conversationsplus.services.AvatarService;
-import de.tzur.conversations.Settings;
-import de.thedevstack.conversationsplus.R;
-import de.thedevstack.conversationsplus.entities.ListItem;
-import de.thedevstack.conversationsplus.ui.XmppActivity;
-import de.thedevstack.conversationsplus.utils.UIHelper;
-import de.thedevstack.conversationsplus.xmpp.jid.Jid;
-
import android.content.Context;
import android.content.res.Resources;
import android.graphics.Bitmap;
@@ -27,6 +14,18 @@ import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;
+import java.lang.ref.WeakReference;
+import java.util.List;
+import java.util.concurrent.RejectedExecutionException;
+
+import de.thedevstack.conversationsplus.ConversationsPlusPreferences;
+import de.tzur.conversations.Settings;
+import de.thedevstack.conversationsplus.R;
+import de.thedevstack.conversationsplus.entities.ListItem;
+import de.thedevstack.conversationsplus.services.AvatarService;
+import de.thedevstack.conversationsplus.ui.XmppActivity;
+import de.thedevstack.conversationsplus.utils.UIHelper;
+
public class ListItemAdapter extends ArrayAdapter<ListItem> {
protected XmppActivity activity;
@@ -82,11 +81,12 @@ public class ListItemAdapter extends ArrayAdapter<ListItem> {
tagLayout.addView(tv);
}
}
- final Jid jid = item.getJid();
+ final String jid = item.getDisplayJid();
if (jid != null) {
- tvJid.setText(jid.toString());
+ tvJid.setVisibility(View.VISIBLE);
+ tvJid.setText(jid);
} else {
- tvJid.setText("");
+ tvJid.setVisibility(View.GONE);
}
tvName.setText(item.getDisplayName());
loadAvatar(item,picture);
@@ -98,7 +98,7 @@ public class ListItemAdapter extends ArrayAdapter<ListItem> {
}
public interface OnTagClickedListener {
- public void onTagClicked(String tag);
+ void onTagClicked(String tag);
}
class BitmapWorkerTask extends AsyncTask<ListItem, Void, Bitmap> {
diff --git a/src/main/java/de/thedevstack/conversationsplus/ui/adapter/MessageAdapter.java b/src/main/java/de/thedevstack/conversationsplus/ui/adapter/MessageAdapter.java
index 647ef68d..6a141f11 100644
--- a/src/main/java/de/thedevstack/conversationsplus/ui/adapter/MessageAdapter.java
+++ b/src/main/java/de/thedevstack/conversationsplus/ui/adapter/MessageAdapter.java
@@ -1,16 +1,24 @@
package de.thedevstack.conversationsplus.ui.adapter;
+import android.content.ActivityNotFoundException;
import android.content.Intent;
import android.content.pm.PackageManager;
import android.content.pm.ResolveInfo;
+import android.content.res.Resources;
+import android.graphics.Bitmap;
import android.graphics.Typeface;
+import android.graphics.drawable.BitmapDrawable;
+import android.graphics.drawable.Drawable;
import android.net.Uri;
+import android.os.AsyncTask;
import android.text.Spannable;
import android.text.SpannableString;
import android.text.Spanned;
import android.text.style.ForegroundColorSpan;
import android.text.style.RelativeSizeSpan;
import android.text.style.StyleSpan;
+import android.util.DisplayMetrics;
+import android.util.Patterns;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.View.OnLongClickListener;
@@ -22,32 +30,38 @@ import android.widget.LinearLayout;
import android.widget.TextView;
import android.widget.Toast;
+import java.lang.ref.WeakReference;
import java.util.List;
+import java.util.concurrent.RejectedExecutionException;
+import java.util.regex.Matcher;
import de.thedevstack.conversationsplus.ConversationsPlusPreferences;
import de.thedevstack.conversationsplus.R;
+import de.thedevstack.conversationsplus.crypto.axolotl.XmppAxolotlSession;
import de.thedevstack.conversationsplus.entities.Account;
-import de.thedevstack.conversationsplus.entities.Contact;
import de.thedevstack.conversationsplus.entities.Conversation;
-import de.thedevstack.conversationsplus.entities.Transferable;
import de.thedevstack.conversationsplus.entities.DownloadableFile;
import de.thedevstack.conversationsplus.entities.Message;
import de.thedevstack.conversationsplus.entities.Message.FileParams;
+import de.thedevstack.conversationsplus.entities.Transferable;
import de.thedevstack.conversationsplus.persistance.FileBackend;
import de.thedevstack.conversationsplus.services.AvatarService;
import de.thedevstack.conversationsplus.ui.ConversationActivity;
+import de.thedevstack.conversationsplus.utils.CryptoHelper;
import de.thedevstack.conversationsplus.utils.GeoHelper;
import de.thedevstack.conversationsplus.utils.UIHelper;
-import github.ankushsachdeva.emojicon.EmojiconTextView;
public class MessageAdapter extends ArrayAdapter<Message> {
private static final int SENT = 0;
private static final int RECEIVED = 1;
private static final int STATUS = 2;
+ private static final int NULL = 3;
private ConversationActivity activity;
+ private DisplayMetrics metrics;
+
private OnContactPictureClicked mOnContactPictureClickedListener;
private OnContactPictureLongClicked mOnContactPictureLongClickedListener;
@@ -63,6 +77,7 @@ public class MessageAdapter extends ArrayAdapter<Message> {
public MessageAdapter(ConversationActivity activity, List<Message> messages) {
super(activity, 0, messages);
this.activity = activity;
+ metrics = getContext().getResources().getDisplayMetrics();
}
public void setOnContactPictureClicked(OnContactPictureClicked listener) {
@@ -79,24 +94,37 @@ public class MessageAdapter extends ArrayAdapter<Message> {
return 3;
}
- @Override
- public int getItemViewType(int position) {
- if (getItem(position).getType() == Message.TYPE_STATUS) {
+ public int getItemViewType(Message message) {
+ if (message.getType() == Message.TYPE_STATUS) {
return STATUS;
- } else if (getItem(position).getStatus() <= Message.STATUS_RECEIVED) {
+ } else if (message.getStatus() <= Message.STATUS_RECEIVED) {
return RECEIVED;
+ }
+
+ return SENT;
+ }
+
+ @Override
+ public int getItemViewType(int position) {
+ return this.getItemViewType(getItem(position));
+ }
+
+ private int getMessageTextColor(boolean onDark, boolean primary) {
+ if (onDark) {
+ return activity.getResources().getColor(primary ? R.color.white : R.color.white70);
} else {
- return SENT;
+ return activity.getResources().getColor(primary ? R.color.black87 : R.color.black54);
}
}
- private void displayStatus(ViewHolder viewHolder, Message message) {
+ private void displayStatus(ViewHolder viewHolder, Message message, int type, boolean darkBackground) {
String filesize = null;
String info = null;
boolean error = false;
if (viewHolder.indicatorReceived != null) {
viewHolder.indicatorReceived.setVisibility(View.GONE);
}
+
boolean multiReceived = message.getConversation().getMode() == Conversation.MODE_MULTI
&& message.getMergedStatus() <= Message.STATUS_RECEIVED;
if (message.getType() == Message.TYPE_IMAGE || message.getType() == Message.TYPE_FILE || message.getTransferable() != null) {
@@ -145,15 +173,40 @@ public class MessageAdapter extends ArrayAdapter<Message> {
}
break;
}
- if (error) {
+ if (error && type == SENT) {
viewHolder.time.setTextColor(activity.getWarningTextColor());
} else {
- viewHolder.time.setTextColor(activity.getSecondaryTextColor());
+ viewHolder.time.setTextColor(this.getMessageTextColor(darkBackground,false));
}
if (message.getEncryption() == Message.ENCRYPTION_NONE) {
viewHolder.indicator.setVisibility(View.GONE);
} else {
+ viewHolder.indicator.setImageResource(darkBackground ? R.drawable.ic_lock_white_18dp : R.drawable.ic_lock_black_18dp);
viewHolder.indicator.setVisibility(View.VISIBLE);
+ if (message.getEncryption() == Message.ENCRYPTION_AXOLOTL) {
+ XmppAxolotlSession.Trust trust = message.getConversation()
+ .getAccount().getAxolotlService().getFingerprintTrust(
+ message.getAxolotlFingerprint());
+
+ if(trust == null || (!trust.trusted() && !trust.trustedInactive())) {
+ viewHolder.indicator.setColorFilter(activity.getWarningTextColor());
+ viewHolder.indicator.setAlpha(1.0f);
+ } else {
+ viewHolder.indicator.clearColorFilter();
+ if (darkBackground) {
+ viewHolder.indicator.setAlpha(0.7f);
+ } else {
+ viewHolder.indicator.setAlpha(0.57f);
+ }
+ }
+ } else {
+ viewHolder.indicator.clearColorFilter();
+ if (darkBackground) {
+ viewHolder.indicator.setAlpha(0.7f);
+ } else {
+ viewHolder.indicator.setAlpha(0.57f);
+ }
+ }
}
String formatedTime = UIHelper.readableTimeDifferenceFull(getContext(),
@@ -185,45 +238,32 @@ public class MessageAdapter extends ArrayAdapter<Message> {
}
}
- private void displayInfoMessage(ViewHolder viewHolder, String text) {
+ private void displayInfoMessage(ViewHolder viewHolder, String text, boolean darkBackground) {
if (viewHolder.download_button != null) {
viewHolder.download_button.setVisibility(View.GONE);
}
viewHolder.image.setVisibility(View.GONE);
viewHolder.messageBody.setVisibility(View.VISIBLE);
viewHolder.messageBody.setText(text);
- viewHolder.messageBody.setTextColor(activity.getSecondaryTextColor());
+ viewHolder.messageBody.setTextColor(getMessageTextColor(darkBackground, false));
viewHolder.messageBody.setTypeface(null, Typeface.ITALIC);
viewHolder.messageBody.setTextIsSelectable(false);
}
- private void displayDecryptionFailed(ViewHolder viewHolder) {
+ private void displayDecryptionFailed(ViewHolder viewHolder, boolean darkBackground) {
if (viewHolder.download_button != null) {
viewHolder.download_button.setVisibility(View.GONE);
}
viewHolder.image.setVisibility(View.GONE);
viewHolder.messageBody.setVisibility(View.VISIBLE);
viewHolder.messageBody.setText(getContext().getString(
- R.string.decryption_failed));
- viewHolder.messageBody.setTextColor(activity.getWarningTextColor());
+ R.string.decryption_failed));
+ viewHolder.messageBody.setTextColor(getMessageTextColor(darkBackground, false));
viewHolder.messageBody.setTypeface(null, Typeface.NORMAL);
viewHolder.messageBody.setTextIsSelectable(false);
}
- private void displayHeartMessage(final ViewHolder viewHolder, final String body) {
- if (viewHolder.download_button != null) {
- viewHolder.download_button.setVisibility(View.GONE);
- }
- viewHolder.image.setVisibility(View.GONE);
- viewHolder.messageBody.setVisibility(View.VISIBLE);
- viewHolder.messageBody.setIncludeFontPadding(false);
- Spannable span = new SpannableString(body);
- span.setSpan(new RelativeSizeSpan(4.0f), 0, body.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
- span.setSpan(new ForegroundColorSpan(activity.getWarningTextColor()), 0, body.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
- viewHolder.messageBody.setText(span);
- }
-
- private void displayTextMessage(final ViewHolder viewHolder, final Message message) {
+ private void displayTextMessage(final ViewHolder viewHolder, final Message message, boolean darkBackground) {
if (viewHolder.download_button != null) {
viewHolder.download_button.setVisibility(View.GONE);
}
@@ -232,7 +272,12 @@ public class MessageAdapter extends ArrayAdapter<Message> {
viewHolder.messageBody.setIncludeFontPadding(true);
if (message.getBody() != null) {
final String nick = UIHelper.getMessageDisplayName(message);
- final String body = message.getMergedBody().replaceAll("^" + Message.ME_COMMAND,nick + " ");
+ String body;
+ try {
+ body = message.getMergedBody().replaceAll("^" + Message.ME_COMMAND, nick + " ");
+ } catch (ArrayIndexOutOfBoundsException e) {
+ body = message.getMergedBody();
+ }
final SpannableString formattedBody = new SpannableString(body);
int i = body.indexOf(Message.MERGE_SEPARATOR);
while(i >= 0) {
@@ -241,14 +286,13 @@ public class MessageAdapter extends ArrayAdapter<Message> {
i = body.indexOf(Message.MERGE_SEPARATOR,end);
}
if (message.getType() != Message.TYPE_PRIVATE) {
-
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(formattedBody);
+ viewHolder.messageBody.setText(formattedBody);
}
} else {
String privateMarker;
@@ -266,8 +310,7 @@ public class MessageAdapter extends ArrayAdapter<Message> {
}
final Spannable span = new SpannableString(privateMarker + " "
+ formattedBody);
- span.setSpan(new ForegroundColorSpan(activity
- .getSecondaryTextColor()), 0, privateMarker
+ span.setSpan(new ForegroundColorSpan(getMessageTextColor(darkBackground,false)), 0, privateMarker
.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
span.setSpan(new StyleSpan(Typeface.BOLD), 0,
privateMarker.length(),
@@ -279,12 +322,21 @@ public class MessageAdapter extends ArrayAdapter<Message> {
}
viewHolder.messageBody.setText(span);
}
+ int urlCount = 0;
+ Matcher matcher = Patterns.WEB_URL.matcher(body);
+ while (matcher.find()) {
+ urlCount++;
+ }
+ viewHolder.messageBody.setTextIsSelectable(urlCount <= 1);
} else {
viewHolder.messageBody.setText("");
+ viewHolder.messageBody.setTextIsSelectable(false);
}
- viewHolder.messageBody.setTextColor(activity.getPrimaryTextColor());
+ viewHolder.messageBody.setTextColor(this.getMessageTextColor(darkBackground, true));
+ viewHolder.messageBody.setLinkTextColor(this.getMessageTextColor(darkBackground, true));
+ viewHolder.messageBody.setHighlightColor(activity.getResources().getColor(darkBackground ? R.color.grey800 : R.color.grey500));
viewHolder.messageBody.setTypeface(null, Typeface.NORMAL);
- viewHolder.messageBody.setTextIsSelectable(true);
+ viewHolder.messageBody.setOnLongClickListener(openContextMenu);
}
private void displayDownloadableMessage(ViewHolder viewHolder,
@@ -295,11 +347,11 @@ public class MessageAdapter extends ArrayAdapter<Message> {
viewHolder.download_button.setText(text);
viewHolder.download_button.setOnClickListener(new OnClickListener() {
- @Override
- public void onClick(View v) {
- startDownloadable(message);
- }
- });
+ @Override
+ public void onClick(View v) {
+ activity.startDownloadable(message);
+ }
+ });
viewHolder.download_button.setOnLongClickListener(openContextMenu);
}
@@ -352,25 +404,25 @@ public class MessageAdapter extends ArrayAdapter<Message> {
scalledW = (int) target;
scalledH = (int) (params.height / ((double) params.width / target));
}
- viewHolder.image.setLayoutParams(new LinearLayout.LayoutParams(
- scalledW, scalledH));*/
+ LinearLayout.LayoutParams layoutParams = new LinearLayout.LayoutParams(scalledW, scalledH);
+ layoutParams.setMargins(0, (int) (metrics.density * 4), 0, (int) (metrics.density * 4));
+ viewHolder.image.setLayoutParams(layoutParams);*/
//TODO Why should this be calculated by hand???
activity.loadBitmap(message, viewHolder.image, true);
- viewHolder.image.setOnClickListener(new OnClickListener() {
-
- @Override
- public void onClick(View v) {
- Intent intent = new Intent(Intent.ACTION_VIEW);
- intent.setDataAndType(FileBackend.getJingleFileUri(message), "image/*");
- getContext().startActivity(intent);
- }
- });
+ viewHolder.image.setOnClickListener(new OnClickListener() {
+
+ @Override
+ public void onClick(View v) {
+ openDownloadable(message);
+ }
+ });
viewHolder.image.setOnLongClickListener(openContextMenu);
}
@Override
public View getView(int position, View view, ViewGroup parent) {
final Message message = getItem(position);
+ final boolean isInValidSession = message.isValidInSession();
final Conversation conversation = message.getConversation();
final Account account = conversation.getAccount();
final int type = getItemViewType(position);
@@ -391,7 +443,7 @@ public class MessageAdapter extends ArrayAdapter<Message> {
.findViewById(R.id.security_indicator);
viewHolder.image = (ImageView) view
.findViewById(R.id.message_image);
- viewHolder.messageBody = (EmojiconTextView) view
+ viewHolder.messageBody = (TextView) view
.findViewById(R.id.message_body);
viewHolder.time = (TextView) view
.findViewById(R.id.message_time);
@@ -411,12 +463,13 @@ public class MessageAdapter extends ArrayAdapter<Message> {
.findViewById(R.id.security_indicator);
viewHolder.image = (ImageView) view
.findViewById(R.id.message_image);
- viewHolder.messageBody = (EmojiconTextView) view
+ viewHolder.messageBody = (TextView) view
.findViewById(R.id.message_body);
viewHolder.time = (TextView) view
.findViewById(R.id.message_time);
viewHolder.indicatorReceived = (ImageView) view
.findViewById(R.id.indicator_received);
+ viewHolder.encryption = (TextView) view.findViewById(R.id.message_encryption);
break;
case STATUS:
view = activity.getLayoutInflater().inflate(R.layout.message_status, parent, false);
@@ -435,25 +488,20 @@ public class MessageAdapter extends ArrayAdapter<Message> {
}
}
+ boolean darkBackground = (type == RECEIVED && !isInValidSession);
+
if (type == STATUS) {
+ viewHolder.status_message.setVisibility(View.VISIBLE);
+ viewHolder.contact_picture.setVisibility(View.VISIBLE);
if (conversation.getMode() == Conversation.MODE_SINGLE) {
- viewHolder.contact_picture.setImageBitmap(AvatarService.getInstance().get(conversation.getContact(),
- activity.getPixel(32)));
+ viewHolder.contact_picture.setImageBitmap(AvatarService.getInstance().get(conversation.getContact(),
+ activity.getPixel(32)));
viewHolder.contact_picture.setAlpha(0.5f);
- viewHolder.status_message.setText(message.getBody());
}
+ viewHolder.status_message.setText(message.getBody());
return view;
- } else if (type == RECEIVED) {
- Contact contact = message.getContact();
- if (contact != null) {
- viewHolder.contact_picture.setImageBitmap(AvatarService.getInstance().get(contact, activity.getPixel(48)));
- } else if (conversation.getMode() == Conversation.MODE_MULTI) {
- viewHolder.contact_picture.setImageBitmap(AvatarService.getInstance().get(
- UIHelper.getMessageDisplayName(message),
- activity.getPixel(48)));
- }
- } else if (type == SENT) {
- viewHolder.contact_picture.setImageBitmap(AvatarService.getInstance().get(account, activity.getPixel(48)));
+ } else {
+ loadAvatar(message, viewHolder.contact_picture);
}
viewHolder.contact_picture
@@ -463,7 +511,7 @@ public class MessageAdapter extends ArrayAdapter<Message> {
public void onClick(View v) {
if (MessageAdapter.this.mOnContactPictureClickedListener != null) {
MessageAdapter.this.mOnContactPictureClickedListener
- .onContactPictureClicked(message);
+ .onContactPictureClicked(message);
}
}
@@ -475,7 +523,7 @@ public class MessageAdapter extends ArrayAdapter<Message> {
public boolean onLongClick(View v) {
if (MessageAdapter.this.mOnContactPictureLongClickedListener != null) {
MessageAdapter.this.mOnContactPictureLongClickedListener
- .onContactPictureLongClicked(message);
+ .onContactPictureLongClicked(message);
return true;
} else {
return false;
@@ -490,7 +538,7 @@ public class MessageAdapter extends ArrayAdapter<Message> {
} else if (transferable.getStatus() == Transferable.STATUS_OFFER_CHECK_FILESIZE) {
displayDownloadableMessage(viewHolder, message, activity.getString(R.string.check_x_filesize, UIHelper.getFileDescriptionString(activity, message)));
} else {
- displayInfoMessage(viewHolder, UIHelper.getMessagePreview(activity, message).first);
+ displayInfoMessage(viewHolder, UIHelper.getMessagePreview(activity, message).first,darkBackground);
}
} else if (message.getType() == Message.TYPE_IMAGE && message.getEncryption() != Message.ENCRYPTION_PGP && message.getEncryption() != Message.ENCRYPTION_DECRYPTION_FAILED) {
displayImageMessage(viewHolder, message);
@@ -502,10 +550,13 @@ public class MessageAdapter extends ArrayAdapter<Message> {
}
} else if (message.getEncryption() == Message.ENCRYPTION_PGP) {
if (activity.hasPgp()) {
- displayInfoMessage(viewHolder,activity.getString(R.string.encrypted_message));
+ if (account.getPgpDecryptionService().isRunning()) {
+ displayInfoMessage(viewHolder, activity.getString(R.string.message_decrypting), darkBackground);
+ } else {
+ displayInfoMessage(viewHolder, activity.getString(R.string.pgp_message), darkBackground);
+ }
} else {
- displayInfoMessage(viewHolder,
- activity.getString(R.string.install_openkeychain));
+ displayInfoMessage(viewHolder,activity.getString(R.string.install_openkeychain),darkBackground);
if (viewHolder != null) {
viewHolder.message_box
.setOnClickListener(new OnClickListener() {
@@ -518,32 +569,30 @@ public class MessageAdapter extends ArrayAdapter<Message> {
}
}
} else if (message.getEncryption() == Message.ENCRYPTION_DECRYPTION_FAILED) {
- displayDecryptionFailed(viewHolder);
+ displayDecryptionFailed(viewHolder,darkBackground);
} else {
if (GeoHelper.isGeoUri(message.getBody())) {
displayLocationMessage(viewHolder,message);
} else if (message.treatAsDownloadable() == Message.Decision.MUST) {
displayDownloadableMessage(viewHolder, message, activity.getString(R.string.check_x_filesize, UIHelper.getFileDescriptionString(activity, message)));
} else {
- displayTextMessage(viewHolder, message);
+ displayTextMessage(viewHolder, message, darkBackground);
}
}
- displayStatus(viewHolder, message);
-
- return view;
- }
-
- public void startDownloadable(Message message) {
- Transferable transferable = message.getTransferable();
- if (transferable != null) {
- if (!transferable.start()) {
- Toast.makeText(activity, R.string.not_connected_try_again,
- Toast.LENGTH_SHORT).show();
+ if (type == RECEIVED) {
+ if(isInValidSession) {
+ viewHolder.encryption.setVisibility(View.GONE);
+ } else {
+ viewHolder.message_box.setBackgroundResource(R.drawable.message_bubble_received_warning);
+ viewHolder.encryption.setVisibility(View.VISIBLE);
+ viewHolder.encryption.setText(CryptoHelper.encryptionTypeToText(message.getEncryption()));
}
- } else if (message.treatAsDownloadable() != Message.Decision.NEVER) {
- activity.xmppConnectionService.getHttpConnectionManager().createNewDownloadConnection(message);
}
+
+ displayStatus(viewHolder, message, type, darkBackground);
+
+ return view;
}
public void openDownloadable(Message message) {
@@ -553,14 +602,23 @@ public class MessageAdapter extends ArrayAdapter<Message> {
return;
}
Intent openIntent = new Intent(Intent.ACTION_VIEW);
- openIntent.setDataAndType(Uri.fromFile(file), file.getMimeType());
+ String mime = file.getMimeType();
+ if (mime == null) {
+ mime = "*/*";
+ }
+ openIntent.setDataAndType(Uri.fromFile(file), mime);
PackageManager manager = activity.getPackageManager();
List<ResolveInfo> infos = manager.queryIntentActivities(openIntent, 0);
- if (infos.size() > 0) {
+ if (infos.size() == 0) {
+ openIntent.setDataAndType(Uri.fromFile(file),"*/*");
+ }
+ try {
getContext().startActivity(openIntent);
- } else {
- Toast.makeText(activity,R.string.no_application_found_to_open_file,Toast.LENGTH_SHORT).show();
+ return;
+ } catch (ActivityNotFoundException e) {
+ //ignored
}
+ Toast.makeText(activity,R.string.no_application_found_to_open_file,Toast.LENGTH_SHORT).show();
}
public void showLocation(Message message) {
@@ -574,11 +632,11 @@ public class MessageAdapter extends ArrayAdapter<Message> {
}
public interface OnContactPictureClicked {
- public void onContactPictureClicked(Message message);
+ void onContactPictureClicked(Message message);
}
public interface OnContactPictureLongClicked {
- public void onContactPictureLongClicked(Message message);
+ void onContactPictureLongClicked(Message message);
}
private static class ViewHolder {
@@ -589,8 +647,92 @@ public class MessageAdapter extends ArrayAdapter<Message> {
protected ImageView indicator;
protected ImageView indicatorReceived;
protected TextView time;
- protected EmojiconTextView messageBody;
+ protected TextView messageBody;
protected ImageView contact_picture;
protected TextView status_message;
+ protected TextView encryption;
+ }
+
+ class BitmapWorkerTask extends AsyncTask<Message, Void, Bitmap> {
+ private final WeakReference<ImageView> imageViewReference;
+ private Message message = null;
+
+ public BitmapWorkerTask(ImageView imageView) {
+ imageViewReference = new WeakReference<>(imageView);
+ }
+
+ @Override
+ protected Bitmap doInBackground(Message... params) {
+ return AvatarService.getInstance().get(params[0], activity.getPixel(48), isCancelled());
+ }
+
+ @Override
+ protected void onPostExecute(Bitmap bitmap) {
+ if (bitmap != null) {
+ final ImageView imageView = imageViewReference.get();
+ if (imageView != null) {
+ imageView.setImageBitmap(bitmap);
+ imageView.setBackgroundColor(0x00000000);
+ }
+ }
+ }
+ }
+
+ public void loadAvatar(Message message, ImageView imageView) {
+ if (cancelPotentialWork(message, imageView)) {
+ final Bitmap bm = AvatarService.getInstance().get(message, activity.getPixel(48), true);
+ if (bm != null) {
+ imageView.setImageBitmap(bm);
+ imageView.setBackgroundColor(0x00000000);
+ } else {
+ imageView.setBackgroundColor(UIHelper.getColorForName(UIHelper.getMessageDisplayName(message)));
+ imageView.setImageDrawable(null);
+ final BitmapWorkerTask task = new BitmapWorkerTask(imageView);
+ final AsyncDrawable asyncDrawable = new AsyncDrawable(activity.getResources(), null, task);
+ imageView.setImageDrawable(asyncDrawable);
+ try {
+ task.execute(message);
+ } catch (final RejectedExecutionException ignored) {
+ }
+ }
+ }
+ }
+
+ public static boolean cancelPotentialWork(Message message, ImageView imageView) {
+ final BitmapWorkerTask bitmapWorkerTask = getBitmapWorkerTask(imageView);
+
+ if (bitmapWorkerTask != null) {
+ final Message oldMessage = bitmapWorkerTask.message;
+ if (oldMessage == null || message != oldMessage) {
+ bitmapWorkerTask.cancel(true);
+ } else {
+ return false;
+ }
+ }
+ return true;
+ }
+
+ private static BitmapWorkerTask getBitmapWorkerTask(ImageView imageView) {
+ if (imageView != null) {
+ final Drawable drawable = imageView.getDrawable();
+ if (drawable instanceof AsyncDrawable) {
+ final AsyncDrawable asyncDrawable = (AsyncDrawable) drawable;
+ return asyncDrawable.getBitmapWorkerTask();
+ }
+ }
+ return null;
+ }
+
+ static class AsyncDrawable extends BitmapDrawable {
+ private final WeakReference<BitmapWorkerTask> bitmapWorkerTaskReference;
+
+ public AsyncDrawable(Resources res, Bitmap bitmap, BitmapWorkerTask bitmapWorkerTask) {
+ super(res, bitmap);
+ bitmapWorkerTaskReference = new WeakReference<>(bitmapWorkerTask);
+ }
+
+ public BitmapWorkerTask getBitmapWorkerTask() {
+ return bitmapWorkerTaskReference.get();
+ }
}
}
diff --git a/src/main/java/de/thedevstack/conversationsplus/ui/adapter/PresencesArrayAdapter.java b/src/main/java/de/thedevstack/conversationsplus/ui/adapter/PresencesArrayAdapter.java
index 0b5cb897..2f8d12f2 100644
--- a/src/main/java/de/thedevstack/conversationsplus/ui/adapter/PresencesArrayAdapter.java
+++ b/src/main/java/de/thedevstack/conversationsplus/ui/adapter/PresencesArrayAdapter.java
@@ -6,7 +6,6 @@ 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.ArrayList;
@@ -45,10 +44,10 @@ public class PresencesArrayAdapter extends ArrayAdapter<Presence> {
private static Presence[] getPresenceArray(Presences presences) {
ArrayList<Presence> presenceArrayList = new ArrayList<>();
if (null != presences && null != presences.getPresences() && !presences.getPresences().isEmpty()) {
- for (Map.Entry<String, Integer> entry : presences.getPresences().entrySet()) {
+ for (Map.Entry<String, de.thedevstack.conversationsplus.entities.Presence> entry : presences.getPresences().entrySet()) {
Presence p = new Presence();
p.resource = entry.getKey();
- p.status = entry.getValue();
+ p.status = entry.getValue().getStatus();
presenceArrayList.add(p);
}
presenceArrayList.trimToSize();
@@ -59,5 +58,5 @@ public class PresencesArrayAdapter extends ArrayAdapter<Presence> {
class Presence {
String resource;
- int status;
+ de.thedevstack.conversationsplus.entities.Presence.Status status;
}
diff --git a/src/main/java/de/thedevstack/conversationsplus/ui/dialogs/UserDecisionDialog.java b/src/main/java/de/thedevstack/conversationsplus/ui/dialogs/UserDecisionDialog.java
index ad920934..72d9d904 100644
--- a/src/main/java/de/thedevstack/conversationsplus/ui/dialogs/UserDecisionDialog.java
+++ b/src/main/java/de/thedevstack/conversationsplus/ui/dialogs/UserDecisionDialog.java
@@ -6,9 +6,9 @@ import android.view.View;
import android.widget.CheckBox;
import android.widget.TextView;
-import de.thedevstack.conversationsplus.R;
import de.thedevstack.conversationsplus.enums.UserDecision;
import de.thedevstack.conversationsplus.ui.listeners.UserDecisionListener;
+import de.thedevstack.conversationsplus.R;
/**
* Created by tzur on 31.10.2015.
diff --git a/src/main/java/de/thedevstack/conversationsplus/ui/forms/FormBooleanFieldWrapper.java b/src/main/java/de/thedevstack/conversationsplus/ui/forms/FormBooleanFieldWrapper.java
new file mode 100644
index 00000000..04c3fe20
--- /dev/null
+++ b/src/main/java/de/thedevstack/conversationsplus/ui/forms/FormBooleanFieldWrapper.java
@@ -0,0 +1,80 @@
+package de.thedevstack.conversationsplus.ui.forms;
+
+import android.content.Context;
+import android.widget.CheckBox;
+import android.widget.CompoundButton;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import de.thedevstack.conversationsplus.R;
+import de.thedevstack.conversationsplus.xmpp.forms.Field;
+
+public class FormBooleanFieldWrapper extends FormFieldWrapper {
+
+ protected CheckBox checkBox;
+
+ protected FormBooleanFieldWrapper(Context context, Field field) {
+ super(context, field);
+ checkBox = (CheckBox) view.findViewById(R.id.field);
+ checkBox.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
+ @Override
+ public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
+ checkBox.setError(null);
+ invokeOnFormFieldValuesEdited();
+ }
+ });
+ }
+
+ @Override
+ protected void setLabel(String label, boolean required) {
+ CheckBox checkBox = (CheckBox) view.findViewById(R.id.field);
+ checkBox.setText(createSpannableLabelString(label, required));
+ }
+
+ @Override
+ public List<String> getValues() {
+ List<String> values = new ArrayList<>();
+ values.add(Boolean.toString(checkBox.isChecked()));
+ return values;
+ }
+
+ @Override
+ protected void setValues(List<String> values) {
+ if (values.size() == 0) {
+ checkBox.setChecked(false);
+ } else {
+ checkBox.setChecked(Boolean.parseBoolean(values.get(0)));
+ }
+ }
+
+ @Override
+ public boolean validates() {
+ if (checkBox.isChecked() || !field.isRequired()) {
+ return true;
+ } else {
+ checkBox.setError(context.getString(R.string.this_field_is_required));
+ checkBox.requestFocus();
+ return false;
+ }
+ }
+
+ @Override
+ public boolean edited() {
+ if (field.getValues().size() == 0) {
+ return checkBox.isChecked();
+ } else {
+ return super.edited();
+ }
+ }
+
+ @Override
+ protected int getLayoutResource() {
+ return R.layout.form_boolean;
+ }
+
+ @Override
+ void setReadOnly(boolean readOnly) {
+ checkBox.setEnabled(!readOnly);
+ }
+}
diff --git a/src/main/java/de/thedevstack/conversationsplus/ui/forms/FormFieldFactory.java b/src/main/java/de/thedevstack/conversationsplus/ui/forms/FormFieldFactory.java
new file mode 100644
index 00000000..e726b6cc
--- /dev/null
+++ b/src/main/java/de/thedevstack/conversationsplus/ui/forms/FormFieldFactory.java
@@ -0,0 +1,30 @@
+package de.thedevstack.conversationsplus.ui.forms;
+
+import android.content.Context;
+
+import java.util.Hashtable;
+
+import de.thedevstack.conversationsplus.xmpp.forms.Field;
+
+
+
+public class FormFieldFactory {
+
+ private static final Hashtable<String, Class> typeTable = new Hashtable<>();
+
+ static {
+ typeTable.put("text-single", FormTextFieldWrapper.class);
+ typeTable.put("text-multi", FormTextFieldWrapper.class);
+ typeTable.put("text-private", FormTextFieldWrapper.class);
+ typeTable.put("jid-single", FormJidSingleFieldWrapper.class);
+ typeTable.put("boolean", FormBooleanFieldWrapper.class);
+ }
+
+ protected static FormFieldWrapper createFromField(Context context, Field field) {
+ Class clazz = typeTable.get(field.getType());
+ if (clazz == null) {
+ clazz = FormTextFieldWrapper.class;
+ }
+ return FormFieldWrapper.createFromField(clazz, context, field);
+ }
+}
diff --git a/src/main/java/de/thedevstack/conversationsplus/ui/forms/FormFieldWrapper.java b/src/main/java/de/thedevstack/conversationsplus/ui/forms/FormFieldWrapper.java
new file mode 100644
index 00000000..c82421a2
--- /dev/null
+++ b/src/main/java/de/thedevstack/conversationsplus/ui/forms/FormFieldWrapper.java
@@ -0,0 +1,93 @@
+package de.thedevstack.conversationsplus.ui.forms;
+
+import android.content.Context;
+import android.text.SpannableString;
+import android.text.style.ForegroundColorSpan;
+import android.text.style.StyleSpan;
+import android.view.LayoutInflater;
+import android.view.View;
+
+import java.util.List;
+
+import de.thedevstack.conversationsplus.R;
+import de.thedevstack.conversationsplus.xmpp.forms.Field;
+
+public abstract class FormFieldWrapper {
+
+ protected final Context context;
+ protected final Field field;
+ protected final View view;
+ protected OnFormFieldValuesEdited onFormFieldValuesEditedListener;
+
+ protected FormFieldWrapper(Context context, Field field) {
+ this.context = context;
+ this.field = field;
+ LayoutInflater inflater = (LayoutInflater)context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
+ this.view = inflater.inflate(getLayoutResource(), null);
+ String label = field.getLabel();
+ if (label == null) {
+ label = field.getFieldName();
+ }
+ setLabel(label, field.isRequired());
+ }
+
+ public final void submit() {
+ this.field.setValues(getValues());
+ }
+
+ public final View getView() {
+ return view;
+ }
+
+ protected abstract void setLabel(String label, boolean required);
+
+ abstract List<String> getValues();
+
+ protected abstract void setValues(List<String> values);
+
+ abstract boolean validates();
+
+ abstract protected int getLayoutResource();
+
+ abstract void setReadOnly(boolean readOnly);
+
+ protected SpannableString createSpannableLabelString(String label, boolean required) {
+ SpannableString spannableString = new SpannableString(label + (required ? " *" : ""));
+ if (required) {
+ int start = label.length();
+ int end = label.length() + 2;
+ spannableString.setSpan(new StyleSpan(android.graphics.Typeface.BOLD), start, end, 0);
+ spannableString.setSpan(new ForegroundColorSpan(context.getResources().getColor(R.color.accent)), start, end, 0);
+ }
+ return spannableString;
+ }
+
+ protected void invokeOnFormFieldValuesEdited() {
+ if (this.onFormFieldValuesEditedListener != null) {
+ this.onFormFieldValuesEditedListener.onFormFieldValuesEdited();
+ }
+ }
+
+ public boolean edited() {
+ return !field.getValues().equals(getValues());
+ }
+
+ public void setOnFormFieldValuesEditedListener(OnFormFieldValuesEdited listener) {
+ this.onFormFieldValuesEditedListener = listener;
+ }
+
+ protected static <F extends FormFieldWrapper> FormFieldWrapper createFromField(Class<F> c, Context context, Field field) {
+ try {
+ F fieldWrapper = c.getDeclaredConstructor(Context.class, Field.class).newInstance(context,field);
+ fieldWrapper.setValues(field.getValues());
+ return fieldWrapper;
+ } catch (Exception e) {
+ e.printStackTrace();
+ return null;
+ }
+ }
+
+ public interface OnFormFieldValuesEdited {
+ void onFormFieldValuesEdited();
+ }
+}
diff --git a/src/main/java/de/thedevstack/conversationsplus/ui/forms/FormJidSingleFieldWrapper.java b/src/main/java/de/thedevstack/conversationsplus/ui/forms/FormJidSingleFieldWrapper.java
new file mode 100644
index 00000000..c86653bf
--- /dev/null
+++ b/src/main/java/de/thedevstack/conversationsplus/ui/forms/FormJidSingleFieldWrapper.java
@@ -0,0 +1,44 @@
+package de.thedevstack.conversationsplus.ui.forms;
+
+import android.content.Context;
+import android.text.InputType;
+
+import java.util.List;
+
+import de.thedevstack.conversationsplus.R;
+import de.thedevstack.conversationsplus.xmpp.forms.Field;
+import de.thedevstack.conversationsplus.xmpp.jid.InvalidJidException;
+import de.thedevstack.conversationsplus.xmpp.jid.Jid;
+
+public class FormJidSingleFieldWrapper extends FormTextFieldWrapper {
+
+ protected FormJidSingleFieldWrapper(Context context, Field field) {
+ super(context, field);
+ editText.setInputType(InputType.TYPE_TEXT_VARIATION_EMAIL_ADDRESS);
+ editText.setHint(R.string.account_settings_example_jabber_id);
+ }
+
+ @Override
+ public boolean validates() {
+ String value = getValue();
+ if (!value.isEmpty()) {
+ try {
+ Jid.fromString(value);
+ } catch (InvalidJidException e) {
+ editText.setError(context.getString(R.string.invalid_jid));
+ editText.requestFocus();
+ return false;
+ }
+ }
+ return super.validates();
+ }
+
+ @Override
+ protected void setValues(List<String> values) {
+ StringBuilder builder = new StringBuilder("");
+ for(String value : values) {
+ builder.append(value);
+ }
+ editText.setText(builder.toString());
+ }
+}
diff --git a/src/main/java/de/thedevstack/conversationsplus/ui/forms/FormTextFieldWrapper.java b/src/main/java/de/thedevstack/conversationsplus/ui/forms/FormTextFieldWrapper.java
new file mode 100644
index 00000000..f825809c
--- /dev/null
+++ b/src/main/java/de/thedevstack/conversationsplus/ui/forms/FormTextFieldWrapper.java
@@ -0,0 +1,97 @@
+package de.thedevstack.conversationsplus.ui.forms;
+
+import android.content.Context;
+import android.text.Editable;
+import android.text.InputType;
+import android.text.TextWatcher;
+import android.widget.EditText;
+import android.widget.TextView;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import de.thedevstack.conversationsplus.R;
+import de.thedevstack.conversationsplus.xmpp.forms.Field;
+
+public class FormTextFieldWrapper extends FormFieldWrapper {
+
+ protected EditText editText;
+
+ protected FormTextFieldWrapper(Context context, Field field) {
+ super(context, field);
+ editText = (EditText) view.findViewById(R.id.field);
+ editText.setSingleLine(!"text-multi".equals(field.getType()));
+ if ("text-private".equals(field.getType())) {
+ editText.setInputType(InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_VARIATION_PASSWORD);
+ }
+ editText.addTextChangedListener(new TextWatcher() {
+ @Override
+ public void beforeTextChanged(CharSequence s, int start, int count, int after) {
+ }
+
+ @Override
+ public void onTextChanged(CharSequence s, int start, int before, int count) {
+ editText.setError(null);
+ invokeOnFormFieldValuesEdited();
+ }
+
+ @Override
+ public void afterTextChanged(Editable s) {
+ }
+ });
+ }
+
+ @Override
+ protected void setLabel(String label, boolean required) {
+ TextView textView = (TextView) view.findViewById(R.id.label);
+ textView.setText(createSpannableLabelString(label, required));
+ }
+
+ protected String getValue() {
+ return editText.getText().toString();
+ }
+
+ @Override
+ public List<String> getValues() {
+ List<String> values = new ArrayList<>();
+ for (String line : getValue().split("\\n")) {
+ if (line.length() > 0) {
+ values.add(line);
+ }
+ }
+ return values;
+ }
+
+ @Override
+ protected void setValues(List<String> values) {
+ StringBuilder builder = new StringBuilder("");
+ for(int i = 0; i < values.size(); ++i) {
+ builder.append(values.get(i));
+ if (i < values.size() - 1 && "text-multi".equals(field.getType())) {
+ builder.append("\n");
+ }
+ }
+ editText.setText(builder.toString());
+ }
+
+ @Override
+ public boolean validates() {
+ if (getValue().trim().length() > 0 || !field.isRequired()) {
+ return true;
+ } else {
+ editText.setError(context.getString(R.string.this_field_is_required));
+ editText.requestFocus();
+ return false;
+ }
+ }
+
+ @Override
+ protected int getLayoutResource() {
+ return R.layout.form_text;
+ }
+
+ @Override
+ void setReadOnly(boolean readOnly) {
+ editText.setEnabled(!readOnly);
+ }
+}
diff --git a/src/main/java/de/thedevstack/conversationsplus/ui/forms/FormWrapper.java b/src/main/java/de/thedevstack/conversationsplus/ui/forms/FormWrapper.java
new file mode 100644
index 00000000..8ff9efae
--- /dev/null
+++ b/src/main/java/de/thedevstack/conversationsplus/ui/forms/FormWrapper.java
@@ -0,0 +1,72 @@
+package de.thedevstack.conversationsplus.ui.forms;
+
+import android.content.Context;
+import android.widget.LinearLayout;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import de.thedevstack.conversationsplus.xmpp.forms.Data;
+import de.thedevstack.conversationsplus.xmpp.forms.Field;
+
+public class FormWrapper {
+
+ private final LinearLayout layout;
+
+ private final Data form;
+
+ private final List<FormFieldWrapper> fieldWrappers = new ArrayList<>();
+
+ private FormWrapper(Context context, LinearLayout linearLayout, Data form) {
+ this.form = form;
+ this.layout = linearLayout;
+ this.layout.removeAllViews();
+ for(Field field : form.getFields()) {
+ FormFieldWrapper fieldWrapper = FormFieldFactory.createFromField(context,field);
+ if (fieldWrapper != null) {
+ layout.addView(fieldWrapper.getView());
+ fieldWrappers.add(fieldWrapper);
+ }
+ }
+ }
+
+ public Data submit() {
+ for(FormFieldWrapper fieldWrapper : fieldWrappers) {
+ fieldWrapper.submit();
+ }
+ this.form.submit();
+ return this.form;
+ }
+
+ public boolean validates() {
+ boolean validates = true;
+ for(FormFieldWrapper fieldWrapper : fieldWrappers) {
+ validates &= fieldWrapper.validates();
+ }
+ return validates;
+ }
+
+ public void setOnFormFieldValuesEditedListener(FormFieldWrapper.OnFormFieldValuesEdited listener) {
+ for(FormFieldWrapper fieldWrapper : fieldWrappers) {
+ fieldWrapper.setOnFormFieldValuesEditedListener(listener);
+ }
+ }
+
+ public void setReadOnly(boolean b) {
+ for(FormFieldWrapper fieldWrapper : fieldWrappers) {
+ fieldWrapper.setReadOnly(b);
+ }
+ }
+
+ public boolean edited() {
+ boolean edited = false;
+ for(FormFieldWrapper fieldWrapper : fieldWrappers) {
+ edited |= fieldWrapper.edited();
+ }
+ return edited;
+ }
+
+ public static FormWrapper createInLayout(Context context, LinearLayout layout, Data form) {
+ return new FormWrapper(context, layout, form);
+ }
+}
diff --git a/src/main/java/de/thedevstack/conversationsplus/ui/listeners/ConversationSwipeRefreshListener.java b/src/main/java/de/thedevstack/conversationsplus/ui/listeners/ConversationSwipeRefreshListener.java
index 30b7bf73..5076da28 100644
--- a/src/main/java/de/thedevstack/conversationsplus/ui/listeners/ConversationSwipeRefreshListener.java
+++ b/src/main/java/de/thedevstack/conversationsplus/ui/listeners/ConversationSwipeRefreshListener.java
@@ -8,11 +8,11 @@ import com.orangegangsters.github.swipyrefreshlayout.library.SwipyRefreshLayoutD
import java.util.List;
import de.thedevstack.android.logcat.Logging;
+import de.thedevstack.conversationsplus.Config;
import de.thedevstack.conversationsplus.R;
import de.thedevstack.conversationsplus.entities.Conversation;
-import de.thedevstack.conversationsplus.services.MessageArchiveService;
-import de.thedevstack.conversationsplus.Config;
import de.thedevstack.conversationsplus.entities.Message;
+import de.thedevstack.conversationsplus.services.MessageArchiveService;
import de.thedevstack.conversationsplus.ui.ConversationActivity;
import de.thedevstack.conversationsplus.ui.ConversationFragment;
import de.thedevstack.conversationsplus.ui.adapter.MessageAdapter;
diff --git a/src/main/java/de/thedevstack/conversationsplus/ui/listeners/ResizePictureUserDecisionListener.java b/src/main/java/de/thedevstack/conversationsplus/ui/listeners/ResizePictureUserDecisionListener.java
index a9c245ed..1b4c7802 100644
--- a/src/main/java/de/thedevstack/conversationsplus/ui/listeners/ResizePictureUserDecisionListener.java
+++ b/src/main/java/de/thedevstack/conversationsplus/ui/listeners/ResizePictureUserDecisionListener.java
@@ -13,19 +13,19 @@ import java.io.InputStream;
import de.thedevstack.android.logcat.Logging;
import de.thedevstack.conversationsplus.ConversationsPlusApplication;
import de.thedevstack.conversationsplus.ConversationsPlusPreferences;
+import de.thedevstack.conversationsplus.enums.UserDecision;
+import de.thedevstack.conversationsplus.exceptions.UiException;
+import de.thedevstack.conversationsplus.utils.FileHelper;
+import de.thedevstack.conversationsplus.utils.ImageUtil;
+import de.thedevstack.conversationsplus.utils.MessageUtil;
import de.thedevstack.conversationsplus.R;
import de.thedevstack.conversationsplus.entities.Conversation;
import de.thedevstack.conversationsplus.entities.DownloadableFile;
import de.thedevstack.conversationsplus.entities.Message;
-import de.thedevstack.conversationsplus.enums.UserDecision;
-import de.thedevstack.conversationsplus.exceptions.UiException;
import de.thedevstack.conversationsplus.persistance.FileBackend;
import de.thedevstack.conversationsplus.services.XmppConnectionService;
import de.thedevstack.conversationsplus.ui.UiCallback;
import de.thedevstack.conversationsplus.ui.XmppActivity;
-import de.thedevstack.conversationsplus.utils.FileHelper;
-import de.thedevstack.conversationsplus.utils.ImageUtil;
-import de.thedevstack.conversationsplus.utils.MessageUtil;
/**
* Created by tzur on 31.10.2015.
@@ -59,6 +59,7 @@ public class ResizePictureUserDecisionListener implements UserDecisionListener {
@Override
public void error(int error, Message message) {
hidePrepareFileToast();
+ //TODO Find another way to display an error dialog
ResizePictureUserDecisionListener.this.activity.displayErrorDialog(error);
}
@@ -96,10 +97,10 @@ public class ResizePictureUserDecisionListener implements UserDecisionListener {
this.showPrepareFileToast();
final Message message;
final boolean forceEncryption = ConversationsPlusPreferences.forceEncryption();
- if (conversation.getNextEncryption(forceEncryption) == Message.ENCRYPTION_PGP) {
+ if (conversation.getNextEncryption() == Message.ENCRYPTION_PGP) {
message = new Message(conversation, "", Message.ENCRYPTION_DECRYPTED);
} else {
- message = new Message(conversation, "", conversation.getNextEncryption(forceEncryption));
+ message = new Message(conversation, "", conversation.getNextEncryption());
}
message.setCounterpart(conversation.getNextCounterpart());
message.setType(Message.TYPE_IMAGE);
@@ -115,7 +116,7 @@ public class ResizePictureUserDecisionListener implements UserDecisionListener {
int imageWidth = resizedAndRotatedImage.getWidth();
int imageHeight = resizedAndRotatedImage.getHeight();
MessageUtil.updateMessageWithImageDetails(message, filePath, imageSize, imageWidth, imageHeight);
- if (conversation.getNextEncryption(forceEncryption) == Message.ENCRYPTION_PGP) {
+ if (conversation.getNextEncryption() == Message.ENCRYPTION_PGP) {
xmppConnectionService.getPgpEngine().encrypt(message, callback);
} else {
callback.success(message);
@@ -133,10 +134,10 @@ public class ResizePictureUserDecisionListener implements UserDecisionListener {
this.showPrepareFileToast();
final Message message;
final boolean forceEncryption = ConversationsPlusPreferences.forceEncryption();
- if (conversation.getNextEncryption(forceEncryption) == Message.ENCRYPTION_PGP) {
+ if (conversation.getNextEncryption() == Message.ENCRYPTION_PGP) {
message = new Message(conversation, "", Message.ENCRYPTION_DECRYPTED);
} else {
- message = new Message(conversation, "", conversation.getNextEncryption(forceEncryption));
+ message = new Message(conversation, "", conversation.getNextEncryption());
}
message.setCounterpart(conversation.getNextCounterpart());
message.setType(Message.TYPE_IMAGE);
@@ -154,7 +155,7 @@ public class ResizePictureUserDecisionListener implements UserDecisionListener {
int imageWidth = options.outWidth;
String filePath = FileHelper.getRealPathFromUri(uri);
MessageUtil.updateMessageWithImageDetails(message, filePath, imageSize, imageWidth, imageHeight);
- if (conversation.getNextEncryption(forceEncryption) == Message.ENCRYPTION_PGP) {
+ if (conversation.getNextEncryption() == Message.ENCRYPTION_PGP) {
xmppConnectionService.getPgpEngine().encrypt(message, callback);
} else {
callback.success(message);
diff --git a/src/main/java/de/thedevstack/conversationsplus/ui/listeners/ShowResourcesListDialogListener.java b/src/main/java/de/thedevstack/conversationsplus/ui/listeners/ShowResourcesListDialogListener.java
index 070ea58c..791b31a7 100644
--- a/src/main/java/de/thedevstack/conversationsplus/ui/listeners/ShowResourcesListDialogListener.java
+++ b/src/main/java/de/thedevstack/conversationsplus/ui/listeners/ShowResourcesListDialogListener.java
@@ -3,10 +3,10 @@ package de.thedevstack.conversationsplus.ui.listeners;
import android.content.Context;
import android.view.View;
-import de.thedevstack.conversationsplus.R;
-import de.thedevstack.conversationsplus.entities.Contact;
import de.thedevstack.conversationsplus.ui.adapter.PresencesArrayAdapter;
import de.thedevstack.conversationsplus.ui.dialogs.AbstractAlertDialog;
+import de.thedevstack.conversationsplus.R;
+import de.thedevstack.conversationsplus.entities.Contact;
/**
* This listener shows the dialog with the resources of a contact.
diff --git a/src/main/java/de/thedevstack/conversationsplus/ui/widget/Switch.java b/src/main/java/de/thedevstack/conversationsplus/ui/widget/Switch.java
new file mode 100644
index 00000000..e5a4f0dc
--- /dev/null
+++ b/src/main/java/de/thedevstack/conversationsplus/ui/widget/Switch.java
@@ -0,0 +1,68 @@
+package de.thedevstack.conversationsplus.ui.widget;
+
+import android.content.Context;
+import android.util.AttributeSet;
+import android.view.MotionEvent;
+import android.view.ViewConfiguration;
+
+import com.kyleduo.switchbutton.SwitchButton;
+
+public class Switch extends SwitchButton {
+
+ private int mTouchSlop;
+ private int mClickTimeout;
+ private float mStartX;
+ private float mStartY;
+ private OnClickListener mOnClickListener;
+
+ public Switch(Context context) {
+ super(context);
+ mTouchSlop = ViewConfiguration.get(getContext()).getScaledTouchSlop();
+ mClickTimeout = ViewConfiguration.getPressedStateDuration() + ViewConfiguration.getTapTimeout();
+ }
+
+ public Switch(Context context, AttributeSet attrs) {
+ super(context, attrs);
+ mTouchSlop = ViewConfiguration.get(getContext()).getScaledTouchSlop();
+ mClickTimeout = ViewConfiguration.getPressedStateDuration() + ViewConfiguration.getTapTimeout();
+ }
+
+ public Switch(Context context, AttributeSet attrs, int defStyle) {
+ super(context, attrs, defStyle);
+ mTouchSlop = ViewConfiguration.get(getContext()).getScaledTouchSlop();
+ mClickTimeout = ViewConfiguration.getPressedStateDuration() + ViewConfiguration.getTapTimeout();
+ }
+
+ @Override
+ public void setOnClickListener(OnClickListener onClickListener) {
+ this.mOnClickListener = onClickListener;
+ }
+
+ @Override
+ public boolean onTouchEvent(MotionEvent event) {
+ if (!isEnabled()) {
+ float deltaX = event.getX() - mStartX;
+ float deltaY = event.getY() - mStartY;
+ int action = event.getAction();
+ switch (action) {
+ case MotionEvent.ACTION_DOWN:
+ mStartX = event.getX();
+ mStartY = event.getY();
+ break;
+ case MotionEvent.ACTION_CANCEL:
+ case MotionEvent.ACTION_UP:
+ float time = event.getEventTime() - event.getDownTime();
+ if (deltaX < mTouchSlop && deltaY < mTouchSlop && time < mClickTimeout) {
+ if (mOnClickListener != null) {
+ this.mOnClickListener.onClick(this);
+ }
+ }
+ break;
+ default:
+ break;
+ }
+ return true;
+ }
+ return super.onTouchEvent(event);
+ }
+}