aboutsummaryrefslogtreecommitdiffstats
path: root/src/main/java/de/pixart/messenger/ui
diff options
context:
space:
mode:
authorChristian Schneppe <christian@pix-art.de>2018-03-24 22:45:55 +0100
committerChristian Schneppe <christian@pix-art.de>2018-03-24 22:45:55 +0100
commit4c109297087f194e34a3e86b18285112fbec33fc (patch)
treeeb7d7e9e5d445442c3e8f59bafd558df36ea46b5 /src/main/java/de/pixart/messenger/ui
parent6e49572be6fdd7c54eb0d6f1939dce9fbb537024 (diff)
made select work
Diffstat (limited to 'src/main/java/de/pixart/messenger/ui')
-rw-r--r--src/main/java/de/pixart/messenger/ui/ConversationFragment.java10
-rw-r--r--src/main/java/de/pixart/messenger/ui/ConversationsMainActivity.java42
-rw-r--r--src/main/java/de/pixart/messenger/ui/ConversationsOverviewFragment.java3
-rw-r--r--src/main/java/de/pixart/messenger/ui/adapter/ConversationAdapter.java20
-rw-r--r--src/main/java/de/pixart/messenger/ui/util/PendingItem.java4
5 files changed, 67 insertions, 12 deletions
diff --git a/src/main/java/de/pixart/messenger/ui/ConversationFragment.java b/src/main/java/de/pixart/messenger/ui/ConversationFragment.java
index 742c14495..710c8d4cc 100644
--- a/src/main/java/de/pixart/messenger/ui/ConversationFragment.java
+++ b/src/main/java/de/pixart/messenger/ui/ConversationFragment.java
@@ -2,6 +2,7 @@ package de.pixart.messenger.ui;
import android.annotation.SuppressLint;
import android.app.Activity;
+import android.app.Fragment;
import android.app.PendingIntent;
import android.content.ActivityNotFoundException;
import android.content.Context;
@@ -2560,6 +2561,15 @@ public class ConversationFragment extends XmppFragment implements EditMessage.Ke
}
}
+ public static Conversation getConversation(Activity activity) {
+ Fragment fragment = activity.getFragmentManager().findFragmentById(R.id.secondary_fragment);
+ if (fragment != null && fragment instanceof ConversationFragment) {
+ return ((ConversationFragment) fragment).getConversation();
+ } else {
+ return null;
+ }
+ }
+
public Conversation getConversation() {
return conversation;
}
diff --git a/src/main/java/de/pixart/messenger/ui/ConversationsMainActivity.java b/src/main/java/de/pixart/messenger/ui/ConversationsMainActivity.java
index 14570af97..9d2f491d8 100644
--- a/src/main/java/de/pixart/messenger/ui/ConversationsMainActivity.java
+++ b/src/main/java/de/pixart/messenger/ui/ConversationsMainActivity.java
@@ -60,24 +60,38 @@ import static de.pixart.messenger.ui.SettingsActivity.USE_BUNDLED_EMOJIS;
public class ConversationsMainActivity extends XmppActivity implements OnConversationSelected, OnConversationArchived, OnConversationsListItemUpdated, OnConversationRead {
+ //secondary fragment (when holding the conversation, must be initialized before refreshing the overview fragment
+ private static final @IdRes
+ int[] FRAGMENT_ID_NOTIFICATION_ORDER = {R.id.secondary_fragment, R.id.main_fragment};
+
private ActivityConversationsBinding binding;
@Override
protected void refreshUiReal() {
-
+ for(@IdRes int id : FRAGMENT_ID_NOTIFICATION_ORDER) {
+ refreshFragment(id);
+ }
}
@Override
void onBackendConnected() {
- notifyFragment(R.id.main_fragment);
- notifyFragment(R.id.secondary_fragment);
+ for (@IdRes int id : FRAGMENT_ID_NOTIFICATION_ORDER) {
+ notifyFragmentOfBackendConnected(id);
+ }
invalidateActionBarTitle();
}
- private void notifyFragment(@IdRes int id) {
- Fragment mainFragment = getFragmentManager().findFragmentById(id);
- if (mainFragment != null && mainFragment instanceof XmppFragment) {
- ((XmppFragment) mainFragment).onBackendConnected();
+ private void notifyFragmentOfBackendConnected(@IdRes int id) {
+ final Fragment fragment = getFragmentManager().findFragmentById(id);
+ if (fragment != null && fragment instanceof XmppFragment) {
+ ((XmppFragment) fragment).onBackendConnected();
+ }
+ }
+
+ private void refreshFragment(@IdRes int id) {
+ final Fragment fragment = getFragmentManager().findFragmentById(id);
+ if (fragment != null && fragment instanceof XmppFragment) {
+ ((XmppFragment) fragment).refresh();
}
}
@@ -101,14 +115,21 @@ public class ConversationsMainActivity extends XmppActivity implements OnConvers
public void onConversationSelected(Conversation conversation) {
Log.d(Config.LOGTAG, "selected " + conversation.getName());
ConversationFragment conversationFragment = (ConversationFragment) getFragmentManager().findFragmentById(R.id.secondary_fragment);
+ final boolean mainNeedsRefresh;
if (conversationFragment == null) {
+ mainNeedsRefresh = false;
conversationFragment = new ConversationFragment();
FragmentTransaction fragmentTransaction = getFragmentManager().beginTransaction();
fragmentTransaction.replace(R.id.main_fragment, conversationFragment);
fragmentTransaction.addToBackStack(null);
fragmentTransaction.commit();
+ } else {
+ mainNeedsRefresh = true;
}
conversationFragment.reInit(conversation);
+ if (mainNeedsRefresh) {
+ refreshFragment(R.id.main_fragment);
+ }
}
@Override
@@ -160,6 +181,8 @@ public class ConversationsMainActivity extends XmppActivity implements OnConvers
} else {
transaction.replace(R.id.main_fragment, new ConversationsOverviewFragment());
}
+
+ //TODO, do this in backendConnected so we can actually decide what to display
if (binding.secondaryFragment != null) {
transaction.replace(R.id.secondary_fragment, new ConversationFragment());
}
@@ -229,7 +252,10 @@ public class ConversationsMainActivity extends XmppActivity implements OnConvers
@Override
public void onConversationsListItemUpdated() {
-
+ Fragment fragment = getFragmentManager().findFragmentById(R.id.main_fragment);
+ if (fragment != null && fragment instanceof ConversationsOverviewFragment) {
+ ((ConversationsOverviewFragment) fragment).refresh();
+ }
}
@Override
diff --git a/src/main/java/de/pixart/messenger/ui/ConversationsOverviewFragment.java b/src/main/java/de/pixart/messenger/ui/ConversationsOverviewFragment.java
index 649bb09a2..ecfbaf595 100644
--- a/src/main/java/de/pixart/messenger/ui/ConversationsOverviewFragment.java
+++ b/src/main/java/de/pixart/messenger/ui/ConversationsOverviewFragment.java
@@ -46,6 +46,7 @@ import de.pixart.messenger.databinding.FragmentConversationsOverviewBinding;
import de.pixart.messenger.entities.Conversation;
import de.pixart.messenger.ui.adapter.ConversationAdapter;
import de.pixart.messenger.ui.interfaces.OnConversationSelected;
+import de.pixart.messenger.ui.util.PendingItem;
public class ConversationsOverviewFragment extends XmppFragment {
@@ -54,6 +55,8 @@ public class ConversationsOverviewFragment extends XmppFragment {
private ConversationAdapter conversationsAdapter;
private XmppActivity activity;
+ private final PendingItem<Conversation> swipedConversation = new PendingItem<>();
+
@Override
public void onAttach(Activity activity) {
super.onAttach(activity);
diff --git a/src/main/java/de/pixart/messenger/ui/adapter/ConversationAdapter.java b/src/main/java/de/pixart/messenger/ui/adapter/ConversationAdapter.java
index 3c2de008e..35d4ad7f4 100644
--- a/src/main/java/de/pixart/messenger/ui/adapter/ConversationAdapter.java
+++ b/src/main/java/de/pixart/messenger/ui/adapter/ConversationAdapter.java
@@ -10,6 +10,7 @@ import android.graphics.drawable.Drawable;
import android.os.AsyncTask;
import android.preference.PreferenceManager;
import android.support.v4.content.ContextCompat;
+import android.util.Log;
import android.util.Pair;
import android.view.LayoutInflater;
import android.view.View;
@@ -22,12 +23,13 @@ import java.lang.ref.WeakReference;
import java.util.List;
import java.util.concurrent.RejectedExecutionException;
+import de.pixart.messenger.Config;
import de.pixart.messenger.R;
import de.pixart.messenger.entities.Conversation;
import de.pixart.messenger.entities.Message;
import de.pixart.messenger.entities.MucOptions;
import de.pixart.messenger.entities.Transferable;
-import de.pixart.messenger.ui.ConversationActivity;
+import de.pixart.messenger.ui.ConversationFragment;
import de.pixart.messenger.ui.XmppActivity;
import de.pixart.messenger.utils.EmojiWrapper;
import de.pixart.messenger.utils.UIHelper;
@@ -36,6 +38,7 @@ import de.pixart.messenger.xmpp.chatstate.ChatState;
public class ConversationAdapter extends ArrayAdapter<Conversation> {
private XmppActivity activity;
+ private Conversation selectedConversation = null;
public ConversationAdapter(XmppActivity activity,
List<Conversation> conversations) {
@@ -75,10 +78,9 @@ public class ConversationAdapter extends ArrayAdapter<Conversation> {
view = inflater.inflate(R.layout.conversation_list_row, parent, false);
}
Conversation conversation = getItem(position);
- if (this.activity instanceof ConversationActivity) {
+ if (this.activity instanceof XmppActivity) {
View swipeableItem = view.findViewById(R.id.swipeable_item);
- ConversationActivity a = (ConversationActivity) this.activity;
- int c = a.highlightSelectedConversations() && conversation == a.getSelectedConversation() ? a.getSecondaryBackgroundColor() : a.getPrimaryBackgroundColor();
+ int c = conversation == selectedConversation ? this.activity.getSecondaryBackgroundColor() : this.activity.getPrimaryBackgroundColor();
swipeableItem.setBackgroundColor(c);
}
ViewHolder viewHolder = ViewHolder.get(view);
@@ -296,6 +298,16 @@ public class ConversationAdapter extends ArrayAdapter<Conversation> {
}
}
+ @Override
+ public void notifyDataSetChanged() {
+ this.selectedConversation = ConversationFragment.getConversation(activity);
+ Log.d(Config.LOGTAG, "notify data set changed");
+ if (this.selectedConversation == null) {
+ Log.d(Config.LOGTAG, "selected conversation is null");
+ }
+ super.notifyDataSetChanged();
+ }
+
public static class ViewHolder {
private TextView name;
private TextView lastMessage;
diff --git a/src/main/java/de/pixart/messenger/ui/util/PendingItem.java b/src/main/java/de/pixart/messenger/ui/util/PendingItem.java
index 772f5e7e1..eaddf3a8c 100644
--- a/src/main/java/de/pixart/messenger/ui/util/PendingItem.java
+++ b/src/main/java/de/pixart/messenger/ui/util/PendingItem.java
@@ -42,4 +42,8 @@ public class PendingItem<T> {
this.item = null;
return item;
}
+
+ public synchronized T peek() {
+ return item;
+ }
} \ No newline at end of file