aboutsummaryrefslogtreecommitdiffstats
path: root/src/main/java/de/pixart/messenger/ui/adapter
diff options
context:
space:
mode:
authorChristian Schneppe <christian@pix-art.de>2019-04-26 23:12:05 +0200
committerChristian Schneppe <christian@pix-art.de>2019-04-26 23:12:22 +0200
commitf9f07063876ec5f3917ce72385b015e1b5f31d7e (patch)
tree093f9ded3021800b20e1e8dcb22d4d8ac17dc7db /src/main/java/de/pixart/messenger/ui/adapter
parent35276c6519afa1da6042dd485ddae09b06c68aeb (diff)
implement channel discovery
refactor muc search to use http cache channel search results
Diffstat (limited to 'src/main/java/de/pixart/messenger/ui/adapter')
-rw-r--r--src/main/java/de/pixart/messenger/ui/adapter/ChannelSearchResultAdapter.java78
1 files changed, 78 insertions, 0 deletions
diff --git a/src/main/java/de/pixart/messenger/ui/adapter/ChannelSearchResultAdapter.java b/src/main/java/de/pixart/messenger/ui/adapter/ChannelSearchResultAdapter.java
new file mode 100644
index 000000000..d137e3a6f
--- /dev/null
+++ b/src/main/java/de/pixart/messenger/ui/adapter/ChannelSearchResultAdapter.java
@@ -0,0 +1,78 @@
+package de.pixart.messenger.ui.adapter;
+
+import android.databinding.DataBindingUtil;
+import android.support.annotation.NonNull;
+import android.support.v7.recyclerview.extensions.ListAdapter;
+import android.support.v7.util.DiffUtil;
+import android.support.v7.widget.RecyclerView;
+import android.text.TextUtils;
+import android.view.LayoutInflater;
+import android.view.View;
+import android.view.ViewGroup;
+
+import de.pixart.messenger.R;
+import de.pixart.messenger.databinding.SearchResultItemBinding;
+import de.pixart.messenger.http.services.MuclumbusService;
+import de.pixart.messenger.ui.util.AvatarWorkerTask;
+
+
+public class ChannelSearchResultAdapter extends ListAdapter<MuclumbusService.Room, ChannelSearchResultAdapter.ViewHolder> {
+
+ private OnChannelSearchResultSelected listener;
+
+ private static final DiffUtil.ItemCallback<MuclumbusService.Room> DIFF = new DiffUtil.ItemCallback<MuclumbusService.Room>() {
+ @Override
+ public boolean areItemsTheSame(@NonNull MuclumbusService.Room a, @NonNull MuclumbusService.Room b) {
+ return a.address != null && a.address.equals(b.address);
+ }
+
+ @Override
+ public boolean areContentsTheSame(@NonNull MuclumbusService.Room a, @NonNull MuclumbusService.Room b) {
+ return a.equals(b);
+ }
+ };
+
+ public ChannelSearchResultAdapter() {
+ super(DIFF);
+ }
+
+ @NonNull
+ @Override
+ public ViewHolder onCreateViewHolder(@NonNull ViewGroup viewGroup, int i) {
+ return new ViewHolder(DataBindingUtil.inflate(LayoutInflater.from(viewGroup.getContext()), R.layout.search_result_item, viewGroup, false));
+ }
+
+ @Override
+ public void onBindViewHolder(@NonNull ViewHolder viewHolder, int position) {
+ final MuclumbusService.Room searchResult = getItem(position);
+ viewHolder.binding.name.setText(searchResult.getName());
+ final String description = searchResult.getDescription();
+ if (TextUtils.isEmpty(description)) {
+ viewHolder.binding.description.setVisibility(View.GONE);
+ } else {
+ viewHolder.binding.description.setText(description);
+ viewHolder.binding.description.setVisibility(View.VISIBLE);
+ }
+ viewHolder.binding.room.setText(searchResult.getRoom().asBareJid().toString());
+ AvatarWorkerTask.loadAvatar(searchResult, viewHolder.binding.avatar, R.dimen.avatar);
+ viewHolder.binding.getRoot().setOnClickListener(v -> listener.onChannelSearchResult(searchResult));
+ }
+
+ public void setOnChannelSearchResultSelectedListener(OnChannelSearchResultSelected listener) {
+ this.listener = listener;
+ }
+
+ public static class ViewHolder extends RecyclerView.ViewHolder {
+
+ private final SearchResultItemBinding binding;
+
+ private ViewHolder(SearchResultItemBinding binding) {
+ super(binding.getRoot());
+ this.binding = binding;
+ }
+ }
+
+ public interface OnChannelSearchResultSelected {
+ void onChannelSearchResult(MuclumbusService.Room result);
+ }
+} \ No newline at end of file