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
|
package com.mapswithme.maps.ugc.routes;
import android.content.Intent;
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.text.TextUtils;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;
import android.view.View;
import android.view.ViewGroup;
import android.widget.EditText;
import android.widget.TextView;
import com.mapswithme.maps.R;
import com.mapswithme.maps.base.BaseMwmToolbarFragment;
import com.mapswithme.maps.bookmarks.data.BookmarkCategory;
import com.mapswithme.maps.bookmarks.data.BookmarkManager;
import com.mapswithme.util.statistics.Statistics;
import java.util.Objects;
public class UgcRouteEditSettingsFragment extends BaseMwmToolbarFragment
{
@SuppressWarnings("NullableProblems")
@NonNull
private BookmarkCategory mCategory;
@SuppressWarnings("NullableProblems")
@NonNull
private TextView mAccessRulesView;
@SuppressWarnings("NullableProblems")
@NonNull
private EditText mEditDescView;
@SuppressWarnings("NullableProblems")
@NonNull
private EditText mEditCategoryNameView;
@Override
public void onCreate(@Nullable Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
Bundle args = getArguments();
if (args == null)
throw new IllegalArgumentException("Args must be not null");
mCategory = Objects.requireNonNull(args.getParcelable(UgcRouteEditSettingsActivity.EXTRA_BOOKMARK_CATEGORY));
}
@Nullable
@Override
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container,
@Nullable Bundle savedInstanceState)
{
View root = inflater.inflate(R.layout.fragment_ugc_route_edit, container, false);
setHasOptionsMenu(true);
initViews(root);
return root;
}
private void initViews(@NonNull View root)
{
mEditCategoryNameView = root.findViewById(R.id.edit_category_name_view);
mEditCategoryNameView.setText(mCategory.getName());
mEditCategoryNameView.requestFocus();
mAccessRulesView = root.findViewById(R.id.sharing_options_desc);
mAccessRulesView.setText(mCategory.getAccessRules().getNameResId());
mEditDescView = root.findViewById(R.id.edit_description);
mEditDescView.setText(mCategory.getDescription());
View clearNameBtn = root.findViewById(R.id.edit_text_clear_btn);
clearNameBtn.setOnClickListener(v -> mEditCategoryNameView.getEditableText().clear());
View sharingOptionsBtn = root.findViewById(R.id.open_sharing_options_screen_btn_container);
sharingOptionsBtn.setOnClickListener(v -> onSharingOptionsClicked());
sharingOptionsBtn.setEnabled(mCategory.isSharingOptionsAllowed());
}
@Override
public void onActivityResult(int requestCode, int resultCode, Intent data)
{
super.onActivityResult(requestCode, resultCode, data);
mCategory = BookmarkManager.INSTANCE.getAllCategoriesSnapshot().refresh(mCategory);
mAccessRulesView.setText(mCategory.getAccessRules().getNameResId());
}
private void onSharingOptionsClicked()
{
openSharingOptionsScreen();
Statistics.INSTANCE.trackEditSettingsSharingOptionsClick();
}
private void openSharingOptionsScreen()
{
UgcRouteSharingOptionsActivity.startForResult(getActivity(), mCategory);
}
@Override
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater)
{
inflater.inflate(R.menu.menu_done, menu);
}
@Override
public boolean onOptionsItemSelected(MenuItem item)
{
if (item.getItemId() == R.id.done)
{
onEditDoneClicked();
getActivity().finish();
return true;
}
return super.onOptionsItemSelected(item);
}
@Override
public boolean onBackPressed()
{
if (isCategoryDescChanged())
Statistics.INSTANCE.trackCategoryDescChanged();
Statistics.INSTANCE.trackEditSettingsCancel();
return super.onBackPressed();
}
private void onEditDoneClicked()
{
if (isCategoryNameChanged())
BookmarkManager.INSTANCE.setCategoryName(mCategory.getId(), getEditableCategoryName());
if (isCategoryDescChanged())
{
BookmarkManager.INSTANCE.setCategoryDescription(mCategory.getId(), getEditableCategoryDesc());
Statistics.INSTANCE.trackCategoryDescChanged();
}
Statistics.INSTANCE.trackEditSettingsConfirm();
}
private boolean isCategoryNameChanged()
{
String categoryName = getEditableCategoryName();
return !TextUtils.equals(categoryName, mCategory.getName());
}
@NonNull
private String getEditableCategoryName()
{
return mEditCategoryNameView.getEditableText().toString().trim();
}
@NonNull
private String getEditableCategoryDesc()
{
return mEditDescView.getEditableText().toString().trim();
}
private boolean isCategoryDescChanged()
{
String categoryDesc = getEditableCategoryDesc();
return !TextUtils.equals(mCategory.getDescription(), categoryDesc);
}
}
|