This commit is contained in:
Hunter Kehoe 2022-06-05 16:22:26 -06:00
parent d3806ea347
commit 8cb852a2cb
3 changed files with 18 additions and 8 deletions

View file

@ -14,10 +14,18 @@ class Colors {
return if (isDarkThemeOn(context)) R.color.black_800b else R.color.gray_400
}
fun cardBackground(context: Context): Int {
return if (isDarkThemeOn(context)) R.color.black_800b else R.color.white
}
fun cardSelectedBackground(context: Context): Int {
return if (isDarkThemeOn(context)) R.color.black_700b else R.color.gray_500
}
fun cardBackgroundColor(context: Context): Int {
return ContextCompat.getColor(context, cardBackground(context))
}
fun cardSelectedBackgroundColor(context: Context): Int {
return ContextCompat.getColor(context, cardSelectedBackground(context))
}

View file

@ -636,7 +636,6 @@ class DetailActivity : AppCompatActivity(), ActionMode.Callback, NotificationFra
finishActionMode()
} else {
actionMode!!.title = adapter.selected.size.toString()
redrawList()
}
}
@ -717,8 +716,7 @@ class DetailActivity : AppCompatActivity(), ActionMode.Callback, NotificationFra
private fun beginActionMode(notification: Notification) {
actionMode = startActionMode(this)
adapter.selected.add(notification.id)
redrawList()
adapter.toggleSelection(notification.id)
// Fade status bar color
val fromColor = ContextCompat.getColor(this, Colors.statusBarNormal(this))
@ -734,7 +732,7 @@ class DetailActivity : AppCompatActivity(), ActionMode.Callback, NotificationFra
private fun endActionModeAndRedraw() {
actionMode = null
adapter.selected.clear()
redrawList()
adapter.notifyItemRangeChanged(0, adapter.currentList.size-1)
// Fade status bar color
val fromColor = ContextCompat.getColor(this, Colors.statusBarActionMode(this))
@ -742,10 +740,6 @@ class DetailActivity : AppCompatActivity(), ActionMode.Callback, NotificationFra
fadeStatusBarColor(window, fromColor, toColor)
}
private fun redrawList() {
mainList.adapter = adapter // Oh, what a hack ...
}
companion object {
const val TAG = "NtfyDetailActivity"
const val EXTRA_SUBSCRIPTION_ID = "subscriptionId"

View file

@ -58,6 +58,12 @@ class DetailAdapter(private val activity: Activity, private val lifecycleScope:
} else {
selected.add(notificationId)
}
if (selected.size != 0) {
val listIds = currentList.map { notification -> notification.id }
val notificationPosition = listIds.indexOf(notificationId)
notifyItemChanged(notificationPosition)
}
}
/* ViewHolder for Topic, takes in the inflated view and the onClick behavior. */
@ -114,6 +120,8 @@ class DetailAdapter(private val activity: Activity, private val lifecycleScope:
}
if (selected.contains(notification.id)) {
cardView.setCardBackgroundColor(Colors.cardSelectedBackgroundColor(context))
} else {
cardView.setCardBackgroundColor(Colors.cardBackgroundColor(context))
}
val attachment = notification.attachment
val exists = if (attachment?.contentUri != null) fileExists(context, attachment.contentUri) else false