X-Git-Url: http://git.linex4red.de/pub/Android/ownCloud.git/blobdiff_plain/41666b2d6cdb5235164f0e2a06ea77b2313426b2..288c148b51b951017a3a9b333797a7e8eeede38a:/src/com/owncloud/android/ui/preview/PreviewImagePagerAdapter.java diff --git a/src/com/owncloud/android/ui/preview/PreviewImagePagerAdapter.java b/src/com/owncloud/android/ui/preview/PreviewImagePagerAdapter.java index 2b9fffa4..6e7f19d4 100644 --- a/src/com/owncloud/android/ui/preview/PreviewImagePagerAdapter.java +++ b/src/com/owncloud/android/ui/preview/PreviewImagePagerAdapter.java @@ -1,5 +1,8 @@ -/* ownCloud Android client application - * Copyright (C) 2012-2013 ownCloud Inc. +/** + * ownCloud Android client application + * + * @author David A. Velasco + * Copyright (C) 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, @@ -16,6 +19,8 @@ */ package com.owncloud.android.ui.preview; +import java.util.Collections; +import java.util.Comparator; import java.util.HashMap; import java.util.HashSet; import java.util.Iterator; @@ -31,12 +36,12 @@ import android.view.ViewGroup; import com.owncloud.android.datamodel.FileDataStorageManager; import com.owncloud.android.datamodel.OCFile; +import com.owncloud.android.ui.adapter.FileListListAdapter; import com.owncloud.android.ui.fragment.FileFragment; +import com.owncloud.android.utils.FileStorageUtils; /** - * Adapter class that provides Fragment instances - * - * @author David A. Velasco + * Adapter class that provides Fragment instances */ //public class PreviewImagePagerAdapter extends PagerAdapter { public class PreviewImagePagerAdapter extends FragmentStatePagerAdapter { @@ -73,13 +78,15 @@ public class PreviewImagePagerAdapter extends FragmentStatePagerAdapter { mAccount = account; mStorageManager = storageManager; mImageFiles = mStorageManager.getFolderImages(parentFolder); + + mImageFiles = FileStorageUtils.sortFolder(mImageFiles); + mObsoleteFragments = new HashSet(); mObsoletePositions = new HashSet(); mDownloadErrors = new HashSet(); //mFragmentManager = fragmentManager; mCachedFragments = new HashMap(); } - /** * Returns the image files handled by the adapter. @@ -95,15 +102,17 @@ public class PreviewImagePagerAdapter extends FragmentStatePagerAdapter { OCFile file = mImageFiles.get(i); Fragment fragment = null; if (file.isDown()) { - fragment = new PreviewImageFragment(file, mAccount, mObsoletePositions.contains(Integer.valueOf(i))); + fragment = PreviewImageFragment.newInstance(file, mObsoletePositions.contains(Integer.valueOf(i))); } else if (mDownloadErrors.contains(Integer.valueOf(i))) { - fragment = new FileDownloadFragment(file, mAccount, true); + fragment = FileDownloadFragment.newInstance(file, mAccount, true); ((FileDownloadFragment)fragment).setError(true); mDownloadErrors.remove(Integer.valueOf(i)); } else { - fragment = new FileDownloadFragment(file, mAccount, mObsoletePositions.contains(Integer.valueOf(i))); + fragment = FileDownloadFragment.newInstance( + file, mAccount, mObsoletePositions.contains(Integer.valueOf(i)) + ); } mObsoletePositions.remove(Integer.valueOf(i)); return fragment; @@ -199,17 +208,17 @@ public class PreviewImagePagerAdapter extends FragmentStatePagerAdapter { *- / @Override public void startUpdate(ViewGroup container) { - Log.e(TAG, "** startUpdate"); + Log_OC.e(TAG, "** startUpdate"); } @Override public Object instantiateItem(ViewGroup container, int position) { - Log.e(TAG, "** instantiateItem " + position); + Log_OC.e(TAG, "** instantiateItem " + position); if (mFragments.size() > position) { Fragment fragment = mFragments.get(position); if (fragment != null) { - Log.e(TAG, "** \t returning cached item"); + Log_OC.e(TAG, "** \t returning cached item"); return fragment; } } @@ -235,7 +244,7 @@ public class PreviewImagePagerAdapter extends FragmentStatePagerAdapter { } fragment.setMenuVisibility(false); mFragments.set(position, fragment); - //Log.e(TAG, "** \t adding fragment at position " + position + ", containerId " + container.getId()); + //Log_OC.e(TAG, "** \t adding fragment at position " + position + ", containerId " + container.getId()); mCurTransaction.add(container.getId(), fragment); return fragment; @@ -243,13 +252,13 @@ public class PreviewImagePagerAdapter extends FragmentStatePagerAdapter { @Override public void destroyItem(ViewGroup container, int position, Object object) { - Log.e(TAG, "** destroyItem " + position); + Log_OC.e(TAG, "** destroyItem " + position); Fragment fragment = (Fragment)object; if (mCurTransaction == null) { mCurTransaction = mFragmentManager.beginTransaction(); } - Log.e(TAG, "** \t removing fragment at position " + position); + Log_OC.e(TAG, "** \t removing fragment at position " + position); while (mSavedState.size() <= position) { mSavedState.add(null); } @@ -275,13 +284,13 @@ public class PreviewImagePagerAdapter extends FragmentStatePagerAdapter { @Override public void finishUpdate(ViewGroup container) { - Log.e(TAG, "** finishUpdate (start)"); + Log_OC.e(TAG, "** finishUpdate (start)"); if (mCurTransaction != null) { mCurTransaction.commitAllowingStateLoss(); mCurTransaction = null; mFragmentManager.executePendingTransactions(); } - Log.e(TAG, "** finishUpdate (end)"); + Log_OC.e(TAG, "** finishUpdate (end)"); } @Override @@ -336,7 +345,7 @@ public class PreviewImagePagerAdapter extends FragmentStatePagerAdapter { f.setMenuVisibility(false); mFragments.set(index, f); } else { - Log.w(TAG, "Bad fragment at key " + key); + Log_OC.w(TAG, "Bad fragment at key " + key); } } }