Show list of recent threads in contact details too

This commit is contained in:
12aw 2024-02-14 10:54:40 +01:00
parent fb0f859abe
commit fe677337b7
3 changed files with 89 additions and 24 deletions

View file

@ -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();
}
}
}

View file

@ -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"

View file

@ -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"