From: jabarros Date: Thu, 23 Oct 2014 08:18:20 +0000 (+0200) Subject: Merge branch 'develop' into sorting_files_2 X-Git-Tag: oc-android-1.7.0_signed~134^2~4 X-Git-Url: http://git.linex4red.de/pub/Android/ownCloud.git/commitdiff_plain/2fad1e1a996c1f6058445ca398a74743b0e93023?ds=inline;hp=-c Merge branch 'develop' into sorting_files_2 Conflicts: src/com/owncloud/android/ui/adapter/FileListListAdapter.java --- 2fad1e1a996c1f6058445ca398a74743b0e93023 diff --combined res/values-de/strings.xml index e8f43195,028b6bc6..360ff0ee --- a/res/values-de/strings.xml +++ b/res/values-de/strings.xml @@@ -11,13 -11,6 +11,13 @@@ Einstellungen Details Senden + Sortieren + Sortieren nach + + A-Z + Neu - Alt + Groß - Klein + Allgemein Mehr Konten @@@ -111,7 -104,7 +111,7 @@@ Inhalte von %1$d konnte nicht synchronisiert werden (%2$d Konflikte) Einige lokale Dateien wurden vergessen %1$d Dateien aus dem %2$s Verzeichnis konnten nicht kopiert werden nach - Mit Version 1.3.16 werden Dateien die von diesem Gerät aus hochgeladen werden in den lokalen Ordner %1$s kopiert um Datenverlust zu vermeiden, wenn eine einzelne Datei mit mehreren Accounts synchronisiert wird.\n\nInfolge dieser Änderung wurden alle Dateien, die mit vorherigen Versionen dieser App hochgeladen wurden, in den Ordner %2$s verschoben. Jedoch ist während der Account-Synchronisation ein Fehler aufgetreten, der das Abschließen dieses Vorgangs verhindert. Du kannst die Datei(en) entweder wie sie sind belassen und den Link zu %3$s entfernen oder die Datei(en) in den %1$s Ordner verschieben und den Link zu %4$s beibehalten.\n\nUnten befindet sich eine Liste der lokalen Datei(en) und der mit ihnen verbundenen Remote-Datei(en) in %5$s. + Mit Version 1.3.16 werden Dateien die von diesem Gerät aus hochgeladen werden in den lokalen Ordner %1$s kopiert um Datenverlust zu vermeiden, wenn eine einzelne Datei mit mehreren Accounts synchronisiert wird.\n\nInfolge dieser Änderung wurden alle Dateien, die mit vorherigen Versionen dieser App hochgeladen wurden, in den Ordner %2$s verschoben. Jedoch ist während der Account-Synchronisation ein Fehler aufgetreten, der das Abschließen dieses Vorgangs verhindert. Du kannst die Datei(en) entweder wie sie sind belassen und den Link zu %3$s entfernen oder die Datei(en) in den Ordner %1$s verschieben und den Link zu %4$s beibehalten.\n\nUnten befindet sich eine Liste der lokalen Datei(en) und der mit ihnen verbundenen Remote-Datei(en) in %5$s. Das Verzeichnis %1$s existiert nicht mehr Verschiebe alle Alle Dateien wurden verschoben @@@ -245,6 -238,7 +245,7 @@@ Bildvorschau Dieses Bild kann nicht angezeigt werden %1$s konnte nicht in den lokalen %2$s Ordner kopiert werden + Pfad hochladen Entschuldigung, Freigaben sind auf Deinem Server nicht aktiviert. Bitte kontaktiere Deinen ⇥⇥Administrator. Teilen nicht möglich. Prüfe, dass die Datei existiert @@@ -281,8 -275,10 +282,10 @@@ Nichts vorhanden. Du kannst einen Ordner hinzufügen! Auswählen Verschieben nicht möglich. Prüfe, dass die Datei existiert - Es ist nicht möglich einen Ordner eine Ebene tiefer zu verschieben + Es ist nicht möglich, einen Ordner in einen seiner Unterordner zu verschieben Die Datei ist bereits im Zielordner vorhanden - Es ist ein Fehler beim Verschieben dieser Datei oder Ordners aufgetreten. - zum Datei verschieben + Es ist ein Fehler beim Verschieben der Datei oder des Ordners aufgetreten. + um diese Datei zu verschieben + Sofortiges Hochladen + Sicherheit diff --combined res/values/strings.xml index 4c5f57b0,389db1da..dfda56b3 --- a/res/values/strings.xml +++ b/res/values/strings.xml @@@ -12,13 -12,6 +12,13 @@@ Settings Details Send + Sort + Sort by + + A-Z + Newest - Oldest + Biggest - Smallest + General More Accounts @@@ -258,6 -251,7 +258,7 @@@ This image cannot be shown %1$s could not be copied to %2$s local folder + Upload Path Sorry, sharing is not enabled on your server. Please contact your administrator. @@@ -290,7 -284,7 +291,7 @@@ Accounts Add account - Secure connection is redirected through an unsecured route. + Secure connection is redirected to an unsecured route. Logs Send History @@@ -309,4 -303,7 +310,7 @@@ An error occurred while trying to move this file or folder to move this file + Instant Uploads + Security + diff --combined src/com/owncloud/android/ui/adapter/FileListListAdapter.java index ffc2d69f,0d10e7fa..451def0e --- a/src/com/owncloud/android/ui/adapter/FileListListAdapter.java +++ b/src/com/owncloud/android/ui/adapter/FileListListAdapter.java @@@ -17,25 -17,11 +17,17 @@@ */ package com.owncloud.android.ui.adapter; ++ +import java.io.File; - import java.lang.ref.WeakReference; +import java.util.Collections; +import java.util.Comparator; import java.util.Vector; import android.accounts.Account; import android.content.Context; +import android.content.SharedPreferences; - import android.content.res.Resources; import android.graphics.Bitmap; - import android.graphics.Bitmap.CompressFormat; - import android.graphics.BitmapFactory; - import android.graphics.drawable.BitmapDrawable; - import android.graphics.drawable.Drawable; - import android.media.ThumbnailUtils; - import android.os.AsyncTask; +import android.preference.PreferenceManager; - import android.util.TypedValue; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; @@@ -47,17 -33,14 +39,17 @@@ import android.widget.TextView import com.owncloud.android.R; import com.owncloud.android.authentication.AccountUtils; +import com.owncloud.android.datamodel.AlphanumComparator; import com.owncloud.android.datamodel.FileDataStorageManager; import com.owncloud.android.datamodel.OCFile; + import com.owncloud.android.datamodel.ThumbnailsCacheManager; + import com.owncloud.android.datamodel.ThumbnailsCacheManager.AsyncDrawable; import com.owncloud.android.files.services.FileDownloader.FileDownloaderBinder; import com.owncloud.android.files.services.FileUploader.FileUploaderBinder; - import com.owncloud.android.lib.common.utils.Log_OC; import com.owncloud.android.ui.activity.ComponentsGetter; - import com.owncloud.android.utils.BitmapUtils; import com.owncloud.android.utils.DisplayUtils; +import com.owncloud.android.utils.FileStorageUtils; + /** @@@ -71,8 -54,6 +63,6 @@@ public class FileListListAdapter extends BaseAdapter implements ListAdapter { private final static String PERMISSION_SHARED_WITH_ME = "S"; - private static final String TAG = FileListListAdapter.class.getSimpleName(); - private Context mContext; private OCFile mFile = null; private Vector mFiles = null; @@@ -81,18 -62,7 +71,10 @@@ private FileDataStorageManager mStorageManager; private Account mAccount; private ComponentsGetter mTransferServiceGetter; + private Integer sortOrder; + private Boolean sortAscending; + private SharedPreferences appPreferences; - private final Object thumbnailDiskCacheLock = new Object(); - private DiskLruImageCache mThumbnailCache; - private boolean mThumbnailCacheStarting = true; - private static final int DISK_CACHE_SIZE = 1024 * 1024 * 10; // 10MB - private static final CompressFormat mCompressFormat = CompressFormat.JPEG; - private static final int mCompressQuality = 70; - private Bitmap defaultImg; - public FileListListAdapter( boolean justFolders, Context context, @@@ -102,153 -72,12 +84,20 @@@ mJustFolders = justFolders; mContext = context; mAccount = AccountUtils.getCurrentOwnCloudAccount(mContext); -- mTransferServiceGetter = transferServiceGetter; ++ mTransferServiceGetter = transferServiceGetter; + + appPreferences = PreferenceManager + .getDefaultSharedPreferences(mContext); + + // Read sorting order, default to sort by name ascending + sortOrder = appPreferences + .getInt("sortOrder", 0); - sortAscending = appPreferences.getBoolean("sortAscending", true); - - defaultImg = BitmapFactory.decodeResource(mContext.getResources(), - DisplayUtils.getResourceId("image/png", "default.png")); - - // Initialise disk cache on background thread - new InitDiskCacheTask().execute(); - } - - class InitDiskCacheTask extends AsyncTask { - @Override - protected Void doInBackground(File... params) { - synchronized (thumbnailDiskCacheLock) { - try { - mThumbnailCache = new DiskLruImageCache(mContext, "thumbnailCache", - DISK_CACHE_SIZE, mCompressFormat, mCompressQuality); - } catch (Exception e) { - Log_OC.d(TAG, "Thumbnail cache could not be opened ", e); - mThumbnailCache = null; - } - mThumbnailCacheStarting = false; // Finished initialization - thumbnailDiskCacheLock.notifyAll(); // Wake any waiting threads - } - return null; - } - } - - static class AsyncDrawable extends BitmapDrawable { - private final WeakReference bitmapWorkerTaskReference; - - public AsyncDrawable(Resources res, Bitmap bitmap, - ThumbnailGenerationTask bitmapWorkerTask) { - super(res, bitmap); - bitmapWorkerTaskReference = - new WeakReference(bitmapWorkerTask); - } - - public ThumbnailGenerationTask getBitmapWorkerTask() { - return bitmapWorkerTaskReference.get(); - } - } - - class ThumbnailGenerationTask extends AsyncTask { - private final WeakReference imageViewReference; - private OCFile file; - - - public ThumbnailGenerationTask(ImageView imageView) { - // Use a WeakReference to ensure the ImageView can be garbage collected - imageViewReference = new WeakReference(imageView); - } - - // Decode image in background. - @Override - protected Bitmap doInBackground(OCFile... params) { - Bitmap thumbnail = null; - - try { - file = params[0]; - final String imageKey = String.valueOf(file.getRemoteId()); - - // Check disk cache in background thread - thumbnail = getBitmapFromDiskCache(imageKey); - - // Not found in disk cache - if (thumbnail == null || file.needsUpdateThumbnail()) { - // Converts dp to pixel - Resources r = mContext.getResources(); - int px = (int) Math.round(TypedValue.applyDimension( - TypedValue.COMPLEX_UNIT_DIP, 150, r.getDisplayMetrics() - )); - - if (file.isDown()){ - Bitmap bitmap = BitmapUtils.decodeSampledBitmapFromFile( - file.getStoragePath(), px, px); - - if (bitmap != null) { - thumbnail = ThumbnailUtils.extractThumbnail(bitmap, px, px); - - // Add thumbnail to cache - addBitmapToCache(imageKey, thumbnail); - - file.setNeedsUpdateThumbnail(false); - mStorageManager.saveFile(file); - } - - } - } - - } catch (Throwable t) { - // the app should never break due to a problem with thumbnails - Log_OC.e(TAG, "Generation of thumbnail for " + file + " failed", t); - if (t instanceof OutOfMemoryError) { - System.gc(); - } - } - - return thumbnail; - } ++ sortAscending = appPreferences.getBoolean("sortAscending", true); - protected void onPostExecute(Bitmap bitmap){ - if (isCancelled()) { - bitmap = null; - } - - if (imageViewReference != null && bitmap != null) { - final ImageView imageView = imageViewReference.get(); - final ThumbnailGenerationTask bitmapWorkerTask = - getBitmapWorkerTask(imageView); - if (this == bitmapWorkerTask && imageView != null) { - imageView.setImageBitmap(bitmap); - } - } - } - } - - public void addBitmapToCache(String key, Bitmap bitmap) { - synchronized (thumbnailDiskCacheLock) { - if (mThumbnailCache != null) { - mThumbnailCache.put(key, bitmap); - } - } + // initialise thumbnails cache on background thread + new ThumbnailsCacheManager.InitDiskCacheTask().execute(); } - - public Bitmap getBitmapFromDiskCache(String key) { - synchronized (thumbnailDiskCacheLock) { - // Wait while disk cache is started from background thread - while (mThumbnailCacheStarting) { - try { - thumbnailDiskCacheLock.wait(); - } catch (InterruptedException e) {} - } - if (mThumbnailCache != null) { - return (Bitmap) mThumbnailCache.getBitmap(key); - } - } - return null; - } - - ++ @Override public boolean areAllItemsEnabled() { return true; @@@ -299,6 -128,7 +148,7 @@@ fileName.setText(name); ImageView fileIcon = (ImageView) view.findViewById(R.id.imageView1); + fileIcon.setTag(file.getFileId()); ImageView sharedIconV = (ImageView) view.findViewById(R.id.sharedIcon); ImageView sharedWithMeIconV = (ImageView) view.findViewById(R.id.sharedWithMeIcon); sharedWithMeIconV.setVisibility(View.GONE); @@@ -353,18 -183,28 +203,28 @@@ } // get Thumbnail if file is image - if (file.isImage()){ + if (file.isImage() && file.getRemoteId() != null){ // Thumbnail in Cache? - Bitmap thumbnail = getBitmapFromDiskCache(String.valueOf(file.getRemoteId())); + Bitmap thumbnail = ThumbnailsCacheManager.getBitmapFromDiskCache( + String.valueOf(file.getRemoteId()) + ); if (thumbnail != null && !file.needsUpdateThumbnail()){ fileIcon.setImageBitmap(thumbnail); } else { // generate new Thumbnail - if (cancelPotentialWork(file, fileIcon)) { - final ThumbnailGenerationTask task = - new ThumbnailGenerationTask(fileIcon); - final AsyncDrawable asyncDrawable = - new AsyncDrawable(mContext.getResources(), defaultImg, task); + if (ThumbnailsCacheManager.cancelPotentialWork(file, fileIcon)) { + final ThumbnailsCacheManager.ThumbnailGenerationTask task = + new ThumbnailsCacheManager.ThumbnailGenerationTask( + fileIcon, mStorageManager + ); + if (thumbnail == null) { + thumbnail = ThumbnailsCacheManager.mDefaultImg; + } + final AsyncDrawable asyncDrawable = new AsyncDrawable( + mContext.getResources(), + thumbnail, + task + ); fileIcon.setImageDrawable(asyncDrawable); task.execute(file); } @@@ -380,13 -220,8 +240,13 @@@ } } else { - fileSizeV.setVisibility(View.INVISIBLE); - //fileSizeV.setText(DisplayUtils.bytesToHumanReadable(file.getFileLength())); + 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( DisplayUtils.unixTimeToHumanReadable(file.getModificationTimestamp()) @@@ -419,78 -254,7 +279,49 @@@ return view; } - + - public static boolean cancelPotentialWork(OCFile file, ImageView imageView) { - final ThumbnailGenerationTask bitmapWorkerTask = getBitmapWorkerTask(imageView); - - if (bitmapWorkerTask != null) { - final OCFile bitmapData = bitmapWorkerTask.file; - // If bitmapData is not yet set or it differs from the new data - if (bitmapData == null || bitmapData != file) { - // Cancel previous task - bitmapWorkerTask.cancel(true); - } else { - // The same work is already in progress - return false; - } - } - // No task associated with the ImageView, or an existing task was cancelled - return true; - } - - private static ThumbnailGenerationTask getBitmapWorkerTask(ImageView imageView) { - if (imageView != null) { - final Drawable drawable = imageView.getDrawable(); - if (drawable instanceof AsyncDrawable) { - final AsyncDrawable asyncDrawable = (AsyncDrawable) drawable; - return asyncDrawable.getBitmapWorkerTask(); - } - } - return null; - } - + /** + * Local Folder size in human readable format + * @param path String + * @return Size in human readable format + */ + private String getFolderSizeHuman(String path) { + + File dir = new File(path); + + if(dir.exists()) { + long bytes = getFolderSize(dir); + if (bytes < 1024) return bytes + " B"; + int exp = (int) (Math.log(bytes) / Math.log(1024)); + String pre = ("KMGTPE").charAt(exp-1) + ""; + + return String.format("%.1f %sB", bytes / Math.pow(1024, exp), pre); + } + + return "0 B"; + } + + /** + * Local Folder size + * @param dir File + * @return Size in bytes + */ + private long getFolderSize(File dir) { + if (dir.exists()) { + long result = 0; + File[] fileList = dir.listFiles(); + for(int i = 0; i < fileList.length; i++) { + if(fileList[i].isDirectory()) { + result += getFolderSize(fileList[i]); + } else { + result += fileList[i].length(); + } + } + return result; + } + return 0; + } - ++ @Override public int getViewTypeCount() { return 1; @@@ -527,26 -291,6 +358,26 @@@ } else { mFiles = null; } + + sortDirectory(); + } + + /** + * Sorts all filenames, regarding last user decision + */ + private void sortDirectory(){ + switch (sortOrder){ + case 0: + sortByName(sortAscending); + break; + case 1: + sortByDate(sortAscending); + break; + case 2: + sortBySize(sortAscending); + break; + } + notifyDataSetChanged(); } @@@ -582,103 -326,4 +413,103 @@@ && file.getPermissions() != null && 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()) { + return val * Long.compare(o1.getModificationTimestamp(), 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 { + return val * Long.compare(o1.getModificationTimestamp(), 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()) { + return val * Long.compare(getFolderSize(new File(FileStorageUtils.getDefaultSavePathFor(mAccount.name, o1))), + 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 { + return val * Long.compare(o1.getFileLength(), 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 = appPreferences.edit(); + editor.putInt("sortOrder", order); + editor.putBoolean("sortAscending", ascending); + editor.commit(); + + sortOrder = order; + sortAscending = ascending; + + sortDirectory(); + } }