Skip to content

Commit

Permalink
Made all user images clickable.
Browse files Browse the repository at this point in the history
Added a dialog with user stats when a user icon is clicked.
Removed the user stats expandable content from the stats listings.
  • Loading branch information
zond committed Jan 2, 2017
1 parent c6a01a3 commit 25fdd36
Show file tree
Hide file tree
Showing 6 changed files with 70 additions and 41 deletions.
1 change: 0 additions & 1 deletion app/src/main/java/se/oort/diplicity/MainActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -510,7 +510,6 @@ 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
29 changes: 1 addition & 28 deletions app/src/main/java/se/oort/diplicity/UserStatsAdapter.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,32 +14,23 @@

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 {
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 {
Expand All @@ -52,28 +43,10 @@ public UserStatsAdapter(RetrofitActivity retrofitActivity, List<SingleContainer<
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 vh;
return new ViewHolder(itemView);
}
}
24 changes: 22 additions & 2 deletions app/src/main/java/se/oort/diplicity/UserView.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,11 @@
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.media.ThumbnailUtils;
import android.support.v7.app.AlertDialog;
import android.util.AttributeSet;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.FrameLayout;
import android.widget.ImageView;
import android.widget.TextView;
Expand All @@ -19,7 +21,9 @@
import rx.Subscriber;
import rx.android.schedulers.AndroidSchedulers;
import rx.schedulers.Schedulers;
import se.oort.diplicity.apigen.SingleContainer;
import se.oort.diplicity.apigen.User;
import se.oort.diplicity.apigen.UserStats;

public class UserView extends FrameLayout {
private void inflate() {
Expand All @@ -30,8 +34,24 @@ public UserView(Context context, AttributeSet attrs) {
super(context, attrs);
inflate();
}
public void setUser(RetrofitActivity retrofitActivity, User user) {
public void setUser(final RetrofitActivity retrofitActivity, final User user) {
((TextView) findViewById(R.id.name)).setText(user.Name);
retrofitActivity.populateImage((ImageView) findViewById(R.id.avatar), user.Picture);
ImageView avatar = (ImageView) findViewById(R.id.avatar);
retrofitActivity.populateImage(avatar, user.Picture);
avatar.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
retrofitActivity.handleReq(
retrofitActivity.userStatsService.UserStatsLoad(user.Id),
new Sendable<SingleContainer<UserStats>>() {
@Override
public void send(SingleContainer<UserStats> userStatsSingleContainer) {
final AlertDialog dialog = new AlertDialog.Builder(retrofitActivity).setView(R.layout.user_dialog).show();
((UserStatsTable) dialog.findViewById(R.id.user_stats)).setUserStats(retrofitActivity, userStatsSingleContainer.Properties);
((UserView) dialog.findViewById(R.id.user)).setUser(retrofitActivity, user);
}
}, getResources().getString(R.string.loading_user_stats));
}
});
}
}
30 changes: 26 additions & 4 deletions app/src/main/java/se/oort/diplicity/game/PressActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import android.support.design.widget.FloatingActionButton;
import android.support.design.widget.Snackbar;
import android.support.v4.widget.NestedScrollView;
import android.support.v7.app.AlertDialog;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.LinearLayoutCompat;
import android.support.v7.widget.Toolbar;
Expand Down Expand Up @@ -41,6 +42,8 @@
import se.oort.diplicity.R;
import se.oort.diplicity.RetrofitActivity;
import se.oort.diplicity.Sendable;
import se.oort.diplicity.UserStatsTable;
import se.oort.diplicity.UserView;
import se.oort.diplicity.apigen.Game;
import se.oort.diplicity.apigen.Member;
import se.oort.diplicity.apigen.Message;
Expand All @@ -49,6 +52,7 @@
import se.oort.diplicity.apigen.PhaseMeta;
import se.oort.diplicity.apigen.SingleContainer;
import se.oort.diplicity.apigen.Ticker;
import se.oort.diplicity.apigen.UserStats;

public class PressActivity extends RetrofitActivity {

Expand Down Expand Up @@ -154,18 +158,36 @@ public void send(final MultiContainer<Message> messageMultiContainer) {
for (int i = 0; i < messageMultiContainer.Properties.size(); i++) {
Message message = messageMultiContainer.Properties.get(messageMultiContainer.Properties.size() - i - 1).Properties;
View row = getLayoutInflater().inflate(R.layout.message_list_row, (ViewGroup) findViewById(R.id.press_layout), false);
String url = null;
Member author = null;
for (Member member : game.Members) {
if (member.Nation.equals(message.Sender)) {
url = member.User.Picture;
author = member;
break;
}
}

((TextView) row.findViewById(R.id.body)).setText(message.Body);
((TextView) row.findViewById(R.id.at)).setText(message.Age.deadlineAt().toString());
((TextView) row.findViewById(R.id.sender)).setText(getResources().getString(R.string.x_, message.Sender));
if (url != null) {
PressActivity.this.populateImage((ImageView) row.findViewById(R.id.avatar), url);
if (author != null) {
ImageView avatar = (ImageView) row.findViewById(R.id.avatar);
PressActivity.this.populateImage(avatar, author.User.Picture);
final Member finalAuthor = author;
avatar.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
PressActivity.this.handleReq(
PressActivity.this.userStatsService.UserStatsLoad(finalAuthor.User.Id),
new Sendable<SingleContainer<UserStats>>() {
@Override
public void send(SingleContainer<UserStats> userStatsSingleContainer) {
final AlertDialog dialog = new AlertDialog.Builder(PressActivity.this).setView(R.layout.user_dialog).show();
((UserStatsTable) dialog.findViewById(R.id.user_stats)).setUserStats(PressActivity.this, userStatsSingleContainer.Properties);
((UserView) dialog.findViewById(R.id.user)).setUser(PressActivity.this, finalAuthor.User);
}
}, getResources().getString(R.string.loading_user_stats));
}
});
}

((LinearLayout) findViewById(R.id.press_messages)).addView(row);
Expand Down
21 changes: 21 additions & 0 deletions app/src/main/res/layout/user_dialog.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent" android:layout_height="match_parent">

<se.oort.diplicity.UserView
android:id="@+id/user"
android:layout_alignParentTop="true"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>

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

</RelativeLayout>
6 changes: 0 additions & 6 deletions app/src/main/res/layout/user_stats_list_row.xml
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,4 @@
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>

0 comments on commit 25fdd36

Please sign in to comment.