ScheduleFragment init working; ScheduleFragment cleaned up
This commit is contained in:
@@ -138,7 +138,7 @@ public class MainActivity extends AppCompatActivity
|
||||
case R.id.nav_schedule:
|
||||
log.d("Stundenplan");
|
||||
fragmentTransaction = fragmentManager.beginTransaction();
|
||||
fragmentTransaction.replace(R.id.fragcontainer, ScheduleFragment.newInstance("bla","bla"));
|
||||
fragmentTransaction.replace(R.id.fragcontainer, ScheduleFragment.newInstance());
|
||||
fragmentTransaction.commit();
|
||||
break;
|
||||
case R.id.nav_share:
|
||||
|
||||
@@ -42,20 +42,9 @@ import de.sebse.fuplanner.tools.network.NetworkErrorCallback;
|
||||
* create an instance of this fragment.
|
||||
*/
|
||||
public class ScheduleFragment extends Fragment implements WeekView.EventClickListener, MonthLoader.MonthChangeListener, WeekView.EventLongPressListener {
|
||||
// TODO: Rename parameter arguments, choose names that match
|
||||
// the fragment initialization parameters, e.g. ARG_ITEM_NUMBER
|
||||
private static final String ARG_PARAM1 = "param1";
|
||||
private static final String ARG_PARAM2 = "param2";
|
||||
|
||||
// TODO: Rename and change types of parameters
|
||||
private String mParam1;
|
||||
private String mParam2;
|
||||
|
||||
private OnFragmentInteractionListener mListener;
|
||||
private WeekView mWeekView;
|
||||
private Logger log = new Logger(this);
|
||||
private ArrayList<WeekViewEvent> a = new ArrayList<>();
|
||||
private HashSet<Integer> addedIds = new HashSet<>();
|
||||
private Modules mModules = null;
|
||||
|
||||
public ScheduleFragment() {
|
||||
@@ -66,16 +55,12 @@ public class ScheduleFragment extends Fragment implements WeekView.EventClickLis
|
||||
* Use this factory method to create a new instance of
|
||||
* this fragment using the provided parameters.
|
||||
*
|
||||
* @param param1 Parameter 1.
|
||||
* @param param2 Parameter 2.
|
||||
* @return A new instance of fragment ScheduleFragment.
|
||||
*/
|
||||
// TODO: Rename and change types and number of parameters
|
||||
public static ScheduleFragment newInstance(String param1, String param2) {
|
||||
public static ScheduleFragment newInstance() {
|
||||
ScheduleFragment fragment = new ScheduleFragment();
|
||||
Bundle args = new Bundle();
|
||||
args.putString(ARG_PARAM1, param1);
|
||||
args.putString(ARG_PARAM2, param2);
|
||||
fragment.setArguments(args);
|
||||
return fragment;
|
||||
}
|
||||
@@ -83,34 +68,19 @@ public class ScheduleFragment extends Fragment implements WeekView.EventClickLis
|
||||
@Override
|
||||
public void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
if (getArguments() != null) {
|
||||
mParam1 = getArguments().getString(ARG_PARAM1);
|
||||
mParam2 = getArguments().getString(ARG_PARAM2);
|
||||
}
|
||||
a.add(new WeekViewEvent(1,"Das ist Test und der wird hoffentlich nicht doppelt", 2018, 10, 3,15,00,2018, 10, 3, 20,00));
|
||||
a.add(new WeekViewEvent(1,"Das ist Test und der wird hoffentlich nicht doppelt", 2018, 7, 3,15,00,2018, 7, 3, 20,00));
|
||||
|
||||
if (getActivity() != null) {
|
||||
KVV kvv = ((MainActivity) getActivity()).getKVV();
|
||||
kvv.getModuleList((Modules success) -> {
|
||||
mModules = success;
|
||||
log.d("Modules in onCreate", mModules.size());
|
||||
final int[] i = {0};
|
||||
Iterator<Modules.Module> it = mModules.iterator();
|
||||
while (it.hasNext()) {
|
||||
|
||||
Modules.Module module = it.next();
|
||||
log.d("onCreate Module gefunden", module.toString());
|
||||
for (Modules.Module module: mModules) {
|
||||
kvv.getModuleEvents(module, success1 -> {
|
||||
log.d("getModuleEvents gefunden");
|
||||
i[0]++;
|
||||
log.d("mModules.size() und i", mModules.size(), i[0]);
|
||||
if (i[0] >= mModules.size()){
|
||||
if (mWeekView != null){
|
||||
log.d("refreshDrawableState");
|
||||
|
||||
if (i[0] >= mModules.size()) {
|
||||
if (mWeekView != null) {
|
||||
mWeekView.invalidate();
|
||||
mWeekView.refreshDrawableState();
|
||||
mWeekView.notifyDatasetChanged();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -121,24 +91,13 @@ public class ScheduleFragment extends Fragment implements WeekView.EventClickLis
|
||||
}
|
||||
|
||||
@Override
|
||||
public View onCreateView(LayoutInflater inflater, ViewGroup container,
|
||||
Bundle savedInstanceState) {
|
||||
|
||||
|
||||
public View onCreateView(@NonNull LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
|
||||
// Inflate the layout for this fragment
|
||||
View v = inflater.inflate(R.layout.fragment_schedule, container, false);
|
||||
// Get a reference for the week view in the layout.
|
||||
mWeekView = (WeekView) v.findViewById(R.id.weekView);
|
||||
|
||||
// Set an action when any event is clicked.
|
||||
mWeekView.setOnEventClickListener(this::onEventClick);
|
||||
|
||||
// The week view has infinite scrolling horizontally. We have to provide the events of a
|
||||
// month every time the month changes on the week view.
|
||||
mWeekView.setMonthChangeListener(this::onMonthChange);
|
||||
|
||||
// Set long press listener for events.
|
||||
mWeekView.setEventLongPressListener(this::onEventLongPress);
|
||||
mWeekView = v.findViewById(R.id.weekView);
|
||||
mWeekView.setOnEventClickListener(this);
|
||||
mWeekView.setMonthChangeListener(this);
|
||||
mWeekView.setEventLongPressListener(this);
|
||||
|
||||
return v;
|
||||
}
|
||||
@@ -176,46 +135,28 @@ public class ScheduleFragment extends Fragment implements WeekView.EventClickLis
|
||||
|
||||
@Override
|
||||
public List<? extends WeekViewEvent> onMonthChange(int newYear, int newMonth) {
|
||||
//log.d("onMonthChange aufgerufen", mModules != null);
|
||||
ArrayList<WeekViewEvent> events = new ArrayList<>();
|
||||
if (mModules != null){
|
||||
|
||||
Iterator<Modules.Module> it = mModules.iterator();
|
||||
while (it.hasNext()) {
|
||||
Modules.Module mod = it.next();
|
||||
//log.d("null vieleicht", mod.events);
|
||||
if (mod.events != null){
|
||||
|
||||
|
||||
//log.d("mod in onMonthChange", mod.events.toString());
|
||||
|
||||
for (Modules.Module mod: mModules) {
|
||||
if (mod.events != null) {
|
||||
Iterator<Event> it_modEvents = mod.events.getEventsOfMonth(newYear, newMonth);
|
||||
while (it_modEvents.hasNext()){
|
||||
while (it_modEvents.hasNext()) {
|
||||
Event e = it_modEvents.next();
|
||||
//log.d("Event in while", e.toString());
|
||||
|
||||
Calendar ende = Calendar.getInstance();
|
||||
ende.setTimeInMillis(e.getEndDate());
|
||||
Calendar start = Calendar.getInstance();
|
||||
start.setTimeInMillis(e.getStartDate());
|
||||
|
||||
|
||||
//log.d("Event?%:", startDate.toString(), "aufgeteilt",start.get(Calendar.YEAR), start.get(Calendar.MONTH)+1, start.get(Calendar.DAY_OF_MONTH), start.get(Calendar.HOUR_OF_DAY), start.get(Calendar.MINUTE) );
|
||||
//log.d("Event?%:ende", endDate.toString(), "aufgeteilt",ende.get(Calendar.YEAR), ende.get(Calendar.MONTH)+1, ende.get(Calendar.DAY_OF_MONTH), ende.get(Calendar.HOUR_OF_DAY), ende.get(Calendar.MINUTE) );
|
||||
//LocalDate localDate = date.toInstant().atZone(ZoneId.systemDefault()).toLocalDate();
|
||||
events.add(new WeekViewEvent(1,e.getTitle(), start.get(Calendar.YEAR), start.get(Calendar.MONTH)+1, start.get(Calendar.DAY_OF_MONTH), start.get(Calendar.HOUR_OF_DAY), start.get(Calendar.MINUTE), ende.get(Calendar.YEAR), ende.get(Calendar.MONTH)+1, ende.get(Calendar.DAY_OF_MONTH), ende.get(Calendar.HOUR_OF_DAY), ende.get(Calendar.MINUTE)));
|
||||
events.add(new WeekViewEvent(1, e.getTitle(), start.get(Calendar.YEAR), start.get(Calendar.MONTH) + 1, start.get(Calendar.DAY_OF_MONTH), start.get(Calendar.HOUR_OF_DAY), start.get(Calendar.MINUTE), ende.get(Calendar.YEAR), ende.get(Calendar.MONTH) + 1, ende.get(Calendar.DAY_OF_MONTH), ende.get(Calendar.HOUR_OF_DAY), ende.get(Calendar.MINUTE)));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
log.d("onMonthChange_aufgerufen", newYear, newMonth);
|
||||
|
||||
//a.add(new WeekViewEvent(2,"Das ist Test und der wird hoffentlich nicht doppelt", 2018, 7, 3,15,00,2018, 7, 3, 20,00));
|
||||
|
||||
return events;//(List<? extends WeekViewEvent>) new WeekViewEvent(l,"Test", 2018, 7, 3,15,00,2018, 7, 3, 20,00);
|
||||
//int startYear, int startMonth, int startDay, int startHour, int startMinute, int endYear, int endMonth, int endDay, int endHour, int endMinute
|
||||
return events;
|
||||
//(List<? extends WeekViewEvent>) new WeekViewEvent(l,"Test", 2018, 7, 3,15,00,2018, 7, 3, 20,00);
|
||||
//int id, String title, int startYear, int startMonth, int startDay, int startHour, int startMinute, int endYear, int endMonth, int endDay, int endHour, int endMinute
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
Reference in New Issue
Block a user