1
0
mirror of https://github.com/wulkanowy/wulkanowy.git synced 2025-02-20 20:54:44 +01:00

Add a view of free days to the timetable (#57)

* Fix Timetable freeze when app was killed
* Add views for free days
This commit is contained in:
Rafał Borcz 2018-03-06 00:57:06 +01:00 committed by Mikołaj Pich
parent e274949257
commit c3803b1c96
17 changed files with 233 additions and 78 deletions

View File

@ -131,14 +131,6 @@ public class Day {
return this;
}
public boolean getIsFreeDay() {
return this.isFreeDay;
}
public void setIsFreeDay(boolean isFreeDay) {
this.isFreeDay = isFreeDay;
}
/**
* To-many relationship, resolved on first access (and after reset).
* Changes to to-many relations are not persisted, make changes to the target entity.
@ -205,6 +197,14 @@ public class Day {
myDao.update(this);
}
public boolean getIsFreeDay() {
return this.isFreeDay;
}
public void setIsFreeDay(boolean isFreeDay) {
this.isFreeDay = isFreeDay;
}
/** called by internal mechanisms, do not call yourself. */
@Generated(hash = 1409317752)
public void __setDaoSession(DaoSession daoSession) {

View File

@ -25,6 +25,10 @@ public class BasePresenter<V extends BaseContract.View> implements BaseContract.
view = null;
}
protected boolean isViewAttached() {
return view != null;
}
public final RepositoryContract getRepository() {
return repository;
}

View File

@ -22,15 +22,6 @@ public class LoginPresenter extends BasePresenter<LoginContract.View>
super(repository);
}
@Override
public void onDestroy() {
super.onDestroy();
if (loginAsync != null) {
loginAsync.cancel(true);
loginAsync = null;
}
}
@Override
public void attemptLogin(String email, String password, String symbol) {
getView().resetViewErrors();
@ -57,7 +48,9 @@ public class LoginPresenter extends BasePresenter<LoginContract.View>
@Override
public void onStartAsync() {
getView().showLoginProgress(true);
if (isViewAttached()) {
getView().showLoginProgress(true);
}
}
@Override
@ -90,7 +83,9 @@ public class LoginPresenter extends BasePresenter<LoginContract.View>
@Override
public void onCanceledAsync() {
getView().showLoginProgress(false);
if (isViewAttached()) {
getView().showLoginProgress(false);
}
}
private boolean isEmailValid(String email) {
@ -140,4 +135,13 @@ public class LoginPresenter extends BasePresenter<LoginContract.View>
}
return correct;
}
@Override
public void onDestroy() {
if (loginAsync != null) {
loginAsync.cancel(true);
loginAsync = null;
}
super.onDestroy();
}
}

View File

@ -78,7 +78,9 @@ public class GradesPresenter extends BasePresenter<GradesContract.View>
@Override
public void onCanceledRefreshAsync() {
getView().hideRefreshingBar();
if (isViewAttached()) {
getView().hideRefreshingBar();
}
}
@Override
@ -138,13 +140,14 @@ public class GradesPresenter extends BasePresenter<GradesContract.View>
} else {
getView().updateAdapterList(headerItems);
getView().showNoItem(false);
listener.onFragmentIsReady();
}
listener.onFragmentIsReady();
}
@Override
public void onDestroy() {
super.onDestroy();
isFirstSight = false;
if (refreshTask != null) {
refreshTask.cancel(true);
refreshTask = null;
@ -153,5 +156,6 @@ public class GradesPresenter extends BasePresenter<GradesContract.View>
loadingTask.cancel(true);
loadingTask = null;
}
super.onDestroy();
}
}

View File

@ -1,6 +1,7 @@
package io.github.wulkanowy.ui.main.timetable;
import android.view.View;
import android.widget.FrameLayout;
import android.widget.ImageView;
import android.widget.TextView;
@ -10,6 +11,7 @@ import org.apache.commons.lang3.builder.HashCodeBuilder;
import java.util.List;
import butterknife.BindColor;
import butterknife.BindView;
import butterknife.ButterKnife;
import eu.davidea.flexibleadapter.FlexibleAdapter;
@ -73,6 +75,15 @@ public class TimetableHeaderItem
@BindView(R.id.timetable_header_alert_image)
ImageView alert;
@BindView(R.id.timetable_header_free_name)
TextView freeName;
@BindColor(R.color.secondary_text)
int secondaryColor;
@BindColor(R.color.free_day)
int backgroundFreeDay;
HeaderViewHolder(View view, FlexibleAdapter adapter) {
super(view, adapter);
view.setOnClickListener(this);
@ -83,6 +94,14 @@ public class TimetableHeaderItem
dayName.setText(StringUtils.capitalize(item.getDayName()));
date.setText(item.getDate());
alert.setVisibility(isSubItemNewMovedInOrChanged(subItems) ? View.VISIBLE : View.INVISIBLE);
freeName.setVisibility(item.isFreeDay() ? View.VISIBLE : View.INVISIBLE);
freeName.setText(item.getFreeDayName());
if (item.isFreeDay()) {
((FrameLayout) getContentView()).setForeground(null);
getContentView().setBackgroundColor(backgroundFreeDay);
dayName.setTextColor(secondaryColor);
}
}
private boolean isSubItemNewMovedInOrChanged(List<TimetableSubItem> subItems) {

View File

@ -98,10 +98,12 @@ public class TimetablePresenter extends BasePresenter<TimetableContract.View>
@Override
public void onDestroy() {
super.onDestroy();
isFirstSight = false;
if (loadingTask != null) {
loadingTask.cancel(true);
loadingTask = null;
}
super.onDestroy();
}
}

View File

@ -14,7 +14,11 @@ public interface TimetableTabContract {
void hideRefreshingBar();
void showNoItem(boolean show);
void showProgressBar(boolean show);
void setFreeWeekName(String text);
}
interface Presenter extends BaseContract.Presenter<View> {

View File

@ -9,6 +9,7 @@ import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;
import java.util.List;
@ -25,7 +26,9 @@ import io.github.wulkanowy.ui.base.BaseFragment;
public class TimetableTabFragment extends BaseFragment implements TimetableTabContract.View,
SwipeRefreshLayout.OnRefreshListener {
private static final String ARGUMENT_KEY = "Date";
private static final String ARGUMENT_KEY = "date";
private static final String SAVED_KEY = "isSelected";
private boolean isPrimary = false;
@ -40,6 +43,12 @@ public class TimetableTabFragment extends BaseFragment implements TimetableTabCo
@BindView(R.id.timetable_tab_fragment_progress_bar)
View progressBar;
@BindView(R.id.timetable_tab_fragment_no_item_container)
View noItemView;
@BindView(R.id.timetable_tab_fragment_no_item_name)
TextView noItemName;
@Inject
TimetableTabContract.Presenter presenter;
@ -56,6 +65,14 @@ public class TimetableTabFragment extends BaseFragment implements TimetableTabCo
return fragmentTab;
}
@Override
public void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
if (savedInstanceState != null) {
isSelected = savedInstanceState.getBoolean(SAVED_KEY, isSelected);
}
}
@Nullable
@Override
public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
@ -104,6 +121,11 @@ public class TimetableTabFragment extends BaseFragment implements TimetableTabCo
}
}
@Override
public void setFreeWeekName(String text) {
noItemName.setText(text);
}
@Override
public void onRefresh() {
presenter.onRefresh();
@ -124,6 +146,11 @@ public class TimetableTabFragment extends BaseFragment implements TimetableTabCo
progressBar.setVisibility(show ? View.VISIBLE : View.INVISIBLE);
}
@Override
public void showNoItem(boolean show) {
noItemView.setVisibility(show ? View.VISIBLE : View.INVISIBLE);
}
public void setSelected(boolean selected) {
isSelected = selected;
}
@ -136,6 +163,12 @@ public class TimetableTabFragment extends BaseFragment implements TimetableTabCo
}
}
@Override
public void onSaveInstanceState(@NonNull Bundle outState) {
outState.putBoolean(SAVED_KEY, isSelected);
super.onSaveInstanceState(outState);
}
@Override
public void onDestroyView() {
isPrimary = false;

View File

@ -26,6 +26,8 @@ public class TimetableTabPresenter extends BasePresenter<TimetableTabContract.Vi
private String date;
private String freeWeekName;
private boolean isFirstSight = false;
@Inject
@ -37,6 +39,7 @@ public class TimetableTabPresenter extends BasePresenter<TimetableTabContract.Vi
public void onStart(TimetableTabContract.View view, boolean isPrimary) {
super.onStart(view);
getView().showProgressBar(true);
getView().showNoItem(false);
onFragmentSelected(isPrimary);
}
@ -70,7 +73,9 @@ public class TimetableTabPresenter extends BasePresenter<TimetableTabContract.Vi
@Override
public void onCanceledRefreshAsync() {
// do nothing
if (isViewAttached()) {
getView().hideRefreshingBar();
}
}
@Override
@ -100,9 +105,15 @@ public class TimetableTabPresenter extends BasePresenter<TimetableTabContract.Vi
headerItems = new ArrayList<>();
boolean isFreeWeek = true;
for (Day day : dayList) {
TimetableHeaderItem headerItem = new TimetableHeaderItem(day);
if (isFreeWeek) {
isFreeWeek = day.isFreeDay();
}
List<Lesson> lessonList = day.getLessons();
List<TimetableSubItem> subItems = new ArrayList<>();
@ -115,6 +126,11 @@ public class TimetableTabPresenter extends BasePresenter<TimetableTabContract.Vi
headerItem.setExpanded(false);
headerItems.add(headerItem);
}
if (isFreeWeek) {
freeWeekName = dayList.get(4).getFreeDayName();
headerItems = new ArrayList<>();
}
}
@Override
@ -124,7 +140,12 @@ public class TimetableTabPresenter extends BasePresenter<TimetableTabContract.Vi
@Override
public void onEndLoadingAsync(boolean result, Exception exception) {
getView().updateAdapterList(headerItems);
if (headerItems.isEmpty()) {
getView().showNoItem(true);
getView().setFreeWeekName(freeWeekName);
} else {
getView().updateAdapterList(headerItems);
}
getView().showProgressBar(false);
}
@ -140,7 +161,6 @@ public class TimetableTabPresenter extends BasePresenter<TimetableTabContract.Vi
@Override
public void onDestroy() {
super.onDestroy();
isFirstSight = false;
if (refreshTask != null) {
@ -151,5 +171,6 @@ public class TimetableTabPresenter extends BasePresenter<TimetableTabContract.Vi
loadingTask.cancel(true);
loadingTask = null;
}
super.onDestroy();
}
}

View File

@ -19,18 +19,18 @@
android:layout_below="@+id/grade_fragment_no_item_text"
android:layout_centerHorizontal="true"
android:layout_marginTop="40dp"
android:contentDescription="@string/activity_dashboard_text"
android:minHeight="100dp"
android:minWidth="100dp"
android:tint="@android:color/black"
app:srcCompat="@drawable/ic_menu_grade_26dp" />
app:srcCompat="@drawable/ic_menu_grade_26dp"
tools:ignore="contentDescription" />
<TextView
android:id="@+id/grade_fragment_no_item_text"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="46dp"
android:text="@string/fragment_no_grades"
android:id="@+id/grade_fragment_no_item_text"
android:textAlignment="center"
android:textSize="20sp" />
</RelativeLayout>

View File

@ -1,5 +1,6 @@
<android.support.design.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/timetable_tab_fragment_container"
android:layout_width="match_parent"
android:layout_height="match_parent"
@ -18,6 +19,45 @@
android:indeterminate="true" />
</RelativeLayout>
<RelativeLayout
android:id="@+id/timetable_tab_fragment_no_item_container"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center">
<ImageView
android:id="@+id/timetable_tab_fragment_no_item_image"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/timetable_tab_fragment_no_item_text"
android:layout_centerHorizontal="true"
android:layout_marginTop="40dp"
android:minHeight="100dp"
android:minWidth="100dp"
android:tint="@android:color/black"
app:srcCompat="@drawable/ic_menu_timetable_24dp"
tools:ignore="contentDescription" />
<TextView
android:id="@+id/timetable_tab_fragment_no_item_text"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="46dp"
android:text="@string/info_free_week"
android:textAlignment="center"
android:textSize="20sp" />
<TextView
android:id="@+id/timetable_tab_fragment_no_item_name"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/app_name"
android:textSize="20sp"
android:layout_below="@id/timetable_tab_fragment_no_item_image"
android:textAlignment="center"
android:layout_marginTop="15dp" />
</RelativeLayout>
<android.support.v4.widget.SwipeRefreshLayout
android:id="@+id/timetable_tab_fragment_swipe_refresh"
android:layout_width="match_parent"

View File

@ -29,7 +29,7 @@
android:layout_below="@+id/grade_header_subject_text"
android:layout_marginTop="5dp"
android:text="@string/app_name"
android:textColor="#4C4C4C"
android:textColor="@color/secondary_text"
android:textSize="12sp" />
<TextView
@ -43,7 +43,7 @@
android:layout_toEndOf="@+id/grade_header_average_text"
android:layout_toRightOf="@+id/grade_header_average_text"
android:text="@string/app_name"
android:textColor="#4C4C4C"
android:textColor="@color/secondary_text"
android:textSize="12sp" />
<ImageView

View File

@ -1,51 +1,71 @@
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@drawable/ic_border"
android:foreground="?attr/selectableItemBackgroundBorderless"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin">
android:foreground="?attr/selectableItemBackgroundBorderless">
<TextView
android:id="@+id/timetable_header_day"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_marginEnd="15dp"
android:layout_marginRight="15dp"
android:layout_toLeftOf="@id/timetable_header_alert_image"
android:layout_toStartOf="@+id/timetable_header_alert_image"
android:ellipsize="end"
android:maxLines="1"
android:text="@string/app_name"
android:textSize="19sp" />
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin">
<TextView
android:id="@+id/timetable_header_date"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_below="@+id/timetable_header_day"
android:layout_marginTop="5dp"
android:maxLines="1"
android:text="@string/app_name"
android:textColor="#4C4C4C"
android:textSize="14sp" />
<TextView
android:id="@+id/timetable_header_day"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_marginEnd="15dp"
android:layout_marginRight="15dp"
android:layout_toLeftOf="@id/timetable_header_alert_image"
android:layout_toStartOf="@+id/timetable_header_alert_image"
android:ellipsize="end"
android:maxLines="1"
android:text="@string/app_name"
android:textSize="19sp" />
<ImageView
android:id="@+id/timetable_header_alert_image"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentEnd="true"
android:layout_alignParentRight="true"
android:layout_marginTop="10dp"
app:srcCompat="@drawable/ic_exclamation_24dp"
tools:ignore="contentDescription" />
<TextView
android:id="@+id/timetable_header_date"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_below="@+id/timetable_header_day"
android:layout_marginTop="5dp"
android:maxLines="1"
android:text="@string/app_name"
android:textColor="@color/secondary_text"
android:textSize="14sp" />
</RelativeLayout>
<TextView
android:id="@+id/timetable_header_free_name"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentEnd="true"
android:layout_alignParentRight="true"
android:layout_centerVertical="true"
android:layout_marginLeft="180dp"
android:layout_marginStart="180dp"
android:gravity="end"
android:maxLines="2"
android:text="@string/app_name"
android:textColor="@color/secondary_text"
android:textSize="16sp" />
<ImageView
android:id="@+id/timetable_header_alert_image"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentEnd="true"
android:layout_alignParentRight="true"
android:layout_marginTop="10dp"
app:srcCompat="@drawable/ic_exclamation_24dp"
tools:ignore="contentDescription" />
</RelativeLayout>
</FrameLayout>

View File

@ -61,7 +61,7 @@
android:layout_alignStart="@id/timetable_subItem_lesson"
android:maxLines="1"
android:text="@string/grades_text"
android:textColor="#4C4C4C"
android:textColor="@color/secondary_text"
android:textSize="12sp" />
<TextView
@ -77,7 +77,7 @@
android:layout_toRightOf="@+id/timetable_subItem_time"
android:maxLines="1"
android:text="@string/grades_text"
android:textColor="#4C4C4C"
android:textColor="@color/secondary_text"
android:textSize="12sp"
tool:ignore="all"/>

View File

@ -73,6 +73,7 @@
<string name="info_average_grades">Średnia: %1$.2f</string>
<string name="info_no_average">Brak średniej</string>
<string name="info_free_week">Brak lekcji w tym tygodniu</string>
<string name="timetable_subitem_room">Sala %s</string>
<plurals name="numberOfGradesPlurals">

View File

@ -10,5 +10,7 @@
<color name="three_grade">#FFE68C</color>
<color name="two_grade">#CE9AD2</color>
<color name="one_grade">#d32f2f</color>
<color name="secondary_text">#4c4c4c</color>
<color name="default_grade">#cdcdcd</color>
<color name="free_day">#eee</color>
</resources>

View File

@ -72,6 +72,7 @@
<string name="info_average_grades">Average: %1$.2f</string>
<string name="info_no_average">No average</string>
<string name="info_free_week">No lesson in this week</string>
<string name="error_host_offline">Technical break</string>
<string name="timetable_subitem_room">Room %s</string>