Added dialog to edit bookmark from bookmark list.

This commit is contained in:
Dmitry Yunitsky 2015-06-16 10:59:02 +03:00 committed by Alex Zolotarev
parent 65a303de9e
commit db96d0cddb
7 changed files with 337 additions and 39 deletions

View file

@ -0,0 +1,109 @@
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
android:id="@+id/rl__bookmark_details"
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:padding="@dimen/margin_small">
<LinearLayout
android:id="@+id/ll__bookmark_name"
android:layout_width="match_parent"
android:layout_height="@dimen/height_item_edit_bookmark"
android:layout_marginLeft="@dimen/margin_small"
android:layout_marginRight="@dimen/margin_small"
android:orientation="vertical">
<com.mapswithme.maps.widget.CustomTextInputLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<EditText
android:id="@+id/et__bookmark_name"
style="@style/MwmWidget.PlacePage.EditText"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="@string/name"
android:inputType="textCapWords"
android:singleLine="true"/>
</com.mapswithme.maps.widget.CustomTextInputLayout>
</LinearLayout>
<RelativeLayout
android:id="@+id/rl__bookmark_set"
android:layout_width="match_parent"
android:layout_height="@dimen/height_item_edit_bookmark"
android:layout_below="@id/ll__bookmark_name"
android:layout_marginLeft="@dimen/margin_small_and_half"
android:layout_marginTop="@dimen/margin_small">
<TextView
android:id="@+id/tv__bookmark_set_title"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginRight="@dimen/margin_extra_large"
android:layout_marginTop="@dimen/margin_medium"
android:text="@string/set"
android:textAppearance="@style/MwmTextAppearance.Body3"/>
<TextView
android:id="@+id/tv__bookmark_set"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@id/tv__bookmark_set_title"
android:layout_centerVertical="true"
android:layout_marginRight="@dimen/margin_extra_large"
android:background="?attr/selectableItemBackground"
android:clickable="true"
android:drawableRight="@drawable/ic_arrow_down"
android:paddingBottom="@dimen/margin_small"
android:paddingTop="@dimen/margin_tiny_and_half"
android:textAppearance="@style/MwmTextAppearance.Body1"/>
<View
android:layout_width="match_parent"
android:layout_height="1dp"
android:layout_alignParentBottom="true"
android:layout_marginBottom="@dimen/margin_small"
android:layout_marginRight="@dimen/margin_extra_large"
android:background="@color/base_black_divider"/>
<ImageView
android:id="@+id/iv__bookmark_color"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentRight="true"
android:background="?attr/clickableBackground"
android:padding="@dimen/margin_small"
android:src="@drawable/color_picker_red_on"/>
</RelativeLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="@dimen/height_item_edit_bookmark"
android:layout_below="@id/rl__bookmark_set"
android:layout_margin="@dimen/margin_small"
android:orientation="vertical"
android:paddingTop="@dimen/margin_medium">
<com.mapswithme.maps.widget.CustomTextInputLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<EditText
android:id="@+id/et__description"
style="@style/MwmWidget.PlacePage.EditText"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="@string/edit_description_hint"
android:inputType="text"
android:singleLine="false"/>
</com.mapswithme.maps.widget.CustomTextInputLayout>
</LinearLayout>
</RelativeLayout>

View file

@ -0,0 +1,36 @@
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@android:color/white">
<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:theme="@style/MwmWidget.Toolbar">
<TextView
android:id="@+id/tv__save"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_gravity="right"
android:background="?attr/selectableItemBackgroundBorderless"
android:clickable="true"
android:gravity="center_vertical"
android:padding="@dimen/margin_small"
android:text="@string/save"
android:textAppearance="@style/MwmTextAppearance.Toolbar.Button"/>
</android.support.v7.widget.Toolbar>
<FrameLayout
style="@style/MwmWidget.FrameLayout.Elevation"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@id/toolbar">
<include layout="@layout/edit_bookmark_common"/>
</FrameLayout>
</RelativeLayout>

View file

@ -10,23 +10,15 @@
<View
android:layout_width="match_parent"
android:layout_height="1px"
android:layout_height="1dp"
android:background="?attr/dividerHorizontal"/>
<ImageView
android:id="@+id/iv__bookmark"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginRight="@dimen/margin_large"
android:layout_marginTop="@dimen/margin_medium"
android:src="@drawable/ic_text_bookmark"/>
<com.mapswithme.maps.widget.CustomTextInputLayout
android:id="@+id/layout__bookmark_name"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignTop="@id/iv__bookmark"
android:layout_toRightOf="@id/iv__bookmark">
android:layout_marginBottom="@dimen/margin_small"
android:layout_marginTop="@dimen/margin_medium">
<EditText
android:id="@+id/et__bookmark_name"
@ -40,20 +32,13 @@
</com.mapswithme.maps.widget.CustomTextInputLayout>
<View
android:layout_width="match_parent"
android:layout_height="1px"
android:layout_below="@id/layout__bookmark_name"
android:layout_marginTop="@dimen/margin_small"
android:background="?attr/dividerHorizontal"/>
<TextView
android:id="@+id/tv__bookmark_group_title"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignLeft="@id/layout__bookmark_name"
android:layout_below="@id/layout__bookmark_name"
android:layout_marginTop="@dimen/margin_medium_and_half"
android:layout_toRightOf="@id/iv__bookmark"
android:lineSpacingMultiplier="1.67"
android:text="@string/set"
android:textColor="@color/text_place_page_subtitle"
@ -63,8 +48,8 @@
android:id="@+id/ll__group"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignLeft="@id/layout__bookmark_name"
android:layout_below="@id/tv__bookmark_group_title"
android:layout_toRightOf="@id/iv__bookmark"
android:clipChildren="false"
android:orientation="horizontal">
@ -85,7 +70,7 @@
<View
android:layout_width="match_parent"
android:layout_height="1px"
android:layout_height="1dp"
android:layout_below="@id/tv__bookmark_group"
android:layout_marginTop="@dimen/margin_tiny"
android:layout_toLeftOf="@+id/iv__bookmark_color"
@ -107,10 +92,10 @@
android:id="@+id/tv__bookmark_notes"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignLeft="@id/layout__bookmark_name"
android:layout_below="@id/ll__group"
android:layout_marginBottom="@dimen/margin_small"
android:layout_marginTop="@dimen/margin_medium"
android:layout_toRightOf="@id/iv__bookmark"
android:clickable="true"
android:lineSpacingMultiplier="1.67"
android:text="@string/description"

View file

@ -12,6 +12,7 @@
<dimen name="margin_medium_and_half">24dp</dimen>
<dimen name="margin_large">32dp</dimen>
<dimen name="margin_large_and_half">48dp</dimen>
<dimen name="margin_extra_large">64dp</dimen>
<dimen name="neg_margin_micro">-2dp</dimen>
<dimen name="neg_margin_tiny">-4dp</dimen>
@ -65,6 +66,7 @@
<dimen name="margin_direction_around_center">20dp</dimen>
<dimen name="height_item_oneline">56dp</dimen>
<dimen name="height_item_edit_bookmark">72dp</dimen>
<dimen name="margin_bottom_zoom_buttons">250dp</dimen>
<!-- map widgets -->

View file

@ -8,6 +8,7 @@
<item name="colorPrimary">@color/base_green</item>
<item name="colorPrimaryDark">@color/base_green_darker</item>
<item name="clickableBackground">?attr/selectableItemBackground</item>
<item name="colorControlNormal">@color/text_dark_hint</item>
<item name="android:listViewStyle">@style/MwmWidget.ListView</item>
<item name="android:textViewStyle">@style/MwmWidget.TextView</item>
<item name="android:contentInsetStart">150dp</item>
@ -36,11 +37,15 @@
</style>
<style name="MwmMain.DialogFragment.Fullscreen" parent="Theme.AppCompat">
<item name="colorPrimary">@color/base_green</item>
<item name="colorPrimaryDark">@color/base_green_darker</item>
<item name="clickableBackground">?attr/selectableItemBackground</item>
<item name="colorControlNormal">@color/text_dark_hint</item>
<item name="colorAccent">?attr/colorPrimary</item>
<item name="android:windowIsTranslucent">true</item>
<item name="android:windowIsFloating">false</item>
<item name="android:windowBackground">@android:color/white</item>
<item name="colorPrimary">@color/base_green</item>
<item name="clickableBackground">?attr/selectableItemBackground</item>
<item name="android:textColorHint">@color/text_dark_hint</item>
<item name="android:textViewStyle">@style/MwmWidget.TextView</item>
<item name="android:colorBackgroundCacheHint">@null</item>
<item name="android:fontFamily" tools:targetApi="jelly_bean">@string/robotoRegular</item>
@ -80,8 +85,8 @@
<style name="MwmWidget.PlacePage.EditText" parent="Widget.AppCompat.EditText">
<item name="android:imeOptions">actionDone</item>
<item name="android:textColor">@color/text_place_page</item>
<item name="android:textCursorDrawable">@null</item>
<item name="android:textColorHint">@color/text_dark_hint</item>
<item name="android:textCursorDrawable">@null</item>
<item name="android:textSize">@dimen/text_size_body_1</item>
<item name="android:fontFamily">@string/robotoRegular</item>
</style>
@ -244,6 +249,10 @@
<item name="android:textAllCaps">true</item>
</style>
<style name="MwmTextAppearance.Hint.InputLayout" parent="TextAppearance.AppCompat">
<item name="android:textColorHint">?attr/colorAccent</item>
</style>
<!-- Text appearance -->
</resources>

View file

@ -4,6 +4,8 @@ import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.support.v7.app.ActionBar;
import android.support.v7.app.ActionBar;
import android.support.v7.app.AppCompatActivity;
import android.util.Log;
@ -25,8 +27,8 @@ import com.mapswithme.maps.base.BaseMwmListFragment;
import com.mapswithme.maps.bookmarks.data.Bookmark;
import com.mapswithme.maps.bookmarks.data.BookmarkCategory;
import com.mapswithme.maps.bookmarks.data.BookmarkManager;
import com.mapswithme.maps.bookmarks.data.ParcelablePoint;
import com.mapswithme.maps.bookmarks.data.Track;
import com.mapswithme.maps.widget.placepage.EditBookmarkFragment;
import com.mapswithme.util.ShareAction;
public class BookmarksListFragment extends BaseMwmListFragment
@ -72,23 +74,15 @@ public class BookmarksListFragment extends BaseMwmListFragment
}
}
@Override
public void onStart()
{
super.onStart();
mAdapter.notifyDataSetChanged();
}
@Override
public void onResume()
{
super.onResume();
mAdapter.startLocationUpdate();
mAdapter.notifyDataSetChanged();
}
@Override
public void onPause()
{
@ -175,7 +169,7 @@ public class BookmarksListFragment extends BaseMwmListFragment
if (itemId == R.id.set_edit)
{
startPinActivity(mCategory.getId(), ((Bookmark) obj).getBookmarkId());
editBookmark(mCategory.getId(), ((Bookmark) obj).getBookmarkId());
}
else if (itemId == R.id.set_delete)
{
@ -196,10 +190,14 @@ public class BookmarksListFragment extends BaseMwmListFragment
return super.onContextItemSelected(item);
}
private void startPinActivity(int cat, int bmk)
private void editBookmark(int cat, int bmk)
{
startActivity(new Intent(getActivity(), ChooseBookmarkCategoryActivity.class)
.putExtra(ChooseBookmarkCategoryActivity.BOOKMARK, new ParcelablePoint(cat, bmk)));
final Bundle args = new Bundle();
args.putInt(EditBookmarkFragment.EXTRA_CATEGORY_ID, cat);
args.putInt(EditBookmarkFragment.EXTRA_BOOKMARK_ID, bmk);
final EditBookmarkFragment fragment = (EditBookmarkFragment) Fragment.instantiate(getActivity(), EditBookmarkFragment.class.getName(), args);
fragment.setArguments(args);
fragment.show(getActivity().getSupportFragmentManager(), null);
}
private void sendBookmarkMail()

View file

@ -0,0 +1,159 @@
package com.mapswithme.maps.widget.placepage;
import android.content.Intent;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.app.DialogFragment;
import android.support.v7.widget.Toolbar;
import android.text.TextUtils;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.TextView;
import com.mapswithme.maps.R;
import com.mapswithme.maps.base.BaseMwmDialogFragment;
import com.mapswithme.maps.bookmarks.ChooseBookmarkCategoryActivity;
import com.mapswithme.maps.bookmarks.data.Bookmark;
import com.mapswithme.maps.bookmarks.data.BookmarkManager;
import com.mapswithme.maps.bookmarks.data.Icon;
import com.mapswithme.maps.bookmarks.data.ParcelablePoint;
import com.mapswithme.util.UiUtils;
import com.mapswithme.util.statistics.Statistics;
public class EditBookmarkFragment extends BaseMwmDialogFragment implements View.OnClickListener
{
public static final String EXTRA_CATEGORY_ID = "CategoryId";
public static final String EXTRA_BOOKMARK_ID = "BookmarkId";
private EditText mEtDescription;
private EditText mEtName;
private TextView mTvBookmarkGroup;
private ImageView mIvColor;
private Bookmark mBookmark;
public EditBookmarkFragment() {}
@Override
public void onCreate(@Nullable Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setStyle(DialogFragment.STYLE_NORMAL, R.style.MwmMain_DialogFragment_Fullscreen);
}
@Nullable
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState)
{
return inflater.inflate(R.layout.fragment_edit_bookmark, container, false);
}
@Override
public void onViewCreated(View view, Bundle savedInstanceState)
{
super.onViewCreated(view, savedInstanceState);
final Bundle args = getArguments();
int categoryId = args.getInt(EXTRA_CATEGORY_ID);
int bookmarkId = args.getInt(EXTRA_BOOKMARK_ID);
mBookmark = BookmarkManager.INSTANCE.getBookmark(categoryId, bookmarkId);
mEtName = (EditText) view.findViewById(R.id.et__bookmark_name);
mEtDescription = (EditText) view.findViewById(R.id.et__description);
mTvBookmarkGroup = (TextView) view.findViewById(R.id.tv__bookmark_set);
mTvBookmarkGroup.setOnClickListener(this);
mIvColor = (ImageView) view.findViewById(R.id.iv__bookmark_color);
mIvColor.setOnClickListener(this);
refreshBookmark();
initToolbar(view);
}
private void initToolbar(View view)
{
Toolbar toolbar = (Toolbar) view.findViewById(R.id.toolbar);
final TextView textView = (TextView) toolbar.findViewById(R.id.tv__save);
textView.setOnClickListener(new View.OnClickListener()
{
@Override
public void onClick(View v)
{
saveBookmark();
}
});
UiUtils.showHomeUpButton(toolbar);
toolbar.setTitle(R.string.description);
toolbar.setNavigationOnClickListener(new View.OnClickListener()
{
@Override
public void onClick(View v)
{
dismiss();
}
});
}
private void saveBookmark()
{
mBookmark.setParams(mEtName.getText().toString(), null, mEtDescription.getText().toString());
dismiss();
}
@Override
public void onClick(View v)
{
switch (v.getId())
{
case R.id.iv__bookmark_color:
selectBookmarkColor();
break;
case R.id.tv__bookmark_set:
selectBookmarkSet();
break;
}
}
private void selectBookmarkSet()
{
final Intent intent = new Intent(getActivity(), ChooseBookmarkCategoryActivity.class)
.putExtra(ChooseBookmarkCategoryActivity.BOOKMARK_SET, mBookmark.getCategoryId())
.putExtra(ChooseBookmarkCategoryActivity.BOOKMARK, new ParcelablePoint(mBookmark.getCategoryId(), mBookmark.getBookmarkId()));
getActivity().startActivityForResult(intent, ChooseBookmarkCategoryActivity.REQUEST_CODE_SET);
}
private void selectBookmarkColor()
{
final Bundle args = new Bundle();
args.putString(BookmarkColorDialogFragment.ICON_TYPE, mBookmark.getIcon().getType());
final BookmarkColorDialogFragment dialogFragment = (BookmarkColorDialogFragment) BookmarkColorDialogFragment.
instantiate(getActivity(), BookmarkColorDialogFragment.class.getName(), args);
dialogFragment.setOnColorSetListener(new BookmarkColorDialogFragment.OnBookmarkColorChangeListener()
{
@Override
public void onBookmarkColorSet(int colorPos)
{
final Icon newIcon = BookmarkManager.INSTANCE.getIcons().get(colorPos);
final String from = mBookmark.getIcon().getName();
final String to = newIcon.getName();
if (!TextUtils.equals(from, to))
Statistics.INSTANCE.trackColorChanged(from, to);
mBookmark.setParams(mBookmark.getName(), newIcon, mBookmark.getBookmarkDescription());
mBookmark = BookmarkManager.INSTANCE.getBookmark(mBookmark.getCategoryId(), mBookmark.getBookmarkId());
refreshBookmark();
}
});
dialogFragment.show(getActivity().getSupportFragmentManager(), null);
}
private void refreshBookmark()
{
mEtName.setText(mBookmark.getName());
mEtDescription.setText(mBookmark.getBookmarkDescription());
mTvBookmarkGroup.setText(mBookmark.getCategoryName(getActivity()));
mIvColor.setImageResource(mBookmark.getIcon().getSelectedResId());
}
}