diff options
| author | Lioncash <mathew1800@gmail.com> | 2014-07-15 11:31:26 -0400 |
|---|---|---|
| committer | Lioncash <mathew1800@gmail.com> | 2014-07-15 11:31:26 -0400 |
| commit | 35b97ed7320a73758a49b7e1d73b3c576fed3fd8 (patch) | |
| tree | cddb3cd7aed6191b83657dcdffc38bcd5188c166 /Source/Android/src | |
| parent | 8cc11de94a6a8679de50b0f968c6126c0919b960 (diff) | |
| parent | 36821cb1171e02aa914fed1f8968d69162d2a353 (diff) | |
Merge pull request #558 from sigmabeta/game-list-fixes
A few tweaks to implementation of the game list screen.
Diffstat (limited to 'Source/Android/src')
3 files changed, 44 insertions, 32 deletions
diff --git a/Source/Android/src/org/dolphinemu/dolphinemu/gamelist/GameListAdapter.java b/Source/Android/src/org/dolphinemu/dolphinemu/gamelist/GameListAdapter.java index 30796593ca..4ca43f6250 100644 --- a/Source/Android/src/org/dolphinemu/dolphinemu/gamelist/GameListAdapter.java +++ b/Source/Android/src/org/dolphinemu/dolphinemu/gamelist/GameListAdapter.java @@ -7,6 +7,7 @@ package org.dolphinemu.dolphinemu.gamelist; import android.content.Context; +import android.graphics.Bitmap; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; @@ -23,6 +24,9 @@ import org.dolphinemu.dolphinemu.R; */ public final class GameListAdapter extends ArrayAdapter<GameListItem> { + private static final float BYTES_PER_GIB = 1024 * 1024 * 1024; + private static final float BYTES_PER_MIB = 1024 * 1024; + private final Context context; private final int id; @@ -74,8 +78,33 @@ public final class GameListAdapter extends ArrayAdapter<GameListItem> if (item != null) { holder.title.setText(item.getName()); - holder.subtitle.setText(item.getData()); - holder.icon.setImageBitmap(item.getImage()); + + Bitmap icon = item.getImage(); + + if (icon != null) + { + holder.icon.setImageBitmap(icon); + } + else + { + holder.icon.setImageResource(R.drawable.no_banner); + } + + float fileSize = item.getFilesize() / BYTES_PER_GIB; + + String subtitle; + + if (fileSize >= 1.0f) + { + subtitle = String.format(context.getString(R.string.file_size_gib), fileSize); + } + else + { + fileSize = item.getFilesize() / BYTES_PER_MIB; + subtitle = String.format(context.getString(R.string.file_size_mib), fileSize); + } + + holder.subtitle.setText(subtitle); } // Make every other game in the list grey diff --git a/Source/Android/src/org/dolphinemu/dolphinemu/gamelist/GameListFragment.java b/Source/Android/src/org/dolphinemu/dolphinemu/gamelist/GameListFragment.java index 244902af67..60e10a3561 100644 --- a/Source/Android/src/org/dolphinemu/dolphinemu/gamelist/GameListFragment.java +++ b/Source/Android/src/org/dolphinemu/dolphinemu/gamelist/GameListFragment.java @@ -60,7 +60,7 @@ public final class GameListFragment extends ListFragment mGameAdapter.notifyDataSetChanged(); } - private void Fill() + private void fill() { List<GameListItem> fls = new ArrayList<GameListItem>(); String Directories = NativeLibrary.GetConfig("Dolphin.ini", "General", "GCMPathes", "0"); @@ -83,8 +83,9 @@ public final class GameListFragment extends ListFragment if (!entry.isHidden() && !entry.isDirectory()) { if (exts.contains(entryName.toLowerCase().substring(entryName.lastIndexOf('.')))) - fls.add(new GameListItem(getActivity(), entryName, String.format(getString(R.string.file_size), entry.length()), entry.getAbsolutePath())); + fls.add(new GameListItem(getActivity(), entryName, entry.length(), entry.getAbsolutePath())); } + } } catch (Exception ignored) @@ -110,7 +111,7 @@ public final class GameListFragment extends ListFragment mGameAdapter = new GameListAdapter(getActivity(), R.layout.gamelist_list_item); rootView.setAdapter(mGameAdapter); - Fill(); + fill(); return rootView; } diff --git a/Source/Android/src/org/dolphinemu/dolphinemu/gamelist/GameListItem.java b/Source/Android/src/org/dolphinemu/dolphinemu/gamelist/GameListItem.java index 1b72da7b9b..6459eda8d8 100644 --- a/Source/Android/src/org/dolphinemu/dolphinemu/gamelist/GameListItem.java +++ b/Source/Android/src/org/dolphinemu/dolphinemu/gamelist/GameListItem.java @@ -23,7 +23,7 @@ import org.dolphinemu.dolphinemu.NativeLibrary; public final class GameListItem implements Comparable<GameListItem> { private String name; - private final String data; + private long filesize; private final String path; private Bitmap image; @@ -32,38 +32,20 @@ public final class GameListItem implements Comparable<GameListItem> * * @param ctx The current {@link Context} * @param name The name of this GameListItem. - * @param data The subtitle for this GameListItem + * @param filesize The filesize for this GameListItem, in GiB * @param path The file path for the game represented by this GameListItem. */ - public GameListItem(Context ctx, String name, String data, String path) + public GameListItem(Context ctx, String name, long filesize, String path) { this.name = name; - this.data = data; + this.filesize = filesize; this.path = path; File file = new File(path); if (!file.isDirectory() && !path.isEmpty()) { int[] Banner = NativeLibrary.GetBanner(path); - if (Banner[0] == 0) - { - try - { - // Open the no banner icon. - InputStream noBannerPath = ctx.getAssets().open("NoBanner.png"); - - // Decode the bitmap. - image = BitmapFactory.decodeStream(noBannerPath); - - // Scale the bitmap to match other banners. - image = Bitmap.createScaledBitmap(image, 96, 32, false); - } - catch (IOException e) - { - Log.e("GameListItem", e.toString()); - } - } - else + if (Banner[0] != 0) { image = Bitmap.createBitmap(Banner, 96, 32, Bitmap.Config.ARGB_8888); } @@ -83,13 +65,13 @@ public final class GameListItem implements Comparable<GameListItem> } /** - * Gets the subtitle of this GameListItem. + * Gets the filesize of this GameListItem, in GiB. * - * @return the subtitle of this GameListItem. + * @return the filesize of this GameListItem. */ - public String getData() + public long getFilesize() { - return data; + return filesize; } /** |
