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 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.ItemAccountBinding
import io.github.wulkanowy.utils.createNameInitialsDrawable
import io.github.wulkanowy.utils.getThemeAttrColor
@ -16,7 +17,9 @@ import javax.inject.Inject
class WidgetConfigureAdapter @Inject constructor() :
RecyclerView.Adapter<WidgetConfigureAdapter.ItemViewHolder>() {
var items = emptyList<Pair<Student, Boolean>>()
var items = emptyList<StudentWithSemesters>()
var selectedId = -1L
var onClickListener: (Student) -> Unit = {}
@ -28,12 +31,13 @@ class WidgetConfigureAdapter @Inject constructor() :
@SuppressLint("SetTextI18n")
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 checkBackgroundColor = context.getThemeAttrColor(R.attr.colorSurface)
val avatar = context.createNameInitialsDrawable(student.nickOrName, student.avatarColor)
val isDuplicatedStudent = items.filter {
val studentToCompare = it.first
val studentToCompare = it.student
studentToCompare.studentId == student.studentId
&& studentToCompare.schoolSymbol == student.schoolSymbol
@ -41,7 +45,7 @@ class WidgetConfigureAdapter @Inject constructor() :
}.size > 1
with(holder.binding) {
accountItemName.text = "${student.nickOrName} ${student.className}"
accountItemName.text = "${student.nickOrName} ${semester?.diaryName.orEmpty()}"
accountItemSchool.text = student.schoolName
accountItemImage.setImageDrawable(avatar)
@ -51,7 +55,7 @@ class WidgetConfigureAdapter @Inject constructor() :
}
with(accountItemCheck) {
isVisible = isCurrent
isVisible = student.id == selectedId
borderColor = checkBackgroundColor
circleColor = checkBackgroundColor
}

View File

@ -74,9 +74,8 @@ class AccountAdapter @Inject constructor() : RecyclerView.Adapter<RecyclerView.V
studentWithSemesters: StudentWithSemesters
) {
val context = binding.root.context
val student = studentWithSemesters.student
val semesters = studentWithSemesters.semesters
val diary = semesters.maxByOrNull { it.semesterId }
val (student, semesters) = studentWithSemesters
val semester = semesters.maxByOrNull { it.semesterId }
val avatar = context.createNameInitialsDrawable(student.nickOrName, student.avatarColor)
val checkBackgroundColor =
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
with(binding) {
accountItemName.text = "${student.nickOrName} ${diary?.diaryName.orEmpty()}"
accountItemName.text = "${student.nickOrName} ${semester?.diaryName.orEmpty()}"
accountItemSchool.text = studentWithSemesters.student.schoolName
accountItemImage.setImageDrawable(avatar)

View File

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

View File

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

View File

@ -1,6 +1,6 @@
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
interface LuckyNumberWidgetConfigureView : BaseView {
@ -9,7 +9,7 @@ interface LuckyNumberWidgetConfigureView : BaseView {
fun showThemeDialog()
fun updateData(data: List<Pair<Student, Boolean>>)
fun updateData(data: List<StudentWithSemesters>, selectedStudentId: Long)
fun updateLuckyNumberWidget(widgetId: Int)

View File

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

View File

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

View File

@ -1,13 +1,13 @@
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
interface TimetableWidgetConfigureView : BaseView {
fun initView()
fun updateData(data: List<Pair<Student, Boolean>>)
fun updateData(data: List<StudentWithSemesters>, selectedStudentId: Long)
fun updateTimetableWidget(widgetId: Int)

View File

@ -49,4 +49,12 @@
<item name="android:navigationBarColor" tools:targetApi="lollipop">?colorSurface</item>
<item name="android:statusBarColor" tools:targetApi="lollipop">@android:color/black</item>
</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>

View File

@ -26,7 +26,7 @@
<item name="android:windowBackground">@drawable/layer_splash_background</item>
</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="colorSecondary">@color/colorPrimary</item>
<item name="windowActionBar">false</item>