footer view disabled due to GridView does not support it
This commit is contained in:
tobiasKaminsky 2015-01-19 22:10:29 +01:00
parent d4e0f3bdb1
commit 04b77aa2f4
3 changed files with 42 additions and 51 deletions

View file

@ -142,28 +142,8 @@ public class FileListListAdapter extends BaseAdapter implements ListAdapter {
@Override
public View getView(int position, View convertView, ViewGroup parent) {
// decide image vs. file view
double countImages = 0;
double countFiles = 0;
for (OCFile file : mFiles){
if (!file.isFolder()){
countFiles++;
if (file.isImage()){
countImages++;
}
}
}
// TODO threshold as constant in Preferences
// > 50% Images --> image view
boolean fileView = true;
if ((countImages / countFiles) >= 0.5){
fileView = false;
} else {
fileView = true;
}
boolean fileView = DisplayUtils.decideViewLayout(mFiles);
View view = convertView;
OCFile file = null;
@ -176,7 +156,7 @@ public class FileListListAdapter extends BaseAdapter implements ListAdapter {
// Find out which layout should be displayed
ViewType viewType;
if (fileView){
if (!fileView){
viewType = ViewType.LIST_ITEM;
} else if (file.isImage()){
viewType = ViewType.GRID_IMAGE;

View file

@ -48,6 +48,7 @@ import com.owncloud.android.ui.dialog.RemoveFileDialogFragment;
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;
/**
@ -393,34 +394,14 @@ public class OCFileListFragment extends ExtendedListFragment {
}
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<OCFile> 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");
if (DisplayUtils.decideViewLayout(files)){
switchImageView();
} else {
Log_OC.i(TAG, "Folder View");
// Update Footer
TextView footerText = (TextView) mFooterView.findViewById(R.id.footerText);
footerText.setText(generateFooterText(directory));
switchFileView();
}
}

View file

@ -26,6 +26,7 @@ import java.util.Date;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Set;
import java.util.Vector;
import android.annotation.TargetApi;
import android.content.Context;
@ -51,6 +52,8 @@ public class DisplayUtils {
private static final String[] sizeSuffixes = { "B", "KB", "MB", "GB", "TB", "PB", "EB", "ZB", "YB" };
private final static Double THUMBNAIL_THRESHOLD = 0.5;
private static HashMap<String, String> mimeType2HUmanReadable;
static {
mimeType2HUmanReadable = new HashMap<String, String>();
@ -340,4 +343,31 @@ public class DisplayUtils {
}
return path;
}
/**
*
* @param mFiles
* @return true: imageView, false: listView
*/
public static boolean decideViewLayout(Vector<OCFile> mFiles){
// decide image vs. file view
double countImages = 0;
double countFiles = 0;
for (OCFile file : mFiles){
if (!file.isFolder()){
countFiles++;
if (file.isImage()){
countImages++;
}
}
}
if ((countImages / countFiles) >= THUMBNAIL_THRESHOLD){
return true;
} else {
return false;
}
}
}