mirror of
https://github.com/wulkanowy/wulkanowy.git
synced 2025-02-20 21:04:45 +01:00
Add semester switch in grades (#94)
This commit is contained in:
parent
cb6d39fe15
commit
4ef3334bf7
@ -10,9 +10,9 @@ public interface DbContract {
|
||||
|
||||
Week getWeek(String date);
|
||||
|
||||
List<Subject> getSubjectList();
|
||||
List<Subject> getSubjectList(int semesterName);
|
||||
|
||||
List<Grade> getNewGrades();
|
||||
List<Grade> getNewGrades(int semesterName);
|
||||
|
||||
long getCurrentStudentId();
|
||||
|
||||
@ -20,5 +20,9 @@ public interface DbContract {
|
||||
|
||||
long getCurrentDiaryId();
|
||||
|
||||
long getSemesterId(int name);
|
||||
|
||||
long getCurrentSemesterId();
|
||||
|
||||
int getCurrentSemesterName();
|
||||
}
|
||||
|
@ -8,6 +8,7 @@ import io.github.wulkanowy.data.db.dao.entities.DaoSession;
|
||||
import io.github.wulkanowy.data.db.dao.entities.DiaryDao;
|
||||
import io.github.wulkanowy.data.db.dao.entities.Grade;
|
||||
import io.github.wulkanowy.data.db.dao.entities.GradeDao;
|
||||
import io.github.wulkanowy.data.db.dao.entities.Semester;
|
||||
import io.github.wulkanowy.data.db.dao.entities.SemesterDao;
|
||||
import io.github.wulkanowy.data.db.dao.entities.StudentDao;
|
||||
import io.github.wulkanowy.data.db.dao.entities.Subject;
|
||||
@ -37,15 +38,16 @@ public class DbRepository implements DbContract {
|
||||
).unique();
|
||||
}
|
||||
|
||||
public List<Subject> getSubjectList() {
|
||||
return daoSession.getSemesterDao().load(getCurrentSemesterId()).getSubjectList();
|
||||
|
||||
public List<Subject> getSubjectList(int semesterName) {
|
||||
return daoSession.getSemesterDao().load(getSemesterId(semesterName)).getSubjectList();
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Grade> getNewGrades() {
|
||||
public List<Grade> getNewGrades(int semesterName) {
|
||||
return daoSession.getGradeDao().queryBuilder().where(
|
||||
GradeDao.Properties.IsNew.eq(1),
|
||||
GradeDao.Properties.SemesterId.eq(getCurrentSemesterId())
|
||||
GradeDao.Properties.SemesterId.eq(getSemesterId(semesterName))
|
||||
).list();
|
||||
}
|
||||
|
||||
@ -72,11 +74,28 @@ public class DbRepository implements DbContract {
|
||||
).unique().getId();
|
||||
}
|
||||
|
||||
@Override
|
||||
public long getSemesterId(int name) {
|
||||
return daoSession.getSemesterDao().queryBuilder().where(
|
||||
SemesterDao.Properties.DiaryId.eq(getCurrentDiaryId()),
|
||||
SemesterDao.Properties.Name.eq(String.valueOf(name))
|
||||
).unique().getId();
|
||||
}
|
||||
|
||||
@Override
|
||||
public long getCurrentSemesterId() {
|
||||
return getCurrentSemester().getId();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getCurrentSemesterName() {
|
||||
return Integer.valueOf(getCurrentSemester().getName());
|
||||
}
|
||||
|
||||
private Semester getCurrentSemester() {
|
||||
return daoSession.getSemesterDao().queryBuilder().where(
|
||||
SemesterDao.Properties.DiaryId.eq(getCurrentDiaryId()),
|
||||
SemesterDao.Properties.Current.eq(true)
|
||||
).unique().getId();
|
||||
).unique();
|
||||
}
|
||||
}
|
||||
|
@ -16,11 +16,11 @@ public interface SyncContract {
|
||||
|
||||
void initLastUser() throws IOException, CryptoException;
|
||||
|
||||
void syncGrades(long semesterId) throws VulcanException, IOException, ParseException;
|
||||
void syncGrades(int semesterName) throws VulcanException, IOException, ParseException;
|
||||
|
||||
void syncGrades() throws VulcanException, IOException, ParseException;
|
||||
|
||||
void syncSubjects(long semesterId) throws VulcanException, IOException;
|
||||
void syncSubjects(int semesterName) throws VulcanException, IOException;
|
||||
|
||||
void syncSubjects() throws VulcanException, IOException;
|
||||
|
||||
|
@ -48,8 +48,8 @@ public class SyncRepository implements SyncContract {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void syncGrades(long semesterId) throws VulcanException, IOException, ParseException {
|
||||
gradeSync.sync(semesterId);
|
||||
public void syncGrades(int semesterName) throws VulcanException, IOException, ParseException {
|
||||
gradeSync.sync(semesterName);
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -58,8 +58,8 @@ public class SyncRepository implements SyncContract {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void syncSubjects(long semesterId) throws VulcanException, IOException {
|
||||
subjectSync.sync(semesterId);
|
||||
public void syncSubjects(int semesterName) throws VulcanException, IOException {
|
||||
subjectSync.sync(semesterName);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -68,7 +68,7 @@ public class SyncJob extends SimpleJobService {
|
||||
repository.getSyncRepo().initLastUser();
|
||||
repository.getSyncRepo().syncAll();
|
||||
|
||||
gradeList = repository.getDbRepo().getNewGrades();
|
||||
gradeList = repository.getDbRepo().getNewGrades(repository.getDbRepo().getCurrentSemesterName());
|
||||
|
||||
if (!gradeList.isEmpty() && repository.getSharedRepo().isNotifyEnable()) {
|
||||
showNotification();
|
||||
|
@ -5,6 +5,7 @@ import android.content.Intent;
|
||||
import android.graphics.Color;
|
||||
import android.os.Bundle;
|
||||
import android.support.v7.app.ActionBar;
|
||||
import android.support.v7.widget.Toolbar;
|
||||
import android.view.View;
|
||||
|
||||
import com.aurelhubert.ahbottomnavigation.AHBottomNavigation;
|
||||
@ -51,6 +52,7 @@ public class MainActivity extends BaseActivity implements MainContract.View,
|
||||
public void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
setContentView(R.layout.activity_main);
|
||||
setSupportActionBar((Toolbar) findViewById(R.id.toolbar));
|
||||
|
||||
getActivityComponent().inject(this);
|
||||
setButterKnife(ButterKnife.bind(this));
|
||||
|
@ -24,6 +24,8 @@ public interface GradesContract {
|
||||
|
||||
void setActivityTitle();
|
||||
|
||||
void setCurrentSemester(int semester);
|
||||
|
||||
boolean isMenuVisible();
|
||||
|
||||
}
|
||||
@ -36,5 +38,7 @@ public interface GradesContract {
|
||||
void onRefresh();
|
||||
|
||||
void onStart(View view, OnFragmentIsReadyListener listener);
|
||||
|
||||
void onSemesterChange(int which);
|
||||
}
|
||||
}
|
||||
|
@ -1,12 +1,17 @@
|
||||
package io.github.wulkanowy.ui.main.grades;
|
||||
|
||||
import android.content.DialogInterface;
|
||||
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.app.AlertDialog;
|
||||
import android.support.v7.widget.RecyclerView;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.Menu;
|
||||
import android.view.MenuInflater;
|
||||
import android.view.MenuItem;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
|
||||
@ -40,6 +45,8 @@ public class GradesFragment extends BaseFragment implements GradesContract.View
|
||||
@Inject
|
||||
GradesContract.Presenter presenter;
|
||||
|
||||
int currentSemester = -1;
|
||||
|
||||
public GradesFragment() {
|
||||
// empty constructor for fragment
|
||||
}
|
||||
@ -59,6 +66,40 @@ public class GradesFragment extends BaseFragment implements GradesContract.View
|
||||
return view;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onCreate(@Nullable Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
setHasOptionsMenu(true);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
|
||||
inflater.inflate(R.menu.semester_switch, menu);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onOptionsItemSelected(MenuItem item) {
|
||||
if (item.getItemId() == R.id.action_filter) {
|
||||
CharSequence[] items = new CharSequence[]{
|
||||
getResources().getString(R.string.semester_text, 1),
|
||||
getResources().getString(R.string.semester_text, 2),
|
||||
};
|
||||
new AlertDialog.Builder(getContext())
|
||||
.setTitle(R.string.switch_semester)
|
||||
.setNegativeButton(R.string.cancel, null)
|
||||
.setSingleChoiceItems(items, this.currentSemester, new DialogInterface.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(DialogInterface dialog, int which) {
|
||||
presenter.onSemesterChange(which);
|
||||
dialog.cancel();
|
||||
}
|
||||
}).show();
|
||||
return true;
|
||||
} else {
|
||||
return super.onOptionsItemSelected(item);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void setUpOnViewCreated(View fragmentView) {
|
||||
noItemView.setVisibility(View.GONE);
|
||||
@ -87,6 +128,10 @@ public class GradesFragment extends BaseFragment implements GradesContract.View
|
||||
setTitle(getString(R.string.grades_text));
|
||||
}
|
||||
|
||||
public void setCurrentSemester(int currentSemester) {
|
||||
this.currentSemester = currentSemester;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onRefresh() {
|
||||
presenter.onRefresh();
|
||||
|
@ -27,6 +27,8 @@ public class GradesPresenter extends BasePresenter<GradesContract.View>
|
||||
|
||||
private boolean isFirstSight = false;
|
||||
|
||||
private int semesterName;
|
||||
|
||||
@Inject
|
||||
GradesPresenter(RepositoryContract repository) {
|
||||
super(repository);
|
||||
@ -41,15 +43,30 @@ public class GradesPresenter extends BasePresenter<GradesContract.View>
|
||||
getView().setActivityTitle();
|
||||
}
|
||||
|
||||
semesterName = getRepository().getDbRepo().getCurrentSemesterName();
|
||||
getView().setCurrentSemester(semesterName - 1);
|
||||
|
||||
if (!isFirstSight) {
|
||||
isFirstSight = true;
|
||||
|
||||
loadingTask = new AbstractTask();
|
||||
loadingTask.setOnFirstLoadingListener(this);
|
||||
loadingTask.execute();
|
||||
reloadGrades();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onSemesterChange(int which) {
|
||||
semesterName = which + 1;
|
||||
getView().setCurrentSemester(which);
|
||||
|
||||
reloadGrades();
|
||||
}
|
||||
|
||||
private void reloadGrades() {
|
||||
loadingTask = new AbstractTask();
|
||||
loadingTask.setOnFirstLoadingListener(this);
|
||||
loadingTask.execute();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onFragmentVisible(boolean isVisible) {
|
||||
if (isVisible) {
|
||||
@ -71,8 +88,8 @@ public class GradesPresenter extends BasePresenter<GradesContract.View>
|
||||
|
||||
@Override
|
||||
public void onDoInBackgroundRefresh() throws Exception {
|
||||
getRepository().getSyncRepo().syncSubjects();
|
||||
getRepository().getSyncRepo().syncGrades();
|
||||
getRepository().getSyncRepo().syncSubjects(semesterName);
|
||||
getRepository().getSyncRepo().syncGrades(semesterName);
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -85,11 +102,9 @@ public class GradesPresenter extends BasePresenter<GradesContract.View>
|
||||
@Override
|
||||
public void onEndRefreshAsync(boolean success, Exception exception) {
|
||||
if (success) {
|
||||
loadingTask = new AbstractTask();
|
||||
loadingTask.setOnFirstLoadingListener(this);
|
||||
loadingTask.execute();
|
||||
reloadGrades();
|
||||
|
||||
int numberOfNewGrades = getRepository().getDbRepo().getNewGrades().size();
|
||||
int numberOfNewGrades = getRepository().getDbRepo().getNewGrades(semesterName).size();
|
||||
|
||||
if (numberOfNewGrades <= 0) {
|
||||
getView().onRefreshSuccessNoGrade();
|
||||
@ -104,7 +119,7 @@ public class GradesPresenter extends BasePresenter<GradesContract.View>
|
||||
|
||||
@Override
|
||||
public void onDoInBackgroundLoading() {
|
||||
List<Subject> subjectList = getRepository().getDbRepo().getSubjectList();
|
||||
List<Subject> subjectList = getRepository().getDbRepo().getSubjectList(semesterName);
|
||||
boolean isShowSummary = getRepository().getSharedRepo().isShowGradesSummary();
|
||||
|
||||
headerItems = new ArrayList<>();
|
||||
@ -136,12 +151,8 @@ public class GradesPresenter extends BasePresenter<GradesContract.View>
|
||||
|
||||
@Override
|
||||
public void onEndLoadingAsync(boolean result, Exception exception) {
|
||||
if (headerItems.isEmpty()) {
|
||||
getView().showNoItem(true);
|
||||
} else {
|
||||
getView().updateAdapterList(headerItems);
|
||||
getView().showNoItem(false);
|
||||
}
|
||||
getView().showNoItem(headerItems.isEmpty());
|
||||
getView().updateAdapterList(headerItems);
|
||||
listener.onFragmentIsReady();
|
||||
}
|
||||
|
||||
|
5
app/src/main/res/drawable/ic_filter_list_black_24dp.xml
Normal file
5
app/src/main/res/drawable/ic_filter_list_black_24dp.xml
Normal file
@ -0,0 +1,5 @@
|
||||
<vector android:height="24dp" android:tint="#FFFFFF"
|
||||
android:viewportHeight="24.0" android:viewportWidth="24.0"
|
||||
android:width="24dp" xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
<path android:fillColor="#FF000000" android:pathData="M10,18h4v-2h-4v2zM3,6v2h18L21,6L3,6zM6,13h12v-2L6,11v2z"/>
|
||||
</vector>
|
@ -1,33 +1,62 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<android.support.design.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
<LinearLayout 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:id="@+id/main_activity_container"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
tools:context="io.github.wulkanowy.ui.main.MainActivity">
|
||||
android:orientation="vertical"
|
||||
android:weightSum="1"
|
||||
tools:context="io.github.wulkanowy.ui.main.MainActivity"
|
||||
>
|
||||
|
||||
<RelativeLayout
|
||||
android:id="@+id/main_activity_progress_bar"
|
||||
<android.support.design.widget.AppBarLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:gravity="center">
|
||||
android:layout_height="wrap_content"
|
||||
android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"
|
||||
>
|
||||
|
||||
<ProgressBar
|
||||
android:layout_width="wrap_content"
|
||||
<android.support.v7.widget.Toolbar
|
||||
android:id="@+id/toolbar"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="?attr/actionBarSize"
|
||||
android:background="?attr/colorPrimary"
|
||||
app:popupTheme="@style/ThemeOverlay.AppCompat.Light"
|
||||
/>
|
||||
|
||||
</android.support.design.widget.AppBarLayout>
|
||||
|
||||
<android.support.design.widget.CoordinatorLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="0dp"
|
||||
android:layout_weight="1"
|
||||
app:layout_behavior="android.support.design.widget.AppBarLayout$ScrollingViewBehavior"
|
||||
>
|
||||
|
||||
<RelativeLayout
|
||||
android:id="@+id/main_activity_progress_bar"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:gravity="center">
|
||||
|
||||
<ProgressBar
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:indeterminate="true" />
|
||||
</RelativeLayout>
|
||||
|
||||
<com.aurelhubert.ahbottomnavigation.AHBottomNavigationViewPager
|
||||
android:id="@+id/main_activity_view_pager"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:indeterminate="true" />
|
||||
</RelativeLayout>
|
||||
android:layout_marginBottom="@dimen/bottom_navigation_height" />
|
||||
|
||||
<com.aurelhubert.ahbottomnavigation.AHBottomNavigationViewPager
|
||||
android:id="@+id/main_activity_view_pager"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginBottom="@dimen/bottom_navigation_height" />
|
||||
<com.aurelhubert.ahbottomnavigation.AHBottomNavigation
|
||||
android:id="@+id/main_activity_nav"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_gravity="bottom" />
|
||||
|
||||
<com.aurelhubert.ahbottomnavigation.AHBottomNavigation
|
||||
android:id="@+id/main_activity_nav"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_gravity="bottom" />
|
||||
</android.support.design.widget.CoordinatorLayout>
|
||||
|
||||
</android.support.design.widget.CoordinatorLayout>
|
||||
</LinearLayout>
|
||||
|
13
app/src/main/res/menu/semester_switch.xml
Normal file
13
app/src/main/res/menu/semester_switch.xml
Normal file
@ -0,0 +1,13 @@
|
||||
<menu 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"
|
||||
tools:context="io.github.wulkanowy.timetable.MainActivity"
|
||||
>
|
||||
<item
|
||||
android:id="@+id/action_filter"
|
||||
android:orderInCategory="100"
|
||||
android:title="@string/switch_semester"
|
||||
android:icon="@drawable/ic_filter_list_black_24dp"
|
||||
app:showAsAction="always"
|
||||
/>
|
||||
</menu>
|
@ -52,6 +52,10 @@
|
||||
<string name="dialog_date_text">Data</string>
|
||||
<string name="dialog_color_text">Kolor</string>
|
||||
|
||||
<string name="switch_semester">Zmień semestr</string>
|
||||
<string name="semester_text">Semestr %d</string>
|
||||
<string name="cancel">Anuluj</string>
|
||||
|
||||
<string name="timetable_dialog_lesson">Lekcja</string>
|
||||
<string name="timetable_dialog_room">Sala</string>
|
||||
<string name="timetable_dialog_group">Grupa</string>
|
||||
|
@ -52,6 +52,10 @@
|
||||
<string name="dialog_date_text">Date</string>
|
||||
<string name="dialog_color_text">Color</string>
|
||||
|
||||
<string name="switch_semester">Switch semester</string>
|
||||
<string name="semester_text">Semester %d</string>
|
||||
<string name="cancel">Cancel</string>
|
||||
|
||||
<string name="timetable_dialog_lesson">Lesson</string>
|
||||
<string name="timetable_dialog_room">Room</string>
|
||||
<string name="timetable_dialog_group">Group</string>
|
||||
|
@ -1,6 +1,6 @@
|
||||
<resources>
|
||||
|
||||
<style name="WulkanowyTheme" parent="Base.Theme.AppCompat.Light">
|
||||
<style name="WulkanowyTheme" parent="@style/Theme.AppCompat.Light.NoActionBar">
|
||||
<item name="colorPrimary">@color/colorPrimary</item>
|
||||
<item name="colorPrimaryDark">@color/colorPrimaryDark</item>
|
||||
<item name="colorAccent">@color/colorPrimary</item>
|
||||
|
Loading…
x
Reference in New Issue
Block a user