From 3f1465196c7ea13a99517ddcdcd56f75d4359f99 Mon Sep 17 00:00:00 2001 From: Eder Bastos Date: Sun, 10 May 2015 10:29:29 -0400 Subject: [PATCH] Add touch feedback to GameGridActivity and AddDirectoryActivity. --- .../dolphinemu/adapters/FileAdapter.java | 50 +++++++++-- .../dolphinemu/adapters/GameAdapter.java | 52 +++++++++++- .../viewholders/GameViewHolder.java | 47 +---------- .../app/src/main/res/layout/card_game.xml | 83 ++++++++----------- .../src/main/res/layout/list_item_file.xml | 21 ++--- .../src/main/res/menu/menu_add_directory.xml | 1 + .../app/src/main/res/values/strings.xml | 3 +- 7 files changed, 145 insertions(+), 112 deletions(-) diff --git a/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/adapters/FileAdapter.java b/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/adapters/FileAdapter.java index 7f4acf6abe..2414883279 100644 --- a/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/adapters/FileAdapter.java +++ b/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/adapters/FileAdapter.java @@ -4,6 +4,7 @@ import android.support.v7.widget.RecyclerView; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; +import android.widget.Toast; import org.dolphinemu.dolphinemu.R; import org.dolphinemu.dolphinemu.model.FileListItem; @@ -102,8 +103,14 @@ public class FileAdapter extends RecyclerView.Adapter implements return mFileList.size(); } + /** + * When a file is clicked, determine if it is a directory; if it is, show that new directory's + * contents. If it is not, end the activity successfully. + * + * @param view + */ @Override - public void onClick(View view) + public void onClick(final View view) { String path = (String) view.getTag(); @@ -111,8 +118,26 @@ public class FileAdapter extends RecyclerView.Adapter implements if (clickedFile.isDirectory()) { - mFileList = generateFileList(clickedFile); - notifyDataSetChanged(); + final ArrayList fileList = generateFileList(clickedFile); + + if (fileList.isEmpty()) + { + Toast.makeText(view.getContext(), R.string.add_directory_empty_folder, Toast.LENGTH_SHORT).show(); + } else + { + // Delay the loading of the new directory to give a little bit of time for UI feedback + // to happen. Hacky, but good enough for now; this is necessary because we're modifying + // the RecyclerView's contents, rather than constructing a new one. + view.getHandler().postDelayed(new Runnable() + { + @Override + public void run() + { + mFileList = fileList; + notifyDataSetChanged(); + } + }, 200); + } } else { // Pass the activity the path of the parent directory of the clicked file. @@ -120,6 +145,12 @@ public class FileAdapter extends RecyclerView.Adapter implements } } + /** + * For a given directory, return a list of Files it contains. + * + * @param directory + * @return + */ private ArrayList generateFileList(File directory) { File[] children = directory.listFiles(); @@ -145,6 +176,12 @@ public class FileAdapter extends RecyclerView.Adapter implements return mPath; } + /** + * Mostly just allows the activity's menu option to kick us up a level in the directory + * structure. + * + * @param path + */ public void setPath(String path) { mPath = path; @@ -154,8 +191,11 @@ public class FileAdapter extends RecyclerView.Adapter implements notifyDataSetChanged(); } - public static interface FileClickListener + /** + * Callback for when the user wants to add the visible directory to the library. + */ + public interface FileClickListener { - public void finishSuccessfully(); + void finishSuccessfully(); } } diff --git a/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/adapters/GameAdapter.java b/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/adapters/GameAdapter.java index bf7bf435b7..883107a410 100644 --- a/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/adapters/GameAdapter.java +++ b/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/adapters/GameAdapter.java @@ -1,5 +1,7 @@ package org.dolphinemu.dolphinemu.adapters; +import android.app.Activity; +import android.content.Intent; import android.graphics.Rect; import android.support.v7.widget.RecyclerView; import android.view.LayoutInflater; @@ -9,12 +11,16 @@ import android.view.ViewGroup; import com.squareup.picasso.Picasso; import org.dolphinemu.dolphinemu.R; +import org.dolphinemu.dolphinemu.dialogs.GameDetailsDialog; +import org.dolphinemu.dolphinemu.emulation.EmulationActivity; import org.dolphinemu.dolphinemu.model.Game; import org.dolphinemu.dolphinemu.viewholders.GameViewHolder; import java.util.ArrayList; -public class GameAdapter extends RecyclerView.Adapter +public class GameAdapter extends RecyclerView.Adapter implements + View.OnClickListener, + View.OnLongClickListener { private ArrayList mGameList; @@ -42,6 +48,9 @@ public class GameAdapter extends RecyclerView.Adapter View gameCard = LayoutInflater.from(parent.getContext()) .inflate(R.layout.card_game, parent, false); + gameCard.setOnClickListener(this); + gameCard.setOnLongClickListener(this); + // Use that view to create a ViewHolder. GameViewHolder holder = new GameViewHolder(gameCard); return holder; @@ -74,7 +83,6 @@ public class GameAdapter extends RecyclerView.Adapter { holder.textDescription.setText(game.getDescription()); } - holder.buttonDetails.setTag(game.getGameId()); holder.path = game.getPath(); holder.screenshotPath = game.getScreenPath(); @@ -92,6 +100,45 @@ public class GameAdapter extends RecyclerView.Adapter return mGameList.size(); } + /** + * Launches the game that was clicked on. + * + * @param view The card representing the game the user wants to play. + */ + @Override + public void onClick(View view) + { + GameViewHolder holder = (GameViewHolder) view.getTag(); + + // Start the emulation activity and send the path of the clicked ISO to it. + Intent intent = new Intent(view.getContext(), EmulationActivity.class); + + intent.putExtra("SelectedGame", holder.path); + + view.getContext().startActivity(intent); + } + + /** + * Launches the details activity for this Game, using an ID stored in the + * details button's Tag. + * + * @param view The Card button that was long-clicked. + */ + @Override + public boolean onLongClick(View view) + { + GameViewHolder holder = (GameViewHolder) view.getTag(); + + // Get the ID of the game we want to look at. + // TODO This should be all we need to pass in, eventually. + // String gameId = (String) holder.gameId; + + Activity activity = (Activity) view.getContext(); + GameDetailsDialog.newInstance(holder.game).show(activity.getFragmentManager(), "game_details"); + + return true; + } + public static class SpacesItemDecoration extends RecyclerView.ItemDecoration { private int space; @@ -108,7 +155,6 @@ public class GameAdapter extends RecyclerView.Adapter outRect.right = space; outRect.bottom = space; outRect.top = space; - } } diff --git a/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/viewholders/GameViewHolder.java b/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/viewholders/GameViewHolder.java index 47acf588de..18e271e0f5 100644 --- a/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/viewholders/GameViewHolder.java +++ b/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/viewholders/GameViewHolder.java @@ -19,7 +19,6 @@ public class GameViewHolder extends RecyclerView.ViewHolder public ImageView imageScreenshot; public TextView textGameTitle; public TextView textDescription; - public ImageButton buttonDetails; // Used to handle onClick(). Set this in onBindViewHolder(). public String path; @@ -30,54 +29,10 @@ public class GameViewHolder extends RecyclerView.ViewHolder { super(itemView); - itemView.setOnClickListener(mCardClickListener); + itemView.setTag(this); imageScreenshot = (ImageView) itemView.findViewById(R.id.image_game_screen); textGameTitle = (TextView) itemView.findViewById(R.id.text_game_title); textDescription = (TextView) itemView.findViewById(R.id.text_game_description); - buttonDetails = (ImageButton) itemView.findViewById(R.id.button_details); - - buttonDetails.setOnClickListener(mDetailsButtonListener); } - - private View.OnClickListener mCardClickListener = new View.OnClickListener() - { - /** - * Launches the game that was clicked on. - * - * @param view The card representing the game the user wants to play. - */ - @Override - public void onClick(View view) - { - // Start the emulation activity and send the path of the clicked ROM to it. - Intent intent = new Intent(view.getContext(), EmulationActivity.class); - - intent.putExtra("SelectedGame", path); - - view.getContext().startActivity(intent); - } - }; - - private View.OnClickListener mDetailsButtonListener = new View.OnClickListener() - { - - /** - * Launches the details activity for this Game, using an ID stored in the - * details button's Tag. - * - * @param view The Details button that was clicked on. - */ - @Override - public void onClick(View view) - { - // Get the ID of the game we want to look at. - // TODO This should be all we need to pass in, eventually. - // String gameId = (String) view.getTag(); - - Activity activity = (Activity) view.getContext(); - GameDetailsDialog.newInstance(game).show(activity.getFragmentManager(), "game_details"); - } - }; - } diff --git a/Source/Android/app/src/main/res/layout/card_game.xml b/Source/Android/app/src/main/res/layout/card_game.xml index e0aa7f01f4..dc8321f8f8 100644 --- a/Source/Android/app/src/main/res/layout/card_game.xml +++ b/Source/Android/app/src/main/res/layout/card_game.xml @@ -2,9 +2,14 @@ + android:layout_width="0dp" + tools:layout_width="224dp" + android:layout_height="256dp" + android:transitionName="card_game" + android:focusable="true" + android:clickable="true" + android:foreground="?android:attr/selectableItemBackground" + > + tools:src="@drawable/placeholder_screenshot" + tools:scaleType="centerCrop"/> - + + - - - - - - diff --git a/Source/Android/app/src/main/res/layout/list_item_file.xml b/Source/Android/app/src/main/res/layout/list_item_file.xml index 3999d0368b..7d54e77d27 100644 --- a/Source/Android/app/src/main/res/layout/list_item_file.xml +++ b/Source/Android/app/src/main/res/layout/list_item_file.xml @@ -1,30 +1,31 @@ + android:layout_height="56dp" + android:background="?android:attr/selectableItemBackground" + android:orientation="horizontal"> + android:background="@drawable/oval_ripple_grey" + android:padding="4dp" + tools:src="@drawable/ic_wii"/> + tools:text="File Name"/> \ No newline at end of file diff --git a/Source/Android/app/src/main/res/menu/menu_add_directory.xml b/Source/Android/app/src/main/res/menu/menu_add_directory.xml index c459811868..667d28a4f0 100644 --- a/Source/Android/app/src/main/res/menu/menu_add_directory.xml +++ b/Source/Android/app/src/main/res/menu/menu_add_directory.xml @@ -1,5 +1,6 @@ + Other - Add Directory to Library + Add Folder to Library Up one level + That folder is empty.