From: zerginator Date: Fri, 12 Apr 2013 11:31:27 +0000 (+0200) Subject: Issue #28 folders don't show date and size info X-Git-Tag: oc-android-1.4.3~19^2~3 X-Git-Url: http://git.linex4red.de/pub/Android/ownCloud.git/commitdiff_plain/5b9bf1ad3fd03c6e8437f6d4b0f9fbdba94fdec6?hp=-c Issue #28 folders don't show date and size info --- 5b9bf1ad3fd03c6e8437f6d4b0f9fbdba94fdec6 diff --git a/src/com/owncloud/android/operations/SynchronizeFileOperation.java b/src/com/owncloud/android/operations/SynchronizeFileOperation.java index 606017aa..4ed56d75 100644 --- a/src/com/owncloud/android/operations/SynchronizeFileOperation.java +++ b/src/com/owncloud/android/operations/SynchronizeFileOperation.java @@ -162,7 +162,7 @@ public class SynchronizeFileOperation extends RemoteOperation { } catch (Exception e) { result = new RemoteOperationResult(e); - Log.e(TAG, "Synchronizing " + mAccount.name + ", file " + mLocalFile.getRemotePath() + ": " + result.getLogMessage(), result.getException()); + Log.e(TAG, "Synchronizing " + mAccount.name + ", file " + (mLocalFile != null ? mLocalFile.getRemotePath() : "NULL") + ": " + result.getLogMessage(), result.getException()); } finally { if (propfind != null) diff --git a/src/com/owncloud/android/ui/adapter/FileListListAdapter.java b/src/com/owncloud/android/ui/adapter/FileListListAdapter.java index 8d879935..59b25cc1 100644 --- a/src/com/owncloud/android/ui/adapter/FileListListAdapter.java +++ b/src/com/owncloud/android/ui/adapter/FileListListAdapter.java @@ -1,211 +1,251 @@ -/* 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 . - * - */ -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 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 . + * + */ +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 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 { + fileSizeV.setVisibility(View.VISIBLE); + getDirectorySizeNumber(file,true); + fileSizeV.setText(DisplayUtils.bytesToHumanReadable((totalSizeOfDirectoriesRecursive == null) ? 0 : totalSizeOfDirectoriesRecursive)); + lastModV.setVisibility(View.VISIBLE); + lastModV.setText(DisplayUtils.unixTimeToHumanReadable((lastModifiedOfAllSubdirectories == null) ? 0 :lastModifiedOfAllSubdirectories)); + 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 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(); + } + +}