1
0
mirror of https://github.com/wulkanowy/wulkanowy.git synced 2025-02-21 19:44:45 +01:00

Fix colorPrimary and class name in widget account manager (#1241)

This commit is contained in:
Rafał Borcz 2021-03-21 22:37:34 +01:00 committed by GitHub
parent e03b0dfa01
commit 8733e7782f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
10 changed files with 59 additions and 31 deletions

View File

@ -7,6 +7,7 @@ import androidx.core.view.isVisible
import androidx.recyclerview.widget.RecyclerView import androidx.recyclerview.widget.RecyclerView
import io.github.wulkanowy.R import io.github.wulkanowy.R
import io.github.wulkanowy.data.db.entities.Student import io.github.wulkanowy.data.db.entities.Student
import io.github.wulkanowy.data.db.entities.StudentWithSemesters
import io.github.wulkanowy.databinding.ItemAccountBinding import io.github.wulkanowy.databinding.ItemAccountBinding
import io.github.wulkanowy.utils.createNameInitialsDrawable import io.github.wulkanowy.utils.createNameInitialsDrawable
import io.github.wulkanowy.utils.getThemeAttrColor import io.github.wulkanowy.utils.getThemeAttrColor
@ -16,7 +17,9 @@ import javax.inject.Inject
class WidgetConfigureAdapter @Inject constructor() : class WidgetConfigureAdapter @Inject constructor() :
RecyclerView.Adapter<WidgetConfigureAdapter.ItemViewHolder>() { RecyclerView.Adapter<WidgetConfigureAdapter.ItemViewHolder>() {
var items = emptyList<Pair<Student, Boolean>>() var items = emptyList<StudentWithSemesters>()
var selectedId = -1L
var onClickListener: (Student) -> Unit = {} var onClickListener: (Student) -> Unit = {}
@ -28,12 +31,13 @@ class WidgetConfigureAdapter @Inject constructor() :
@SuppressLint("SetTextI18n") @SuppressLint("SetTextI18n")
override fun onBindViewHolder(holder: ItemViewHolder, position: Int) { override fun onBindViewHolder(holder: ItemViewHolder, position: Int) {
val (student, isCurrent) = items[position] val (student, semesters) = items[position]
val semester = semesters.maxByOrNull { it.semesterId }
val context = holder.binding.root.context val context = holder.binding.root.context
val checkBackgroundColor = context.getThemeAttrColor(R.attr.colorSurface) val checkBackgroundColor = context.getThemeAttrColor(R.attr.colorSurface)
val avatar = context.createNameInitialsDrawable(student.nickOrName, student.avatarColor) val avatar = context.createNameInitialsDrawable(student.nickOrName, student.avatarColor)
val isDuplicatedStudent = items.filter { val isDuplicatedStudent = items.filter {
val studentToCompare = it.first val studentToCompare = it.student
studentToCompare.studentId == student.studentId studentToCompare.studentId == student.studentId
&& studentToCompare.schoolSymbol == student.schoolSymbol && studentToCompare.schoolSymbol == student.schoolSymbol
@ -41,7 +45,7 @@ class WidgetConfigureAdapter @Inject constructor() :
}.size > 1 }.size > 1
with(holder.binding) { with(holder.binding) {
accountItemName.text = "${student.nickOrName} ${student.className}" accountItemName.text = "${student.nickOrName} ${semester?.diaryName.orEmpty()}"
accountItemSchool.text = student.schoolName accountItemSchool.text = student.schoolName
accountItemImage.setImageDrawable(avatar) accountItemImage.setImageDrawable(avatar)
@ -51,7 +55,7 @@ class WidgetConfigureAdapter @Inject constructor() :
} }
with(accountItemCheck) { with(accountItemCheck) {
isVisible = isCurrent isVisible = student.id == selectedId
borderColor = checkBackgroundColor borderColor = checkBackgroundColor
circleColor = checkBackgroundColor circleColor = checkBackgroundColor
} }

View File

@ -74,9 +74,8 @@ class AccountAdapter @Inject constructor() : RecyclerView.Adapter<RecyclerView.V
studentWithSemesters: StudentWithSemesters studentWithSemesters: StudentWithSemesters
) { ) {
val context = binding.root.context val context = binding.root.context
val student = studentWithSemesters.student val (student, semesters) = studentWithSemesters
val semesters = studentWithSemesters.semesters val semester = semesters.maxByOrNull { it.semesterId }
val diary = semesters.maxByOrNull { it.semesterId }
val avatar = context.createNameInitialsDrawable(student.nickOrName, student.avatarColor) val avatar = context.createNameInitialsDrawable(student.nickOrName, student.avatarColor)
val checkBackgroundColor = val checkBackgroundColor =
context.getThemeAttrColor(if (isAccountQuickDialogMode) R.attr.colorBackgroundFloating else R.attr.colorSurface) context.getThemeAttrColor(if (isAccountQuickDialogMode) R.attr.colorBackgroundFloating else R.attr.colorSurface)
@ -90,7 +89,7 @@ class AccountAdapter @Inject constructor() : RecyclerView.Adapter<RecyclerView.V
}.size > 1 && isAccountQuickDialogMode }.size > 1 && isAccountQuickDialogMode
with(binding) { with(binding) {
accountItemName.text = "${student.nickOrName} ${diary?.diaryName.orEmpty()}" accountItemName.text = "${student.nickOrName} ${semester?.diaryName.orEmpty()}"
accountItemSchool.text = studentWithSemesters.student.schoolName accountItemSchool.text = studentWithSemesters.student.schoolName
accountItemImage.setImageDrawable(avatar) accountItemImage.setImageDrawable(avatar)

View File

@ -11,7 +11,7 @@ import androidx.appcompat.app.AlertDialog
import androidx.recyclerview.widget.LinearLayoutManager import androidx.recyclerview.widget.LinearLayoutManager
import dagger.hilt.android.AndroidEntryPoint import dagger.hilt.android.AndroidEntryPoint
import io.github.wulkanowy.R import io.github.wulkanowy.R
import io.github.wulkanowy.data.db.entities.Student import io.github.wulkanowy.data.db.entities.StudentWithSemesters
import io.github.wulkanowy.databinding.ActivityWidgetConfigureBinding import io.github.wulkanowy.databinding.ActivityWidgetConfigureBinding
import io.github.wulkanowy.ui.base.BaseActivity import io.github.wulkanowy.ui.base.BaseActivity
import io.github.wulkanowy.ui.base.WidgetConfigureAdapter import io.github.wulkanowy.ui.base.WidgetConfigureAdapter
@ -38,7 +38,9 @@ class LuckyNumberWidgetConfigureActivity :
override fun onCreate(savedInstanceState: Bundle?) { override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState) super.onCreate(savedInstanceState)
setResult(RESULT_CANCELED) setResult(RESULT_CANCELED)
setContentView(ActivityWidgetConfigureBinding.inflate(layoutInflater).apply { binding = this }.root) setContentView(
ActivityWidgetConfigureBinding.inflate(layoutInflater).apply { binding = this }.root
)
intent.extras.let { intent.extras.let {
presenter.onAttachView(this, it?.getInt(EXTRA_APPWIDGET_ID)) presenter.onAttachView(this, it?.getInt(EXTRA_APPWIDGET_ID))
@ -70,8 +72,9 @@ class LuckyNumberWidgetConfigureActivity :
.show() .show()
} }
override fun updateData(data: List<Pair<Student, Boolean>>) { override fun updateData(data: List<StudentWithSemesters>, selectedStudentId: Long) {
with(configureAdapter) { with(configureAdapter) {
selectedId = selectedStudentId
items = data items = data
notifyDataSetChanged() notifyDataSetChanged()
} }

View File

@ -51,16 +51,17 @@ class LuckyNumberWidgetConfigurePresenter @Inject constructor(
when (it.status) { when (it.status) {
Status.LOADING -> Timber.d("Lucky number widget configure students data load") Status.LOADING -> Timber.d("Lucky number widget configure students data load")
Status.SUCCESS -> { Status.SUCCESS -> {
val widgetId = appWidgetId?.let { id -> sharedPref.getLong(getStudentWidgetKey(id), 0) } val selectedStudentId = appWidgetId?.let { id ->
sharedPref.getLong(getStudentWidgetKey(id), 0)
} ?: -1
when { when {
it.data!!.isEmpty() -> view?.openLoginView() it.data!!.isEmpty() -> view?.openLoginView()
it.data.size == 1 -> { it.data.size == 1 -> {
selectedStudent = it.data.single().student selectedStudent = it.data.single().student
view?.showThemeDialog() view?.showThemeDialog()
} }
else -> view?.updateData(it.data.map { entity -> else -> view?.updateData(it.data, selectedStudentId)
entity.student to (entity.student.id == widgetId)
})
} }
} }
Status.ERROR -> errorHandler.dispatch(it.error!!) Status.ERROR -> errorHandler.dispatch(it.error!!)

View File

@ -1,6 +1,6 @@
package io.github.wulkanowy.ui.modules.luckynumberwidget package io.github.wulkanowy.ui.modules.luckynumberwidget
import io.github.wulkanowy.data.db.entities.Student import io.github.wulkanowy.data.db.entities.StudentWithSemesters
import io.github.wulkanowy.ui.base.BaseView import io.github.wulkanowy.ui.base.BaseView
interface LuckyNumberWidgetConfigureView : BaseView { interface LuckyNumberWidgetConfigureView : BaseView {
@ -9,7 +9,7 @@ interface LuckyNumberWidgetConfigureView : BaseView {
fun showThemeDialog() fun showThemeDialog()
fun updateData(data: List<Pair<Student, Boolean>>) fun updateData(data: List<StudentWithSemesters>, selectedStudentId: Long)
fun updateLuckyNumberWidget(widgetId: Int) fun updateLuckyNumberWidget(widgetId: Int)

View File

@ -12,7 +12,7 @@ import androidx.appcompat.app.AlertDialog
import androidx.recyclerview.widget.LinearLayoutManager import androidx.recyclerview.widget.LinearLayoutManager
import dagger.hilt.android.AndroidEntryPoint import dagger.hilt.android.AndroidEntryPoint
import io.github.wulkanowy.R import io.github.wulkanowy.R
import io.github.wulkanowy.data.db.entities.Student import io.github.wulkanowy.data.db.entities.StudentWithSemesters
import io.github.wulkanowy.databinding.ActivityWidgetConfigureBinding import io.github.wulkanowy.databinding.ActivityWidgetConfigureBinding
import io.github.wulkanowy.ui.base.BaseActivity import io.github.wulkanowy.ui.base.BaseActivity
import io.github.wulkanowy.ui.base.WidgetConfigureAdapter import io.github.wulkanowy.ui.base.WidgetConfigureAdapter
@ -37,13 +37,19 @@ class TimetableWidgetConfigureActivity :
private var dialog: AlertDialog? = null private var dialog: AlertDialog? = null
override public fun onCreate(savedInstanceState: Bundle?) { override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState) super.onCreate(savedInstanceState)
setResult(RESULT_CANCELED) setResult(RESULT_CANCELED)
setContentView(ActivityWidgetConfigureBinding.inflate(layoutInflater).apply { binding = this }.root) setContentView(
ActivityWidgetConfigureBinding.inflate(layoutInflater).apply { binding = this }.root
)
intent.extras.let { intent.extras.let {
presenter.onAttachView(this, it?.getInt(EXTRA_APPWIDGET_ID), it?.getBoolean(EXTRA_FROM_PROVIDER)) presenter.onAttachView(
this,
it?.getInt(EXTRA_APPWIDGET_ID),
it?.getBoolean(EXTRA_FROM_PROVIDER)
)
} }
} }
@ -61,6 +67,7 @@ class TimetableWidgetConfigureActivity :
getString(R.string.widget_timetable_theme_light), getString(R.string.widget_timetable_theme_light),
getString(R.string.widget_timetable_theme_dark) getString(R.string.widget_timetable_theme_dark)
) )
if (appInfo.systemVersion >= Build.VERSION_CODES.Q) items += getString(R.string.widget_timetable_theme_system) if (appInfo.systemVersion >= Build.VERSION_CODES.Q) items += getString(R.string.widget_timetable_theme_system)
dialog = AlertDialog.Builder(this, R.style.WulkanowyTheme_WidgetAccountSwitcher) dialog = AlertDialog.Builder(this, R.style.WulkanowyTheme_WidgetAccountSwitcher)
@ -72,8 +79,9 @@ class TimetableWidgetConfigureActivity :
.show() .show()
} }
override fun updateData(data: List<Pair<Student, Boolean>>) { override fun updateData(data: List<StudentWithSemesters>, selectedStudentId: Long) {
with(configureAdapter) { with(configureAdapter) {
selectedId = selectedStudentId
items = data items = data
notifyDataSetChanged() notifyDataSetChanged()
} }

View File

@ -25,7 +25,11 @@ class TimetableWidgetConfigurePresenter @Inject constructor(
private var selectedStudent: Student? = null private var selectedStudent: Student? = null
fun onAttachView(view: TimetableWidgetConfigureView, appWidgetId: Int?, isFromProvider: Boolean?) { fun onAttachView(
view: TimetableWidgetConfigureView,
appWidgetId: Int?,
isFromProvider: Boolean?
) {
super.onAttachView(view) super.onAttachView(view)
this.appWidgetId = appWidgetId this.appWidgetId = appWidgetId
this.isFromProvider = isFromProvider ?: false this.isFromProvider = isFromProvider ?: false
@ -56,16 +60,17 @@ class TimetableWidgetConfigurePresenter @Inject constructor(
when (it.status) { when (it.status) {
Status.LOADING -> Timber.d("Timetable widget configure students data load") Status.LOADING -> Timber.d("Timetable widget configure students data load")
Status.SUCCESS -> { Status.SUCCESS -> {
val widgetId = appWidgetId?.let { id -> sharedPref.getLong(getStudentWidgetKey(id), 0) } val selectedStudentId = appWidgetId?.let { id ->
sharedPref.getLong(getStudentWidgetKey(id), 0)
} ?: -1
when { when {
it.data!!.isEmpty() -> view?.openLoginView() it.data!!.isEmpty() -> view?.openLoginView()
it.data.size == 1 && !isFromProvider -> { it.data.size == 1 && !isFromProvider -> {
selectedStudent = it.data.single().student selectedStudent = it.data.single().student
view?.showThemeDialog() view?.showThemeDialog()
} }
else -> view?.updateData(it.data.map { entity -> else -> view?.updateData(it.data, selectedStudentId)
entity.student to (entity.student.id == widgetId)
})
} }
} }
Status.ERROR -> errorHandler.dispatch(it.error!!) Status.ERROR -> errorHandler.dispatch(it.error!!)

View File

@ -1,13 +1,13 @@
package io.github.wulkanowy.ui.modules.timetablewidget package io.github.wulkanowy.ui.modules.timetablewidget
import io.github.wulkanowy.data.db.entities.Student import io.github.wulkanowy.data.db.entities.StudentWithSemesters
import io.github.wulkanowy.ui.base.BaseView import io.github.wulkanowy.ui.base.BaseView
interface TimetableWidgetConfigureView : BaseView { interface TimetableWidgetConfigureView : BaseView {
fun initView() fun initView()
fun updateData(data: List<Pair<Student, Boolean>>) fun updateData(data: List<StudentWithSemesters>, selectedStudentId: Long)
fun updateTimetableWidget(widgetId: Int) fun updateTimetableWidget(widgetId: Int)

View File

@ -49,4 +49,12 @@
<item name="android:navigationBarColor" tools:targetApi="lollipop">?colorSurface</item> <item name="android:navigationBarColor" tools:targetApi="lollipop">?colorSurface</item>
<item name="android:statusBarColor" tools:targetApi="lollipop">@android:color/black</item> <item name="android:statusBarColor" tools:targetApi="lollipop">@android:color/black</item>
</style> </style>
<style name="WulkanowyTheme.WidgetAccountSwitcher" parent="Theme.MaterialComponents.Dialog">
<item name="colorPrimary">@color/colorPrimaryLight</item>
<item name="colorSecondary">@color/colorPrimaryLight</item>
<item name="windowActionBar">false</item>
<item name="windowNoTitle">true</item>
<item name="android:textColor">?android:textColorPrimary</item>
</style>
</resources> </resources>

View File

@ -26,7 +26,7 @@
<item name="android:windowBackground">@drawable/layer_splash_background</item> <item name="android:windowBackground">@drawable/layer_splash_background</item>
</style> </style>
<style name="WulkanowyTheme.WidgetAccountSwitcher" parent="Theme.MaterialComponents.DayNight.Dialog"> <style name="WulkanowyTheme.WidgetAccountSwitcher" parent="Theme.MaterialComponents.Light.Dialog">
<item name="colorPrimary">@color/colorPrimary</item> <item name="colorPrimary">@color/colorPrimary</item>
<item name="colorSecondary">@color/colorPrimary</item> <item name="colorSecondary">@color/colorPrimary</item>
<item name="windowActionBar">false</item> <item name="windowActionBar">false</item>