mirror of
https://github.com/nextcloud/android.git
synced 2024-11-23 13:45:35 +03:00
rebased
footer view disabled due to GridView does not support it
This commit is contained in:
parent
d4e0f3bdb1
commit
04b77aa2f4
3 changed files with 42 additions and 51 deletions
|
@ -65,7 +65,7 @@ import com.owncloud.android.utils.FileStorageUtils;
|
||||||
*/
|
*/
|
||||||
public class FileListListAdapter extends BaseAdapter implements ListAdapter {
|
public class FileListListAdapter extends BaseAdapter implements ListAdapter {
|
||||||
private final static String PERMISSION_SHARED_WITH_ME = "S";
|
private final static String PERMISSION_SHARED_WITH_ME = "S";
|
||||||
|
|
||||||
private Context mContext;
|
private Context mContext;
|
||||||
private OCFile mFile = null;
|
private OCFile mFile = null;
|
||||||
private Vector<OCFile> mFiles = null;
|
private Vector<OCFile> mFiles = null;
|
||||||
|
@ -142,29 +142,9 @@ public class FileListListAdapter extends BaseAdapter implements ListAdapter {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public View getView(int position, View convertView, ViewGroup parent) {
|
public View getView(int position, View convertView, ViewGroup parent) {
|
||||||
// decide image vs. file view
|
|
||||||
double countImages = 0;
|
boolean fileView = DisplayUtils.decideViewLayout(mFiles);
|
||||||
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;
|
|
||||||
}
|
|
||||||
|
|
||||||
View view = convertView;
|
View view = convertView;
|
||||||
OCFile file = null;
|
OCFile file = null;
|
||||||
LayoutInflater inflator = (LayoutInflater) mContext
|
LayoutInflater inflator = (LayoutInflater) mContext
|
||||||
|
@ -176,7 +156,7 @@ public class FileListListAdapter extends BaseAdapter implements ListAdapter {
|
||||||
|
|
||||||
// Find out which layout should be displayed
|
// Find out which layout should be displayed
|
||||||
ViewType viewType;
|
ViewType viewType;
|
||||||
if (fileView){
|
if (!fileView){
|
||||||
viewType = ViewType.LIST_ITEM;
|
viewType = ViewType.LIST_ITEM;
|
||||||
} else if (file.isImage()){
|
} else if (file.isImage()){
|
||||||
viewType = ViewType.GRID_IMAGE;
|
viewType = ViewType.GRID_IMAGE;
|
||||||
|
|
|
@ -48,6 +48,7 @@ import com.owncloud.android.ui.dialog.RemoveFileDialogFragment;
|
||||||
import com.owncloud.android.ui.dialog.RenameFileDialogFragment;
|
import com.owncloud.android.ui.dialog.RenameFileDialogFragment;
|
||||||
import com.owncloud.android.ui.preview.PreviewImageFragment;
|
import com.owncloud.android.ui.preview.PreviewImageFragment;
|
||||||
import com.owncloud.android.ui.preview.PreviewMediaFragment;
|
import com.owncloud.android.ui.preview.PreviewMediaFragment;
|
||||||
|
import com.owncloud.android.utils.DisplayUtils;
|
||||||
import com.owncloud.android.utils.FileStorageUtils;
|
import com.owncloud.android.utils.FileStorageUtils;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -392,35 +393,15 @@ public class OCFileListFragment extends ExtendedListFragment {
|
||||||
imageView.setSelection(0);
|
imageView.setSelection(0);
|
||||||
}
|
}
|
||||||
mFile = directory;
|
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);
|
Vector<OCFile> files = storageManager.getFolderContent(directory);
|
||||||
for (OCFile file : files){
|
if (DisplayUtils.decideViewLayout(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();
|
switchImageView();
|
||||||
} else {
|
} else {
|
||||||
Log_OC.i(TAG, "Folder View");
|
// Update Footer
|
||||||
|
TextView footerText = (TextView) mFooterView.findViewById(R.id.footerText);
|
||||||
|
footerText.setText(generateFooterText(directory));
|
||||||
|
|
||||||
switchFileView();
|
switchFileView();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -26,6 +26,7 @@ import java.util.Date;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
import java.util.Vector;
|
||||||
|
|
||||||
import android.annotation.TargetApi;
|
import android.annotation.TargetApi;
|
||||||
import android.content.Context;
|
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 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;
|
private static HashMap<String, String> mimeType2HUmanReadable;
|
||||||
static {
|
static {
|
||||||
mimeType2HUmanReadable = new HashMap<String, String>();
|
mimeType2HUmanReadable = new HashMap<String, String>();
|
||||||
|
@ -340,4 +343,31 @@ public class DisplayUtils {
|
||||||
}
|
}
|
||||||
return path;
|
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;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue