added new ButtomSheet to editFavouriteGroup

This commit is contained in:
Chumva 2018-03-06 11:11:51 +02:00
parent 38954241c3
commit 9fe01ced66
2 changed files with 183 additions and 133 deletions

View file

@ -0,0 +1,37 @@
<?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="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:paddingBottom="6dp"
android:paddingLeft="@dimen/list_content_padding"
android:paddingTop="6dp"
android:text="@string/change_color"
android:textColor="?android:attr/textColorPrimary"
android:textSize="@dimen/default_list_text_size" />
<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>

View file

@ -9,7 +9,7 @@ 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;
@ -30,11 +30,16 @@ 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.DividerItem;
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";
@ -56,7 +61,7 @@ public class EditFavoriteGroupDialogFragment extends BottomSheetDialogFragment {
} }
@Override @Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { public void createMenuItems(Bundle savedInstanceState) {
final Activity activity = getActivity(); final Activity activity = getActivity();
app = (OsmandApplication) activity.getApplicationContext(); app = (OsmandApplication) activity.getApplicationContext();
@ -75,29 +80,22 @@ public class EditFavoriteGroupDialogFragment extends BottomSheetDialogFragment {
group = helper.getGroup(groupName); group = helper.getGroup(groupName);
} }
} }
items.add(new TitleItem(Algorithms.isEmpty(group.name) ? app.getString(R.string.shared_string_favorites) : group.name));
final View view = inflater.inflate(R.layout.edit_fav_fragment, container,
false);
if (group == null) {
return view;
}
IconsCache ic = app.getIconsCache(); IconsCache ic = app.getIconsCache();
final TextView title = (TextView) view.findViewById(R.id.title); BaseBottomSheetItem byTypeItem = new SimpleBottomSheetItem.Builder()
title.setText(Algorithms.isEmpty(group.name) ? app.getString(R.string.shared_string_favorites) : group.name); .setIcon(ic.getThemedIcon(R.drawable.ic_action_edit_dark))
View editNameView = view.findViewById(R.id.edit_name_view); .setTitle(getString(R.string.edit_name))
((ImageView) view.findViewById(R.id.edit_name_icon)) .setLayoutId(R.layout.bottom_sheet_item_simple)
.setImageDrawable(ic.getThemedIcon(R.drawable.ic_action_edit_dark)); .setOnClickListener(new View.OnClickListener() {
editNameView.setOnClickListener(new View.OnClickListener() {
@Override @Override
public void onClick(View v) { public void onClick(View v) {
AlertDialog.Builder b = new AlertDialog.Builder(activity); AlertDialog.Builder b = new AlertDialog.Builder(getContext());
b.setTitle(R.string.favorite_group_name); b.setTitle(R.string.favorite_group_name);
final EditText nameEditText = new EditText(activity); final EditText nameEditText = new EditText(getContext());
nameEditText.setText(group.name); nameEditText.setText(group.name);
int leftPadding = AndroidUtils.dpToPx(activity, 24f); int leftPadding = AndroidUtils.dpToPx(getContext(), 24f);
int topPadding = AndroidUtils.dpToPx(activity, 4f); int topPadding = AndroidUtils.dpToPx(getContext(), 4f);
b.setView(nameEditText, leftPadding, topPadding, leftPadding, topPadding); b.setView(nameEditText, leftPadding, topPadding, leftPadding, topPadding);
b.setNegativeButton(R.string.shared_string_cancel, null); b.setNegativeButton(R.string.shared_string_cancel, null);
b.setPositiveButton(R.string.shared_string_save, new DialogInterface.OnClickListener() { b.setPositiveButton(R.string.shared_string_save, new DialogInterface.OnClickListener() {
@ -115,13 +113,20 @@ public class EditFavoriteGroupDialogFragment extends BottomSheetDialogFragment {
}); });
b.show(); b.show();
} }
}); })
.create();
items.add(byTypeItem);
final View changeColorView = view.findViewById(R.id.change_color_view); final int themeRes = nightMode ? R.style.OsmandDarkTheme : R.style.OsmandLightTheme;
((ImageView) view.findViewById(R.id.change_color_icon))
final View changeColorView = View.inflate(new ContextThemeWrapper(getContext(), themeRes),
R.layout.change_fav_color, null);
((ImageView) changeColorView.findViewById(R.id.change_color_icon))
.setImageDrawable(ic.getThemedIcon(R.drawable.ic_action_appearance)); .setImageDrawable(ic.getThemedIcon(R.drawable.ic_action_appearance));
updateColorView(changeColorView); updateColorView(changeColorView);
changeColorView.setOnClickListener(new View.OnClickListener() {
BaseBottomSheetItem changeColorItem = new BaseBottomSheetItem.Builder().setCustomView(changeColorView)
.setOnClickListener(new View.OnClickListener() {
@Override @Override
public void onClick(View v) { public void onClick(View v) {
final ListPopupWindow popup = new ListPopupWindow(getActivity()); final ListPopupWindow popup = new ListPopupWindow(getActivity());
@ -151,34 +156,43 @@ public class EditFavoriteGroupDialogFragment extends BottomSheetDialogFragment {
}); });
popup.show(); popup.show();
} }
}); }).create();
items.add(changeColorItem);
View showOnMapView = view.findViewById(R.id.show_on_map_view); BaseBottomSheetItem showOnMapItem = new BottomSheetItemWithCompoundButton.Builder()
((ImageView) view.findViewById(R.id.show_on_map_icon)) .setChecked(group.visible)
.setImageDrawable(ic.getThemedIcon(R.drawable.ic_map)); .setIcon(ic.getThemedIcon(R.drawable.ic_map))
final SwitchCompat checkbox = (SwitchCompat) view.findViewById(R.id.show_on_map_switch); .setTitle(getString(R.string.shared_string_show_on_map))
checkbox.setChecked(group.visible); .setLayoutId(R.layout.bottom_sheet_item_with_switch)
showOnMapView.setOnClickListener(new View.OnClickListener() { .setOnClickListener(new View.OnClickListener() {
@Override @Override
public void onClick(View v) { public void onClick(View v) {
boolean visible = !group.visible; boolean visible = !group.visible;
checkbox.setChecked(visible); // showOnMapItem.setChecked(visible);
getMyApplication().getFavorites() getMyApplication().getFavorites()
.editFavouriteGroup(group, group.name, group.color, visible); .editFavouriteGroup(group, group.name, group.color, visible);
updateParentFragment(); updateParentFragment();
} }
}); })
.create();
items.add(showOnMapItem);
if (group.points.size() > 0) {
items.add(new DividerItem(getContext()));
}
final MapMarkersHelper markersHelper = getMyApplication().getMapMarkersHelper(); 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(ic.getThemedIcon(R.drawable.ic_action_flag_dark))
addToMarkersView.setOnClickListener(new View.OnClickListener() { .setTitle(getString(R.string.shared_string_add_to_map_markers))
.setLayoutId(R.layout.bottom_sheet_item_simple)
.setOnClickListener(new View.OnClickListener() {
@Override @Override
public void onClick(View v) { public void onClick(View v) {
markersHelper.addMarkersSyncGroup(syncGroup); markersHelper.addMarkersSyncGroup(syncGroup);
@ -186,48 +200,47 @@ public class EditFavoriteGroupDialogFragment extends BottomSheetDialogFragment {
dismiss(); dismiss();
MapActivity.launchMapActivityMoveToTop(getActivity()); MapActivity.launchMapActivityMoveToTop(getActivity());
} }
}); })
} else { .create();
addToMarkersView.setVisibility(View.GONE); 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(ic.getThemedIcon(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)
.setOnClickListener(new View.OnClickListener() {
@Override @Override
public void onClick(View view) { public void onClick(View view) {
markersHelper.removeMarkersSyncGroup(syncGroup.getId(), true); markersHelper.removeMarkersSyncGroup(syncGroup.getId(), true);
dismiss(); dismiss();
MapActivity.launchMapActivityMoveToTop(getActivity()); 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(ic.getThemedIcon(R.drawable.ic_action_gshare_dark))
shareView.setOnClickListener(new View.OnClickListener() { .setTitle(getString(R.string.shared_string_share))
.setLayoutId(R.layout.bottom_sheet_item_simple)
.setOnClickListener(new View.OnClickListener() {
@Override @Override
public void onClick(View v) { public void onClick(View view) {
FavoritesTreeFragment fragment = getFavoritesTreeFragment(); FavoritesTreeFragment fragment = getFavoritesTreeFragment();
if (fragment != null) { if (fragment != null) {
fragment.shareFavorites(group); fragment.shareFavorites(group);
} }
dismiss(); dismiss();
} }
}); })
} else { .create();
shareView.setVisibility(View.GONE); items.add(shareItem);
}
if (group.points.size() == 0) {
view.findViewById(R.id.divider).setVisibility(View.GONE);
} }
return view;
} }
@Override @Override