Stundenplan wird nun angezeit, aber noch probleme mit dem refresh
This commit is contained in:
@@ -1,14 +1,37 @@
|
||||
package de.sebse.fuplanner.fragments;
|
||||
|
||||
import android.content.Context;
|
||||
import android.graphics.RectF;
|
||||
import android.net.Uri;
|
||||
import android.os.Bundle;
|
||||
import android.support.annotation.NonNull;
|
||||
import android.support.v4.app.Fragment;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
|
||||
import com.alamkanak.weekview.MonthLoader;
|
||||
import com.alamkanak.weekview.WeekView;
|
||||
import com.alamkanak.weekview.WeekViewEvent;
|
||||
|
||||
import java.time.LocalDate;
|
||||
import java.time.ZoneId;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Calendar;
|
||||
import java.util.Date;
|
||||
import java.util.HashSet;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
|
||||
import de.sebse.fuplanner.MainActivity;
|
||||
import de.sebse.fuplanner.R;
|
||||
import de.sebse.fuplanner.services.KVV.KVV;
|
||||
import de.sebse.fuplanner.services.KVV.types.Event;
|
||||
import de.sebse.fuplanner.services.KVV.types.Modules;
|
||||
import de.sebse.fuplanner.tools.logging.Logger;
|
||||
import de.sebse.fuplanner.tools.network.NetworkCallback;
|
||||
import de.sebse.fuplanner.tools.network.NetworkError;
|
||||
import de.sebse.fuplanner.tools.network.NetworkErrorCallback;
|
||||
|
||||
/**
|
||||
* A simple {@link Fragment} subclass.
|
||||
@@ -18,7 +41,7 @@ import de.sebse.fuplanner.R;
|
||||
* Use the {@link ScheduleFragment#newInstance} factory method to
|
||||
* create an instance of this fragment.
|
||||
*/
|
||||
public class ScheduleFragment extends 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";
|
||||
@@ -29,6 +52,11 @@ public class ScheduleFragment extends Fragment {
|
||||
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() {
|
||||
// Required empty public constructor
|
||||
@@ -59,15 +87,64 @@ public class ScheduleFragment extends Fragment {
|
||||
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());
|
||||
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");
|
||||
|
||||
mWeekView.invalidate();
|
||||
mWeekView.refreshDrawableState();
|
||||
}
|
||||
}
|
||||
|
||||
}, error1 -> log.e(error1));
|
||||
}
|
||||
}, error -> log.e(error));
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public View onCreateView(LayoutInflater inflater, ViewGroup container,
|
||||
Bundle savedInstanceState) {
|
||||
|
||||
|
||||
// Inflate the layout for this fragment
|
||||
return inflater.inflate(R.layout.fragment_schedule, container, false);
|
||||
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);
|
||||
|
||||
return v;
|
||||
}
|
||||
|
||||
|
||||
|
||||
// TODO: Rename method, update argument and hook method into UI event
|
||||
public void onButtonPressed(Uri uri) {
|
||||
if (mListener != null) {
|
||||
@@ -92,6 +169,60 @@ public class ScheduleFragment extends Fragment {
|
||||
mListener = null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onEventClick(WeekViewEvent event, RectF eventRect) {
|
||||
|
||||
}
|
||||
|
||||
@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());
|
||||
|
||||
Iterator<Event> it_modEvents = mod.events.getEventsOfMonth(newYear, newMonth);
|
||||
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)));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
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
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onEventLongPress(WeekViewEvent event, RectF eventRect) {
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* This interface must be implemented by activities that contain this
|
||||
* fragment to allow an interaction in this fragment to be communicated
|
||||
|
||||
@@ -6,10 +6,11 @@ import java.util.Collections;
|
||||
import java.util.Iterator;
|
||||
|
||||
import de.sebse.fuplanner.services.KVV.types.Event;
|
||||
import de.sebse.fuplanner.tools.logging.Logger;
|
||||
|
||||
public class EventList extends ArrayList<Event> {
|
||||
private int split = 0;
|
||||
|
||||
private Logger log = new Logger(this);
|
||||
public Event getPast(int index) {
|
||||
if (split < 0)
|
||||
sort();
|
||||
@@ -78,9 +79,10 @@ public class EventList extends ArrayList<Event> {
|
||||
@Override
|
||||
public Event next() {
|
||||
if (hasNext()) {
|
||||
i[0]++;
|
||||
return EventList.this.get(i[0]);
|
||||
log.d("Event hasnext", hasNext());
|
||||
return EventList.this.get(i[0]++);
|
||||
} else {
|
||||
log.d("Event null", hasNext());
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,12 +3,28 @@
|
||||
xmlns:tools="http://schemas.android.com/tools"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||
tools:context=".fragments.ScheduleFragment">
|
||||
|
||||
<!-- TODO: Update blank fragment layout -->
|
||||
<TextView
|
||||
|
||||
|
||||
|
||||
<com.alamkanak.weekview.WeekView
|
||||
android:id="@+id/weekView"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:text="@string/hello_blank_fragment" />
|
||||
app:eventTextColor="@android:color/white"
|
||||
app:textSize="12sp"
|
||||
app:hourHeight="60dp"
|
||||
app:headerColumnPadding="8dp"
|
||||
app:headerColumnTextColor="#8f000000"
|
||||
app:headerRowPadding="12dp"
|
||||
app:columnGap="8dp"
|
||||
app:noOfVisibleDays="5"
|
||||
app:headerRowBackgroundColor="#ffefefef"
|
||||
app:dayBackgroundColor="#05000000"
|
||||
app:todayBackgroundColor="#1848adff"
|
||||
app:headerColumnBackground="#ffffffff"/>
|
||||
|
||||
|
||||
</FrameLayout>
|
||||
Reference in New Issue
Block a user