1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package org.exoplatform.controller.document;
20
21 import java.util.List;
22
23 import org.exoplatform.R;
24 import org.exoplatform.model.ExoFile;
25 import org.exoplatform.ui.DocumentActionDialog;
26 import org.exoplatform.ui.DocumentActivity;
27 import org.exoplatform.utils.CompatibleFileOpen.FileOpenRequest;
28 import org.exoplatform.utils.CompatibleFileOpen.FileOpenRequestResult;
29 import org.exoplatform.utils.ExoConstants;
30 import org.exoplatform.utils.ExoDocumentUtils;
31 import org.exoplatform.widget.UnreadableFileDialog;
32
33 import android.content.Context;
34 import android.view.LayoutInflater;
35 import android.view.View;
36 import android.view.ViewGroup;
37 import android.widget.BaseAdapter;
38 import android.widget.ImageButton;
39 import android.widget.ImageView;
40 import android.widget.TextView;
41
42 public class DocumentAdapter extends BaseAdapter {
43
44 private List<ExoFile> _documentList;
45
46 private DocumentActivity _mContext;
47
48 public DocumentActionDialog _documentActionDialog;
49
50 public DocumentAdapter(DocumentActivity context, List<ExoFile> list) {
51
52 _mContext = context;
53 _documentList = list;
54
55 }
56
57 @Override
58 public int getCount() {
59 return _documentList.size();
60 }
61
62 @Override
63 public Object getItem(int pos) {
64 return pos;
65 }
66
67 @Override
68 public long getItemId(int pos) {
69 return pos;
70 }
71
72 @Override
73 public View getView(int position, View convertView, ViewGroup parent) {
74
75 final int pos = position;
76
77 LayoutInflater inflater = (LayoutInflater) _mContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
78
79 final ExoFile myFile = _documentList.get(pos);
80
81 if ("".equals(myFile.name) && "".equals(myFile.path)) {
82 convertView = inflater.inflate(R.layout.gadget_tab_layout, parent, false);
83 TextView textViewTabTitle = (TextView) convertView.findViewById(R.id.textView_Tab_Title);
84 if (myFile.driveName.equals(ExoConstants.DOCUMENT_PERSONAL_DRIVER))
85 textViewTabTitle.setText(_mContext.getResources().getString(R.string.Personal));
86 else if (myFile.driveName.equals(ExoConstants.DOCUMENT_GROUP_DRIVER))
87 textViewTabTitle.setText(_mContext.getResources().getString(R.string.Group));
88 else if (myFile.driveName.equals(ExoConstants.DOCUMENT_GENERAL_DRIVER))
89 textViewTabTitle.setText(_mContext.getResources().getString(R.string.General));
90 return (convertView);
91 } else {
92 convertView = inflater.inflate(R.layout.fileitem, parent, false);
93
94 ImageButton btnAction = (ImageButton) convertView.findViewById(R.id.Button_FileAction);
95 ImageView icon = (ImageView) convertView.findViewById(R.id.icon);
96 TextView lb = (TextView) convertView.findViewById(R.id.label);
97
98 lb.setText(myFile.getName());
99
100 if ("".equals(myFile.currentFolder)) {
101
102
103
104 btnAction.setVisibility(View.INVISIBLE);
105
106 }
107
108 if (position == 0) {
109 if (_documentList.size() == 1)
110 convertView.setBackgroundResource(R.drawable.dashboard_single_background_shape);
111 else {
112 convertView.setBackgroundResource(R.drawable.dashboard_top_background_shape);
113 }
114 } else {
115 if (position + 1 == _documentList.size())
116 convertView.setBackgroundResource(R.drawable.dasboard_bottom_background_shape);
117 else {
118 ExoFile previousItem = _documentList.get(position - 1);
119 ExoFile nextItem = _documentList.get(position + 1);
120
121 if ("".equals(previousItem.name) && "".equals(previousItem.path) && "".equals(nextItem.name)
122 && "".equals(nextItem.path)) {
123 convertView.setBackgroundResource(R.drawable.dashboard_single_background_shape);
124 } else if ("".equals(previousItem.name) && "".equals(previousItem.path)) {
125 convertView.setBackgroundResource(R.drawable.dashboard_top_background_shape);
126 } else if ("".equals(nextItem.name) && "".equals(nextItem.path))
127 convertView.setBackgroundResource(R.drawable.dasboard_bottom_background_shape);
128 else
129 convertView.setBackgroundResource(R.drawable.dashboard_middle_background_shape);
130 }
131 }
132
133 if (!myFile.isFolder) {
134 btnAction.setVisibility(View.VISIBLE);
135
136 icon.setImageResource(ExoDocumentUtils.getIconFromType(myFile.nodeType));
137
138 } else {
139 icon.setImageResource(R.drawable.documenticonforfolder);
140 }
141
142 convertView.setOnClickListener(new View.OnClickListener() {
143 public void onClick(View v) {
144 if (!myFile.isFolder) {
145
146
147
148 if (ExoDocumentUtils.isForbidden(myFile.nodeType)) {
149 new UnreadableFileDialog(_mContext, null).show();
150 } else {
151 FileOpenRequest fileOpenReq = ExoDocumentUtils.fileOpen(_mContext, myFile.nodeType, myFile.path, myFile.name);
152 if (fileOpenReq.mResult == FileOpenRequestResult.EXTERNAL) {
153 DocumentActivity._documentActivityInstance.mFileOpenController = fileOpenReq.mFileOpenController;
154 }
155 }
156 } else {
157 DocumentActivity._documentActivityInstance.loadFolderContent(myFile);
158 }
159 }
160 });
161
162 btnAction.setOnClickListener(new View.OnClickListener() {
163 public void onClick(View v) {
164 ExoFile file = _documentList.get(pos);
165 _documentActionDialog = new DocumentActionDialog(_mContext, file, false);
166 _documentActionDialog.myFile = file;
167 _documentActionDialog._documentActionAdapter.setSelectedFile(file);
168 _documentActionDialog._documentActionAdapter.notifyDataSetChanged();
169 _documentActionDialog.setTileForDialog(file.name);
170 _documentActionDialog.show();
171 }
172 });
173 return convertView;
174 }
175 }
176 }