Merge pull request #5105 from osmandapp/EditFavBottomSheet
added new ButtomSheet to editFavouriteGroup
This commit is contained in:
commit
6292c37028
3 changed files with 200 additions and 428 deletions
39
OsmAnd/res/layout/change_fav_color.xml
Normal file
39
OsmAnd/res/layout/change_fav_color.xml
Normal file
|
@ -0,0 +1,39 @@
|
||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
|
android:id="@+id/change_color_view"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:background="?attr/selectableItemBackground"
|
||||||
|
android:gravity="center_vertical"
|
||||||
|
android:minHeight="@dimen/list_item_height"
|
||||||
|
android:orientation="horizontal"
|
||||||
|
android:paddingLeft="@dimen/list_content_padding"
|
||||||
|
android:paddingRight="@dimen/list_content_padding">
|
||||||
|
|
||||||
|
<ImageView
|
||||||
|
android:id="@+id/change_color_icon"
|
||||||
|
android:layout_width="@dimen/standard_icon_size"
|
||||||
|
android:layout_height="@dimen/standard_icon_size"
|
||||||
|
android:layout_gravity="center_vertical"
|
||||||
|
android:layout_marginEnd="@dimen/bottom_sheet_icon_margin"
|
||||||
|
android:layout_marginRight="@dimen/bottom_sheet_icon_margin"
|
||||||
|
android:src="@drawable/ic_action_appearance" />
|
||||||
|
|
||||||
|
<TextView
|
||||||
|
android:id="@+id/title"
|
||||||
|
android:layout_width="0dp"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_gravity="center_vertical"
|
||||||
|
android:layout_weight="1"
|
||||||
|
android:ellipsize="end"
|
||||||
|
android:maxLines="1"
|
||||||
|
android:text="@string/change_color"
|
||||||
|
android:textAppearance="@style/TextAppearance.ListItemTitle" />
|
||||||
|
|
||||||
|
<android.support.v7.widget.AppCompatImageView
|
||||||
|
android:id="@+id/colorImage"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:src="@drawable/ic_action_circle" />
|
||||||
|
|
||||||
|
</LinearLayout>
|
|
@ -1,249 +0,0 @@
|
||||||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
|
||||||
xmlns:tools="http://schemas.android.com/tools"
|
|
||||||
android:layout_width="match_parent"
|
|
||||||
android:layout_height="wrap_content"
|
|
||||||
xmlns:osmand="http://schemas.android.com/apk/res-auto"
|
|
||||||
android:layout_gravity="bottom"
|
|
||||||
android:background="?attr/bottom_menu_view_bg"
|
|
||||||
android:orientation="vertical"
|
|
||||||
tools:context="net.osmand.plus.download.ui.DataStoragePlaceDialogFragment">
|
|
||||||
|
|
||||||
<LinearLayout
|
|
||||||
android:layout_width="match_parent"
|
|
||||||
android:layout_height="wrap_content"
|
|
||||||
android:orientation="vertical">
|
|
||||||
|
|
||||||
<LinearLayout
|
|
||||||
android:layout_width="match_parent"
|
|
||||||
android:layout_height="wrap_content"
|
|
||||||
android:orientation="horizontal"
|
|
||||||
android:minHeight="@dimen/list_item_height"
|
|
||||||
android:paddingLeft="@dimen/list_content_padding"
|
|
||||||
android:paddingRight="@dimen/list_content_padding"
|
|
||||||
android:gravity="center_vertical">
|
|
||||||
|
|
||||||
<net.osmand.plus.widgets.TextViewEx
|
|
||||||
android:id="@+id/title"
|
|
||||||
android:layout_width="match_parent"
|
|
||||||
android:layout_height="wrap_content"
|
|
||||||
android:paddingTop="6dp"
|
|
||||||
android:paddingBottom="6dp"
|
|
||||||
android:textColor="?android:attr/textColorPrimary"
|
|
||||||
android:textSize="@dimen/default_list_text_size"
|
|
||||||
osmand:typeface="@string/font_roboto_medium"
|
|
||||||
tools:text="Category"/>
|
|
||||||
|
|
||||||
</LinearLayout>
|
|
||||||
|
|
||||||
<ScrollView
|
|
||||||
android:layout_width="match_parent"
|
|
||||||
android:layout_height="match_parent">
|
|
||||||
|
|
||||||
<LinearLayout
|
|
||||||
android:layout_width="match_parent"
|
|
||||||
android:layout_height="wrap_content"
|
|
||||||
android:orientation="vertical">
|
|
||||||
|
|
||||||
<LinearLayout
|
|
||||||
android:id="@+id/edit_name_view"
|
|
||||||
android:layout_width="match_parent"
|
|
||||||
android:layout_height="wrap_content"
|
|
||||||
android:minHeight="@dimen/list_item_height"
|
|
||||||
android:background="?attr/selectableItemBackground"
|
|
||||||
android:paddingLeft="@dimen/list_content_padding"
|
|
||||||
android:paddingRight="@dimen/list_content_padding"
|
|
||||||
android:orientation="horizontal"
|
|
||||||
android:gravity="center_vertical">
|
|
||||||
|
|
||||||
<ImageView
|
|
||||||
android:id="@+id/edit_name_icon"
|
|
||||||
android:layout_width="wrap_content"
|
|
||||||
android:layout_height="wrap_content"
|
|
||||||
android:src="@drawable/ic_action_edit_dark"/>
|
|
||||||
|
|
||||||
<TextView
|
|
||||||
android:layout_width="match_parent"
|
|
||||||
android:layout_height="wrap_content"
|
|
||||||
android:paddingLeft="@dimen/list_content_padding"
|
|
||||||
android:paddingTop="6dp"
|
|
||||||
android:paddingBottom="6dp"
|
|
||||||
android:textColor="?android:attr/textColorPrimary"
|
|
||||||
android:textSize="@dimen/default_list_text_size"
|
|
||||||
android:text="@string/edit_name"/>
|
|
||||||
|
|
||||||
</LinearLayout>
|
|
||||||
|
|
||||||
<LinearLayout
|
|
||||||
android:id="@+id/change_color_view"
|
|
||||||
android:layout_width="match_parent"
|
|
||||||
android:layout_height="wrap_content"
|
|
||||||
android:minHeight="@dimen/list_item_height"
|
|
||||||
android:background="?attr/selectableItemBackground"
|
|
||||||
android:paddingLeft="@dimen/list_content_padding"
|
|
||||||
android:paddingRight="@dimen/list_content_padding"
|
|
||||||
android:orientation="horizontal"
|
|
||||||
android:gravity="center_vertical">
|
|
||||||
|
|
||||||
<ImageView
|
|
||||||
android:id="@+id/change_color_icon"
|
|
||||||
android:layout_width="wrap_content"
|
|
||||||
android:layout_height="wrap_content"
|
|
||||||
android:src="@drawable/ic_action_appearance"/>
|
|
||||||
|
|
||||||
<TextView
|
|
||||||
android:layout_width="0dp"
|
|
||||||
android:layout_height="wrap_content"
|
|
||||||
android:layout_weight="1"
|
|
||||||
android:paddingLeft="@dimen/list_content_padding"
|
|
||||||
android:paddingTop="6dp"
|
|
||||||
android:paddingBottom="6dp"
|
|
||||||
android:textColor="?android:attr/textColorPrimary"
|
|
||||||
android:textSize="@dimen/default_list_text_size"
|
|
||||||
android:text="@string/change_color"/>
|
|
||||||
|
|
||||||
<android.support.v7.widget.AppCompatImageView
|
|
||||||
android:id="@+id/colorImage"
|
|
||||||
android:layout_width="wrap_content"
|
|
||||||
android:layout_height="wrap_content"
|
|
||||||
android:src="@drawable/ic_action_circle"/>
|
|
||||||
|
|
||||||
</LinearLayout>
|
|
||||||
|
|
||||||
<LinearLayout
|
|
||||||
android:id="@+id/show_on_map_view"
|
|
||||||
android:layout_width="match_parent"
|
|
||||||
android:layout_height="wrap_content"
|
|
||||||
android:minHeight="@dimen/list_item_height"
|
|
||||||
android:background="?attr/selectableItemBackground"
|
|
||||||
android:paddingLeft="@dimen/list_content_padding"
|
|
||||||
android:paddingRight="@dimen/list_content_padding"
|
|
||||||
android:orientation="horizontal"
|
|
||||||
android:gravity="center_vertical">
|
|
||||||
|
|
||||||
<ImageView
|
|
||||||
android:id="@+id/show_on_map_icon"
|
|
||||||
android:layout_width="wrap_content"
|
|
||||||
android:layout_height="wrap_content"
|
|
||||||
android:src="@drawable/ic_map"/>
|
|
||||||
|
|
||||||
<TextView
|
|
||||||
android:layout_width="0dp"
|
|
||||||
android:layout_height="wrap_content"
|
|
||||||
android:layout_weight="1"
|
|
||||||
android:paddingLeft="@dimen/list_content_padding"
|
|
||||||
android:paddingTop="6dp"
|
|
||||||
android:paddingBottom="6dp"
|
|
||||||
android:paddingRight="8dp"
|
|
||||||
android:textColor="?android:attr/textColorPrimary"
|
|
||||||
android:textSize="@dimen/default_list_text_size"
|
|
||||||
android:text="@string/shared_string_show_on_map"/>
|
|
||||||
|
|
||||||
<android.support.v7.widget.SwitchCompat
|
|
||||||
android:id="@+id/show_on_map_switch"
|
|
||||||
android:layout_width="wrap_content"
|
|
||||||
android:layout_height="wrap_content"
|
|
||||||
android:clickable="false"/>
|
|
||||||
|
|
||||||
</LinearLayout>
|
|
||||||
|
|
||||||
<View
|
|
||||||
android:id="@+id/divider"
|
|
||||||
android:layout_width="match_parent"
|
|
||||||
android:layout_height="1dp"
|
|
||||||
android:background="?attr/dashboard_divider"/>
|
|
||||||
|
|
||||||
<LinearLayout
|
|
||||||
android:id="@+id/add_to_markers_view"
|
|
||||||
android:layout_width="match_parent"
|
|
||||||
android:layout_height="wrap_content"
|
|
||||||
android:minHeight="@dimen/list_item_height"
|
|
||||||
android:background="?attr/selectableItemBackground"
|
|
||||||
android:paddingLeft="@dimen/list_content_padding"
|
|
||||||
android:paddingRight="@dimen/list_content_padding"
|
|
||||||
android:orientation="horizontal"
|
|
||||||
android:gravity="center_vertical">
|
|
||||||
|
|
||||||
<ImageView
|
|
||||||
android:id="@+id/add_to_markers_icon"
|
|
||||||
android:layout_width="wrap_content"
|
|
||||||
android:layout_height="wrap_content"
|
|
||||||
android:src="@drawable/ic_action_flag_dark"/>
|
|
||||||
|
|
||||||
<TextView
|
|
||||||
android:layout_width="match_parent"
|
|
||||||
android:layout_height="wrap_content"
|
|
||||||
android:paddingLeft="@dimen/list_content_padding"
|
|
||||||
android:paddingTop="6dp"
|
|
||||||
android:paddingBottom="6dp"
|
|
||||||
android:textColor="?android:attr/textColorPrimary"
|
|
||||||
android:textSize="@dimen/default_list_text_size"
|
|
||||||
android:text="@string/shared_string_add_to_map_markers"/>
|
|
||||||
|
|
||||||
</LinearLayout>
|
|
||||||
|
|
||||||
<LinearLayout
|
|
||||||
android:id="@+id/remove_from_markers_view"
|
|
||||||
android:layout_width="match_parent"
|
|
||||||
android:layout_height="wrap_content"
|
|
||||||
android:background="?attr/selectableItemBackground"
|
|
||||||
android:gravity="center_vertical"
|
|
||||||
android:minHeight="@dimen/list_item_height"
|
|
||||||
android:paddingLeft="@dimen/list_content_padding"
|
|
||||||
android:paddingRight="@dimen/list_content_padding"
|
|
||||||
android:visibility="gone"
|
|
||||||
tools:visibility="visible">
|
|
||||||
|
|
||||||
<ImageView
|
|
||||||
android:id="@+id/remove_from_markers_icon"
|
|
||||||
android:layout_width="wrap_content"
|
|
||||||
android:layout_height="wrap_content"
|
|
||||||
tools:src="@drawable/ic_action_delete_dark"/>
|
|
||||||
|
|
||||||
<TextView
|
|
||||||
android:layout_width="match_parent"
|
|
||||||
android:layout_height="wrap_content"
|
|
||||||
android:paddingBottom="6dp"
|
|
||||||
android:paddingLeft="@dimen/list_content_padding"
|
|
||||||
android:paddingTop="6dp"
|
|
||||||
android:text="@string/remove_from_map_markers"
|
|
||||||
android:textColor="?android:attr/textColorPrimary"
|
|
||||||
android:textSize="@dimen/default_list_text_size"/>
|
|
||||||
|
|
||||||
</LinearLayout>
|
|
||||||
|
|
||||||
<LinearLayout
|
|
||||||
android:id="@+id/share_view"
|
|
||||||
android:layout_width="match_parent"
|
|
||||||
android:layout_height="wrap_content"
|
|
||||||
android:minHeight="@dimen/list_item_height"
|
|
||||||
android:background="?attr/selectableItemBackground"
|
|
||||||
android:paddingLeft="@dimen/list_content_padding"
|
|
||||||
android:paddingRight="@dimen/list_content_padding"
|
|
||||||
android:orientation="horizontal"
|
|
||||||
android:gravity="center_vertical">
|
|
||||||
|
|
||||||
<ImageView
|
|
||||||
android:id="@+id/share_icon"
|
|
||||||
android:layout_width="wrap_content"
|
|
||||||
android:layout_height="wrap_content"
|
|
||||||
android:src="@drawable/ic_action_gshare_dark"/>
|
|
||||||
|
|
||||||
<TextView
|
|
||||||
android:layout_width="match_parent"
|
|
||||||
android:layout_height="wrap_content"
|
|
||||||
android:paddingLeft="@dimen/list_content_padding"
|
|
||||||
android:paddingTop="6dp"
|
|
||||||
android:paddingBottom="6dp"
|
|
||||||
android:textColor="?android:attr/textColorPrimary"
|
|
||||||
android:textSize="@dimen/default_list_text_size"
|
|
||||||
android:text="@string/shared_string_share"/>
|
|
||||||
|
|
||||||
</LinearLayout>
|
|
||||||
|
|
||||||
</LinearLayout>
|
|
||||||
|
|
||||||
</ScrollView>
|
|
||||||
|
|
||||||
</LinearLayout>
|
|
||||||
|
|
||||||
</LinearLayout>
|
|
|
@ -1,6 +1,5 @@
|
||||||
package net.osmand.plus.activities;
|
package net.osmand.plus.activities;
|
||||||
|
|
||||||
import android.app.Activity;
|
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.content.DialogInterface;
|
import android.content.DialogInterface;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
|
@ -9,13 +8,11 @@ import android.support.v4.app.Fragment;
|
||||||
import android.support.v4.app.FragmentManager;
|
import android.support.v4.app.FragmentManager;
|
||||||
import android.support.v7.app.AlertDialog;
|
import android.support.v7.app.AlertDialog;
|
||||||
import android.support.v7.widget.ListPopupWindow;
|
import android.support.v7.widget.ListPopupWindow;
|
||||||
import android.support.v7.widget.SwitchCompat;
|
import android.view.ContextThemeWrapper;
|
||||||
import android.view.Gravity;
|
import android.view.Gravity;
|
||||||
import android.view.LayoutInflater;
|
import android.view.LayoutInflater;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
import android.view.ViewGroup;
|
import android.view.ViewGroup;
|
||||||
import android.view.Window;
|
|
||||||
import android.view.WindowManager;
|
|
||||||
import android.widget.AdapterView;
|
import android.widget.AdapterView;
|
||||||
import android.widget.ArrayAdapter;
|
import android.widget.ArrayAdapter;
|
||||||
import android.widget.EditText;
|
import android.widget.EditText;
|
||||||
|
@ -25,209 +22,195 @@ import android.widget.TextView;
|
||||||
import net.osmand.AndroidUtils;
|
import net.osmand.AndroidUtils;
|
||||||
import net.osmand.plus.FavouritesDbHelper;
|
import net.osmand.plus.FavouritesDbHelper;
|
||||||
import net.osmand.plus.FavouritesDbHelper.FavoriteGroup;
|
import net.osmand.plus.FavouritesDbHelper.FavoriteGroup;
|
||||||
import net.osmand.plus.IconsCache;
|
|
||||||
import net.osmand.plus.MapMarkersHelper;
|
import net.osmand.plus.MapMarkersHelper;
|
||||||
import net.osmand.plus.MapMarkersHelper.MarkersSyncGroup;
|
import net.osmand.plus.MapMarkersHelper.MarkersSyncGroup;
|
||||||
import net.osmand.plus.OsmandApplication;
|
import net.osmand.plus.OsmandApplication;
|
||||||
import net.osmand.plus.R;
|
import net.osmand.plus.R;
|
||||||
import net.osmand.plus.base.BottomSheetDialogFragment;
|
import net.osmand.plus.base.MenuBottomSheetDialogFragment;
|
||||||
|
import net.osmand.plus.base.bottomsheetmenu.BaseBottomSheetItem;
|
||||||
|
import net.osmand.plus.base.bottomsheetmenu.BottomSheetItemWithCompoundButton;
|
||||||
|
import net.osmand.plus.base.bottomsheetmenu.SimpleBottomSheetItem;
|
||||||
|
import net.osmand.plus.base.bottomsheetmenu.simpleitems.DividerHalfItem;
|
||||||
|
import net.osmand.plus.base.bottomsheetmenu.simpleitems.TitleItem;
|
||||||
import net.osmand.plus.helpers.ColorDialogs;
|
import net.osmand.plus.helpers.ColorDialogs;
|
||||||
import net.osmand.util.Algorithms;
|
import net.osmand.util.Algorithms;
|
||||||
|
|
||||||
public class EditFavoriteGroupDialogFragment extends BottomSheetDialogFragment {
|
public class EditFavoriteGroupDialogFragment extends MenuBottomSheetDialogFragment {
|
||||||
|
|
||||||
public static final String TAG = "EditFavoriteGroupDialogFragment";
|
public static final String TAG = "EditFavoriteGroupDialogFragment";
|
||||||
private static final String GROUP_NAME_KEY = "group_name_key";
|
private static final String GROUP_NAME_KEY = "group_name_key";
|
||||||
|
|
||||||
private OsmandApplication app;
|
|
||||||
private FavoriteGroup group;
|
private FavoriteGroup group;
|
||||||
private FavouritesDbHelper helper;
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onStart() {
|
public void createMenuItems(Bundle savedInstanceState) {
|
||||||
super.onStart();
|
final OsmandApplication app = getMyApplication();
|
||||||
|
FavouritesDbHelper helper = app.getFavorites();
|
||||||
final Window window = getDialog().getWindow();
|
Bundle args = getArguments();
|
||||||
WindowManager.LayoutParams params = window.getAttributes();
|
|
||||||
params.height = ViewGroup.LayoutParams.WRAP_CONTENT;
|
|
||||||
params.gravity = Gravity.BOTTOM;
|
|
||||||
params.width = ViewGroup.LayoutParams.MATCH_PARENT;
|
|
||||||
window.setAttributes(params);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
|
|
||||||
|
|
||||||
final Activity activity = getActivity();
|
|
||||||
app = (OsmandApplication) activity.getApplicationContext();
|
|
||||||
helper = app.getFavorites();
|
|
||||||
|
|
||||||
Bundle args = null;
|
|
||||||
if (savedInstanceState != null) {
|
|
||||||
args = savedInstanceState;
|
|
||||||
} else if (getArguments() != null) {
|
|
||||||
args = getArguments();
|
|
||||||
}
|
|
||||||
|
|
||||||
if (args != null) {
|
if (args != null) {
|
||||||
String groupName = args.getString(GROUP_NAME_KEY);
|
String groupName = args.getString(GROUP_NAME_KEY);
|
||||||
if (groupName != null) {
|
if (groupName != null) {
|
||||||
group = helper.getGroup(groupName);
|
group = helper.getGroup(groupName);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
final View view = inflater.inflate(R.layout.edit_fav_fragment, container,
|
|
||||||
false);
|
|
||||||
if (group == null) {
|
if (group == null) {
|
||||||
return view;
|
return;
|
||||||
|
}
|
||||||
|
items.add(new TitleItem(Algorithms.isEmpty(group.name) ? app.getString(R.string.shared_string_favorites) : group.name));
|
||||||
|
|
||||||
|
BaseBottomSheetItem editNameItem = new SimpleBottomSheetItem.Builder()
|
||||||
|
.setIcon(getContentIcon(R.drawable.ic_action_edit_dark))
|
||||||
|
.setTitle(getString(R.string.edit_name))
|
||||||
|
.setLayoutId(R.layout.bottom_sheet_item_simple)
|
||||||
|
.setOnClickListener(new View.OnClickListener() {
|
||||||
|
@Override
|
||||||
|
public void onClick(View v) {
|
||||||
|
AlertDialog.Builder b = new AlertDialog.Builder(getContext());
|
||||||
|
b.setTitle(R.string.favorite_group_name);
|
||||||
|
final EditText nameEditText = new EditText(getContext());
|
||||||
|
nameEditText.setText(group.name);
|
||||||
|
b.setView(nameEditText);
|
||||||
|
b.setNegativeButton(R.string.shared_string_cancel, null);
|
||||||
|
b.setPositiveButton(R.string.shared_string_save, new DialogInterface.OnClickListener() {
|
||||||
|
@Override
|
||||||
|
public void onClick(DialogInterface dialog, int which) {
|
||||||
|
String name = nameEditText.getText().toString();
|
||||||
|
boolean nameChanged = !Algorithms.objectEquals(group.name, name);
|
||||||
|
if (nameChanged) {
|
||||||
|
app.getFavorites()
|
||||||
|
.editFavouriteGroup(group, name, group.color, group.visible);
|
||||||
|
updateParentFragment();
|
||||||
|
}
|
||||||
|
dismiss();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
b.show();
|
||||||
|
}
|
||||||
|
})
|
||||||
|
.create();
|
||||||
|
items.add(editNameItem);
|
||||||
|
|
||||||
|
final int themeRes = nightMode ? R.style.OsmandDarkTheme : R.style.OsmandLightTheme;
|
||||||
|
final View changeColorView = View.inflate(new ContextThemeWrapper(getContext(), themeRes),
|
||||||
|
R.layout.change_fav_color, null);
|
||||||
|
((ImageView) changeColorView.findViewById(R.id.change_color_icon))
|
||||||
|
.setImageDrawable(getContentIcon(R.drawable.ic_action_appearance));
|
||||||
|
updateColorView((ImageView) changeColorView.findViewById(R.id.colorImage));
|
||||||
|
BaseBottomSheetItem changeColorItem = new BaseBottomSheetItem.Builder()
|
||||||
|
.setCustomView(changeColorView)
|
||||||
|
.setOnClickListener(new View.OnClickListener() {
|
||||||
|
@Override
|
||||||
|
public void onClick(View v) {
|
||||||
|
final ListPopupWindow popup = new ListPopupWindow(getActivity());
|
||||||
|
popup.setAnchorView(changeColorView);
|
||||||
|
popup.setContentWidth(AndroidUtils.dpToPx(app, 200f));
|
||||||
|
popup.setModal(true);
|
||||||
|
popup.setDropDownGravity(Gravity.END | Gravity.TOP);
|
||||||
|
popup.setVerticalOffset(AndroidUtils.dpToPx(app, -48f));
|
||||||
|
popup.setHorizontalOffset(AndroidUtils.dpToPx(app, -6f));
|
||||||
|
final FavoriteColorAdapter colorAdapter = new FavoriteColorAdapter(getActivity());
|
||||||
|
popup.setAdapter(colorAdapter);
|
||||||
|
popup.setOnItemClickListener(new AdapterView.OnItemClickListener() {
|
||||||
|
@Override
|
||||||
|
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
|
||||||
|
Integer color = colorAdapter.getItem(position);
|
||||||
|
if (color != null) {
|
||||||
|
if (color != group.color) {
|
||||||
|
app.getFavorites()
|
||||||
|
.editFavouriteGroup(group, group.name, color, group.visible);
|
||||||
|
updateParentFragment();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
popup.dismiss();
|
||||||
|
dismiss();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
popup.show();
|
||||||
|
}
|
||||||
|
})
|
||||||
|
.create();
|
||||||
|
items.add(changeColorItem);
|
||||||
|
|
||||||
|
BaseBottomSheetItem showOnMapItem = new BottomSheetItemWithCompoundButton.Builder()
|
||||||
|
.setChecked(group.visible)
|
||||||
|
.setIcon(getContentIcon(R.drawable.ic_map))
|
||||||
|
.setTitle(getString(R.string.shared_string_show_on_map))
|
||||||
|
.setLayoutId(R.layout.bottom_sheet_item_with_switch)
|
||||||
|
.setOnClickListener(new View.OnClickListener() {
|
||||||
|
@Override
|
||||||
|
public void onClick(View v) {
|
||||||
|
boolean visible = !group.visible;
|
||||||
|
app.getFavorites()
|
||||||
|
.editFavouriteGroup(group, group.name, group.color, visible);
|
||||||
|
updateParentFragment();
|
||||||
|
dismiss();
|
||||||
|
}
|
||||||
|
})
|
||||||
|
.create();
|
||||||
|
items.add(showOnMapItem);
|
||||||
|
|
||||||
|
if (group.points.size() > 0) {
|
||||||
|
items.add(new DividerHalfItem(getContext()));
|
||||||
}
|
}
|
||||||
|
|
||||||
IconsCache ic = app.getIconsCache();
|
final MapMarkersHelper markersHelper = app.getMapMarkersHelper();
|
||||||
|
|
||||||
final TextView title = (TextView) view.findViewById(R.id.title);
|
|
||||||
title.setText(Algorithms.isEmpty(group.name) ? app.getString(R.string.shared_string_favorites) : group.name);
|
|
||||||
View editNameView = view.findViewById(R.id.edit_name_view);
|
|
||||||
((ImageView) view.findViewById(R.id.edit_name_icon))
|
|
||||||
.setImageDrawable(ic.getThemedIcon(R.drawable.ic_action_edit_dark));
|
|
||||||
editNameView.setOnClickListener(new View.OnClickListener() {
|
|
||||||
@Override
|
|
||||||
public void onClick(View v) {
|
|
||||||
AlertDialog.Builder b = new AlertDialog.Builder(activity);
|
|
||||||
b.setTitle(R.string.favorite_group_name);
|
|
||||||
final EditText nameEditText = new EditText(activity);
|
|
||||||
nameEditText.setText(group.name);
|
|
||||||
int leftPadding = AndroidUtils.dpToPx(activity, 24f);
|
|
||||||
int topPadding = AndroidUtils.dpToPx(activity, 4f);
|
|
||||||
b.setView(nameEditText, leftPadding, topPadding, leftPadding, topPadding);
|
|
||||||
b.setNegativeButton(R.string.shared_string_cancel, null);
|
|
||||||
b.setPositiveButton(R.string.shared_string_save, new DialogInterface.OnClickListener() {
|
|
||||||
@Override
|
|
||||||
public void onClick(DialogInterface dialog, int which) {
|
|
||||||
String name = nameEditText.getText().toString();
|
|
||||||
boolean nameChanged = !Algorithms.objectEquals(group.name, name);
|
|
||||||
if (nameChanged) {
|
|
||||||
getMyApplication().getFavorites()
|
|
||||||
.editFavouriteGroup(group, name, group.color, group.visible);
|
|
||||||
updateParentFragment();
|
|
||||||
}
|
|
||||||
dismiss();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
b.show();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
final View changeColorView = view.findViewById(R.id.change_color_view);
|
|
||||||
((ImageView) view.findViewById(R.id.change_color_icon))
|
|
||||||
.setImageDrawable(ic.getThemedIcon(R.drawable.ic_action_appearance));
|
|
||||||
updateColorView(changeColorView);
|
|
||||||
changeColorView.setOnClickListener(new View.OnClickListener() {
|
|
||||||
@Override
|
|
||||||
public void onClick(View v) {
|
|
||||||
final ListPopupWindow popup = new ListPopupWindow(getActivity());
|
|
||||||
popup.setAnchorView(changeColorView);
|
|
||||||
popup.setContentWidth(AndroidUtils.dpToPx(app, 200f));
|
|
||||||
popup.setModal(true);
|
|
||||||
popup.setDropDownGravity(Gravity.RIGHT | Gravity.TOP);
|
|
||||||
popup.setVerticalOffset(AndroidUtils.dpToPx(app, -48f));
|
|
||||||
popup.setHorizontalOffset(AndroidUtils.dpToPx(app, -6f));
|
|
||||||
final FavoriteColorAdapter colorAdapter = new FavoriteColorAdapter(getActivity());
|
|
||||||
popup.setAdapter(colorAdapter);
|
|
||||||
popup.setOnItemClickListener(new AdapterView.OnItemClickListener() {
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
|
|
||||||
Integer color = colorAdapter.getItem(position);
|
|
||||||
if (color != null) {
|
|
||||||
if (color != group.color) {
|
|
||||||
getMyApplication().getFavorites()
|
|
||||||
.editFavouriteGroup(group, group.name, color, group.visible);
|
|
||||||
updateParentFragment();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
popup.dismiss();
|
|
||||||
dismiss();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
popup.show();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
View showOnMapView = view.findViewById(R.id.show_on_map_view);
|
|
||||||
((ImageView) view.findViewById(R.id.show_on_map_icon))
|
|
||||||
.setImageDrawable(ic.getThemedIcon(R.drawable.ic_map));
|
|
||||||
final SwitchCompat checkbox = (SwitchCompat) view.findViewById(R.id.show_on_map_switch);
|
|
||||||
checkbox.setChecked(group.visible);
|
|
||||||
showOnMapView.setOnClickListener(new View.OnClickListener() {
|
|
||||||
@Override
|
|
||||||
public void onClick(View v) {
|
|
||||||
boolean visible = !group.visible;
|
|
||||||
checkbox.setChecked(visible);
|
|
||||||
getMyApplication().getFavorites()
|
|
||||||
.editFavouriteGroup(group, group.name, group.color, visible);
|
|
||||||
updateParentFragment();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
final MapMarkersHelper markersHelper = getMyApplication().getMapMarkersHelper();
|
|
||||||
final MarkersSyncGroup syncGroup =
|
final MarkersSyncGroup syncGroup =
|
||||||
new MarkersSyncGroup(group.name, group.name, MarkersSyncGroup.FAVORITES_TYPE, group.color);
|
new MarkersSyncGroup(group.name, group.name, MarkersSyncGroup.FAVORITES_TYPE, group.color);
|
||||||
boolean groupSyncedWithMarkers = markersHelper.isGroupSynced(syncGroup.getId());
|
boolean groupSyncedWithMarkers = markersHelper.isGroupSynced(syncGroup.getId());
|
||||||
|
|
||||||
View addToMarkersView = view.findViewById(R.id.add_to_markers_view);
|
|
||||||
if (app.getSettings().USE_MAP_MARKERS.get() && group.points.size() > 0 && !groupSyncedWithMarkers) {
|
if (app.getSettings().USE_MAP_MARKERS.get() && group.points.size() > 0 && !groupSyncedWithMarkers) {
|
||||||
((ImageView) view.findViewById(R.id.add_to_markers_icon))
|
BaseBottomSheetItem addToMarkersItem = new SimpleBottomSheetItem.Builder()
|
||||||
.setImageDrawable(ic.getThemedIcon(R.drawable.ic_action_flag_dark));
|
.setIcon(getContentIcon(R.drawable.ic_action_flag_dark))
|
||||||
addToMarkersView.setOnClickListener(new View.OnClickListener() {
|
.setTitle(getString(R.string.shared_string_add_to_map_markers))
|
||||||
@Override
|
.setLayoutId(R.layout.bottom_sheet_item_simple)
|
||||||
public void onClick(View v) {
|
.setOnClickListener(new View.OnClickListener() {
|
||||||
markersHelper.addMarkersSyncGroup(syncGroup);
|
@Override
|
||||||
markersHelper.syncGroupAsync(syncGroup);
|
public void onClick(View v) {
|
||||||
dismiss();
|
markersHelper.addMarkersSyncGroup(syncGroup);
|
||||||
MapActivity.launchMapActivityMoveToTop(getActivity());
|
markersHelper.syncGroupAsync(syncGroup);
|
||||||
}
|
dismiss();
|
||||||
});
|
MapActivity.launchMapActivityMoveToTop(getActivity());
|
||||||
} else {
|
}
|
||||||
addToMarkersView.setVisibility(View.GONE);
|
})
|
||||||
|
.create();
|
||||||
|
items.add(addToMarkersItem);
|
||||||
}
|
}
|
||||||
|
|
||||||
View removeFromMarkersView = view.findViewById(R.id.remove_from_markers_view);
|
|
||||||
if (app.getSettings().USE_MAP_MARKERS.get() && groupSyncedWithMarkers) {
|
if (app.getSettings().USE_MAP_MARKERS.get() && groupSyncedWithMarkers) {
|
||||||
removeFromMarkersView.setVisibility(View.VISIBLE);
|
BaseBottomSheetItem removeFromMarkersItem = new SimpleBottomSheetItem.Builder()
|
||||||
((ImageView) view.findViewById(R.id.remove_from_markers_icon))
|
.setIcon(getContentIcon(R.drawable.ic_action_delete_dark))
|
||||||
.setImageDrawable(ic.getThemedIcon(R.drawable.ic_action_delete_dark));
|
.setTitle(getString(R.string.remove_from_map_markers))
|
||||||
removeFromMarkersView.setOnClickListener(new View.OnClickListener() {
|
.setLayoutId(R.layout.bottom_sheet_item_simple)
|
||||||
@Override
|
.setOnClickListener(new View.OnClickListener() {
|
||||||
public void onClick(View view) {
|
@Override
|
||||||
markersHelper.removeMarkersSyncGroup(syncGroup.getId(), true);
|
public void onClick(View view) {
|
||||||
dismiss();
|
markersHelper.removeMarkersSyncGroup(syncGroup.getId(), true);
|
||||||
MapActivity.launchMapActivityMoveToTop(getActivity());
|
dismiss();
|
||||||
}
|
MapActivity.launchMapActivityMoveToTop(getActivity());
|
||||||
});
|
}
|
||||||
|
})
|
||||||
|
.create();
|
||||||
|
items.add(removeFromMarkersItem);
|
||||||
}
|
}
|
||||||
|
|
||||||
View shareView = view.findViewById(R.id.share_view);
|
|
||||||
if (group.points.size() > 0) {
|
if (group.points.size() > 0) {
|
||||||
((ImageView) view.findViewById(R.id.share_icon))
|
BaseBottomSheetItem shareItem = new SimpleBottomSheetItem.Builder()
|
||||||
.setImageDrawable(ic.getThemedIcon(R.drawable.ic_action_gshare_dark));
|
.setIcon(getContentIcon(R.drawable.ic_action_gshare_dark))
|
||||||
shareView.setOnClickListener(new View.OnClickListener() {
|
.setTitle(getString(R.string.shared_string_share))
|
||||||
@Override
|
.setLayoutId(R.layout.bottom_sheet_item_simple)
|
||||||
public void onClick(View v) {
|
.setOnClickListener(new View.OnClickListener() {
|
||||||
FavoritesTreeFragment fragment = getFavoritesTreeFragment();
|
@Override
|
||||||
if (fragment != null) {
|
public void onClick(View view) {
|
||||||
fragment.shareFavorites(group);
|
FavoritesTreeFragment fragment = getFavoritesTreeFragment();
|
||||||
}
|
if (fragment != null) {
|
||||||
dismiss();
|
fragment.shareFavorites(group);
|
||||||
}
|
}
|
||||||
});
|
dismiss();
|
||||||
} else {
|
}
|
||||||
shareView.setVisibility(View.GONE);
|
})
|
||||||
|
.create();
|
||||||
|
items.add(shareItem);
|
||||||
}
|
}
|
||||||
if (group.points.size() == 0) {
|
|
||||||
view.findViewById(R.id.divider).setVisibility(View.GONE);
|
|
||||||
}
|
|
||||||
|
|
||||||
return view;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -253,13 +236,12 @@ public class EditFavoriteGroupDialogFragment extends BottomSheetDialogFragment {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void updateColorView(View colorView) {
|
private void updateColorView(ImageView colorImageView) {
|
||||||
ImageView colorImageView = (ImageView) colorView.findViewById(R.id.colorImage);
|
|
||||||
int color = group.color == 0 ? getResources().getColor(R.color.color_favorite) : group.color;
|
int color = group.color == 0 ? getResources().getColor(R.color.color_favorite) : group.color;
|
||||||
if (color == 0) {
|
if (color == 0) {
|
||||||
colorImageView.setImageDrawable(app.getIconsCache().getThemedIcon(R.drawable.ic_action_circle));
|
colorImageView.setImageDrawable(getContentIcon(R.drawable.ic_action_circle));
|
||||||
} else {
|
} else {
|
||||||
colorImageView.setImageDrawable(app.getIconsCache().getPaintedIcon(R.drawable.ic_action_circle, color));
|
colorImageView.setImageDrawable(getMyApplication().getIconsCache().getPaintedIcon(R.drawable.ic_action_circle, color));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -273,9 +255,9 @@ public class EditFavoriteGroupDialogFragment extends BottomSheetDialogFragment {
|
||||||
|
|
||||||
public static class FavoriteColorAdapter extends ArrayAdapter<Integer> {
|
public static class FavoriteColorAdapter extends ArrayAdapter<Integer> {
|
||||||
|
|
||||||
private OsmandApplication app;
|
private final OsmandApplication app;
|
||||||
|
|
||||||
public FavoriteColorAdapter(Context context) {
|
FavoriteColorAdapter(Context context) {
|
||||||
super(context, R.layout.rendering_prop_menu_item);
|
super(context, R.layout.rendering_prop_menu_item);
|
||||||
this.app = (OsmandApplication) getContext().getApplicationContext();
|
this.app = (OsmandApplication) getContext().getApplicationContext();
|
||||||
init();
|
init();
|
||||||
|
@ -293,7 +275,7 @@ public class EditFavoriteGroupDialogFragment extends BottomSheetDialogFragment {
|
||||||
Integer color = getItem(position);
|
Integer color = getItem(position);
|
||||||
View v = convertView;
|
View v = convertView;
|
||||||
if (v == null) {
|
if (v == null) {
|
||||||
v = LayoutInflater.from(getContext()).inflate(R.layout.rendering_prop_menu_item, null);
|
v = LayoutInflater.from(getContext()).inflate(R.layout.rendering_prop_menu_item, parent, false);
|
||||||
}
|
}
|
||||||
if (color != null) {
|
if (color != null) {
|
||||||
TextView textView = (TextView) v.findViewById(R.id.text1);
|
TextView textView = (TextView) v.findViewById(R.id.text1);
|
||||||
|
|
Loading…
Reference in a new issue