1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
|
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.InputUtils;
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_CATEGORY_INDEX, mBookmark.getCategoryId())
.putExtra(ChooseBookmarkCategoryActivity.BOOKMARK, new ParcelablePoint(mBookmark.getCategoryId(), mBookmark.getBookmarkId()));
getActivity().startActivityForResult(intent, ChooseBookmarkCategoryActivity.REQUEST_CODE_BOOKMARK_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.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());
refreshColorMarker();
}
});
dialogFragment.show(getActivity().getSupportFragmentManager(), null);
}
private void refreshColorMarker()
{
mIvColor.setImageResource(mBookmark.getIcon().getSelectedResId());
}
private void refreshBookmark()
{
mEtName.setText(mBookmark.getName());
mEtName.selectAll();
InputUtils.showKeyboard(mEtName);
mEtDescription.setText(mBookmark.getBookmarkDescription());
mTvBookmarkGroup.setText(mBookmark.getCategoryName(getActivity()));
refreshColorMarker();
}
}
|