aboutsummaryrefslogtreecommitdiffstats
path: root/src/main/java/de
diff options
context:
space:
mode:
Diffstat (limited to 'src/main/java/de')
-rw-r--r--src/main/java/de/pixart/messenger/services/XmppConnectionService.java11
-rw-r--r--src/main/java/de/pixart/messenger/ui/BlockContactDialog.java49
-rw-r--r--src/main/java/de/pixart/messenger/ui/ConversationFragment.java24
-rw-r--r--src/main/java/de/pixart/messenger/ui/ConversationsActivity.java2
4 files changed, 50 insertions, 36 deletions
diff --git a/src/main/java/de/pixart/messenger/services/XmppConnectionService.java b/src/main/java/de/pixart/messenger/services/XmppConnectionService.java
index 5d36f7bd0..60ecbe7c0 100644
--- a/src/main/java/de/pixart/messenger/services/XmppConnectionService.java
+++ b/src/main/java/de/pixart/messenger/services/XmppConnectionService.java
@@ -1791,6 +1791,17 @@ public class XmppConnectionService extends Service {
}
}
+ public boolean isConversationStillOpen(final Conversation conversation) {
+ synchronized (this.conversations) {
+ for (Conversation current : this.conversations) {
+ if (current == conversation) {
+ return true;
+ }
+ }
+ }
+ return false;
+ }
+
public Conversation findOrCreateConversation(Account account, Jid jid, boolean muc, final boolean async) {
return this.findOrCreateConversation(account, jid, muc, false, async);
}
diff --git a/src/main/java/de/pixart/messenger/ui/BlockContactDialog.java b/src/main/java/de/pixart/messenger/ui/BlockContactDialog.java
index 981b29c41..f7711ce34 100644
--- a/src/main/java/de/pixart/messenger/ui/BlockContactDialog.java
+++ b/src/main/java/de/pixart/messenger/ui/BlockContactDialog.java
@@ -1,19 +1,15 @@
package de.pixart.messenger.ui;
-import android.content.Context;
-import android.content.DialogInterface;
+import android.databinding.DataBindingUtil;
import android.support.v7.app.AlertDialog;
import android.text.SpannableString;
import android.text.Spanned;
import android.text.style.TypefaceSpan;
-import android.view.LayoutInflater;
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.databinding.DialogBlockContactBinding;
import de.pixart.messenger.entities.Blockable;
import de.pixart.messenger.entities.Conversation;
import rocks.xmpp.addr.Jid;
@@ -23,13 +19,10 @@ public final class BlockContactDialog {
final AlertDialog.Builder builder = new AlertDialog.Builder(xmppActivity);
final boolean isBlocked = blockable.isBlocked();
builder.setNegativeButton(R.string.cancel, null);
- LayoutInflater inflater = (LayoutInflater) xmppActivity.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
- LinearLayout view = (LinearLayout) inflater.inflate(R.layout.dialog_block_contact, null);
- TextView message = view.findViewById(R.id.text);
- final CheckBox report = view.findViewById(R.id.report_spam);
+ DialogBlockContactBinding binding = DataBindingUtil.inflate(xmppActivity.getLayoutInflater(), R.layout.dialog_block_contact, null, false);
final boolean reporting = blockable.getAccount().getXmppConnection().getFeatures().spamReporting();
- report.setVisibility(!isBlocked && reporting ? View.VISIBLE : View.GONE);
- builder.setView(view);
+ binding.reportSpam.setVisibility(!isBlocked && reporting ? View.VISIBLE : View.GONE);
+ builder.setView(binding.getRoot());
String value;
SpannableString spannable;
@@ -47,25 +40,21 @@ public final class BlockContactDialog {
if (start >= 0) {
spannable.setSpan(new TypefaceSpan("monospace"), start, start + value.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
}
- message.setText(spannable);
- builder.setPositiveButton(isBlocked ? R.string.unblock : R.string.block, new DialogInterface.OnClickListener() {
-
- @Override
- public void onClick(final DialogInterface dialog, final int which) {
- if (isBlocked) {
- xmppActivity.xmppConnectionService.sendUnblockRequest(blockable);
- } else {
- 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();
+ binding.text.setText(spannable);
+ builder.setPositiveButton(isBlocked ? R.string.unblock : R.string.block, (dialog, which) -> {
+ if (isBlocked) {
+ xmppActivity.xmppConnectionService.sendUnblockRequest(blockable);
+ } else {
+ boolean toastShown = false;
+ if (xmppActivity.xmppConnectionService.sendBlockRequest(blockable, binding.reportSpam.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/ConversationFragment.java b/src/main/java/de/pixart/messenger/ui/ConversationFragment.java
index c92ca19d3..29b034308 100644
--- a/src/main/java/de/pixart/messenger/ui/ConversationFragment.java
+++ b/src/main/java/de/pixart/messenger/ui/ConversationFragment.java
@@ -2078,6 +2078,12 @@ public class ConversationFragment extends XmppFragment implements EditMessage.Ke
if (this.activity == null || this.binding == null) {
return false;
}
+
+ if (!activity.xmppConnectionService.isConversationStillOpen(this.conversation)) {
+ activity.onConversationArchived(this.conversation);
+ return false;
+ }
+
stopScrolling();
Log.d(Config.LOGTAG, "reInit(hasExtras=" + Boolean.toString(hasExtras) + ")");
@@ -2344,6 +2350,12 @@ public class ConversationFragment extends XmppFragment implements EditMessage.Ke
Log.d(Config.LOGTAG, "ConversationFragment.refresh() skipped updated because view binding was null");
return;
}
+ if (this.conversation != null && this.activity != null && this.activity.xmppConnectionService != null) {
+ if (!activity.xmppConnectionService.isConversationStillOpen(this.conversation)) {
+ activity.onConversationArchived(this.conversation);
+ return;
+ }
+ }
this.refresh(true);
}
@@ -2386,10 +2398,6 @@ public class ConversationFragment extends XmppFragment implements EditMessage.Ke
}
}
- public void setFocusOnInputField() {
- this.binding.textinput.requestFocus();
- }
-
public void doneSendingPgpMessage() {
mSendingPgpMessage.set(false);
}
@@ -2906,8 +2914,8 @@ public class ConversationFragment extends XmppFragment implements EditMessage.Ke
if (uuid != null) {
Conversation conversation = activity.xmppConnectionService.findConversationByUuid(uuid);
if (conversation == null) {
- Log.d(Config.LOGTAG, "unable to restore activity");
clearPending();
+ activity.onConversationArchived(null);
return;
}
reInit(conversation);
@@ -2915,6 +2923,12 @@ public class ConversationFragment extends XmppFragment implements EditMessage.Ke
if (scrollState != null) {
setScrollPosition(scrollState);
}
+ } else {
+ if (!activity.xmppConnectionService.isConversationStillOpen(conversation)) {
+ clearPending();
+ activity.onConversationArchived(conversation);
+ return;
+ }
}
ActivityResult activityResult = postponedActivityResult.pop();
if (activityResult != null) {
diff --git a/src/main/java/de/pixart/messenger/ui/ConversationsActivity.java b/src/main/java/de/pixart/messenger/ui/ConversationsActivity.java
index 3c4b9fb59..2eef85029 100644
--- a/src/main/java/de/pixart/messenger/ui/ConversationsActivity.java
+++ b/src/main/java/de/pixart/messenger/ui/ConversationsActivity.java
@@ -303,7 +303,7 @@ public class ConversationsActivity extends XmppActivity implements OnConversatio
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR2) {
builder.setOnDismissListener(dialog -> setNeverAskForBatteryOptimizationsAgain());
}
- AlertDialog dialog = builder.create();
+ final AlertDialog dialog = builder.create();
dialog.setCanceledOnTouchOutside(false);
dialog.show();
}