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.camps; /* ww w . j a v a2 s . c o m*/ import android.app.Activity; import android.app.AlertDialog; import android.content.DialogInterface; import android.content.Intent; import android.graphics.Typeface; import android.os.Bundle; import android.support.v4.app.Fragment; import android.support.v7.widget.CardView; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; import android.widget.ImageView; import android.widget.LinearLayout; import android.widget.RelativeLayout; import android.widget.TextView; import com.example.jens.myapplication.R; import com.example.jens.myapplication.account.LoginDialogActivity; import com.example.jens.myapplication.account.RegisterDialogActivity; import com.example.jens.myapplication.apimanager.ApiConnection; import com.example.jens.myapplication.apimanager.manager.LoginManager; import com.example.jens.myapplication.domain.Camp; import com.example.jens.myapplication.domain.PeriodCategory; import com.example.jens.myapplication.sam.JoetzApplication; import com.example.jens.myapplication.util.DateTimeStringConverter; import com.nostra13.universalimageloader.core.DisplayImageOptions; import com.nostra13.universalimageloader.core.ImageLoader; /** * Fragment for detailed camp info */ public class InfoFragment extends Fragment { private static final int REQUEST_CODE_LOGIN = 1; private static final int REQUEST_CODE_REGISTER = 2; // private RecyclerView mRecyclerView; private CardView mCavBook; private OnFragmentInteractionListener mListener; private LinearLayout mLlyMonitors; public InfoFragment() { // Required empty public constructor } public static final String ARG_CAMP_ID = "item_id"; private Long mCampId; private Camp mCamp; private DisplayImageOptions options; private ImageView mPeriodImage; private RelativeLayout mPeriodImageContainer; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); mCampId = getActivity().getIntent().getExtras().getLong(ARG_CAMP_ID); mCamp = JoetzApplication.getContext().getCampManager().findCampById(mCampId); options = new DisplayImageOptions.Builder() .showImageOnLoading(R.drawable.stub) // .showImageForEmptyUri(R.drawable.ic_empty) // .showImageOnFail(R.drawable.ic_error) .cacheInMemory(true) .cacheOnDisk(true) .considerExifParams(true) .build(); } private void inschrijven(){ LoginManager loginManager = JoetzApplication.getContext().getLoginManager(); if( !loginManager.isLoggedIn() ){ AlertDialog.OnClickListener buttonListener = new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { if(which == AlertDialog.BUTTON_POSITIVE){ doLoginAndBook(); }else if(which == AlertDialog.BUTTON_NEUTRAL){ doRegisterAndBook(); } } }; AlertDialog.Builder dialogBuilder = new AlertDialog.Builder(getActivity()); dialogBuilder.setMessage(R.string.niet_loggedin_choice_register_login) .setPositiveButton(R.string.login, buttonListener) .setNeutralButton(R.string.register, buttonListener); dialogBuilder.create().show(); }else{ toBooking(); } } private void toBooking(){ mListener.toBooking(mCampId); } private void doLoginAndBook(){ Intent i = new Intent(getActivity(), LoginDialogActivity.class); startActivityForResult(i, REQUEST_CODE_LOGIN); } private void doRegisterAndBook(){ Intent i = new Intent(getActivity(), RegisterDialogActivity.class); startActivityForResult(i, REQUEST_CODE_REGISTER); } @Override public void onActivityResult(int requestCode, int resultCode, Intent data) { //super.onActivityResult(requestCode, resultCode, data); if(requestCode == REQUEST_CODE_LOGIN){ if(resultCode == Activity.RESULT_OK){ toBooking(); }else if(resultCode == LoginDialogActivity.RESULT_REGISTER){ doRegisterAndBook(); } } else if(requestCode == REQUEST_CODE_REGISTER){ if(resultCode == Activity.RESULT_OK){ toBooking(); } } } @Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { // Inflate the layout for this fragment View rootView = inflater.inflate(R.layout.fragment_info, container,false); mCavBook = (CardView) rootView.findViewById(R.id.cardViewInschrijven); if (mCamp!= null) { getActivity().getActionBar().setTitle(mCamp.getTitle()); ((TextView) rootView.findViewById(R.id.lbl_date)).setText(DateTimeStringConverter.getSimpleDate(mCamp.getStartDate()) + " - " + DateTimeStringConverter.getSimpleDate(mCamp.getEndDate())); /* if(mCamp.getPeriodCategory() != PeriodCategory.OTHER){ TextView v = (TextView) rootView.findViewById(R.id.lbl_period); v.setText("( " + getString(mCamp.getPeriodCategory().getNameResourceId()) + " )"); v.setVisibility(View.VISIBLE); }*/ mPeriodImage = (ImageView) rootView.findViewById(R.id.periodeImage); mPeriodImageContainer = (RelativeLayout) rootView.findViewById(R.id.periodeImageContainer); final TextView txtPeriodInfo = (TextView) rootView.findViewById(R.id.txtPeriodInfo); if(mCamp.getPeriodCategory() == PeriodCategory.OTHER){ mPeriodImageContainer.setVisibility(View.GONE); }else{ View.OnClickListener listener = new View.OnClickListener() { @Override public void onClick(View v) { txtPeriodInfo.setText(mCamp.getPeriodCategory().getNameResourceId()); txtPeriodInfo.setVisibility(View.VISIBLE); } }; mPeriodImageContainer.setOnClickListener(listener); mPeriodImage.setOnClickListener(listener); } mPeriodImage.setImageDrawable(getActivity().getResources().getDrawable(mCamp.getPeriodCategory().getResourceIdImage())); ((TextView) rootView.findViewById(R.id.lbl_age)).setText(mCamp.getMinimumAge() + " - " + mCamp.getMaximumAge() + " " + "j"); ((TextView) rootView.findViewById(R.id.lbl_dest)).setText(mCamp.getLocation()); ((TextView) rootView.findViewById(R.id.lbl_price)).setText("\u20ac " + mCamp.getPrice().toString()); ((TextView) rootView.findViewById(R.id.txtBeschrijving)).setText(mCamp.getDescription()); TextView txtFreeSpots = (TextView) rootView.findViewById(R.id.txtFreePlaces); if(mCamp.getFreeSpots() > 1){ txtFreeSpots.setText(getString(R.string.$_free_places, mCamp.getFreeSpots())); }else if(mCamp.getFreeSpots() == 0){ txtFreeSpots.setText(getString(R.string.one_free_place)); }else{ txtFreeSpots.setText(getString(R.string.camp_is_fully_booked)); txtFreeSpots.setTextColor(getResources().getColor(R.color.color_action_bar)); txtFreeSpots.setTypeface(Typeface.DEFAULT_BOLD); } ImageView image = ((ImageView) rootView.findViewById(R.id.campImage)); ImageLoader.getInstance().displayImage(ApiConnection.URL + "api/images/"+mCamp.getFirstImageId(),image, options); mLlyMonitors = (LinearLayout) rootView.findViewById(R.id.llyMonitors); if(mCamp.getMonitors().size() < 1){ mLlyMonitors.addView(createTextView(getString(R.string.camp_no_monitors))); }else{ for(String moni : mCamp.getMonitors()){ mLlyMonitors.addView(createTextView(moni)); } } } mCavBook.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { inschrijven(); } }); return rootView; } private TextView createTextView(String text){ TextView tv = new TextView(getActivity()); /*LinearLayout.LayoutParams layoutParams = new LinearLayout.LayoutParams( LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.WRAP_CONTENT );*/ tv.setLayoutParams(new LinearLayout.LayoutParams( LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.WRAP_CONTENT )); tv.setPadding(0, 5, 0, 5); tv.setText(text); return tv; } @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{ public void toBooking(long campId); } }