fixed notifications not turning off when unselecting app

This commit is contained in:
X1nto 2021-01-30 13:53:13 +04:00
parent 6a0bd14680
commit bff17853d7
4 changed files with 26 additions and 12 deletions

View File

@ -8,9 +8,11 @@ import com.google.firebase.messaging.FirebaseMessaging
import com.vanced.manager.R
import com.vanced.manager.databinding.ViewNotificationSettingBinding
import com.vanced.manager.model.NotifModel
import com.vanced.manager.utils.defPrefs
class GetNotifAdapter(private val context: Context) :
RecyclerView.Adapter<GetNotifAdapter.GetNotifViewHolder>() {
class GetNotifAdapter(private val context: Context) : RecyclerView.Adapter<GetNotifAdapter.GetNotifViewHolder>() {
private val prefs = context.defPrefs
private val vanced = NotifModel(
"Vanced-Update",
@ -35,20 +37,22 @@ class GetNotifAdapter(private val context: Context) :
inner class GetNotifViewHolder(val binding: ViewNotificationSettingBinding) : RecyclerView.ViewHolder(binding.root) {
val switch = binding.notifSwitch
fun bind(position: Int) {
val app = apps[position]
with(binding.notifSwitch) {
setKey(apps[position].key)
setSummary(apps[position].switchSummary)
setTitle(apps[position].switchTitle)
setKey(app.key)
setSummary(app.switchSummary)
setTitle(app.switchTitle)
setDefaultValue(true)
with (prefs) {
setChecked(getBoolean(app.key.substringBefore("_") + "_enabled", true) && getBoolean(app.key, true))
}
}
}
}
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): GetNotifViewHolder {
val view =
ViewNotificationSettingBinding.inflate(LayoutInflater.from(context), parent, false)
val view = ViewNotificationSettingBinding.inflate(LayoutInflater.from(context), parent, false)
return GetNotifViewHolder(view)
}

View File

@ -1,8 +1,8 @@
package com.vanced.manager.model
data class NotifModel(
val topic: String,
val switchTitle: String,
val switchSummary: String,
val key: String
val topic: String,
val switchTitle: String,
val switchSummary: String,
val key: String
)

View File

@ -38,6 +38,11 @@ class PreferenceSwitch @JvmOverloads constructor(
init {
_binding = ViewPreferenceSwitchBinding.inflate(LayoutInflater.from(context), this, true)
prefs.registerOnSharedPreferenceChangeListener { sharedPreferences, key ->
if (key == prefKey) {
binding.preferenceSwitch.isChecked = sharedPreferences.getBoolean(key, defValue)
}
}
attrs?.let { mAttrs ->
with(context.obtainStyledAttributes(mAttrs, R.styleable.PreferenceSwitch, 0, 0)) {
val title = getText(R.styleable.PreferenceSwitch_switch_title)
@ -85,4 +90,8 @@ class PreferenceSwitch @JvmOverloads constructor(
defValue = newVal
binding.preferenceSwitch.isChecked = prefs.getBoolean(prefKey, newVal)
}
fun setChecked(checked: Boolean) {
binding.preferenceSwitch.isChecked = checked
}
}

View File

@ -49,6 +49,7 @@ class SelectAppsDialog : BindingBottomSheetDialogFragment<DialogSelectAppsBindin
prefs.edit {
ad.apps.forEach { app ->
putBoolean("enable_${app.tag}", app.isChecked)
putBoolean("${app.tag}_notifs", app.isChecked)
}
}
dismiss()