diff options
Diffstat (limited to '')
6 files changed, 73 insertions, 41 deletions
diff --git a/src/main/java/de/pixart/messenger/ui/BlockContactDialog.java b/src/main/java/de/pixart/messenger/ui/BlockContactDialog.java index 3be0d9344..bf33c35d9 100644 --- a/src/main/java/de/pixart/messenger/ui/BlockContactDialog.java +++ b/src/main/java/de/pixart/messenger/ui/BlockContactDialog.java @@ -11,19 +11,18 @@ import android.view.View; import android.widget.CheckBox; import android.widget.LinearLayout; import android.widget.TextView; +import android.widget.Toast; import de.pixart.messenger.R; import de.pixart.messenger.entities.Blockable; -import de.pixart.messenger.services.XmppConnectionService; public final class BlockContactDialog { - public static void show(final Context context, - final XmppConnectionService xmppConnectionService, + public static void show(final XmppActivity xmppActivity, final Blockable blockable) { - final AlertDialog.Builder builder = new AlertDialog.Builder(context); + final AlertDialog.Builder builder = new AlertDialog.Builder(xmppActivity); final boolean isBlocked = blockable.isBlocked(); builder.setNegativeButton(R.string.cancel, null); - LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE); + LayoutInflater inflater = (LayoutInflater) xmppActivity.getSystemService(Context.LAYOUT_INFLATER_SERVICE); LinearLayout view = (LinearLayout) inflater.inflate(R.layout.dialog_block_contact, null); TextView message = (TextView) view.findViewById(R.id.text); final CheckBox report = (CheckBox) view.findViewById(R.id.report_spam); @@ -36,11 +35,11 @@ public final class BlockContactDialog { if (blockable.getJid().isDomainJid() || blockable.getAccount().isBlocked(blockable.getJid().toDomainJid())) { builder.setTitle(isBlocked ? R.string.action_unblock_domain : R.string.action_block_domain); value = blockable.getJid().toDomainJid().toString(); - spannable = new SpannableString(context.getString(isBlocked ? R.string.unblock_domain_text : R.string.block_domain_text, value)); + spannable = new SpannableString(xmppActivity.getString(isBlocked ? R.string.unblock_domain_text : R.string.block_domain_text, value)); } else { builder.setTitle(isBlocked ? R.string.action_unblock_contact : R.string.action_block_contact); value = blockable.getJid().toBareJid().toString(); - spannable = new SpannableString(context.getString(isBlocked ? R.string.unblock_contact_text : R.string.block_contact_text, value)); + spannable = new SpannableString(xmppActivity.getString(isBlocked ? R.string.unblock_contact_text : R.string.block_contact_text, value)); } int start = spannable.toString().indexOf(value); if (start >= 0) { @@ -52,9 +51,19 @@ public final class BlockContactDialog { @Override public void onClick(final DialogInterface dialog, final int which) { if (isBlocked) { - xmppConnectionService.sendUnblockRequest(blockable); + xmppActivity.xmppConnectionService.sendUnblockRequest(blockable); } else { - xmppConnectionService.sendBlockRequest(blockable, report.isChecked()); + boolean toastShown = false; + if (xmppActivity.xmppConnectionService.sendBlockRequest(blockable, report.isChecked())) { + Toast.makeText(xmppActivity, R.string.corresponding_conversations_closed, Toast.LENGTH_SHORT).show(); + toastShown = true; + } + if (xmppActivity instanceof ContactDetailsActivity) { + if (!toastShown) { + Toast.makeText(xmppActivity, R.string.contact_blocked_past_tense, Toast.LENGTH_SHORT).show(); + } + xmppActivity.finish(); + } } } }); diff --git a/src/main/java/de/pixart/messenger/ui/BlocklistActivity.java b/src/main/java/de/pixart/messenger/ui/BlocklistActivity.java index 3f6a57381..3ee40aa7f 100644 --- a/src/main/java/de/pixart/messenger/ui/BlocklistActivity.java +++ b/src/main/java/de/pixart/messenger/ui/BlocklistActivity.java @@ -6,6 +6,7 @@ import android.view.Menu; import android.view.MenuItem; import android.view.View; import android.widget.AdapterView; +import android.widget.Toast; import java.util.ArrayList; import java.util.Collections; @@ -31,7 +32,7 @@ public class BlocklistActivity extends AbstractSearchableListItemActivity implem final View view, final int position, final long id) { - BlockContactDialog.show(parent.getContext(), xmppConnectionService, (Contact) getListItems().get(position)); + BlockContactDialog.show(BlocklistActivity.this, (Contact) getListItems().get(position)); return true; } }); @@ -92,7 +93,9 @@ public class BlocklistActivity extends AbstractSearchableListItemActivity implem @Override public boolean onEnterJidDialogPositive(Jid accountJid, Jid contactJid) throws EnterJidDialog.JidError { Contact contact = account.getRoster().getContact(contactJid); - xmppConnectionService.sendBlockRequest(contact, false); + if (xmppConnectionService.sendBlockRequest(contact, false)) { + Toast.makeText(BlocklistActivity.this, R.string.corresponding_conversations_closed, Toast.LENGTH_SHORT).show(); + } return true; } }); diff --git a/src/main/java/de/pixart/messenger/ui/ContactDetailsActivity.java b/src/main/java/de/pixart/messenger/ui/ContactDetailsActivity.java index de633ad17..1837e6df5 100644 --- a/src/main/java/de/pixart/messenger/ui/ContactDetailsActivity.java +++ b/src/main/java/de/pixart/messenger/ui/ContactDetailsActivity.java @@ -366,10 +366,10 @@ public class ContactDetailsActivity extends OmemoActivity implements OnAccountUp } break; case R.id.action_block: - BlockContactDialog.show(this, xmppConnectionService, contact); + BlockContactDialog.show(this, contact); break; case R.id.action_unblock: - BlockContactDialog.show(this, xmppConnectionService, contact); + BlockContactDialog.show(this, contact); break; } return super.onOptionsItemSelected(menuItem); diff --git a/src/main/java/de/pixart/messenger/ui/ConversationActivity.java b/src/main/java/de/pixart/messenger/ui/ConversationActivity.java index e8d61d1df..d60fbcbe4 100644 --- a/src/main/java/de/pixart/messenger/ui/ConversationActivity.java +++ b/src/main/java/de/pixart/messenger/ui/ConversationActivity.java @@ -837,10 +837,10 @@ public class ConversationActivity extends XmppActivity clearHistoryDialog(getSelectedConversation()); break; case R.id.action_block: - BlockContactDialog.show(this, xmppConnectionService, getSelectedConversation()); + BlockContactDialog.show(this, getSelectedConversation()); break; case R.id.action_unblock: - BlockContactDialog.show(this, xmppConnectionService, getSelectedConversation()); + BlockContactDialog.show(this, getSelectedConversation()); break; default: break; @@ -1281,6 +1281,18 @@ public class ConversationActivity extends XmppActivity mPostponedActivityResult = null; } + private void redirectToStartConversationActivity() { + Account pendingAccount = xmppConnectionService.getPendingAccount(); + if (pendingAccount == null) { + Intent startConversationActivity = new Intent(this, StartConversationActivity.class); + startConversationActivity.putExtra("init", true); + startActivity(startConversationActivity); + } else { + switchToAccount(pendingAccount, true); + } + finish(); + } + @Override void onBackendConnected() { this.xmppConnectionService.getNotificationService().setIsInForeground(true); @@ -1338,15 +1350,7 @@ public class ConversationActivity extends XmppActivity } } else if (conversationList.size() <= 0) { if (mRedirected.compareAndSet(false, true)) { - Account pendingAccount = xmppConnectionService.getPendingAccount(); - if (pendingAccount == null) { - Intent startConversationActivity = new Intent(this, StartConversationActivity.class); - intent.putExtra("init", true); - startActivity(startConversationActivity); - } else { - switchToAccount(pendingAccount, true); - } - finish(); + redirectToStartConversationActivity(); } } else if (selectConversationByUuid(mOpenConversation)) { if (mPanelOpen) { @@ -1367,10 +1371,7 @@ public class ConversationActivity extends XmppActivity handleViewConversationIntent(intent); intent.setAction(Intent.ACTION_MAIN); } else if (getSelectedConversation() == null) { - showConversationsOverview(); - clearPending(); - setSelectedConversation(conversationList.get(0)); - this.mConversationFragment.reInit(getSelectedConversation()); + reInitLatestConversation(); } else { this.mConversationFragment.messageListAdapter.updatePreferences(); this.mConversationFragment.messagesView.invalidateViews(); @@ -1388,12 +1389,7 @@ public class ConversationActivity extends XmppActivity this.onActivityResult(mPostponedActivityResult.first, RESULT_OK, mPostponedActivityResult.second); } - final boolean stopping; - if (Build.VERSION.SDK_INT >= 17) { - stopping = isFinishing() || isDestroyed(); - } else { - stopping = isFinishing(); - } + final boolean stopping = isStopping(); if (!forbidProcessingPendings) { int ImageUrisCount = mPendingImageUris.size(); @@ -1436,6 +1432,21 @@ public class ConversationActivity extends XmppActivity } } + private boolean isStopping() { + if (Build.VERSION.SDK_INT >= 17) { + return isFinishing() || isDestroyed(); + } else { + return isFinishing(); + } + } + + private void reInitLatestConversation() { + showConversationsOverview(); + clearPending(); + setSelectedConversation(conversationList.get(0)); + this.mConversationFragment.reInit(getSelectedConversation()); + } + private void handleViewConversationIntent(final Intent intent) { final String uuid = intent.getStringExtra(CONVERSATION); final String downloadUuid = intent.getStringExtra(EXTRA_DOWNLOAD_UUID); @@ -1939,8 +1950,10 @@ public class ConversationActivity extends XmppActivity } public void updateConversationList() { - xmppConnectionService - .populateWithOrderedConversations(conversationList); + xmppConnectionService.populateWithOrderedConversations(conversationList); + if (!conversationList.contains(mSelectedConversation)) { + mSelectedConversation = null; + } if (swipedConversation != null) { if (swipedConversation.isRead()) { conversationList.remove(swipedConversation); @@ -2044,10 +2057,17 @@ public class ConversationActivity extends XmppActivity if (!this.mConversationFragment.isAdded()) { Log.d(Config.LOGTAG, "fragment NOT added to activity. detached=" + Boolean.toString(mConversationFragment.isDetached())); } - ConversationActivity.this.mConversationFragment.updateMessages(); - updateActionBarTitle(); - invalidateOptionsMenu(); + if (getSelectedConversation() == null) { + reInitLatestConversation(); + } else { + ConversationActivity.this.mConversationFragment.updateMessages(); + updateActionBarTitle(); + invalidateOptionsMenu(); + } } else { + if (!isStopping() && mRedirected.compareAndSet(false, true)) { + redirectToStartConversationActivity(); + } Log.d(Config.LOGTAG, "not updating conversations fragment because conversations list size was 0"); } } diff --git a/src/main/java/de/pixart/messenger/ui/ConversationFragment.java b/src/main/java/de/pixart/messenger/ui/ConversationFragment.java index 8e8fb5e46..b985a2c35 100644 --- a/src/main/java/de/pixart/messenger/ui/ConversationFragment.java +++ b/src/main/java/de/pixart/messenger/ui/ConversationFragment.java @@ -981,7 +981,7 @@ public class ConversationFragment extends Fragment implements EditMessage.Keyboa } }); if (conversation.isDomainBlocked()) { - BlockContactDialog.show(activity, activity.xmppConnectionService, conversation); + BlockContactDialog.show(activity, conversation); } else { activity.unblockConversation(conversation); } diff --git a/src/main/java/de/pixart/messenger/ui/StartConversationActivity.java b/src/main/java/de/pixart/messenger/ui/StartConversationActivity.java index a4a9db761..93663bda5 100644 --- a/src/main/java/de/pixart/messenger/ui/StartConversationActivity.java +++ b/src/main/java/de/pixart/messenger/ui/StartConversationActivity.java @@ -389,7 +389,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, (Contact) contacts.get(position)); } protected void deleteContact() { |