From d83bdd3389f6c90c0b93676ad2e1252f10dbec48 Mon Sep 17 00:00:00 2001 From: androiddevkotlin <64539346+androiddevkotlin@users.noreply.github.com> Date: Mon, 1 Mar 2021 10:24:14 +0200 Subject: [PATCH] Base Choose category and Add new category https://github.com/osmandapp/OsmAnd/issues/10835 --- .../res/layout/add_new_favorite_category.xml | 80 ++++++ ...om_sheet_item_with_descr_and_radio_btn.xml | 1 + OsmAnd/res/values/strings.xml | 1 + .../osmand/plus/activities/MapActivity.java | 5 + .../AddNewFavoriteCategoryBottomSheet.java | 231 ++++++++++++++++++ .../editors/PointEditorFragment.java | 7 +- .../editors/PointEditorFragmentNew.java | 18 +- .../SelectFavoriteCategoryBottomSheet.java | 208 ++++++++++++++++ 8 files changed, 537 insertions(+), 14 deletions(-) create mode 100644 OsmAnd/res/layout/add_new_favorite_category.xml create mode 100644 OsmAnd/src/net/osmand/plus/mapcontextmenu/editors/AddNewFavoriteCategoryBottomSheet.java create mode 100644 OsmAnd/src/net/osmand/plus/mapcontextmenu/editors/SelectFavoriteCategoryBottomSheet.java diff --git a/OsmAnd/res/layout/add_new_favorite_category.xml b/OsmAnd/res/layout/add_new_favorite_category.xml new file mode 100644 index 0000000000..74510f0842 --- /dev/null +++ b/OsmAnd/res/layout/add_new_favorite_category.xml @@ -0,0 +1,80 @@ + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/OsmAnd/res/layout/bottom_sheet_item_with_descr_and_radio_btn.xml b/OsmAnd/res/layout/bottom_sheet_item_with_descr_and_radio_btn.xml index a346825302..d4d052c868 100644 --- a/OsmAnd/res/layout/bottom_sheet_item_with_descr_and_radio_btn.xml +++ b/OsmAnd/res/layout/bottom_sheet_item_with_descr_and_radio_btn.xml @@ -9,6 +9,7 @@ + Select category or add new one Distance by tap A toggle to show or hide the Coordinates widget on the map. Show Coordinates widget diff --git a/OsmAnd/src/net/osmand/plus/activities/MapActivity.java b/OsmAnd/src/net/osmand/plus/activities/MapActivity.java index 2273c91742..cc8340e598 100644 --- a/OsmAnd/src/net/osmand/plus/activities/MapActivity.java +++ b/OsmAnd/src/net/osmand/plus/activities/MapActivity.java @@ -93,6 +93,7 @@ import net.osmand.plus.importfiles.ImportHelper; import net.osmand.plus.mapcontextmenu.AdditionalActionsBottomSheetDialogFragment; import net.osmand.plus.mapcontextmenu.MapContextMenu; import net.osmand.plus.mapcontextmenu.builders.cards.dialogs.ContextMenuCardDialogFragment; +import net.osmand.plus.mapcontextmenu.editors.SelectFavoriteCategoryBottomSheet; import net.osmand.plus.mapcontextmenu.other.DestinationReachedMenu; import net.osmand.plus.mapcontextmenu.other.TrackDetailsMenu; import net.osmand.plus.mapmarkers.MapMarker; @@ -2245,6 +2246,10 @@ public class MapActivity extends OsmandActionBarActivity implements DownloadEven return getFragment(TripRecordingBottomSheet.TAG); } + public SelectFavoriteCategoryBottomSheet getSelectFavoriteCategoryBottomSheet() { + return getFragment(SelectFavoriteCategoryBottomSheet.TAG); + } + public ChooseRouteFragment getChooseRouteFragment() { return getFragment(ChooseRouteFragment.TAG); } diff --git a/OsmAnd/src/net/osmand/plus/mapcontextmenu/editors/AddNewFavoriteCategoryBottomSheet.java b/OsmAnd/src/net/osmand/plus/mapcontextmenu/editors/AddNewFavoriteCategoryBottomSheet.java new file mode 100644 index 0000000000..5b49efe9ed --- /dev/null +++ b/OsmAnd/src/net/osmand/plus/mapcontextmenu/editors/AddNewFavoriteCategoryBottomSheet.java @@ -0,0 +1,231 @@ +package net.osmand.plus.mapcontextmenu.editors; + +import android.content.res.ColorStateList; +import android.os.Bundle; +import android.text.Editable; +import android.text.TextWatcher; +import android.view.View; +import android.view.WindowManager; +import android.widget.LinearLayout; +import android.widget.TextView; + +import androidx.annotation.ColorInt; +import androidx.annotation.NonNull; +import androidx.annotation.Nullable; +import androidx.appcompat.app.AlertDialog; +import androidx.core.content.ContextCompat; +import androidx.fragment.app.Fragment; +import androidx.fragment.app.FragmentActivity; +import androidx.fragment.app.FragmentManager; + +import com.google.android.material.textfield.TextInputEditText; +import com.google.android.material.textfield.TextInputLayout; + +import net.osmand.PlatformUtil; +import net.osmand.plus.FavouritesDbHelper; +import net.osmand.plus.OsmandApplication; +import net.osmand.plus.R; +import net.osmand.plus.UiUtilities; +import net.osmand.plus.activities.MapActivity; +import net.osmand.plus.base.MenuBottomSheetDialogFragment; +import net.osmand.plus.base.bottomsheetmenu.BaseBottomSheetItem; +import net.osmand.plus.base.bottomsheetmenu.simpleitems.TitleItem; +import net.osmand.plus.helpers.ColorDialogs; +import net.osmand.plus.myplaces.AddNewTrackFolderBottomSheet; +import net.osmand.plus.routepreparationmenu.cards.BaseCard; +import net.osmand.plus.track.ColorsCard; +import net.osmand.plus.track.CustomColorBottomSheet; + +import org.apache.commons.logging.Log; + +import java.util.ArrayList; +import java.util.List; + +public class AddNewFavoriteCategoryBottomSheet extends MenuBottomSheetDialogFragment implements CustomColorBottomSheet.ColorPickerListener, BaseCard.CardListener { + + + public static final String TAG = AddNewTrackFolderBottomSheet.class.getName(); + private static final Log LOG = PlatformUtil.getLog(AddNewTrackFolderBottomSheet.class); + private static final String FOLDER_NAME_KEY = "folder_name_key"; + FavouritesDbHelper favoritesHelper; + private boolean isGpx; + private ArrayList gpxCategories; + private int selectedColor; + private ColorsCard colorsCard; + private TextInputEditText editText; + private TextInputLayout nameTextBox; + private String folderName; + private int defaultColor; + private View view; + private String editorTag; + private SelectFavoriteCategoryBottomSheet.CategorySelectionListener selectionListener; + + public static void showInstance(@NonNull FragmentManager fragmentManager, @Nullable Fragment target) { + if (!fragmentManager.isStateSaved()) { + AddNewFavoriteCategoryBottomSheet fragment = new AddNewFavoriteCategoryBottomSheet(); + fragment.setRetainInstance(true); + fragment.setTargetFragment(target, 0); + fragment.show(fragmentManager, TAG); + } + } + + @Override + protected int getRightBottomButtonTextId() { + return R.string.shared_string_save; + } + + private boolean isGpxCategoryExists(@NonNull String name) { + boolean res = false; + if (gpxCategories != null) { + String nameLC = name.toLowerCase(); + for (String category : gpxCategories) { + if (category.toLowerCase().equals(nameLC)) { + res = true; + break; + } + } + } + return res; + } + + @Override + protected void onRightBottomButtonClick() { + String name = editText.getText().toString().trim(); + FragmentActivity activity = getActivity(); + if (activity != null) { + boolean exists = isGpx ? isGpxCategoryExists(name) : favoritesHelper.groupExists(name); + if (exists) { + AlertDialog.Builder b = new AlertDialog.Builder(activity); + b.setMessage(getString(R.string.favorite_category_dublicate_message)); + b.setNegativeButton(R.string.shared_string_ok, null); + b.show(); + } else { + if (activity instanceof MapActivity) { + if (!isGpx) { + favoritesHelper.addEmptyCategory(name, selectedColor); + } + PointEditor editor = ((MapActivity) activity).getContextMenu().getPointEditor(editorTag); + + if (editor != null) { + editor.setCategory(name, selectedColor); + } + + if (selectionListener != null) { + selectionListener.onCategorySelected(name, selectedColor); + } + } + dismiss(); + } + } + } + + @Override + protected UiUtilities.DialogButtonType getRightBottomButtonType() { + return UiUtilities.DialogButtonType.PRIMARY; + } + + @Nullable + public FavouritesDbHelper getHelper() { + return favoritesHelper; + } + + @ColorInt + public int getCategoryColor(String category) { + FavouritesDbHelper helper = getHelper(); + if (helper != null) { + for (FavouritesDbHelper.FavoriteGroup fg : getHelper().getFavoriteGroups()) { + if (fg.getDisplayName(getMyApplication()).equals(category)) { + return fg.getColor(); + } + } + } + return defaultColor; + } + + @Override + public void createMenuItems(Bundle savedInstanceState) { + OsmandApplication app = requiredMyApplication(); + favoritesHelper = app.getFavorites(); + if (savedInstanceState != null) { + folderName = savedInstanceState.getString(FOLDER_NAME_KEY); + } + items.add(new TitleItem(getString(R.string.favorite_category_add_new_title))); + defaultColor = getResources().getColor(R.color.color_favorite); + selectedColor = defaultColor; + + view = UiUtilities.getInflater(app, nightMode).inflate(R.layout.add_new_favorite_category, null); + nameTextBox = view.findViewById(R.id.name_text_box); + nameTextBox.setBoxBackgroundColorResource(nightMode ? R.color.list_background_color_dark : R.color.activity_background_color_light); + nameTextBox.setHint(app.getResources().getString(R.string.favorite_category_name)); + ColorStateList colorStateList = ColorStateList.valueOf(ContextCompat + .getColor(app, nightMode ? R.color.text_color_secondary_dark : R.color.text_color_secondary_light)); + nameTextBox.setDefaultHintTextColor(colorStateList); + editText = view.findViewById(R.id.name_edit_text); + editText.setText(folderName); + if (editText.requestFocus()) { + getActivity().getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_VISIBLE); + } + nameTextBox.setStartIconTintList(ColorStateList.valueOf(selectedColor)); + nameTextBox.setBoxStrokeColorStateList(ColorStateList.valueOf(selectedColor)); + editText.addTextChangedListener(new TextWatcher() { + @Override + public void beforeTextChanged(CharSequence s, int start, int count, int after) { + } + + @Override + public void onTextChanged(CharSequence s, int start, int before, int count) { + } + + @Override + public void afterTextChanged(Editable s) { + + } + }); + BaseBottomSheetItem editFolderName = new BaseBottomSheetItem.Builder() + .setCustomView(view) + .create(); + items.add(editFolderName); + MapActivity mapActivity = (MapActivity) getActivity(); + List colors = new ArrayList<>(); + for (int color : ColorDialogs.pallette) { + colors.add(color); + } + colorsCard = new ColorsCard(mapActivity, selectedColor, this, colors); + colorsCard.setListener(this); + LinearLayout selectColor = view.findViewById(R.id.select_color); + selectColor.addView(colorsCard.build(view.getContext())); + } + + private void updateColorSelector(int color) { + ((TextView) view.findViewById(R.id.color_name)).setText(ColorDialogs.getColorName(color)); + selectedColor = color; + nameTextBox.setStartIconTintList(ColorStateList.valueOf(selectedColor)); + nameTextBox.setBoxStrokeColorStateList(ColorStateList.valueOf(selectedColor)); + } + + @Override + public void onCardLayoutNeeded(@NonNull BaseCard card) { + + } + + @Override + public void onCardPressed(@NonNull BaseCard card) { + if (card instanceof ColorsCard) { + int color = ((ColorsCard) card).getSelectedColor(); + updateColorSelector(color); + } + } + + @Override + public void onCardButtonPressed(@NonNull BaseCard card, int buttonIndex) { + + } + + @Override + public void onColorSelected(Integer prevColor, int newColor) { + colorsCard.onColorSelected(prevColor, newColor); + int color = colorsCard.getSelectedColor(); + updateColorSelector(color); + } + +} diff --git a/OsmAnd/src/net/osmand/plus/mapcontextmenu/editors/PointEditorFragment.java b/OsmAnd/src/net/osmand/plus/mapcontextmenu/editors/PointEditorFragment.java index c24a29ff71..8d118bb7dc 100644 --- a/OsmAnd/src/net/osmand/plus/mapcontextmenu/editors/PointEditorFragment.java +++ b/OsmAnd/src/net/osmand/plus/mapcontextmenu/editors/PointEditorFragment.java @@ -24,6 +24,7 @@ import androidx.appcompat.widget.Toolbar; import androidx.core.content.ContextCompat; import androidx.fragment.app.DialogFragment; import androidx.fragment.app.FragmentActivity; +import androidx.fragment.app.FragmentManager; import net.osmand.AndroidUtils; import net.osmand.plus.OsmandApplication; @@ -136,9 +137,9 @@ public abstract class PointEditorFragment extends BaseOsmAndFragment { @Override public boolean onTouch(final View v, MotionEvent event) { if (event.getAction() == MotionEvent.ACTION_UP) { - DialogFragment dialogFragment = createSelectCategoryDialog(); - if (dialogFragment != null) { - dialogFragment.show(getChildFragmentManager(), SelectCategoryDialogFragment.TAG); + FragmentManager fragmentManager = getFragmentManager(); + if (fragmentManager != null) { + SelectFavoriteCategoryBottomSheet.showInstance(getChildFragmentManager(), getTargetFragment()); } return true; } diff --git a/OsmAnd/src/net/osmand/plus/mapcontextmenu/editors/PointEditorFragmentNew.java b/OsmAnd/src/net/osmand/plus/mapcontextmenu/editors/PointEditorFragmentNew.java index e59ce02373..6f50d80214 100644 --- a/OsmAnd/src/net/osmand/plus/mapcontextmenu/editors/PointEditorFragmentNew.java +++ b/OsmAnd/src/net/osmand/plus/mapcontextmenu/editors/PointEditorFragmentNew.java @@ -38,6 +38,7 @@ import androidx.appcompat.widget.Toolbar; import androidx.core.content.ContextCompat; import androidx.fragment.app.DialogFragment; import androidx.fragment.app.FragmentActivity; +import androidx.fragment.app.FragmentManager; import androidx.recyclerview.widget.LinearLayoutManager; import androidx.recyclerview.widget.RecyclerView; @@ -190,9 +191,9 @@ public abstract class PointEditorFragmentNew extends BaseOsmAndFragment implemen groupList.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { - DialogFragment dialogFragment = createSelectCategoryDialog(); - if (dialogFragment != null) { - dialogFragment.show(getChildFragmentManager(), SelectCategoryDialogFragment.TAG); + FragmentManager fragmentManager = getFragmentManager(); + if (fragmentManager != null) { + SelectFavoriteCategoryBottomSheet.showInstance(getChildFragmentManager(), getTargetFragment()); } } }); @@ -887,8 +888,6 @@ public abstract class PointEditorFragmentNew extends BaseOsmAndFragment implemen return true; } - ; - String getNameTextValue() { EditText nameEdit = view.findViewById(R.id.name_edit); return nameEdit.getText().toString().trim(); @@ -1006,12 +1005,9 @@ public abstract class PointEditorFragmentNew extends BaseOsmAndFragment implemen holder.groupButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { - PointEditor editor = getEditor(); - if (editor != null) { - EditCategoryDialogFragment dialogFragment = - EditCategoryDialogFragment.createInstance(editor.getFragmentTag(), getCategories(), - !editor.getFragmentTag().equals(FavoritePointEditor.TAG)); - dialogFragment.show(requireActivity().getSupportFragmentManager(), EditCategoryDialogFragment.TAG); + FragmentManager fragmentManager = getFragmentManager(); + if (fragmentManager != null) { + SelectFavoriteCategoryBottomSheet.showInstance(getChildFragmentManager(), getTargetFragment()); } } }); diff --git a/OsmAnd/src/net/osmand/plus/mapcontextmenu/editors/SelectFavoriteCategoryBottomSheet.java b/OsmAnd/src/net/osmand/plus/mapcontextmenu/editors/SelectFavoriteCategoryBottomSheet.java new file mode 100644 index 0000000000..131f10da71 --- /dev/null +++ b/OsmAnd/src/net/osmand/plus/mapcontextmenu/editors/SelectFavoriteCategoryBottomSheet.java @@ -0,0 +1,208 @@ +package net.osmand.plus.mapcontextmenu.editors; + +import android.app.Activity; +import android.graphics.PorterDuff; +import android.graphics.Typeface; +import android.graphics.drawable.Drawable; +import android.os.Bundle; +import android.view.View; +import android.widget.LinearLayout; +import android.widget.RadioButton; +import android.widget.TextView; + +import androidx.annotation.NonNull; +import androidx.annotation.Nullable; +import androidx.appcompat.content.res.AppCompatResources; +import androidx.appcompat.widget.AppCompatImageView; +import androidx.core.content.ContextCompat; +import androidx.core.graphics.drawable.DrawableCompat; +import androidx.fragment.app.Fragment; +import androidx.fragment.app.FragmentActivity; +import androidx.fragment.app.FragmentManager; + +import net.osmand.GPXUtilities; +import net.osmand.plus.FavouritesDbHelper; +import net.osmand.plus.OsmandApplication; +import net.osmand.plus.R; +import net.osmand.plus.UiUtilities; +import net.osmand.plus.activities.MapActivity; +import net.osmand.plus.base.MenuBottomSheetDialogFragment; +import net.osmand.plus.base.bottomsheetmenu.BaseBottomSheetItem; +import net.osmand.plus.base.bottomsheetmenu.BottomSheetItemWithDescription; +import net.osmand.plus.base.bottomsheetmenu.SimpleBottomSheetItem; +import net.osmand.plus.base.bottomsheetmenu.simpleitems.DividerItem; +import net.osmand.plus.helpers.AndroidUiHelper; + +import java.util.List; +import java.util.Map; + +public class SelectFavoriteCategoryBottomSheet extends MenuBottomSheetDialogFragment { + + public static final String TAG = SelectFavoriteCategoryBottomSheet.class.getSimpleName(); + private OsmandApplication app; + private GPXUtilities.GPXFile gpxFile; + private String editorTag; + private Map gpxCategories; + private SelectCategoryDialogFragment.CategorySelectionListener selectionListener; + + public static void showInstance(@NonNull FragmentManager fragmentManager, @Nullable Fragment target) { + if (!fragmentManager.isStateSaved()) { + SelectFavoriteCategoryBottomSheet fragment = new SelectFavoriteCategoryBottomSheet(); + fragment.setRetainInstance(true); + fragment.setTargetFragment(target, 0); + fragment.show(fragmentManager, TAG); + } + } + + private static Drawable getIcon(final Activity activity, int iconId) { + OsmandApplication app = (OsmandApplication) activity.getApplication(); + UiUtilities iconsCache = app.getUIUtilities(); + boolean light = app.getSettings().isLightContent(); + return iconsCache.getIcon(iconId, + light ? R.color.icon_color_default_light : R.color.icon_color_default_dark); + } + + private static Drawable getIcon(final Activity activity, int resId, int color) { + Drawable drawable = AppCompatResources.getDrawable(activity, resId); + if (drawable != null) { + drawable = DrawableCompat.wrap(drawable).mutate(); + drawable.clearColorFilter(); + drawable.setColorFilter(color, PorterDuff.Mode.SRC_IN); + } + return drawable; + } + + + public GPXUtilities.GPXFile getGpxFile() { + return gpxFile; + } + + public void setGpxFile(GPXUtilities.GPXFile gpxFile) { + this.gpxFile = gpxFile; + } + + public void setGpxCategories(Map gpxCategories) { + this.gpxCategories = gpxCategories; + } + + @Override + public void createMenuItems(Bundle savedInstanceState) { + app = requiredMyApplication(); + + BaseBottomSheetItem titleItem = new BottomSheetItemWithDescription.Builder() + .setDescription(getString(R.string.select_category_descr)) + .setTitle(getString(R.string.favorite_category_select)) + .setLayoutId(R.layout.bottom_sheet_item_title_with_description) + .create(); + items.add(titleItem); + final FragmentActivity activity = requireActivity(); + + View addNewCategoryView = UiUtilities.getInflater(app, nightMode).inflate(R.layout.bottom_sheet_item_with_descr_64dp, null); + addNewCategoryView.setMinimumHeight(getResources().getDimensionPixelSize(R.dimen.bottom_sheet_list_item_height)); + TextView title = addNewCategoryView.findViewById(R.id.title); + Typeface face = Typeface.createFromAsset(app.getAssets(), + "fonts/Roboto-Medium.ttf"); + title.setTypeface(face); + AndroidUiHelper.updateVisibility(addNewCategoryView.findViewById(R.id.description), false); + BaseBottomSheetItem addNewFolderItem = new SimpleBottomSheetItem.Builder() + .setTitle(getString(R.string.favorite_category_add_new)) + .setTitleColorId(nightMode ? R.color.active_color_primary_dark : R.color.active_color_primary_light) + .setIcon(getActiveIcon(R.drawable.ic_action_folder_add)) + .setLayoutId(R.layout.bottom_sheet_item_with_descr_64dp) + .setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + AddNewFavoriteCategoryBottomSheet.showInstance(getFragmentManager(), getTargetFragment()); + dismiss(); + } + }) + .setCustomView(addNewCategoryView) + .create(); + items.add(addNewFolderItem); + + DividerItem dividerItem = new DividerItem(app); + dividerItem.setMargins(0, 0, 0, 0); + items.add(dividerItem); + + View favoriteCategoryList = UiUtilities.getInflater(app, nightMode).inflate(R.layout.favorite_categories_dialog, null); + LinearLayout favoriteCategoryContainer = favoriteCategoryList.findViewById(R.id.list_container); + + final FavouritesDbHelper helper2 = app.getFavorites(); + if (gpxFile != null) { + if (gpxCategories != null) { + for (Map.Entry e : gpxCategories.entrySet()) { + String categoryName = e.getKey(); + int favoriteCategoryCount = e.getKey().length(); + favoriteCategoryContainer.addView(createCategoryItem(activity, nightMode, categoryName, e.getValue(), favoriteCategoryCount, false, true)); + } + } + } else { + List gs = helper2.getFavoriteGroups(); + for (final FavouritesDbHelper.FavoriteGroup category : gs) { + int favoriteCategoryCount = category.getPoints().size(); + favoriteCategoryContainer.addView(createCategoryItem(activity, nightMode, category.getDisplayName(getContext()), + category.getColor(), favoriteCategoryCount, !category.isVisible(), true)); + } + + items.add(new BaseBottomSheetItem.Builder() + .setCustomView(favoriteCategoryList) + .create()); + } + } + + private View createCategoryItem(@NonNull final Activity activity, boolean nightMode, final String categoryName, final int categoryColor, int categoryPointCount, boolean isHidden, final boolean selected) { + View itemView = UiUtilities.getInflater(activity, nightMode).inflate(R.layout.bottom_sheet_item_with_descr_and_radio_btn, null); + final AppCompatImageView button = (AppCompatImageView) itemView.findViewById(R.id.icon); + LinearLayout test = itemView.findViewById(R.id.descriptionContainer); + test.setPadding(0, 0, 0, 0); + View divider = itemView.findViewById(R.id.divider_bottom); + divider.setVisibility(View.GONE); + itemView.setPadding(0, 0, 0, 0); + final RadioButton compoundButton = itemView.findViewById(R.id.compound_button); + int activeColorId = nightMode ? + R.color.active_color_primary_dark : R.color.active_color_primary_light; + int disableColorId = nightMode ? + R.color.icon_color_default_dark : R.color.icon_color_default_light; + UiUtilities.setupCompoundButton(nightMode, ContextCompat.getColor(app, + nightMode ? activeColorId : disableColorId), compoundButton); + + if (isHidden) { + button.setImageResource(R.drawable.ic_action_hide); + } else { + if (categoryColor != 0) { + button.setImageDrawable(getIcon(activity, R.drawable.ic_action_folder, categoryColor)); + } else { + button.setImageDrawable(getIcon(activity, R.drawable.ic_action_folder, ContextCompat.getColor(activity, + gpxFile != null ? R.color.gpx_color_point : R.color.color_favorite))); + } + } + String name = categoryName.length() == 0 ? getString(R.string.shared_string_favorites) : categoryName; + TextView text = itemView.findViewById(R.id.title); + TextView description = itemView.findViewById(R.id.description); + text.setText(name); + description.setText(String.valueOf(categoryPointCount)); + test.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + FragmentActivity a = getActivity(); + compoundButton.setSelected(true); + if (a instanceof MapActivity) { + PointEditor pointEditor = ((MapActivity) a).getContextMenu().getPointEditor(editorTag); + if (pointEditor != null) { + pointEditor.setCategory(categoryName, categoryColor); + } + if (selectionListener != null) { + selectionListener.onCategorySelected(categoryName, categoryColor); + } + } + dismiss(); + } + }); + return itemView; + } + + public interface CategorySelectionListener { + + void onCategorySelected(String category, int color); + } +}