Add option to show only student plan lessons (#654)

This commit is contained in:
Mikołaj Pich 2020-01-20 22:18:26 +01:00 committed by Rafał Borcz
parent e9fa95f113
commit ad3bb3a522
21 changed files with 1835 additions and 15 deletions

View File

@ -122,7 +122,7 @@ configurations.all {
} }
dependencies { dependencies {
implementation "io.github.wulkanowy:sdk:0.14.2" implementation "io.github.wulkanowy:sdk:8ad4480"
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk8:$kotlin_version" implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk8:$kotlin_version"
implementation "androidx.core:core-ktx:1.2.0-rc01" implementation "androidx.core:core-ktx:1.2.0-rc01"

File diff suppressed because it is too large Load Diff

View File

@ -21,6 +21,7 @@ fun createTimetableLocal(start: LocalDateTime, number: Int, room: String = "", s
teacher = teacher, teacher = teacher,
teacherOld = "", teacherOld = "",
info = "", info = "",
studentPlan = true,
changes = changes, changes = changes,
canceled = false canceled = false
) )

View File

@ -60,6 +60,7 @@ import io.github.wulkanowy.data.db.migrations.Migration17
import io.github.wulkanowy.data.db.migrations.Migration18 import io.github.wulkanowy.data.db.migrations.Migration18
import io.github.wulkanowy.data.db.migrations.Migration19 import io.github.wulkanowy.data.db.migrations.Migration19
import io.github.wulkanowy.data.db.migrations.Migration2 import io.github.wulkanowy.data.db.migrations.Migration2
import io.github.wulkanowy.data.db.migrations.Migration20
import io.github.wulkanowy.data.db.migrations.Migration3 import io.github.wulkanowy.data.db.migrations.Migration3
import io.github.wulkanowy.data.db.migrations.Migration4 import io.github.wulkanowy.data.db.migrations.Migration4
import io.github.wulkanowy.data.db.migrations.Migration5 import io.github.wulkanowy.data.db.migrations.Migration5
@ -101,7 +102,7 @@ import javax.inject.Singleton
abstract class AppDatabase : RoomDatabase() { abstract class AppDatabase : RoomDatabase() {
companion object { companion object {
const val VERSION_SCHEMA = 19 const val VERSION_SCHEMA = 20
fun getMigrations(sharedPrefProvider: SharedPrefProvider): Array<Migration> { fun getMigrations(sharedPrefProvider: SharedPrefProvider): Array<Migration> {
return arrayOf( return arrayOf(
@ -122,7 +123,8 @@ abstract class AppDatabase : RoomDatabase() {
Migration16(), Migration16(),
Migration17(), Migration17(),
Migration18(), Migration18(),
Migration19(sharedPrefProvider) Migration19(sharedPrefProvider),
Migration20()
) )
} }

View File

@ -40,6 +40,9 @@ data class Timetable(
val info: String, val info: String,
@ColumnInfo(name = "student_plan")
val studentPlan: Boolean,
val changes: Boolean, val changes: Boolean,
val canceled: Boolean val canceled: Boolean

View File

@ -0,0 +1,33 @@
package io.github.wulkanowy.data.db.migrations
import androidx.room.migration.Migration
import androidx.sqlite.db.SupportSQLiteDatabase
class Migration20 : Migration(19, 20) {
override fun migrate(database: SupportSQLiteDatabase) {
database.execSQL("DROP TABLE Timetable")
database.execSQL("""
CREATE TABLE IF NOT EXISTS `Timetable` (
`id` INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL,
`student_id` INTEGER NOT NULL,
`diary_id` INTEGER NOT NULL,
`number` INTEGER NOT NULL,
`start` INTEGER NOT NULL,
`end` INTEGER NOT NULL,
`date` INTEGER NOT NULL,
`subject` TEXT NOT NULL,
`subjectOld` TEXT NOT NULL,
`group` TEXT NOT NULL,
`room` TEXT NOT NULL,
`roomOld` TEXT NOT NULL,
`teacher` TEXT NOT NULL,
`teacherOld` TEXT NOT NULL,
`info` TEXT NOT NULL,
`student_plan` INTEGER NOT NULL,
`changes` INTEGER NOT NULL,
`canceled` INTEGER NOT NULL
)
""")
}
}

View File

@ -65,6 +65,9 @@ class PreferencesRepository @Inject constructor(
val fillMessageContent: Boolean val fillMessageContent: Boolean
get() = getBoolean(R.string.pref_key_fill_message_content, R.bool.pref_default_fill_message_content) get() = getBoolean(R.string.pref_key_fill_message_content, R.bool.pref_default_fill_message_content)
val showWholeClassPlan: String
get() = getString(R.string.pref_key_timetable_show_whole_class, R.string.pref_default_timetable_show_whole_class)
private fun getString(id: Int, default: Int) = getString(context.getString(id), default) private fun getString(id: Int, default: Int) = getString(context.getString(id), default)
private fun getString(id: String, default: Int) = sharedPref.getString(id, context.getString(default)) ?: context.getString(default) private fun getString(id: String, default: Int) = sharedPref.getString(id, context.getString(default)) ?: context.getString(default)

View File

@ -36,7 +36,7 @@ class SemesterRepository @Inject constructor(
local.saveSemesters(new.uniqueSubtract(old)) local.saveSemesters(new.uniqueSubtract(old))
} }
} else { } else {
Timber.i("Current semesters list:\n${currentSemesters.joinToString(separator = "\n")}") Timber.i("Current semesters list:\n${new.joinToString(separator = "\n")}")
throw IllegalArgumentException("Current semester can be only one.") throw IllegalArgumentException("Current semester can be only one.")
} }
}.flatMap { local.getSemesters(student).toSingle(emptyList()) }) }.flatMap { local.getSemesters(student).toSingle(emptyList()) })

View File

@ -30,6 +30,7 @@ class TimetableRemote @Inject constructor(private val sdk: Sdk) {
teacher = it.teacher, teacher = it.teacher,
teacherOld = it.teacherOld, teacherOld = it.teacherOld,
info = it.info, info = it.info,
studentPlan = it.studentPlan,
changes = it.changes, changes = it.changes,
canceled = it.canceled canceled = it.canceled
) )

View File

@ -15,11 +15,15 @@ import io.github.wulkanowy.utils.getThemeAttrColor
import io.github.wulkanowy.utils.toFormattedString import io.github.wulkanowy.utils.toFormattedString
import kotlinx.android.extensions.LayoutContainer import kotlinx.android.extensions.LayoutContainer
import kotlinx.android.synthetic.main.item_timetable.* import kotlinx.android.synthetic.main.item_timetable.*
import kotlinx.android.synthetic.main.item_timetable_small.*
class TimetableItem(val lesson: Timetable) : class TimetableItem(val lesson: Timetable, private val showWholeClassPlan: String) :
AbstractFlexibleItem<TimetableItem.ViewHolder>() { AbstractFlexibleItem<TimetableItem.ViewHolder>() {
override fun getLayoutRes() = R.layout.item_timetable override fun getLayoutRes() = when {
showWholeClassPlan == "small" && !lesson.studentPlan -> R.layout.item_timetable_small
else -> R.layout.item_timetable
}
override fun createViewHolder(view: View, adapter: FlexibleAdapter<IFlexible<*>>): ViewHolder { override fun createViewHolder(view: View, adapter: FlexibleAdapter<IFlexible<*>>): ViewHolder {
return ViewHolder(view, adapter) return ViewHolder(view, adapter)
@ -27,16 +31,29 @@ class TimetableItem(val lesson: Timetable) :
@SuppressLint("SetTextI18n") @SuppressLint("SetTextI18n")
override fun bindViewHolder(adapter: FlexibleAdapter<IFlexible<*>>, holder: ViewHolder, position: Int, payloads: MutableList<Any>?) { override fun bindViewHolder(adapter: FlexibleAdapter<IFlexible<*>>, holder: ViewHolder, position: Int, payloads: MutableList<Any>?) {
updateFields(holder) when (itemViewType) {
R.layout.item_timetable_small -> {
with(holder) {
timetableSmallItemNumber.text = lesson.number.toString()
timetableSmallItemSubject.text = lesson.subject
timetableSmallItemTimeStart.text = lesson.start.toFormattedString("HH:mm")
timetableSmallItemRoom.text = lesson.room
timetableSmallItemTeacher.text = lesson.teacher
}
}
R.layout.item_timetable -> {
updateFields(holder)
with(holder) { with(holder) {
timetableItemSubject.paintFlags = timetableItemSubject.paintFlags =
if (lesson.canceled) timetableItemSubject.paintFlags or Paint.STRIKE_THRU_TEXT_FLAG if (lesson.canceled) timetableItemSubject.paintFlags or Paint.STRIKE_THRU_TEXT_FLAG
else timetableItemSubject.paintFlags and Paint.STRIKE_THRU_TEXT_FLAG.inv() else timetableItemSubject.paintFlags and Paint.STRIKE_THRU_TEXT_FLAG.inv()
}
updateDescription(holder)
updateColors(holder)
}
} }
updateDescription(holder)
updateColors(holder)
} }
private fun updateFields(holder: ViewHolder) { private fun updateFields(holder: ViewHolder) {

View File

@ -2,6 +2,8 @@ package io.github.wulkanowy.ui.modules.timetable
import android.annotation.SuppressLint import android.annotation.SuppressLint
import eu.davidea.flexibleadapter.items.AbstractFlexibleItem import eu.davidea.flexibleadapter.items.AbstractFlexibleItem
import io.github.wulkanowy.data.db.entities.Timetable
import io.github.wulkanowy.data.repositories.preferences.PreferencesRepository
import io.github.wulkanowy.data.repositories.semester.SemesterRepository import io.github.wulkanowy.data.repositories.semester.SemesterRepository
import io.github.wulkanowy.data.repositories.student.StudentRepository import io.github.wulkanowy.data.repositories.student.StudentRepository
import io.github.wulkanowy.data.repositories.timetable.TimetableRepository import io.github.wulkanowy.data.repositories.timetable.TimetableRepository
@ -29,6 +31,7 @@ class TimetablePresenter @Inject constructor(
studentRepository: StudentRepository, studentRepository: StudentRepository,
private val timetableRepository: TimetableRepository, private val timetableRepository: TimetableRepository,
private val semesterRepository: SemesterRepository, private val semesterRepository: SemesterRepository,
private val prefRepository: PreferencesRepository,
private val analytics: FirebaseAnalyticsHelper private val analytics: FirebaseAnalyticsHelper
) : BasePresenter<TimetableView>(errorHandler, studentRepository, schedulers) { ) : BasePresenter<TimetableView>(errorHandler, studentRepository, schedulers) {
@ -134,7 +137,7 @@ class TimetablePresenter @Inject constructor(
.flatMap { semesterRepository.getCurrentSemester(it) } .flatMap { semesterRepository.getCurrentSemester(it) }
.delay(200, MILLISECONDS) .delay(200, MILLISECONDS)
.flatMap { timetableRepository.getTimetable(it, currentDate, currentDate, forceRefresh) } .flatMap { timetableRepository.getTimetable(it, currentDate, currentDate, forceRefresh) }
.map { items -> items.map { TimetableItem(it) } } .map { createTimetableItems(it) }
.map { items -> items.sortedBy { it.lesson.number } } .map { items -> items.sortedBy { it.lesson.number } }
.subscribeOn(schedulers.backgroundThread) .subscribeOn(schedulers.backgroundThread)
.observeOn(schedulers.mainThread) .observeOn(schedulers.mainThread)
@ -172,6 +175,12 @@ class TimetablePresenter @Inject constructor(
} }
} }
private fun createTimetableItems(items: List<Timetable>): List<TimetableItem> {
return items
.filter { if (prefRepository.showWholeClassPlan == "no") it.studentPlan else true }
.map { TimetableItem(it, prefRepository.showWholeClassPlan) }
}
private fun reloadView() { private fun reloadView() {
Timber.i("Reload timetable view with the date ${currentDate.toFormattedString()}") Timber.i("Reload timetable view with the date ${currentDate.toFormattedString()}")
view?.apply { view?.apply {

View File

@ -0,0 +1,81 @@
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="?selectableItemBackground"
tools:context=".ui.modules.timetable.TimetableItem">
<TextView
android:id="@+id/timetableSmallItemNumber"
android:layout_width="40dp"
android:layout_height="wrap_content"
android:layout_marginStart="8dp"
android:layout_marginLeft="8dp"
android:gravity="center"
android:maxLength="2"
android:textColor="?android:textColorPrimary"
android:textSize="15sp"
tools:text="5" />
<TextView
android:id="@+id/timetableSmallItemTimeStart"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignTop="@id/timetableSmallItemNumber"
android:layout_marginStart="8dp"
android:layout_marginLeft="8dp"
android:layout_toEndOf="@id/timetableSmallItemNumber"
android:layout_toRightOf="@id/timetableSmallItemNumber"
android:maxLines="1"
android:textColor="?android:textColorSecondary"
android:textSize="15sp"
tools:text="11:11" />
<TextView
android:id="@+id/timetableSmallItemSubject"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_marginStart="10dp"
android:layout_marginLeft="10dp"
android:layout_marginEnd="10dp"
android:layout_marginRight="10dp"
android:layout_toEndOf="@+id/timetableSmallItemTimeStart"
android:layout_toRightOf="@+id/timetableSmallItemTimeStart"
android:ellipsize="end"
android:maxLines="1"
android:textColor="?android:textColorPrimary"
android:textSize="15sp"
tools:text="Sieci komputerowe" />
<TextView
android:id="@+id/timetableSmallItemRoom"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="10dp"
android:layout_marginLeft="10dp"
android:layout_toEndOf="@+id/timetableSmallItemSubject"
android:layout_toRightOf="@+id/timetableSmallItemSubject"
android:maxLines="1"
android:textColor="?android:textColorSecondary"
android:textSize="15sp"
tools:text="22" />
<TextView
android:id="@+id/timetableSmallItemTeacher"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="10dp"
android:layout_marginLeft="10dp"
android:layout_marginEnd="16dp"
android:layout_marginRight="16dp"
android:layout_toEndOf="@id/timetableSmallItemRoom"
android:layout_toRightOf="@id/timetableSmallItemRoom"
android:ellipsize="end"
android:maxLines="1"
android:textColor="?android:textColorSecondary"
android:textSize="15sp"
tools:text="Agata Kowalska - Błaszczyk" />
</RelativeLayout>

View File

@ -41,4 +41,10 @@
<item>Średnia ocen z 2 semestru</item> <item>Średnia ocen z 2 semestru</item>
<item>Średnia ocen z całego roku</item> <item>Średnia ocen z całego roku</item>
</string-array> </string-array>
<string-array name="timetable_show_whole_class_entries">
<item>Nie pokazuj</item>
<item>Pokazuj wszystkie</item>
<item>Pokazuj pomniejszone</item>
</string-array>
</resources> </resources>

View File

@ -366,4 +366,5 @@
<string name="error_unknown">Wystąpił nieoczekiwany błąd</string> <string name="error_unknown">Wystąpił nieoczekiwany błąd</string>
<string name="error_feature_disabled">Funkcja wyłączona przez szkołę</string> <string name="error_feature_disabled">Funkcja wyłączona przez szkołę</string>
<string name="error_feature_not_available">Funkcja niedostępna w tym trybie</string> <string name="error_feature_not_available">Funkcja niedostępna w tym trybie</string>
<string name="pref_view_timetable_show_whole_class">Pokazuj lekcje całej klasy</string>
</resources> </resources>

View File

@ -36,4 +36,10 @@
<item>Средняя оценка со 2 семестра</item> <item>Средняя оценка со 2 семестра</item>
<item>Средняя оценка с целого года</item> <item>Средняя оценка с целого года</item>
</string-array> </string-array>
<string-array name="timetable_show_whole_class_entries">
<item>Не показывать</item>
<item>Показать все</item>
<item>Показать меньше</item>
</string-array>
</resources> </resources>

View File

@ -364,5 +364,6 @@
<string name="error_unknown">Произошла неожиданная ошибка</string> <string name="error_unknown">Произошла неожиданная ошибка</string>
<string name="error_feature_disabled">Функция была выключена школой</string> <string name="error_feature_disabled">Функция была выключена школой</string>
<string name="error_feature_not_available">Функция не доступна в этом режиме</string> <string name="error_feature_not_available">Функция не доступна в этом режиме</string>
<string name="pref_view_timetable_show_whole_class">Показать уроки всего класса</string>
</resources> </resources>

View File

@ -16,4 +16,5 @@
<string name="pref_default_grade_modifier_plus">0.33</string> <string name="pref_default_grade_modifier_plus">0.33</string>
<string name="pref_default_grade_modifier_minus">0.33</string> <string name="pref_default_grade_modifier_minus">0.33</string>
<bool name="pref_default_fill_message_content">true</bool> <bool name="pref_default_fill_message_content">true</bool>
<string name="pref_default_timetable_show_whole_class">no</string>
</resources> </resources>

View File

@ -16,4 +16,5 @@
<string name="pref_key_grade_modifier_plus">grade_modifier_plus</string> <string name="pref_key_grade_modifier_plus">grade_modifier_plus</string>
<string name="pref_key_grade_modifier_minus">grade_modifier_minus</string> <string name="pref_key_grade_modifier_minus">grade_modifier_minus</string>
<string name="pref_key_fill_message_content">fill_message_content</string> <string name="pref_key_fill_message_content">fill_message_content</string>
<string name="pref_key_timetable_show_whole_class">show_whole_class_plan</string>
</resources> </resources>

View File

@ -90,4 +90,15 @@
<item>only_one_semester</item> <item>only_one_semester</item>
<item>all_year</item> <item>all_year</item>
</string-array> </string-array>
<string-array name="timetable_show_whole_class_entries">
<item>No show</item>
<item>Show all</item>
<item>Show smaller</item>
</string-array>
<string-array name="timetable_show_whole_class_values" translatable="false">
<item>no</item>
<item>yes</item>
<item>small</item>
</string-array>
</resources> </resources>

View File

@ -301,6 +301,7 @@
<string name="pref_view_present">Show presence in attendance</string> <string name="pref_view_present">Show presence in attendance</string>
<string name="pref_view_app_theme">Application theme</string> <string name="pref_view_app_theme">Application theme</string>
<string name="pref_view_expand_grade">Expand grades</string> <string name="pref_view_expand_grade">Expand grades</string>
<string name="pref_view_timetable_show_whole_class">Show whole class lessons</string>
<string name="pref_view_grade_color_scheme">Grades color scheme</string> <string name="pref_view_grade_color_scheme">Grades color scheme</string>
<string name="pref_view_app_language">App language</string> <string name="pref_view_app_language">App language</string>

View File

@ -29,6 +29,14 @@
app:iconSpaceReserved="false" app:iconSpaceReserved="false"
app:key="@string/pref_key_expand_grade" app:key="@string/pref_key_expand_grade"
app:title="@string/pref_view_expand_grade" /> app:title="@string/pref_view_expand_grade" />
<ListPreference
app:defaultValue="@string/pref_default_timetable_show_whole_class"
app:entries="@array/timetable_show_whole_class_entries"
app:entryValues="@array/timetable_show_whole_class_values"
app:iconSpaceReserved="false"
app:key="@string/pref_key_timetable_show_whole_class"
app:title="@string/pref_view_timetable_show_whole_class"
app:useSimpleSummaryProvider="true" />
<ListPreference <ListPreference
app:defaultValue="@string/pref_default_grade_color_scheme" app:defaultValue="@string/pref_default_grade_color_scheme"
app:entries="@array/grade_color_scheme_entries" app:entries="@array/grade_color_scheme_entries"