|
@@ -1,210 +1,260 @@
|
|
|
-/* ownCloud Android client application
|
|
|
- * Copyright (C) 2011 Bartek Przybylski
|
|
|
- * Copyright (C) 2012-2013 ownCloud Inc.
|
|
|
- *
|
|
|
- * This program is free software: you can redistribute it and/or modify
|
|
|
- * it under the terms of the GNU General Public License version 2,
|
|
|
- * as published by the Free Software Foundation.
|
|
|
- *
|
|
|
- * This program is distributed in the hope that it will be useful,
|
|
|
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
- * GNU General Public License for more details.
|
|
|
- *
|
|
|
- * You should have received a copy of the GNU General Public License
|
|
|
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
- *
|
|
|
- */
|
|
|
-package com.owncloud.android.ui.adapter;
|
|
|
-
|
|
|
-import java.util.Vector;
|
|
|
-
|
|
|
-import com.owncloud.android.AccountUtils;
|
|
|
-import com.owncloud.android.DisplayUtils;
|
|
|
-import com.owncloud.android.datamodel.DataStorageManager;
|
|
|
-import com.owncloud.android.datamodel.OCFile;
|
|
|
-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.R;
|
|
|
-
|
|
|
-import android.accounts.Account;
|
|
|
-import android.content.Context;
|
|
|
-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;
|
|
|
-
|
|
|
-/**
|
|
|
- * This Adapter populates a ListView with all files and folders in an ownCloud
|
|
|
- * instance.
|
|
|
- *
|
|
|
- * @author Bartek Przybylski
|
|
|
- *
|
|
|
- */
|
|
|
-public class FileListListAdapter extends BaseAdapter implements ListAdapter {
|
|
|
- private Context mContext;
|
|
|
- private OCFile mFile = null;
|
|
|
- private Vector<OCFile> mFiles = null;
|
|
|
- private DataStorageManager mStorageManager;
|
|
|
- private Account mAccount;
|
|
|
- private TransferServiceGetter mTransferServiceGetter;
|
|
|
-
|
|
|
- public FileListListAdapter(OCFile file, DataStorageManager storage_man,
|
|
|
- Context context, TransferServiceGetter transferServiceGetter) {
|
|
|
- mStorageManager = storage_man;
|
|
|
- mContext = context;
|
|
|
- mAccount = AccountUtils.getCurrentOwnCloudAccount(mContext);
|
|
|
- mTransferServiceGetter = transferServiceGetter;
|
|
|
- swapDirectory(file, mStorageManager);
|
|
|
- /*mFile = file;
|
|
|
- mFiles = mStorageManager.getDirectoryContent(mFile);*/
|
|
|
- }
|
|
|
-
|
|
|
- @Override
|
|
|
- public boolean areAllItemsEnabled() {
|
|
|
- return true;
|
|
|
- }
|
|
|
-
|
|
|
- @Override
|
|
|
- public boolean isEnabled(int position) {
|
|
|
- return true;
|
|
|
- }
|
|
|
-
|
|
|
- @Override
|
|
|
- public int getCount() {
|
|
|
- return mFiles != null ? mFiles.size() : 0;
|
|
|
- }
|
|
|
-
|
|
|
- @Override
|
|
|
- public Object getItem(int position) {
|
|
|
- if (mFiles == null || mFiles.size() <= position)
|
|
|
- return null;
|
|
|
- return mFiles.get(position);
|
|
|
- }
|
|
|
-
|
|
|
- @Override
|
|
|
- public long getItemId(int position) {
|
|
|
- if (mFiles == null || mFiles.size() <= position)
|
|
|
- return 0;
|
|
|
- return mFiles.get(position).getFileId();
|
|
|
- }
|
|
|
-
|
|
|
- @Override
|
|
|
- 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.isDirectory()) {
|
|
|
- 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.GONE);
|
|
|
- lastModV.setVisibility(View.GONE);
|
|
|
- checkBoxV.setVisibility(View.GONE);
|
|
|
- view.findViewById(R.id.imageView3).setVisibility(View.GONE);
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- return view;
|
|
|
- }
|
|
|
-
|
|
|
- @Override
|
|
|
- public int getViewTypeCount() {
|
|
|
- return 1;
|
|
|
- }
|
|
|
-
|
|
|
- @Override
|
|
|
- public boolean hasStableIds() {
|
|
|
- return true;
|
|
|
- }
|
|
|
-
|
|
|
- @Override
|
|
|
- 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 updatedStorageManager Optional updated storage manager; used to replace mStorageManager if is different (and not NULL)
|
|
|
- */
|
|
|
- public void swapDirectory(OCFile directory, DataStorageManager updatedStorageManager) {
|
|
|
- mFile = directory;
|
|
|
- if (updatedStorageManager != null && updatedStorageManager != mStorageManager) {
|
|
|
- mStorageManager = updatedStorageManager;
|
|
|
- mAccount = AccountUtils.getCurrentOwnCloudAccount(mContext);
|
|
|
- }
|
|
|
- if (mStorageManager != null) {
|
|
|
- mFiles = mStorageManager.getDirectoryContent(mFile);
|
|
|
- } else {
|
|
|
- mFiles = null;
|
|
|
- }
|
|
|
- notifyDataSetChanged();
|
|
|
- }
|
|
|
-
|
|
|
-}
|
|
|
+
|
|
|
+/* ownCloud Android client application
|
|
|
+ * Copyright (C) 2011 Bartek Przybylski
|
|
|
+ * Copyright (C) 2012-2013 ownCloud Inc.
|
|
|
+ *
|
|
|
+ * This program is free software: you can redistribute it and/or modify
|
|
|
+ * it under the terms of the GNU General Public License as published by
|
|
|
+ * the Free Software Foundation, either version 2 of the License, or
|
|
|
+ * (at your option) any later version.
|
|
|
+ *
|
|
|
+ * This program is distributed in the hope that it will be useful,
|
|
|
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
+ * GNU General Public License for more details.
|
|
|
+ *
|
|
|
+ * You should have received a copy of the GNU General Public License
|
|
|
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
+ *
|
|
|
+ */
|
|
|
+package com.owncloud.android.ui.adapter;
|
|
|
+
|
|
|
+import java.util.Vector;
|
|
|
+
|
|
|
+import android.accounts.Account;
|
|
|
+import android.content.Context;
|
|
|
+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 com.owncloud.android.AccountUtils;
|
|
|
+import com.owncloud.android.DisplayUtils;
|
|
|
+import com.owncloud.android.R;
|
|
|
+import com.owncloud.android.datamodel.DataStorageManager;
|
|
|
+import com.owncloud.android.datamodel.OCFile;
|
|
|
+import com.owncloud.android.files.services.FileDownloader.FileDownloaderBinder;
|
|
|
+import com.owncloud.android.files.services.FileUploader.FileUploaderBinder;
|
|
|
+import com.owncloud.android.ui.activity.TransferServiceGetter;
|
|
|
+
|
|
|
+/**
|
|
|
+ * This Adapter populates a ListView with all files and folders in an ownCloud
|
|
|
+ * instance.
|
|
|
+ *
|
|
|
+ * @author Bartek Przybylski
|
|
|
+ *
|
|
|
+ */
|
|
|
+public class FileListListAdapter extends BaseAdapter implements ListAdapter {
|
|
|
+ private Context mContext;
|
|
|
+ private OCFile mFile = null;
|
|
|
+ private Vector<OCFile> mFiles = null;
|
|
|
+ private DataStorageManager mStorageManager;
|
|
|
+ private Account mAccount;
|
|
|
+ private TransferServiceGetter mTransferServiceGetter;
|
|
|
+ //total size of a directory (recursive)
|
|
|
+ private Long totalSizeOfDirectoriesRecursive = null;
|
|
|
+ private Long lastModifiedOfAllSubdirectories = null;
|
|
|
+
|
|
|
+ public FileListListAdapter(OCFile file, DataStorageManager storage_man,
|
|
|
+ Context context, TransferServiceGetter transferServiceGetter) {
|
|
|
+ mStorageManager = storage_man;
|
|
|
+ mContext = context;
|
|
|
+ mAccount = AccountUtils.getCurrentOwnCloudAccount(mContext);
|
|
|
+ mTransferServiceGetter = transferServiceGetter;
|
|
|
+ swapDirectory(file, mStorageManager);
|
|
|
+ /*mFile = file;
|
|
|
+ mFiles = mStorageManager.getDirectoryContent(mFile);*/
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public boolean areAllItemsEnabled() {
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public boolean isEnabled(int position) {
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public int getCount() {
|
|
|
+ return mFiles != null ? mFiles.size() : 0;
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public Object getItem(int position) {
|
|
|
+ if (mFiles == null || mFiles.size() <= position)
|
|
|
+ return null;
|
|
|
+ return mFiles.get(position);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public long getItemId(int position) {
|
|
|
+ if (mFiles == null || mFiles.size() <= position)
|
|
|
+ return 0;
|
|
|
+ return mFiles.get(position).getFileId();
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ 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.isDirectory()) {
|
|
|
+ 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 {
|
|
|
+
|
|
|
+ getDirectorySizeNumber(file,true);
|
|
|
+ if (lastModifiedOfAllSubdirectories == null)
|
|
|
+ {
|
|
|
+ lastModV.setVisibility(View.GONE);
|
|
|
+ fileSizeV.setVisibility(View.GONE);
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ lastModV.setVisibility(View.VISIBLE);
|
|
|
+ lastModV.setText(DisplayUtils.unixTimeToHumanReadable(lastModifiedOfAllSubdirectories));
|
|
|
+ fileSizeV.setVisibility(View.VISIBLE);
|
|
|
+ fileSizeV.setText(DisplayUtils.bytesToHumanReadable((totalSizeOfDirectoriesRecursive == null) ? 0 : totalSizeOfDirectoriesRecursive));
|
|
|
+ }
|
|
|
+ checkBoxV.setVisibility(View.GONE);
|
|
|
+ view.findViewById(R.id.imageView3).setVisibility(View.GONE);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ return view;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ /**
|
|
|
+ * - This method counts recursively all subdirectories and their files from the root directory.
|
|
|
+ * - It also shows a timestamp of the last modificated file inside the root directory
|
|
|
+ *
|
|
|
+ * @param OCFile : startDirectory
|
|
|
+ * @param boolean : counting starts from here ?
|
|
|
+ */
|
|
|
+ private void getDirectorySizeNumber(OCFile directory,boolean startOfRecursive) {
|
|
|
+ if (startOfRecursive) {
|
|
|
+ totalSizeOfDirectoriesRecursive = null;
|
|
|
+ }
|
|
|
+ Vector<OCFile> files = mStorageManager.getDirectoryContent(directory);
|
|
|
+ for (OCFile file : files) {
|
|
|
+ if(!file.isDirectory()) {
|
|
|
+ if (totalSizeOfDirectoriesRecursive == null) {
|
|
|
+ totalSizeOfDirectoriesRecursive = file.getFileLength();
|
|
|
+ lastModifiedOfAllSubdirectories = file.getModificationTimestamp();
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+
|
|
|
+ totalSizeOfDirectoriesRecursive += file.getFileLength();
|
|
|
+ if (lastModifiedOfAllSubdirectories < file.getModificationTimestamp()) {
|
|
|
+ lastModifiedOfAllSubdirectories = file.getModificationTimestamp();
|
|
|
+ }
|
|
|
+ }
|
|
|
+ else {
|
|
|
+ this.getDirectorySizeNumber(file, false);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public int getViewTypeCount() {
|
|
|
+ return 1;
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public boolean hasStableIds() {
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ 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 updatedStorageManager Optional updated storage manager; used to replace mStorageManager if is different (and not NULL)
|
|
|
+ */
|
|
|
+ public void swapDirectory(OCFile directory, DataStorageManager updatedStorageManager) {
|
|
|
+ mFile = directory;
|
|
|
+ if (updatedStorageManager != null && updatedStorageManager != mStorageManager) {
|
|
|
+ mStorageManager = updatedStorageManager;
|
|
|
+ mAccount = AccountUtils.getCurrentOwnCloudAccount(mContext);
|
|
|
+ }
|
|
|
+ if (mStorageManager != null) {
|
|
|
+ mFiles = mStorageManager.getDirectoryContent(mFile);
|
|
|
+ } else {
|
|
|
+ mFiles = null;
|
|
|
+ }
|
|
|
+ notifyDataSetChanged();
|
|
|
+ }
|
|
|
+
|
|
|
+}
|