{"metadata":{"image":[],"title":"","description":""},"api":{"url":"","auth":"required","settings":"","results":{"codes":[]},"params":[]},"next":{"description":"","pages":[]},"title":"Custom Pulsate Inbox","type":"basic","slug":"custom-pulsate-inbox","excerpt":"","body":"[block:api-header]\n{\n  \"title\": \"Creating a custom Pulsate Inbox\"\n}\n[/block]\nThe PuslateSDK also allows Developers to directly access the Pulsate Feed API to get the Pulsate Feed Models and build them in a custom way.\n\nTo get the Feed Models just call this method \"*void getFeed(int page, IPulsateValueListener<PulsateFeedState> listener)*\". This method takes two arguments - \"*page*\" which specifies which page of the Feed do you want to get and \"*listener*\" which is the listener to which we send the Feed Models and any errors if they occur. The models that are returned are - PulsateInboxItemCard and PulsateInboxItemTalk. Having all these models you can build a custom Feed.\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"IPulsateManager pulsateManager = PulsateFactory.getInstance();\\npulsateManager.getFeed(1, new IPulsateValueListener<PulsateFeedState>() {\\n    :::at:::Override\\n    public void onSuccess(PulsateFeedState feedState) {\\n        mAdapter.setCustomFeed(feedState.mInboxItems);\\n    }\\n\\n    @Override\\n    public void onError(Throwable e) {\\n        e.printStackTrace();\\n    }\\n});\",\n      \"language\": \"java\"\n    }\n  ]\n}\n[/block]\nShowing the Feed in a custom way also means that item clicks also need to be handled in a custom way. When handling on click events you must pass those clicks also to the PulsateSDK for it to be able to open the proper destination (deeplink, url, back of card, feed, reply) and also to send open event and custom events. To pass the clicks use the \"*void handleFeedClick(PulsateInboxItem pulsateInboxItem, int destination)*\" method.\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"mBinding.cardView.setOnClickListener(view -> {\\n    IPulsateManager pulsateManager = PulsateFactory.getInstance();\\n    pulsateManager.handleFeedClick(itemCard, PulsateUtils.PulsateCardDestination.VIEW_MORE);\\n});\",\n      \"language\": \"java\"\n    }\n  ]\n}\n[/block]\nExample:\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"<layout xmlns:tools=\\\"http://schemas.android.com/tools\\\"\\n    xmlns:android=\\\"http://schemas.android.com/apk/res/android\\\"\\n    xmlns:app=\\\"http://schemas.android.com/apk/res-auto\\\">\\n\\n    <data>\\n\\n    </data>\\n\\n    <androidx.constraintlayout.widget.ConstraintLayout\\n        android:id=\\\"@+id/container\\\"\\n        android:layout_width=\\\"match_parent\\\"\\n        android:layout_height=\\\"match_parent\\\">\\n\\n        <androidx.recyclerview.widget.RecyclerView\\n            android:id=\\\"@+id/custom_feed_recycler\\\"\\n            android:layout_width=\\\"0dp\\\"\\n            android:layout_height=\\\"0dp\\\"\\n            app:layout_constraintBottom_toBottomOf=\\\"parent\\\"\\n            app:layout_constraintEnd_toEndOf=\\\"parent\\\"\\n            app:layout_constraintStart_toStartOf=\\\"parent\\\"\\n            app:layout_constraintTop_toTopOf=\\\"parent\\\" />\\n    </androidx.constraintlayout.widget.ConstraintLayout>\\n</layout>\",\n      \"language\": \"xml\",\n      \"name\": \"fragment_custom_feed.xml\"\n    }\n  ]\n}\n[/block]\n\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"<layout xmlns:tools=\\\"http://schemas.android.com/tools\\\"\\n    xmlns:android=\\\"http://schemas.android.com/apk/res/android\\\"\\n    xmlns:app=\\\"http://schemas.android.com/apk/res-auto\\\">\\n\\n    <data>\\n\\n    </data>\\n\\n    <androidx.constraintlayout.widget.ConstraintLayout\\n        android:id=\\\"@+id/container\\\"\\n        android:layout_width=\\\"match_parent\\\"\\n        android:layout_height=\\\"wrap_content\\\">\\n\\n        <androidx.cardview.widget.CardView\\n            android:id=\\\"@+id/card_view\\\"\\n            android:layout_width=\\\"0dp\\\"\\n            android:layout_height=\\\"wrap_content\\\"\\n            android:layout_marginStart=\\\"16dp\\\"\\n            android:layout_marginLeft=\\\"16dp\\\"\\n            android:layout_marginTop=\\\"16dp\\\"\\n            android:layout_marginEnd=\\\"16dp\\\"\\n            android:layout_marginRight=\\\"16dp\\\"\\n            android:layout_marginBottom=\\\"16dp\\\"\\n            app:cardBackgroundColor=\\\"@color/colorAccent\\\"\\n            app:cardCornerRadius=\\\"16dp\\\"\\n            app:layout_constraintBottom_toBottomOf=\\\"parent\\\"\\n            app:layout_constraintEnd_toEndOf=\\\"parent\\\"\\n            app:layout_constraintStart_toStartOf=\\\"parent\\\"\\n            app:layout_constraintTop_toTopOf=\\\"parent\\\">\\n\\n            <androidx.constraintlayout.widget.ConstraintLayout\\n                android:id=\\\"@+id/card_view_container\\\"\\n                android:layout_width=\\\"match_parent\\\"\\n                android:layout_height=\\\"match_parent\\\">\\n\\n                <TextView\\n                    android:id=\\\"@+id/card_view_title\\\"\\n                    android:layout_width=\\\"0dp\\\"\\n                    android:layout_height=\\\"wrap_content\\\"\\n                    android:layout_marginStart=\\\"16dp\\\"\\n                    android:layout_marginLeft=\\\"16dp\\\"\\n                    android:layout_marginTop=\\\"16dp\\\"\\n                    android:layout_marginEnd=\\\"16dp\\\"\\n                    android:layout_marginRight=\\\"16dp\\\"\\n                    android:text=\\\"TextView\\\"\\n                    app:layout_constraintEnd_toEndOf=\\\"parent\\\"\\n                    app:layout_constraintStart_toStartOf=\\\"parent\\\"\\n                    app:layout_constraintTop_toTopOf=\\\"parent\\\" />\\n\\n                <TextView\\n                    android:id=\\\"@+id/card_view_body\\\"\\n                    android:layout_width=\\\"0dp\\\"\\n                    android:layout_height=\\\"wrap_content\\\"\\n                    android:layout_marginStart=\\\"16dp\\\"\\n                    android:layout_marginLeft=\\\"16dp\\\"\\n                    android:layout_marginTop=\\\"16dp\\\"\\n                    android:layout_marginEnd=\\\"16dp\\\"\\n                    android:layout_marginRight=\\\"16dp\\\"\\n                    android:layout_marginBottom=\\\"16dp\\\"\\n                    android:text=\\\"TextView\\\"\\n                    app:layout_constraintBottom_toTopOf=\\\"@+id/card_view_reply\\\"\\n                    app:layout_constraintEnd_toEndOf=\\\"parent\\\"\\n                    app:layout_constraintStart_toStartOf=\\\"parent\\\"\\n                    app:layout_constraintTop_toBottomOf=\\\"@+id/card_view_title\\\" />\\n\\n                <Button\\n                    android:id=\\\"@+id/card_view_reply\\\"\\n                    android:layout_width=\\\"0dp\\\"\\n                    android:layout_height=\\\"wrap_content\\\"\\n                    android:text=\\\"Reply\\\"\\n                    app:layout_constraintBottom_toBottomOf=\\\"parent\\\"\\n                    app:layout_constraintEnd_toStartOf=\\\"@+id/card_view_view_more\\\"\\n                    app:layout_constraintHorizontal_bias=\\\"0.5\\\"\\n                    app:layout_constraintStart_toStartOf=\\\"parent\\\" />\\n\\n                <Button\\n                    android:id=\\\"@+id/card_view_view_more\\\"\\n                    android:layout_width=\\\"0dp\\\"\\n                    android:layout_height=\\\"wrap_content\\\"\\n                    android:text=\\\"View More\\\"\\n                    app:layout_constraintBottom_toBottomOf=\\\"parent\\\"\\n                    app:layout_constraintEnd_toEndOf=\\\"parent\\\"\\n                    app:layout_constraintHorizontal_bias=\\\"0.5\\\"\\n                    app:layout_constraintStart_toEndOf=\\\"@+id/card_view_reply\\\" />\\n\\n            </androidx.constraintlayout.widget.ConstraintLayout>\\n        </androidx.cardview.widget.CardView>\\n    </androidx.constraintlayout.widget.ConstraintLayout>\\n</layout>\",\n      \"language\": \"xml\",\n      \"name\": \"fragment_custom_feed_item.xml\"\n    }\n  ]\n}\n[/block]\n\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"public class CustomFeedFragment extends Fragment {\\n    private FragmentCustomFeedBinding mBinding;\\n    private CustomFeedRecyclerAdapter mAdapter;\\n\\n    @Override\\n    public void onCreate(Bundle savedInstanceState) {\\n        super.onCreate(savedInstanceState);\\n        mAdapter = new CustomFeedRecyclerAdapter();\\n    }\\n\\n    @Override\\n    public View onCreateView(@NotNull LayoutInflater inflater, ViewGroup container,\\n                             Bundle savedInstanceState) {\\n        mBinding = DataBindingUtil.inflate(inflater, R.layout.fragment_custom_feed, container, false);\\n        setupRecyclerView();\\n        return mBinding.getRoot();\\n    }\\n\\n    @Override\\n    public void onStart() {\\n        super.onStart();\\n\\n        IPulsateManager pulsateManager = PulsateFactory.getInstance();\\n        pulsateManager.getFeed(1, new IPulsateValueListener<PulsateFeedState>() {\\n            @Override\\n            public void onSuccess(PulsateFeedState feedState) {\\n                mAdapter.setCustomFeed(feedState.mInboxItems);\\n            }\\n\\n            @Override\\n            public void onError(Throwable e) {\\n                e.printStackTrace();\\n            }\\n        });\\n    }\\n\\n    private void setupRecyclerView() {\\n        mBinding.customFeedRecycler.setLayoutManager(new GridLayoutManager(getContext(), 1));\\n        mBinding.customFeedRecycler.setAdapter(mAdapter);\\n    }\\n}\",\n      \"language\": \"java\",\n      \"name\": \"CustomFeedFragment.java\"\n    }\n  ]\n}\n[/block]\n\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"public class CustomFeedRecyclerAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> {\\n    public static final int INBOX_ITEM_NONE = 0;\\n    public static final int INBOX_ITEM_CARD = 1;\\n    public static final int INBOX_ITEM_TALK = 2;\\n    private final List<PulsateInboxItem> mInboxItems = new ArrayList<>();\\n\\n    public CustomFeedRecyclerAdapter() {\\n    }\\n\\n    public void setCustomFeed(List<PulsateInboxItem> newPulsateInboxItems) {\\n        mInboxItems.clear();\\n        mInboxItems.addAll(newPulsateInboxItems);\\n        notifyDataSetChanged();\\n    }\\n\\n    @Override\\n    public int getItemViewType(int position) {\\n        if (mInboxItems.get(position) instanceof PulsateInboxItemCard) {\\n            return INBOX_ITEM_CARD;\\n        } else if (mInboxItems.get(position) instanceof PulsateInboxItemTalk) {\\n            return INBOX_ITEM_TALK;\\n        }\\n        return INBOX_ITEM_NONE;\\n    }\\n\\n    @Override\\n    public int getItemCount() {\\n        return mInboxItems.size();\\n    }\\n\\n    @NotNull\\n    @Override\\n    public RecyclerView.ViewHolder onCreateViewHolder(@NotNull ViewGroup parent, int viewType) {\\n        LayoutInflater layoutInflater = LayoutInflater.from(parent.getContext());\\n        switch (viewType) {\\n            case INBOX_ITEM_CARD: {\\n                FragmentCustomFeedItemBinding itemBinding = FragmentCustomFeedItemBinding.inflate(layoutInflater, parent, false);\\n                return new FragmentCustomFeedItemCardViewHolder(itemBinding);\\n            }\\n            case INBOX_ITEM_TALK:\\n            default: {\\n                FragmentCustomFeedItemBinding itemBinding = FragmentCustomFeedItemBinding.inflate(layoutInflater, parent, false);\\n                return new FragmentCustomFeedItemTalkViewHolder(itemBinding);\\n            }\\n        }\\n    }\\n\\n    @Override\\n    public void onBindViewHolder(@NotNull RecyclerView.ViewHolder holder, int position) {\\n        switch (holder.getItemViewType()) {\\n            case INBOX_ITEM_CARD: {\\n                PulsateInboxItemCard itemCard = (PulsateInboxItemCard) mInboxItems.get(position);\\n                ((FragmentCustomFeedItemCardViewHolder) holder).bind(itemCard);\\n                break;\\n            }\\n            case INBOX_ITEM_TALK: {\\n                PulsateInboxItemTalk itemTalk = (PulsateInboxItemTalk) mInboxItems.get(position);\\n                ((FragmentCustomFeedItemTalkViewHolder) holder).bind(itemTalk);\\n                break;\\n            }\\n        }\\n    }\\n\\n    private static class FragmentCustomFeedItemCardViewHolder extends RecyclerView.ViewHolder {\\n        public final FragmentCustomFeedItemBinding mBinding;\\n\\n        public FragmentCustomFeedItemCardViewHolder(FragmentCustomFeedItemBinding binding) {\\n            super(binding.getRoot());\\n            this.mBinding = binding;\\n        }\\n\\n        public void bind(PulsateInboxItemCard itemCard) {\\n            mBinding.cardViewReply.setOnClickListener(view -> {\\n                IPulsateManager pulsateManager = PulsateFactory.getInstance();\\n                pulsateManager.handleFeedClick(itemCard, PulsateUtils.PulsateCardDestination.REPLY);\\n            });\\n            mBinding.cardViewViewMore.setOnClickListener(view -> {\\n                IPulsateManager pulsateManager = PulsateFactory.getInstance();\\n                pulsateManager.handleFeedClick(itemCard, PulsateUtils.PulsateCardDestination.VIEW_MORE);\\n            });\\n\\n            if (itemCard.front == null) {\\n                return;\\n            }\\n\\n            for (int i = 0; i < itemCard.front.size(); i++) {\\n                PulsateInboxFrontResponse frontElement = itemCard.front.get(i);\\n                if (frontElement.type.equals(\\\"headline\\\")) {\\n                    mBinding.cardViewTitle.setText(frontElement.attrs.get(0).text);\\n                } else if (frontElement.type.equals(\\\"text\\\")) {\\n                    mBinding.cardViewBody.setText(frontElement.attrs.get(0).text);\\n                }\\n            }\\n        }\\n    }\\n\\n    private static class FragmentCustomFeedItemTalkViewHolder extends RecyclerView.ViewHolder {\\n        public final FragmentCustomFeedItemBinding mBinding;\\n\\n        public FragmentCustomFeedItemTalkViewHolder(FragmentCustomFeedItemBinding binding) {\\n            super(binding.getRoot());\\n            this.mBinding = binding;\\n        }\\n\\n        public void bind(PulsateInboxItemTalk itemTalk) {\\n            mBinding.cardViewReply.setOnClickListener(view -> {\\n                IPulsateManager pulsateManager = PulsateFactory.getInstance();\\n                pulsateManager.handleFeedClick(itemTalk, PulsateUtils.PulsateCardDestination.REPLY);\\n            });\\n\\n            PulsateInboxLastMessageResponse lastMessage = itemTalk.lastMessages.get(0);\\n            mBinding.cardViewTitle.setText(lastMessage.sender);\\n            mBinding.cardViewBody.setText(lastMessage.content);\\n        }\\n    }\\n}\",\n      \"language\": \"java\",\n      \"name\": \"CustomFeedRecyclerAdapter.java\"\n    }\n  ]\n}\n[/block]","updates":[],"order":3,"isReference":false,"hidden":false,"sync_unique":"","link_url":"","link_external":false,"_id":"5f2ac541f25d380432a03e97","createdAt":"2020-08-05T14:42:09.311Z","user":"57bc3654b9c7f0220009c77b","category":{"sync":{"isSync":false,"url":""},"pages":[],"title":"SDK Advanced","slug":"sdk-advanced","order":3,"from_sync":false,"reference":false,"_id":"5f2ab1f9c1644603559149ac","createdAt":"2020-08-05T13:19:53.807Z","version":"5e5019b49e8f240011cc6ade","project":"54aa7f773b56130b0056c86e","__v":0},"version":{"version":"2.8","version_clean":"2.8.0","codename":"Android SDK","is_stable":false,"is_beta":false,"is_hidden":false,"is_deprecated":false,"categories":["5e5019b49e8f240011cc6a47","55781fe35129590d003ff4f9","55781fe35129590d003ff4fa","5e5019b49e8f240011cc6a48","5e5019b49e8f240011cc6a49","5e5019b49e8f240011cc6a4a","5e5019b49e8f240011cc6a4b","5e5019b49e8f240011cc6a4c","565b66c446118c0d00dcb0bb","56898269f8dc340d00308c13","5e5019b49e8f240011cc6a4d","5e5019b49e8f240011cc6a4e","5c73dd27e8fdc000572a206a","5e5019b49e8f240011cc6a4f","5e501b7e7c8bdc00450ea66a","5e53daa9884b750025b5cad4","5f2ab0dfbf70f7063ad0c4f3","5f2ab1e9448d87068b348f9c","5f2ab1f9c1644603559149ac","5f2ab205bc35e507e8cead35"],"_id":"5e5019b49e8f240011cc6ade","project":"54aa7f773b56130b0056c86e","forked_from":"5e4fbbbda8fb41028f1861fe","__v":6,"createdAt":"2015-06-10T11:30:42.700Z","releaseDate":"2015-06-10T11:30:42.700Z"},"project":"54aa7f773b56130b0056c86e","__v":0,"parentDoc":null}

Custom Pulsate Inbox


[block:api-header] { "title": "Creating a custom Pulsate Inbox" } [/block] The PuslateSDK also allows Developers to directly access the Pulsate Feed API to get the Pulsate Feed Models and build them in a custom way. To get the Feed Models just call this method "*void getFeed(int page, IPulsateValueListener<PulsateFeedState> listener)*". This method takes two arguments - "*page*" which specifies which page of the Feed do you want to get and "*listener*" which is the listener to which we send the Feed Models and any errors if they occur. The models that are returned are - PulsateInboxItemCard and PulsateInboxItemTalk. Having all these models you can build a custom Feed. [block:code] { "codes": [ { "code": "IPulsateManager pulsateManager = PulsateFactory.getInstance();\npulsateManager.getFeed(1, new IPulsateValueListener<PulsateFeedState>() {\n @Override\n public void onSuccess(PulsateFeedState feedState) {\n mAdapter.setCustomFeed(feedState.mInboxItems);\n }\n\n @Override\n public void onError(Throwable e) {\n e.printStackTrace();\n }\n});", "language": "java" } ] } [/block] Showing the Feed in a custom way also means that item clicks also need to be handled in a custom way. When handling on click events you must pass those clicks also to the PulsateSDK for it to be able to open the proper destination (deeplink, url, back of card, feed, reply) and also to send open event and custom events. To pass the clicks use the "*void handleFeedClick(PulsateInboxItem pulsateInboxItem, int destination)*" method. [block:code] { "codes": [ { "code": "mBinding.cardView.setOnClickListener(view -> {\n IPulsateManager pulsateManager = PulsateFactory.getInstance();\n pulsateManager.handleFeedClick(itemCard, PulsateUtils.PulsateCardDestination.VIEW_MORE);\n});", "language": "java" } ] } [/block] Example: [block:code] { "codes": [ { "code": "<layout xmlns:tools=\"http://schemas.android.com/tools\"\n xmlns:android=\"http://schemas.android.com/apk/res/android\"\n xmlns:app=\"http://schemas.android.com/apk/res-auto\">\n\n <data>\n\n </data>\n\n <androidx.constraintlayout.widget.ConstraintLayout\n android:id=\"@+id/container\"\n android:layout_width=\"match_parent\"\n android:layout_height=\"match_parent\">\n\n <androidx.recyclerview.widget.RecyclerView\n android:id=\"@+id/custom_feed_recycler\"\n android:layout_width=\"0dp\"\n android:layout_height=\"0dp\"\n app:layout_constraintBottom_toBottomOf=\"parent\"\n app:layout_constraintEnd_toEndOf=\"parent\"\n app:layout_constraintStart_toStartOf=\"parent\"\n app:layout_constraintTop_toTopOf=\"parent\" />\n </androidx.constraintlayout.widget.ConstraintLayout>\n</layout>", "language": "xml", "name": "fragment_custom_feed.xml" } ] } [/block] [block:code] { "codes": [ { "code": "<layout xmlns:tools=\"http://schemas.android.com/tools\"\n xmlns:android=\"http://schemas.android.com/apk/res/android\"\n xmlns:app=\"http://schemas.android.com/apk/res-auto\">\n\n <data>\n\n </data>\n\n <androidx.constraintlayout.widget.ConstraintLayout\n android:id=\"@+id/container\"\n android:layout_width=\"match_parent\"\n android:layout_height=\"wrap_content\">\n\n <androidx.cardview.widget.CardView\n android:id=\"@+id/card_view\"\n android:layout_width=\"0dp\"\n android:layout_height=\"wrap_content\"\n android:layout_marginStart=\"16dp\"\n android:layout_marginLeft=\"16dp\"\n android:layout_marginTop=\"16dp\"\n android:layout_marginEnd=\"16dp\"\n android:layout_marginRight=\"16dp\"\n android:layout_marginBottom=\"16dp\"\n app:cardBackgroundColor=\"@color/colorAccent\"\n app:cardCornerRadius=\"16dp\"\n app:layout_constraintBottom_toBottomOf=\"parent\"\n app:layout_constraintEnd_toEndOf=\"parent\"\n app:layout_constraintStart_toStartOf=\"parent\"\n app:layout_constraintTop_toTopOf=\"parent\">\n\n <androidx.constraintlayout.widget.ConstraintLayout\n android:id=\"@+id/card_view_container\"\n android:layout_width=\"match_parent\"\n android:layout_height=\"match_parent\">\n\n <TextView\n android:id=\"@+id/card_view_title\"\n android:layout_width=\"0dp\"\n android:layout_height=\"wrap_content\"\n android:layout_marginStart=\"16dp\"\n android:layout_marginLeft=\"16dp\"\n android:layout_marginTop=\"16dp\"\n android:layout_marginEnd=\"16dp\"\n android:layout_marginRight=\"16dp\"\n android:text=\"TextView\"\n app:layout_constraintEnd_toEndOf=\"parent\"\n app:layout_constraintStart_toStartOf=\"parent\"\n app:layout_constraintTop_toTopOf=\"parent\" />\n\n <TextView\n android:id=\"@+id/card_view_body\"\n android:layout_width=\"0dp\"\n android:layout_height=\"wrap_content\"\n android:layout_marginStart=\"16dp\"\n android:layout_marginLeft=\"16dp\"\n android:layout_marginTop=\"16dp\"\n android:layout_marginEnd=\"16dp\"\n android:layout_marginRight=\"16dp\"\n android:layout_marginBottom=\"16dp\"\n android:text=\"TextView\"\n app:layout_constraintBottom_toTopOf=\"@+id/card_view_reply\"\n app:layout_constraintEnd_toEndOf=\"parent\"\n app:layout_constraintStart_toStartOf=\"parent\"\n app:layout_constraintTop_toBottomOf=\"@+id/card_view_title\" />\n\n <Button\n android:id=\"@+id/card_view_reply\"\n android:layout_width=\"0dp\"\n android:layout_height=\"wrap_content\"\n android:text=\"Reply\"\n app:layout_constraintBottom_toBottomOf=\"parent\"\n app:layout_constraintEnd_toStartOf=\"@+id/card_view_view_more\"\n app:layout_constraintHorizontal_bias=\"0.5\"\n app:layout_constraintStart_toStartOf=\"parent\" />\n\n <Button\n android:id=\"@+id/card_view_view_more\"\n android:layout_width=\"0dp\"\n android:layout_height=\"wrap_content\"\n android:text=\"View More\"\n app:layout_constraintBottom_toBottomOf=\"parent\"\n app:layout_constraintEnd_toEndOf=\"parent\"\n app:layout_constraintHorizontal_bias=\"0.5\"\n app:layout_constraintStart_toEndOf=\"@+id/card_view_reply\" />\n\n </androidx.constraintlayout.widget.ConstraintLayout>\n </androidx.cardview.widget.CardView>\n </androidx.constraintlayout.widget.ConstraintLayout>\n</layout>", "language": "xml", "name": "fragment_custom_feed_item.xml" } ] } [/block] [block:code] { "codes": [ { "code": "public class CustomFeedFragment extends Fragment {\n private FragmentCustomFeedBinding mBinding;\n private CustomFeedRecyclerAdapter mAdapter;\n\n @Override\n public void onCreate(Bundle savedInstanceState) {\n super.onCreate(savedInstanceState);\n mAdapter = new CustomFeedRecyclerAdapter();\n }\n\n @Override\n public View onCreateView(@NotNull LayoutInflater inflater, ViewGroup container,\n Bundle savedInstanceState) {\n mBinding = DataBindingUtil.inflate(inflater, R.layout.fragment_custom_feed, container, false);\n setupRecyclerView();\n return mBinding.getRoot();\n }\n\n @Override\n public void onStart() {\n super.onStart();\n\n IPulsateManager pulsateManager = PulsateFactory.getInstance();\n pulsateManager.getFeed(1, new IPulsateValueListener<PulsateFeedState>() {\n @Override\n public void onSuccess(PulsateFeedState feedState) {\n mAdapter.setCustomFeed(feedState.mInboxItems);\n }\n\n @Override\n public void onError(Throwable e) {\n e.printStackTrace();\n }\n });\n }\n\n private void setupRecyclerView() {\n mBinding.customFeedRecycler.setLayoutManager(new GridLayoutManager(getContext(), 1));\n mBinding.customFeedRecycler.setAdapter(mAdapter);\n }\n}", "language": "java", "name": "CustomFeedFragment.java" } ] } [/block] [block:code] { "codes": [ { "code": "public class CustomFeedRecyclerAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> {\n public static final int INBOX_ITEM_NONE = 0;\n public static final int INBOX_ITEM_CARD = 1;\n public static final int INBOX_ITEM_TALK = 2;\n private final List<PulsateInboxItem> mInboxItems = new ArrayList<>();\n\n public CustomFeedRecyclerAdapter() {\n }\n\n public void setCustomFeed(List<PulsateInboxItem> newPulsateInboxItems) {\n mInboxItems.clear();\n mInboxItems.addAll(newPulsateInboxItems);\n notifyDataSetChanged();\n }\n\n @Override\n public int getItemViewType(int position) {\n if (mInboxItems.get(position) instanceof PulsateInboxItemCard) {\n return INBOX_ITEM_CARD;\n } else if (mInboxItems.get(position) instanceof PulsateInboxItemTalk) {\n return INBOX_ITEM_TALK;\n }\n return INBOX_ITEM_NONE;\n }\n\n @Override\n public int getItemCount() {\n return mInboxItems.size();\n }\n\n @NotNull\n @Override\n public RecyclerView.ViewHolder onCreateViewHolder(@NotNull ViewGroup parent, int viewType) {\n LayoutInflater layoutInflater = LayoutInflater.from(parent.getContext());\n switch (viewType) {\n case INBOX_ITEM_CARD: {\n FragmentCustomFeedItemBinding itemBinding = FragmentCustomFeedItemBinding.inflate(layoutInflater, parent, false);\n return new FragmentCustomFeedItemCardViewHolder(itemBinding);\n }\n case INBOX_ITEM_TALK:\n default: {\n FragmentCustomFeedItemBinding itemBinding = FragmentCustomFeedItemBinding.inflate(layoutInflater, parent, false);\n return new FragmentCustomFeedItemTalkViewHolder(itemBinding);\n }\n }\n }\n\n @Override\n public void onBindViewHolder(@NotNull RecyclerView.ViewHolder holder, int position) {\n switch (holder.getItemViewType()) {\n case INBOX_ITEM_CARD: {\n PulsateInboxItemCard itemCard = (PulsateInboxItemCard) mInboxItems.get(position);\n ((FragmentCustomFeedItemCardViewHolder) holder).bind(itemCard);\n break;\n }\n case INBOX_ITEM_TALK: {\n PulsateInboxItemTalk itemTalk = (PulsateInboxItemTalk) mInboxItems.get(position);\n ((FragmentCustomFeedItemTalkViewHolder) holder).bind(itemTalk);\n break;\n }\n }\n }\n\n private static class FragmentCustomFeedItemCardViewHolder extends RecyclerView.ViewHolder {\n public final FragmentCustomFeedItemBinding mBinding;\n\n public FragmentCustomFeedItemCardViewHolder(FragmentCustomFeedItemBinding binding) {\n super(binding.getRoot());\n this.mBinding = binding;\n }\n\n public void bind(PulsateInboxItemCard itemCard) {\n mBinding.cardViewReply.setOnClickListener(view -> {\n IPulsateManager pulsateManager = PulsateFactory.getInstance();\n pulsateManager.handleFeedClick(itemCard, PulsateUtils.PulsateCardDestination.REPLY);\n });\n mBinding.cardViewViewMore.setOnClickListener(view -> {\n IPulsateManager pulsateManager = PulsateFactory.getInstance();\n pulsateManager.handleFeedClick(itemCard, PulsateUtils.PulsateCardDestination.VIEW_MORE);\n });\n\n if (itemCard.front == null) {\n return;\n }\n\n for (int i = 0; i < itemCard.front.size(); i++) {\n PulsateInboxFrontResponse frontElement = itemCard.front.get(i);\n if (frontElement.type.equals(\"headline\")) {\n mBinding.cardViewTitle.setText(frontElement.attrs.get(0).text);\n } else if (frontElement.type.equals(\"text\")) {\n mBinding.cardViewBody.setText(frontElement.attrs.get(0).text);\n }\n }\n }\n }\n\n private static class FragmentCustomFeedItemTalkViewHolder extends RecyclerView.ViewHolder {\n public final FragmentCustomFeedItemBinding mBinding;\n\n public FragmentCustomFeedItemTalkViewHolder(FragmentCustomFeedItemBinding binding) {\n super(binding.getRoot());\n this.mBinding = binding;\n }\n\n public void bind(PulsateInboxItemTalk itemTalk) {\n mBinding.cardViewReply.setOnClickListener(view -> {\n IPulsateManager pulsateManager = PulsateFactory.getInstance();\n pulsateManager.handleFeedClick(itemTalk, PulsateUtils.PulsateCardDestination.REPLY);\n });\n\n PulsateInboxLastMessageResponse lastMessage = itemTalk.lastMessages.get(0);\n mBinding.cardViewTitle.setText(lastMessage.sender);\n mBinding.cardViewBody.setText(lastMessage.content);\n }\n }\n}", "language": "java", "name": "CustomFeedRecyclerAdapter.java" } ] } [/block]