|
@@ -1,5 +1,8 @@
|
|
|
package org.love2d.android;
|
|
package org.love2d.android;
|
|
|
|
|
|
|
|
|
|
+import android.content.Context;
|
|
|
|
|
+import android.content.Intent;
|
|
|
|
|
+import android.net.Uri;
|
|
|
import android.view.LayoutInflater;
|
|
import android.view.LayoutInflater;
|
|
|
import android.view.View;
|
|
import android.view.View;
|
|
|
import android.view.ViewGroup;
|
|
import android.view.ViewGroup;
|
|
@@ -20,15 +23,14 @@ public class GameListAdapter extends RecyclerView.Adapter<GameListAdapter.ViewHo
|
|
|
public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
|
|
public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
|
|
|
View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.row_game, parent, false);
|
|
View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.row_game, parent, false);
|
|
|
ViewHolder holder = new ViewHolder(view);
|
|
ViewHolder holder = new ViewHolder(view);
|
|
|
|
|
+ view.setOnClickListener(holder);
|
|
|
|
|
|
|
|
return holder;
|
|
return holder;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
@Override
|
|
|
public void onBindViewHolder(ViewHolder holder, int position) {
|
|
public void onBindViewHolder(ViewHolder holder, int position) {
|
|
|
- Data data = this.data[position];
|
|
|
|
|
- holder.setName(data.path.getName());
|
|
|
|
|
- holder.setIsDirectory(data.directory);
|
|
|
|
|
|
|
+ holder.setData(this.data[position]);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
@Override
|
|
@@ -40,10 +42,11 @@ public class GameListAdapter extends RecyclerView.Adapter<GameListAdapter.ViewHo
|
|
|
this.data = data;
|
|
this.data = data;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- static class ViewHolder extends RecyclerView.ViewHolder {
|
|
|
|
|
|
|
+ static class ViewHolder extends RecyclerView.ViewHolder implements View.OnClickListener {
|
|
|
|
|
|
|
|
private final TextView name;
|
|
private final TextView name;
|
|
|
private final ImageView image;
|
|
private final ImageView image;
|
|
|
|
|
+ private File file;
|
|
|
|
|
|
|
|
public ViewHolder(View itemView) {
|
|
public ViewHolder(View itemView) {
|
|
|
super(itemView);
|
|
super(itemView);
|
|
@@ -52,12 +55,22 @@ public class GameListAdapter extends RecyclerView.Adapter<GameListAdapter.ViewHo
|
|
|
image = itemView.findViewById(R.id.imageView);
|
|
image = itemView.findViewById(R.id.imageView);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- public void setName(String name) {
|
|
|
|
|
- this.name.setText(name);
|
|
|
|
|
|
|
+ public void setData(Data data) {
|
|
|
|
|
+ name.setText(data.path.getName());
|
|
|
|
|
+ image.setImageResource(data.directory ? R.drawable.ic_baseline_folder_32 : R.drawable.ic_baseline_insert_drive_file_32);
|
|
|
|
|
+ file = data.path;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- public void setIsDirectory(boolean directory) {
|
|
|
|
|
- this.image.setImageResource(directory ? R.drawable.ic_baseline_folder_32 : R.drawable.ic_baseline_insert_drive_file_32);
|
|
|
|
|
|
|
+ @Override
|
|
|
|
|
+ public void onClick(View v) {
|
|
|
|
|
+ if (file == null) {
|
|
|
|
|
+ return;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ Context context = v.getContext();
|
|
|
|
|
+ Intent intent = new Intent(context, GameActivity.class);
|
|
|
|
|
+ intent.setData(Uri.fromFile(file));
|
|
|
|
|
+ context.startActivity(intent);
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|