diff --git a/src/main/java/eu/siacs/conversations/ui/ContactDetailsActivity.java b/src/main/java/eu/siacs/conversations/ui/ContactDetailsActivity.java index 98bd2efb4b..33c56f867d 100644 --- a/src/main/java/eu/siacs/conversations/ui/ContactDetailsActivity.java +++ b/src/main/java/eu/siacs/conversations/ui/ContactDetailsActivity.java @@ -1,6 +1,10 @@ package eu.siacs.conversations.ui; import static eu.siacs.conversations.ui.util.IntroHelper.showIntro; +import eu.siacs.conversations.databinding.ThreadRowBinding; +import de.monocles.chat.Util; +import androidx.annotation.NonNull; +import android.view.ViewGroup; import android.Manifest; import android.content.ActivityNotFoundException; @@ -312,6 +316,10 @@ public class ContactDetailsActivity extends OmemoActivity implements OnAccountUp mMediaAdapter = new MediaAdapter(this, R.dimen.media_size); this.binding.media.setAdapter(mMediaAdapter); GridManager.setupLayoutManager(this, this.binding.media, R.dimen.media_size); + this.binding.recentThreads.setOnItemClickListener((a0, v, pos, a3) -> { + final Conversation.Thread thread = (Conversation.Thread) binding.recentThreads.getAdapter().getItem(pos); + switchToConversation(mConversation, null, false, null, false, true, null, thread.getThreadId()); + }); showIntro(this, false); } @@ -915,6 +923,18 @@ public class ContactDetailsActivity extends OmemoActivity implements OnAccountUp binding.tags.addView(tv); } } + + final List<Conversation.Thread> recentThreads = mConversation.recentThreads(); + if (recentThreads.isEmpty()) { + this.binding.recentThreadsWrapper.setVisibility(View.GONE); + } else { + final ContactDetailsActivity.ThreadAdapter threads = new ContactDetailsActivity.ThreadAdapter(); + threads.addAll(recentThreads); + this.binding.recentThreads.setAdapter(threads); + this.binding.recentThreadsWrapper.setVisibility(View.VISIBLE); + Util.justifyListViewHeightBasedOnChildren(binding.recentThreads); + } + } private void onBadgeClick(View view) { @@ -1086,4 +1106,21 @@ public class ContactDetailsActivity extends OmemoActivity implements OnAccountUp return null; } } + + class ThreadAdapter extends ArrayAdapter<Conversation.Thread> { + ThreadAdapter() { super(ContactDetailsActivity.this, 0); } + + @Override + public View getView(int position, View view, @NonNull ViewGroup parent) { + final ThreadRowBinding binding = DataBindingUtil.inflate(LayoutInflater.from(parent.getContext()), R.layout.thread_row, parent, false); + final Conversation.Thread item = getItem(position); + + binding.threadIdenticon.setColor(UIHelper.getColorForName(item.getThreadId())); + binding.threadIdenticon.setHash(UIHelper.identiconHash(item.getThreadId())); + + binding.threadSubject.setText(item.getDisplay()); + + return binding.getRoot(); + } + } } diff --git a/src/main/res/layout/activity_contact_details.xml b/src/main/res/layout/activity_contact_details.xml index 6732e618c5..6987efbc0b 100644 --- a/src/main/res/layout/activity_contact_details.xml +++ b/src/main/res/layout/activity_contact_details.xml @@ -241,6 +241,34 @@ android:visibility="visible" /> </LinearLayout> + <View + android:layout_width="match_parent" + android:layout_height="0.05dp" + android:background="?attr/text_Color_Main" /> + + <TextView + android:layout_width="wrap_content" + android:layout_height="wrap_content" + android:padding="12dp" + android:text="@string/recent_threads" + android:textStyle="bold" + style="@style/TextAppearance.Conversations.Subhead" /> + + <LinearLayout + android:id="@+id/recent_threads_wrapper" + android:layout_width="match_parent" + android:layout_height="wrap_content" + android:padding="@dimen/card_padding_regular" > + + <ListView + android:id="@+id/recent_threads" + android:layout_width="fill_parent" + android:layout_height="wrap_content" + android:divider="@android:color/transparent" + android:dividerHeight="0dp" /> + + </LinearLayout> + <View android:layout_width="match_parent" android:layout_height="0.05dp" diff --git a/src/main/res/layout/activity_muc_details.xml b/src/main/res/layout/activity_muc_details.xml index ee645c94bd..e3cba01f61 100644 --- a/src/main/res/layout/activity_muc_details.xml +++ b/src/main/res/layout/activity_muc_details.xml @@ -307,33 +307,33 @@ android:layout_height="wrap_content" android:orientation="vertical"> - <View - android:layout_width="match_parent" - android:layout_height="0.05dp" - android:background="?attr/text_Color_Main" /> + <View + android:layout_width="match_parent" + android:layout_height="0.05dp" + android:background="?attr/text_Color_Main" /> - <TextView - android:layout_width="wrap_content" - android:layout_height="wrap_content" - android:padding="12dp" - android:text="@string/recent_threads" - android:textStyle="bold" - style="@style/TextAppearance.Conversations.Subhead" /> - - <LinearLayout - android:id="@+id/recent_threads_wrapper" - android:layout_width="match_parent" - android:layout_height="wrap_content" - android:padding="@dimen/card_padding_regular" > - - <ListView - android:id="@+id/recent_threads" - android:layout_width="fill_parent" + <TextView + android:layout_width="wrap_content" android:layout_height="wrap_content" - android:divider="@android:color/transparent" - android:dividerHeight="0dp" /> + android:padding="12dp" + android:text="@string/recent_threads" + android:textStyle="bold" + style="@style/TextAppearance.Conversations.Subhead" /> - </LinearLayout> + <LinearLayout + android:id="@+id/recent_threads_wrapper" + android:layout_width="match_parent" + android:layout_height="wrap_content" + android:padding="@dimen/card_padding_regular" > + + <ListView + android:id="@+id/recent_threads" + android:layout_width="fill_parent" + android:layout_height="wrap_content" + android:divider="@android:color/transparent" + android:dividerHeight="0dp" /> + + </LinearLayout> <View android:layout_width="match_parent"