1 /* 2 * Copyright (C) 2017 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License 15 */ 16 package com.android.dialer.calllog.ui; 17 18 import android.database.Cursor; 19 import android.support.v7.widget.RecyclerView; 20 import android.view.LayoutInflater; 21 import android.view.ViewGroup; 22 import com.android.dialer.calllog.database.contract.AnnotatedCallLogContract.CoalescedAnnotatedCallLog; 23 24 /** {@link RecyclerView.Adapter} for the new call log fragment. */ 25 final class NewCallLogAdapter extends RecyclerView.Adapter<NewCallLogViewHolder> { 26 27 private final Cursor cursor; 28 private final int timestampIndex; 29 NewCallLogAdapter(Cursor cursor)30 NewCallLogAdapter(Cursor cursor) { 31 this.cursor = cursor; 32 timestampIndex = cursor.getColumnIndexOrThrow(CoalescedAnnotatedCallLog.TIMESTAMP); 33 } 34 35 @Override onCreateViewHolder(ViewGroup viewGroup, int viewType)36 public NewCallLogViewHolder onCreateViewHolder(ViewGroup viewGroup, int viewType) { 37 return new NewCallLogViewHolder( 38 LayoutInflater.from(viewGroup.getContext()) 39 .inflate(R.layout.new_call_log_entry, viewGroup, false)); 40 } 41 42 @Override onBindViewHolder(NewCallLogViewHolder viewHolder, int position)43 public void onBindViewHolder(NewCallLogViewHolder viewHolder, int position) { 44 cursor.moveToPosition(position); 45 long timestamp = cursor.getLong(timestampIndex); 46 viewHolder.bind(timestamp); 47 } 48 49 @Override getItemCount()50 public int getItemCount() { 51 return cursor.getCount(); 52 } 53 } 54