From: David A. Velasco Date: Mon, 2 Feb 2015 12:48:30 +0000 (+0100) Subject: Merge branch 'develop' into imageGrid X-Git-Tag: oc-android-1.7.0_signed~16^2~1 X-Git-Url: http://git.linex4red.de/pub/Android/ownCloud.git/commitdiff_plain/4af15f7b4ed255f8ccc378e9cf2e47280868129d?ds=inline;hp=-c Merge branch 'develop' into imageGrid --- 4af15f7b4ed255f8ccc378e9cf2e47280868129d diff --combined src/com/owncloud/android/ui/adapter/FileListListAdapter.java index 1e6670dc,df05ba4d..d809f141 --- a/src/com/owncloud/android/ui/adapter/FileListListAdapter.java +++ b/src/com/owncloud/android/ui/adapter/FileListListAdapter.java @@@ -1,6 -1,6 +1,6 @@@ /* ownCloud Android client application * Copyright (C) 2011 Bartek Przybylski -- * Copyright (C) 2012-2014 ownCloud Inc. ++ * Copyright (C) 2012-2015 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, @@@ -19,28 -19,21 +19,21 @@@ package com.owncloud.android.ui.adapter import java.io.File; - import java.util.Collections; - import java.util.Comparator; import java.util.Vector; - import third_parties.daveKoeller.AlphanumComparator; import android.accounts.Account; import android.content.Context; import android.content.SharedPreferences; import android.graphics.Bitmap; - import android.graphics.BitmapFactory; - import android.media.ThumbnailUtils; import android.preference.PreferenceManager; import android.text.format.DateUtils; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; import android.widget.BaseAdapter; - import android.widget.Filter; - import android.widget.Filterable; +import android.widget.GridView; import android.widget.ImageView; import android.widget.ListAdapter; -import android.widget.ListView; import android.widget.TextView; import com.owncloud.android.R; @@@ -50,6 -43,7 +43,7 @@@ import com.owncloud.android.datamodel.O import com.owncloud.android.datamodel.ThumbnailsCacheManager; import com.owncloud.android.files.services.FileDownloader.FileDownloaderBinder; import com.owncloud.android.files.services.FileUploader.FileUploaderBinder; + import com.owncloud.android.services.OperationsService.OperationsServiceBinder; import com.owncloud.android.ui.activity.ComponentsGetter; import com.owncloud.android.utils.DisplayUtils; import com.owncloud.android.utils.FileStorageUtils; @@@ -65,35 -59,30 +59,32 @@@ */ public class FileListListAdapter extends BaseAdapter implements ListAdapter { private final static String PERMISSION_SHARED_WITH_ME = "S"; - + private Context mContext; private OCFile mFile = null; private Vector mFiles = null; + private Vector mFilesOrig = new Vector(); private boolean mJustFolders; private FileDataStorageManager mStorageManager; private Account mAccount; private ComponentsGetter mTransferServiceGetter; + + private enum ViewType {LIST_ITEM, GRID_IMAGE, GRID_ITEM }; - private Integer mSortOrder; - public static final Integer SORT_NAME = 0; - public static final Integer SORT_DATE = 1; - public static final Integer SORT_SIZE = 2; - private Boolean mSortAscending; ++ private SharedPreferences mAppPreferences; public FileListListAdapter( boolean justFolders, - Context context, + Context context, ComponentsGetter transferServiceGetter ) { - + mJustFolders = justFolders; mContext = context; mAccount = AccountUtils.getCurrentOwnCloudAccount(mContext); - mTransferServiceGetter = transferServiceGetter; - + mAppPreferences = PreferenceManager .getDefaultSharedPreferences(mContext); @@@ -104,6 -93,7 +95,6 @@@ // initialise thumbnails cache on background thread new ThumbnailsCacheManager.InitDiskCacheTask().execute(); - } @Override @@@ -142,154 -132,90 +133,158 @@@ @Override public View getView(int position, View convertView, ViewGroup parent) { + + boolean fileView = DisplayUtils.decideViewLayout(mFiles); + View view = convertView; - if (view == null) { - LayoutInflater inflator = (LayoutInflater) mContext - .getSystemService(Context.LAYOUT_INFLATER_SERVICE); - view = inflator.inflate(R.layout.list_item, null); - } - + OCFile file = null; + LayoutInflater inflator = (LayoutInflater) mContext + .getSystemService(Context.LAYOUT_INFLATER_SERVICE); + if (mFiles != null && mFiles.size() > position) { - OCFile file = mFiles.get(position); - TextView fileName = (TextView) view.findViewById(R.id.Filename); - String name = file.getFileName(); + file = mFiles.get(position); + } + + // Find out which layout should be displayed + ViewType viewType; + if (!fileView){ + viewType = ViewType.LIST_ITEM; + } else if (file.isImage()){ + viewType = ViewType.GRID_IMAGE; + } else { + viewType = ViewType.GRID_ITEM; + } + + // Create View + switch (viewType){ + case GRID_IMAGE: + view = inflator.inflate(R.layout.grid_image, null); + break; + case GRID_ITEM: + view = inflator.inflate(R.layout.grid_item, null); + break; + case LIST_ITEM: + view = inflator.inflate(R.layout.list_item, null); + break; + } - fileName.setText(name); - ImageView fileIcon = (ImageView) view.findViewById(R.id.imageView1); + view.invalidate(); + + if (file != null){ + + ImageView fileIcon = (ImageView) view.findViewById(R.id.thumbnail); + fileIcon.setTag(file.getFileId()); - ImageView sharedIconV = (ImageView) view.findViewById(R.id.sharedIcon); - ImageView sharedWithMeIconV = (ImageView) view.findViewById(R.id.sharedWithMeIcon); - sharedWithMeIconV.setVisibility(View.GONE); - - ImageView localStateView = (ImageView) view.findViewById(R.id.imageView2); - localStateView.bringToFront(); - FileDownloaderBinder downloaderBinder = mTransferServiceGetter.getFileDownloaderBinder(); - FileUploaderBinder uploaderBinder = mTransferServiceGetter.getFileUploaderBinder(); - boolean downloading = (downloaderBinder != null && downloaderBinder.isDownloading(mAccount, file)); - OperationsServiceBinder opsBinder = mTransferServiceGetter.getOperationsServiceBinder(); - downloading |= (opsBinder != null && opsBinder.isSynchronizing(mAccount, file.getRemotePath())); - if (downloading) { - 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 fileName; + String name; + + switch (viewType){ + case LIST_ITEM: + 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); + + lastModV.setVisibility(View.VISIBLE); + lastModV.setText(showRelativeTimestamp(file)); + + checkBoxV.setVisibility(View.GONE); + + fileSizeV.setVisibility(View.VISIBLE); + fileSizeV.setText(DisplayUtils.bytesToHumanReadable(file.getFileLength())); + + if (!file.isFolder()) { + GridView parentList = (GridView)parent; + if (parentList.getChoiceMode() == GridView.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 { //Folder + fileSizeV.setVisibility(View.INVISIBLE); + } + + case GRID_ITEM: + // filename + fileName = (TextView) view.findViewById(R.id.Filename); + name = file.getFileName(); + fileName.setText(name); + + case GRID_IMAGE: + // sharedIcon + ImageView sharedIconV = (ImageView) view.findViewById(R.id.sharedIcon); + if (file.isShareByLink()) { + sharedIconV.setVisibility(View.VISIBLE); + sharedIconV.bringToFront(); + } else { + sharedIconV.setVisibility(View.GONE); + } + + // local state + ImageView localStateView = (ImageView) view.findViewById(R.id.localFileIndicator); + localStateView.bringToFront(); + FileDownloaderBinder downloaderBinder = mTransferServiceGetter.getFileDownloaderBinder(); + FileUploaderBinder uploaderBinder = mTransferServiceGetter.getFileUploaderBinder(); - if (downloaderBinder != null && downloaderBinder.isDownloading(mAccount, file)) { ++ boolean downloading = (downloaderBinder != null && downloaderBinder.isDownloading(mAccount, file)); ++ OperationsServiceBinder opsBinder = mTransferServiceGetter.getOperationsServiceBinder(); ++ downloading |= (opsBinder != null && opsBinder.isSynchronizing(mAccount, file.getRemotePath())); ++ if (downloading) { + 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); + } + + // share with me icon + if (!file.isFolder()) { + ImageView sharedWithMeIconV = (ImageView) view.findViewById(R.id.sharedWithMeIcon); + sharedWithMeIconV.bringToFront(); + if (checkIfFileIsSharedWithMe(file)) { + sharedWithMeIconV.setVisibility(View.VISIBLE); + } else { + sharedWithMeIconV.setVisibility(View.GONE); + } + } + + break; } - 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); + // For all Views + // this if-else is needed even though favorite icon is visible by default + // because android reuses views in listview + if (!file.keepInSync()) { + view.findViewById(R.id.favoriteIcon).setVisibility(View.GONE); + } else { + view.findViewById(R.id.favoriteIcon).setVisibility(View.VISIBLE); + } + + // No Folder if (!file.isFolder()) { - fileSizeV.setVisibility(View.VISIBLE); - fileSizeV.setText(DisplayUtils.bytesToHumanReadable(file.getFileLength())); - lastModV.setVisibility(View.VISIBLE); - lastModV.setText(showRelativeTimestamp(file)); - // 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); - } - - // get Thumbnail if file is image if (file.isImage() && file.getRemoteId() != null){ - // Thumbnail in Cache? + // Thumbnail in Cache? Bitmap thumbnail = ThumbnailsCacheManager.getBitmapFromDiskCache( String.valueOf(file.getRemoteId()) - ); + ); if (thumbnail != null && !file.needsUpdateThumbnail()){ fileIcon.setImageBitmap(thumbnail); } else { - // generate new Thumbnail if (ThumbnailsCacheManager.cancelPotentialWork(file, fileIcon)) { final ThumbnailsCacheManager.ThumbnailGenerationTask task = new ThumbnailsCacheManager.ThumbnailGenerationTask( fileIcon, mStorageManager, mAccount - ); + ); if (thumbnail == null) { thumbnail = ThumbnailsCacheManager.mDefaultImg; } @@@ -298,7 -224,7 +293,7 @@@ mContext.getResources(), thumbnail, task - ); + ); fileIcon.setImageDrawable(asyncDrawable); task.execute(file); } @@@ -306,19 -232,45 +301,19 @@@ } else { fileIcon.setImageResource(DisplayUtils.getFileTypeIconId(file.getMimetype(), file.getFileName())); } - - if (checkIfFileIsSharedWithMe(file)) { - sharedWithMeIconV.setVisibility(View.VISIBLE); - } - } - else { - // TODO Re-enable when server supports folder-size calculation -// if (FileStorageUtils.getDefaultSavePathFor(mAccount.name, file) != null){ -// fileSizeV.setVisibility(View.VISIBLE); -// fileSizeV.setText(getFolderSizeHuman(FileStorageUtils.getDefaultSavePathFor(mAccount.name, file))); -// } else { - fileSizeV.setVisibility(View.INVISIBLE); -// } - - lastModV.setVisibility(View.VISIBLE); - lastModV.setText(showRelativeTimestamp(file)); - checkBoxV.setVisibility(View.GONE); - view.findViewById(R.id.imageView3).setVisibility(View.GONE); - + } else { + // Folder if (checkIfFileIsSharedWithMe(file)) { fileIcon.setImageResource(R.drawable.shared_with_me_folder); - sharedWithMeIconV.setVisibility(View.VISIBLE); + } else if (file.isShareByLink()) { + // If folder is sharedByLink, icon folder must be changed to + // folder-public one + fileIcon.setImageResource(R.drawable.folder_public); } else { fileIcon.setImageResource( DisplayUtils.getFileTypeIconId(file.getMimetype(), file.getFileName()) ); } - - // If folder is sharedByLink, icon folder must be changed to - // folder-public one - if (file.isShareByLink()) { - fileIcon.setImageResource(R.drawable.folder_public); - } - } - - if (file.isShareByLink()) { - sharedIconV.setVisibility(View.VISIBLE); - } else { - sharedIconV.setVisibility(View.GONE); } } @@@ -395,9 -347,6 +390,9 @@@ } if (mStorageManager != null) { mFiles = mStorageManager.getFolderContent(mFile); + mFilesOrig.clear(); + mFilesOrig.addAll(mFiles); + if (mJustFolders) { mFiles = getFolders(mFiles); } @@@ -442,96 -391,6 +437,6 @@@ && file.getPermissions().contains(PERMISSION_SHARED_WITH_ME)); } - /** - * Sorts list by Date - * @param sortAscending true: ascending, false: descending - */ - private void sortByDate(boolean sortAscending){ - final Integer val; - if (sortAscending){ - val = 1; - } else { - val = -1; - } - - Collections.sort(mFiles, new Comparator() { - public int compare(OCFile o1, OCFile o2) { - if (o1.isFolder() && o2.isFolder()) { - Long obj1 = o1.getModificationTimestamp(); - return val * obj1.compareTo(o2.getModificationTimestamp()); - } - else if (o1.isFolder()) { - return -1; - } else if (o2.isFolder()) { - return 1; - } else if (o1.getModificationTimestamp() == 0 || o2.getModificationTimestamp() == 0){ - return 0; - } else { - Long obj1 = o1.getModificationTimestamp(); - return val * obj1.compareTo(o2.getModificationTimestamp()); - } - } - }); - } - - /** - * Sorts list by Size - * @param sortAscending true: ascending, false: descending - */ - private void sortBySize(boolean sortAscending){ - final Integer val; - if (sortAscending){ - val = 1; - } else { - val = -1; - } - - Collections.sort(mFiles, new Comparator() { - public int compare(OCFile o1, OCFile o2) { - if (o1.isFolder() && o2.isFolder()) { - Long obj1 = getFolderSize(new File(FileStorageUtils.getDefaultSavePathFor(mAccount.name, o1))); - return val * obj1.compareTo(getFolderSize(new File(FileStorageUtils.getDefaultSavePathFor(mAccount.name, o2)))); - } - else if (o1.isFolder()) { - return -1; - } else if (o2.isFolder()) { - return 1; - } else if (o1.getFileLength() == 0 || o2.getFileLength() == 0){ - return 0; - } else { - Long obj1 = o1.getFileLength(); - return val * obj1.compareTo(o2.getFileLength()); - } - } - }); - } - - /** - * Sorts list by Name - * @param sortAscending true: ascending, false: descending - */ - private void sortByName(boolean sortAscending){ - final Integer val; - if (sortAscending){ - val = 1; - } else { - val = -1; - } - - Collections.sort(mFiles, new Comparator() { - public int compare(OCFile o1, OCFile o2) { - if (o1.isFolder() && o2.isFolder()) { - return val * o1.getRemotePath().toLowerCase().compareTo(o2.getRemotePath().toLowerCase()); - } else if (o1.isFolder()) { - return -1; - } else if (o2.isFolder()) { - return 1; - } - return val * new AlphanumComparator().compare(o1, o2); - } - }); - } - public void setSortOrder(Integer order, boolean ascending) { SharedPreferences.Editor editor = mAppPreferences.edit(); editor.putInt("sortOrder", order); @@@ -545,7 -404,7 +450,7 @@@ mFiles = FileStorageUtils.sortFolder(mFiles); notifyDataSetChanged(); - } + } private CharSequence showRelativeTimestamp(OCFile file){ return DisplayUtils.getRelativeDateTimeString(mContext, file.getModificationTimestamp(), diff --combined src/com/owncloud/android/ui/fragment/OCFileListFragment.java index fa144b8a,b70262ff..5386ac8c --- a/src/com/owncloud/android/ui/fragment/OCFileListFragment.java +++ b/src/com/owncloud/android/ui/fragment/OCFileListFragment.java @@@ -29,7 -29,6 +29,7 @@@ import android.view.ContextMenu import android.view.MenuInflater; import android.view.MenuItem; import android.view.View; +import android.view.ViewGroup; import android.widget.AdapterView; import android.widget.AdapterView.AdapterContextMenuInfo; import android.widget.TextView; @@@ -49,7 -48,6 +49,7 @@@ import com.owncloud.android.ui.dialog.R import com.owncloud.android.ui.dialog.RenameFileDialogFragment; import com.owncloud.android.ui.preview.PreviewImageFragment; import com.owncloud.android.ui.preview.PreviewMediaFragment; +import com.owncloud.android.utils.DisplayUtils; import com.owncloud.android.utils.FileStorageUtils; /** @@@ -133,15 -131,15 +133,15 @@@ public class OCFileListFragment extend boolean justFolders = (args == null) ? false : args.getBoolean(ARG_JUST_FOLDERS, false); mAdapter = new FileListListAdapter( justFolders, - getSherlockActivity(), + getSherlockActivity(), mContainerActivity ); setListAdapter(mAdapter); - - registerForContextMenu(getListView()); - getListView().setOnCreateContextMenuListener(this); - } - + + registerForContextMenu(getGridView()); + getGridView().setOnCreateContextMenuListener(this); + } + /** * Saves the current listed folder. */ @@@ -391,19 -389,15 +391,19 @@@ mAdapter.swapDirectory(directory, storageManager); if (mFile == null || !mFile.equals(directory)) { - mList.setSelectionFromTop(0, 0); + imageView.setSelection(0); } mFile = directory; - + + Vector files = storageManager.getFolderContent(directory); // Update Footer TextView footerText = (TextView) mFooterView.findViewById(R.id.footerText); - Log_OC.d("footer", String.valueOf(System.currentTimeMillis())); footerText.setText(generateFooterText(directory)); - Log_OC.d("footer", String.valueOf(System.currentTimeMillis())); + if (DisplayUtils.decideViewLayout(files)){ + switchImageView(); + } else { + switchFileView(); + } } } @@@ -439,17 -433,6 +439,17 @@@ } else if (folders > 1) { output = output + folders.toString() + " " + getResources().getString(R.string.file_list_folders); } + + // Fix for showing or not to show the footerView + if (folders == 0 && files == 0) { // If no files or folders, remove footerView for allowing + // to show the emptyList message + removeFooterView(mFooterView); + } else { // set a new footerView if there is not one for showing the number or files/folders + if (getFooterViewCount()== 0) { + ((ViewGroup)mFooterView.getParent()).removeView(mFooterView); + setFooterView(mFooterView); + } + } return output; }