mirror of
https://github.com/libretro/Play-.git
synced 2025-03-05 17:57:25 +00:00
Android: move GamesAdapter class to own file
This commit is contained in:
parent
fd92504f75
commit
6e4f2b4e8c
@ -0,0 +1,116 @@
|
||||
package com.virtualapplications.play;
|
||||
|
||||
import android.content.Context;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.ArrayAdapter;
|
||||
import android.widget.ImageView;
|
||||
import android.widget.TextView;
|
||||
|
||||
import com.virtualapplications.play.database.GameInfo;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import static com.virtualapplications.play.MainActivity.launchGame;
|
||||
|
||||
class GamesAdapter extends ArrayAdapter<GameInfoStruct> {
|
||||
|
||||
private final int layoutid;
|
||||
private List<GameInfoStruct> games;
|
||||
private GameInfo gameInfo;
|
||||
|
||||
public GamesAdapter(Context context, int ResourceId, List<GameInfoStruct> images, GameInfo gameInfo) {
|
||||
super(context, ResourceId, images);
|
||||
this.games = images;
|
||||
this.layoutid = ResourceId;
|
||||
this.gameInfo = gameInfo;
|
||||
}
|
||||
|
||||
public int getCount() {
|
||||
//return mThumbIds.length;
|
||||
return games.size();
|
||||
}
|
||||
|
||||
public GameInfoStruct getItem(int position) {
|
||||
return games.get(position);
|
||||
}
|
||||
|
||||
public long getItemId(int position) {
|
||||
return position;
|
||||
}
|
||||
|
||||
@Override
|
||||
public View getView(int position, View convertView, ViewGroup parent) {
|
||||
View v = convertView;
|
||||
if (v == null) {
|
||||
LayoutInflater vi = (LayoutInflater) this.getContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
|
||||
v = vi.inflate(layoutid, null);
|
||||
}
|
||||
else
|
||||
{
|
||||
((TextView) v.findViewById(R.id.game_text)).setText("");
|
||||
((TextView) v.findViewById(R.id.game_text)).setVisibility(View.VISIBLE);
|
||||
ImageView preview = (ImageView) v.findViewById(R.id.game_icon);
|
||||
preview.setImageResource(R.drawable.boxart);
|
||||
|
||||
}
|
||||
|
||||
((TextView) v.findViewById(R.id.currentPosition)).setText(String.valueOf(position));
|
||||
|
||||
final GameInfoStruct game = games.get(position);
|
||||
if (game != null) {
|
||||
createListItem(game, v, position);
|
||||
}
|
||||
return v;
|
||||
}
|
||||
|
||||
private View createListItem(final GameInfoStruct game, final View childview, int pos) {
|
||||
((TextView) childview.findViewById(R.id.game_text)).setText(game.getTitleName());
|
||||
//If user has set values, then read them, if not read from database
|
||||
if (!game.isDescriptionEmptyNull() && game.getFrontLink() != null && !game.getFrontLink().equals("")) {
|
||||
childview.findViewById(R.id.childview).setOnLongClickListener(
|
||||
gameInfo.configureLongClick(game));
|
||||
|
||||
if (!game.getFrontLink().equals("404")) {
|
||||
gameInfo.setCoverImage(game.getGameID(), childview, game.getFrontLink(), pos);
|
||||
} else {
|
||||
ImageView preview = (ImageView) childview.findViewById(R.id.game_icon);
|
||||
preview.setImageResource(R.drawable.boxart);
|
||||
}
|
||||
} else if (VirtualMachineManager.IsLoadableExecutableFileName(game.getFile().getName())) {
|
||||
ImageView preview = (ImageView) childview.findViewById(R.id.game_icon);
|
||||
preview.setImageResource(R.drawable.boxart);
|
||||
childview.findViewById(R.id.childview).setOnLongClickListener(null);
|
||||
} else {
|
||||
childview.findViewById(R.id.childview).setOnLongClickListener(null);
|
||||
// passing game, as to pass and use (if) any user defined values
|
||||
final GameInfoStruct gameStats = gameInfo.getGameInfo(game.getFile(), childview, game, pos);
|
||||
|
||||
if (gameStats != null) {
|
||||
games.set(pos, gameStats);
|
||||
childview.findViewById(R.id.childview).setOnLongClickListener(
|
||||
gameInfo.configureLongClick(gameStats));
|
||||
|
||||
if (gameStats.getFrontLink() != null && !gameStats.getFrontLink().equals("404")) {
|
||||
gameInfo.setCoverImage(gameStats.getGameID(), childview, gameStats.getFrontLink(), pos);
|
||||
}
|
||||
} else {
|
||||
ImageView preview = (ImageView) childview.findViewById(R.id.game_icon);
|
||||
preview.setImageResource(R.drawable.boxart);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
childview.findViewById(R.id.childview).setOnClickListener(new View.OnClickListener() {
|
||||
public void onClick(View view) {
|
||||
launchGame(game, getContext());
|
||||
return;
|
||||
}
|
||||
});
|
||||
return childview;
|
||||
|
||||
}
|
||||
|
||||
}
|
@ -38,7 +38,7 @@ public class MainActivity extends AppCompatActivity implements NavigationDrawerF
|
||||
{
|
||||
static Activity mActivity;
|
||||
private int currentOrientation;
|
||||
private GameInfo gameInfo;
|
||||
private static GameInfo gameInfo;
|
||||
protected NavigationDrawerFragment mNavigationDrawerFragment;
|
||||
|
||||
private List<GameInfoStruct> currentGames = new ArrayList<>();
|
||||
@ -168,9 +168,9 @@ public class MainActivity extends AppCompatActivity implements NavigationDrawerF
|
||||
));
|
||||
}
|
||||
|
||||
private void displaySimpleMessage(String title, String message)
|
||||
private static void displaySimpleMessage(String title, String message, Context context)
|
||||
{
|
||||
AlertDialog.Builder builder = new AlertDialog.Builder(this);
|
||||
AlertDialog.Builder builder = new AlertDialog.Builder(context);
|
||||
|
||||
builder.setTitle(title);
|
||||
builder.setMessage(message);
|
||||
@ -188,9 +188,9 @@ public class MainActivity extends AppCompatActivity implements NavigationDrawerF
|
||||
dialog.show();
|
||||
}
|
||||
|
||||
private void displayGameNotFound(final GameInfoStruct game)
|
||||
private static void displayGameNotFound(final GameInfoStruct game, final Context context)
|
||||
{
|
||||
AlertDialog.Builder builder = new AlertDialog.Builder(this);
|
||||
AlertDialog.Builder builder = new AlertDialog.Builder(context);
|
||||
|
||||
builder.setTitle(R.string.not_found);
|
||||
builder.setMessage(R.string.game_unavailable);
|
||||
@ -199,7 +199,7 @@ public class MainActivity extends AppCompatActivity implements NavigationDrawerF
|
||||
new DialogInterface.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(DialogInterface dialog, int id) {
|
||||
game.removeIndex(getBaseContext());
|
||||
game.removeIndex(context);
|
||||
prepareFileListView(false);
|
||||
}
|
||||
}
|
||||
@ -247,7 +247,7 @@ public class MainActivity extends AppCompatActivity implements NavigationDrawerF
|
||||
String timestamp = buildDateString.substring(11, buildDateString.length()).startsWith("0:")
|
||||
? buildDateString.replace("0:", "12:") : buildDateString;
|
||||
String aboutMessage = String.format("Build Date: %s", timestamp);
|
||||
displaySimpleMessage("About Play!", aboutMessage);
|
||||
displaySimpleMessage("About Play!", aboutMessage, this);
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -411,7 +411,7 @@ public class MainActivity extends AppCompatActivity implements NavigationDrawerF
|
||||
gameGrid.setNumColumns(1);
|
||||
gameGrid.setAdapter(adapter);
|
||||
} else {
|
||||
GamesAdapter adapter = new GamesAdapter(this, R.layout.game_list_item, images);
|
||||
GamesAdapter adapter = new GamesAdapter(this, R.layout.game_list_item, images, gameInfo);
|
||||
/*
|
||||
-1 = autofit
|
||||
*/
|
||||
@ -424,115 +424,16 @@ public class MainActivity extends AppCompatActivity implements NavigationDrawerF
|
||||
}
|
||||
}
|
||||
|
||||
public class GamesAdapter extends ArrayAdapter<GameInfoStruct> {
|
||||
|
||||
private final int layoutid;
|
||||
private List<GameInfoStruct> games;
|
||||
|
||||
public GamesAdapter(Context context, int ResourceId, List<GameInfoStruct> images) {
|
||||
super(context, ResourceId, images);
|
||||
this.games = images;
|
||||
this.layoutid = ResourceId;
|
||||
}
|
||||
|
||||
public int getCount() {
|
||||
//return mThumbIds.length;
|
||||
return games.size();
|
||||
}
|
||||
|
||||
public GameInfoStruct getItem(int position) {
|
||||
return games.get(position);
|
||||
}
|
||||
|
||||
public long getItemId(int position) {
|
||||
return position;
|
||||
}
|
||||
|
||||
@Override
|
||||
public View getView(int position, View convertView, ViewGroup parent) {
|
||||
View v = convertView;
|
||||
if (v == null) {
|
||||
LayoutInflater vi = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE);
|
||||
v = vi.inflate(layoutid, null);
|
||||
}
|
||||
else
|
||||
{
|
||||
((TextView) v.findViewById(R.id.game_text)).setText("");
|
||||
((TextView) v.findViewById(R.id.game_text)).setVisibility(View.VISIBLE);
|
||||
ImageView preview = (ImageView) v.findViewById(R.id.game_icon);
|
||||
preview.setImageResource(R.drawable.boxart);
|
||||
|
||||
}
|
||||
|
||||
((TextView) v.findViewById(R.id.currentPosition)).setText(String.valueOf(position));
|
||||
|
||||
final GameInfoStruct game = games.get(position);
|
||||
if (game != null) {
|
||||
createListItem(game, v, position);
|
||||
}
|
||||
return v;
|
||||
}
|
||||
|
||||
private View createListItem(final GameInfoStruct game, final View childview, int pos) {
|
||||
((TextView) childview.findViewById(R.id.game_text)).setText(game.getTitleName());
|
||||
//If user has set values, then read them, if not read from database
|
||||
if (!game.isDescriptionEmptyNull() && game.getFrontLink() != null && !game.getFrontLink().equals("")) {
|
||||
childview.findViewById(R.id.childview).setOnLongClickListener(
|
||||
gameInfo.configureLongClick(game));
|
||||
|
||||
if (!game.getFrontLink().equals("404")) {
|
||||
gameInfo.setCoverImage(game.getGameID(), childview, game.getFrontLink(), pos);
|
||||
} else {
|
||||
ImageView preview = (ImageView) childview.findViewById(R.id.game_icon);
|
||||
preview.setImageResource(R.drawable.boxart);
|
||||
}
|
||||
} else if (VirtualMachineManager.IsLoadableExecutableFileName(game.getFile().getName())) {
|
||||
ImageView preview = (ImageView) childview.findViewById(R.id.game_icon);
|
||||
preview.setImageResource(R.drawable.boxart);
|
||||
childview.findViewById(R.id.childview).setOnLongClickListener(null);
|
||||
} else {
|
||||
childview.findViewById(R.id.childview).setOnLongClickListener(null);
|
||||
// passing game, as to pass and use (if) any user defined values
|
||||
final GameInfoStruct gameStats = gameInfo.getGameInfo(game.getFile(), childview, game, pos);
|
||||
|
||||
if (gameStats != null) {
|
||||
games.set(pos, gameStats);
|
||||
childview.findViewById(R.id.childview).setOnLongClickListener(
|
||||
gameInfo.configureLongClick(gameStats));
|
||||
|
||||
if (gameStats.getFrontLink() != null && !gameStats.getFrontLink().equals("404")) {
|
||||
gameInfo.setCoverImage(gameStats.getGameID(), childview, gameStats.getFrontLink(), pos);
|
||||
}
|
||||
} else {
|
||||
ImageView preview = (ImageView) childview.findViewById(R.id.game_icon);
|
||||
preview.setImageResource(R.drawable.boxart);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
childview.findViewById(R.id.childview).setOnClickListener(new OnClickListener() {
|
||||
public void onClick(View view) {
|
||||
launchGame(game);
|
||||
return;
|
||||
}
|
||||
});
|
||||
return childview;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public void launchGame(GameInfoStruct game) {
|
||||
public static void launchGame(GameInfoStruct game, Context context) {
|
||||
if (game.getFile().exists()){
|
||||
game.setlastplayed(mActivity);
|
||||
game.setlastplayed(context);
|
||||
try {
|
||||
VirtualMachineManager.launchDisk(this, game.getFile());
|
||||
VirtualMachineManager.launchDisk(context, game.getFile());
|
||||
} catch (Exception e) {
|
||||
displaySimpleMessage("Error", e.getMessage());
|
||||
displaySimpleMessage("Error", e.getMessage(), context);
|
||||
}
|
||||
} else {
|
||||
((MainActivity) mActivity).displayGameNotFound(game);
|
||||
displayGameNotFound(game, context);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -34,6 +34,8 @@ import com.virtualapplications.play.MainActivity;
|
||||
import com.virtualapplications.play.NativeInterop;
|
||||
import com.virtualapplications.play.database.SqliteHelper.Games;
|
||||
|
||||
import static com.virtualapplications.play.MainActivity.launchGame;
|
||||
|
||||
public class GameInfo {
|
||||
|
||||
private Context mContext;
|
||||
@ -278,7 +280,7 @@ public class GameInfo {
|
||||
new DialogInterface.OnClickListener() {
|
||||
public void onClick(DialogInterface dialog, int which) {
|
||||
dialog.dismiss();
|
||||
((MainActivity)mContext).launchGame(gameFile);
|
||||
launchGame(gameFile, mContext);
|
||||
return;
|
||||
}
|
||||
});
|
||||
|
Loading…
x
Reference in New Issue
Block a user