blob: 868fed46c55462938d7d292dadd3927d6a37d80b (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
|
/*
* Copyright (C) 2015 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.tv.guide;
import android.content.res.Resources;
import android.support.v7.widget.RecyclerView;
import android.text.format.DateFormat;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;
import com.android.tv.R;
import java.util.Date;
import java.util.concurrent.TimeUnit;
/**
* Adapts the time range from {@link ProgramManager} to the timeline header row of the program
* guide table.
*/
public class TimeListAdapter extends RecyclerView.Adapter<TimeListAdapter.TimeViewHolder> {
private static final long TIME_UNIT_MS = TimeUnit.MINUTES.toMillis(30);
private static int sRowHeaderOverlapping;
// Nearest half hour at or before the start time.
private long mStartUtcMs;
public TimeListAdapter(Resources res) {
if (sRowHeaderOverlapping == 0) {
sRowHeaderOverlapping = Math.abs(res.getDimensionPixelOffset(
R.dimen.program_guide_table_header_row_overlap));
}
}
public void update(long startTimeMs) {
mStartUtcMs = startTimeMs;
notifyDataSetChanged();
}
@Override
public int getItemCount() {
return Integer.MAX_VALUE;
}
@Override
public int getItemViewType(int position) {
return R.layout.program_guide_table_header_row_item;
}
@Override
public void onBindViewHolder(TimeViewHolder holder, int position) {
long startTime = mStartUtcMs + position * TIME_UNIT_MS;
long endTime = startTime + TIME_UNIT_MS;
View itemView = holder.itemView;
TextView textView = (TextView) itemView.findViewById(R.id.time);
String time = DateFormat.getTimeFormat(itemView.getContext()).format(new Date(startTime));
textView.setText(time);
RecyclerView.LayoutParams lp = (RecyclerView.LayoutParams) itemView.getLayoutParams();
lp.width = GuideUtils.convertMillisToPixel(startTime, endTime);
if (position == 0) {
// Adjust width for the first entry to make the item starts from the fading edge.
lp.setMarginStart(sRowHeaderOverlapping - lp.width / 2);
} else {
lp.setMarginStart(0);
}
itemView.setLayoutParams(lp);
}
@Override
public TimeViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
View itemView = LayoutInflater.from(parent.getContext()).inflate(viewType, parent, false);
return new TimeViewHolder(itemView);
}
public static class TimeViewHolder extends RecyclerView.ViewHolder {
public TimeViewHolder(View itemView) {
super(itemView);
}
}
}
|