Android Open Source - Joetz-Android-V2 Info Fragment






From Project

Back to project page Joetz-Android-V2.

License

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.

Java Source Code

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);
    }
}




Java Source Code List

com.example.jens.myapplication.ApplicationTest.java
com.example.jens.myapplication.account.FragmentAccount.java
com.example.jens.myapplication.account.LoginDialogActivity.java
com.example.jens.myapplication.account.LoginFragment.java
com.example.jens.myapplication.account.PersonsFragment.java
com.example.jens.myapplication.account.ProfileFragment.java
com.example.jens.myapplication.account.RegisterDialogActivity.java
com.example.jens.myapplication.account.RegisterFragment.java
com.example.jens.myapplication.account.TabsPagerAdapter.java
com.example.jens.myapplication.activities.ActivityDetailActivity.java
com.example.jens.myapplication.activities.ActivityDetailFragment.java
com.example.jens.myapplication.activities.FragmentListActivities.java
com.example.jens.myapplication.activities.JoetzActivitiesAdapter.java
com.example.jens.myapplication.activities.JoetzActivity.java
com.example.jens.myapplication.activities.StartActivity.java
com.example.jens.myapplication.apimanager.ApiConnection.java
com.example.jens.myapplication.apimanager.CancellableTask.java
com.example.jens.myapplication.apimanager.JSONParsingTask.java
com.example.jens.myapplication.apimanager.PostRequestTask.java
com.example.jens.myapplication.apimanager.RequestParams.java
com.example.jens.myapplication.apimanager.SimpleRequestTask.java
com.example.jens.myapplication.apimanager.filter.PersonFilter.java
com.example.jens.myapplication.apimanager.manager.ActivityManager.java
com.example.jens.myapplication.apimanager.manager.AuthToken.java
com.example.jens.myapplication.apimanager.manager.BookingManager.java
com.example.jens.myapplication.apimanager.manager.CampManager.java
com.example.jens.myapplication.apimanager.manager.ImageManager.java
com.example.jens.myapplication.apimanager.manager.LoginManager.java
com.example.jens.myapplication.apimanager.manager.ProfileManager.java
com.example.jens.myapplication.apimanager.manager.RegisterManager.java
com.example.jens.myapplication.booking.AddPersonActivity.java
com.example.jens.myapplication.booking.BookingActivity.java
com.example.jens.myapplication.booking.BookingBondFragment.java
com.example.jens.myapplication.booking.BookingContactFragment.java
com.example.jens.myapplication.booking.BookingExtraFragment.java
com.example.jens.myapplication.booking.BookingParticipantsFragment.java
com.example.jens.myapplication.bookingHistory.BookingHistoryDetailActivity.java
com.example.jens.myapplication.bookingHistory.BookingHistoryDetailFragment.java
com.example.jens.myapplication.bookingHistory.BookingHistoryOverviewFragment.java
com.example.jens.myapplication.bookingHistory.BookingsAdapter.java
com.example.jens.myapplication.calendar.FragmentCalendar.java
com.example.jens.myapplication.calendar.KalenderAdapter.java
com.example.jens.myapplication.calendar.KalenderItem.java
com.example.jens.myapplication.camps.CampAdapter.java
com.example.jens.myapplication.camps.CampDetailActivity.java
com.example.jens.myapplication.camps.CampFilterActivity.java
com.example.jens.myapplication.camps.FilterFragment.java
com.example.jens.myapplication.camps.FragmentListCamps.java
com.example.jens.myapplication.camps.ImageActivity.java
com.example.jens.myapplication.camps.ImagePagerFragment.java
com.example.jens.myapplication.camps.InfoFragment.java
com.example.jens.myapplication.camps.PhotoFragment.java
com.example.jens.myapplication.camps.RecyclerItemClickListener.java
com.example.jens.myapplication.camps.SquareImageView.java
com.example.jens.myapplication.camps.TabsPagerAdapter.java
com.example.jens.myapplication.domain.BookingStatus.java
com.example.jens.myapplication.domain.Booking.java
com.example.jens.myapplication.domain.Camp.java
com.example.jens.myapplication.domain.PeriodCategory.java
com.example.jens.myapplication.domain.Person.java
com.example.jens.myapplication.domain.UserRole.java
com.example.jens.myapplication.domain.User.java
com.example.jens.myapplication.domain.binding.PersonValidatorBinding.java
com.example.jens.myapplication.domain.binding.UserValidatorBinding.java
com.example.jens.myapplication.domain.binding.ValidatorBinding.java
com.example.jens.myapplication.domain.converter.ErrorConverter.java
com.example.jens.myapplication.domain.converter.MyStringParser.java
com.example.jens.myapplication.domain.converter.UnixDateTimeConverter.java
com.example.jens.myapplication.domain.validator.PersonValidator.java
com.example.jens.myapplication.domain.validator.UserValidator.java
com.example.jens.myapplication.domain.validator.Validator.java
com.example.jens.myapplication.home.AanbevolenAdapter.java
com.example.jens.myapplication.home.HomeFragment.java
com.example.jens.myapplication.home.ImageSlideAdapter.java
com.example.jens.myapplication.home.Reclame.java
com.example.jens.myapplication.lib.RangeSeekBar.java
com.example.jens.myapplication.main.MainActivity.java
com.example.jens.myapplication.main.NavDrawerAdapter.java
com.example.jens.myapplication.main.NavDrawerItem.java
com.example.jens.myapplication.main.NavMenuItem.java
com.example.jens.myapplication.main.NavMenuSection.java
com.example.jens.myapplication.sam.JoetzApplication.java
com.example.jens.myapplication.sam.MyFragment.java
com.example.jens.myapplication.sam.MySaveableFragment.java
com.example.jens.myapplication.util.AESEncryption.java
com.example.jens.myapplication.util.ActivityUtils.java
com.example.jens.myapplication.util.BindingUtils.java
com.example.jens.myapplication.util.DateTimeStringConverter.java
com.example.jens.myapplication.util.JsonUtils.java
com.example.jens.myapplication.util.MyMonths.java
com.example.jens.myapplication.util.StringUtils.java
com.example.jens.myapplication.view.MyLinearLayout.java