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.Collections;
import java.util.List; import java.util.List;
import java.util.Map;
import java.util.Set; import java.util.Set;
import eu.siacs.conversations.services.AvatarService; import eu.siacs.conversations.services.AvatarService;
import eu.siacs.conversations.utils.LanguageUtils;
import eu.siacs.conversations.utils.UIHelper; import eu.siacs.conversations.utils.UIHelper;
import retrofit2.Call; import retrofit2.Call;
import retrofit2.http.Body; import retrofit2.http.Body;
@ -35,6 +37,7 @@ public interface MuclumbusService {
public String address; public String address;
public String name; public String name;
public String description; public String description;
public String language;
public String getName() { public String getName() {
return name; return name;
@ -52,6 +55,10 @@ public interface MuclumbusService {
} }
} }
public String getLanguage() {
return LanguageUtils.convert(language);
}
@Override @Override
public int getAvatarBackgroundColor() { public int getAvatarBackgroundColor() {
Jid room = getRoom(); Jid room = getRoom();

View file

@ -10,6 +10,8 @@ import android.view.LayoutInflater;
import android.view.View; import android.view.View;
import android.view.ViewGroup; import android.view.ViewGroup;
import java.util.Locale;
import eu.siacs.conversations.R; import eu.siacs.conversations.R;
import eu.siacs.conversations.databinding.SearchResultItemBinding; import eu.siacs.conversations.databinding.SearchResultItemBinding;
import eu.siacs.conversations.http.services.MuclumbusService; import eu.siacs.conversations.http.services.MuclumbusService;
@ -46,12 +48,19 @@ public class ChannelSearchResultAdapter extends ListAdapter<MuclumbusService.Roo
final MuclumbusService.Room searchResult = getItem(position); final MuclumbusService.Room searchResult = getItem(position);
viewHolder.binding.name.setText(searchResult.getName()); viewHolder.binding.name.setText(searchResult.getName());
final String description = searchResult.getDescription(); final String description = searchResult.getDescription();
final String language = searchResult.getLanguage();
if (TextUtils.isEmpty(description)) { if (TextUtils.isEmpty(description)) {
viewHolder.binding.description.setVisibility(View.GONE); viewHolder.binding.description.setVisibility(View.GONE);
} else { } else {
viewHolder.binding.description.setText(description); viewHolder.binding.description.setText(description);
viewHolder.binding.description.setVisibility(View.VISIBLE); 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()); viewHolder.binding.room.setText(searchResult.getRoom().asBareJid().toString());
AvatarWorkerTask.loadAvatar(searchResult, viewHolder.binding.avatar, R.dimen.avatar); AvatarWorkerTask.loadAvatar(searchResult, viewHolder.binding.avatar, R.dimen.avatar);
viewHolder.binding.getRoot().setOnClickListener(v -> listener.onChannelSearchResult(searchResult)); 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"?> <?xml version="1.0" encoding="utf-8"?>
<layout xmlns:android="http://schemas.android.com/apk/res/android" <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 <RelativeLayout
android:layout_width="match_parent" android:layout_width="match_parent"
@ -16,33 +17,47 @@
android:scaleType="centerCrop" android:scaleType="centerCrop"
app:riv_corner_radius="2dp" /> app:riv_corner_radius="2dp" />
<LinearLayout <RelativeLayout
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_toRightOf="@+id/avatar" android:layout_marginLeft="@dimen/avatar_item_distance"
android:orientation="vertical" android:layout_toRightOf="@+id/avatar">
android:layout_marginLeft="@dimen/avatar_item_distance">
<TextView <TextView
android:id="@+id/name" android:id="@+id/name"
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:singleLine="true" 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 <TextView
android:id="@+id/description" android:id="@+id/description"
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_below="@id/name"
android:maxLines="2" android:maxLines="2"
android:textAppearance="@style/TextAppearance.Conversations.Body1" /> android:textAppearance="@style/TextAppearance.Conversations.Body1" />
<TextView <TextView
android:id="@+id/room" android:id="@+id/room"
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_below="@id/description"
android:maxLines="2" android:maxLines="2"
android:textAppearance="@style/TextAppearance.Conversations.Body1.Secondary" /> android:textAppearance="@style/TextAppearance.Conversations.Body1.Secondary" />
</LinearLayout> </RelativeLayout>
</RelativeLayout> </RelativeLayout>
</layout> </layout>