mirror of
https://codeberg.org/comaps/comaps
synced 2025-12-21 22:03:37 +00:00
[android] Show bookmark icon in color selector
Signed-off-by: Andrei Shkrob <github@shkrob.dev>
This commit is contained in:
committed by
Konstantin Pastbin
parent
d0bb8c1c49
commit
1c8ac1f32a
@@ -593,7 +593,7 @@ public class BookmarksListFragment extends BaseMwmRecyclerFragment<ConcatAdapter
|
||||
if (mTrack == null)
|
||||
return;
|
||||
final Bundle args = new Bundle();
|
||||
args.putInt(BookmarkColorDialogFragment.ICON_TYPE, PredefinedColors.getPredefinedColorIndex(mTrack.getColor()));
|
||||
args.putInt(BookmarkColorDialogFragment.ICON_COLOR, PredefinedColors.getPredefinedColorIndex(mTrack.getColor()));
|
||||
final FragmentManager manager = getChildFragmentManager();
|
||||
String className = BookmarkColorDialogFragment.class.getName();
|
||||
final FragmentFactory factory = manager.getFragmentFactory();
|
||||
|
||||
@@ -6,6 +6,7 @@ import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.ArrayAdapter;
|
||||
import androidx.annotation.DrawableRes;
|
||||
import app.organicmaps.R;
|
||||
import app.organicmaps.sdk.bookmarks.data.PredefinedColors;
|
||||
import app.organicmaps.util.Graphics;
|
||||
@@ -18,9 +19,13 @@ public class ColorsAdapter extends ArrayAdapter<Integer>
|
||||
@PredefinedColors.Color
|
||||
private int mCheckedIconColor;
|
||||
|
||||
public ColorsAdapter(Context context, List<Integer> list)
|
||||
@DrawableRes
|
||||
private final int mIconResId;
|
||||
|
||||
public ColorsAdapter(Context context, List<Integer> list, @DrawableRes int iconResId)
|
||||
{
|
||||
super(context, 0, 0, list);
|
||||
mIconResId = iconResId;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -44,8 +49,7 @@ public class ColorsAdapter extends ArrayAdapter<Integer>
|
||||
if (color == mCheckedIconColor)
|
||||
{
|
||||
circle = Graphics.drawCircleAndImage(PredefinedColors.getColor(mCheckedIconColor), R.dimen.track_circle_size,
|
||||
app.organicmaps.sdk.R.drawable.ic_bookmark_none, R.dimen.bookmark_icon_size,
|
||||
getContext());
|
||||
mIconResId, R.dimen.bookmark_icon_size, getContext());
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
@@ -16,8 +16,6 @@ public class Icon implements Parcelable
|
||||
{
|
||||
private static final String TAG = Icon.class.getSimpleName();
|
||||
|
||||
static final int BOOKMARK_ICON_TYPE_NONE = 0;
|
||||
|
||||
@DrawableRes
|
||||
private static int[] sTypeIcons = null;
|
||||
|
||||
@@ -25,11 +23,6 @@ public class Icon implements Parcelable
|
||||
private final int mColor;
|
||||
private final int mType;
|
||||
|
||||
public Icon(@PredefinedColors.Color int color)
|
||||
{
|
||||
this(color, BOOKMARK_ICON_TYPE_NONE);
|
||||
}
|
||||
|
||||
public Icon(@PredefinedColors.Color int color, int type)
|
||||
{
|
||||
mColor = color;
|
||||
@@ -75,6 +68,11 @@ public class Icon implements Parcelable
|
||||
return sTypeIcons[mType];
|
||||
}
|
||||
|
||||
public int getType()
|
||||
{
|
||||
return mType;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o)
|
||||
{
|
||||
|
||||
@@ -6,6 +6,7 @@ import android.os.Bundle;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.widget.GridView;
|
||||
import androidx.annotation.DrawableRes;
|
||||
import androidx.annotation.NonNull;
|
||||
import app.organicmaps.R;
|
||||
import app.organicmaps.base.BaseMwmDialogFragment;
|
||||
@@ -16,11 +17,15 @@ import java.util.List;
|
||||
|
||||
public class BookmarkColorDialogFragment extends BaseMwmDialogFragment
|
||||
{
|
||||
public static final String ICON_TYPE = "ExtraIconType";
|
||||
public static final String ICON_COLOR = "ExtraIconColor";
|
||||
public static final String ICON_RES = "ExtraIconRes";
|
||||
|
||||
@PredefinedColors.Color
|
||||
private int mIconColor;
|
||||
|
||||
@DrawableRes
|
||||
private int mIconResId = app.organicmaps.sdk.R.drawable.ic_bookmark_none;
|
||||
|
||||
public interface OnBookmarkColorChangeListener
|
||||
{
|
||||
void onBookmarkColorSet(@PredefinedColors.Color int color);
|
||||
@@ -35,7 +40,12 @@ public class BookmarkColorDialogFragment extends BaseMwmDialogFragment
|
||||
public Dialog onCreateDialog(Bundle savedInstanceState)
|
||||
{
|
||||
if (getArguments() != null)
|
||||
mIconColor = getArguments().getInt(ICON_TYPE);
|
||||
{
|
||||
if (getArguments().containsKey(ICON_COLOR))
|
||||
mIconColor = getArguments().getInt(ICON_COLOR);
|
||||
if (getArguments().containsKey(ICON_RES))
|
||||
mIconResId = getArguments().getInt(ICON_RES);
|
||||
}
|
||||
|
||||
return new MaterialAlertDialogBuilder(requireActivity(), R.style.MwmTheme_AlertDialog)
|
||||
.setView(buildView())
|
||||
@@ -53,7 +63,7 @@ public class BookmarkColorDialogFragment extends BaseMwmDialogFragment
|
||||
private View buildView()
|
||||
{
|
||||
final List<Integer> colors = PredefinedColors.getAllPredefinedColors();
|
||||
final ColorsAdapter adapter = new ColorsAdapter(requireActivity(), colors);
|
||||
final ColorsAdapter adapter = new ColorsAdapter(requireActivity(), colors, mIconResId);
|
||||
adapter.chooseItem(mIconColor);
|
||||
|
||||
@SuppressLint("InflateParams")
|
||||
|
||||
@@ -305,9 +305,12 @@ public class EditBookmarkFragment extends BaseMwmDialogFragment implements View.
|
||||
|
||||
final Bundle args = new Bundle();
|
||||
if (mTrack != null)
|
||||
args.putInt(BookmarkColorDialogFragment.ICON_TYPE, PredefinedColors.getPredefinedColorIndex(mColor));
|
||||
args.putInt(BookmarkColorDialogFragment.ICON_COLOR, PredefinedColors.getPredefinedColorIndex(mColor));
|
||||
else
|
||||
args.putInt(BookmarkColorDialogFragment.ICON_TYPE, mIcon.getColor());
|
||||
{
|
||||
args.putInt(BookmarkColorDialogFragment.ICON_COLOR, mIcon.getColor());
|
||||
args.putInt(BookmarkColorDialogFragment.ICON_RES, mIcon.getResId());
|
||||
}
|
||||
final FragmentManager manager = getChildFragmentManager();
|
||||
String className = BookmarkColorDialogFragment.class.getName();
|
||||
final FragmentFactory factory = manager.getFragmentFactory();
|
||||
@@ -321,7 +324,7 @@ public class EditBookmarkFragment extends BaseMwmDialogFragment implements View.
|
||||
if (mIcon != null && mIcon.getColor() == colorPos)
|
||||
return;
|
||||
|
||||
mIcon = new Icon(colorPos);
|
||||
mIcon = new Icon(colorPos, mIcon.getType());
|
||||
refreshColorMarker();
|
||||
});
|
||||
case TYPE_TRACK ->
|
||||
@@ -342,9 +345,8 @@ public class EditBookmarkFragment extends BaseMwmDialogFragment implements View.
|
||||
{
|
||||
if (mIcon != null)
|
||||
{
|
||||
Drawable circle = Graphics.drawCircleAndImage(mIcon.argb(), R.dimen.track_circle_size,
|
||||
app.organicmaps.sdk.R.drawable.ic_bookmark_none,
|
||||
R.dimen.bookmark_icon_size, requireContext());
|
||||
final Drawable circle = Graphics.drawCircleAndImage(mIcon.argb(), R.dimen.track_circle_size, mIcon.getResId(),
|
||||
R.dimen.bookmark_icon_size, requireContext());
|
||||
mIvColor.setImageDrawable(circle);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user