Skip to content

Commit

Permalink
[android] Implemented pull up on touch antimation for guides gallery …
Browse files Browse the repository at this point in the history
…item and it goes to activate state
  • Loading branch information
alexzatsepin authored and devnullorthrow committed Apr 30, 2020
1 parent d4d5b96 commit cea59d6
Show file tree
Hide file tree
Showing 6 changed files with 87 additions and 13 deletions.
23 changes: 23 additions & 0 deletions android/res/animator/pull_up_on_touch.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item
android:state_activated="true">
<set>
<objectAnimator
android:duration="100"
android:propertyName="translationY"
android:valueTo="-16dp"
android:valueType="floatType"/>
</set>
</item>
<item
android:state_activated="false">
<set>
<objectAnimator
android:duration="100"
android:propertyName="translationY"
android:valueTo="0"
android:valueType="floatType"/>
</set>
</item>
</selector>
1 change: 1 addition & 0 deletions android/res/layout/guides_discovery_item.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
xmlns:tools="http://schemas.android.com/tools"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:stateListAnimator="@animator/pull_up_on_touch"
android:padding="@dimen/margin_eighth"
android:clipToPadding="false">
<RelativeLayout
Expand Down
4 changes: 3 additions & 1 deletion android/res/layout/guides_gallery_bottom_sheet.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,10 @@
android:layout_height="wrap_content"
android:background="@android:color/transparent"
android:orientation="vertical"
android:paddingTop="@dimen/margin_base"
android:paddingTop="@dimen/margin_quadruple"
android:paddingBottom="@dimen/margin_quadruple"
android:clipChildren="false"
android:clipToPadding="false"
app:behavior_defaultState="hidden"
app:behavior_hideable="true"
app:behavior_skipAnchored="true"
Expand Down
17 changes: 15 additions & 2 deletions android/src/com/mapswithme/maps/gallery/Holders.java
Original file line number Diff line number Diff line change
Expand Up @@ -562,11 +562,14 @@ public static class GuideHodler extends BaseViewHolder<GuidesGallery.Item>
private final View mCityContent;
@NonNull
private final View mOutdoorContent;*/
@NonNull
private final View mItemView;
public GuideHodler(@NonNull View itemView, @NonNull List<GuidesGallery.Item> items, @Nullable ItemSelectedListener<GuidesGallery.Item> listener)
{
super(itemView, items, listener);
mImage = itemView.findViewById(R.id.image);
mSubtitle = itemView.findViewById(R.id.subtitle);
mItemView = itemView;
mImage = mItemView.findViewById(R.id.image);
mSubtitle = mItemView.findViewById(R.id.subtitle);
}

@Override
Expand All @@ -580,7 +583,17 @@ public void bind(@NonNull GuidesGallery.Item item)
.centerCrop()
.into(mImage);
mSubtitle.setText(item.getSubtitle());
bindActivationState(item);
// TODO: another fields comming soon;
}

private void bindActivationState(@NonNull GuidesGallery.Item item)
{
boolean activated = mItemView.isActivated();
if (activated != item.isActivated())
{
mItemView.post(() -> mItemView.setActivated(item.isActivated()));
}
}
}
}
11 changes: 11 additions & 0 deletions android/src/com/mapswithme/maps/guides/GuidesGallery.java
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ public static class Item extends RegularAdapterStrategy.Item
private final CityParams mCityParams;
@Nullable
private final OutdoorParams mOutdoorParams;
private boolean mActivated = false;

public Item(@NonNull String guideId, @NonNull String url, @NonNull String imageUrl,
@NonNull String title, @NonNull String subTitle, int type,
Expand Down Expand Up @@ -156,6 +157,16 @@ public OutdoorParams getOutdoorParams()
return mOutdoorParams;
}

public void setActivated(boolean activated)
{
mActivated = activated;
}

public boolean isActivated()
{
return mActivated;
}

@Override
public int describeContents()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
import com.mapswithme.maps.R;
import com.mapswithme.maps.gallery.GalleryAdapter;
import com.mapswithme.maps.gallery.ItemSelectedListener;
import com.mapswithme.maps.gallery.Items;
import com.mapswithme.maps.gallery.impl.Factory;
import com.mapswithme.maps.guides.GuidesGallery;
import com.mapswithme.maps.widget.recycler.ItemDecoratorFactory;
Expand All @@ -37,6 +36,8 @@ public class GuidesGalleryViewRenderer implements PlacePageViewRenderer<PlacePag
@NonNull
private SnapHelper mSnapHelper;
private int mSnapViewPosition;
@Nullable
private GuidesGallery.Item mActiveItem;
@SuppressWarnings("NullableProblems")
@NonNull
private RecyclerView.SmoothScroller mSmoothScroller;
Expand Down Expand Up @@ -71,6 +72,8 @@ public void onActionButtonSelected(@NonNull GuidesGallery.Item item, int positio
// No op.
}
};
@Nullable
private GalleryAdapter mAdapter;

private void smoothScrollToPosition(int position)
{
Expand All @@ -92,27 +95,48 @@ public void onScrollStateChanged(@NonNull RecyclerView recyclerView, int newStat

private void setActiveGuide()
{
final int oldSnapViewPosition = mSnapViewPosition;
View snapView = mSnapHelper.findSnapView(mLayoutManager);
mSnapViewPosition = snapView == null ? 0 : mLayoutManager.getPosition(snapView);
Items.Item item = mGallery.getItems().get(mSnapViewPosition);
Toast.makeText(mRecyclerView.getContext(), "TODO: Shift y for = " + item.getTitle(),
Toast.LENGTH_SHORT).show();
GuidesGallery.Item item = mGallery.getItems().get(mSnapViewPosition);
if (oldSnapViewPosition == mSnapViewPosition)
{
if (mActiveItem == null)
{
mActiveItem = item;
mActiveItem.setActivated(true);
if (mAdapter != null)
mAdapter.notifyDataSetChanged();
return;
}
return;
}

if (mActiveItem != null)
mActiveItem.setActivated(false);
mActiveItem = item;
mActiveItem.setActivated(true);
if (mAdapter != null)
mAdapter.notifyDataSetChanged();
}

@Override
public void render(@NonNull PlacePageData data)
{
mGallery = (GuidesGallery) data;
GalleryAdapter adapter = Factory.createGuidesAdapter(mGallery.getItems(), mItemSelectedListener,
mAdapter = Factory.createGuidesAdapter(mGallery.getItems(), mItemSelectedListener,
GalleryPlacement.MAP);
mRecyclerView.setAdapter(adapter);
mRecyclerView.setAdapter(mAdapter);
mActiveItem = null;
setActiveGuide();
}

@Override
public void onHide()
{

mActiveItem = null;
mSnapViewPosition = 0;
smoothScrollToPosition(0);
}

@Override
Expand Down Expand Up @@ -160,9 +184,9 @@ public void onRestore(@NonNull Bundle inState)
if (mGallery == null)
return;

GalleryAdapter adapter = Factory.createGuidesAdapter(mGallery.getItems(), mItemSelectedListener,
GalleryPlacement.MAP);
mRecyclerView.setAdapter(adapter);
mAdapter = Factory.createGuidesAdapter(mGallery.getItems(), mItemSelectedListener,
GalleryPlacement.MAP);
mRecyclerView.setAdapter(mAdapter);
mSnapViewPosition = inState.getInt(EXTRA_SNAP_VIEW_POSITION);
mRecyclerView.post(() -> {
smoothScrollToPosition(mSnapViewPosition);
Expand Down

0 comments on commit cea59d6

Please sign in to comment.