jenkins-bot has submitted this change and it was merged. Change subject: Hygiene: remove duplicate code in ListCardView ......................................................................
Hygiene: remove duplicate code in ListCardView Refactor HorizontalScrollingListCardView to subclass ListCardView. The current @Override mechanism seems clumsy and could probably be further improved but is preferable to the nearly identical code in ListCardView. Change-Id: Ib54e329104f7e7a635e06c81a3dc929b33fd3b73 --- M app/src/main/java/org/wikipedia/feed/view/HorizontalScrollingListCardView.java M app/src/main/java/org/wikipedia/feed/view/ListCardView.java D app/src/main/res/layout/view_horizontal_scrolling_list_card.xml 3 files changed, 11 insertions(+), 71 deletions(-) Approvals: Dbrant: Looks good to me, approved jenkins-bot: Verified diff --git a/app/src/main/java/org/wikipedia/feed/view/HorizontalScrollingListCardView.java b/app/src/main/java/org/wikipedia/feed/view/HorizontalScrollingListCardView.java index 1db791f..ce6bfaa 100644 --- a/app/src/main/java/org/wikipedia/feed/view/HorizontalScrollingListCardView.java +++ b/app/src/main/java/org/wikipedia/feed/view/HorizontalScrollingListCardView.java @@ -2,69 +2,25 @@ import android.content.Context; import android.support.annotation.NonNull; -import android.support.annotation.Nullable; -import android.support.v7.widget.CardView; import android.support.v7.widget.LinearLayoutManager; import android.support.v7.widget.RecyclerView; -import android.view.View; import android.view.ViewGroup; import org.wikipedia.R; +import org.wikipedia.util.DimenUtil; import org.wikipedia.views.DefaultRecyclerAdapter; import org.wikipedia.views.DefaultViewHolder; import org.wikipedia.views.DontInterceptTouchListener; import org.wikipedia.views.MarginItemDecoration; -import org.wikipedia.views.ViewUtil; import java.util.List; -import butterknife.BindView; -import butterknife.ButterKnife; - -public abstract class HorizontalScrollingListCardView extends CardView { - @BindView(R.id.view_horizontal_scrolling_list_card_header) View headerView; - @BindView(R.id.view_horizontal_scrolling_list_card_list) RecyclerView recyclerView; - - @Nullable private FeedViewCallback callback; - - @Nullable - public FeedViewCallback callback() { - return callback; - } - +public abstract class HorizontalScrollingListCardView extends ListCardView { public HorizontalScrollingListCardView(@NonNull Context context) { super(context); - inflate(getContext(), R.layout.view_horizontal_scrolling_list_card, this); - ButterKnife.bind(this); - initRecycler(); } - @NonNull public HorizontalScrollingListCardView setCallback(@Nullable FeedViewCallback callback) { - this.callback = callback; - return this; - } - - protected void update() { - if (recyclerView.getAdapter() != null) { - recyclerView.getAdapter().notifyDataSetChanged(); - } - } - - protected void header(@NonNull View view) { - ViewUtil.replace(headerView, view); - headerView = view; - } - - @Nullable - public FeedViewCallback getCallback() { - return callback; - } - - protected void set(@Nullable RecyclerAdapter<?> adapter) { - recyclerView.setAdapter(adapter); - } - - private void initRecycler() { + @Override protected void initRecycler(@NonNull RecyclerView recyclerView) { recyclerView.setLayoutManager(new LinearLayoutManager(getContext(), LinearLayoutManager.HORIZONTAL, false)); recyclerView.addItemDecoration(new MarginItemDecoration(getContext(), R.dimen.view_horizontal_scrolling_list_card_item_margin_horizontal, @@ -73,6 +29,12 @@ R.dimen.view_horizontal_scrolling_list_card_item_margin_vertical)); recyclerView.addOnItemTouchListener(new DontInterceptTouchListener()); recyclerView.setNestedScrollingEnabled(false); + recyclerView.setClipChildren(false); + MarginLayoutParams params = (MarginLayoutParams) recyclerView.getLayoutParams(); + final int height = DimenUtil.roundedDpToPx(228); + params.height = height; + final int margin = DimenUtil.roundedDpToPx(12); + params.setMargins(margin, 0, margin, 0); } protected abstract static class RecyclerAdapter<T> diff --git a/app/src/main/java/org/wikipedia/feed/view/ListCardView.java b/app/src/main/java/org/wikipedia/feed/view/ListCardView.java index 50ef6b8..9e3f35c 100644 --- a/app/src/main/java/org/wikipedia/feed/view/ListCardView.java +++ b/app/src/main/java/org/wikipedia/feed/view/ListCardView.java @@ -25,7 +25,7 @@ inflate(getContext(), R.layout.view_list_card, this); ButterKnife.bind(this); - initRecycler(); + initRecycler(recyclerView); } protected void set(@Nullable RecyclerView.Adapter<?> adapter) { @@ -48,7 +48,7 @@ largeHeaderView = view; } - private void initRecycler() { + protected void initRecycler(@NonNull RecyclerView recyclerView) { recyclerView.setLayoutManager(new LinearLayoutManager(getContext())); recyclerView.addItemDecoration(new DrawableItemDecoration(getContext(), ResourceUtil.getThemedAttributeId(getContext(), R.attr.list_separator_drawable), true)); diff --git a/app/src/main/res/layout/view_horizontal_scrolling_list_card.xml b/app/src/main/res/layout/view_horizontal_scrolling_list_card.xml deleted file mode 100644 index 7285592..0000000 --- a/app/src/main/res/layout/view_horizontal_scrolling_list_card.xml +++ /dev/null @@ -1,22 +0,0 @@ -<?xml version="1.0" encoding="utf-8"?> -<LinearLayout - xmlns:android="http://schemas.android.com/apk/res/android" - android:layout_width="match_parent" - android:layout_height="wrap_content" - android:orientation="vertical" - android:clipChildren="false"> - - <View - android:id="@+id/view_horizontal_scrolling_list_card_header" - android:layout_width="match_parent" - android:layout_height="wrap_content" /> - - <android.support.v7.widget.RecyclerView - android:id="@+id/view_horizontal_scrolling_list_card_list" - android:layout_width="match_parent" - android:layout_height="228dp" - android:layout_marginLeft="12dp" - android:layout_marginRight="12dp" - android:clipChildren="false"/> - -</LinearLayout> \ No newline at end of file -- To view, visit https://gerrit.wikimedia.org/r/311634 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: merged Gerrit-Change-Id: Ib54e329104f7e7a635e06c81a3dc929b33fd3b73 Gerrit-PatchSet: 1 Gerrit-Project: apps/android/wikipedia Gerrit-Branch: master Gerrit-Owner: Niedzielski <sniedziel...@wikimedia.org> Gerrit-Reviewer: BearND <bsitzm...@wikimedia.org> Gerrit-Reviewer: Brion VIBBER <br...@wikimedia.org> Gerrit-Reviewer: Dbrant <dbr...@wikimedia.org> Gerrit-Reviewer: Mholloway <mhollo...@wikimedia.org> Gerrit-Reviewer: jenkins-bot <> _______________________________________________ MediaWiki-commits mailing list MediaWiki-commits@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits