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.calendar;
//fromwww.java2s.comimport android.app.Activity;
import android.os.Bundle;
import android.support.v7.widget.DefaultItemAnimator;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import com.example.jens.myapplication.R;
import com.example.jens.myapplication.activities.JoetzActivity;
import com.example.jens.myapplication.camps.RecyclerItemClickListener;
import com.example.jens.myapplication.domain.Booking;
import com.example.jens.myapplication.domain.BookingStatus;
import com.example.jens.myapplication.domain.Camp;
import com.example.jens.myapplication.domain.User;
import com.example.jens.myapplication.sam.JoetzApplication;
import com.example.jens.myapplication.sam.MyFragment;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;
/**
* Created by Jens on 8/11/2014.
*/publicclass FragmentCalendar extends MyFragment {
private List<KalenderItem> mItems;
private RecyclerView mRecyclerView;
private KalenderAdapter mAdapter;
private Callbacks mCallbacks = sKalenderCallbacks;
public FragmentCalendar() {
}
@Override
publicvoid onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
if(JoetzApplication.getContext().getLoginManager().isLoggedIn()) {
User user = JoetzApplication.getContext().getLoginManager().getUser();
fillItems(user);
}
else
{
// NIET INGELOGD HIER
}
}
privatevoid fillItems(User user){
mItems = new ArrayList<>();
for (Booking b : user.getBookings()){
if(b.getStatus() == BookingStatus.PAID) {
Camp camp = JoetzApplication.getContext().getCampManager().findCampById(b.getCampId());
mItems.add(new KalenderItem(camp.getId(), "CAMP", camp.getStartDateJson(),camp.getEndDateJson(), camp.getTitle()));
}
}
for (long activityId : user.getAcceptedActivities()){
JoetzActivity activity = JoetzApplication.getContext().getActivityManager().findActivityById(activityId);
mItems.add(new KalenderItem(activity.getId(), "ACTIVITY", activity.getUnixStartDate(),activity.getUnixEndDate(), activity.getTitle()));
}
Collections.sort(mItems, new CustomComparator());
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.fragment_calendar, container,
false);
mAdapter = new KalenderAdapter(mItems, R.layout.item_calendar, getActivity());
mRecyclerView = (RecyclerView) view.findViewById(R.id.list);
mRecyclerView.setLayoutManager(new LinearLayoutManager(getActivity()));
mRecyclerView.setItemAnimator(new DefaultItemAnimator());
mRecyclerView.setAdapter(mAdapter);
mRecyclerView.addOnItemTouchListener(
new RecyclerItemClickListener(getActivity(), new RecyclerItemClickListener.OnItemClickListener() {
@Override
publicvoid onItemClick(View view, int position) {
KalenderItem k = mAdapter.getItem(position);
mCallbacks.onKalenderItemSelected(k.getId(),k.getSoort());
}
})
);
return view;
}
// comperator om te sorteren
publicclass CustomComparator implements Comparator<KalenderItem> {
@Override
publicint compare(KalenderItem o1, KalenderItem o2) {
Long l1 = o1.getDate();
Long l2 = o2.getDate();
return l1.compareTo(l2);
}
}
@Override
publicvoid onAttach(Activity activity) {
super.onAttach(activity);
// Activities containing this fragment must implement its callbacks.
if (!(activity instanceof Callbacks)) {
thrownew IllegalStateException("Activity must implement fragment's callbacks.");
}
mCallbacks = (Callbacks) activity;
}
@Override
publicvoid onDetach() {
super.onDetach();
// Reset the active callbacks interface to the dummy implementation.
mCallbacks = sKalenderCallbacks;
}
publicinterface Callbacks {
/**
* Callback for when an item has been selected.
*/publicvoid onKalenderItemSelected(Long id, String soort);
}
privatestatic Callbacks sKalenderCallbacks = new Callbacks() {
publicvoid onKalenderItemSelected(Long id, String soort) {
}
};
}