Optimize special category icons

Signed-off-by: Stefan Niedermann <info@niedermann.it>
This commit is contained in:
Stefan Niedermann 2021-10-08 13:56:45 +02:00
parent 565915d0bd
commit 9a4f84eb61
7 changed files with 82 additions and 8 deletions

View file

@ -1,8 +1,10 @@
package it.niedermann.owncloud.notes.shared.util; package it.niedermann.owncloud.notes.shared.util;
import static java.util.Arrays.asList;
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.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;
@ -15,6 +17,7 @@ import androidx.core.view.WindowInsetsCompat;
import java.util.Collection; import java.util.Collection;
import java.util.List; import java.util.List;
import java.util.Map;
import java.util.stream.Collectors; import java.util.stream.Collectors;
import it.niedermann.owncloud.notes.R; import it.niedermann.owncloud.notes.R;
@ -24,6 +27,17 @@ import it.niedermann.owncloud.notes.persistence.entity.CategoryWithNotesCount;
public class DisplayUtils { public class DisplayUtils {
private static final Map<Integer, Collection<Integer>> SPECIAL_CATEGORY_REPLACEMENTS = Map.of(
R.drawable.ic_library_music_grey600_24dp, singletonList(R.string.category_music),
R.drawable.ic_local_movies_grey600_24dp, asList(R.string.category_movies, R.string.category_movie),
R.drawable.ic_work_grey600_24dp, singletonList(R.string.category_work),
R.drawable.ic_baseline_checklist_24, asList(R.string.category_todo, R.string.category_todos, R.string.category_tasks, R.string.category_checklists),
R.drawable.ic_baseline_fastfood_24, asList(R.string.category_recipe, R.string.category_recipes, R.string.category_restaurant, R.string.category_restaurants, R.string.category_food, R.string.category_bake),
R.drawable.ic_baseline_vpn_key_24, asList(R.string.category_key, R.string.category_keys, R.string.category_password, R.string.category_passwords, R.string.category_credentials),
R.drawable.ic_baseline_games_24, asList(R.string.category_game, R.string.category_games, R.string.category_play),
R.drawable.ic_baseline_card_giftcard_24, asList(R.string.category_gift, R.string.category_gifts, R.string.category_present, R.string.category_presents)
);
private DisplayUtils() { private DisplayUtils() {
throw new UnsupportedOperationException("Do not instantiate this util class."); throw new UnsupportedOperationException("Do not instantiate this util class.");
} }
@ -36,14 +50,17 @@ 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 String category = counter.getCategory().toLowerCase(); final String category = counter.getCategory().replaceAll("\\s+", "");
int icon = NavigationAdapter.ICON_FOLDER; int icon = NavigationAdapter.ICON_FOLDER;
if (category.equals(res.getString(R.string.category_music).toLowerCase())) {
icon = R.drawable.ic_library_music_grey600_24dp; for (Map.Entry<Integer, Collection<Integer>> replacement : SPECIAL_CATEGORY_REPLACEMENTS.entrySet()) {
} else if (category.equals(res.getString(R.string.category_movies).toLowerCase()) || category.equals(res.getString(R.string.category_movie).toLowerCase())) { if (replacement.getValue().stream()
icon = R.drawable.ic_local_movies_grey600_24dp; .map(res::getString)
} else if (category.equals(res.getString(R.string.category_work).toLowerCase())) { .map(str -> str.replaceAll("\\s+", ""))
icon = R.drawable.ic_work_grey600_24dp; .anyMatch(r -> r.equalsIgnoreCase(category))) {
icon = replacement.getKey();
break;
}
} }
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());
} }

View file

@ -0,0 +1,5 @@
<vector android:autoMirrored="true" android:height="24dp"
android:tint="#757575" android:viewportHeight="24"
android:viewportWidth="24" android:width="24dp" xmlns:android="http://schemas.android.com/apk/res/android">
<path android:fillColor="@android:color/white" android:pathData="M20,6h-2.18c0.11,-0.31 0.18,-0.65 0.18,-1 0,-1.66 -1.34,-3 -3,-3 -1.05,0 -1.96,0.54 -2.5,1.35l-0.5,0.67 -0.5,-0.68C10.96,2.54 10.05,2 9,2 7.34,2 6,3.34 6,5c0,0.35 0.07,0.69 0.18,1L4,6c-1.11,0 -1.99,0.89 -1.99,2L2,19c0,1.11 0.89,2 2,2h16c1.11,0 2,-0.89 2,-2L22,8c0,-1.11 -0.89,-2 -2,-2zM15,4c0.55,0 1,0.45 1,1s-0.45,1 -1,1 -1,-0.45 -1,-1 0.45,-1 1,-1zM9,4c0.55,0 1,0.45 1,1s-0.45,1 -1,1 -1,-0.45 -1,-1 0.45,-1 1,-1zM20,19L4,19v-2h16v2zM20,14L4,14L4,8h5.08L7,10.83 8.62,12 11,8.76l1,-1.36 1,1.36L15.38,12 17,10.83 14.92,8L20,8v6z"/>
</vector>

View file

@ -0,0 +1,11 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:autoMirrored="true"
android:tint="#757575"
android:viewportWidth="24"
android:viewportHeight="24">
<path
android:fillColor="#FF757575"
android:pathData="M22,7h-9v2h9V7zM22,15h-9v2h9V15zM5.54,11L2,7.46l1.41,-1.41l2.12,2.12l4.24,-4.24l1.41,1.41L5.54,11zM5.54,19L2,15.46l1.41,-1.41l2.12,2.12l4.24,-4.24l1.41,1.41L5.54,19z" />
</vector>

View file

@ -0,0 +1,5 @@
<vector android:autoMirrored="true" android:height="24dp"
android:tint="#757575" android:viewportHeight="24"
android:viewportWidth="24" android:width="24dp" xmlns:android="http://schemas.android.com/apk/res/android">
<path android:fillColor="#FF757575" android:pathData="M18.06,22.99h1.66c0.84,0 1.53,-0.64 1.63,-1.46L23,5.05h-5L18,1h-1.97v4.05h-4.97l0.3,2.34c1.71,0.47 3.31,1.32 4.27,2.26 1.44,1.42 2.43,2.89 2.43,5.29v8.05zM1,21.99L1,21h15.03v0.99c0,0.55 -0.45,1 -1.01,1L2.01,22.99c-0.56,0 -1.01,-0.45 -1.01,-1zM16.03,14.99c0,-8 -15.03,-8 -15.03,0h15.03zM1.02,17h15v2h-15z"/>
</vector>

View file

@ -0,0 +1,5 @@
<vector android:autoMirrored="true" android:height="24dp"
android:tint="#757575" android:viewportHeight="24"
android:viewportWidth="24" android:width="24dp" xmlns:android="http://schemas.android.com/apk/res/android">
<path android:fillColor="#FF757575" android:pathData="M15,7.5V2H9v5.5l3,3 3,-3zM7.5,9H2v6h5.5l3,-3 -3,-3zM9,16.5V22h6v-5.5l-3,-3 -3,3zM16.5,9l-3,3 3,3H22V9h-5.5z"/>
</vector>

View file

@ -0,0 +1,5 @@
<vector android:autoMirrored="true" android:height="24dp"
android:tint="#757575" android:viewportHeight="24"
android:viewportWidth="24" android:width="24dp" xmlns:android="http://schemas.android.com/apk/res/android">
<path android:fillColor="#FF757575" android:pathData="M12.65,10C11.83,7.67 9.61,6 7,6c-3.31,0 -6,2.69 -6,6s2.69,6 6,6c2.61,0 4.83,-1.67 5.65,-4H17v4h4v-4h2v-4H12.65zM7,14c-1.1,0 -2,-0.9 -2,-2s0.9,-2 2,-2 2,0.9 2,2 -0.9,2 -2,2z"/>
</vector>

View file

@ -140,6 +140,32 @@
<string name="category_movies">Movies</string> <string name="category_movies">Movies</string>
<string name="category_movie">Movie</string> <string name="category_movie">Movie</string>
<string name="category_work">Work</string> <string name="category_work">Work</string>
<string name="category_todo">ToDo</string>
<string name="category_todos">ToDos</string>
<string name="category_checklists">Check lists</string>
<string name="category_tasks">Tasks</string>
<string name="category_recipe">Recipe</string>
<string name="category_recipes">Recipes</string>
<string name="category_restaurant">Restaurant</string>
<string name="category_restaurants">Restaurants</string>
<string name="category_food">Food</string>
<string name="category_bake">Bake</string>
<string name="category_key">Key</string>
<string name="category_keys">Keys</string>
<string name="category_password">Password</string>
<string name="category_passwords">Passwords</string>
<string name="category_credentials">Credential</string>
<string name="category_game">Game</string>
<string name="category_games">Games</string>
<string name="category_play">Play</string>
<string name="category_gift">Gift</string>
<string name="category_gifts">Gifts</string>
<string name="category_present">Present</string>
<string name="category_presents">Presents</string>
<string name="account_already_imported">Account has already been imported</string> <string name="account_already_imported">Account has already been imported</string>
<string name="no_notes_yet">No notes yet</string> <string name="no_notes_yet">No notes yet</string>
<string name="no_notes_yet_description">Press + button to create a new note</string> <string name="no_notes_yet_description">Press + button to create a new note</string>