added language tag in channel search results

This commit is contained in:
Daniel Gultsch 2019-05-02 20:09:43 +02:00
parent 818f2ab61c
commit 82dcae59e3
4 changed files with 70 additions and 11 deletions

View File

@ -4,9 +4,11 @@ import com.google.common.base.Objects;
import java.util.Collections;
import java.util.List;
import java.util.Map;
import java.util.Set;
import eu.siacs.conversations.services.AvatarService;
import eu.siacs.conversations.utils.LanguageUtils;
import eu.siacs.conversations.utils.UIHelper;
import retrofit2.Call;
import retrofit2.http.Body;
@ -35,6 +37,7 @@ public interface MuclumbusService {
public String address;
public String name;
public String description;
public String language;
public String getName() {
return name;
@ -52,6 +55,10 @@ public interface MuclumbusService {
}
}
public String getLanguage() {
return LanguageUtils.convert(language);
}
@Override
public int getAvatarBackgroundColor() {
Jid room = getRoom();

View File

@ -10,6 +10,8 @@ import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import java.util.Locale;
import eu.siacs.conversations.R;
import eu.siacs.conversations.databinding.SearchResultItemBinding;
import eu.siacs.conversations.http.services.MuclumbusService;
@ -38,7 +40,7 @@ public class ChannelSearchResultAdapter extends ListAdapter<MuclumbusService.Roo
@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));
return new ViewHolder(DataBindingUtil.inflate(LayoutInflater.from(viewGroup.getContext()), R.layout.search_result_item, viewGroup, false));
}
@Override
@ -46,12 +48,19 @@ public class ChannelSearchResultAdapter extends ListAdapter<MuclumbusService.Roo
final MuclumbusService.Room searchResult = getItem(position);
viewHolder.binding.name.setText(searchResult.getName());
final String description = searchResult.getDescription();
final String language = searchResult.getLanguage();
if (TextUtils.isEmpty(description)) {
viewHolder.binding.description.setVisibility(View.GONE);
} else {
viewHolder.binding.description.setText(description);
viewHolder.binding.description.setVisibility(View.VISIBLE);
}
if (language == null || language.length() != 2) {
viewHolder.binding.language.setVisibility(View.GONE);
} else {
viewHolder.binding.language.setText(language.toUpperCase(Locale.ENGLISH));
viewHolder.binding.language.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));

View File

@ -0,0 +1,28 @@
package eu.siacs.conversations.utils;
import com.google.common.collect.ImmutableMap;
import java.util.Locale;
import java.util.Map;
public class LanguageUtils {
private static final Map<String,String> LANGUAGE_MAP;
static {
ImmutableMap.Builder<String, String> builder = new ImmutableMap.Builder<>();
builder.put("german","de");
builder.put("deutsch","de");
builder.put("english","en");
builder.put("russian","ru");
LANGUAGE_MAP = builder.build();
}
public static String convert(final String in) {
if (in == null) {
return null;
}
final String out = LANGUAGE_MAP.get(in.toLowerCase(Locale.US));
return out == null ? in : out;
}
}

View File

@ -1,6 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<layout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto">
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools">
<RelativeLayout
android:layout_width="match_parent"
@ -14,35 +15,49 @@
android:layout_height="48dp"
android:layout_alignParentLeft="true"
android:scaleType="centerCrop"
app:riv_corner_radius="2dp"/>
app:riv_corner_radius="2dp" />
<LinearLayout
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_toRightOf="@+id/avatar"
android:orientation="vertical"
android:layout_marginLeft="@dimen/avatar_item_distance">
android:layout_marginLeft="@dimen/avatar_item_distance"
android:layout_toRightOf="@+id/avatar">
<TextView
android:id="@+id/name"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:singleLine="true"
android:textAppearance="@style/TextAppearance.Conversations.Subhead"/>
android:textAppearance="@style/TextAppearance.Conversations.Subhead"
tools:text="Proosdy IM Chat trantu" />
<TextView
android:id="@+id/language"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBaseline="@id/name"
android:layout_marginLeft="8sp"
android:layout_toRightOf="@id/name"
android:singleLine="true"
android:textAppearance="@style/TextAppearance.Conversations.Caption"
tools:text="EN" />
<TextView
android:id="@+id/description"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@id/name"
android:maxLines="2"
android:textAppearance="@style/TextAppearance.Conversations.Body1"/>
android:textAppearance="@style/TextAppearance.Conversations.Body1" />
<TextView
android:id="@+id/room"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@id/description"
android:maxLines="2"
android:textAppearance="@style/TextAppearance.Conversations.Body1.Secondary"/>
</LinearLayout>
android:textAppearance="@style/TextAppearance.Conversations.Body1.Secondary" />
</RelativeLayout>
</RelativeLayout>
</layout>