mirror of
https://github.com/syncthing/syncthing-android.git
synced 2024-11-23 04:41:16 +00:00
Show files in folder picker (fixes #167).
This commit is contained in:
parent
535b1f6108
commit
fd861cdee9
1 changed files with 22 additions and 9 deletions
|
@ -27,9 +27,9 @@ import com.nutomic.syncthingandroid.R;
|
||||||
import com.nutomic.syncthingandroid.syncthing.SyncthingService;
|
import com.nutomic.syncthingandroid.syncthing.SyncthingService;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.FileFilter;
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
|
import java.util.Comparator;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Activity that allows selecting a directory in the local file system.
|
* Activity that allows selecting a directory in the local file system.
|
||||||
|
@ -169,13 +169,17 @@ public class FolderPickerActivity extends SyncthingActivity
|
||||||
private void displayFolder(File folder) {
|
private void displayFolder(File folder) {
|
||||||
mLocation = folder;
|
mLocation = folder;
|
||||||
mFilesAdapter.clear();
|
mFilesAdapter.clear();
|
||||||
File[] contents = mLocation.listFiles(new FileFilter() {
|
File[] contents = mLocation.listFiles();
|
||||||
@Override
|
Arrays.sort(contents, new Comparator<File>() {
|
||||||
public boolean accept(File file) {
|
public int compare(File f1, File f2) {
|
||||||
return file.isDirectory();
|
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) {
|
for (File f : contents) {
|
||||||
mFilesAdapter.add(f);
|
mFilesAdapter.add(f);
|
||||||
}
|
}
|
||||||
|
@ -185,8 +189,11 @@ public class FolderPickerActivity extends SyncthingActivity
|
||||||
@Override
|
@Override
|
||||||
public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) {
|
public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) {
|
||||||
ArrayAdapter<File> adapter = (ArrayAdapter<File>) mListView.getAdapter();
|
ArrayAdapter<File> adapter = (ArrayAdapter<File>) mListView.getAdapter();
|
||||||
displayFolder(adapter.getItem(i));
|
File f = adapter.getItem(i);
|
||||||
invalidateOptionsMenu();
|
if (f.isDirectory()) {
|
||||||
|
displayFolder(f);
|
||||||
|
invalidateOptionsMenu();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private class FileAdapter extends ArrayAdapter<File> {
|
private class FileAdapter extends ArrayAdapter<File> {
|
||||||
|
@ -199,7 +206,13 @@ public class FolderPickerActivity extends SyncthingActivity
|
||||||
public View getView(int position, View convertView, ViewGroup parent) {
|
public View getView(int position, View convertView, ViewGroup parent) {
|
||||||
convertView = super.getView(position, convertView, parent);
|
convertView = super.getView(position, convertView, parent);
|
||||||
TextView title = (TextView) convertView.findViewById(android.R.id.text1);
|
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;
|
return convertView;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue