mirror of
https://github.com/love2d/love-android.git
synced 2026-08-12 08:31:04 +02:00
Implement click event to game list.
This commit is contained in:
@@ -1,5 +1,8 @@
|
||||
package org.love2d.android;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.net.Uri;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
@@ -20,15 +23,14 @@ public class GameListAdapter extends RecyclerView.Adapter<GameListAdapter.ViewHo
|
||||
public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
|
||||
View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.row_game, parent, false);
|
||||
ViewHolder holder = new ViewHolder(view);
|
||||
view.setOnClickListener(holder);
|
||||
|
||||
return holder;
|
||||
}
|
||||
|
||||
@Override
|
||||
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
|
||||
@@ -40,10 +42,11 @@ public class GameListAdapter extends RecyclerView.Adapter<GameListAdapter.ViewHo
|
||||
this.data = data;
|
||||
}
|
||||
|
||||
static class ViewHolder extends RecyclerView.ViewHolder {
|
||||
static class ViewHolder extends RecyclerView.ViewHolder implements View.OnClickListener {
|
||||
|
||||
private final TextView name;
|
||||
private final ImageView image;
|
||||
private File file;
|
||||
|
||||
public ViewHolder(View itemView) {
|
||||
super(itemView);
|
||||
@@ -52,12 +55,22 @@ public class GameListAdapter extends RecyclerView.Adapter<GameListAdapter.ViewHo
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user