|
@@ -20,28 +20,25 @@ package com.owncloud.android.ui.adapter;
|
|
|
import android.accounts.Account;
|
|
|
import android.content.Context;
|
|
|
import android.database.Cursor;
|
|
|
-import android.support.v4.widget.SimpleCursorAdapter;
|
|
|
+import android.support.v4.widget.CursorAdapter;
|
|
|
import android.view.LayoutInflater;
|
|
|
import android.view.View;
|
|
|
import android.view.ViewGroup;
|
|
|
-//import android.widget.BaseAdapter;
|
|
|
import android.widget.ImageView;
|
|
|
import android.widget.ListAdapter;
|
|
|
import android.widget.ListView;
|
|
|
import android.widget.TextView;
|
|
|
|
|
|
|
|
|
-import java.util.Vector;
|
|
|
-
|
|
|
import com.owncloud.android.R;
|
|
|
import com.owncloud.android.authentication.AccountUtils;
|
|
|
import com.owncloud.android.datamodel.FileDataStorageManager;
|
|
|
import com.owncloud.android.datamodel.OCFile;
|
|
|
-import com.owncloud.android.db.ProviderMeta;
|
|
|
import com.owncloud.android.files.services.FileDownloader.FileDownloaderBinder;
|
|
|
import com.owncloud.android.files.services.FileUploader.FileUploaderBinder;
|
|
|
import com.owncloud.android.ui.activity.TransferServiceGetter;
|
|
|
import com.owncloud.android.utils.DisplayUtils;
|
|
|
+import com.owncloud.android.utils.Log_OC;
|
|
|
|
|
|
|
|
|
/**
|
|
@@ -51,44 +48,23 @@ import com.owncloud.android.utils.DisplayUtils;
|
|
|
* @author Bartek Przybylski
|
|
|
*
|
|
|
*/
|
|
|
-public class FileListListAdapter extends SimpleCursorAdapter implements ListAdapter {
|
|
|
+public class FileListListAdapter extends CursorAdapter implements ListAdapter {
|
|
|
|
|
|
+ private static final String TAG = FileListListAdapter.class.getSimpleName();
|
|
|
+
|
|
|
private Context mContext;
|
|
|
- private static OCFile mFile = null;
|
|
|
- private Vector<OCFile> mFiles = null;
|
|
|
- private static FileDataStorageManager mStorageManager;
|
|
|
+ private FileDataStorageManager mStorageManager;
|
|
|
private Account mAccount;
|
|
|
private TransferServiceGetter mTransferServiceGetter;
|
|
|
- private static Cursor mCursor = null;
|
|
|
-
|
|
|
- private static String[] cursorFrom = { ProviderMeta.ProviderTableMeta.FILE_NAME,
|
|
|
- ProviderMeta.ProviderTableMeta.FILE_MODIFIED,
|
|
|
- ProviderMeta.ProviderTableMeta.FILE_CONTENT_LENGTH
|
|
|
- };
|
|
|
- private static int[] cursorTo = { R.id.Filename,
|
|
|
- R.id.last_mod,
|
|
|
- R.id.file_size
|
|
|
- };
|
|
|
-
|
|
|
- public FileListListAdapter(Context context, int layout, Cursor c, String[] from, int[] to, int flags) {
|
|
|
- super(context, layout, c, from, to, flags);
|
|
|
- // TODO Auto-generated constructor stub
|
|
|
- }
|
|
|
|
|
|
- public FileListListAdapter(Context context, TransferServiceGetter transferServiceGetter, OCFile file) {
|
|
|
- super(context,
|
|
|
- R.layout.list_item,
|
|
|
- mCursor,
|
|
|
- cursorFrom,
|
|
|
- cursorTo,
|
|
|
- 0);
|
|
|
+ public FileListListAdapter(Context context, TransferServiceGetter transferServiceGetter) {
|
|
|
+ super(context, null, 0);
|
|
|
mContext = context;
|
|
|
mAccount = AccountUtils.getCurrentOwnCloudAccount(mContext);
|
|
|
mTransferServiceGetter = transferServiceGetter;
|
|
|
- mFile = file;
|
|
|
- mCursor = file == null ? null: mStorageManager.getContent(file.getParentId());
|
|
|
}
|
|
|
|
|
|
+ /*
|
|
|
@Override
|
|
|
public boolean areAllItemsEnabled() {
|
|
|
return true;
|
|
@@ -122,91 +98,7 @@ public class FileListListAdapter extends SimpleCursorAdapter implements ListAdap
|
|
|
public int getItemViewType(int position) {
|
|
|
return 0;
|
|
|
}
|
|
|
-
|
|
|
- @Override
|
|
|
- public View getView(int position, View convertView, ViewGroup parent) {
|
|
|
- View view = convertView;
|
|
|
- if (view == null) {
|
|
|
- LayoutInflater inflator = (LayoutInflater) mContext
|
|
|
- .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
|
|
|
- view = inflator.inflate(R.layout.list_item, null);
|
|
|
- }
|
|
|
|
|
|
- if (mFiles != null && mFiles.size() > position) {
|
|
|
- OCFile file = mFiles.get(position);
|
|
|
- TextView fileName = (TextView) view.findViewById(R.id.Filename);
|
|
|
- String name = file.getFileName();
|
|
|
-
|
|
|
- fileName.setText(name);
|
|
|
- ImageView fileIcon = (ImageView) view.findViewById(R.id.imageView1);
|
|
|
- fileIcon.setImageResource(DisplayUtils.getResourceId(file.getMimetype()));
|
|
|
- ImageView localStateView = (ImageView) view.findViewById(R.id.imageView2);
|
|
|
- FileDownloaderBinder downloaderBinder = mTransferServiceGetter.getFileDownloaderBinder();
|
|
|
- FileUploaderBinder uploaderBinder = mTransferServiceGetter.getFileUploaderBinder();
|
|
|
- if (downloaderBinder != null && downloaderBinder.isDownloading(mAccount, file)) {
|
|
|
- localStateView.setImageResource(R.drawable.downloading_file_indicator);
|
|
|
- localStateView.setVisibility(View.VISIBLE);
|
|
|
- } else if (uploaderBinder != null && uploaderBinder.isUploading(mAccount, file)) {
|
|
|
- localStateView.setImageResource(R.drawable.uploading_file_indicator);
|
|
|
- localStateView.setVisibility(View.VISIBLE);
|
|
|
- } else if (file.isDown()) {
|
|
|
- localStateView.setImageResource(R.drawable.local_file_indicator);
|
|
|
- localStateView.setVisibility(View.VISIBLE);
|
|
|
- } else {
|
|
|
- localStateView.setVisibility(View.INVISIBLE);
|
|
|
- }
|
|
|
-
|
|
|
- TextView fileSizeV = (TextView) view.findViewById(R.id.file_size);
|
|
|
- TextView lastModV = (TextView) view.findViewById(R.id.last_mod);
|
|
|
- ImageView checkBoxV = (ImageView) view.findViewById(R.id.custom_checkbox);
|
|
|
-
|
|
|
- if (!file.isFolder()) {
|
|
|
- fileSizeV.setVisibility(View.VISIBLE);
|
|
|
- fileSizeV.setText(DisplayUtils.bytesToHumanReadable(file.getFileLength()));
|
|
|
- lastModV.setVisibility(View.VISIBLE);
|
|
|
- lastModV.setText(DisplayUtils.unixTimeToHumanReadable(file.getModificationTimestamp()));
|
|
|
- // this if-else is needed even thoe fav icon is visible by default
|
|
|
- // because android reuses views in listview
|
|
|
- if (!file.keepInSync()) {
|
|
|
- view.findViewById(R.id.imageView3).setVisibility(View.GONE);
|
|
|
- } else {
|
|
|
- view.findViewById(R.id.imageView3).setVisibility(View.VISIBLE);
|
|
|
- }
|
|
|
-
|
|
|
- ListView parentList = (ListView)parent;
|
|
|
- if (parentList.getChoiceMode() == ListView.CHOICE_MODE_NONE) {
|
|
|
- checkBoxV.setVisibility(View.GONE);
|
|
|
- } else {
|
|
|
- if (parentList.isItemChecked(position)) {
|
|
|
- checkBoxV.setImageResource(android.R.drawable.checkbox_on_background);
|
|
|
- } else {
|
|
|
- checkBoxV.setImageResource(android.R.drawable.checkbox_off_background);
|
|
|
- }
|
|
|
- checkBoxV.setVisibility(View.VISIBLE);
|
|
|
- }
|
|
|
-
|
|
|
- }
|
|
|
- else {
|
|
|
-
|
|
|
- fileSizeV.setVisibility(View.INVISIBLE);
|
|
|
- //fileSizeV.setText(DisplayUtils.bytesToHumanReadable(file.getFileLength()));
|
|
|
- lastModV.setVisibility(View.VISIBLE);
|
|
|
- lastModV.setText(DisplayUtils.unixTimeToHumanReadable(file.getModificationTimestamp()));
|
|
|
- checkBoxV.setVisibility(View.GONE);
|
|
|
- view.findViewById(R.id.imageView3).setVisibility(View.GONE);
|
|
|
- }
|
|
|
-
|
|
|
- ImageView shareIconV = (ImageView) view.findViewById(R.id.shareIcon);
|
|
|
- if (file.isShareByLink()) {
|
|
|
- shareIconV.setVisibility(View.VISIBLE);
|
|
|
- } else {
|
|
|
- shareIconV.setVisibility(View.INVISIBLE);
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- return view;
|
|
|
- }
|
|
|
-
|
|
|
@Override
|
|
|
public int getViewTypeCount() {
|
|
|
return 1;
|
|
@@ -221,26 +113,118 @@ public class FileListListAdapter extends SimpleCursorAdapter implements ListAdap
|
|
|
public boolean isEmpty() {
|
|
|
return (mFiles == null || mFiles.isEmpty());
|
|
|
}
|
|
|
+ */
|
|
|
|
|
|
/**
|
|
|
* Change the adapted directory for a new one
|
|
|
- * @param directory New file to adapt. Can be NULL, meaning "no content to adapt".
|
|
|
+ * @param folder New file to adapt. Can be NULL, meaning "no content to adapt".
|
|
|
* @param updatedStorageManager Optional updated storage manager; used to replace mStorageManager if is different (and not NULL)
|
|
|
*/
|
|
|
- public void swapDirectory(OCFile directory, FileDataStorageManager updatedStorageManager) {
|
|
|
- mFile = directory;
|
|
|
+ public void swapDirectory(OCFile folder, FileDataStorageManager updatedStorageManager) {
|
|
|
if (updatedStorageManager != null && updatedStorageManager != mStorageManager) {
|
|
|
mStorageManager = updatedStorageManager;
|
|
|
mAccount = AccountUtils.getCurrentOwnCloudAccount(mContext);
|
|
|
}
|
|
|
+ Cursor newCursor = null;
|
|
|
if (mStorageManager != null) {
|
|
|
- mFiles = mStorageManager.getFolderContent(mFile);
|
|
|
- mCursor = mStorageManager.getContent(mFile.getParentId());
|
|
|
- } else {
|
|
|
- mFiles = null;
|
|
|
- mCursor = null;
|
|
|
+ //mFiles = mStorageManager.getFolderContent(mFile);
|
|
|
+ newCursor = mStorageManager.getContent(folder.getFileId());
|
|
|
+ }
|
|
|
+ Cursor oldCursor = swapCursor(newCursor);
|
|
|
+ if (oldCursor != null){
|
|
|
+ oldCursor.close();
|
|
|
}
|
|
|
notifyDataSetChanged();
|
|
|
}
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void bindView(View view, Context context, Cursor cursor) {
|
|
|
+ Log_OC.d(TAG, "bindView start");
|
|
|
+
|
|
|
+ OCFile file = mStorageManager.createFileInstance(cursor);
|
|
|
+
|
|
|
+ TextView fileName = (TextView) view.findViewById(R.id.Filename);
|
|
|
+ String name = file.getFileName();
|
|
|
+
|
|
|
+ fileName.setText(name);
|
|
|
+ ImageView fileIcon = (ImageView) view.findViewById(R.id.imageView1);
|
|
|
+ fileIcon.setImageResource(DisplayUtils.getResourceId(file.getMimetype()));
|
|
|
+ ImageView localStateView = (ImageView) view.findViewById(R.id.imageView2);
|
|
|
+ FileDownloaderBinder downloaderBinder = mTransferServiceGetter.getFileDownloaderBinder();
|
|
|
+ FileUploaderBinder uploaderBinder = mTransferServiceGetter.getFileUploaderBinder();
|
|
|
+ if (downloaderBinder != null && downloaderBinder.isDownloading(mAccount, file)) {
|
|
|
+ localStateView.setImageResource(R.drawable.downloading_file_indicator);
|
|
|
+ localStateView.setVisibility(View.VISIBLE);
|
|
|
+ } else if (uploaderBinder != null && uploaderBinder.isUploading(mAccount, file)) {
|
|
|
+ localStateView.setImageResource(R.drawable.uploading_file_indicator);
|
|
|
+ localStateView.setVisibility(View.VISIBLE);
|
|
|
+ } else if (file.isDown()) {
|
|
|
+ localStateView.setImageResource(R.drawable.local_file_indicator);
|
|
|
+ localStateView.setVisibility(View.VISIBLE);
|
|
|
+ } else {
|
|
|
+ localStateView.setVisibility(View.INVISIBLE);
|
|
|
+ }
|
|
|
+
|
|
|
+ TextView fileSizeV = (TextView) view.findViewById(R.id.file_size);
|
|
|
+ TextView lastModV = (TextView) view.findViewById(R.id.last_mod);
|
|
|
+ ImageView checkBoxV = (ImageView) view.findViewById(R.id.custom_checkbox);
|
|
|
+
|
|
|
+ if (!file.isFolder()) {
|
|
|
+ fileSizeV.setVisibility(View.VISIBLE);
|
|
|
+ fileSizeV.setText(DisplayUtils.bytesToHumanReadable(file.getFileLength()));
|
|
|
+ lastModV.setVisibility(View.VISIBLE);
|
|
|
+ lastModV.setText(DisplayUtils.unixTimeToHumanReadable(file.getModificationTimestamp()));
|
|
|
+ // this if-else is needed even thoe fav icon is visible by default
|
|
|
+ // because android reuses views in listview
|
|
|
+ if (!file.keepInSync()) {
|
|
|
+ view.findViewById(R.id.imageView3).setVisibility(View.GONE);
|
|
|
+ } else {
|
|
|
+ view.findViewById(R.id.imageView3).setVisibility(View.VISIBLE);
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+ else {
|
|
|
+
|
|
|
+ fileSizeV.setVisibility(View.INVISIBLE);
|
|
|
+ //fileSizeV.setText(DisplayUtils.bytesToHumanReadable(file.getFileLength()));
|
|
|
+ lastModV.setVisibility(View.VISIBLE);
|
|
|
+ lastModV.setText(DisplayUtils.unixTimeToHumanReadable(file.getModificationTimestamp()));
|
|
|
+ checkBoxV.setVisibility(View.GONE);
|
|
|
+ view.findViewById(R.id.imageView3).setVisibility(View.GONE);
|
|
|
+ }
|
|
|
+
|
|
|
+ ImageView shareIconV = (ImageView) view.findViewById(R.id.shareIcon);
|
|
|
+ if (file.isShareByLink()) {
|
|
|
+ shareIconV.setVisibility(View.VISIBLE);
|
|
|
+ } else {
|
|
|
+ shareIconV.setVisibility(View.INVISIBLE);
|
|
|
+ }
|
|
|
+ //}
|
|
|
+ Log_OC.d(TAG, "bindView end");
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public View newView(Context context, Cursor cursor, ViewGroup parent) {
|
|
|
+ Log_OC.d(TAG, "newView start");
|
|
|
+ LayoutInflater inflator = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
|
|
|
+ View view = inflator.inflate(R.layout.list_item, null);
|
|
|
+
|
|
|
+ // TODO check activity to upload
|
|
|
+ ListView parentList = (ListView) parent;
|
|
|
+ ImageView checkBoxV = (ImageView) view.findViewById(R.id.custom_checkbox);
|
|
|
+ if (parentList.getChoiceMode() == ListView.CHOICE_MODE_NONE) {
|
|
|
+ checkBoxV.setVisibility(View.GONE);
|
|
|
+ } else {
|
|
|
+ /*if (parentList.isItemChecked(position)) {
|
|
|
+ checkBoxV.setImageResource(android.R.drawable.checkbox_on_background);
|
|
|
+ } else {
|
|
|
+ checkBoxV.setImageResource(android.R.drawable.checkbox_off_background);
|
|
|
+ }*/
|
|
|
+ checkBoxV.setVisibility(View.VISIBLE);
|
|
|
+ }
|
|
|
+ Log_OC.d(TAG, "newView end");
|
|
|
+ return view;
|
|
|
+
|
|
|
+ }
|
|
|
|
|
|
}
|