use of se.oort.diplicity.UserView 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