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)
|
if (mTrack == null)
|
||||||
return;
|
return;
|
||||||
final Bundle args = new Bundle();
|
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();
|
final FragmentManager manager = getChildFragmentManager();
|
||||||
String className = BookmarkColorDialogFragment.class.getName();
|
String className = BookmarkColorDialogFragment.class.getName();
|
||||||
final FragmentFactory factory = manager.getFragmentFactory();
|
final FragmentFactory factory = manager.getFragmentFactory();
|
||||||
|
|||||||
@@ -6,6 +6,7 @@ import android.view.LayoutInflater;
|
|||||||
import android.view.View;
|
import android.view.View;
|
||||||
import android.view.ViewGroup;
|
import android.view.ViewGroup;
|
||||||
import android.widget.ArrayAdapter;
|
import android.widget.ArrayAdapter;
|
||||||
|
import androidx.annotation.DrawableRes;
|
||||||
import app.organicmaps.R;
|
import app.organicmaps.R;
|
||||||
import app.organicmaps.sdk.bookmarks.data.PredefinedColors;
|
import app.organicmaps.sdk.bookmarks.data.PredefinedColors;
|
||||||
import app.organicmaps.util.Graphics;
|
import app.organicmaps.util.Graphics;
|
||||||
@@ -18,9 +19,13 @@ public class ColorsAdapter extends ArrayAdapter<Integer>
|
|||||||
@PredefinedColors.Color
|
@PredefinedColors.Color
|
||||||
private int mCheckedIconColor;
|
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);
|
super(context, 0, 0, list);
|
||||||
|
mIconResId = iconResId;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -44,8 +49,7 @@ public class ColorsAdapter extends ArrayAdapter<Integer>
|
|||||||
if (color == mCheckedIconColor)
|
if (color == mCheckedIconColor)
|
||||||
{
|
{
|
||||||
circle = Graphics.drawCircleAndImage(PredefinedColors.getColor(mCheckedIconColor), R.dimen.track_circle_size,
|
circle = Graphics.drawCircleAndImage(PredefinedColors.getColor(mCheckedIconColor), R.dimen.track_circle_size,
|
||||||
app.organicmaps.sdk.R.drawable.ic_bookmark_none, R.dimen.bookmark_icon_size,
|
mIconResId, R.dimen.bookmark_icon_size, getContext());
|
||||||
getContext());
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -16,8 +16,6 @@ public class Icon implements Parcelable
|
|||||||
{
|
{
|
||||||
private static final String TAG = Icon.class.getSimpleName();
|
private static final String TAG = Icon.class.getSimpleName();
|
||||||
|
|
||||||
static final int BOOKMARK_ICON_TYPE_NONE = 0;
|
|
||||||
|
|
||||||
@DrawableRes
|
@DrawableRes
|
||||||
private static int[] sTypeIcons = null;
|
private static int[] sTypeIcons = null;
|
||||||
|
|
||||||
@@ -25,11 +23,6 @@ public class Icon implements Parcelable
|
|||||||
private final int mColor;
|
private final int mColor;
|
||||||
private final int mType;
|
private final int mType;
|
||||||
|
|
||||||
public Icon(@PredefinedColors.Color int color)
|
|
||||||
{
|
|
||||||
this(color, BOOKMARK_ICON_TYPE_NONE);
|
|
||||||
}
|
|
||||||
|
|
||||||
public Icon(@PredefinedColors.Color int color, int type)
|
public Icon(@PredefinedColors.Color int color, int type)
|
||||||
{
|
{
|
||||||
mColor = color;
|
mColor = color;
|
||||||
@@ -75,6 +68,11 @@ public class Icon implements Parcelable
|
|||||||
return sTypeIcons[mType];
|
return sTypeIcons[mType];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public int getType()
|
||||||
|
{
|
||||||
|
return mType;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean equals(Object o)
|
public boolean equals(Object o)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -6,6 +6,7 @@ import android.os.Bundle;
|
|||||||
import android.view.LayoutInflater;
|
import android.view.LayoutInflater;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
import android.widget.GridView;
|
import android.widget.GridView;
|
||||||
|
import androidx.annotation.DrawableRes;
|
||||||
import androidx.annotation.NonNull;
|
import androidx.annotation.NonNull;
|
||||||
import app.organicmaps.R;
|
import app.organicmaps.R;
|
||||||
import app.organicmaps.base.BaseMwmDialogFragment;
|
import app.organicmaps.base.BaseMwmDialogFragment;
|
||||||
@@ -16,11 +17,15 @@ import java.util.List;
|
|||||||
|
|
||||||
public class BookmarkColorDialogFragment extends BaseMwmDialogFragment
|
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
|
@PredefinedColors.Color
|
||||||
private int mIconColor;
|
private int mIconColor;
|
||||||
|
|
||||||
|
@DrawableRes
|
||||||
|
private int mIconResId = app.organicmaps.sdk.R.drawable.ic_bookmark_none;
|
||||||
|
|
||||||
public interface OnBookmarkColorChangeListener
|
public interface OnBookmarkColorChangeListener
|
||||||
{
|
{
|
||||||
void onBookmarkColorSet(@PredefinedColors.Color int color);
|
void onBookmarkColorSet(@PredefinedColors.Color int color);
|
||||||
@@ -35,7 +40,12 @@ public class BookmarkColorDialogFragment extends BaseMwmDialogFragment
|
|||||||
public Dialog onCreateDialog(Bundle savedInstanceState)
|
public Dialog onCreateDialog(Bundle savedInstanceState)
|
||||||
{
|
{
|
||||||
if (getArguments() != null)
|
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)
|
return new MaterialAlertDialogBuilder(requireActivity(), R.style.MwmTheme_AlertDialog)
|
||||||
.setView(buildView())
|
.setView(buildView())
|
||||||
@@ -53,7 +63,7 @@ public class BookmarkColorDialogFragment extends BaseMwmDialogFragment
|
|||||||
private View buildView()
|
private View buildView()
|
||||||
{
|
{
|
||||||
final List<Integer> colors = PredefinedColors.getAllPredefinedColors();
|
final List<Integer> colors = PredefinedColors.getAllPredefinedColors();
|
||||||
final ColorsAdapter adapter = new ColorsAdapter(requireActivity(), colors);
|
final ColorsAdapter adapter = new ColorsAdapter(requireActivity(), colors, mIconResId);
|
||||||
adapter.chooseItem(mIconColor);
|
adapter.chooseItem(mIconColor);
|
||||||
|
|
||||||
@SuppressLint("InflateParams")
|
@SuppressLint("InflateParams")
|
||||||
|
|||||||
@@ -305,9 +305,12 @@ public class EditBookmarkFragment extends BaseMwmDialogFragment implements View.
|
|||||||
|
|
||||||
final Bundle args = new Bundle();
|
final Bundle args = new Bundle();
|
||||||
if (mTrack != null)
|
if (mTrack != null)
|
||||||
args.putInt(BookmarkColorDialogFragment.ICON_TYPE, PredefinedColors.getPredefinedColorIndex(mColor));
|
args.putInt(BookmarkColorDialogFragment.ICON_COLOR, PredefinedColors.getPredefinedColorIndex(mColor));
|
||||||
else
|
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();
|
final FragmentManager manager = getChildFragmentManager();
|
||||||
String className = BookmarkColorDialogFragment.class.getName();
|
String className = BookmarkColorDialogFragment.class.getName();
|
||||||
final FragmentFactory factory = manager.getFragmentFactory();
|
final FragmentFactory factory = manager.getFragmentFactory();
|
||||||
@@ -321,7 +324,7 @@ public class EditBookmarkFragment extends BaseMwmDialogFragment implements View.
|
|||||||
if (mIcon != null && mIcon.getColor() == colorPos)
|
if (mIcon != null && mIcon.getColor() == colorPos)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
mIcon = new Icon(colorPos);
|
mIcon = new Icon(colorPos, mIcon.getType());
|
||||||
refreshColorMarker();
|
refreshColorMarker();
|
||||||
});
|
});
|
||||||
case TYPE_TRACK ->
|
case TYPE_TRACK ->
|
||||||
@@ -342,8 +345,7 @@ public class EditBookmarkFragment extends BaseMwmDialogFragment implements View.
|
|||||||
{
|
{
|
||||||
if (mIcon != null)
|
if (mIcon != null)
|
||||||
{
|
{
|
||||||
Drawable circle = Graphics.drawCircleAndImage(mIcon.argb(), R.dimen.track_circle_size,
|
final Drawable circle = Graphics.drawCircleAndImage(mIcon.argb(), R.dimen.track_circle_size, mIcon.getResId(),
|
||||||
app.organicmaps.sdk.R.drawable.ic_bookmark_none,
|
|
||||||
R.dimen.bookmark_icon_size, requireContext());
|
R.dimen.bookmark_icon_size, requireContext());
|
||||||
mIvColor.setImageDrawable(circle);
|
mIvColor.setImageDrawable(circle);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user