diff --git a/app/src/main/java/gq/cyuubi/lightswitch/FileAdapter.java b/app/src/main/java/gq/cyuubi/lightswitch/FileAdapter.java index e8d87067..ffc88990 100644 --- a/app/src/main/java/gq/cyuubi/lightswitch/FileAdapter.java +++ b/app/src/main/java/gq/cyuubi/lightswitch/FileAdapter.java @@ -1,12 +1,17 @@ package gq.cyuubi.lightswitch; +import android.app.Dialog; import android.content.Context; import android.graphics.Bitmap; +import android.graphics.drawable.ColorDrawable; +import android.util.Log; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; +import android.view.Window; import android.widget.ArrayAdapter; import android.widget.ImageView; +import android.widget.RelativeLayout; import android.widget.TextView; import androidx.annotation.NonNull; @@ -14,13 +19,13 @@ import androidx.annotation.NonNull; import java.io.File; import java.util.ArrayList; -class DataModel { +class GameItem { File file; TitleEntry meta; int index; - public DataModel(File file) { + public GameItem(File file) { this.file = file; index = file.getName().lastIndexOf("."); meta = NroMeta.GetNroTitle(getPath()); @@ -34,10 +39,6 @@ class DataModel { return meta.getName() + " (" + getType() + ")"; } - public String getFileName() { - return file.getName(); - } - public String getAuthor() { return meta.getAuthor(); } @@ -51,33 +52,34 @@ class DataModel { } } -public class FileAdapter extends ArrayAdapter implements View.OnClickListener { - +public class FileAdapter extends ArrayAdapter implements View.OnClickListener { Context mContext; - private ArrayList dataSet; - public FileAdapter(Context context, @NonNull ArrayList data) { + public FileAdapter(Context context, @NonNull ArrayList data) { super(context, R.layout.file_item, data); - this.dataSet = new ArrayList<>(); this.mContext = context; } @Override public void onClick(View v) { - int position = (Integer) v.getTag(); - Object object = getItem(position); - DataModel dataModel = (DataModel) object; + GameItem dataModel = getItem(position); switch (v.getId()) { case R.id.icon: - + Dialog builder = new Dialog(mContext); + builder.requestWindowFeature(Window.FEATURE_NO_TITLE); + builder.getWindow().setBackgroundDrawable(new ColorDrawable(android.graphics.Color.TRANSPARENT)); + ImageView imageView = new ImageView(mContext); + imageView.setImageBitmap(dataModel.getIcon()); + builder.addContentView(imageView, new RelativeLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT)); + builder.show(); break; } } @Override public View getView(int position, View convertView, ViewGroup parent) { - DataModel dataModel = getItem(position); + GameItem dataModel = getItem(position); ViewHolder viewHolder; if (convertView == null) { viewHolder = new ViewHolder(); @@ -93,6 +95,8 @@ public class FileAdapter extends ArrayAdapter implements View.OnClick viewHolder.txtTitle.setText(dataModel.getTitle()); viewHolder.txtSub.setText(dataModel.getAuthor()); viewHolder.icon.setImageBitmap(dataModel.getIcon()); + viewHolder.icon.setOnClickListener(this); + viewHolder.icon.setTag(position); return convertView; } diff --git a/app/src/main/java/gq/cyuubi/lightswitch/MainActivity.java b/app/src/main/java/gq/cyuubi/lightswitch/MainActivity.java index 10bd872d..617f137e 100644 --- a/app/src/main/java/gq/cyuubi/lightswitch/MainActivity.java +++ b/app/src/main/java/gq/cyuubi/lightswitch/MainActivity.java @@ -10,7 +10,6 @@ import android.view.MenuItem; import android.view.View; import android.widget.AdapterView; import android.widget.ListView; -import android.widget.Toast; import androidx.annotation.Nullable; import androidx.appcompat.app.AppCompatActivity; @@ -66,7 +65,7 @@ public class MainActivity extends AppCompatActivity { adapter.clear(); List files = findFile("nro", new File(sharedPreferences.getString("search_location", "")), null); for (File file : files) { - adapter.add(new DataModel(file)); + adapter.add(new GameItem(file)); } } @@ -83,13 +82,13 @@ public class MainActivity extends AppCompatActivity { setSupportActionBar((Toolbar) findViewById(R.id.toolbar)); PreferenceManager.setDefaultValues(this, R.xml.preferences, false); sharedPreferences = PreferenceManager.getDefaultSharedPreferences(this); - adapter = new FileAdapter(this, new ArrayList()); + adapter = new FileAdapter(this, new ArrayList()); ListView game_list = findViewById(R.id.game_list); game_list.setAdapter(adapter); game_list.setOnItemClickListener(new AdapterView.OnItemClickListener() { @Override public void onItemClick(AdapterView parent, View view, int position, long id) { - String path = ((DataModel) parent.getItemAtPosition(position)).getPath(); + String path = ((GameItem) parent.getItemAtPosition(position)).getPath(); notifyUser(getString(R.string.launch_string) + " " + path); loadFile(path); }