forked from github/wulkanowy-mirror
Respect user settings in timetable app widget (#687)
This commit is contained in:
parent
30e43501ac
commit
9a87df7315
@ -21,7 +21,7 @@ fun createTimetableLocal(start: LocalDateTime, number: Int, room: String = "", s
|
|||||||
teacher = teacher,
|
teacher = teacher,
|
||||||
teacherOld = "",
|
teacherOld = "",
|
||||||
info = "",
|
info = "",
|
||||||
studentPlan = true,
|
isStudentPlan = true,
|
||||||
changes = changes,
|
changes = changes,
|
||||||
canceled = false
|
canceled = false
|
||||||
)
|
)
|
||||||
|
@ -41,7 +41,7 @@ data class Timetable(
|
|||||||
val info: String,
|
val info: String,
|
||||||
|
|
||||||
@ColumnInfo(name = "student_plan")
|
@ColumnInfo(name = "student_plan")
|
||||||
val studentPlan: Boolean,
|
val isStudentPlan: Boolean,
|
||||||
|
|
||||||
val changes: Boolean,
|
val changes: Boolean,
|
||||||
|
|
||||||
|
@ -30,7 +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,
|
isStudentPlan = it.studentPlan,
|
||||||
changes = it.changes,
|
changes = it.changes,
|
||||||
canceled = it.canceled
|
canceled = it.canceled
|
||||||
)
|
)
|
||||||
|
@ -4,6 +4,7 @@ import android.content.Intent
|
|||||||
import android.widget.RemoteViewsService
|
import android.widget.RemoteViewsService
|
||||||
import dagger.android.AndroidInjection
|
import dagger.android.AndroidInjection
|
||||||
import io.github.wulkanowy.data.db.SharedPrefProvider
|
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.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
|
||||||
@ -22,6 +23,9 @@ class TimetableWidgetService : RemoteViewsService() {
|
|||||||
@Inject
|
@Inject
|
||||||
lateinit var semesterRepo: SemesterRepository
|
lateinit var semesterRepo: SemesterRepository
|
||||||
|
|
||||||
|
@Inject
|
||||||
|
lateinit var prefRepository: PreferencesRepository
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
lateinit var sharedPref: SharedPrefProvider
|
lateinit var sharedPref: SharedPrefProvider
|
||||||
|
|
||||||
@ -30,6 +34,6 @@ class TimetableWidgetService : RemoteViewsService() {
|
|||||||
|
|
||||||
override fun onGetViewFactory(intent: Intent?): RemoteViewsFactory {
|
override fun onGetViewFactory(intent: Intent?): RemoteViewsFactory {
|
||||||
AndroidInjection.inject(this)
|
AndroidInjection.inject(this)
|
||||||
return TimetableWidgetFactory(timetableRepo, studentRepo, semesterRepo, sharedPref, schedulers, applicationContext, intent)
|
return TimetableWidgetFactory(timetableRepo, studentRepo, semesterRepo, prefRepository, sharedPref, schedulers, applicationContext, intent)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -21,7 +21,7 @@ class TimetableItem(val lesson: Timetable, private val showWholeClassPlan: Strin
|
|||||||
AbstractFlexibleItem<TimetableItem.ViewHolder>() {
|
AbstractFlexibleItem<TimetableItem.ViewHolder>() {
|
||||||
|
|
||||||
override fun getLayoutRes() = when {
|
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
|
else -> R.layout.item_timetable
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -177,7 +177,7 @@ class TimetablePresenter @Inject constructor(
|
|||||||
|
|
||||||
private fun createTimetableItems(items: List<Timetable>): List<TimetableItem> {
|
private fun createTimetableItems(items: List<Timetable>): List<TimetableItem> {
|
||||||
return items
|
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) }
|
.map { TimetableItem(it, prefRepository.showWholeClassPlan) }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -14,6 +14,7 @@ import android.widget.RemoteViewsService
|
|||||||
import io.github.wulkanowy.R
|
import io.github.wulkanowy.R
|
||||||
import io.github.wulkanowy.data.db.SharedPrefProvider
|
import io.github.wulkanowy.data.db.SharedPrefProvider
|
||||||
import io.github.wulkanowy.data.db.entities.Timetable
|
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
|
||||||
@ -31,6 +32,7 @@ class TimetableWidgetFactory(
|
|||||||
private val timetableRepository: TimetableRepository,
|
private val timetableRepository: TimetableRepository,
|
||||||
private val studentRepository: StudentRepository,
|
private val studentRepository: StudentRepository,
|
||||||
private val semesterRepository: SemesterRepository,
|
private val semesterRepository: SemesterRepository,
|
||||||
|
private val prefRepository: PreferencesRepository,
|
||||||
private val sharedPref: SharedPrefProvider,
|
private val sharedPref: SharedPrefProvider,
|
||||||
private val schedulers: SchedulersProvider,
|
private val schedulers: SchedulersProvider,
|
||||||
private val context: Context,
|
private val context: Context,
|
||||||
@ -39,6 +41,8 @@ class TimetableWidgetFactory(
|
|||||||
|
|
||||||
private var lessons = emptyList<Timetable>()
|
private var lessons = emptyList<Timetable>()
|
||||||
|
|
||||||
|
private var savedTheme: Long? = null
|
||||||
|
|
||||||
private var layoutId: Int? = null
|
private var layoutId: Int? = null
|
||||||
|
|
||||||
private var primaryColor: Int? = null
|
private var primaryColor: Int? = null
|
||||||
@ -53,7 +57,7 @@ class TimetableWidgetFactory(
|
|||||||
|
|
||||||
override fun getCount() = lessons.size
|
override fun getCount() = lessons.size
|
||||||
|
|
||||||
override fun getViewTypeCount() = 1
|
override fun getViewTypeCount() = 2
|
||||||
|
|
||||||
override fun getItemId(position: Int) = position.toLong()
|
override fun getItemId(position: Int) = position.toLong()
|
||||||
|
|
||||||
@ -73,7 +77,7 @@ class TimetableWidgetFactory(
|
|||||||
}
|
}
|
||||||
|
|
||||||
private fun updateTheme(appWidgetId: Int) {
|
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
|
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
|
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
|
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) {
|
private fun updateLessons(date: LocalDate, studentId: Long) {
|
||||||
lessons = try {
|
lessons = try {
|
||||||
studentRepository.isStudentSaved()
|
studentRepository.isStudentSaved()
|
||||||
@ -95,6 +110,7 @@ class TimetableWidgetFactory(
|
|||||||
.flatMap { semesterRepository.getCurrentSemester(it).toMaybe() }
|
.flatMap { semesterRepository.getCurrentSemester(it).toMaybe() }
|
||||||
.flatMap { timetableRepository.getTimetable(it, date, date).toMaybe() }
|
.flatMap { timetableRepository.getTimetable(it, date, date).toMaybe() }
|
||||||
.map { item -> item.sortedBy { it.number } }
|
.map { item -> item.sortedBy { it.number } }
|
||||||
|
.map { lessons -> lessons.filter { if (prefRepository.showWholeClassPlan == "no") it.isStudentPlan else true } }
|
||||||
.subscribeOn(schedulers.backgroundThread)
|
.subscribeOn(schedulers.backgroundThread)
|
||||||
.blockingGet(emptyList())
|
.blockingGet(emptyList())
|
||||||
} catch (e: Exception) {
|
} catch (e: Exception) {
|
||||||
@ -107,9 +123,8 @@ class TimetableWidgetFactory(
|
|||||||
override fun getViewAt(position: Int): RemoteViews? {
|
override fun getViewAt(position: Int): RemoteViews? {
|
||||||
if (position == INVALID_POSITION || lessons.getOrNull(position) == null) return null
|
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.timetableWidgetItemSubject, lesson.subject)
|
||||||
setTextViewText(R.id.timetableWidgetItemNumber, lesson.number.toString())
|
setTextViewText(R.id.timetableWidgetItemNumber, lesson.number.toString())
|
||||||
setTextViewText(R.id.timetableWidgetItemTimeStart, lesson.start.toFormattedString("HH:mm"))
|
setTextViewText(R.id.timetableWidgetItemTimeStart, lesson.start.toFormattedString("HH:mm"))
|
||||||
|
94
app/src/main/res/layout/item_widget_timetable_small.xml
Normal file
94
app/src/main/res/layout/item_widget_timetable_small.xml
Normal file
@ -0,0 +1,94 @@
|
|||||||
|
<LinearLayout 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="@android:color/white"
|
||||||
|
android:orientation="vertical"
|
||||||
|
android:paddingStart="6dp"
|
||||||
|
android:paddingLeft="6dp"
|
||||||
|
android:paddingEnd="6dp"
|
||||||
|
android:paddingRight="6dp"
|
||||||
|
tools:context=".ui.modules.timetablewidget.TimetableWidgetFactory">
|
||||||
|
|
||||||
|
<LinearLayout
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content">
|
||||||
|
<TextView
|
||||||
|
android:id="@+id/timetableWidgetItemNumber"
|
||||||
|
android:layout_width="40dp"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:gravity="center"
|
||||||
|
android:maxLength="2"
|
||||||
|
android:textColor="@android:color/black"
|
||||||
|
android:textSize="15sp"
|
||||||
|
tools:text="5" />
|
||||||
|
|
||||||
|
<TextView
|
||||||
|
android:id="@+id/timetableWidgetItemTimeStart"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_marginStart="6dp"
|
||||||
|
android:layout_marginLeft="6dp"
|
||||||
|
android:maxLines="1"
|
||||||
|
android:textColor="@android:color/black"
|
||||||
|
android:textSize="13sp"
|
||||||
|
tools:text="11:11" />
|
||||||
|
|
||||||
|
<TextView
|
||||||
|
android:id="@+id/timetableWidgetItemTimeFinish"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:visibility="gone" />
|
||||||
|
|
||||||
|
<TextView
|
||||||
|
android:id="@+id/timetableWidgetItemSubject"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_marginStart="10dp"
|
||||||
|
android:layout_marginLeft="10dp"
|
||||||
|
android:layout_marginEnd="10dp"
|
||||||
|
android:layout_marginRight="10dp"
|
||||||
|
android:ellipsize="end"
|
||||||
|
android:maxLines="1"
|
||||||
|
android:textColor="@android:color/black"
|
||||||
|
android:textSize="15sp"
|
||||||
|
tools:text="Sieci komputerowe" />
|
||||||
|
|
||||||
|
|
||||||
|
<TextView
|
||||||
|
android:id="@+id/timetableWidgetItemRoom"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_marginStart="10dp"
|
||||||
|
android:layout_marginLeft="10dp"
|
||||||
|
android:maxLines="1"
|
||||||
|
android:textColor="@android:color/black"
|
||||||
|
android:textSize="15sp"
|
||||||
|
tools:text="22" />
|
||||||
|
|
||||||
|
<TextView
|
||||||
|
android:id="@+id/timetableWidgetItemTeacher"
|
||||||
|
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:ellipsize="end"
|
||||||
|
android:maxLines="1"
|
||||||
|
android:textColor="@android:color/black"
|
||||||
|
android:textSize="15sp"
|
||||||
|
tools:text="Agata Kowalska - Błaszczyk" />
|
||||||
|
|
||||||
|
<TextView
|
||||||
|
android:id="@+id/timetableWidgetItemDescription"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:visibility="gone" />
|
||||||
|
</LinearLayout>
|
||||||
|
|
||||||
|
<FrameLayout
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="1dp"
|
||||||
|
android:background="@color/colorDivider" />
|
||||||
|
</LinearLayout>
|
95
app/src/main/res/layout/item_widget_timetable_small_dark.xml
Normal file
95
app/src/main/res/layout/item_widget_timetable_small_dark.xml
Normal file
@ -0,0 +1,95 @@
|
|||||||
|
<LinearLayout 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="@color/colorWidgetBackground"
|
||||||
|
android:orientation="vertical"
|
||||||
|
android:paddingStart="6dp"
|
||||||
|
android:paddingLeft="6dp"
|
||||||
|
android:paddingEnd="6dp"
|
||||||
|
android:paddingRight="6dp"
|
||||||
|
tools:context=".ui.modules.timetablewidget.TimetableWidgetFactory">
|
||||||
|
|
||||||
|
<LinearLayout
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content">
|
||||||
|
|
||||||
|
<TextView
|
||||||
|
android:id="@+id/timetableWidgetItemNumber"
|
||||||
|
android:layout_width="40dp"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:gravity="center"
|
||||||
|
android:maxLength="2"
|
||||||
|
android:textColor="@android:color/white"
|
||||||
|
android:textSize="15sp"
|
||||||
|
tools:text="5" />
|
||||||
|
|
||||||
|
<TextView
|
||||||
|
android:id="@+id/timetableWidgetItemTimeStart"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_marginStart="6dp"
|
||||||
|
android:layout_marginLeft="6dp"
|
||||||
|
android:maxLines="1"
|
||||||
|
android:textColor="@android:color/white"
|
||||||
|
android:textSize="13sp"
|
||||||
|
tools:text="11:11" />
|
||||||
|
|
||||||
|
<TextView
|
||||||
|
android:id="@+id/timetableWidgetItemTimeFinish"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:visibility="gone" />
|
||||||
|
|
||||||
|
<TextView
|
||||||
|
android:id="@+id/timetableWidgetItemSubject"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_marginStart="10dp"
|
||||||
|
android:layout_marginLeft="10dp"
|
||||||
|
android:layout_marginEnd="10dp"
|
||||||
|
android:layout_marginRight="10dp"
|
||||||
|
android:ellipsize="end"
|
||||||
|
android:maxLines="1"
|
||||||
|
android:textColor="@android:color/white"
|
||||||
|
android:textSize="15sp"
|
||||||
|
tools:text="Sieci komputerowe" />
|
||||||
|
|
||||||
|
|
||||||
|
<TextView
|
||||||
|
android:id="@+id/timetableWidgetItemRoom"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_marginStart="10dp"
|
||||||
|
android:layout_marginLeft="10dp"
|
||||||
|
android:maxLines="1"
|
||||||
|
android:textColor="@android:color/white"
|
||||||
|
android:textSize="15sp"
|
||||||
|
tools:text="22" />
|
||||||
|
|
||||||
|
<TextView
|
||||||
|
android:id="@+id/timetableWidgetItemTeacher"
|
||||||
|
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:ellipsize="end"
|
||||||
|
android:maxLines="1"
|
||||||
|
android:textColor="@android:color/white"
|
||||||
|
android:textSize="15sp"
|
||||||
|
tools:text="Agata Kowalska - Błaszczyk" />
|
||||||
|
|
||||||
|
<TextView
|
||||||
|
android:id="@+id/timetableWidgetItemDescription"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:visibility="gone" />
|
||||||
|
</LinearLayout>
|
||||||
|
|
||||||
|
<FrameLayout
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="1dp"
|
||||||
|
android:background="@color/colorDividerInverse" />
|
||||||
|
</LinearLayout>
|
Loading…
x
Reference in New Issue
Block a user