mirror of
https://github.com/wulkanowy/wulkanowy.git
synced 2025-01-19 00:16:48 -06:00
Add info about predicted and final ratings (#88)
This commit is contained in:
parent
176d17e1ec
commit
7dde13585c
@ -88,6 +88,11 @@ public class Repository implements RepositoryContract {
|
||||
return sharedPref.getStartupTab();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isShowGradesSummary() {
|
||||
return sharedPref.isShowGradesSummary();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getServicesInterval() {
|
||||
return sharedPref.getServicesInterval();
|
||||
|
@ -29,6 +29,8 @@ public interface RepositoryContract extends ResourcesContract, AccountSyncContra
|
||||
|
||||
boolean isNotifyEnable();
|
||||
|
||||
boolean isShowGradesSummary();
|
||||
|
||||
int getServicesInterval();
|
||||
|
||||
boolean isMobileDisable();
|
||||
|
@ -55,6 +55,11 @@ public class SharedPref implements SharedPrefContract {
|
||||
return Integer.parseInt(settingsSharedPref.getString(SettingsFragment.SHARED_KEY_START_TAB, "2"));
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isShowGradesSummary() {
|
||||
return settingsSharedPref.getBoolean(SettingsFragment.SHARED_KEY_GRADES_SUMMARY, false);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getServicesInterval() {
|
||||
return Integer.parseInt(settingsSharedPref.getString(SettingsFragment.SHARED_KEY_SERVICES_INTERVAL, "60"));
|
||||
|
@ -12,6 +12,8 @@ public interface SharedPrefContract {
|
||||
|
||||
int getStartupTab();
|
||||
|
||||
boolean isShowGradesSummary();
|
||||
|
||||
int getServicesInterval();
|
||||
|
||||
boolean isMobileDisable();
|
||||
|
@ -35,7 +35,9 @@ public class SubjectSync implements SyncContract {
|
||||
public void sync(long semesterId) throws VulcanException, IOException {
|
||||
this.semesterId = semesterId;
|
||||
|
||||
List<Subject> lastList = getUpdatedList(getSubjectsFromNet());
|
||||
Semester semester = daoSession.getSemesterDao().load(semesterId);
|
||||
|
||||
List<Subject> lastList = getUpdatedList(getSubjectsFromNet(semester));
|
||||
|
||||
daoSession.getSubjectDao().deleteInTx(getSubjectsFromDb());
|
||||
daoSession.getSubjectDao().insertInTx(lastList);
|
||||
@ -43,9 +45,9 @@ public class SubjectSync implements SyncContract {
|
||||
LogUtils.debug("Synchronization subjects (amount = " + lastList.size() + ")");
|
||||
}
|
||||
|
||||
private List<Subject> getSubjectsFromNet() throws VulcanException, IOException {
|
||||
private List<Subject> getSubjectsFromNet(Semester semester) throws VulcanException, IOException {
|
||||
return DataObjectConverter.subjectsToSubjectEntities(
|
||||
vulcan.getSubjectsList().getAll(String.valueOf(semesterId)), semesterId);
|
||||
vulcan.getSubjectsList().getAll(semester.getValue()), semesterId);
|
||||
}
|
||||
|
||||
private List<Subject> getSubjectsFromDb() {
|
||||
|
@ -17,6 +17,7 @@ import eu.davidea.flexibleadapter.items.AbstractExpandableHeaderItem;
|
||||
import eu.davidea.viewholders.ExpandableViewHolder;
|
||||
import io.github.wulkanowy.R;
|
||||
import io.github.wulkanowy.data.db.dao.entities.Subject;
|
||||
import io.github.wulkanowy.utils.AnimationUtils;
|
||||
import io.github.wulkanowy.utils.AverageCalculator;
|
||||
|
||||
public class GradeHeaderItem
|
||||
@ -24,8 +25,11 @@ public class GradeHeaderItem
|
||||
|
||||
private Subject subject;
|
||||
|
||||
GradeHeaderItem(Subject subject) {
|
||||
private final boolean isShowSummary;
|
||||
|
||||
GradeHeaderItem(Subject subject, boolean isShowSummary) {
|
||||
this.subject = subject;
|
||||
this.isShowSummary = isShowSummary;
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -55,7 +59,7 @@ public class GradeHeaderItem
|
||||
|
||||
@Override
|
||||
public HeaderViewHolder createViewHolder(View view, FlexibleAdapter adapter) {
|
||||
return new HeaderViewHolder(view, adapter);
|
||||
return new HeaderViewHolder(view, adapter, isShowSummary);
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -74,16 +78,27 @@ public class GradeHeaderItem
|
||||
@BindView(R.id.grade_header_number_of_grade_text)
|
||||
TextView numberText;
|
||||
|
||||
@BindView(R.id.grade_header_predicted_rating_text)
|
||||
TextView predictedTest;
|
||||
|
||||
@BindView(R.id.grade_header_final_rating_text)
|
||||
TextView finalText;
|
||||
|
||||
@BindView(R.id.grade_header_alert_image)
|
||||
View alertImage;
|
||||
|
||||
Resources resources;
|
||||
|
||||
HeaderViewHolder(View view, FlexibleAdapter adapter) {
|
||||
private boolean isSummaryTogglable = true;
|
||||
|
||||
private boolean isShowSummary;
|
||||
|
||||
HeaderViewHolder(View view, FlexibleAdapter adapter, boolean isShowSummary) {
|
||||
super(view, adapter);
|
||||
ButterKnife.bind(this, view);
|
||||
resources = view.getResources();
|
||||
view.setOnClickListener(this);
|
||||
this.isShowSummary = isShowSummary;
|
||||
}
|
||||
|
||||
void onBind(Subject item, List<GradesSubItem> subItems) {
|
||||
@ -91,6 +106,29 @@ public class GradeHeaderItem
|
||||
numberText.setText(resources.getQuantityString(R.plurals.numberOfGradesPlurals,
|
||||
subItems.size(), subItems.size()));
|
||||
averageText.setText(getGradesAverageString(item));
|
||||
|
||||
predictedTest.setText(resources.getString(R.string.info_grades_predicted_rating,
|
||||
item.getPredictedRating()));
|
||||
finalText.setText(resources.getString(R.string.info_grades_final_rating,
|
||||
item.getFinalRating()));
|
||||
predictedTest.setVisibility(View.GONE);
|
||||
finalText.setVisibility(View.GONE);
|
||||
|
||||
boolean isSummaryEmpty = true;
|
||||
|
||||
if (!"-".equals(item.getPredictedRating()) || !"-".equals(item.getFinalRating())) {
|
||||
isSummaryEmpty = false;
|
||||
}
|
||||
|
||||
if (isSummaryEmpty) {
|
||||
isSummaryTogglable = false;
|
||||
} else if (isShowSummary) {
|
||||
predictedTest.setVisibility(View.VISIBLE);
|
||||
finalText.setVisibility(View.VISIBLE);
|
||||
|
||||
isSummaryTogglable = false;
|
||||
}
|
||||
|
||||
alertImage.setVisibility(isSubItemsReadAndSaveAlertView(subItems)
|
||||
? View.INVISIBLE : View.VISIBLE);
|
||||
}
|
||||
@ -103,6 +141,19 @@ public class GradeHeaderItem
|
||||
} else {
|
||||
subjectName.setMaxLines(1);
|
||||
}
|
||||
|
||||
if (isSummaryTogglable) {
|
||||
toggleText(predictedTest);
|
||||
toggleText(finalText);
|
||||
}
|
||||
}
|
||||
|
||||
private void toggleText(final View view) {
|
||||
if (view.getVisibility() == View.GONE) {
|
||||
AnimationUtils.slideDown(view);
|
||||
} else {
|
||||
AnimationUtils.slideUp(view);
|
||||
}
|
||||
}
|
||||
|
||||
private boolean isSubItemsReadAndSaveAlertView(List<GradesSubItem> subItems) {
|
||||
@ -112,6 +163,7 @@ public class GradeHeaderItem
|
||||
isRead = item.getGrade().getRead();
|
||||
item.setSubjectAlertImage(alertImage);
|
||||
}
|
||||
|
||||
return isRead;
|
||||
}
|
||||
|
||||
@ -120,9 +172,9 @@ public class GradeHeaderItem
|
||||
|
||||
if (average < 0) {
|
||||
return resources.getString(R.string.info_no_average);
|
||||
} else {
|
||||
return resources.getString(R.string.info_average_grades, average);
|
||||
}
|
||||
|
||||
return resources.getString(R.string.info_average_grades, average);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -105,6 +105,7 @@ public class GradesPresenter extends BasePresenter<GradesContract.View>
|
||||
@Override
|
||||
public void onDoInBackgroundLoading() {
|
||||
List<Subject> subjectList = getRepository().getSubjectList();
|
||||
boolean isShowSummary = getRepository().isShowGradesSummary();
|
||||
|
||||
headerItems = new ArrayList<>();
|
||||
|
||||
@ -113,7 +114,7 @@ public class GradesPresenter extends BasePresenter<GradesContract.View>
|
||||
List<Grade> gradeList = subject.getGradeList();
|
||||
|
||||
if (!gradeList.isEmpty()) {
|
||||
GradeHeaderItem headerItem = new GradeHeaderItem(subject);
|
||||
GradeHeaderItem headerItem = new GradeHeaderItem(subject, isShowSummary);
|
||||
|
||||
List<GradesSubItem> subItems = new ArrayList<>();
|
||||
|
||||
|
@ -12,6 +12,8 @@ public class SettingsFragment extends PreferenceFragmentCompat
|
||||
|
||||
public static final String SHARED_KEY_START_TAB = "startup_tab";
|
||||
|
||||
public static final String SHARED_KEY_GRADES_SUMMARY = "grades_summary";
|
||||
|
||||
public static final String SHARED_KEY_SERVICES_ENABLE = "services_enable";
|
||||
|
||||
public static final String SHARED_KEY_NOTIFY_ENABLE = "notify_enable";
|
||||
|
@ -0,0 +1,40 @@
|
||||
package io.github.wulkanowy.utils;
|
||||
|
||||
import android.animation.Animator;
|
||||
import android.animation.AnimatorListenerAdapter;
|
||||
import android.view.View;
|
||||
|
||||
public final class AnimationUtils {
|
||||
|
||||
public static void slideDown(final View view) {
|
||||
view.setVisibility(View.VISIBLE);
|
||||
view.setAlpha(0.f);
|
||||
|
||||
view.setTranslationY(-(view.getHeight() / 2));
|
||||
view.animate()
|
||||
.translationY(0)
|
||||
.alpha(1.f)
|
||||
.setListener(new AnimatorListenerAdapter() {
|
||||
@Override
|
||||
public void onAnimationEnd(Animator animation) {
|
||||
view.setVisibility(View.VISIBLE);
|
||||
view.setAlpha(1.f);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public static void slideUp(final View view) {
|
||||
view.animate()
|
||||
.translationY(-(view.getHeight() / 2))
|
||||
.alpha(0.f)
|
||||
.setListener(new AnimatorListenerAdapter() {
|
||||
@Override
|
||||
public void onAnimationEnd(Animator animation) {
|
||||
// superfluous restoration
|
||||
view.setVisibility(View.GONE);
|
||||
view.setAlpha(1.f);
|
||||
view.setTranslationY(0.f);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
@ -46,6 +46,30 @@
|
||||
android:textColor="@color/secondary_text"
|
||||
android:textSize="12sp" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/grade_header_predicted_rating_text"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_below="@id/grade_header_average_text"
|
||||
android:layout_marginTop="5dp"
|
||||
android:text="@string/info_grades_predicted_rating"
|
||||
android:textColor="@color/secondary_text"
|
||||
android:textSize="12sp" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/grade_header_final_rating_text"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_below="@id/grade_header_average_text"
|
||||
android:layout_marginLeft="10dp"
|
||||
android:layout_marginStart="10dp"
|
||||
android:layout_marginTop="5dp"
|
||||
android:layout_toEndOf="@+id/grade_header_predicted_rating_text"
|
||||
android:layout_toRightOf="@+id/grade_header_predicted_rating_text"
|
||||
android:text="@string/info_grades_final_rating"
|
||||
android:textColor="@color/secondary_text"
|
||||
android:textSize="12sp" />
|
||||
|
||||
<ImageView
|
||||
android:id="@+id/grade_header_alert_image"
|
||||
android:layout_width="wrap_content"
|
||||
@ -55,4 +79,4 @@
|
||||
android:layout_marginTop="10dp"
|
||||
app:srcCompat="@drawable/ic_alert_24dp"
|
||||
tool:ignore="contentDescription" />
|
||||
</RelativeLayout>
|
||||
</RelativeLayout>
|
||||
|
@ -72,6 +72,8 @@
|
||||
|
||||
<string name="info_average_grades">Średnia: %1$.2f</string>
|
||||
<string name="info_no_average">Brak średniej</string>
|
||||
<string name="info_grades_predicted_rating">Przewidywana: %1$s</string>
|
||||
<string name="info_grades_final_rating">Końcowa: %1$s</string>
|
||||
<string name="info_free_week">Brak lekcji w tym tygodniu</string>
|
||||
<string name="timetable_subitem_room">Sala %s</string>
|
||||
|
||||
@ -114,11 +116,15 @@
|
||||
<item quantity="many">%1$d nieobecności</item>
|
||||
</plurals>
|
||||
|
||||
<string name="pref_view">Widok</string>
|
||||
|
||||
<string name="pref_view_header">Widok</string>
|
||||
<string name="pref_tab_list">Domyślny widok</string>
|
||||
<string name="pref_notify">Powiadomienia</string>
|
||||
<string name="pref_grades_summary_line_show">Pokazuj podsumowanie w ocenach</string>
|
||||
|
||||
<string name="pref_notify_header">Powiadomienia</string>
|
||||
<string name="pref_notify_switch">Pokazuj powiadomienia</string>
|
||||
<string name="pref_services">Usługi</string>
|
||||
|
||||
<string name="pref_services_header">Usługi</string>
|
||||
<string name="pref_services_switch">Włącz odświeżanie danych w tle</string>
|
||||
<string name="pref_services_interval">Interwał między odświeżaniem danych</string>
|
||||
<string name="pref_services_mobile_data">Synchronizacja tylko przez WiFi</string>
|
||||
|
@ -72,6 +72,8 @@
|
||||
|
||||
<string name="info_average_grades">Average: %1$.2f</string>
|
||||
<string name="info_no_average">No average</string>
|
||||
<string name="info_grades_predicted_rating">Predicted: %1$s</string>
|
||||
<string name="info_grades_final_rating">Final: %1$s</string>
|
||||
<string name="info_free_week">No lesson in this week</string>
|
||||
|
||||
<string name="timetable_subitem_room">Room %s</string>
|
||||
@ -110,11 +112,14 @@
|
||||
<item quantity="other">%1$d absences</item>
|
||||
</plurals>
|
||||
|
||||
<string name="pref_view_header">View</string>
|
||||
<string name="pref_tab_list">Default view after startup</string>
|
||||
<string name="pref_view">View</string>
|
||||
<string name="pref_notify">Notifications</string>
|
||||
<string name="pref_grades_summary_line_show">Show summary in grades</string>
|
||||
|
||||
<string name="pref_notify_header">Notifications</string>
|
||||
<string name="pref_notify_switch">Show the notifications</string>
|
||||
<string name="pref_services">Services</string>
|
||||
|
||||
<string name="pref_services_header">Services</string>
|
||||
<string name="pref_services_switch">Enable background data refreshing</string>
|
||||
<string name="pref_services_interval">Interval between data refreshing</string>
|
||||
<string name="pref_services_mobile_data">Synchronization via WiFi only</string>
|
||||
|
@ -1,6 +1,6 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
<PreferenceCategory android:title="@string/pref_view">
|
||||
<PreferenceCategory android:title="@string/pref_view_header">
|
||||
<ListPreference
|
||||
android:defaultValue="2"
|
||||
android:entries="@array/startup_tab_entries"
|
||||
@ -8,8 +8,12 @@
|
||||
android:key="startup_tab"
|
||||
android:summary="%s"
|
||||
android:title="@string/pref_tab_list" />
|
||||
<SwitchPreference
|
||||
android:defaultValue="false"
|
||||
android:key="grades_summary"
|
||||
android:title="@string/pref_grades_summary_line_show"/>
|
||||
</PreferenceCategory>
|
||||
<PreferenceCategory android:title="@string/pref_services">
|
||||
<PreferenceCategory android:title="@string/pref_services_header">
|
||||
<SwitchPreference
|
||||
android:defaultValue="true"
|
||||
android:key="services_enable"
|
||||
@ -28,11 +32,11 @@
|
||||
android:title="@string/pref_services_mobile_data"
|
||||
android:dependency="services_enable" />
|
||||
</PreferenceCategory>
|
||||
<PreferenceCategory android:title="@string/pref_notify">
|
||||
<PreferenceCategory android:title="@string/pref_notify_header">
|
||||
<SwitchPreference
|
||||
android:defaultValue="true"
|
||||
android:dependency="services_enable"
|
||||
android:key="notify_enable"
|
||||
android:title="@string/pref_notify_switch" />
|
||||
</PreferenceCategory>
|
||||
</PreferenceScreen>
|
||||
</PreferenceScreen>
|
||||
|
Loading…
x
Reference in New Issue
Block a user