Fix dark theme selected row color
This commit is contained in:
parent
0a5470cfe1
commit
a135f5b312
4 changed files with 33 additions and 8 deletions
|
@ -92,7 +92,8 @@ class DetailAdapter(private val activity: Activity, private val repository: Repo
|
|||
tagsView.visibility = View.GONE
|
||||
}
|
||||
if (selected.contains(notification.id)) {
|
||||
itemView.setBackgroundResource(R.color.primarySelectedRowColor);
|
||||
val backgroundColor = if (isDarkThemeOn(context, repository)) R.color.primaryDarkSelectedRowColor else R.color.primaryLightSelectedRowColor
|
||||
itemView.setBackgroundResource(backgroundColor);
|
||||
}
|
||||
renderPriority(context, notification)
|
||||
maybeRenderAttachment(context, notification)
|
||||
|
|
|
@ -5,6 +5,7 @@ import android.view.LayoutInflater
|
|||
import android.view.View
|
||||
import android.view.ViewGroup
|
||||
import android.widget.TextView
|
||||
import androidx.appcompat.app.AppCompatDelegate
|
||||
import androidx.recyclerview.widget.DiffUtil
|
||||
import androidx.recyclerview.widget.ListAdapter
|
||||
import androidx.recyclerview.widget.RecyclerView
|
||||
|
@ -13,6 +14,7 @@ import io.heckel.ntfy.R
|
|||
import io.heckel.ntfy.db.ConnectionState
|
||||
import io.heckel.ntfy.db.Repository
|
||||
import io.heckel.ntfy.db.Subscription
|
||||
import io.heckel.ntfy.util.isDarkThemeOn
|
||||
import io.heckel.ntfy.util.topicShortUrl
|
||||
import java.text.DateFormat
|
||||
import java.util.*
|
||||
|
@ -100,7 +102,8 @@ class MainAdapter(private val repository: Repository, private val onClick: (Subs
|
|||
itemView.setOnClickListener { onClick(subscription) }
|
||||
itemView.setOnLongClickListener { onLongClick(subscription); true }
|
||||
if (selected.contains(subscription.id)) {
|
||||
itemView.setBackgroundResource(R.color.primarySelectedRowColor);
|
||||
val backgroundColor = if (isDarkThemeOn(context, repository)) R.color.primaryDarkSelectedRowColor else R.color.primaryLightSelectedRowColor
|
||||
itemView.setBackgroundResource(backgroundColor)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -4,14 +4,18 @@ import android.animation.ArgbEvaluator
|
|||
import android.animation.ValueAnimator
|
||||
import android.content.Context
|
||||
import android.content.Intent
|
||||
import android.content.res.Configuration
|
||||
import android.content.res.Configuration.UI_MODE_NIGHT_YES
|
||||
import android.net.Uri
|
||||
import android.os.Build
|
||||
import android.os.PowerManager
|
||||
import android.provider.OpenableColumns
|
||||
import android.provider.Settings
|
||||
import android.view.Window
|
||||
import androidx.appcompat.app.AppCompatDelegate
|
||||
import io.heckel.ntfy.R
|
||||
import io.heckel.ntfy.db.Notification
|
||||
import io.heckel.ntfy.db.Repository
|
||||
import io.heckel.ntfy.db.Subscription
|
||||
import java.security.SecureRandom
|
||||
import java.text.DateFormat
|
||||
|
@ -200,3 +204,19 @@ fun isIgnoringBatteryOptimizations(context: Context): Boolean {
|
|||
return true
|
||||
}
|
||||
|
||||
// Returns true if dark mode is on, see https://stackoverflow.com/a/60761189/1440785
|
||||
fun Context.isDarkThemeOn(): Boolean {
|
||||
return resources.configuration.uiMode and
|
||||
Configuration.UI_MODE_NIGHT_MASK == UI_MODE_NIGHT_YES
|
||||
}
|
||||
|
||||
fun isDarkThemeOn(context: Context, repository: Repository): Boolean {
|
||||
val darkMode = repository.getDarkMode()
|
||||
if (darkMode == AppCompatDelegate.MODE_NIGHT_YES) {
|
||||
return true
|
||||
}
|
||||
if (darkMode == AppCompatDelegate.MODE_NIGHT_FOLLOW_SYSTEM && context.isDarkThemeOn()) {
|
||||
return true
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
|
|
@ -1,12 +1,13 @@
|
|||
<!--?xml version="1.0" encoding="UTF-8"?-->
|
||||
<resources>
|
||||
<color name="primaryColor">#338574</color>
|
||||
<color name="primaryLightColor">#338574</color>
|
||||
<color name="primaryDarkColor">#2A6E60</color>
|
||||
<color name="primaryLightTextColor">#FFFFFF</color>
|
||||
<color name="primarySelectedRowColor">#EEEEEE</color>
|
||||
<color name="primaryDangerButtonColor">#C30000</color>
|
||||
<color name="primaryPriorityUrgentColor">#C30000</color>
|
||||
<color name="primaryPriorityHighColor">#E10000</color>
|
||||
|
||||
<color name="primaryLightColor">#338574</color>
|
||||
<color name="primaryLightTextColor">#FFFFFF</color>
|
||||
<color name="primaryLightSelectedRowColor">#EEEEEE</color>
|
||||
|
||||
<color name="primaryDarkColor">#2A6E60</color>
|
||||
<color name="primaryDarkSelectedRowColor">#444444</color>
|
||||
</resources>
|
||||
|
||||
|
|
Loading…
Reference in a new issue