Merge pull request #32 from wunter8/235-long-click-notifications
Fixed: Long-click selecting of notifications scrolls to the top
This commit is contained in:
commit
2f1aa65d5b
5 changed files with 29 additions and 14 deletions
|
@ -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))
|
||||
}
|
||||
|
|
|
@ -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)
|
||||
|
||||
// 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"
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -538,7 +538,6 @@ class MainActivity : AppCompatActivity(), ActionMode.Callback, AddFragment.Subsc
|
|||
finishActionMode()
|
||||
} else {
|
||||
actionMode!!.title = adapter.selected.size.toString()
|
||||
redrawList()
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -593,8 +592,7 @@ class MainActivity : AppCompatActivity(), ActionMode.Callback, AddFragment.Subsc
|
|||
|
||||
private fun beginActionMode(subscription: Subscription) {
|
||||
actionMode = startActionMode(this)
|
||||
adapter.selected.add(subscription.id)
|
||||
redrawList()
|
||||
adapter.toggleSelection(subscription.id)
|
||||
|
||||
// Fade out FAB
|
||||
fab.alpha = 1f
|
||||
|
@ -647,9 +645,7 @@ class MainActivity : AppCompatActivity(), ActionMode.Callback, AddFragment.Subsc
|
|||
if (!this::mainList.isInitialized) {
|
||||
return
|
||||
}
|
||||
runOnUiThread {
|
||||
mainList.adapter = adapter // Oh, what a hack ...
|
||||
}
|
||||
adapter.notifyItemRangeChanged(0, adapter.currentList.size)
|
||||
}
|
||||
|
||||
companion object {
|
||||
|
|
|
@ -2,6 +2,7 @@ package io.heckel.ntfy.ui
|
|||
|
||||
import android.content.Context
|
||||
import android.graphics.BitmapFactory
|
||||
import android.graphics.Color
|
||||
import android.net.Uri
|
||||
import android.view.LayoutInflater
|
||||
import android.view.View
|
||||
|
@ -46,6 +47,12 @@ class MainAdapter(private val repository: Repository, private val onClick: (Subs
|
|||
} else {
|
||||
selected.add(subscriptionId)
|
||||
}
|
||||
|
||||
if (selected.size != 0) {
|
||||
val listIds = currentList.map { subscription -> subscription.id }
|
||||
val subscriptionPosition = listIds.indexOf(subscriptionId)
|
||||
notifyItemChanged(subscriptionPosition)
|
||||
}
|
||||
}
|
||||
|
||||
/* ViewHolder for Topic, takes in the inflated view and the onClick behavior. */
|
||||
|
@ -111,6 +118,8 @@ class MainAdapter(private val repository: Repository, private val onClick: (Subs
|
|||
itemView.setOnLongClickListener { onLongClick(subscription); true }
|
||||
if (selected.contains(subscription.id)) {
|
||||
itemView.setBackgroundResource(Colors.itemSelectedBackground(context))
|
||||
} else {
|
||||
itemView.setBackgroundColor(Color.TRANSPARENT);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue