use of se.oort.diplicity.apigen.Ban 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.Ban in project android-diplicity by zond.
the class MainActivity method onOptionsItemSelected.
@Override
public boolean onOptionsItemSelected(MenuItem item) {
int id = item.getItemId();
if (id == R.id.action_settings) {
Intent i = new Intent(this, PreferenceActivity.class);
startActivity(i);
return true;
} else if (id == R.id.action_error_log) {
AlertDialog dialog = new AlertDialog.Builder(MainActivity.this).setView(R.layout.error_log_dialog).show();
((EditText) dialog.findViewById(R.id.error_log)).setText(App.errorLog.toString());
} else if (id == R.id.action_forum) {
String url = "https://groups.google.com/forum/#!forum/diplicity-talk";
Intent i = new Intent(Intent.ACTION_VIEW);
i.setData(Uri.parse(url));
startActivity(i);
} else if (id == R.id.action_source) {
String url = "https://github.com/zond/android-diplicity";
Intent i = new Intent(Intent.ACTION_VIEW);
i.setData(Uri.parse(url));
startActivity(i);
} else if (id == R.id.action_alarms) {
AlertDialog dialog = new AlertDialog.Builder(MainActivity.this).setView(R.layout.alarms_dialog).show();
Map<String, ?> alarms = Alarm.getAlarmPreferences(this).getAll();
LinearLayout layout = (LinearLayout) dialog.findViewById(R.id.alarms_list);
if (alarms.size() == 0) {
dialog.findViewById(R.id.empty_view).setVisibility(View.VISIBLE);
layout.setVisibility(View.GONE);
} else {
dialog.findViewById(R.id.empty_view).setVisibility(View.GONE);
for (Object json : Alarm.getAlarmPreferences(this).getAll().values()) {
Alarm.Alert alert = Alarm.Alert.fromJSON("" + json);
LayoutInflater inflater = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View row = inflater.inflate(R.layout.alarm_list_row, null);
((TextView) row.findViewById(R.id.desc)).setText(alert.desc);
((TextView) row.findViewById(R.id.at)).setText(alert.alertAt(this).toString());
layout.addView(row);
}
layout.setVisibility(View.VISIBLE);
}
} else if (id == R.id.action_bans) {
handleReq(banService.ListBans(getLoggedInUser().Id), new Sendable<MultiContainer<Ban>>() {
private RelativeLayout.LayoutParams wrapContentParams = new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.WRAP_CONTENT, RelativeLayout.LayoutParams.WRAP_CONTENT);
private void setMargins(RelativeLayout.LayoutParams params) {
int margin = getResources().getDimensionPixelSize(R.dimen.member_table_margin);
params.bottomMargin = margin;
params.topMargin = margin;
params.leftMargin = margin;
params.rightMargin = margin;
}
private void setupView(final AlertDialog dialog, final MultiContainer<Ban> banMultiContainer, final SingleContainer<Ban> ban, View convertView) {
User other = null;
for (User u : ban.Properties.Users) {
if (!u.Id.equals(getLoggedInUser().Id)) {
other = u;
break;
}
}
if (other != null) {
final User finalOther = other;
((UserView) convertView.findViewById(R.id.other_user)).setUser(MainActivity.this, other, true);
if (ban.Properties.OwnerIds.contains(getLoggedInUser().Id)) {
LayoutInflater inflater = (LayoutInflater) MainActivity.this.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
FloatingActionButton button = (FloatingActionButton) inflater.inflate(R.layout.clear_button, null);
setMargins(wrapContentParams);
wrapContentParams.addRule(RelativeLayout.ALIGN_PARENT_RIGHT);
wrapContentParams.addRule(RelativeLayout.ALIGN_PARENT_END);
wrapContentParams.addRule(RelativeLayout.ALIGN_PARENT_TOP);
button.setLayoutParams(wrapContentParams);
button.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
handleReq(banService.BanDelete(getLoggedInUser().Id, finalOther.Id), new Sendable<SingleContainer<Ban>>() {
@Override
public void send(SingleContainer<Ban> banSingleContainer) {
ban.Properties.OwnerIds.remove(getLoggedInUser().Id);
if (ban.Properties.OwnerIds.isEmpty()) {
banMultiContainer.Properties.remove(ban);
}
setupDialog(dialog, banMultiContainer);
}
}, getResources().getString(R.string.updating));
}
});
((RelativeLayout) convertView.findViewById(R.id.ban_list_row_layout)).addView(button);
}
}
}
@Override
public void send(MultiContainer<Ban> banMultiContainer) {
AlertDialog dialog = new AlertDialog.Builder(MainActivity.this).setView(R.layout.bans_dialog).show();
setupDialog(dialog, banMultiContainer);
}
private void setupDialog(AlertDialog dialog, MultiContainer<Ban> banMultiContainer) {
List<SingleContainer<Ban>> asBannerList = new ArrayList<>();
List<SingleContainer<Ban>> asBannedList = new ArrayList<>();
for (SingleContainer<Ban> banSingleContainer : banMultiContainer.Properties) {
if (banSingleContainer.Properties.OwnerIds.contains(getLoggedInUser().Id)) {
asBannerList.add(banSingleContainer);
} else {
asBannedList.add(banSingleContainer);
}
}
ViewGroup parent = (ViewGroup) dialog.findViewById(R.id.bans_dialog_layout);
LinearLayout asBanner = (LinearLayout) dialog.findViewById(R.id.hater_list);
if (asBannerList.isEmpty()) {
dialog.findViewById(R.id.as_banner_no_data).setVisibility(View.VISIBLE);
asBanner.setVisibility(View.GONE);
} else {
dialog.findViewById(R.id.as_banner_no_data).setVisibility(View.GONE);
asBanner.removeAllViews();
for (SingleContainer<Ban> ban : asBannerList) {
View itemView = LayoutInflater.from(MainActivity.this).inflate(R.layout.ban_list_row, parent, false);
asBanner.addView(itemView);
setupView(dialog, banMultiContainer, ban, itemView);
}
}
LinearLayout asBanned = (LinearLayout) dialog.findViewById(R.id.hated_list);
if (asBannedList.isEmpty()) {
dialog.findViewById(R.id.as_banned_no_data).setVisibility(View.VISIBLE);
asBanned.setVisibility(View.GONE);
} else {
dialog.findViewById(R.id.as_banner_no_data).setVisibility(View.GONE);
asBanned.removeAllViews();
for (SingleContainer<Ban> ban : asBannedList) {
View itemView = LayoutInflater.from(MainActivity.this).inflate(R.layout.ban_list_row, parent, false);
asBanned.addView(itemView);
setupView(dialog, banMultiContainer, ban, itemView);
}
}
}
}, getResources().getString(R.string.loading_bans));
}
return super.onOptionsItemSelected(item);
}
use of se.oort.diplicity.apigen.Ban in project android-diplicity by zond.
the class UserView method getAvatarClickListener.
public static OnClickListener getAvatarClickListener(final RetrofitActivity retrofitActivity, final User user) {
return new OnClickListener() {
@Override
public void onClick(View v) {
retrofitActivity.handleReq(JoinObservable.when(JoinObservable.from(retrofitActivity.userStatsService.UserStatsLoad(user.Id)).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 Func2<SingleContainer<UserStats>, SingleContainer<Ban>, Object>() {
@Override
public Object call(SingleContainer<UserStats> userStatsSingleContainer, SingleContainer<Ban> banSingleContainer) {
AlertDialog dialog = new AlertDialog.Builder(retrofitActivity).setView(R.layout.user_dialog).show();
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));
}
};
}
use of se.oort.diplicity.apigen.Ban in project android-diplicity by zond.
the class UserView method setupUserDialog.
private static void setupUserDialog(final RetrofitActivity retrofitActivity, AlertDialog dialog, final SingleContainer<UserStats> userStats, final SingleContainer<Ban> ban) {
((UserStatsTable) dialog.findViewById(R.id.user_stats)).setUserStats(retrofitActivity, userStats.Properties);
((UserView) dialog.findViewById(R.id.user)).setUser(retrofitActivity, userStats.Properties.User, true);
final CheckBox bannedCheckBox = (CheckBox) dialog.findViewById(R.id.banned);
if (userStats.Properties.UserId.equals(retrofitActivity.getLoggedInUser().Id)) {
bannedCheckBox.setVisibility(GONE);
} else {
bannedCheckBox.setVisibility(VISIBLE);
bannedCheckBox.setChecked(ban != null);
bannedCheckBox.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
if (isChecked) {
Ban ban = new Ban();
ban.UserIds = new ArrayList<String>();
ban.UserIds.add(userStats.Properties.UserId);
ban.UserIds.add(retrofitActivity.getLoggedInUser().Id);
retrofitActivity.handleReq(retrofitActivity.banService.BanCreate(ban, retrofitActivity.getLoggedInUser().Id), new Sendable<SingleContainer<Ban>>() {
@Override
public void send(SingleContainer<Ban> banSingleContainer) {
}
}, retrofitActivity.getResources().getString(R.string.updating));
} else {
retrofitActivity.handleReq(retrofitActivity.banService.BanDelete(retrofitActivity.getLoggedInUser().Id, userStats.Properties.UserId), new Sendable<SingleContainer<Ban>>() {
@Override
public void send(SingleContainer<Ban> banSingleContainer) {
}
}, retrofitActivity.getResources().getString(R.string.updating));
}
}
});
}
dialog.findViewById(R.id.muted).setVisibility(GONE);
((Button) dialog.findViewById(R.id.other_finished_game_button)).setOnClickListener(getOtherGamesClickListener(retrofitActivity, userStats.Properties.User, MainActivity.FINISHED));
((Button) dialog.findViewById(R.id.other_staging_game_button)).setOnClickListener(getOtherGamesClickListener(retrofitActivity, userStats.Properties.User, MainActivity.STAGING));
((Button) dialog.findViewById(R.id.other_started_game_button)).setOnClickListener(getOtherGamesClickListener(retrofitActivity, userStats.Properties.User, MainActivity.STARTED));
}
Aggregations