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.
Java Source Code
package com.example.jens.myapplication.bookingHistory;
/*www.java2s.com*/import android.os.Bundle;
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.domain.Booking;
import com.example.jens.myapplication.domain.Camp;
import com.example.jens.myapplication.sam.JoetzApplication;
import com.example.jens.myapplication.sam.MyFragment;
import com.example.jens.myapplication.util.DateTimeStringConverter;
import com.example.jens.myapplication.util.StringUtils;
import java.util.Iterator;
import java.util.List;
/**
* Fragment with detailed information about a booking the user has made
*/publicclass BookingHistoryDetailFragment extends MyFragment {
privatestaticfinal String ARG_BOOKING_ID = "argBookingId";
// private OnFragmentInteractionListener mListener;
private Booking mBooking;
private Camp mCampForBooking;
private TextView mTxtStatus;
private TextView mTxtBookingId;
private TextView mTxtBookingDate;
private TextView mTxtPersons;
private TextView mTxtCampTitle;
private TextView mTxtCampDate;
private TextView mTxtCampLocation;
private TextView mTxtCampPrice;
/**
*
* @param bookingId the ID of the booking
* @return
*/publicstatic BookingHistoryDetailFragment newInstance(long bookingId) {
BookingHistoryDetailFragment fragment = new BookingHistoryDetailFragment();
Bundle args = new Bundle();
args.putLong(ARG_BOOKING_ID, bookingId);
fragment.setArguments(args);
return fragment;
}
public BookingHistoryDetailFragment() {
// Required empty public constructor
}
@Override
publicvoid onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
if (getArguments() != null) {
long bookingId = getArguments().getLong(ARG_BOOKING_ID);
List<Booking> bookings = JoetzApplication.getContext()
.getLoginManager().getUser().getBookings();
for(Booking b : bookings){
if(b.getId() == bookingId){
mBooking = b;
break;
}
}
}
if(mBooking == null){
thrownew IllegalStateException("Booking was not found");
}
mCampForBooking =
JoetzApplication.getContext().getCampManager().findCampById(mBooking.getCampId());
if(mCampForBooking == null){
thrownew IllegalStateException("Camp for booking was not found");
}
getActivity().setTitle(R.string.booking_detail);
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View rootView = inflater.inflate(R.layout.fragment_booking_history_detail, container, false);
mTxtStatus = (TextView) rootView.findViewById(R.id.txtStatus);
mTxtStatus.setText(StringUtils.firstUpper(getString(R.string.status))
+ ": " + getString(mBooking.getStatus().getStringResId()));
//Color indication for the state of the booking
int bgColorId = -1;
switch(mBooking.getStatus()){
case PAID: bgColorId = R.color.state_green; break;
case IN_PROCESS: bgColorId = R.color.state_yellow; break;
case CANCELLED: bgColorId = R.color.state_red;
}
if(bgColorId >= 0){
mTxtStatus.setBackgroundColor(getResources().getColor(bgColorId));
}
mTxtBookingId = (TextView) rootView.findViewById(R.id.txtBookingId);
mTxtBookingDate = (TextView) rootView.findViewById(R.id.txtDateOfRegistration);
mTxtPersons = (TextView) rootView.findViewById(R.id.txtPersons);
mTxtCampTitle = (TextView) rootView.findViewById(R.id.txtCampTitle);
mTxtCampDate = (TextView) rootView.findViewById(R.id.txtCampDate);
mTxtCampLocation = (TextView) rootView.findViewById(R.id.txtCampLocation);
mTxtCampPrice = (TextView) rootView.findViewById(R.id.txtCampPrice);
mTxtBookingId.setText(String.valueOf(mBooking.getId()));
mTxtBookingDate.setText(DateTimeStringConverter.getSimpleDate(mBooking.getDateOfRegistration()));
StringBuilder sb = new StringBuilder();
Iterator<String> it = mBooking.getPersons().iterator();
if(it.hasNext()){
sb.append(it.next());
}
while(it.hasNext()){
sb.append(System.getProperty("line.separator") + it.next());
}
mTxtPersons.setText(sb.toString());
mTxtCampTitle.setText(mCampForBooking.getTitle());
mTxtCampDate.setText(DateTimeStringConverter.getSimpleDateRange(
mCampForBooking.getStartDate(), mCampForBooking.getEndDate(), getString(R.string.until)));
mTxtCampLocation.setText(mCampForBooking.getLocation());
mTxtCampPrice.setText("\u20ac " + mCampForBooking.getPrice().toString());
return rootView;
}
/*@Override
public void onAttach(Activity activity) {
super.onAttach(activity);
try {
mListener = (OnFragmentInteractionListener) activity;
} catch (ClassCastException e) {
throw new ClassCastException(activity.toString()
+ " must implement OnFragmentInteractionListener");
}
}
@Override
public void onDetach() {
super.onDetach();
mListener = null;
}*/// public interface OnFragmentInteractionListener {
// }
}