11package com .elifut ;
22
3- import com .google .common .collect .FluentIterable ;
4-
53import android .app .ProgressDialog ;
64import android .content .SharedPreferences ;
75import android .util .Log ;
86
97import com .elifut .models .Club ;
108import com .elifut .models .League ;
119import com .elifut .models .Player ;
10+ import com .elifut .models .PlayersKt ;
1211import com .elifut .preferences .JsonPreference ;
1312import com .elifut .preferences .LeagueDetails ;
1413import com .elifut .preferences .UserPreferences ;
1716import com .elifut .services .ElifutService ;
1817import com .elifut .services .ResponseBodyMapper ;
1918import com .elifut .services .ResponseMapper ;
19+ import com .google .common .collect .FluentIterable ;
2020
2121import java .util .List ;
2222
@@ -58,6 +58,7 @@ public Observable<Void> initialize(int nationId, ProgressDialog progressDialog)
5858 .flatMap (Observable ::from )
5959 .flatMap (this ::loadPlayers )
6060 .filter (this ::checkMinimumPlayers )
61+ .filter (this ::checkGoalKeepers )
6162 .doOnNext (i -> progressDialog .setProgress (progressDialog .getProgress () + 2 ))
6263 .toList ()
6364 .map (this ::persistClubs )
@@ -68,9 +69,17 @@ public Observable<Void> initialize(int nationId, ProgressDialog progressDialog)
6869 .map (nothing -> (Void ) null );
6970 }
7071
72+ private boolean checkGoalKeepers (ClubAndPlayers clubAndPlayers ) {
73+ boolean hasNoGKs = PlayersKt .goalkeepers (clubAndPlayers .players ).isEmpty ();
74+ if (hasNoGKs ) {
75+ Log .w (TAG , String .format ("Dropping club %s due to not having at least 1 goalkeeper" ,
76+ clubAndPlayers .club ));
77+ }
78+ return !hasNoGKs ;
79+ }
80+
7181 private List <ClubAndPlayers > persistClubs (List <ClubAndPlayers > clubAndPlayers ) {
72- leagueDetails .initialize (FluentIterable
73- .from (clubAndPlayers )
82+ leagueDetails .initialize (FluentIterable .from (clubAndPlayers )
7483 .transform (cp -> cp .club )
7584 .toList ());
7685 return clubAndPlayers ;
0 commit comments