Witam,
Mam pewien problem, chodzi o to ze już zrobiłam ustawianie domyślnej karty w adapterze. Teraz chciałabym zrobic tak ze jak wychodzę z aplikacji chciałabym zeby nie pokazła mi się lista kart ale zaznaczona od razu karta ze szczegółami tej karty.
pu```
blic class CardAdapter extends RecyclerView.Adapter<CardAdapter.CardViewHolder> {
private static int lastCheckedPos = 0;
private Card card;
private Context mContext;
private ArrayList<Card> cardsList = new ArrayList<Card>();
private MySharedPreference mySharedPreference;
public CardAdapter(Context mContext, ArrayList<Card> cardsList) {
this.mContext = mContext;
this.cardsList = cardsList;
notifyDataSetChanged();
}
@Override
public CardViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.item_card, parent, false);
return new CardViewHolder(view);
}
@Override
public void onBindViewHolder(final CardViewHolder holder, final int position) {
card = cardsList.get(position);
mySharedPreference = new MySharedPreference();
holder.nameCard.setText(card.getNameCard());
holder.setDate.setText(card.getCreateDate());
holder.expirationDate.setText(card.getExpirationDate());
if (position == lastCheckedPos) {
holder.cardView.setBackgroundResource(R.drawable.style_card_shadow);
holder.cardView.setCardBackgroundColor(Color.RED);
} else {
holder.cardView.setCardBackgroundColor(Color.WHITE);
}
holder.menu.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
final PopupMenu popupMenu = new PopupMenu(mContext, holder.menu);
popupMenu.inflate(R.menu.cardmenu);
popupMenu.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() {
@Override
public boolean onMenuItemClick(MenuItem item) {
Typeface custom_fonts = Typeface.createFromAsset(mContext.getAssets(), "fonts/OpenSans-Regular.ttf");
Typeface custom_fonts_Bold = Typeface.createFromAsset(mContext.getAssets(), "fonts/OpenSans-Bold.ttf");
switch (item.getItemId()) {
case R.id.defaultCard:
int currnetPosition = position;
int prePos = lastCheckedPos;
lastCheckedPos = position;
notifyItemChanged(prePos);
notifyItemChanged(lastCheckedPos);
break;
default:
break;
}
return false;
}
});
popupMenu.show();
}
});
}
@Override
public int getItemCount() {
return (cardsList == null) ? 0 : cardsList.size();
}
public class CardViewHolder extends RecyclerView.ViewHolder implements View.OnClickListener {
Typeface custom_fonts = Typeface.createFromAsset(itemView.getContext().getAssets(), "fonts/OpenSans-Regular.ttf");
private ImageView menu;
private CardView cardView;
private TextView nameCard, setDate, expirationDate, dateText, expirationText, numberCard;
public CardViewHolder(View itemView) {
super(itemView);
nameCard = (TextView) itemView.findViewById(R.id.nameCard);
nameCard.setTypeface(custom_fonts);
setDate = (TextView) itemView.findViewById(R.id.setDateText);
setDate.setTypeface(custom_fonts);
expirationDate = (TextView) itemView.findViewById(R.id.setDateExpirationText);
expirationDate.setTypeface(custom_fonts);
dateText = (TextView) itemView.findViewById(R.id.dateText);
dateText.setTypeface(custom_fonts);
expirationText = (TextView) itemView.findViewById(R.id.dateExpiration);
expirationText.setTypeface(custom_fonts);
menu = (ImageView) itemView.findViewById(R.id.menu);
cardView = (CardView) itemView.findViewById(R.id.cardView);
cardView.setOnClickListener(this);
}
@Override
public void onClick(View v) {
int position = getAdapterPosition();
Card cardDetails = cardsList.get(position);
Intent start = new Intent(mContext, CardDetailsActivity.class);
start.putExtra("cardName", cardDetails.getNameCard());
start.putExtra("path", cardDetails.getPath3());
start.putExtra("intervalTotp", cardDetails.getInvertalTotp());
start.putExtra("otp", cardDetails.getOTP());
v.getContext().startActivity(start);
}
}
}