mirror of
https://github.com/nextcloud/notes-android.git
synced 2024-11-25 22:36:17 +03:00
Also use english category names for category icon replacements
Signed-off-by: Stefan Niedermann <info@niedermann.it>
This commit is contained in:
parent
bdc4f3c303
commit
4b17e5e573
1 changed files with 16 additions and 4 deletions
|
@ -5,6 +5,8 @@ import static java.util.Collections.singletonList;
|
||||||
|
|
||||||
import android.annotation.SuppressLint;
|
import android.annotation.SuppressLint;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
|
import android.content.res.Configuration;
|
||||||
|
import android.content.res.Resources;
|
||||||
import android.graphics.Rect;
|
import android.graphics.Rect;
|
||||||
import android.os.Build;
|
import android.os.Build;
|
||||||
import android.util.TypedValue;
|
import android.util.TypedValue;
|
||||||
|
@ -13,12 +15,13 @@ import android.view.WindowInsets;
|
||||||
|
|
||||||
import androidx.annotation.NonNull;
|
import androidx.annotation.NonNull;
|
||||||
import androidx.core.view.ViewCompat;
|
import androidx.core.view.ViewCompat;
|
||||||
import androidx.core.view.WindowInsetsCompat;
|
|
||||||
|
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.Locale;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
import java.util.stream.Stream;
|
||||||
|
|
||||||
import it.niedermann.owncloud.notes.R;
|
import it.niedermann.owncloud.notes.R;
|
||||||
import it.niedermann.owncloud.notes.main.navigation.NavigationAdapter;
|
import it.niedermann.owncloud.notes.main.navigation.NavigationAdapter;
|
||||||
|
@ -50,13 +53,15 @@ public class DisplayUtils {
|
||||||
|
|
||||||
public static NavigationItem.CategoryNavigationItem convertToCategoryNavigationItem(@NonNull Context context, @NonNull CategoryWithNotesCount counter) {
|
public static NavigationItem.CategoryNavigationItem convertToCategoryNavigationItem(@NonNull Context context, @NonNull CategoryWithNotesCount counter) {
|
||||||
final var res = context.getResources();
|
final var res = context.getResources();
|
||||||
|
final var englishRes = getEnglishResources(context);
|
||||||
final String category = counter.getCategory().replaceAll("\\s+", "");
|
final String category = counter.getCategory().replaceAll("\\s+", "");
|
||||||
int icon = NavigationAdapter.ICON_FOLDER;
|
int icon = NavigationAdapter.ICON_FOLDER;
|
||||||
|
|
||||||
for (Map.Entry<Integer, Collection<Integer>> replacement : SPECIAL_CATEGORY_REPLACEMENTS.entrySet()) {
|
for (Map.Entry<Integer, Collection<Integer>> replacement : SPECIAL_CATEGORY_REPLACEMENTS.entrySet()) {
|
||||||
if (replacement.getValue().stream()
|
if (Stream.concat(
|
||||||
.map(res::getString)
|
replacement.getValue().stream().map(res::getString),
|
||||||
.map(str -> str.replaceAll("\\s+", ""))
|
replacement.getValue().stream().map(englishRes::getString)
|
||||||
|
).map(str -> str.replaceAll("\\s+", ""))
|
||||||
.anyMatch(r -> r.equalsIgnoreCase(category))) {
|
.anyMatch(r -> r.equalsIgnoreCase(category))) {
|
||||||
icon = replacement.getKey();
|
icon = replacement.getKey();
|
||||||
break;
|
break;
|
||||||
|
@ -65,6 +70,13 @@ public class DisplayUtils {
|
||||||
return new NavigationItem.CategoryNavigationItem("category:" + counter.getCategory(), counter.getCategory(), counter.getTotalNotes(), icon, counter.getAccountId(), counter.getCategory());
|
return new NavigationItem.CategoryNavigationItem("category:" + counter.getCategory(), counter.getCategory(), counter.getTotalNotes(), icon, counter.getAccountId(), counter.getCategory());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@NonNull
|
||||||
|
private static Resources getEnglishResources(@NonNull Context context) {
|
||||||
|
final var config = new Configuration(context.getResources().getConfiguration());
|
||||||
|
config.setLocale(new Locale("en"));
|
||||||
|
return context.createConfigurationContext(config).getResources();
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Detect if the soft keyboard is open.
|
* Detect if the soft keyboard is open.
|
||||||
* On API prior to 30 we fall back to workaround which might be less reliable
|
* On API prior to 30 we fall back to workaround which might be less reliable
|
||||||
|
|
Loading…
Reference in a new issue