Skip to content

Commit

Permalink
Added content to the user stats listings.
Browse files Browse the repository at this point in the history
  • Loading branch information
zond committed Jan 2, 2017
1 parent 0e75d1d commit c6a01a3
Show file tree
Hide file tree
Showing 6 changed files with 184 additions and 5 deletions.
31 changes: 31 additions & 0 deletions app/src/main/java/se/oort/diplicity/MainActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -390,6 +390,12 @@ public void send(String s) {
case 1: // Users
switch (child) {
case 0: // Top rated
userStatsAdapter.setEmitter(new UserStatsAdapter.StatsEmitter() {
@Override
public String emit(UserStats stats) {
return MainActivity.this.toString(stats.Glicko.PracticalRating);
}
});
loadMoreProcContainer.set(0, new Sendable<String>() {
@Override
public void send(String s) {
Expand All @@ -399,6 +405,12 @@ public void send(String s) {
displayItems(userStatsService.ListTopRatedPlayers(null, null), navigationChildGroups.get(root).get(child).get("CHILD_NAME"), navigationRootGroups.get(root).get("ROOT_NAME").toLowerCase(), userStatsAdapter);
break;
case 1: // Top reliable
userStatsAdapter.setEmitter(new UserStatsAdapter.StatsEmitter() {
@Override
public String emit(UserStats stats) {
return MainActivity.this.toString(stats.Reliability);
}
});
loadMoreProcContainer.set(0, new Sendable<String>() {
@Override
public void send(String s) {
Expand All @@ -408,6 +420,12 @@ public void send(String s) {
displayItems(userStatsService.ListTopReliablePlayers(null, null), navigationChildGroups.get(root).get(child).get("CHILD_NAME"), navigationRootGroups.get(root).get("ROOT_NAME").toLowerCase(), userStatsAdapter);
break;
case 2: // Top quick
userStatsAdapter.setEmitter(new UserStatsAdapter.StatsEmitter() {
@Override
public String emit(UserStats stats) {
return MainActivity.this.toString(stats.Quickness);
}
});
loadMoreProcContainer.set(0, new Sendable<String>() {
@Override
public void send(String s) {
Expand All @@ -417,6 +435,12 @@ public void send(String s) {
displayItems(userStatsService.ListTopQuickPlayers(null, null), navigationChildGroups.get(root).get(child).get("CHILD_NAME"), navigationRootGroups.get(root).get("ROOT_NAME").toLowerCase(), userStatsAdapter);
break;
case 3: // Top hated
userStatsAdapter.setEmitter(new UserStatsAdapter.StatsEmitter() {
@Override
public String emit(UserStats stats) {
return MainActivity.this.toString(stats.Hated);
}
});
loadMoreProcContainer.set(0, new Sendable<String>() {
@Override
public void send(String s) {
Expand All @@ -426,6 +450,12 @@ public void send(String s) {
displayItems(userStatsService.ListTopHatedPlayers(null, null), navigationChildGroups.get(root).get(child).get("CHILD_NAME"), navigationRootGroups.get(root).get("ROOT_NAME").toLowerCase(), userStatsAdapter);
break;
case 4: // Top hater
userStatsAdapter.setEmitter(new UserStatsAdapter.StatsEmitter() {
@Override
public String emit(UserStats stats) {
return MainActivity.this.toString(stats.Hater);
}
});
loadMoreProcContainer.set(0, new Sendable<String>() {
@Override
public void send(String s) {
Expand Down Expand Up @@ -480,6 +510,7 @@ public void send(MultiContainer<T> container) {
private <T> void displayItems(Observable<MultiContainer<T>> call, String what, String typ, RecycleAdapter<SingleContainer<T>,?> adapter) {
adapter.clear();
gamesAdapter.clearExpanded();
userStatsAdapter.clearExpanded();
contentList.setAdapter(adapter);
scrollListener.resetState();
appendItems(call, what, typ, adapter);
Expand Down
47 changes: 44 additions & 3 deletions app/src/main/java/se/oort/diplicity/UserStatsAdapter.java
Original file line number Diff line number Diff line change
@@ -1,38 +1,79 @@
package se.oort.diplicity;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import java.util.HashSet;
import java.util.List;
import java.util.Set;

import se.oort.diplicity.apigen.SingleContainer;
import se.oort.diplicity.apigen.UserStats;

public class UserStatsAdapter extends RecycleAdapter<SingleContainer<UserStats>, UserStatsAdapter.ViewHolder> {
private RetrofitActivity retrofitActivity;
private Set<Integer> expandedItems = new HashSet<>();
private StatsEmitter emitter = null;
public class ViewHolder extends RecycleAdapter<SingleContainer<UserStats>, UserStatsAdapter.ViewHolder>.ViewHolder {
public UserView userView;
UserView userView;
TextView sortLabel;
UserStatsTable expanded;

View.OnClickListener delegateClickListener;
public ViewHolder(View view) {
super(view);
userView = (UserView) view.findViewById(R.id.user);
sortLabel = (TextView) view.findViewById(R.id.sort_label);
expanded = (UserStatsTable) view.findViewById(R.id.expanded);
}
@Override
public void bind(SingleContainer<UserStats> user, int pos) {
userView.setUser(retrofitActivity, user.Properties.User);
expanded.setUserStats(retrofitActivity, user.Properties);
if (emitter != null) {
sortLabel.setText(emitter.emit(user.Properties));
}
if (expandedItems.contains(pos)) {
expanded.setVisibility(View.VISIBLE);
} else {
expanded.setVisibility(View.GONE);
}
}
}
public interface StatsEmitter {
public String emit(UserStats stats);
}
public UserStatsAdapter(RetrofitActivity retrofitActivity, List<SingleContainer<UserStats>> users) {
super(retrofitActivity, users);
this.retrofitActivity = retrofitActivity;
}
public void setEmitter(StatsEmitter emitter) {
this.emitter = emitter;
}
public void clearExpanded() {
expandedItems.clear();
}
@Override
public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
View itemView = LayoutInflater.from(parent.getContext())
.inflate(R.layout.user_stats_list_row, parent, false);
final ViewHolder vh = new ViewHolder(itemView);
View.OnClickListener clickListener = new View.OnClickListener() {
@Override
public void onClick(View view) {
if (expandedItems.contains(vh.getAdapterPosition())) {
expandedItems.remove(vh.getAdapterPosition());
} else {
expandedItems.add(vh.getAdapterPosition());
}
notifyItemChanged(vh.getAdapterPosition());
}
};
itemView.setOnClickListener(clickListener);
vh.delegateClickListener = clickListener;

return new ViewHolder(itemView);
return vh;
}
}
80 changes: 80 additions & 0 deletions app/src/main/java/se/oort/diplicity/UserStatsTable.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
package se.oort.diplicity;

import android.content.Context;
import android.util.AttributeSet;
import android.widget.CheckBox;
import android.widget.CompoundButton;
import android.widget.TableLayout;
import android.widget.TableRow;
import android.widget.TextView;

import java.util.List;

import se.oort.diplicity.apigen.Game;
import se.oort.diplicity.apigen.GameScore;
import se.oort.diplicity.apigen.Member;
import se.oort.diplicity.apigen.PhaseMeta;
import se.oort.diplicity.apigen.PhaseState;
import se.oort.diplicity.apigen.SingleContainer;
import se.oort.diplicity.apigen.UserStats;

public class UserStatsTable extends TableLayout {
private AttributeSet attributeSet;
private UserStats userStats;
private TableRow.LayoutParams wrapContentParams =
new TableRow.LayoutParams(
TableRow.LayoutParams.WRAP_CONTENT,
TableRow.LayoutParams.WRAP_CONTENT, 0.0f);
private TableRow.LayoutParams matchParentParams =
new TableRow.LayoutParams(
TableRow.LayoutParams.MATCH_PARENT,
TableRow.LayoutParams.WRAP_CONTENT, 0.0f);

private void setMargins(TableRow.LayoutParams params) {
int margin = getResources().getDimensionPixelSize(R.dimen.member_table_margin);
params.bottomMargin = margin;
params.topMargin = margin;
params.leftMargin = margin;
params.rightMargin = margin;
}
public UserStatsTable(Context context, AttributeSet attrs) {
super(context, attrs);
this.attributeSet = attrs;
setMargins(wrapContentParams);
setMargins(matchParentParams);
}
public void addText(RetrofitActivity retrofitActivity, TableRow tableRow, String text) {
TextView scs = new TextView(retrofitActivity);
scs.setLayoutParams(wrapContentParams);
scs.setText(text);
tableRow.addView(scs);
}
public void addRow(RetrofitActivity retrofitActivity, String text1, String text2) {
TableRow tableRow = new TableRow(retrofitActivity);
tableRow.setLayoutParams(matchParentParams);

addText(retrofitActivity, tableRow, text1);
addText(retrofitActivity, tableRow, text2);

addView(tableRow);
}
public void setUserStats(RetrofitActivity retrofitActivity, final UserStats userStats) {
removeAllViews();
addRow(retrofitActivity, getResources().getString(R.string.rating), retrofitActivity.toString(userStats.Glicko.PracticalRating));
addRow(retrofitActivity, getResources().getString(R.string.started_games), "" + userStats.StartedGames);
addRow(retrofitActivity, getResources().getString(R.string.finished_games), "" + userStats.FinishedGames);
addRow(retrofitActivity, getResources().getString(R.string.solo_wins), "" + userStats.SoloGames);
addRow(retrofitActivity, getResources().getString(R.string.draws), "" + userStats.DIASGames);
addRow(retrofitActivity, getResources().getString(R.string.eliminations), "" + userStats.EliminatedGames);
addRow(retrofitActivity, getResources().getString(R.string.dropped_games), "" + userStats.DroppedGames);
addRow(retrofitActivity, getResources().getString(R.string.ready_phases), "" + userStats.ReadyPhases);
addRow(retrofitActivity, getResources().getString(R.string.active_phases), "" + userStats.ActivePhases);
addRow(retrofitActivity, getResources().getString(R.string.nmr_phases), "" + userStats.NMRPhases);
addRow(retrofitActivity, getResources().getString(R.string.reliability), retrofitActivity.toString(userStats.Reliability));
addRow(retrofitActivity, getResources().getString(R.string.quickness), retrofitActivity.toString(userStats.Quickness));
addRow(retrofitActivity, getResources().getString(R.string.owned_bans), "" + userStats.OwnedBans);
addRow(retrofitActivity, getResources().getString(R.string.shared_bans), "" + userStats.SharedBans);
addRow(retrofitActivity, getResources().getString(R.string.hated), retrofitActivity.toString(userStats.Hated));
addRow(retrofitActivity, getResources().getString(R.string.hater), retrofitActivity.toString(userStats.Hater));
}
}
1 change: 0 additions & 1 deletion app/src/main/res/layout/game_list_row.xml
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,6 @@
android:id="@+id/expanded"
android:layout_below="@id/variant"
android:background="?android:attr/selectableItemBackground"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="wrap_content">

Expand Down
17 changes: 16 additions & 1 deletion app/src/main/res/layout/user_stats_list_row.xml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,22 @@
android:layout_alignParentTop="true"
android:layout_alignParentStart="true"
android:layout_alignParentLeft="true"
android:layout_width="match_parent"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />

<TextView
android:id="@+id/sort_label"
android:layout_below="@id/user"
android:layout_alignParentTop="true"
android:layout_alignParentEnd="true"
android:layout_alignParentRight="true"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />

<se.oort.diplicity.UserStatsTable
android:id="@+id/expanded"
android:layout_below="@id/user"
android:layout_width="match_parent"
android:layout_height="wrap_content"/>

</RelativeLayout>
13 changes: 13 additions & 0 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -144,4 +144,17 @@
<string name="local_development_mode_fake_id_pref_key">local_development_mode_fake_id_pref_key</string>
<string name="you_can_build_n_this_phase">You can build %s this phase.</string>
<string name="you_have_to_disband_n_this_phase">You have to disband %s this phase.</string>
<string name="started_games">Started games</string>
<string name="finished_games">Finished games</string>
<string name="solo_wins">Solo wins</string>
<string name="draws">Draws</string>
<string name="eliminations">Eliminations</string>
<string name="dropped_games">Dropped games</string>
<string name="ready_phases">Ready phases</string>
<string name="active_phases">Active phases</string>
<string name="nmr_phases">NMR phases</string>
<string name="owned_bans">Owned bans</string>
<string name="shared_bans">Shared bans</string>
<string name="hated">Hated</string>
<string name="hater">Hater</string>
</resources>

0 comments on commit c6a01a3

Please sign in to comment.