From 19ae4e10db89f3c8ec3c297820b2de7895ef7c71 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thomas=20Barth=C3=A9l=C3=A9my?= Date: Wed, 29 Oct 2014 08:00:10 +0100 Subject: [PATCH] Revert "First attempt to use RecyclerView" This reverts commit 833ffcdaf9f58ffb7fb3b20073b9e441c386bcf1. --- ChaseWhisply/build.gradle | 1 - .../ui/adapter/GameModeViewAdapter.java | 55 +++++++------------ .../ui/fragments/GameModeChooserFragment.java | 29 ++++------ .../fragments/LeaderboardChooserFragment.java | 29 ++++------ .../res/layout/fragment_game_mode_chooser.xml | 48 +++++++++------- .../layout/fragment_leaderboard_chooser.xml | 4 +- 6 files changed, 73 insertions(+), 93 deletions(-) diff --git a/ChaseWhisply/build.gradle b/ChaseWhisply/build.gradle index 5d1c3e91..bc1b428d 100644 --- a/ChaseWhisply/build.gradle +++ b/ChaseWhisply/build.gradle @@ -12,7 +12,6 @@ dependencies { compile 'com.android.support:gridlayout-v7:18.0.0' compile 'com.android.support:support-v4:21.0.0' compile 'com.android.support:cardview-v7:21.0.0' - compile 'com.android.support:recyclerview-v7:21.0.0' compile 'com.nineoldandroids:library:2.4.0' compile project(':BaseGameUtils') } diff --git a/ChaseWhisply/src/main/java/fr/tvbarthel/games/chasewhisply/ui/adapter/GameModeViewAdapter.java b/ChaseWhisply/src/main/java/fr/tvbarthel/games/chasewhisply/ui/adapter/GameModeViewAdapter.java index bb1a3ddf..763e8385 100644 --- a/ChaseWhisply/src/main/java/fr/tvbarthel/games/chasewhisply/ui/adapter/GameModeViewAdapter.java +++ b/ChaseWhisply/src/main/java/fr/tvbarthel/games/chasewhisply/ui/adapter/GameModeViewAdapter.java @@ -1,71 +1,58 @@ package fr.tvbarthel.games.chasewhisply.ui.adapter; -import android.support.v7.widget.RecyclerView; +import android.content.Context; +import android.view.View; import android.view.ViewGroup; +import android.widget.ArrayAdapter; import java.util.ArrayList; +import fr.tvbarthel.games.chasewhisply.R; import fr.tvbarthel.games.chasewhisply.model.PlayerProfile; import fr.tvbarthel.games.chasewhisply.model.mode.GameMode; import fr.tvbarthel.games.chasewhisply.ui.customviews.GameModeView; -public class GameModeViewAdapter extends RecyclerView.Adapter { - +public class GameModeViewAdapter extends ArrayAdapter { private ArrayList mGameModes; private PlayerProfile mPlayerProfile; public Listener mListener; - // Provide a reference to the views for each data item - // Complex data items may need more than one view per item, and - // you provide access to all the views for a data item in a view holder - public static class ViewHolder extends RecyclerView.ViewHolder { - - private GameModeView mGameView; - public ViewHolder(GameModeView gameView) { - super(gameView); - mGameView = gameView; - } - } - - - public GameModeViewAdapter(ArrayList gameModes, PlayerProfile p, Listener l) { + public GameModeViewAdapter(Context context, ArrayList gameModes, PlayerProfile p, Listener l) { + super(context, R.layout.view_game_mode, gameModes); mGameModes = gameModes; mPlayerProfile = p; mListener = l; } - public GameModeViewAdapter(ArrayList gameModes, Listener l) { + public GameModeViewAdapter(Context context, ArrayList gameModes, Listener l) { + super(context, R.layout.view_game_mode, gameModes); mGameModes = gameModes; mPlayerProfile = null; mListener = l; } - @Override - public GameModeViewAdapter.ViewHolder onCreateViewHolder(ViewGroup viewGroup, int i) { - GameModeView raw = new GameModeView(viewGroup.getContext()); - return new ViewHolder(raw); - } + public View getView(int position, View convertView, ViewGroup parent) { + final GameMode currentGameMode = mGameModes.get(position); + GameModeView rowView = (GameModeView) convertView; - @Override - public void onBindViewHolder(GameModeViewAdapter.ViewHolder viewHolder, int i) { - final GameMode currentGameMode = mGameModes.get(i); + if (rowView == null) { + rowView = new GameModeView(getContext()); + } if (mPlayerProfile == null) { - viewHolder.mGameView.setModelForLeaderboard(currentGameMode); + rowView.setModelForLeaderboard(currentGameMode); } else { - viewHolder.mGameView.setModel(currentGameMode); - viewHolder.mGameView.setGameModeEnabled(currentGameMode.isAvailable(mPlayerProfile)); + rowView.setModel(currentGameMode); + rowView.setGameModeEnabled(currentGameMode.isAvailable(mPlayerProfile)); } - viewHolder.mGameView.setGameModeSelectedListener(mListener); - } + rowView.setGameModeSelectedListener(mListener); + + return rowView; - @Override - public int getItemCount() { - return mGameModes.size(); } public interface Listener { diff --git a/ChaseWhisply/src/main/java/fr/tvbarthel/games/chasewhisply/ui/fragments/GameModeChooserFragment.java b/ChaseWhisply/src/main/java/fr/tvbarthel/games/chasewhisply/ui/fragments/GameModeChooserFragment.java index 30e22df3..b7a51452 100644 --- a/ChaseWhisply/src/main/java/fr/tvbarthel/games/chasewhisply/ui/fragments/GameModeChooserFragment.java +++ b/ChaseWhisply/src/main/java/fr/tvbarthel/games/chasewhisply/ui/fragments/GameModeChooserFragment.java @@ -4,11 +4,10 @@ import android.content.Context; import android.os.Bundle; import android.support.v4.app.Fragment; -import android.support.v7.widget.GridLayoutManager; -import android.support.v7.widget.RecyclerView; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; +import android.widget.GridView; import java.util.ArrayList; @@ -26,7 +25,6 @@ public class GameModeChooserFragment extends Fragment implements GameModeViewAda private Listener mListener; private PlayerProfile mPlayerProfile; private GameModeViewAdapter mGameModeViewAdapter; - private ArrayList mGameModes; /** @@ -66,46 +64,41 @@ public void onDetach() { public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { View v = inflater.inflate(R.layout.fragment_game_mode_chooser, container, false); - mGameModes = new ArrayList(); - mGameModeViewAdapter = new GameModeViewAdapter(mGameModes, mPlayerProfile, this); - - RecyclerView recyclerView = ((RecyclerView) v.findViewById(R.id.gamemode_grid_view)); - recyclerView.setHasFixedSize(true); - recyclerView.setLayoutManager(new GridLayoutManager(getActivity(), 1)); - recyclerView.setAdapter(mGameModeViewAdapter); + mGameModeViewAdapter = new GameModeViewAdapter(getActivity(), new ArrayList(), mPlayerProfile, this); + ((GridView) v.findViewById(R.id.gamemode_grid_view)).setAdapter(mGameModeViewAdapter); loadGameMode(); return v; } private void loadGameMode() { - mGameModes.clear(); + mGameModeViewAdapter.clear(); //how to play : learn basics of the game play - mGameModes.add(GameModeFactory.createTutorialGame()); + mGameModeViewAdapter.add(GameModeFactory.createTutorialGame()); //First mission: Scouts First //Sprint mode - mGameModes.add(GameModeFactory.createRemainingTimeGame(1)); + mGameModeViewAdapter.add(GameModeFactory.createRemainingTimeGame(1)); //Second mission: Everything is an illusion //Twenty in a row - mGameModes.add(GameModeFactory.createTwentyInARow(1)); + mGameModeViewAdapter.add(GameModeFactory.createTwentyInARow(1)); //Third mission: Prove your stamina //Marathon mode - mGameModes.add(GameModeFactory.createRemainingTimeGame(3)); + mGameModeViewAdapter.add(GameModeFactory.createRemainingTimeGame(3)); //Fourth mission: Brainteaser //Memorize - mGameModes.add(GameModeFactory.createMemorize(1)); + mGameModeViewAdapter.add(GameModeFactory.createMemorize(1)); //Fifth mission: Death to the king //Death to the king - mGameModes.add(GameModeFactory.createKillTheKingGame(1)); + mGameModeViewAdapter.add(GameModeFactory.createKillTheKingGame(1)); //Sixth mission: The Final Battle - mGameModes.add(GameModeFactory.createSurvivalGame(1)); + mGameModeViewAdapter.add(GameModeFactory.createSurvivalGame(1)); mGameModeViewAdapter.notifyDataSetChanged(); } diff --git a/ChaseWhisply/src/main/java/fr/tvbarthel/games/chasewhisply/ui/fragments/LeaderboardChooserFragment.java b/ChaseWhisply/src/main/java/fr/tvbarthel/games/chasewhisply/ui/fragments/LeaderboardChooserFragment.java index da5bd838..510d8be6 100644 --- a/ChaseWhisply/src/main/java/fr/tvbarthel/games/chasewhisply/ui/fragments/LeaderboardChooserFragment.java +++ b/ChaseWhisply/src/main/java/fr/tvbarthel/games/chasewhisply/ui/fragments/LeaderboardChooserFragment.java @@ -3,11 +3,10 @@ import android.app.Activity; import android.os.Bundle; import android.support.v4.app.Fragment; -import android.support.v7.widget.GridLayoutManager; -import android.support.v7.widget.RecyclerView; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; +import android.widget.GridView; import java.util.ArrayList; @@ -22,7 +21,6 @@ public class LeaderboardChooserFragment extends Fragment implements GameModeView private Listener mListener; private GameModeViewAdapter mGameModeViewAdapter; - private ArrayList mGameModes; public interface Listener { public void onLeaderboardChosen(int leaderboardStringId); @@ -59,13 +57,8 @@ public void onDetach() { public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { View v = inflater.inflate(R.layout.fragment_leaderboard_chooser, container, false); - mGameModes = new ArrayList(); - mGameModeViewAdapter = new GameModeViewAdapter(mGameModes, this); - - RecyclerView recyclerView = ((RecyclerView) v.findViewById(R.id.leaderboard_grid_view)); - recyclerView.setHasFixedSize(true); - recyclerView.setLayoutManager(new GridLayoutManager(getActivity(), 1)); - recyclerView.setAdapter(mGameModeViewAdapter); + mGameModeViewAdapter = new GameModeViewAdapter(getActivity(), new ArrayList(), this); + ((GridView) v.findViewById(R.id.leaderboard_grid_view)).setAdapter(mGameModeViewAdapter); loadGameMode(); @@ -74,33 +67,33 @@ public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle sa private void loadGameMode() { - mGameModes.clear(); + mGameModeViewAdapter.clear(); //Overall Ranking - mGameModes.add(GameModeFactory.createOverallRanking()); + mGameModeViewAdapter.add(GameModeFactory.createOverallRanking()); //First mission: Scouts First //Sprint mode - mGameModes.add(GameModeFactory.createRemainingTimeGame(1)); + mGameModeViewAdapter.add(GameModeFactory.createRemainingTimeGame(1)); //Second mission: Everything is an illusion //Twenty in a row - mGameModes.add(GameModeFactory.createTwentyInARow(1)); + mGameModeViewAdapter.add(GameModeFactory.createTwentyInARow(1)); //Third mission: Prove your stamina //Marathon mode - mGameModes.add(GameModeFactory.createRemainingTimeGame(3)); + mGameModeViewAdapter.add(GameModeFactory.createRemainingTimeGame(3)); //Fourth mission: Brainteaser //Memorize - mGameModes.add(GameModeFactory.createMemorize(1)); + mGameModeViewAdapter.add(GameModeFactory.createMemorize(1)); //Fifth mission: Death to the king //Death to the king - mGameModes.add(GameModeFactory.createKillTheKingGame(1)); + mGameModeViewAdapter.add(GameModeFactory.createKillTheKingGame(1)); //Sixth mission: The Final Battle - mGameModes.add(GameModeFactory.createSurvivalGame(1)); + mGameModeViewAdapter.add(GameModeFactory.createSurvivalGame(1)); mGameModeViewAdapter.notifyDataSetChanged(); } diff --git a/ChaseWhisply/src/main/res/layout/fragment_game_mode_chooser.xml b/ChaseWhisply/src/main/res/layout/fragment_game_mode_chooser.xml index d482ac61..566889e5 100644 --- a/ChaseWhisply/src/main/res/layout/fragment_game_mode_chooser.xml +++ b/ChaseWhisply/src/main/res/layout/fragment_game_mode_chooser.xml @@ -1,36 +1,44 @@ - - + android:layout_height="match_parent" + android:padding="@dimen/default_padding"> + android:id="@+id/textView" + android:layout_gravity="center" + android:layout_marginBottom="@dimen/default_half_vertical_margin" /> - + android:scrollbarStyle="outsideInset" /> + + - + diff --git a/ChaseWhisply/src/main/res/layout/fragment_leaderboard_chooser.xml b/ChaseWhisply/src/main/res/layout/fragment_leaderboard_chooser.xml index 7ca84228..92554e15 100644 --- a/ChaseWhisply/src/main/res/layout/fragment_leaderboard_chooser.xml +++ b/ChaseWhisply/src/main/res/layout/fragment_leaderboard_chooser.xml @@ -16,9 +16,9 @@ android:layout_gravity="center" android:layout_marginBottom="@dimen/default_vertical_margin" /> -