Back to project page Joetz-Android-V2.
The source code is released under:
GNU General Public License
If you think the Android project Joetz-Android-V2 listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.
package com.example.jens.myapplication.bookingHistory; // w ww .jav a 2 s . c o m import android.content.Context; import android.support.v4.util.LongSparseArray; import android.support.v7.widget.RecyclerView; import android.util.Log; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; import android.widget.TextView; import com.example.jens.myapplication.R; import com.example.jens.myapplication.apimanager.manager.CampManager; import com.example.jens.myapplication.domain.Booking; import com.example.jens.myapplication.domain.Camp; import com.example.jens.myapplication.sam.JoetzApplication; import com.example.jens.myapplication.util.DateTimeStringConverter; import java.util.List; /** * Adapter for all the booking objects */ public class BookingsAdapter extends RecyclerView.Adapter<BookingsAdapter.ViewHolder> { private Context context; private List<Booking> bookings; private LongSparseArray<Camp> campsForBookings; public BookingsAdapter(Context context, List<Booking> bookings){ this.context = context; this.bookings = bookings; campsForBookings = new LongSparseArray<Camp>(); CampManager campManager = JoetzApplication.getContext().getCampManager(); for(Booking b : bookings){ campsForBookings.put(b.getId(), campManager.findCampById(b.getCampId())); } } @Override public ViewHolder onCreateViewHolder(ViewGroup viewGroup, int i) { return new ViewHolder(LayoutInflater.from(viewGroup.getContext()).inflate( R.layout.item_booking, viewGroup, false)); } @Override public void onBindViewHolder(ViewHolder viewHolder, int i) { final Booking booking = bookings.get(i); final Camp camp = campsForBookings.get(booking.getId()); viewHolder.txtCampName.setText(camp.getTitle()); viewHolder.txtDateOfRegistration.setText( DateTimeStringConverter.getSimpleDate(booking.getDateOfRegistration())); viewHolder.txtAmountPersons.setText( context.getString(R.string.$_amount_participants, booking.getPersons().size())); int colorId; switch(booking.getStatus()){ case PAID: colorId = R.color.state_green; break; case IN_PROCESS: colorId = R.color.state_yellow; break; case CANCELLED: colorId = R.color.state_red; break; default: colorId = R.color.color_action_bar; Log.wtf("CampAdapter", "crazy wth"); } viewHolder.txtCampName.setBackgroundColor(context.getResources().getColor(colorId)); } @Override public int getItemCount() { return bookings == null ? 0 : bookings.size(); } public static class ViewHolder extends RecyclerView.ViewHolder{ private TextView txtCampName; private TextView txtDateOfRegistration; private TextView txtAmountPersons; public ViewHolder(View v) { super(v); txtCampName = (TextView) v.findViewById(R.id.txtCampName); txtDateOfRegistration = (TextView) v.findViewById(R.id.txtDateRegistration); txtAmountPersons = (TextView) v.findViewById(R.id.txtAmountPersons); } } }