forked from organicmaps/organicmaps
[android] Added tags selection limit without production colors, Modified Edit on Web block on main Sharing Options screen
This commit is contained in:
parent
31a4e2f0f1
commit
0280af6790
6 changed files with 127 additions and 74 deletions
|
@ -132,48 +132,6 @@
|
|||
android:layout_marginRight="@dimen/margin_base"
|
||||
android:layout_marginEnd="@dimen/margin_base"/>
|
||||
</LinearLayout>
|
||||
<LinearLayout
|
||||
android:id="@+id/edit_on_web_btn"
|
||||
android:orientation="vertical"
|
||||
android:layout_below="@id/upload_and_publish_desc_container"
|
||||
android:background="?selectableItemBackground"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content">
|
||||
<include
|
||||
android:id="@+id/upload_and_publish_desc_container_divider"
|
||||
android:layout_height="@dimen/divider_height"
|
||||
android:layout_width="match_parent"
|
||||
layout="@layout/list_divider"/>
|
||||
<LinearLayout
|
||||
android:orientation="horizontal"
|
||||
android:gravity="center_vertical"
|
||||
android:minHeight="@dimen/height_block_base"
|
||||
android:paddingTop="@dimen/margin_half_plus"
|
||||
android:paddingBottom="@dimen/margin_half_plus"
|
||||
android:layout_marginStart="@dimen/margin_base"
|
||||
android:layout_marginLeft="@dimen/margin_base"
|
||||
android:layout_marginEnd="@dimen/margin_base"
|
||||
android:layout_marginRight="@dimen/margin_base"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content">
|
||||
<ImageView
|
||||
android:layout_width="@dimen/sharing_options_img_size"
|
||||
android:layout_height="@dimen/sharing_options_img_size"
|
||||
android:tint="?colorAccent"
|
||||
android:src="@drawable/ic_edit"/>
|
||||
<TextView
|
||||
android:text="@string/edit_on_web"
|
||||
android:textAppearance="?android:attr/textAppearance"
|
||||
android:layout_marginLeft="@dimen/margin_double_plus"
|
||||
android:layout_marginStart="@dimen/margin_double_plus"
|
||||
android:textColor="?colorAccent"
|
||||
android:textAllCaps="true"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:fontFamily="@string/robotoMedium"
|
||||
tools:targetApi="jelly_bean"/>
|
||||
</LinearLayout>
|
||||
</LinearLayout>
|
||||
</RelativeLayout>
|
||||
</LinearLayout>
|
||||
<include layout="@layout/list_divider"/>
|
||||
|
@ -280,6 +238,44 @@
|
|||
</RelativeLayout>
|
||||
<include layout="@layout/list_divider"/>
|
||||
</LinearLayout>
|
||||
<LinearLayout
|
||||
android:orientation="vertical"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content">
|
||||
<!--FIXME text id-->
|
||||
<TextView
|
||||
android:minHeight="@dimen/height_block_base"
|
||||
android:gravity="center_vertical"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="@string/edit_on_web"
|
||||
android:paddingStart="@dimen/margin_base"
|
||||
android:paddingRight="@dimen/margin_base"
|
||||
android:paddingEnd="@dimen/margin_base"
|
||||
android:paddingLeft="@dimen/margin_base"/>
|
||||
<include layout="@layout/list_divider"/>
|
||||
<LinearLayout
|
||||
android:id="@+id/edit_on_web_btn_container"
|
||||
android:orientation="vertical"
|
||||
android:padding="@dimen/margin_base"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:background="?attr/cardBackground">
|
||||
<TextView
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="@string/upload_and_publish_desc"/>
|
||||
<Button
|
||||
android:id="@+id/edit_on_web_btn"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginTop="@dimen/margin_base"
|
||||
style="@style/MwmWidget.Button.Primary"
|
||||
android:text="@string/edit_on_web"
|
||||
android:textAppearance="?android:attr/textAppearanceLarge"/>
|
||||
</LinearLayout>
|
||||
<include layout="@layout/list_divider"/>
|
||||
</LinearLayout>
|
||||
</LinearLayout>
|
||||
</android.support.v4.widget.NestedScrollView>
|
||||
</LinearLayout>
|
||||
|
|
|
@ -34,12 +34,17 @@ public class TagsAdapter extends RecyclerView.Adapter<TagsAdapter.TagViewHolder>
|
|||
@NonNull
|
||||
private final List<CatalogTag> mTags;
|
||||
|
||||
@NonNull
|
||||
private final TagsCompositeAdapter.SelectionPolicy mSelectionPolicy;
|
||||
|
||||
TagsAdapter(@NonNull OnItemClickListener<TagViewHolder> listener, @NonNull SelectionState state,
|
||||
@NonNull List<CatalogTag> tags)
|
||||
@NonNull List<CatalogTag> tags,
|
||||
@NonNull TagsCompositeAdapter.SelectionPolicy selectionPolicy)
|
||||
{
|
||||
mListener = new ClickListenerWrapper(listener);
|
||||
mState = state;
|
||||
mTags = tags;
|
||||
mSelectionPolicy = selectionPolicy;
|
||||
setHasStableIds(true);
|
||||
}
|
||||
|
||||
|
@ -61,14 +66,24 @@ public class TagsAdapter extends RecyclerView.Adapter<TagsAdapter.TagViewHolder>
|
|||
public void onBindViewHolder(TagViewHolder holder, int position)
|
||||
{
|
||||
CatalogTag tag = mTags.get(position);
|
||||
holder.itemView.setSelected(mState.contains(tag));
|
||||
boolean isTagSelected = mState.contains(tag);
|
||||
holder.itemView.setSelected(isTagSelected);
|
||||
holder.mTag = tag;
|
||||
Context context = holder.itemView.getContext();
|
||||
holder.mText.setText(tag.getLocalizedName());
|
||||
boolean isEnabled = hasTagsFreeSpace() || isTagSelected;
|
||||
holder.itemView.setEnabled(isEnabled);
|
||||
StateListDrawable selector = TagsResFactory.makeSelector(context, tag.getColor());
|
||||
holder.itemView.setBackgroundDrawable(selector);
|
||||
ColorStateList color = TagsResFactory.makeColor(context, tag.getColor());
|
||||
holder.mText.setTextColor(color);
|
||||
holder.mText.setText(tag.getLocalizedName());
|
||||
holder.mText.setSelected(isTagSelected);
|
||||
holder.mText.setEnabled(isEnabled);
|
||||
}
|
||||
|
||||
private boolean hasTagsFreeSpace()
|
||||
{
|
||||
return mSelectionPolicy.isTagsSelectionAllowed();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -34,11 +34,14 @@ public class TagsCompositeAdapter extends RecyclerView.Adapter<TagsCompositeAdap
|
|||
public TagsCompositeAdapter(@NonNull Context context,
|
||||
@NonNull List<CatalogTagsGroup> groups,
|
||||
@NonNull List<CatalogTag> savedState,
|
||||
@NonNull OnItemClickListener<Pair<TagsAdapter, TagsAdapter.TagViewHolder>> clickListener)
|
||||
@NonNull OnItemClickListener<Pair<TagsAdapter, TagsAdapter.TagViewHolder>> clickListener,
|
||||
int selectedTagsLimit)
|
||||
{
|
||||
mContext = context;
|
||||
mCatalogTagsGroups = groups;
|
||||
mComponentHolders = makeRecyclerComponents(context, groups, savedState, clickListener);
|
||||
|
||||
mComponentHolders = makeRecyclerComponents(context, groups, savedState, clickListener,
|
||||
selectedTagsLimit);
|
||||
setHasStableIds(true);
|
||||
}
|
||||
|
||||
|
@ -46,16 +49,18 @@ public class TagsCompositeAdapter extends RecyclerView.Adapter<TagsCompositeAdap
|
|||
private List<ComponentHolder> makeRecyclerComponents(@NonNull Context context,
|
||||
@NonNull List<CatalogTagsGroup> groups,
|
||||
@NonNull List<CatalogTag> savedState,
|
||||
@NonNull OnItemClickListener<Pair<TagsAdapter, TagsAdapter.TagViewHolder>> externalListener)
|
||||
@NonNull OnItemClickListener<Pair<TagsAdapter, TagsAdapter.TagViewHolder>> externalListener,
|
||||
int selectedTagsLimit)
|
||||
{
|
||||
List<ComponentHolder> result = new ArrayList<>();
|
||||
|
||||
SelectionPolicy selectionPolicy = () -> getSelectedTags().size() < selectedTagsLimit;
|
||||
for (int i = 0; i < groups.size(); i++)
|
||||
{
|
||||
CatalogTagsGroup each = groups.get(i);
|
||||
TagsAdapter.SelectionState state = TagsAdapter.SelectionState.from(savedState, each);
|
||||
OnItemClickListener<TagsAdapter.TagViewHolder> listener = new TagsListClickListener(externalListener, i);
|
||||
TagsAdapter adapter = new TagsAdapter(listener, state, each.getTags());
|
||||
|
||||
TagsAdapter adapter = new TagsAdapter(listener, state, each.getTags(), selectionPolicy);
|
||||
Resources res = context.getResources();
|
||||
Drawable divider = res.getDrawable(R.drawable.divider_transparent_base);
|
||||
TagItemDecoration decor = new UgcRouteTagItemDecorator(divider);
|
||||
|
@ -129,6 +134,12 @@ public class TagsCompositeAdapter extends RecyclerView.Adapter<TagsCompositeAdap
|
|||
return false;
|
||||
}
|
||||
|
||||
@NonNull
|
||||
public TagsAdapter getItem(int index)
|
||||
{
|
||||
return mComponentHolders.get(index).mAdapter;
|
||||
}
|
||||
|
||||
private static class ComponentHolder
|
||||
{
|
||||
@NonNull
|
||||
|
@ -177,4 +188,9 @@ public class TagsCompositeAdapter extends RecyclerView.Adapter<TagsCompositeAdap
|
|||
mListener.onItemClick(v, pair);
|
||||
}
|
||||
}
|
||||
|
||||
public interface SelectionPolicy
|
||||
{
|
||||
boolean isTagsSelectionAllowed();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -21,8 +21,13 @@ public class TagsResFactory
|
|||
public static StateListDrawable makeSelector(@NonNull Context context, int color)
|
||||
{
|
||||
StateListDrawable drawable = new StateListDrawable();
|
||||
drawable.addState(new int[] { android.R.attr.state_selected }, makeSelectedDrawable(color));
|
||||
drawable.addState(new int[] {}, makeDefaultDrawable(context, color));
|
||||
drawable.addState(new int[] { android.R.attr.state_selected, android.R.attr.state_enabled },
|
||||
makeSelectedDrawable(color));
|
||||
drawable.addState(new int[] { -android.R.attr.state_selected, android.R.attr.state_enabled },
|
||||
makeDefaultDrawable(context, color));
|
||||
drawable.addState(new int[] { -android.R.attr.state_selected, -android.R.attr.state_enabled },
|
||||
/* FIXME */
|
||||
makeDefaultDrawable(context, Color.BLACK));
|
||||
return drawable;
|
||||
}
|
||||
|
||||
|
@ -43,12 +48,14 @@ public class TagsResFactory
|
|||
{
|
||||
return new ColorStateList(
|
||||
new int[][] {
|
||||
new int[] { android.R.attr.state_selected },
|
||||
new int[] {}
|
||||
},
|
||||
new int[] { android.R.attr.state_selected, android.R.attr.state_enabled },
|
||||
new int[] { -android.R.attr.state_selected, android.R.attr.state_enabled },
|
||||
new int[] { -android.R.attr.state_selected, -android.R.attr.state_enabled } },
|
||||
new int[] {
|
||||
context.getResources().getColor(android.R.color.white),
|
||||
color
|
||||
color,
|
||||
/* FIXME */
|
||||
Color.GRAY
|
||||
}
|
||||
);
|
||||
}
|
||||
|
|
|
@ -38,6 +38,7 @@ import com.mapswithme.util.UiUtils;
|
|||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
|
||||
public class UgcRouteTagsFragment extends BaseMwmFragment implements BookmarkManager.BookmarksCatalogListener,
|
||||
OnItemClickListener<Pair<TagsAdapter, TagsAdapter.TagViewHolder>>,
|
||||
|
@ -200,7 +201,7 @@ public class UgcRouteTagsFragment extends BaseMwmFragment implements BookmarkMan
|
|||
showErrorLoadingDialog();
|
||||
return;
|
||||
}
|
||||
installTags(tagsGroups);
|
||||
installTags(tagsGroups, 1);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -210,11 +211,12 @@ public class UgcRouteTagsFragment extends BaseMwmFragment implements BookmarkMan
|
|||
/* Not ready yet */
|
||||
}
|
||||
|
||||
private void installTags(@NonNull List<CatalogTagsGroup> tagsGroups)
|
||||
private void installTags(@NonNull List<CatalogTagsGroup> tagsGroups, int tagsLimit)
|
||||
{
|
||||
List<CatalogTag> savedStateTags = validateSavedState(mSavedInstanceState);
|
||||
TagGroupNameAdapter categoryAdapter = new TagGroupNameAdapter(tagsGroups);
|
||||
mTagsAdapter = new TagsCompositeAdapter(getContext(), tagsGroups, savedStateTags, this);
|
||||
mTagsAdapter = new TagsCompositeAdapter(getContext(), tagsGroups, savedStateTags, this,
|
||||
tagsLimit);
|
||||
RecyclerCompositeAdapter compositeAdapter = makeCompositeAdapter(categoryAdapter, mTagsAdapter);
|
||||
LinearLayoutManager layoutManager = new LinearLayoutManager(getContext(),
|
||||
LinearLayoutManager.VERTICAL,
|
||||
|
@ -262,9 +264,11 @@ public class UgcRouteTagsFragment extends BaseMwmFragment implements BookmarkMan
|
|||
@NonNull Pair<TagsAdapter, TagsAdapter.TagViewHolder> item)
|
||||
{
|
||||
ActivityCompat.invalidateOptionsMenu(getActivity());
|
||||
TagsAdapter adapter = item.first;
|
||||
int position = item.second.getAdapterPosition();
|
||||
adapter.notifyItemChanged(position);
|
||||
Objects.requireNonNull(mTagsAdapter);
|
||||
for (int i = 0; i < mTagsAdapter.getItemCount(); i++)
|
||||
{
|
||||
mTagsAdapter.getItem(i).notifyDataSetChanged();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -50,9 +50,11 @@ public class UgcSharingOptionsFragment extends BaseMwmAuthorizationFragment impl
|
|||
private static final int REQ_CODE_ERROR_BROKEN_FILE_DIALOG = 104;
|
||||
private static final int REQ_CODE_ERROR_EDITED_ON_WEB_DIALOG = 105;
|
||||
private static final int REQ_CODE_ERROR_COMMON = 106;
|
||||
private static final int REQ_CODE_ERROR_NOT_ENOUGH_BOOKMARKS = 107;
|
||||
private static final String BUNDLE_CURRENT_MODE = "current_mode";
|
||||
private static final String UPLOADING_PROGRESS_DIALOG_TAG = "uploading_progress_dialog";
|
||||
private static final String NO_NETWORK_CONNECTION_DIALOG_TAG = "no_network_connection_dialog";
|
||||
private static final String NOT_ENOUGH_BOOKMARKS_DIALOG_TAG = "not_enough_bookmarks_dialog";
|
||||
private static final String ERROR_BROKEN_FILE_DIALOG_TAG = "error_broken_file_dialog";
|
||||
private static final String ERROR_EDITED_ON_WEB_DIALOG_REQ_TAG = "error_edited_on_web_dialog";
|
||||
private static final String ERROR_COMMON_DIALOG_TAG = "error_common_dialog";
|
||||
|
@ -143,7 +145,7 @@ public class UgcSharingOptionsFragment extends BaseMwmAuthorizationFragment impl
|
|||
{
|
||||
boolean isPublished = mCategory.getAccessRules() == BookmarkCategory.AccessRules.ACCESS_RULES_PUBLIC;
|
||||
UiUtils.hideIf(isPublished, mUploadAndPublishText, mGetDirectLinkContainer);
|
||||
UiUtils.showIf(isPublished, mPublishingCompletedStatusContainer, mEditOnWebBtn);
|
||||
UiUtils.showIf(isPublished, mPublishingCompletedStatusContainer);
|
||||
mPublishCategoryImage.setSelected(!isPublished);
|
||||
|
||||
boolean isLinkSuccessFormed = mCategory.getAccessRules() == BookmarkCategory.AccessRules.ACCESS_RULES_DIRECT_LINK;
|
||||
|
@ -447,9 +449,9 @@ public class UgcSharingOptionsFragment extends BaseMwmAuthorizationFragment impl
|
|||
|
||||
private void showCommonErrorDialog()
|
||||
{
|
||||
showErrorDialog(R.string.upload_error_toast,
|
||||
REQ_CODE_ERROR_COMMON,
|
||||
ERROR_COMMON_DIALOG_TAG);
|
||||
showUploadErrorDialog(R.string.upload_error_toast,
|
||||
REQ_CODE_ERROR_COMMON,
|
||||
ERROR_COMMON_DIALOG_TAG);
|
||||
}
|
||||
|
||||
private void onUploadSuccess()
|
||||
|
@ -477,23 +479,36 @@ public class UgcSharingOptionsFragment extends BaseMwmAuthorizationFragment impl
|
|||
|
||||
private void showErrorEditedOnWebDialog()
|
||||
{
|
||||
showErrorDialog(R.string.unable_upload_error_subtitle_edited,
|
||||
REQ_CODE_ERROR_EDITED_ON_WEB_DIALOG,
|
||||
ERROR_EDITED_ON_WEB_DIALOG_REQ_TAG);
|
||||
showUploadErrorDialog(R.string.unable_upload_error_subtitle_edited,
|
||||
REQ_CODE_ERROR_EDITED_ON_WEB_DIALOG,
|
||||
ERROR_EDITED_ON_WEB_DIALOG_REQ_TAG);
|
||||
}
|
||||
|
||||
|
||||
private void showErrorBrokenFileDialog()
|
||||
{
|
||||
showErrorDialog(R.string.unable_upload_error_subtitle_broken,
|
||||
REQ_CODE_ERROR_BROKEN_FILE_DIALOG,
|
||||
ERROR_BROKEN_FILE_DIALOG_TAG);
|
||||
showUploadErrorDialog(R.string.unable_upload_error_subtitle_broken,
|
||||
REQ_CODE_ERROR_BROKEN_FILE_DIALOG,
|
||||
ERROR_BROKEN_FILE_DIALOG_TAG);
|
||||
}
|
||||
|
||||
private void showErrorDialog(@StringRes int subtitle, int reqCode, @NonNull String tag)
|
||||
private void showUploadErrorDialog(@StringRes int subtitle, int reqCode, @NonNull String tag)
|
||||
{
|
||||
showErrorDialog(R.string.unable_upload_errorr_title, subtitle, reqCode, tag);
|
||||
}
|
||||
|
||||
private void showNotEnoughBookmarksDialog()
|
||||
{
|
||||
/* FIXME */
|
||||
showErrorDialog(R.string.not_enough_memory, R.string.not_enough_memory,
|
||||
REQ_CODE_ERROR_NOT_ENOUGH_BOOKMARKS, NOT_ENOUGH_BOOKMARKS_DIALOG_TAG);
|
||||
}
|
||||
|
||||
private void showErrorDialog(@StringRes int title, @StringRes int subtitle, int reqCode,
|
||||
@NonNull String tag)
|
||||
{
|
||||
AlertDialog dialog = new AlertDialog.Builder()
|
||||
.setTitleId(R.string.unable_upload_errorr_title)
|
||||
.setTitleId(title)
|
||||
.setMessageId(subtitle)
|
||||
.setPositiveBtnId(R.string.ok)
|
||||
.setReqCode(reqCode)
|
||||
|
|
Loading…
Add table
Reference in a new issue