From: tobiasKaminsky Date: Sun, 18 Jan 2015 16:00:29 +0000 (+0100) Subject: Merge branch 'develop2' into imageGrid2 X-Git-Tag: oc-android-1.7.0_signed~16^2~21 X-Git-Url: http://git.linex4red.de/pub/Android/ownCloud.git/commitdiff_plain/6d5c6f86e5fa9a2edb51562d028554cbc49cdf93?ds=inline Merge branch 'develop2' into imageGrid2 Conflicts: owncloud-android-library res/layout/list_fragment.xml res/values-fr/strings.xml src/com/owncloud/android/datamodel/ThumbnailsCacheManager.java src/com/owncloud/android/ui/adapter/FileListListAdapter.java src/com/owncloud/android/ui/adapter/LocalFileListAdapter.java src/com/owncloud/android/ui/fragment/ExtendedListFragment.java src/com/owncloud/android/ui/fragment/LocalFileListFragment.java src/com/owncloud/android/ui/fragment/OCFileListFragment.java --- 6d5c6f86e5fa9a2edb51562d028554cbc49cdf93 diff --cc res/layout/list_fragment.xml index 564404af,160edc1d..570970a6 --- a/res/layout/list_fragment.xml +++ b/res/layout/list_fragment.xml @@@ -31,18 -32,11 +33,18 @@@ - + android:layout_height="match_parent" + android:columnWidth="100dp" + android:gravity="center" + android:horizontalSpacing="2dp" + android:numColumns="auto_fit" + android:stretchMode="columnWidth" + android:verticalSpacing="2dp" + android:visibility="visible" /> + - - no blurry images on big screens + int px = mImageViewReference.get().getWidth(); + + if (mFile.isDown()){ + Bitmap bitmap = BitmapUtils.decodeSampledBitmapFromFile( + mFile.getStoragePath(), px, px); + + if (bitmap != null) { + thumbnail = ThumbnailUtils.extractThumbnail(bitmap, px, px); + + // Add thumbnail to cache + addBitmapToCache(imageKey, thumbnail); - mFile.setNeedsUpdateThumbnail(false); - mStorageManager.saveFile(mFile); - } - - } else { - // Download thumbnail from server - if (mClient != null && mServerVersion != null) { - OwnCloudVersion serverOCVersion = new OwnCloudVersion(mServerVersion); - if (serverOCVersion.compareTo(new OwnCloudVersion(MINOR_SERVER_VERSION_FOR_THUMBS)) >= 0) { - try { - int status = -1; - - String uri = mClient.getBaseUri() + "/index.php/apps/files/api/v1/thumbnail/" + - px + "/" + px + Uri.encode(mFile.getRemotePath(), "/"); - Log_OC.d("Thumbnail", "URI: " + uri); - GetMethod get = new GetMethod(uri); - status = mClient.executeMethod(get); - if (status == HttpStatus.SC_OK) { - byte[] bytes = get.getResponseBody(); - Bitmap bitmap = BitmapFactory.decodeByteArray(bytes, 0, bytes.length); - thumbnail = ThumbnailUtils.extractThumbnail(bitmap, px, px); - - // Add thumbnail to cache - if (thumbnail != null) { - addBitmapToCache(imageKey, thumbnail); - } - } - } catch (Exception e) { - e.printStackTrace(); - } - } else { - Log_OC.d(TAG, "Server too old"); - } - } - } + if (mFile instanceof OCFile) { + thumbnail = doOCFileInBackground(); + } else if (mFile instanceof File) { + thumbnail = doFileInBackground(); + } else { + // do nothing } - - } catch (Throwable t) { - // the app should never break due to a problem with thumbnails - Log_OC.e(TAG, "Generation of thumbnail for " + mFile + " failed", t); - if (t instanceof OutOfMemoryError) { - System.gc(); + + }catch(Throwable t){ + // the app should never break due to a problem with thumbnails + Log_OC.e(TAG, "Generation of thumbnail for " + mFile + " failed", t); + if (t instanceof OutOfMemoryError) { + System.gc(); + } } - } - + return thumbnail; } - + protected void onPostExecute(Bitmap bitmap){ if (isCancelled()) { bitmap = null; diff --cc src/com/owncloud/android/ui/adapter/FileListListAdapter.java index 9d054bc7,9c8c8e1f..ad399762 --- a/src/com/owncloud/android/ui/adapter/FileListListAdapter.java +++ b/src/com/owncloud/android/ui/adapter/FileListListAdapter.java @@@ -71,18 -65,12 +69,18 @@@ public class FileListListAdapter extend 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 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( @@@ -94,7 -82,8 +92,7 @@@ mJustFolders = justFolders; mContext = context; mAccount = AccountUtils.getCurrentOwnCloudAccount(mContext); - mTransferServiceGetter = transferServiceGetter; - + mTransferServiceGetter = transferServiceGetter; mAppPreferences = PreferenceManager .getDefaultSharedPreferences(mContext); @@@ -106,8 -95,9 +104,8 @@@ // initialise thumbnails cache on background thread new ThumbnailsCacheManager.InitDiskCacheTask().execute(); - } - + @Override public boolean areAllItemsEnabled() { return true; @@@ -313,32 -219,59 +312,37 @@@ if (thumbnail == null) { thumbnail = ThumbnailsCacheManager.mDefaultImg; } - final AsyncDrawable asyncDrawable = new AsyncDrawable( - mContext.getResources(), - thumbnail, + final ThumbnailsCacheManager.AsyncDrawable asyncDrawable = + new ThumbnailsCacheManager.AsyncDrawable( + mContext.getResources(), + thumbnail, task - ); + ); fileIcon.setImageDrawable(asyncDrawable); task.execute(file); + } } + } else { + fileIcon.setImageResource(DisplayUtils.getFileTypeIconId(file.getMimetype(), file.getFileName())); } - - if (checkIfFileIsSharedWithMe(file)) { - sharedWithMeIconV.setVisibility(View.VISIBLE); + else { + fileIcon.setImageResource(DisplayUtils.getResourceId(file.getMimetype(), file.getFileName())); } - } - 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.getResourceId(file.getMimetype(), file.getFileName())); + 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); - } + } } return view; @@@ -479,108 -391,20 +465,112 @@@ && 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)))); ++ 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); editor.putBoolean("sortAscending", ascending); editor.commit(); - mSortOrder = order; - mSortAscending = ascending; + FileStorageUtils.mSortOrder = order; + FileStorageUtils.mSortAscending = ascending; + + mFiles = FileStorageUtils.sortFolder(mFiles); + notifyDataSetChanged(); + + } + sortDirectory(); - } ++ } private CharSequence showRelativeTimestamp(OCFile file){ return DisplayUtils.getRelativeDateTimeString(mContext, file.getModificationTimestamp(), diff --cc src/com/owncloud/android/ui/adapter/LocalFileListAdapter.java index 7f4d7d53,996851e1..d65c70ed --- a/src/com/owncloud/android/ui/adapter/LocalFileListAdapter.java +++ b/src/com/owncloud/android/ui/adapter/LocalFileListAdapter.java @@@ -124,9 -129,40 +128,40 @@@ public class LocalFileListAdapter exten } checkBoxV.setVisibility(View.VISIBLE); } + + // get Thumbnail if file is image + if (BitmapUtils.isImage(file)){ + // Thumbnail in Cache? + Bitmap thumbnail = ThumbnailsCacheManager.getBitmapFromDiskCache( + String.valueOf(file.hashCode()) + ); + if (thumbnail != null){ + fileIcon.setImageBitmap(thumbnail); + } else { + + // generate new Thumbnail + if (ThumbnailsCacheManager.cancelPotentialWork(file, fileIcon)) { + final ThumbnailsCacheManager.ThumbnailGenerationTask task = + new ThumbnailsCacheManager.ThumbnailGenerationTask(fileIcon); + if (thumbnail == null) { + thumbnail = ThumbnailsCacheManager.mDefaultImg; + } + final ThumbnailsCacheManager.AsyncDrawable asyncDrawable = + new ThumbnailsCacheManager.AsyncDrawable( + mContext.getResources(), + thumbnail, + task + ); + fileIcon.setImageDrawable(asyncDrawable); + task.execute(file); + } + } + } else { + fileIcon.setImageResource(DisplayUtils.getFileTypeIconId(null, file.getName())); + } } else { - fileSizeV.setVisibility(View.GONE); + //fileSizeV.setVisibility(View.GONE); lastModV.setVisibility(View.GONE); checkBoxV.setVisibility(View.GONE); } diff --cc src/com/owncloud/android/ui/fragment/ExtendedListFragment.java index b48456f0,1b7a1ddf..def08c51 --- a/src/com/owncloud/android/ui/fragment/ExtendedListFragment.java +++ b/src/com/owncloud/android/ui/fragment/ExtendedListFragment.java @@@ -67,36 -66,32 +67,42 @@@ implements OnItemClickListener, OnEnfor private OnEnforceableRefreshListener mOnRefreshListener = null; - + protected GridView imageView; + public void setListAdapter(ListAdapter listAdapter) { - mList.setAdapter(listAdapter); - mList.invalidate(); + imageView.setAdapter(listAdapter); + imageView.invalidate(); } + public GridView getGridView() { + return imageView; + } + public void setFooterView(View footer) { + mList.addFooterView(footer, null, false); + mList.invalidate(); + } + - public ListView getListView() { - return mList; - } + + + protected void switchImageView(){ + imageView.setNumColumns(GridView.AUTO_FIT); + imageView.invalidate(); + } + + protected void switchFileView(){ + imageView.setNumColumns(1); + imageView.invalidate(); + } + + @Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { Log_OC.e(TAG, "onCreateView"); - + View v = inflater.inflate(R.layout.list_fragment, null); - mEmptyListMessage = (TextView) v.findViewById(R.id.empty_list_view); - mList = (ExtendedListView) (v.findViewById(R.id.list_root)); - mList.setOnItemClickListener(this); - - mList.setDivider(getResources().getDrawable(R.drawable.uploader_list_separator)); - mList.setDividerHeight(1); + + imageView = (ExtendedListView)(v.findViewById(R.id.list_root)); + imageView.setOnItemClickListener(this); if (savedInstanceState != null) { int referencePosition = savedInstanceState.getInt(KEY_SAVED_LIST_POSITION); @@@ -149,18 -145,20 +154,20 @@@ savedInstanceState.putString(KEY_EMPTY_LIST_MESSAGE, getEmptyViewText()); } - /** - * Calculates the position of the item that will be used as a reference to reposition the visible items - * in the list when the device is turned to other position. + * Calculates the position of the item that will be used as a reference to + * reposition the visible items in the list when the device is turned to + * other position. * - * THe current policy is take as a reference the visible item in the center of the screen. + * THe current policy is take as a reference the visible item in the center + * of the screen. * - * @return The position in the list of the visible item in the center of the screen. + * @return The position in the list of the visible item in the center of the + * screen. */ protected int getReferencePosition() { - if (mList != null) { - return (mList.getFirstVisiblePosition() + mList.getLastVisiblePosition()) / 2; + if (imageView != null) { + return (imageView.getFirstVisiblePosition() + imageView.getLastVisiblePosition()) / 2; } else { return 0; } @@@ -169,13 -167,12 +176,12 @@@ /** * Sets the visible part of the list from the reference position. * - * @param position Reference position previously - * returned by {@link LocalFileListFragment#getReferencePosition()} + * @param position Reference position previously returned by + * {@link LocalFileListFragment#getReferencePosition()} */ protected void setReferencePosition(int position) { - if (mList != null) { - mList.setAndCenterSelection(position); + if (imageView != null) { + imageView.setSelection(position); } } diff --cc src/com/owncloud/android/ui/fragment/LocalFileListFragment.java index e954f027,c9408b1e..02a1bfea --- a/src/com/owncloud/android/ui/fragment/LocalFileListFragment.java +++ b/src/com/owncloud/android/ui/fragment/LocalFileListFragment.java @@@ -98,26 -98,7 +98,21 @@@ public class LocalFileListFragment exte Log_OC.i(TAG, "onActivityCreated() stop"); } + public void selectAll(){ + int numberOfFiles = mAdapter.getCount(); + for(int i = 0; i < numberOfFiles; i++){ + File file = (File) mAdapter.getItem(i); + if (file != null) { + if (!file.isDirectory()) { + /// Click on a file + getGridView().setItemChecked(i, true); + // notify the change to the container Activity + mContainerActivity.onFileClick(file); + } + } + } + } - public void deselectAll(){ - mAdapter = new LocalFileListAdapter(mContainerActivity.getInitialDirectory(), getActivity()); - setListAdapter(mAdapter); - } - /** * Checks the file clicked over. Browses inside if it is a directory. Notifies the container activity in any case. */ diff --cc src/com/owncloud/android/ui/fragment/OCFileListFragment.java index dc96ca00,9c85dd98..114b048d --- a/src/com/owncloud/android/ui/fragment/OCFileListFragment.java +++ b/src/com/owncloud/android/ui/fragment/OCFileListFragment.java @@@ -124,13 -133,13 +133,13 @@@ public class OCFileListFragment extend justFolders, getSherlockActivity(), mContainerActivity - ); + ); setListAdapter(mAdapter); - - registerForContextMenu(getListView()); - getListView().setOnCreateContextMenuListener(this); - } - + + registerForContextMenu(getGridView()); + getGridView().setOnCreateContextMenuListener(this); + } + /** * Saves the current listed folder. */ @@@ -386,30 -393,11 +393,36 @@@ } mFile = 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())); ++ + // decide image vs. file view + double countImages = 0; + double countFiles = 0; + + Vector files = storageManager.getFolderContent(directory); + for (OCFile file : files){ + if (!file.isFolder()){ + countFiles++; + + if (file.isImage()){ + countImages++; + } + } + } + + // > 50% Images --> image view + // TODO threshold as constant in Preferences + if ((countImages / countFiles) >= 0.5){ + Log_OC.i(TAG, "Image View"); + switchImageView(); + } else { + Log_OC.i(TAG, "Folder View"); + switchFileView(); + } } }