Skip to content

Commit

Permalink
add some method to get result
Browse files Browse the repository at this point in the history
  • Loading branch information
jdagnogo committed Nov 28, 2017
1 parent da543b6 commit 85eb52e
Show file tree
Hide file tree
Showing 5 changed files with 61 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@

public class MainActivity extends Activity {
ArrayList<Team> teams = new ArrayList<>();
ArrayList<Match> matches = new ArrayList<>();
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Expand All @@ -20,23 +21,31 @@ protected void onCreate(Bundle savedInstanceState) {
initTeams();
SoccerLeagueView soccerLeagueView = (SoccerLeagueView) findViewById(R.id.soccer);
soccerLeagueView.addTeam(teams);
soccerLeagueView.startLeague();
soccerLeagueView.addMatch(new Match(teams.get(1),teams.get(1),1,1));
soccerLeagueView.addMatch(new Match(teams.get(1),teams.get(0),1,1));
// dont forget to call this method
// a league will start if there more than one team
soccerLeagueView.startLeague("Premiere League");

// add a list of matches
matches.add(new Match(teams.get(1),teams.get(1),1,1));
matches.add(new Match(teams.get(1),teams.get(0),1,1));
soccerLeagueView.addMatch(matches);

// or add a single match
soccerLeagueView.addMatch(new Match(teams.get(1),teams.get(2),1,4));
soccerLeagueView.addMatch(new Match(teams.get(1),teams.get(2),2,4));
soccerLeagueView.addMatch(new Match(teams.get(2),teams.get(1),2,4));
soccerLeagueView.addMatch(new Match(teams.get(2),teams.get(1),2,4));
soccerLeagueView.addMatch(new Match(teams.get(2),teams.get(0),2,4));
}


private void initTeams() {
/*Team arsenal = new Team("Arsenal", "Ars");
Team manchester = new Team("Manchester Utd", "Utd");
Team chelsea = new Team("Chelsea", "CHE");
Team tot = new Team("Totenham", "TOT");
*/
for( int i =0; i<3;i++){
for( int i =0; i<19;i++){
Team team = new Team("team"+i,"t"+i);
teams.add(team);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,16 +17,15 @@
import com.example.jdagnogo.soccerleagueviewlib.models.TeamInLeague;

import java.util.ArrayList;
import java.util.HashMap;

public class SoccerLeagueView extends LinearLayout implements View.OnClickListener {

View rootView;
League league;
private League league;
private Context context;
private RecyclerView recyclerView;
private SoccerLeagueAdapter adapter;
private TextView mj, g, n, p, bm, be, diff, pts;
private TextView mj, g, n, p, bm, be, diff, pts, name;

public SoccerLeagueView(Context context, @Nullable AttributeSet attrs) {
super(context, attrs);
Expand All @@ -37,6 +36,14 @@ public SoccerLeagueView(Context context, @Nullable AttributeSet attrs) {
updateElementsAccordingToAttributs(context, attrs);
}

public League getLeague() {
return league;
}

public void setLeague(League league) {
this.league = league;
}

private void initTextviews() {
mj = (TextView) rootView.findViewById(R.id.mj);
g = (TextView) rootView.findViewById(R.id.g);
Expand All @@ -46,6 +53,8 @@ private void initTextviews() {
be = (TextView) rootView.findViewById(R.id.be);
diff = (TextView) rootView.findViewById(R.id.diff);
pts = (TextView) rootView.findViewById(R.id.pts);
name = (TextView) rootView.findViewById(R.id.name);
name.setText(league.getName());

mj.setOnClickListener(this);
g.setOnClickListener(this);
Expand All @@ -63,19 +72,28 @@ public void addMatch(Match match) {
adapter.setDataSet(list);
}

public void addMatch(ArrayList<Match> matchs) {
for (Match match : matchs) {
league.addMatch(match);
}
ArrayList<TeamInLeague> list = new ArrayList<TeamInLeague>(league.getTeams().values());
adapter.setDataSet(list);
}

private void updateElementsAccordingToAttributs(Context context, AttributeSet attrs) {

}

public void startLeague() {
public void startLeague(String name) {
this.name.setText(name);
league.setName(name);
if (league.getTeams().size() < 2) {
//TODO show toast
} else {
league.startTournament();
initViews();
intiAdapter();
}

}

public void addTeam(Team team) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,20 @@ public class League {
private HashMap<String, Match> matchAlreadyPlayed;
private int numberOfMatchesByTeams;
private boolean isHomeAway = true;
private String name;

public League(boolean isHomeAway) {
teams = new HashMap<>();
matchAlreadyPlayed = new HashMap<>();
this.isHomeAway = isHomeAway;
}

public String getName() {
return name;
}

public void setName(String name) {
this.name = name;
}

public void addMatch(Match match) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package com.example.jdagnogo.soccerleagueviewlib.models;

import java.util.HashMap;

public class TeamInLeague {

int currentPoints = 0;
Expand All @@ -11,23 +13,37 @@ public class TeamInLeague {
int goalScored = 0;
int goalConceded = 0;
int diff = 0;
private HashMap<String, Match> matchAlreadyPlayed;

public TeamInLeague(Team team) {
this.team = team;
currentPoints = 0;
matchAlreadyPlayed = new HashMap<>();

}

public HashMap<String, Match> getMatchAlreadyPlayed() {
return matchAlreadyPlayed;
}

public void setMatchAlreadyPlayed(HashMap<String, Match> matchAlreadyPlayed) {
this.matchAlreadyPlayed = matchAlreadyPlayed;
}

public void updateHomeMatch(Match match) {
updateMatch(match.scoreHome,match.scoreAway);
getMatchAlreadyPlayed().put(match.generateId(match.home, match.away), match);
}
public void updateAwayMatch(Match match) {
updateMatch(match.scoreAway,match.scoreHome);
getMatchAlreadyPlayed().put(match.generateId(match.home, match.away), match);

}
private void updateMatch(int matchScoreHome, int matchScoreAway){
numberOfMatchPlayed++;
setGoalConceded(goalConceded + matchScoreAway);
setGoalScored(goalScored + matchScoreHome);

if (matchScoreHome> matchScoreAway){
numberOfmatchWin ++;
currentPoints = currentPoints+3;
Expand Down
1 change: 1 addition & 0 deletions soccerleagueviewlib/src/main/res/layout/main_view.xml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
android:gravity="center_vertical"
android:elevation="6dp"
android:paddingLeft="@dimen/defaut_space_size"
android:id="@+id/name"
android:text="Nom de la compétition"
android:textColor="@android:color/white"
android:textSize="@dimen/tite_text_size" />
Expand Down

0 comments on commit 85eb52e

Please sign in to comment.