com.xamoom.android.xamoomcontentblocks.Adapters.ContentBlock1Adapter.java Source code

Java tutorial

Introduction

Here is the source code for com.xamoom.android.xamoomcontentblocks.Adapters.ContentBlock1Adapter.java

Source

/*
* Copyright 2017 by xamoom GmbH <apps@xamoom.com>
*
* This file is part of some open source application.
*
* Some open source application is free software: you can redistribute
* it and/or modify it under the terms of the GNU General Public
* License as published by the Free Software Foundation, either
* version 2 of the License, or (at your option) any later version.
*
* Some open source application is distributed in the hope that it will
* be useful, but WITHOUT ANY WARRANTY; without even the implied warranty
* of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with xamoom-android-sdk. If not, see <http://www.gnu.org/licenses/>.
*
* author: Raphael Seher <raphael@xamoom.com>
*/

package com.xamoom.android.xamoomcontentblocks.Adapters;

import android.support.annotation.NonNull;
import android.support.v4.app.Fragment;
import android.support.v4.util.LruCache;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import com.xamoom.android.xamoomcontentblocks.ViewHolders.ContentBlock1ViewHolder;
import com.xamoom.android.xamoomcontentblocks.ViewHolders.ContentBlock3ViewHolder;
import com.xamoom.android.xamoomcontentblocks.XamoomContentFragment;
import com.xamoom.android.xamoomsdk.EnduserApi;
import com.xamoom.android.xamoomsdk.R;
import com.xamoom.android.xamoomsdk.Resource.ContentBlock;
import com.xamoom.android.xamoomsdk.Resource.Style;

import java.util.List;

public class ContentBlock1Adapter implements AdapterDelegate<List<ContentBlock>> {
    private static final int BLOCK_TYPE = 1;

    @Override
    public boolean isForViewType(@NonNull List<ContentBlock> items, int position) {
        ContentBlock cb = items.get(position);
        return cb.getBlockType() == BLOCK_TYPE;
    }

    @NonNull
    @Override
    public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, Fragment fragment, EnduserApi enduserApi,
            String youtubeApiKey, LruCache bitmapCache, LruCache contentCache, boolean showContentLinks,
            ContentBlock3ViewHolder.OnContentBlock3ViewHolderInteractionListener onContentBlock3ViewHolderInteractionListener,
            XamoomContentFragment.OnXamoomContentFragmentInteractionListener onXamoomContentFragmentInteractionListener) {
        View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.content_block_1_layout, parent,
                false);
        return new ContentBlock1ViewHolder(view, fragment);
    }

    @Override
    public void onBindViewHolder(@NonNull List<ContentBlock> items, int position,
            @NonNull RecyclerView.ViewHolder holder, Style style, boolean offline) {
        ContentBlock cb = items.get(position);
        ContentBlock1ViewHolder newHolder = (ContentBlock1ViewHolder) holder;
        newHolder.setupContentBlock(cb, offline);
    }
}