diff options
Diffstat (limited to 'src/main/java/eu/siacs/conversations/ui/XmppActivity.java')
-rw-r--r-- | src/main/java/eu/siacs/conversations/ui/XmppActivity.java | 83 |
1 files changed, 56 insertions, 27 deletions
diff --git a/src/main/java/eu/siacs/conversations/ui/XmppActivity.java b/src/main/java/eu/siacs/conversations/ui/XmppActivity.java index 26b7909b..28405537 100644 --- a/src/main/java/eu/siacs/conversations/ui/XmppActivity.java +++ b/src/main/java/eu/siacs/conversations/ui/XmppActivity.java @@ -108,6 +108,13 @@ public abstract class XmppActivity extends Activity { private DisplayMetrics metrics; protected int mTheme; + protected Runnable onOpenPGPKeyPublished = new Runnable() { + @Override + public void run() { + Toast.makeText(XmppActivity.this,R.string.openpgp_has_been_published, Toast.LENGTH_SHORT).show(); + } + }; + private long mLastUiRefresh = 0; private Handler mRefreshUiHandler = new Handler(); private Runnable mRefreshUiRunnable = new Runnable() { @@ -357,19 +364,6 @@ public abstract class XmppActivity extends Activity { } } - @Override - public boolean onCreateOptionsMenu(Menu menu) { - final MenuItem menuSettings = menu.findItem(R.id.action_settings); - final MenuItem menuManageAccounts = menu.findItem(R.id.action_accounts); - if (menuSettings != null) { - menuSettings.setVisible(!Config.LOCK_SETTINGS); - } - if (menuManageAccounts != null) { - menuManageAccounts.setVisible(!Config.LOCK_SETTINGS); - } - return super.onCreateOptionsMenu(menu); - } - protected boolean isOptimizingBattery() { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { PowerManager pm = (PowerManager) getSystemService(POWER_SERVICE); @@ -451,8 +445,8 @@ public abstract class XmppActivity extends Activity { ChooseContactActivity.class); List<String> contacts = new ArrayList<>(); if (conversation.getMode() == Conversation.MODE_MULTI) { - for (MucOptions.User user : conversation.getMucOptions().getUsers()) { - Jid jid = user.getJid(); + for (MucOptions.User user : conversation.getMucOptions().getUsers(false)) { + Jid jid = user.getRealJid(); if (jid != null) { contacts.add(jid.toBareJid().toString()); } @@ -468,18 +462,23 @@ public abstract class XmppActivity extends Activity { startActivityForResult(intent, REQUEST_INVITE_TO_CONVERSATION); } - protected void announcePgp(Account account, final Conversation conversation) { - if (account.getPgpId() == -1) { + protected void announcePgp(Account account, final Conversation conversation, final Runnable onSuccess) { + if (account.getPgpId() == 0) { choosePgpSignId(account); } else { - xmppConnectionService.getPgpEngine().generateSignature(account, "", new UiCallback<Account>() { + String status = null; + if (manuallyChangePresence()) { + status = account.getPresenceStatusMessage(); + } + if (status == null) { + status = ""; + } + xmppConnectionService.getPgpEngine().generateSignature(account, status, new UiCallback<Account>() { @Override - public void userInputRequried(PendingIntent pi, - Account account) { + public void userInputRequried(PendingIntent pi, Account account) { try { - startIntentSenderForResult(pi.getIntentSender(), - REQUEST_ANNOUNCE_PGP, null, 0, 0, 0); + startIntentSenderForResult(pi.getIntentSender(), REQUEST_ANNOUNCE_PGP, null, 0, 0, 0); } catch (final SendIntentException ignored) { } } @@ -492,6 +491,9 @@ public abstract class XmppActivity extends Activity { conversation.setNextEncryption(Message.ENCRYPTION_PGP); xmppConnectionService.databaseBackend.updateConversation(conversation); } + if (onSuccess != null) { + runOnUiThread(onSuccess); + } } @Override @@ -502,6 +504,29 @@ public abstract class XmppActivity extends Activity { } } + protected boolean noAccountUsesPgp() { + if (!hasPgp()) { + return true; + } + for(Account account : xmppConnectionService.getAccounts()) { + if (account.getPgpId() != 0) { + return false; + } + } + return true; + } + + @SuppressWarnings("deprecation") + @TargetApi(Build.VERSION_CODES.JELLY_BEAN) + protected void setListItemBackgroundOnView(View view) { + int sdk = android.os.Build.VERSION.SDK_INT; + if (sdk < android.os.Build.VERSION_CODES.JELLY_BEAN) { + view.setBackgroundDrawable(getResources().getDrawable(R.drawable.greybackground)); + } else { + view.setBackground(getResources().getDrawable(R.drawable.greybackground)); + } + } + protected void choosePgpSignId(Account account) { xmppConnectionService.getPgpEngine().chooseKey(account, new UiCallback<Account>() { @Override @@ -524,7 +549,7 @@ public abstract class XmppActivity extends Activity { }); } - public void displayErrorDialog(final int errorCode) { + protected void displayErrorDialog(final int errorCode) { runOnUiThread(new Runnable() { @Override @@ -1069,13 +1094,16 @@ public abstract class XmppActivity extends Activity { private final boolean setSize; private Message message = null; - public BitmapWorkerTask(ImageView imageView, boolean setSize) { + public BitmapWorkerTask(ImageView imageView) { imageViewReference = new WeakReference<>(imageView); this.setSize = setSize; } @Override protected Bitmap doInBackground(Message... params) { + if (isCancelled()) { + return null; + } message = params[0]; try { return ImageUtil.getThumbnail(message, (int) (metrics.density * 288), false); @@ -1086,7 +1114,7 @@ public abstract class XmppActivity extends Activity { @Override protected void onPostExecute(Bitmap bitmap) { - if (bitmap != null) { + if (bitmap != null && !isCancelled()) { final ImageView imageView = imageViewReference.get(); if (imageView != null) { imageView.setImageBitmap(bitmap); @@ -1109,6 +1137,7 @@ public abstract class XmppActivity extends Activity { } if (bm != null) { + cancelPotentialWork(message, imageView); imageView.setImageBitmap(bm); imageView.setBackgroundColor(0x00000000); if (setSize) { @@ -1126,13 +1155,13 @@ public abstract class XmppActivity extends Activity { try { task.execute(message); } catch (final RejectedExecutionException ignored) { + ignored.printStackTrace(); } } } } - public static boolean cancelPotentialWork(Message message, - ImageView imageView) { + public static boolean cancelPotentialWork(Message message, ImageView imageView) { final BitmapWorkerTask bitmapWorkerTask = getBitmapWorkerTask(imageView); if (bitmapWorkerTask != null) { |