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 */
16package com.android.dialer.calllog.ui;
17
18import android.database.Cursor;
19import android.support.v7.widget.RecyclerView;
20import android.view.LayoutInflater;
21import android.view.ViewGroup;
22import com.android.dialer.calllog.database.contract.AnnotatedCallLogContract.CoalescedAnnotatedCallLog;
23
24/** {@link RecyclerView.Adapter} for the new call log fragment. */
25final class NewCallLogAdapter extends RecyclerView.Adapter<NewCallLogViewHolder> {
26
27  private final Cursor cursor;
28  private final int timestampIndex;
29
30  NewCallLogAdapter(Cursor cursor) {
31    this.cursor = cursor;
32    timestampIndex = cursor.getColumnIndexOrThrow(CoalescedAnnotatedCallLog.TIMESTAMP);
33  }
34
35  @Override
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
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
50  public int getItemCount() {
51    return cursor.getCount();
52  }
53}
54