use of se.oort.diplicity.apigen.GameState in project android-diplicity by zond.
the class UserView method getAvatarClickListener.
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) {
if (throwable instanceof HttpException) {
HttpException he = (HttpException) throwable;
if (he.code() == 404) {
return null;
}
}
throw new RuntimeException(throwable);
}
})).then(new Func3<SingleContainer<UserStats>, SingleContainer<GameState>, SingleContainer<Ban>, Object>() {
@Override
public Object call(final SingleContainer<UserStats> userStatsSingleContainer, final SingleContainer<GameState> gameStateSingleContainer, final SingleContainer<Ban> banSingleContainer) {
AlertDialog dialog = new AlertDialog.Builder(retrofitActivity).setView(R.layout.user_dialog).show();
setupUserDialog(retrofitActivity, dialog, userStatsSingleContainer, banSingleContainer);
final CheckBox mutedCheckBox = (CheckBox) dialog.findViewById(R.id.muted);
mutedCheckBox.setVisibility(VISIBLE);
mutedCheckBox.setChecked(gameStateSingleContainer.Properties.Muted != null && gameStateSingleContainer.Properties.Muted.contains(member.Nation));
mutedCheckBox.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
if (isChecked && (gameStateSingleContainer.Properties.Muted == null || !gameStateSingleContainer.Properties.Muted.contains(member.Nation))) {
if (gameStateSingleContainer.Properties.Muted == null) {
gameStateSingleContainer.Properties.Muted = new ArrayList<String>();
}
gameStateSingleContainer.Properties.Muted.add(member.Nation);
} else if (!isChecked && gameStateSingleContainer.Properties.Muted != null && gameStateSingleContainer.Properties.Muted.contains(member.Nation)) {
gameStateSingleContainer.Properties.Muted.remove(member.Nation);
}
retrofitActivity.handleReq(retrofitActivity.gameStateService.GameStateUpdate(gameStateSingleContainer.Properties, game.ID, finalMe.Nation), new Sendable<SingleContainer<GameState>>() {
@Override
public void send(SingleContainer<GameState> gameStateSingleContainer) {
}
}, retrofitActivity.getResources().getString(R.string.updating));
}
});
return null;
}
})).toObservable(), new Sendable<Object>() {
@Override
public void send(Object o) {
}
}, retrofitActivity.getResources().getString(R.string.loading_user_stats));
}
};
}
use of se.oort.diplicity.apigen.GameState in project android-diplicity by zond.
the class GameActivity method showGameStates.
public void showGameStates() {
hideAllExcept(R.id.game_state_view);
if (member == null) {
findViewById(R.id.edit_game_state_button).setVisibility(View.GONE);
}
handleReq(gameStateService.ListGameStates(game.ID), new Sendable<MultiContainer<GameState>>() {
@Override
public void send(MultiContainer<GameState> gameStateMultiContainer) {
GameState myState = null;
TableLayout mutedTable = (TableLayout) findViewById(R.id.muted_table);
mutedTable.removeAllViews();
FloatingActionButton button = ((FloatingActionButton) mutedTable.findViewById(R.id.open_button));
if (button != null) {
mutedTable.removeView(button);
}
final List<String> nations = new ArrayList<String>();
for (Member thisMember : game.Members) {
if (member == null || !thisMember.Nation.equals(member.Nation)) {
nations.add(thisMember.Nation);
}
GameState foundState = null;
for (SingleContainer<GameState> singleContainer : gameStateMultiContainer.Properties) {
if (singleContainer.Properties.Nation.equals(thisMember.Nation)) {
foundState = singleContainer.Properties;
}
}
if (member != null && thisMember.Nation.equals(member.Nation)) {
myState = foundState;
}
TableRow.LayoutParams params = new TableRow.LayoutParams(TableRow.LayoutParams.WRAP_CONTENT, TableRow.LayoutParams.WRAP_CONTENT, 1.0f);
int margin = getResources().getDimensionPixelSize(R.dimen.muted_table_margin);
params.bottomMargin = margin;
params.topMargin = margin;
params.leftMargin = margin;
params.rightMargin = margin;
TableRow tableRow = new TableRow(GameActivity.this);
tableRow.setLayoutParams(params);
LinearLayout playerSide = new LinearLayout(GameActivity.this);
LinearLayout.LayoutParams linearParams = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.WRAP_CONTENT, LinearLayout.LayoutParams.WRAP_CONTENT);
playerSide.setLayoutParams(params);
playerSide.setOrientation(LinearLayout.VERTICAL);
UserView user = new UserView(GameActivity.this, null);
user.setUser(GameActivity.this, thisMember.User, true);
user.setLayoutParams(linearParams);
playerSide.addView(user);
TextView nation = new TextView(GameActivity.this);
nation.setText(thisMember.Nation);
nation.setLayoutParams(linearParams);
playerSide.addView(nation);
tableRow.addView(playerSide);
TextView muteds = new TextView(GameActivity.this);
muteds.setLayoutParams(params);
if (foundState != null && foundState.Muted != null) {
muteds.setText(TextUtils.join(", ", foundState.Muted));
} else {
muteds.setText("");
}
tableRow.addView(muteds);
mutedTable.addView(tableRow);
}
final GameState finalMyState = myState;
if (finalMyState != null) {
((FloatingActionButton) findViewById(R.id.edit_game_state_button)).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
final boolean[] checked = new boolean[nations.size()];
if (finalMyState.Muted != null) {
for (String muted : finalMyState.Muted) {
int pos = nations.indexOf(muted);
if (pos > -1) {
checked[pos] = true;
}
}
}
final AlertDialog dialog = new AlertDialog.Builder(GameActivity.this).setMultiChoiceItems(nations.toArray(new String[] {}), checked, new DialogInterface.OnMultiChoiceClickListener() {
@Override
public void onClick(DialogInterface dialogInterface, int i, boolean b) {
checked[i] = b;
}
}).setTitle(R.string.muted).setPositiveButton(R.string.update, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialogInterface, int j) {
List<String> mutedMembers = new ArrayList<String>();
for (int i = 0; i < checked.length; i++) {
if (checked[i]) {
mutedMembers.add(nations.get(i));
}
}
Collections.sort(mutedMembers);
finalMyState.Muted = mutedMembers;
handleReq(gameStateService.GameStateUpdate(finalMyState, game.ID, finalMyState.Nation), new Sendable<SingleContainer<GameState>>() {
@Override
public void send(SingleContainer<GameState> gameStateSingleContainer) {
showGameStates();
}
}, getResources().getString(R.string.updating_game_state));
}
}).show();
}
});
}
}
}, getResources().getString(R.string.loading_game_settings));
}
Aggregations