diff --git a/app/src/main/kotlin/com/simplemobiletools/calendar/fragments/WeekFragment.kt b/app/src/main/kotlin/com/simplemobiletools/calendar/fragments/WeekFragment.kt index dec964006..24420cb4a 100644 --- a/app/src/main/kotlin/com/simplemobiletools/calendar/fragments/WeekFragment.kt +++ b/app/src/main/kotlin/com/simplemobiletools/calendar/fragments/WeekFragment.kt @@ -9,16 +9,17 @@ import android.view.ViewTreeObserver import com.simplemobiletools.calendar.R import com.simplemobiletools.calendar.activities.MainActivity import com.simplemobiletools.calendar.adapters.WeekEventsAdapter -import com.simplemobiletools.calendar.helpers.DBHelper +import com.simplemobiletools.calendar.helpers.WeeklyCalendarImpl +import com.simplemobiletools.calendar.interfaces.WeeklyCalendar import com.simplemobiletools.calendar.models.Event import com.simplemobiletools.calendar.views.MyScrollView import kotlinx.android.synthetic.main.fragment_week.view.* -import java.util.* -import kotlin.comparisons.compareBy +import org.joda.time.DateTime -class WeekFragment : Fragment(), DBHelper.GetEventsListener { +class WeekFragment : Fragment(), WeeklyCalendar { private var mListener: WeekScrollListener? = null lateinit var mView: View + lateinit var mCalendar: WeeklyCalendarImpl override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? { mView = inflater.inflate(R.layout.fragment_week, container, false) @@ -37,14 +38,18 @@ class WeekFragment : Fragment(), DBHelper.GetEventsListener { }) mView.week_events_grid.adapter = WeekEventsAdapter(context) + + mCalendar = WeeklyCalendarImpl(this, context) return mView } - override fun gotEvents(events: MutableList) { - val sorted = ArrayList(events.sortedWith(compareBy({ it.startTS }, { it.endTS }, { it.title }, { it.description }))) - activity?.runOnUiThread { + override fun onResume() { + super.onResume() + mCalendar.updateWeeklyCalendar(DateTime()) + } + + override fun updateWeeklyCalendar(events: List) { - } } fun setListener(listener: WeekScrollListener) { diff --git a/app/src/main/kotlin/com/simplemobiletools/calendar/helpers/WeeklyCalendarImpl.kt b/app/src/main/kotlin/com/simplemobiletools/calendar/helpers/WeeklyCalendarImpl.kt index a625e6585..0217b92f4 100644 --- a/app/src/main/kotlin/com/simplemobiletools/calendar/helpers/WeeklyCalendarImpl.kt +++ b/app/src/main/kotlin/com/simplemobiletools/calendar/helpers/WeeklyCalendarImpl.kt @@ -17,9 +17,13 @@ class WeeklyCalendarImpl(val mCallback: WeeklyCalendar, val mContext: Context) : fun updateWeeklyCalendar(targetDate: DateTime) { mTargetDate = targetDate + val startTS = (mTargetDate.millis / 1000).toInt() + val endTS = (mTargetDate.plusWeeks(1).millis / 1000).toInt() + DBHelper(mContext).getEvents(startTS, endTS, this) } override fun gotEvents(events: MutableList) { mEvents = events + mCallback.updateWeeklyCalendar(events) } }