Base Choose category and Add new category
https://github.com/osmandapp/OsmAnd/issues/10835
This commit is contained in:
parent
428327c2cd
commit
d83bdd3389
8 changed files with 537 additions and 14 deletions
80
OsmAnd/res/layout/add_new_favorite_category.xml
Normal file
80
OsmAnd/res/layout/add_new_favorite_category.xml
Normal file
|
@ -0,0 +1,80 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||
xmlns:osmand="http://schemas.android.com/tools"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:orientation="vertical">
|
||||
|
||||
<View
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="0dp"
|
||||
android:focusable="true"
|
||||
android:focusableInTouchMode="true" />
|
||||
|
||||
<com.google.android.material.textfield.TextInputLayout
|
||||
android:id="@+id/name_text_box"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:hint="@string/favorite_category_name"
|
||||
android:paddingStart="@dimen/content_padding"
|
||||
android:paddingLeft="@dimen/content_padding"
|
||||
android:paddingEnd="@dimen/content_padding"
|
||||
android:paddingRight="@dimen/content_padding"
|
||||
app:startIconDrawable="@drawable/ic_action_folder">
|
||||
|
||||
<com.google.android.material.textfield.TextInputEditText
|
||||
android:id="@+id/name_edit_text"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:inputType="textCapSentences"
|
||||
android:lineSpacingMultiplier="@dimen/bottom_sheet_text_spacing_multiplier" />
|
||||
|
||||
</com.google.android.material.textfield.TextInputLayout>
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:orientation="horizontal">
|
||||
|
||||
<net.osmand.plus.widgets.TextViewEx
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_weight="1"
|
||||
android:letterSpacing="@dimen/description_letter_spacing"
|
||||
android:paddingLeft="@dimen/content_padding"
|
||||
android:paddingTop="@dimen/context_menu_first_line_top_margin"
|
||||
android:paddingRight="@dimen/content_padding"
|
||||
android:paddingBottom="@dimen/context_menu_first_line_top_margin"
|
||||
android:text="@string/select_color"
|
||||
android:textColor="?android:textColorSecondary"
|
||||
android:textSize="@dimen/default_desc_text_size"
|
||||
osmand:typeface="@string/font_roboto_medium" />
|
||||
|
||||
<net.osmand.plus.widgets.TextViewEx
|
||||
android:id="@+id/color_name"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:gravity="end"
|
||||
android:letterSpacing="@dimen/description_letter_spacing"
|
||||
android:paddingLeft="@dimen/content_padding"
|
||||
android:paddingTop="@dimen/context_menu_first_line_top_margin"
|
||||
android:paddingRight="@dimen/content_padding"
|
||||
android:paddingBottom="@dimen/context_menu_first_line_top_margin"
|
||||
android:text="@string/select_color"
|
||||
android:textColor="?android:textColorSecondary"
|
||||
android:textSize="@dimen/default_desc_text_size"
|
||||
osmand:typeface="@string/font_roboto_medium" />
|
||||
</LinearLayout>
|
||||
|
||||
<LinearLayout
|
||||
android:id="@+id/select_color"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginStart="@dimen/content_padding_small"
|
||||
android:layout_marginLeft="@dimen/content_padding_small"
|
||||
android:layout_marginTop="@dimen/context_menu_padding_margin_tiny"
|
||||
android:layout_marginBottom="@dimen/content_padding_half"
|
||||
android:orientation="horizontal" />
|
||||
|
||||
</LinearLayout>
|
|
@ -9,6 +9,7 @@
|
|||
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
android:id="@+id/descriptionContainer"
|
||||
android:layout_height="@dimen/bottom_sheet_large_list_item_height"
|
||||
android:gravity="center_vertical"
|
||||
android:orientation="horizontal"
|
||||
|
|
|
@ -12,6 +12,7 @@
|
|||
|
||||
-->
|
||||
|
||||
<string name="select_category_descr">Select category or add new one</string>
|
||||
<string name="map_widget_distance_by_tap">Distance by tap</string>
|
||||
<string name="quick_action_coordinates_widget_descr">A toggle to show or hide the Coordinates widget on the map.</string>
|
||||
<string name="quick_action_coordinates_widget_show">Show Coordinates widget</string>
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
|
|
@ -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<String> 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<Integer> 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);
|
||||
}
|
||||
|
||||
}
|
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -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());
|
||||
}
|
||||
}
|
||||
});
|
||||
|
|
|
@ -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<String, Integer> 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<String, Integer> 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<String, Integer> 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<FavouritesDbHelper.FavoriteGroup> 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);
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue