Skip to content

Commit

Permalink
Revert "First attempt to use RecyclerView"
Browse files Browse the repository at this point in the history
This reverts commit 833ffcd.
  • Loading branch information
tbarthel-fr committed Oct 29, 2014
1 parent 833ffcd commit 19ae4e1
Show file tree
Hide file tree
Showing 6 changed files with 73 additions and 93 deletions.
1 change: 0 additions & 1 deletion ChaseWhisply/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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')
}
Expand Down
Original file line number Diff line number Diff line change
@@ -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<GameModeViewAdapter.ViewHolder> {

public class GameModeViewAdapter extends ArrayAdapter<GameMode> {

private ArrayList<GameMode> 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<GameMode> gameModes, PlayerProfile p, Listener l) {
public GameModeViewAdapter(Context context, ArrayList<GameMode> gameModes, PlayerProfile p, Listener l) {
super(context, R.layout.view_game_mode, gameModes);
mGameModes = gameModes;
mPlayerProfile = p;
mListener = l;
}

public GameModeViewAdapter(ArrayList<GameMode> gameModes, Listener l) {
public GameModeViewAdapter(Context context, ArrayList<GameMode> 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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -26,7 +25,6 @@ public class GameModeChooserFragment extends Fragment implements GameModeViewAda
private Listener mListener;
private PlayerProfile mPlayerProfile;
private GameModeViewAdapter mGameModeViewAdapter;
private ArrayList<GameMode> mGameModes;


/**
Expand Down Expand Up @@ -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<GameMode>();
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<GameMode>(), 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();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -22,7 +21,6 @@ public class LeaderboardChooserFragment extends Fragment implements GameModeView

private Listener mListener;
private GameModeViewAdapter mGameModeViewAdapter;
private ArrayList<GameMode> mGameModes;

public interface Listener {
public void onLeaderboardChosen(int leaderboardStringId);
Expand Down Expand Up @@ -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<GameMode>();
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<GameMode>(), this);
((GridView) v.findViewById(R.id.leaderboard_grid_view)).setAdapter(mGameModeViewAdapter);

loadGameMode();

Expand All @@ -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();
}
Expand Down
48 changes: 28 additions & 20 deletions ChaseWhisply/src/main/res/layout/fragment_game_mode_chooser.xml
Original file line number Diff line number Diff line change
@@ -1,36 +1,44 @@
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">

android:layout_height="match_parent"
android:padding="@dimen/default_padding">

<TextView
android:layout_width="match_parent"
android:layout_height="100dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceLarge"
android:textColor="@color/text_view_grey"
android:gravity="center"
android:layout_gravity="top"
android:textColor="@color/holo_dark_green"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:text="@string/level_chooser"
android:padding="@dimen/card_content_padding"
android:paddingBottom="30dp" />
android:id="@+id/textView"
android:layout_gravity="center"
android:layout_marginBottom="@dimen/default_half_vertical_margin" />

<android.support.v7.widget.RecyclerView
android:scrollbars="vertical"
<GridView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_height="wrap_content"
android:id="@+id/gamemode_grid_view"
android:paddingLeft="@dimen/default_padding"
android:paddingRight="@dimen/default_padding"
android:paddingBottom="@dimen/default_padding"
android:paddingTop="100dp"
android:layout_gravity="center"
android:columnWidth="@dimen/game_mode_width"
android:numColumns="auto_fit"
android:layout_above="@+id/fragment_game_mode_chooser_remember"
android:layout_below="@+id/textView"
android:verticalSpacing="@dimen/grid_view_spacing"
android:horizontalSpacing="@dimen/grid_view_spacing"
android:stretchMode="columnWidth"
android:scrollbarStyle="outsideOverlay"
android:clipToPadding="false" />
android:scrollbarStyle="outsideInset" />

<TextView
android:id="@+id/fragment_game_mode_chooser_remember"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:background="@drawable/card_shadow_base"
android:layout_marginTop="@dimen/default_half_vertical_margin"
android:padding="@dimen/half_padding"
android:text="@string/fragment_game_mode_chooser_remember"
android:textColor="@color/text_view_grey" />

</FrameLayout>
</RelativeLayout>
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@
android:layout_gravity="center"
android:layout_marginBottom="@dimen/default_vertical_margin" />

<android.support.v7.widget.RecyclerView
<GridView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_height="wrap_content"
android:id="@+id/leaderboard_grid_view"
android:layout_gravity="center"
android:columnWidth="@dimen/leaderboard_mode_width"
Expand Down

0 comments on commit 19ae4e1

Please sign in to comment.