// Path: app/src/main/java/se/oort/diplicity/apigen/Ban.java
// public class Ban implements java.io.Serializable {
//   public java.util.List<String> UserIds;
//   public java.util.List<String> OwnerIds;
//   public java.util.List<User> Users;
// }
// 
// Path: app/src/main/java/se/oort/diplicity/apigen/Game.java
// public class Game implements java.io.Serializable {
//   public String ID;
//   public Boolean Started;
//   public Boolean Closed;
//   public Boolean Finished;
//   public String Desc;
//   public String Variant;
//   public Long PhaseLengthMinutes;
//   public Long NonMovementPhaseLengthMinutes;
//   public Double MaxHated;
//   public Double MaxHater;
//   public Double MinRating;
//   public Double MaxRating;
//   public Double MinReliability;
//   public Double MinQuickness;
//   public Boolean Private;
//   public Boolean NoMerge;
//   public Boolean DisableConferenceChat;
//   public Boolean DisableGroupChat;
//   public Boolean DisablePrivateChat;
//   public Long NationAllocation;
//   public Boolean Anonymous;
//   public Long LastYear;
//   public Long NMembers;
//   public java.util.List<Member> Members;
//   public java.util.Date StartETA;
//   public java.util.List<PhaseMeta> NewestPhaseMeta;
//   public java.util.List<Ban> ActiveBans;
//   public java.util.List<String> FailedRequirements;
//   public Member FirstMember;
//   public java.util.Date CreatedAt;
//   public Ticker CreatedAgo;
//   public java.util.Date StartedAt;
//   public Ticker StartedAgo;
//   public java.util.Date FinishedAt;
//   public Ticker FinishedAgo;
// }
// 
// Path: app/src/main/java/se/oort/diplicity/apigen/GameState.java
// public class GameState implements java.io.Serializable {
//   public String GameID;
//   public String Nation;
//   public java.util.List<String> Muted;
// }
// 
// Path: app/src/main/java/se/oort/diplicity/apigen/Member.java
// public class Member implements java.io.Serializable {
//   public User User;
//   public String Nation;
//   public String GameAlias;
//   public String NationPreferences;
//   public PhaseState NewestPhaseState;
//   public Long UnreadMessages;
// }
// 
// Path: app/src/main/java/se/oort/diplicity/apigen/SingleContainer.java
// public class SingleContainer<T> implements java.io.Serializable {
//   public SingleContainer() {
//   }
//   public T Properties;
//   public java.util.List<Link> Links;
//   public String name;
//   public java.util.List<java.util.List<String>> Desc;
// }
// 
// Path: app/src/main/java/se/oort/diplicity/apigen/User.java
// public class User implements java.io.Serializable {
//   public String Email;
//   public String FamilyName;
//   public String Gender;
//   public String GivenName;
//   public String Hd;
//   public String Id;
//   public String Link;
//   public String Locale;
//   public String Name;
//   public String Picture;
//   public Boolean VerifiedEmail;
//   public java.util.Date ValidUntil;
// }
// 
// Path: app/src/main/java/se/oort/diplicity/apigen/UserStats.java
// public class UserStats implements java.io.Serializable {
//   public String UserId;
//   public Long JoinedGames;
//   public Long StartedGames;
//   public Long FinishedGames;
//   public Long SoloGames;
//   public Long DIASGames;
//   public Long EliminatedGames;
//   public Long DroppedGames;
//   public Long NMRPhases;
//   public Long ActivePhases;
//   public Long ReadyPhases;
//   public Double Reliability;
//   public Double Quickness;
//   public Long OwnedBans;
//   public Long SharedBans;
//   public Double Hated;
//   public Double Hater;
//   public UserStatsNumbers PrivateStats;
//   public Glicko Glicko;
//   public TrueSkill TrueSkill;
//   public User User;
// }


import android.content.Context;
import android.content.Intent;
import android.support.v7.app.AlertDialog;
import android.util.AttributeSet;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.Button;
import android.widget.CheckBox;
import android.widget.CompoundButton;
import android.widget.FrameLayout;
import android.widget.ImageView;
import android.widget.TextView;
import java.util.ArrayList;
import retrofit2.Retrofit;
import retrofit2.adapter.rxjava.HttpException;
import rx.functions.Func1;
import rx.functions.Func2;
import rx.functions.Func3;
import rx.observables.JoinObservable;
import se.oort.diplicity.apigen.Ban;
import se.oort.diplicity.apigen.Game;
import se.oort.diplicity.apigen.GameState;
import se.oort.diplicity.apigen.Member;
import se.oort.diplicity.apigen.SingleContainer;
import se.oort.diplicity.apigen.User;
import se.oort.diplicity.apigen.UserStats;
                                        setupUserDialog(retrofitActivity, dialog, userStatsSingleContainer, banSingleContainer);
                                        return null;
                                    }
                                })).toObservable(),
                        new Sendable<Object>() {
                            @Override
                            public void send(Object o) {}
                        }, retrofitActivity.getResources().getString(R.string.loading_user_stats));
            }
        };
    }

    public static OnClickListener getAvatarClickListener(final RetrofitActivity retrofitActivity, final Game game, final Member member, final User user) {
        if (game == null) {
            return getAvatarClickListener(retrofitActivity, user);
        }
        Member me = retrofitActivity.getLoggedInMember(game);
        if (me == null || me.Nation.equals(member.Nation)) {
            return getAvatarClickListener(retrofitActivity, user);
        }
        final Member finalMe = me;
        return new OnClickListener() {
            @Override
            public void onClick(View v) {
                retrofitActivity.handleReq(
                        JoinObservable.when(JoinObservable
                                .from(retrofitActivity.userStatsService.UserStatsLoad(user.Id))
                                .and(retrofitActivity.gameStateService.GameStateLoad(game.ID, finalMe.Nation))
                                .and(retrofitActivity.banService.BanLoad(retrofitActivity.getLoggedInUser().Id, user.Id).onErrorReturn(new Func1<Throwable, SingleContainer<Ban>>() {
                                    @Override
// Path: app/src/main/java/se/oort/diplicity/apigen/Ban.java
// public class Ban implements java.io.Serializable {
//   public java.util.List<String> UserIds;
//   public java.util.List<String> OwnerIds;
//   public java.util.List<User> Users;
// }
// 
// Path: app/src/main/java/se/oort/diplicity/apigen/Game.java
// public class Game implements java.io.Serializable {
//   public String ID;
//   public Boolean Started;
//   public Boolean Closed;
//   public Boolean Finished;
//   public String Desc;
//   public String Variant;
//   public Long PhaseLengthMinutes;
//   public Long NonMovementPhaseLengthMinutes;
//   public Double MaxHated;
//   public Double MaxHater;
//   public Double MinRating;
//   public Double MaxRating;
//   public Double MinReliability;
//   public Double MinQuickness;
//   public Boolean Private;
//   public Boolean NoMerge;
//   public Boolean DisableConferenceChat;
//   public Boolean DisableGroupChat;
//   public Boolean DisablePrivateChat;
//   public Long NationAllocation;
//   public Boolean Anonymous;
//   public Long LastYear;
//   public Long NMembers;
//   public java.util.List<Member> Members;
//   public java.util.Date StartETA;
//   public java.util.List<PhaseMeta> NewestPhaseMeta;
//   public java.util.List<Ban> ActiveBans;
//   public java.util.List<String> FailedRequirements;
//   public Member FirstMember;
//   public java.util.Date CreatedAt;
//   public Ticker CreatedAgo;
//   public java.util.Date StartedAt;
//   public Ticker StartedAgo;
//   public java.util.Date FinishedAt;
//   public Ticker FinishedAgo;
// }
// 
// Path: app/src/main/java/se/oort/diplicity/apigen/GameState.java
// public class GameState implements java.io.Serializable {
//   public String GameID;
//   public String Nation;
//   public java.util.List<String> Muted;
// }
// 
// Path: app/src/main/java/se/oort/diplicity/apigen/Member.java
// public class Member implements java.io.Serializable {
//   public User User;
//   public String Nation;
//   public String GameAlias;
//   public String NationPreferences;
//   public PhaseState NewestPhaseState;
//   public Long UnreadMessages;
// }
// 
// Path: app/src/main/java/se/oort/diplicity/apigen/SingleContainer.java
// public class SingleContainer<T> implements java.io.Serializable {
//   public SingleContainer() {
//   }
//   public T Properties;
//   public java.util.List<Link> Links;
//   public String name;
//   public java.util.List<java.util.List<String>> Desc;
// }
// 
// Path: app/src/main/java/se/oort/diplicity/apigen/User.java
// public class User implements java.io.Serializable {
//   public String Email;
//   public String FamilyName;
//   public String Gender;
//   public String GivenName;
//   public String Hd;
//   public String Id;
//   public String Link;
//   public String Locale;
//   public String Name;
//   public String Picture;
//   public Boolean VerifiedEmail;
//   public java.util.Date ValidUntil;
// }
// 
// Path: app/src/main/java/se/oort/diplicity/apigen/UserStats.java
// public class UserStats implements java.io.Serializable {
//   public String UserId;
//   public Long JoinedGames;
//   public Long StartedGames;
//   public Long FinishedGames;
//   public Long SoloGames;
//   public Long DIASGames;
//   public Long EliminatedGames;
//   public Long DroppedGames;
//   public Long NMRPhases;
//   public Long ActivePhases;
//   public Long ReadyPhases;
//   public Double Reliability;
//   public Double Quickness;
//   public Long OwnedBans;
//   public Long SharedBans;
//   public Double Hated;
//   public Double Hater;
//   public UserStatsNumbers PrivateStats;
//   public Glicko Glicko;
//   public TrueSkill TrueSkill;
//   public User User;
// }


// Path: app/src/main/java/se/oort/diplicity/UserView.java
import android.content.Context;
import android.content.Intent;
import android.support.v7.app.AlertDialog;
import android.util.AttributeSet;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.Button;
import android.widget.CheckBox;
import android.widget.CompoundButton;
import android.widget.FrameLayout;
import android.widget.ImageView;
import android.widget.TextView;
import java.util.ArrayList;
import retrofit2.Retrofit;
import retrofit2.adapter.rxjava.HttpException;
import rx.functions.Func1;
import rx.functions.Func2;
import rx.functions.Func3;
import rx.observables.JoinObservable;
import se.oort.diplicity.apigen.Ban;
import se.oort.diplicity.apigen.Game;
import se.oort.diplicity.apigen.GameState;
import se.oort.diplicity.apigen.Member;
import se.oort.diplicity.apigen.SingleContainer;
import se.oort.diplicity.apigen.User;
import se.oort.diplicity.apigen.UserStats;

                                        setupUserDialog(retrofitActivity, dialog, userStatsSingleContainer, banSingleContainer);
                                        return null;
                                    }
                                })).toObservable(),
                        new Sendable<Object>() {
                            @Override
                            public void send(Object o) {}
                        }, retrofitActivity.getResources().getString(R.string.loading_user_stats));
            }
        };
    }

    public static OnClickListener getAvatarClickListener(final RetrofitActivity retrofitActivity, final Game game, final Member member, final User user) {
        if (game == null) {
            return getAvatarClickListener(retrofitActivity, user);
        }
        Member me = retrofitActivity.getLoggedInMember(game);
        if (me == null || me.Nation.equals(member.Nation)) {
            return getAvatarClickListener(retrofitActivity, user);
        }
        final Member finalMe = me;
        return new OnClickListener() {
            @Override
            public void onClick(View v) {
                retrofitActivity.handleReq(
                        JoinObservable.when(JoinObservable
                                .from(retrofitActivity.userStatsService.UserStatsLoad(user.Id))
                                .and(retrofitActivity.gameStateService.GameStateLoad(game.ID, finalMe.Nation))
                                .and(retrofitActivity.banService.BanLoad(retrofitActivity.getLoggedInUser().Id, user.Id).onErrorReturn(new Func1<Throwable, SingleContainer<Ban>>() {
                                    @Override
                                    public SingleContainer<Ban> call(Throwable throwable) {