Skip to content
This repository has been archived by the owner on Dec 3, 2024. It is now read-only.

Commit

Permalink
Show files in folder picker (fixes #167).
Browse files Browse the repository at this point in the history
  • Loading branch information
Nutomic committed Jan 19, 2015
1 parent 535b1f6 commit fd861cd
Showing 1 changed file with 22 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,9 @@
import com.nutomic.syncthingandroid.syncthing.SyncthingService;

import java.io.File;
import java.io.FileFilter;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Comparator;

/**
* Activity that allows selecting a directory in the local file system.
Expand Down Expand Up @@ -169,13 +169,17 @@ private void createFolder(String name) {
private void displayFolder(File folder) {
mLocation = folder;
mFilesAdapter.clear();
File[] contents = mLocation.listFiles(new FileFilter() {
@Override
public boolean accept(File file) {
return file.isDirectory();
File[] contents = mLocation.listFiles();
Arrays.sort(contents, new Comparator<File>() {
public int compare(File f1, File f2) {
if (f1.isDirectory() && f2.isFile())
return -1;
if (f1.isFile() && f2.isDirectory())
return 1;
return f1.getName().compareTo(f2.getName());
}
});
Arrays.sort(contents);

for (File f : contents) {
mFilesAdapter.add(f);
}
Expand All @@ -185,8 +189,11 @@ public boolean accept(File file) {
@Override
public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) {
ArrayAdapter<File> adapter = (ArrayAdapter<File>) mListView.getAdapter();
displayFolder(adapter.getItem(i));
invalidateOptionsMenu();
File f = adapter.getItem(i);
if (f.isDirectory()) {
displayFolder(f);
invalidateOptionsMenu();
}
}

private class FileAdapter extends ArrayAdapter<File> {
Expand All @@ -199,7 +206,13 @@ public FileAdapter(Context context) {
public View getView(int position, View convertView, ViewGroup parent) {
convertView = super.getView(position, convertView, parent);
TextView title = (TextView) convertView.findViewById(android.R.id.text1);
title.setText(getItem(position).getName());
File f = getItem(position);
title.setText(f.getName());
int textColor = (f.isDirectory())
? android.R.color.primary_text_light
: android.R.color.tertiary_text_light;
title.setTextColor(getContext().getResources().getColor(textColor));

return convertView;
}
}
Expand Down

0 comments on commit fd861cd

Please sign in to comment.