Android Open Source - Joetz-Android-V2 Booking History Overview 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.bookingHistory;
//ww  w  . j  a v a 2s . co  m
import android.content.Intent;
import android.os.Bundle;
import android.support.v7.widget.GridLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.LinearLayout;
import android.widget.ProgressBar;
import android.widget.TextView;

import com.example.jens.myapplication.R;
import com.example.jens.myapplication.apimanager.ApiConnection;
import com.example.jens.myapplication.apimanager.CancellableTask;
import com.example.jens.myapplication.apimanager.SimpleRequestTask;
import com.example.jens.myapplication.apimanager.manager.CampManager;
import com.example.jens.myapplication.apimanager.manager.LoginManager;
import com.example.jens.myapplication.camps.RecyclerItemClickListener;
import com.example.jens.myapplication.domain.Booking;
import com.example.jens.myapplication.sam.JoetzApplication;
import com.example.jens.myapplication.sam.MyFragment;
import com.example.jens.myapplication.util.ActivityUtils;

import java.util.Collections;
import java.util.Comparator;
import java.util.LinkedList;
import java.util.List;

public class BookingHistoryOverviewFragment extends MyFragment {
    //private OnFragmentInteractionListener mListener;

    private RecyclerView mLstBookings;
    private List<Booking> mBookings;
    private CancellableTask mTaskRetrieveCamps;
    private SimpleRequestTask mListenerLoadCamps;

    private LinkedList<View> rootViews = new LinkedList<>();
    private LinearLayout mLlyError;
    private TextView mTxtNoBookings;
    private ProgressBar mPgbLoading;

    public static BookingHistoryOverviewFragment newInstance() {
        BookingHistoryOverviewFragment fragment = new BookingHistoryOverviewFragment();
        return fragment;
    }

    public BookingHistoryOverviewFragment() {
        // Required empty public constructor
    }

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        JoetzApplication.getContext().restartIfLoggedOut();

        LoginManager loginManager = JoetzApplication.getContext().getLoginManager();
        mBookings = loginManager.getUser().getBookings();
        Collections.sort(mBookings, new Comparator<Booking>() {
            @Override
            public int compare(Booking lhs, Booking rhs) {
                return rhs.getDateOfRegistration().compareTo(lhs.getDateOfRegistration());
            }
        });

    }

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        // Inflate the layout for this fragment
        View rootView = inflater.inflate(R.layout.fragment_booking_history_overview, container, false);

        mLlyError = (LinearLayout) rootView.findViewById(R.id.llyError);
        rootViews.add(mLlyError);
        mTxtNoBookings = (TextView) rootView.findViewById(R.id.txtNoBookings);
        rootViews.add(mTxtNoBookings);
        mPgbLoading = (ProgressBar) rootView.findViewById(R.id.pgbLoading);
        rootViews.add(mPgbLoading);

        GridLayoutManager gridLayoutManager = new GridLayoutManager(getActivity(),
                ActivityUtils.getSpanCount(getActivity()));
        mLstBookings = (RecyclerView) rootView.findViewById(R.id.lstBookings);
        mLstBookings.setLayoutManager(gridLayoutManager);
        mLstBookings.addOnItemTouchListener(new RecyclerItemClickListener(getActivity(),
                new RecyclerItemClickListener.OnItemClickListener() {
                    @Override
                    public void onItemClick(View view, int position) {
                        openBooking(mBookings.get(position).getId());
                    }
                }));

        rootViews.add(mLstBookings);

        CampManager campManager = JoetzApplication.getContext().getCampManager();
        if(campManager.isCampsLoaded()){
            loadBookings();
        }else{
            loadCamps();
        }

        return rootView;
    }

    private void loadCamps(){
        CampManager campManager = JoetzApplication.getContext().getCampManager();
//        mLstBookings.setVisibility(View.GONE);
//        mPgbLoading.setVisibility(View.VISIBLE);
        setRootview(mPgbLoading);
        mListenerLoadCamps = new SimpleRequestTask() {
            @Override
            public void doTask(int statusCode) {
                mListenerLoadCamps = null;
                mTaskRetrieveCamps = null;
                if(!ApiConnection.isSuccessCode(statusCode)){
                    //TODO some fancy error message
                    return;
                }
//                mLstBookings.setVisibility(View.VISIBLE);
//                mPgbLoading.setVisibility(View.GONE);
//                setRootview(mLstBookings);
                loadBookings();
            }
        };
        mTaskRetrieveCamps = campManager.retrieveCamps(mListenerLoadCamps);
    }

    private void openBooking(long id){
        Intent i = new Intent(getActivity(), BookingHistoryDetailActivity.class);
        i.putExtra(BookingHistoryDetailActivity.ARG_BOOKING_ID, id);
        startActivity(i);
    }

    private void loadBookings(){
        if(mBookings.size() == 0){
//            mTxtNoBookings.setVisibility(View.VISIBLE);
//            mLstBookings.setVisibility(View.GONE);
            setRootview(mTxtNoBookings);
        }
        else{
            mLstBookings.setAdapter(new BookingsAdapter(getActivity(), mBookings));
//            mTxtNoBookings.setVisibility(View.GONE);
//            mLstBookings.setVisibility(View.VISIBLE);
            setRootview(mLstBookings);
        }
    }

    private void setRootview(View view){
        for(View v : rootViews){
            v.setVisibility(View.GONE);
        }
        view.setVisibility(View.VISIBLE);
    }

    @Override
    public void onDestroy() {
        super.onDestroy();
        if(mListenerLoadCamps != null){
            JoetzApplication.getContext().getCampManager().unsubscribeLoadCamps(mListenerLoadCamps);
        }
    }

    /*@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 onUserLogout();
    }*/
}




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