mirror of
https://github.com/libretro/RetroArch
synced 2025-02-06 09:40:06 +00:00
Merge pull request #332 from lioncash/master
[Android] Simplify how ListActivities set their adapters. Also tiny FileWrapper change.
This commit is contained in:
commit
7487c666c8
@ -33,13 +33,14 @@ public final class CoreSelection extends ListActivity {
|
||||
final String cpuInfo = UserPreferences.readCPUInfo();
|
||||
final boolean cpuIsNeon = cpuInfo.contains("neon");
|
||||
|
||||
// Setup the layout
|
||||
setContentView(R.layout.line_list);
|
||||
|
||||
// Setup the list
|
||||
adapter = new IconAdapter<ModuleWrapper>(this, R.layout.line_list_item);
|
||||
ListView list = getListView();
|
||||
list.setAdapter(adapter);
|
||||
setListAdapter(adapter);
|
||||
|
||||
// Set the activity title.
|
||||
setTitle(R.string.select_libretro_core);
|
||||
|
||||
// Populate the list
|
||||
|
@ -6,25 +6,24 @@ import org.retroarch.R;
|
||||
|
||||
import android.graphics.drawable.Drawable;
|
||||
|
||||
public final class FileWrapper implements IconAdapterItem {
|
||||
public final File file;
|
||||
public final boolean parentItem;
|
||||
public final boolean dirSelectItem;
|
||||
|
||||
protected final boolean enabled;
|
||||
|
||||
public final class FileWrapper implements IconAdapterItem, Comparable<FileWrapper> {
|
||||
|
||||
public static final int DIRSELECT = 0;
|
||||
public static final int PARENT = 1;
|
||||
public static final int FILE = 2;
|
||||
|
||||
protected final int typeIndex;
|
||||
|
||||
private final File file;
|
||||
private final boolean parentItem;
|
||||
private final boolean dirSelectItem;
|
||||
private final boolean enabled;
|
||||
private final int typeIndex;
|
||||
|
||||
public FileWrapper(File file, int type, boolean isEnabled) {
|
||||
this.file = file;
|
||||
|
||||
this.parentItem = type == PARENT;
|
||||
this.dirSelectItem = type == DIRSELECT;
|
||||
this.typeIndex = type == FILE ? (FILE + (file.isDirectory() ? 0 : 1)) : type;
|
||||
this.parentItem = (type == PARENT);
|
||||
this.dirSelectItem = (type == DIRSELECT);
|
||||
this.typeIndex = (type == FILE) ? (FILE + (file.isDirectory() ? 0 : 1)) : type;
|
||||
|
||||
this.enabled = parentItem || dirSelectItem || isEnabled;
|
||||
}
|
||||
@ -43,7 +42,7 @@ public final class FileWrapper implements IconAdapterItem {
|
||||
else
|
||||
return file.getName();
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public String getSubText() {
|
||||
return null;
|
||||
@ -63,6 +62,38 @@ public final class FileWrapper implements IconAdapterItem {
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks whether or not the wrapped {@link File} is
|
||||
* the "Parent Directory" item in the file browser.
|
||||
*
|
||||
* @return true if the wrapped {@link File} is the "Parent Directory"
|
||||
* item in the file browser; false otherwise.
|
||||
*/
|
||||
public boolean isParentItem() {
|
||||
return parentItem;
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks whether or not the wrapped {@link File}
|
||||
* is the "use this directory" item.
|
||||
*
|
||||
* @return true if the wrapped {@link File} is the "Use this directory"
|
||||
* item in the file browser; false otherwise.
|
||||
*/
|
||||
public boolean isDirSelectItem() {
|
||||
return dirSelectItem;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the file wrapped by this FileWrapper.
|
||||
*
|
||||
* @return the file wrapped by this FileWrapper.
|
||||
*/
|
||||
public File getFile() {
|
||||
return file;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int compareTo(FileWrapper other) {
|
||||
if (other != null) {
|
||||
// Who says ternary is hard to follow
|
||||
|
@ -24,18 +24,19 @@ public final class HistorySelection extends ListActivity {
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
|
||||
|
||||
// Setup the layout.
|
||||
setContentView(R.layout.line_list);
|
||||
|
||||
// Setup the list
|
||||
adapter = new IconAdapter<HistoryWrapper>(this, R.layout.line_list_item);
|
||||
ListView list = getListView();
|
||||
list.setAdapter(adapter);
|
||||
setListAdapter(adapter);
|
||||
|
||||
// Set activity title.
|
||||
setTitle(R.string.recently_played_games);
|
||||
|
||||
|
||||
File history = new File(getApplicationInfo().dataDir, "retroarch-history.txt");
|
||||
|
||||
|
||||
try {
|
||||
BufferedReader br = new BufferedReader(new InputStreamReader(
|
||||
new FileInputStream(history)));
|
||||
@ -46,14 +47,14 @@ public final class HistorySelection extends ListActivity {
|
||||
String name = br.readLine();
|
||||
if (game == null || core == null || name == null)
|
||||
break;
|
||||
|
||||
|
||||
adapter.add(new HistoryWrapper(game, core, name));
|
||||
}
|
||||
br.close();
|
||||
} catch (IOException ex) {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void onListItemClick(ListView listView, View view, int position, long id) {
|
||||
final HistoryWrapper item = adapter.getItem(position);
|
||||
|
@ -21,8 +21,8 @@ public class DirectoryActivity extends ListActivity {
|
||||
private File listedDirectory;
|
||||
|
||||
public static class BackStackItem implements Parcelable {
|
||||
public String path;
|
||||
public boolean parentIsBack;
|
||||
private final String path;
|
||||
private final boolean parentIsBack;
|
||||
|
||||
public BackStackItem(String path, boolean parentIsBack) {
|
||||
this.path = path;
|
||||
@ -80,8 +80,7 @@ public class DirectoryActivity extends ListActivity {
|
||||
|
||||
// Setup the list
|
||||
adapter = new IconAdapter<FileWrapper>(this, R.layout.line_list_item);
|
||||
ListView list = getListView();
|
||||
list.setAdapter(adapter);
|
||||
setListAdapter(adapter);
|
||||
|
||||
// Load Directory
|
||||
if (savedInstanceState != null) {
|
||||
@ -123,21 +122,20 @@ public class DirectoryActivity extends ListActivity {
|
||||
public void onListItemClick(ListView listView, View aView, int position, long id) {
|
||||
final FileWrapper item = adapter.getItem(position);
|
||||
|
||||
if (item.parentItem && backStack.get(backStack.size() - 1).parentIsBack) {
|
||||
if (item.isParentItem() && backStack.get(backStack.size() - 1).parentIsBack) {
|
||||
backStack.remove(backStack.size() - 1);
|
||||
wrapFiles();
|
||||
return;
|
||||
} else if (item.dirSelectItem) {
|
||||
} else if (item.isDirSelectItem()) {
|
||||
finishWithPath(listedDirectory.getAbsolutePath());
|
||||
return;
|
||||
}
|
||||
|
||||
final File selected = item.parentItem ? listedDirectory.getParentFile()
|
||||
: item.file;
|
||||
final File selected = item.isParentItem() ? listedDirectory.getParentFile() : item.getFile();
|
||||
|
||||
if (selected.isDirectory()) {
|
||||
backStack.add(new BackStackItem(selected.getAbsolutePath(),
|
||||
!item.parentItem));
|
||||
!item.isParentItem()));
|
||||
wrapFiles();
|
||||
} else {
|
||||
String filePath = selected.getAbsolutePath();
|
||||
@ -229,8 +227,8 @@ public class DirectoryActivity extends ListActivity {
|
||||
// Sort items
|
||||
adapter.sort(new Comparator<FileWrapper>() {
|
||||
@Override
|
||||
public int compare(FileWrapper aLeft, FileWrapper aRight) {
|
||||
return aLeft.compareTo(aRight);
|
||||
public int compare(FileWrapper left, FileWrapper right) {
|
||||
return left.compareTo(right);
|
||||
};
|
||||
});
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user