[Android] Make FolderBrowser.Fill look slightly nicer. Improve readability a bit.
- Added a basic function description. - Modified the main parameter to be more informative of what should be passed. Helps people who read the codebase for the first time. - Made a variable for storing the entry name so getName() isn't called a bunch of times. - Added some comments to explain some parts. - Rename the exception catch variable to ignored, since it currently isn't being used.
This commit is contained in:
parent
c86480d082
commit
4e8c3b2f12
|
@ -19,48 +19,59 @@ import java.util.List;
|
||||||
public class FolderBrowser extends ListActivity {
|
public class FolderBrowser extends ListActivity {
|
||||||
private FolderBrowserAdapter adapter;
|
private FolderBrowserAdapter adapter;
|
||||||
private static File currentDir = null;
|
private static File currentDir = null;
|
||||||
private void Fill(File f)
|
|
||||||
|
// Populates the FolderView with the given currDir's contents.
|
||||||
|
private void Fill(File currDir)
|
||||||
{
|
{
|
||||||
File[]dirs = f.listFiles();
|
this.setTitle("Current Dir: " + currDir.getName());
|
||||||
this.setTitle("Current Dir: " + f.getName());
|
File[] dirs = currDir.listFiles();
|
||||||
List<GameListItem>dir = new ArrayList<GameListItem>();
|
List<GameListItem>dir = new ArrayList<GameListItem>();
|
||||||
List<GameListItem>fls = new ArrayList<GameListItem>();
|
List<GameListItem>fls = new ArrayList<GameListItem>();
|
||||||
|
|
||||||
|
// Search for any directories or supported files within the current dir.
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
for(File ff: dirs)
|
for(File entry : dirs)
|
||||||
{
|
{
|
||||||
if (ff.getName().charAt(0) != '.')
|
String entryName = entry.getName();
|
||||||
if(ff.isDirectory())
|
|
||||||
dir.add(new GameListItem(getApplicationContext(), ff.getName(),"Folder",ff.getAbsolutePath(), true));
|
if (entryName.charAt(0) != '.')
|
||||||
|
{
|
||||||
|
if(entry.isDirectory())
|
||||||
|
{
|
||||||
|
dir.add(new GameListItem(getApplicationContext(), entryName,"Folder",entry.getAbsolutePath(), true));
|
||||||
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
if (ff.getName().toLowerCase().contains(".gcm") ||
|
if (entryName.toLowerCase().contains(".gcm") ||
|
||||||
ff.getName().toLowerCase().contains(".iso") ||
|
entryName.toLowerCase().contains(".iso") ||
|
||||||
ff.getName().toLowerCase().contains(".wbfs") ||
|
entryName.toLowerCase().contains(".wbfs") ||
|
||||||
ff.getName().toLowerCase().contains(".gcz") ||
|
entryName.toLowerCase().contains(".gcz") ||
|
||||||
ff.getName().toLowerCase().contains(".dol") ||
|
entryName.toLowerCase().contains(".dol") ||
|
||||||
ff.getName().toLowerCase().contains(".elf"))
|
entryName.toLowerCase().contains(".elf"))
|
||||||
fls.add(new GameListItem(getApplicationContext(), ff.getName(),"File Size: "+ff.length(),ff.getAbsolutePath(), true));
|
fls.add(new GameListItem(getApplicationContext(), entryName,"File Size: "+entry.length(),entry.getAbsolutePath(), true));
|
||||||
else if (ff.getName().toLowerCase().contains(".zip") ||
|
else if (entryName.toLowerCase().contains(".zip") ||
|
||||||
ff.getName().toLowerCase().contains(".rar") ||
|
entryName.toLowerCase().contains(".rar") ||
|
||||||
ff.getName().toLowerCase().contains(".7z"))
|
entryName.toLowerCase().contains(".7z"))
|
||||||
fls.add(new GameListItem(getApplicationContext(), ff.getName(),"File Size: "+ff.length(),ff.getAbsolutePath(), false));
|
fls.add(new GameListItem(getApplicationContext(), entryName,"File Size: "+entry.length(),entry.getAbsolutePath(), false));
|
||||||
}
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
catch(Exception e)
|
catch(Exception ignored)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
Collections.sort(dir);
|
|
||||||
Collections.sort(fls);
|
|
||||||
dir.addAll(fls);
|
|
||||||
if (!f.getPath().equalsIgnoreCase("/"))
|
|
||||||
dir.add(0, new GameListItem(getApplicationContext(), "..", "Parent Directory", f.getParent(), true));
|
|
||||||
|
|
||||||
adapter = new FolderBrowserAdapter(this,R.layout.folderbrowser,dir);
|
Collections.sort(dir);
|
||||||
this.setListAdapter(adapter);
|
Collections.sort(fls);
|
||||||
|
dir.addAll(fls);
|
||||||
|
|
||||||
|
// Check for a parent directory to the one we're currently in.
|
||||||
|
if (!currDir.getPath().equalsIgnoreCase("/"))
|
||||||
|
dir.add(0, new GameListItem(getApplicationContext(), "..", "Parent Directory", currDir.getParent(), true));
|
||||||
|
|
||||||
|
adapter = new FolderBrowserAdapter(this,R.layout.folderbrowser,dir);
|
||||||
|
this.setListAdapter(adapter);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
Loading…
Reference in New Issue