diff --git a/app/src/androidTest/java/io/github/wulkanowy/data/repositories/timetable/TestTimetableEntityCreator.kt b/app/src/androidTest/java/io/github/wulkanowy/data/repositories/timetable/TestTimetableEntityCreator.kt index 77c061821..aa35fe790 100644 --- a/app/src/androidTest/java/io/github/wulkanowy/data/repositories/timetable/TestTimetableEntityCreator.kt +++ b/app/src/androidTest/java/io/github/wulkanowy/data/repositories/timetable/TestTimetableEntityCreator.kt @@ -21,7 +21,7 @@ fun createTimetableLocal(start: LocalDateTime, number: Int, room: String = "", s teacher = teacher, teacherOld = "", info = "", - studentPlan = true, + isStudentPlan = true, changes = changes, canceled = false ) diff --git a/app/src/main/java/io/github/wulkanowy/data/db/entities/Timetable.kt b/app/src/main/java/io/github/wulkanowy/data/db/entities/Timetable.kt index 313feb62c..cad3b7c69 100644 --- a/app/src/main/java/io/github/wulkanowy/data/db/entities/Timetable.kt +++ b/app/src/main/java/io/github/wulkanowy/data/db/entities/Timetable.kt @@ -41,7 +41,7 @@ data class Timetable( val info: String, @ColumnInfo(name = "student_plan") - val studentPlan: Boolean, + val isStudentPlan: Boolean, val changes: Boolean, diff --git a/app/src/main/java/io/github/wulkanowy/data/repositories/timetable/TimetableRemote.kt b/app/src/main/java/io/github/wulkanowy/data/repositories/timetable/TimetableRemote.kt index 26e7836ad..c0aa16ebb 100644 --- a/app/src/main/java/io/github/wulkanowy/data/repositories/timetable/TimetableRemote.kt +++ b/app/src/main/java/io/github/wulkanowy/data/repositories/timetable/TimetableRemote.kt @@ -30,7 +30,7 @@ class TimetableRemote @Inject constructor(private val sdk: Sdk) { teacher = it.teacher, teacherOld = it.teacherOld, info = it.info, - studentPlan = it.studentPlan, + isStudentPlan = it.studentPlan, changes = it.changes, canceled = it.canceled ) diff --git a/app/src/main/java/io/github/wulkanowy/services/widgets/TimetableWidgetService.kt b/app/src/main/java/io/github/wulkanowy/services/widgets/TimetableWidgetService.kt index 7c7e67101..e5ccf963c 100644 --- a/app/src/main/java/io/github/wulkanowy/services/widgets/TimetableWidgetService.kt +++ b/app/src/main/java/io/github/wulkanowy/services/widgets/TimetableWidgetService.kt @@ -4,6 +4,7 @@ import android.content.Intent import android.widget.RemoteViewsService import dagger.android.AndroidInjection import io.github.wulkanowy.data.db.SharedPrefProvider +import io.github.wulkanowy.data.repositories.preferences.PreferencesRepository import io.github.wulkanowy.data.repositories.semester.SemesterRepository import io.github.wulkanowy.data.repositories.student.StudentRepository import io.github.wulkanowy.data.repositories.timetable.TimetableRepository @@ -22,6 +23,9 @@ class TimetableWidgetService : RemoteViewsService() { @Inject lateinit var semesterRepo: SemesterRepository + @Inject + lateinit var prefRepository: PreferencesRepository + @Inject lateinit var sharedPref: SharedPrefProvider @@ -30,6 +34,6 @@ class TimetableWidgetService : RemoteViewsService() { override fun onGetViewFactory(intent: Intent?): RemoteViewsFactory { AndroidInjection.inject(this) - return TimetableWidgetFactory(timetableRepo, studentRepo, semesterRepo, sharedPref, schedulers, applicationContext, intent) + return TimetableWidgetFactory(timetableRepo, studentRepo, semesterRepo, prefRepository, sharedPref, schedulers, applicationContext, intent) } } diff --git a/app/src/main/java/io/github/wulkanowy/ui/modules/timetable/TimetableItem.kt b/app/src/main/java/io/github/wulkanowy/ui/modules/timetable/TimetableItem.kt index 99aca2a23..8dd48abd7 100644 --- a/app/src/main/java/io/github/wulkanowy/ui/modules/timetable/TimetableItem.kt +++ b/app/src/main/java/io/github/wulkanowy/ui/modules/timetable/TimetableItem.kt @@ -21,7 +21,7 @@ class TimetableItem(val lesson: Timetable, private val showWholeClassPlan: Strin AbstractFlexibleItem() { override fun getLayoutRes() = when { - showWholeClassPlan == "small" && !lesson.studentPlan -> R.layout.item_timetable_small + showWholeClassPlan == "small" && !lesson.isStudentPlan -> R.layout.item_timetable_small else -> R.layout.item_timetable } diff --git a/app/src/main/java/io/github/wulkanowy/ui/modules/timetable/TimetablePresenter.kt b/app/src/main/java/io/github/wulkanowy/ui/modules/timetable/TimetablePresenter.kt index d9eb44785..7916a4b87 100644 --- a/app/src/main/java/io/github/wulkanowy/ui/modules/timetable/TimetablePresenter.kt +++ b/app/src/main/java/io/github/wulkanowy/ui/modules/timetable/TimetablePresenter.kt @@ -177,7 +177,7 @@ class TimetablePresenter @Inject constructor( private fun createTimetableItems(items: List): List { return items - .filter { if (prefRepository.showWholeClassPlan == "no") it.studentPlan else true } + .filter { if (prefRepository.showWholeClassPlan == "no") it.isStudentPlan else true } .map { TimetableItem(it, prefRepository.showWholeClassPlan) } } diff --git a/app/src/main/java/io/github/wulkanowy/ui/modules/timetablewidget/TimetableWidgetFactory.kt b/app/src/main/java/io/github/wulkanowy/ui/modules/timetablewidget/TimetableWidgetFactory.kt index fa989749a..0141e4d32 100644 --- a/app/src/main/java/io/github/wulkanowy/ui/modules/timetablewidget/TimetableWidgetFactory.kt +++ b/app/src/main/java/io/github/wulkanowy/ui/modules/timetablewidget/TimetableWidgetFactory.kt @@ -14,6 +14,7 @@ import android.widget.RemoteViewsService import io.github.wulkanowy.R import io.github.wulkanowy.data.db.SharedPrefProvider 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.student.StudentRepository import io.github.wulkanowy.data.repositories.timetable.TimetableRepository @@ -31,6 +32,7 @@ class TimetableWidgetFactory( private val timetableRepository: TimetableRepository, private val studentRepository: StudentRepository, private val semesterRepository: SemesterRepository, + private val prefRepository: PreferencesRepository, private val sharedPref: SharedPrefProvider, private val schedulers: SchedulersProvider, private val context: Context, @@ -39,6 +41,8 @@ class TimetableWidgetFactory( private var lessons = emptyList() + private var savedTheme: Long? = null + private var layoutId: Int? = null private var primaryColor: Int? = null @@ -53,7 +57,7 @@ class TimetableWidgetFactory( override fun getCount() = lessons.size - override fun getViewTypeCount() = 1 + override fun getViewTypeCount() = 2 override fun getItemId(position: Int) = position.toLong() @@ -73,7 +77,7 @@ class TimetableWidgetFactory( } private fun updateTheme(appWidgetId: Int) { - val savedTheme = sharedPref.getLong(getThemeWidgetKey(appWidgetId), 0) + savedTheme = sharedPref.getLong(getThemeWidgetKey(appWidgetId), 0) layoutId = if (savedTheme == 0L) R.layout.item_widget_timetable else R.layout.item_widget_timetable_dark primaryColor = if (savedTheme == 0L) R.color.colorPrimary else R.color.colorPrimaryLight @@ -81,6 +85,17 @@ class TimetableWidgetFactory( timetableChangeColor = if (savedTheme == 0L) R.color.timetable_change_dark else R.color.timetable_change_light } + private fun getItemLayout(lesson: Timetable): Int { + return when { + prefRepository.showWholeClassPlan == "small" && !lesson.isStudentPlan -> { + if (savedTheme == 0L) R.layout.item_widget_timetable_small + else R.layout.item_widget_timetable_small_dark + } + savedTheme == 0L -> R.layout.item_widget_timetable + else -> R.layout.item_widget_timetable_dark + } + } + private fun updateLessons(date: LocalDate, studentId: Long) { lessons = try { studentRepository.isStudentSaved() @@ -95,6 +110,7 @@ class TimetableWidgetFactory( .flatMap { semesterRepository.getCurrentSemester(it).toMaybe() } .flatMap { timetableRepository.getTimetable(it, date, date).toMaybe() } .map { item -> item.sortedBy { it.number } } + .map { lessons -> lessons.filter { if (prefRepository.showWholeClassPlan == "no") it.isStudentPlan else true } } .subscribeOn(schedulers.backgroundThread) .blockingGet(emptyList()) } catch (e: Exception) { @@ -107,9 +123,8 @@ class TimetableWidgetFactory( override fun getViewAt(position: Int): RemoteViews? { if (position == INVALID_POSITION || lessons.getOrNull(position) == null) return null - return RemoteViews(context.packageName, layoutId!!).apply { - val lesson = lessons[position] - + val lesson = lessons[position] + return RemoteViews(context.packageName, getItemLayout(lesson)).apply { setTextViewText(R.id.timetableWidgetItemSubject, lesson.subject) setTextViewText(R.id.timetableWidgetItemNumber, lesson.number.toString()) setTextViewText(R.id.timetableWidgetItemTimeStart, lesson.start.toFormattedString("HH:mm")) diff --git a/app/src/main/res/layout/item_widget_timetable_small.xml b/app/src/main/res/layout/item_widget_timetable_small.xml new file mode 100644 index 000000000..fb75a7517 --- /dev/null +++ b/app/src/main/res/layout/item_widget_timetable_small.xml @@ -0,0 +1,94 @@ + + + + + + + + + + + + + + + + + + + + + diff --git a/app/src/main/res/layout/item_widget_timetable_small_dark.xml b/app/src/main/res/layout/item_widget_timetable_small_dark.xml new file mode 100644 index 000000000..43ff6b1ad --- /dev/null +++ b/app/src/main/res/layout/item_widget_timetable_small_dark.xml @@ -0,0 +1,95 @@ + + + + + + + + + + + + + + + + + + + + + +