Download File
Download Project
Settings
Line Wrap
Themes
default
ambiance
bespin
dracula
eclipse
material
mbo
mdn-like
neat
solarized dark
ttcn
zenburn
RepoListAdapter.java
/* * Copyright (C) 2017 The Android Open Source Project * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.android.example.github.ui.common; import com.android.example.github.R; import com.android.example.github.databinding.RepoItemBinding; import com.android.example.github.util.Objects; import com.android.example.github.vo.Repo; import android.databinding.DataBindingComponent; import android.databinding.DataBindingUtil; import android.view.LayoutInflater; import android.view.ViewGroup; /** * A RecyclerView adapter for {@link Repo} class. */ public class RepoListAdapter extends DataBoundListAdapter
{ private final DataBindingComponent dataBindingComponent; private final RepoClickCallback repoClickCallback; private final boolean showFullName; public RepoListAdapter(DataBindingComponent dataBindingComponent, boolean showFullName, RepoClickCallback repoClickCallback) { this.dataBindingComponent = dataBindingComponent; this.repoClickCallback = repoClickCallback; this.showFullName = showFullName; } @Override protected RepoItemBinding createBinding(ViewGroup parent) { RepoItemBinding binding = DataBindingUtil .inflate(LayoutInflater.from(parent.getContext()), R.layout.repo_item, parent, false, dataBindingComponent); binding.setShowFullName(showFullName); binding.getRoot().setOnClickListener(v -> { Repo repo = binding.getRepo(); if (repo != null && repoClickCallback != null) { repoClickCallback.onClick(repo); } }); return binding; } @Override protected void bind(RepoItemBinding binding, Repo item) { binding.setRepo(item); } @Override protected boolean areItemsTheSame(Repo oldItem, Repo newItem) { return Objects.equals(oldItem.owner, newItem.owner) && Objects.equals(oldItem.name, newItem.name); } @Override protected boolean areContentsTheSame(Repo oldItem, Repo newItem) { return Objects.equals(oldItem.description, newItem.description) && oldItem.stars == newItem.stars; } public interface RepoClickCallback { void onClick(Repo repo); } }