Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Merge pull request #558 from sigmabeta/game-list-fixes
A few tweaks to implementation of the game list screen.
  • Loading branch information
lioncash committed Jul 15, 2014
2 parents 8cc11de + 36821cb commit 35b97ed
Show file tree
Hide file tree
Showing 6 changed files with 49 additions and 32 deletions.
File renamed without changes
2 changes: 2 additions & 0 deletions Source/Android/res/values-ja/strings.xml
Expand Up @@ -41,6 +41,8 @@
<string name="browse_folder">フォルダの参照</string>
<string name="settings">設定</string>
<string name="about">について</string>
<string name="file_size_gib">ファイルサイズ: %.2f GiB</string>
<string name="file_size_mib">ファイルサイズ: %.2f MiB</string>

<!-- Game List Activity - Device Compatibility AlertDialog -->
<string name="device_compat_warning">デバイスの互換性の警告</string>
Expand Down
3 changes: 3 additions & 0 deletions Source/Android/res/values/strings.xml
Expand Up @@ -34,13 +34,16 @@
<string name="parent_directory">Parent Directory</string>
<string name="file_size">File Size: %1$s</string>


<!-- Game List Activity -->
<string name="clear_game_list">Clear game list</string>
<string name="clear_game_list_confirm">Do you want to clear the game list?</string>
<string name="game_list">Game List</string>
<string name="browse_folder">Browse Folder</string>
<string name="settings">Settings</string>
<string name="about">About</string>
<string name="file_size_gib">File Size: %.2f GiB</string>
<string name="file_size_mib">File Size: %.2f MiB</string>

<!-- Game List Activity - Device Compatibility AlertDialog -->
<string name="device_compat_warning">Device Compatibility Warning</string>
Expand Down
Expand Up @@ -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;
Expand All @@ -23,6 +24,9 @@
*/
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;

Expand Down Expand Up @@ -74,8 +78,33 @@ public View getView(int position, View gameView, ViewGroup parent)
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
Expand Down
Expand Up @@ -60,7 +60,7 @@ public void clearGameList()
mGameAdapter.notifyDataSetChanged();
}

private void Fill()
private void fill()
{
List<GameListItem> fls = new ArrayList<GameListItem>();
String Directories = NativeLibrary.GetConfig("Dolphin.ini", "General", "GCMPathes", "0");
Expand All @@ -83,8 +83,9 @@ private void Fill()
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)
Expand All @@ -110,7 +111,7 @@ public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle sa
mGameAdapter = new GameListAdapter(getActivity(), R.layout.gamelist_list_item);
rootView.setAdapter(mGameAdapter);

Fill();
fill();

return rootView;
}
Expand Down
Expand Up @@ -23,7 +23,7 @@
public final class GameListItem implements Comparable<GameListItem>
{
private String name;
private final String data;
private long filesize;
private final String path;
private Bitmap image;

Expand All @@ -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);
}
Expand All @@ -83,13 +65,13 @@ public String getName()
}

/**
* 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;
}

/**
Expand Down

0 comments on commit 35b97ed

Please sign in to comment.