1 package be
.nikiroo
.fanfix
.reader
.android
;
3 import android
.app
.Fragment
;
4 import android
.app
.FragmentTransaction
;
5 import android
.content
.Context
;
6 import android
.os
.Bundle
;
7 import android
.view
.LayoutInflater
;
8 import android
.view
.View
;
9 import android
.view
.ViewGroup
;
10 import android
.widget
.BaseAdapter
;
11 import android
.widget
.ListView
;
13 import java
.util
.ArrayList
;
14 import java
.util
.HashMap
;
15 import java
.util
.List
;
18 import be
.nikiroo
.fanfix
.data
.MetaData
;
19 import be
.nikiroo
.fanfix
.reader
.Reader
;
22 * A simple {@link Fragment} subclass. Activities that contain this fragment
23 * must implement the {@link AndroidReaderGroup.OnFragmentInteractionListener}
24 * interface to handle interaction events.
26 public class AndroidReaderGroup
extends Fragment
{
27 private OnFragmentInteractionListener listener
;
28 private Map
<View
, AndroidReaderBook
> books
= new HashMap
<View
, AndroidReaderBook
>();
30 public interface OnFragmentInteractionListener
{
31 void onFragmentInteraction(MetaData meta
);
34 public AndroidReaderGroup() {
35 // Required empty public constructor
39 public View
onCreateView(LayoutInflater inflater
, ViewGroup container
,
40 Bundle savedInstanceState
) {
41 return inflater
.inflate(R
.layout
.fragment_android_reader_group
,
46 public void onAttach(Context context
) {
47 super.onAttach(context
);
48 if (context
instanceof OnFragmentInteractionListener
) {
49 listener
= (OnFragmentInteractionListener
) context
;
54 public void onDetach() {
59 public void fill(final List
<MetaData
> metas
, final Reader reader
) {
60 final List
<MetaData
> datas
= new ArrayList
<MetaData
>(metas
);
62 ListView list
= getView().findViewById(R
.id
.Group_root
);
63 list
.setAdapter(new BaseAdapter() {
65 public int getCount() {
70 public long getItemId(int position
) {
71 return -1; // TODO: what is a "row id" in this context?
75 public Object
getItem(int position
) {
76 return datas
.get(position
);
80 public View
getView(int position
, View convertView
, ViewGroup parent
) {
81 AndroidReaderBook book
= books
.get(convertView
);
83 book
= new AndroidReaderBook();
85 FragmentTransaction trans
= getFragmentManager()
87 trans
.add(book
, null);
89 getFragmentManager().executePendingTransactions();
91 books
.put(book
.getView(), book
);
94 MetaData meta
= (MetaData
) getItem(position
);
95 book
.fill(meta
, reader
);
97 return book
.getView();