package org.smartpaws.recycler.cards; import android.app.AlertDialog; import android.graphics.Bitmap; import android.support.v7.widget.RecyclerView; import android.view.LayoutInflater; import android.view.View; import android.widget.ImageView; import android.widget.TextView; import com.squareup.picasso.NetworkPolicy; import org.smartpaws.MainActivity; import org.smartpaws.R; import org.smartpaws.net.DataMan; import org.smartpaws.net.HttpClient; import org.smartpaws.objects.User; import org.smartpaws.util.ScreenDensity; import org.smartpaws.util.TimeUtils; public class CardDealer extends RecyclerView.ViewHolder { private User user; private final View root; private final TextView name; private final TextView table; private final ImageView icon; public CardDealer(View v) { super(v); this.root = v; this.name = (TextView) v.findViewById(R.id.card_dealer_name); this.table = (TextView) v.findViewById(R.id.card_dealer_table); this.icon = (ImageView) v.findViewById(R.id.card_dealer_icon); } public void setUser(final User user) { this.user = user; root.setOnClickListener(new View.OnClickListener() { @Override public void onClick(final View v) { AlertDialog.Builder b = new AlertDialog.Builder(v.getContext()) .setCancelable(true) .setPositiveButton("Done", null); View dialogView = LayoutInflater.from(root.getContext()).inflate(R.layout.card_dealer_dialog, null); ((TextView) dialogView.findViewById(R.id.card_dealer_name)).setText(user.getName()); ((TextView) dialogView.findViewById(R.id.card_dealer_table)).setText(user.getTable()); TextView descriptionView = ((TextView) dialogView.findViewById(R.id.card_dealer_dialog_description)); if (user.getDescription() == null || user.getDescription().trim().isEmpty()) { descriptionView.setVisibility(View.GONE); } else { descriptionView.setText(user.getDescription()); } if (user.hasIcon()) { ImageView img = (ImageView) dialogView.findViewById(R.id.card_dealer_icon); String picUri = HttpClient.BASE_URL + "img/" + DataMan.getSelectedConvention(root.getContext()) + "/dealer/" + user.getId() + "/" + ScreenDensity.getName() + ".png"; Bitmap cachedPic = DataMan.getDatabase().getImage(picUri); if (cachedPic == null) { MainActivity.PICASSO .load(picUri) .placeholder(R.drawable.ic_user_generic) .error(R.drawable.ic_user_generic) .into(img); } else { img.setImageBitmap(cachedPic); } } b.setView(dialogView); b.show(); } }); this.name.setText(user.getName()); this.table.setText(user.getTable()); } public User getUser() { return user; } public ImageView getIcon() { return icon; } public void setIcon(int drawable) { this.icon.setImageResource(drawable); } }