mirror of
https://github.com/szkolny-eu/szkolny-android.git
synced 2025-01-31 13:48:20 +01:00
[APIv2/Timetable] Make swipe refresh download timetable for the selected week
This commit is contained in:
parent
63960c5e05
commit
6a4994b9c2
@ -537,9 +537,16 @@ class MainActivity : AppCompatActivity() {
|
|||||||
DRAWER_ITEM_MESSAGES -> MessagesFragment.pageSelection
|
DRAWER_ITEM_MESSAGES -> MessagesFragment.pageSelection
|
||||||
else -> 0
|
else -> 0
|
||||||
}
|
}
|
||||||
|
val arguments = when (navTargetId) {
|
||||||
|
DRAWER_ITEM_TIMETABLE -> JsonObject().apply {
|
||||||
|
addProperty("weekStart", TimetableFragment.pageSelection?.weekStart?.stringY_m_d)
|
||||||
|
}
|
||||||
|
else -> null
|
||||||
|
}
|
||||||
EdziennikTask.syncProfile(
|
EdziennikTask.syncProfile(
|
||||||
App.profileId,
|
App.profileId,
|
||||||
listOf(navTargetId to fragmentParam)
|
listOf(navTargetId to fragmentParam),
|
||||||
|
arguments
|
||||||
).enqueue(this)
|
).enqueue(this)
|
||||||
}
|
}
|
||||||
@Subscribe(threadMode = ThreadMode.MAIN)
|
@Subscribe(threadMode = ThreadMode.MAIN)
|
||||||
|
@ -1,11 +1,12 @@
|
|||||||
package pl.szczodrzynski.edziennik.ui.modules.home;
|
package pl.szczodrzynski.edziennik.ui.modules.home;
|
||||||
|
|
||||||
import androidx.databinding.DataBindingUtil;
|
|
||||||
import android.os.AsyncTask;
|
import android.os.AsyncTask;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
|
import android.util.Log;
|
||||||
|
|
||||||
import androidx.annotation.Nullable;
|
import androidx.annotation.Nullable;
|
||||||
import androidx.appcompat.app.AppCompatActivity;
|
import androidx.appcompat.app.AppCompatActivity;
|
||||||
import android.util.Log;
|
import androidx.databinding.DataBindingUtil;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
@ -14,8 +15,8 @@ import java.util.TimerTask;
|
|||||||
|
|
||||||
import pl.szczodrzynski.edziennik.App;
|
import pl.szczodrzynski.edziennik.App;
|
||||||
import pl.szczodrzynski.edziennik.R;
|
import pl.szczodrzynski.edziennik.R;
|
||||||
import pl.szczodrzynski.edziennik.databinding.ActivityCounterBinding;
|
|
||||||
import pl.szczodrzynski.edziennik.data.db.modules.lessons.LessonFull;
|
import pl.szczodrzynski.edziennik.data.db.modules.lessons.LessonFull;
|
||||||
|
import pl.szczodrzynski.edziennik.databinding.ActivityCounterBinding;
|
||||||
import pl.szczodrzynski.edziennik.utils.models.Date;
|
import pl.szczodrzynski.edziennik.utils.models.Date;
|
||||||
import pl.szczodrzynski.edziennik.utils.models.Time;
|
import pl.szczodrzynski.edziennik.utils.models.Time;
|
||||||
|
|
||||||
@ -88,7 +89,7 @@ public class CounterActivity extends AppCompatActivity {
|
|||||||
private void findLessons(Time syncedNow) {
|
private void findLessons(Time syncedNow) {
|
||||||
AsyncTask.execute(() -> {
|
AsyncTask.execute(() -> {
|
||||||
Date today = Date.getToday();
|
Date today = Date.getToday();
|
||||||
lessons = app.db.lessonDao().getAllNearestNow(App.profileId, today.clone().stepForward(0, 0, -today.getWeekDay()), today, syncedNow);
|
lessons = app.db.lessonDao().getAllNearestNow(App.profileId, today.getWeekStart(), today, syncedNow);
|
||||||
|
|
||||||
if (lessons != null && lessons.size() != 0) {
|
if (lessons != null && lessons.size() != 0) {
|
||||||
Date displayingDate = lessons.get(0).lessonDate;
|
Date displayingDate = lessons.get(0).lessonDate;
|
||||||
|
@ -184,7 +184,7 @@ public class TimetableFragment extends Fragment {
|
|||||||
if (app == null || app.profile == null || activity == null || b == null || !isAdded())
|
if (app == null || app.profile == null || activity == null || b == null || !isAdded())
|
||||||
return;
|
return;
|
||||||
|
|
||||||
List<LessonFull> lessons = app.db.lessonDao().getAllWeekNow(App.profileId, today.clone().stepForward(0, 0, -today.getWeekDay()), today);
|
List<LessonFull> lessons = app.db.lessonDao().getAllWeekNow(App.profileId, today.getWeekStart(), today);
|
||||||
displayingDate = HomeFragment.findDateWithLessons(App.profileId, lessons);
|
displayingDate = HomeFragment.findDateWithLessons(App.profileId, lessons);
|
||||||
pageSelection = app.appConfig.timetableDisplayDaysBackward + Date.diffDays(displayingDate, today); // DEFAULT HERE
|
pageSelection = app.appConfig.timetableDisplayDaysBackward + Date.diffDays(displayingDate, today); // DEFAULT HERE
|
||||||
|
|
||||||
|
@ -19,7 +19,7 @@ class TimetablePagerAdapter(
|
|||||||
}
|
}
|
||||||
|
|
||||||
private val today by lazy { Date.getToday() }
|
private val today by lazy { Date.getToday() }
|
||||||
private val weekStart by lazy { today.clone().stepForward(0, 0, -today.weekDay) }
|
private val weekStart by lazy { today.weekStart }
|
||||||
private val weekEnd by lazy { weekStart.clone().stepForward(0, 0, 6) }
|
private val weekEnd by lazy { weekStart.clone().stepForward(0, 0, 6) }
|
||||||
|
|
||||||
override fun getItem(position: Int): Fragment {
|
override fun getItem(position: Int): Fragment {
|
||||||
@ -49,4 +49,4 @@ class TimetablePagerAdapter(
|
|||||||
}
|
}
|
||||||
return pageTitle
|
return pageTitle
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -120,7 +120,7 @@ class TimetableDayFragment : Fragment(), CoroutineScope {
|
|||||||
parent?.removeAllViews()
|
parent?.removeAllViews()
|
||||||
parent?.addView(view)
|
parent?.addView(view)
|
||||||
val b = TimetableNoTimetableBinding.bind(view)
|
val b = TimetableNoTimetableBinding.bind(view)
|
||||||
val weekStart = date.clone().stepForward(0, 0, -date.weekDay).stringY_m_d
|
val weekStart = date.weekStart.stringY_m_d
|
||||||
b.noTimetableSync.onClick {
|
b.noTimetableSync.onClick {
|
||||||
it.isEnabled = false
|
it.isEnabled = false
|
||||||
EdziennikTask.syncProfile(
|
EdziennikTask.syncProfile(
|
||||||
|
@ -41,6 +41,10 @@ public class Date implements Comparable<Date> {
|
|||||||
return new Date(this.year, this.month, this.day);
|
return new Date(this.year, this.month, this.day);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public Date getWeekStart() {
|
||||||
|
return clone().stepForward(0, 0, -getWeekDay());
|
||||||
|
}
|
||||||
|
|
||||||
public static Date fromYmd(String dateTime) {
|
public static Date fromYmd(String dateTime) {
|
||||||
return new Date(Integer.parseInt(dateTime.substring(0, 4)), Integer.parseInt(dateTime.substring(4, 6)), Integer.parseInt(dateTime.substring(6, 8)));
|
return new Date(Integer.parseInt(dateTime.substring(0, 4)), Integer.parseInt(dateTime.substring(4, 6)), Integer.parseInt(dateTime.substring(6, 8)));
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user