-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added content to the user stats listings.
- Loading branch information
Showing
6 changed files
with
184 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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)); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters