Added Android code
[wl-app.git] / Android / folioreader / src / main / java / com / folioreader / ui / folio / adapter / FontAdapter.java
1 /*
2 * Copyright (C) 2016 Pedro Paulo de Amorim
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.folioreader.ui.folio.adapter;
17
18 import com.folioreader.Font;
19 import com.folioreader.R;
20
21 import android.support.v7.widget.RecyclerView;
22 import android.view.LayoutInflater;
23 import android.view.View;
24 import android.view.ViewGroup;
25 import android.widget.TextView;
26
27 import java.util.ArrayList;
28
29 public class FontAdapter extends RecyclerView.Adapter<FontAdapter.ViewHolder> {
30
31     private ArrayList<Font> mFonts = null;
32
33     @Override
34     public FontAdapter.ViewHolder onCreateViewHolder(ViewGroup parent, int i) {
35         return new ViewHolder(LayoutInflater.from(parent.getContext())
36                 .inflate(R.layout.row_font, parent, false));
37     }
38
39     @Override
40     public void onBindViewHolder(ViewHolder viewHolder, int i) {
41         viewHolder.mName.setText(mFonts.get(i).getName());
42     }
43
44     @Override
45     public int getItemCount() {
46         return mFonts != null ? mFonts.size() : 0;
47     }
48
49     public void setFonts(ArrayList<Font> mFonts) {
50         this.mFonts = mFonts;
51     }
52
53     public static class ViewHolder extends RecyclerView.ViewHolder {
54
55         private TextView mName;
56
57         public ViewHolder(View v) {
58             super(v);
59             mName = (TextView) v.findViewById(R.id.name);
60         }
61     }
62 }