forked from github/wulkanowy-mirror
Expand current day on startup (#129)
This commit is contained in:
parent
228f680e5d
commit
e2003e2538
@ -3,7 +3,6 @@ package io.github.wulkanowy.ui.main.timetable;
|
||||
import android.os.Bundle;
|
||||
import android.support.annotation.NonNull;
|
||||
import android.support.annotation.Nullable;
|
||||
import android.support.design.widget.Snackbar;
|
||||
import android.support.design.widget.TabLayout;
|
||||
import android.support.v4.view.ViewPager;
|
||||
import android.view.LayoutInflater;
|
||||
|
@ -10,6 +10,8 @@ public interface TimetableTabContract {
|
||||
|
||||
void updateAdapterList(List<TimetableHeaderItem> headerItems);
|
||||
|
||||
void expandItem(int item);
|
||||
|
||||
void onRefreshSuccess();
|
||||
|
||||
void hideRefreshingBar();
|
||||
|
@ -3,7 +3,6 @@ package io.github.wulkanowy.ui.main.timetable.tab;
|
||||
import android.os.Bundle;
|
||||
import android.support.annotation.NonNull;
|
||||
import android.support.annotation.Nullable;
|
||||
import android.support.design.widget.Snackbar;
|
||||
import android.support.v4.widget.SwipeRefreshLayout;
|
||||
import android.support.v7.widget.RecyclerView;
|
||||
import android.view.LayoutInflater;
|
||||
@ -91,6 +90,12 @@ public class TimetableTabFragment extends BaseFragment implements TimetableTabCo
|
||||
adapter.updateDataSet(headerItems);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void expandItem(int position) {
|
||||
adapter.expand(adapter.getItem(position), true);
|
||||
recyclerView.scrollToPosition(position);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setMenuVisibility(boolean menuVisible) {
|
||||
super.setMenuVisibility(menuVisible);
|
||||
|
@ -1,8 +1,9 @@
|
||||
package io.github.wulkanowy.ui.main.timetable.tab;
|
||||
|
||||
|
||||
import android.support.annotation.NonNull;
|
||||
|
||||
import org.threeten.bp.LocalDate;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
@ -13,7 +14,9 @@ import io.github.wulkanowy.data.db.dao.entities.Day;
|
||||
import io.github.wulkanowy.data.db.dao.entities.TimetableLesson;
|
||||
import io.github.wulkanowy.data.db.dao.entities.Week;
|
||||
import io.github.wulkanowy.ui.base.BasePresenter;
|
||||
import io.github.wulkanowy.utils.AppConstant;
|
||||
import io.github.wulkanowy.utils.FabricUtils;
|
||||
import io.github.wulkanowy.utils.TimeUtils;
|
||||
import io.github.wulkanowy.utils.async.AbstractTask;
|
||||
import io.github.wulkanowy.utils.async.AsyncListeners;
|
||||
|
||||
@ -48,8 +51,6 @@ public class TimetableTabPresenter extends BasePresenter<TimetableTabContract.Vi
|
||||
@Override
|
||||
public void onFragmentActivated(boolean isSelected) {
|
||||
if (!isFirstSight && isSelected && isViewAttached()) {
|
||||
isFirstSight = true;
|
||||
|
||||
loadingTask = new AbstractTask();
|
||||
loadingTask.setOnFirstLoadingListener(this);
|
||||
loadingTask.execute();
|
||||
@ -148,15 +149,24 @@ public class TimetableTabPresenter extends BasePresenter<TimetableTabContract.Vi
|
||||
|
||||
@Override
|
||||
public void onEndLoadingAsync(boolean result, Exception exception) {
|
||||
getView().showNoItem(headerItems.isEmpty());
|
||||
getView().updateAdapterList(headerItems);
|
||||
|
||||
if (headerItems.isEmpty()) {
|
||||
getView().showNoItem(true);
|
||||
getView().setFreeWeekName(freeWeekName);
|
||||
getView().updateAdapterList(null);
|
||||
} else {
|
||||
getView().updateAdapterList(headerItems);
|
||||
getView().showNoItem(false);
|
||||
expandCurrentDayHeader();
|
||||
}
|
||||
getView().showProgressBar(false);
|
||||
isFirstSight = true;
|
||||
}
|
||||
|
||||
private void expandCurrentDayHeader() {
|
||||
LocalDate monday = TimeUtils.getParsedDate(date, AppConstant.DATE_PATTERN);
|
||||
|
||||
if (TimeUtils.isDateInWeek(monday, LocalDate.now()) && !isFirstSight) {
|
||||
getView().expandItem(LocalDate.now().getDayOfWeek().getValue() - 1);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -44,6 +44,10 @@ public final class TimeUtils {
|
||||
return getNetTicks(dateObject);
|
||||
}
|
||||
|
||||
public static LocalDate getParsedDate(String dateString, String dateFormat) {
|
||||
return LocalDate.parse(dateString, DateTimeFormatter.ofPattern(dateFormat));
|
||||
}
|
||||
|
||||
public static Date getDate(long netTicks) {
|
||||
return new Date((netTicks - TICKS_AT_EPOCH) / TICKS_PER_MILLISECOND);
|
||||
}
|
||||
@ -102,4 +106,9 @@ public final class TimeUtils {
|
||||
LocalDate current = LocalDate.now();
|
||||
return nextDay ? current.plusDays(1).format(formatter) : current.format(formatter);
|
||||
}
|
||||
|
||||
public static boolean isDateInWeek(LocalDate firstWeekDay, LocalDate date) {
|
||||
return date.isAfter(firstWeekDay.minusDays(1)) && date.isBefore(firstWeekDay.plusDays(5));
|
||||
|
||||
}
|
||||
}
|
||||
|
@ -2,6 +2,7 @@ package io.github.wulkanowy.utils;
|
||||
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
import org.threeten.bp.LocalDate;
|
||||
|
||||
import java.text.DateFormat;
|
||||
import java.text.ParseException;
|
||||
@ -47,6 +48,11 @@ public class TimeUtilsTest {
|
||||
Assert.assertEquals(636080256000000000L, TimeUtils.getNetTicks("2016-08-29"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getParsedDateTest() {
|
||||
Assert.assertEquals(LocalDate.of(1970, 1, 1), TimeUtils.getParsedDate("1970-01-01", "yyyy-MM-dd"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getDateTest() throws Exception {
|
||||
DateFormat format = new SimpleDateFormat("dd.MM.yyyy", Locale.ROOT);
|
||||
@ -55,4 +61,38 @@ public class TimeUtilsTest {
|
||||
|
||||
Assert.assertEquals(date, TimeUtils.getDate(636370560000000000L));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void isDateInWeekInsideTest() {
|
||||
Assert.assertTrue(TimeUtils.isDateInWeek(
|
||||
LocalDate.of(2018, 5, 28),
|
||||
LocalDate.of(2018, 5, 31)
|
||||
));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void isDateInWeekExtremesTest() {
|
||||
Assert.assertTrue(TimeUtils.isDateInWeek(
|
||||
LocalDate.of(2018, 5, 28),
|
||||
LocalDate.of(2018, 5, 28)
|
||||
));
|
||||
|
||||
Assert.assertTrue(TimeUtils.isDateInWeek(
|
||||
LocalDate.of(2018, 5, 28),
|
||||
LocalDate.of(2018, 6, 1)
|
||||
));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void isDateInWeekOutOfTest() {
|
||||
Assert.assertFalse(TimeUtils.isDateInWeek(
|
||||
LocalDate.of(2018, 5, 28),
|
||||
LocalDate.of(2018, 6, 2)
|
||||
));
|
||||
|
||||
Assert.assertFalse(TimeUtils.isDateInWeek(
|
||||
LocalDate.of(2018, 5, 28),
|
||||
LocalDate.of(2018, 5, 27)
|
||||
));
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user