From 82dcae59e3f150b033b4120680d71ac81b504686 Mon Sep 17 00:00:00 2001 From: Daniel Gultsch Date: Thu, 2 May 2019 20:09:43 +0200 Subject: [PATCH] added language tag in channel search results --- .../http/services/MuclumbusService.java | 7 ++++ .../adapter/ChannelSearchResultAdapter.java | 11 +++++- .../conversations/utils/LanguageUtils.java | 28 +++++++++++++++ src/main/res/layout/search_result_item.xml | 35 +++++++++++++------ 4 files changed, 70 insertions(+), 11 deletions(-) create mode 100644 src/main/java/eu/siacs/conversations/utils/LanguageUtils.java diff --git a/src/main/java/eu/siacs/conversations/http/services/MuclumbusService.java b/src/main/java/eu/siacs/conversations/http/services/MuclumbusService.java index 5ef557c0f..4f2b8f533 100644 --- a/src/main/java/eu/siacs/conversations/http/services/MuclumbusService.java +++ b/src/main/java/eu/siacs/conversations/http/services/MuclumbusService.java @@ -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(); diff --git a/src/main/java/eu/siacs/conversations/ui/adapter/ChannelSearchResultAdapter.java b/src/main/java/eu/siacs/conversations/ui/adapter/ChannelSearchResultAdapter.java index 7d1a7c873..03f09f70c 100644 --- a/src/main/java/eu/siacs/conversations/ui/adapter/ChannelSearchResultAdapter.java +++ b/src/main/java/eu/siacs/conversations/ui/adapter/ChannelSearchResultAdapter.java @@ -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 listener.onChannelSearchResult(searchResult)); diff --git a/src/main/java/eu/siacs/conversations/utils/LanguageUtils.java b/src/main/java/eu/siacs/conversations/utils/LanguageUtils.java new file mode 100644 index 000000000..28cb44343 --- /dev/null +++ b/src/main/java/eu/siacs/conversations/utils/LanguageUtils.java @@ -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 LANGUAGE_MAP; + + static { + ImmutableMap.Builder 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; + } +} diff --git a/src/main/res/layout/search_result_item.xml b/src/main/res/layout/search_result_item.xml index 2d77be1fb..c006dabd8 100644 --- a/src/main/res/layout/search_result_item.xml +++ b/src/main/res/layout/search_result_item.xml @@ -1,6 +1,7 @@ + xmlns:app="http://schemas.android.com/apk/res-auto" + xmlns:tools="http://schemas.android.com/tools"> + app:riv_corner_radius="2dp" /> - + android:layout_marginLeft="@dimen/avatar_item_distance" + android:layout_toRightOf="@+id/avatar"> + android:textAppearance="@style/TextAppearance.Conversations.Subhead" + tools:text="Proosdy IM Chat trantu" /> + + + android:textAppearance="@style/TextAppearance.Conversations.Body1" /> + - + android:textAppearance="@style/TextAppearance.Conversations.Body1.Secondary" /> + \ No newline at end of file