Default new notification profiles to allow calls.
This commit is contained in:
parent
20f8c69b07
commit
64e9324aa0
7 changed files with 71 additions and 13 deletions
|
@ -7,9 +7,12 @@ import androidx.navigation.fragment.findNavController
|
|||
import com.google.android.material.snackbar.Snackbar
|
||||
import io.reactivex.rxjava3.kotlin.subscribeBy
|
||||
import org.signal.core.util.concurrent.LifecycleDisposable
|
||||
import org.signal.core.util.logging.Log
|
||||
import org.thoughtcrime.securesms.R
|
||||
import org.thoughtcrime.securesms.components.settings.DSLConfiguration
|
||||
import org.thoughtcrime.securesms.components.settings.DSLSettingsFragment
|
||||
import org.thoughtcrime.securesms.components.settings.DSLSettingsIcon
|
||||
import org.thoughtcrime.securesms.components.settings.DSLSettingsText
|
||||
import org.thoughtcrime.securesms.components.settings.app.notifications.profiles.models.NotificationProfileAddMembers
|
||||
import org.thoughtcrime.securesms.components.settings.app.notifications.profiles.models.NotificationProfileRecipient
|
||||
import org.thoughtcrime.securesms.components.settings.configure
|
||||
|
@ -93,6 +96,32 @@ class AddAllowedMembersFragment : DSLSettingsFragment(layoutId = R.layout.fragme
|
|||
)
|
||||
)
|
||||
}
|
||||
|
||||
sectionHeaderPref(R.string.AddAllowedMembers__exceptions)
|
||||
|
||||
switchPref(
|
||||
title = DSLSettingsText.from(R.string.AddAllowedMembers__allow_all_calls),
|
||||
icon = DSLSettingsIcon.from(R.drawable.symbol_phone_24),
|
||||
isChecked = profile.allowAllCalls,
|
||||
onClick = {
|
||||
lifecycleDisposable += viewModel.toggleAllowAllCalls()
|
||||
.subscribeBy(
|
||||
onError = { Log.w(TAG, "Error updating profile", it) }
|
||||
)
|
||||
}
|
||||
)
|
||||
|
||||
switchPref(
|
||||
title = DSLSettingsText.from(R.string.AddAllowedMembers__notify_for_all_mentions),
|
||||
icon = DSLSettingsIcon.from(R.drawable.symbol_at_24),
|
||||
isChecked = profile.allowAllMentions,
|
||||
onClick = {
|
||||
lifecycleDisposable += viewModel.toggleAllowAllMentions()
|
||||
.subscribeBy(
|
||||
onError = { Log.w(TAG, "Error updating profile", it) }
|
||||
)
|
||||
}
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -100,4 +129,8 @@ class AddAllowedMembersFragment : DSLSettingsFragment(layoutId = R.layout.fragme
|
|||
lifecycleDisposable += viewModel.addMember(id)
|
||||
.subscribe()
|
||||
}
|
||||
|
||||
companion object {
|
||||
private val TAG = Log.tag(AddAllowedMembersFragment::class.java)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -30,6 +30,16 @@ class AddAllowedMembersViewModel(private val profileId: Long, private val reposi
|
|||
.observeOn(AndroidSchedulers.mainThread())
|
||||
}
|
||||
|
||||
fun toggleAllowAllMentions(): Single<NotificationProfile> {
|
||||
return repository.toggleAllowAllMentions(profileId)
|
||||
.observeOn(AndroidSchedulers.mainThread())
|
||||
}
|
||||
|
||||
fun toggleAllowAllCalls(): Single<NotificationProfile> {
|
||||
return repository.toggleAllowAllCalls(profileId)
|
||||
.observeOn(AndroidSchedulers.mainThread())
|
||||
}
|
||||
|
||||
data class NotificationProfileAndRecipients(val profile: NotificationProfile, val recipients: List<Recipient>)
|
||||
|
||||
class Factory(private val profileId: Long) : ViewModelProvider.Factory {
|
||||
|
|
|
@ -9,7 +9,6 @@ import io.reactivex.rxjava3.core.Single
|
|||
import io.reactivex.rxjava3.disposables.CompositeDisposable
|
||||
import io.reactivex.rxjava3.kotlin.plusAssign
|
||||
import io.reactivex.rxjava3.kotlin.subscribeBy
|
||||
import org.thoughtcrime.securesms.database.NotificationProfileDatabase
|
||||
import org.thoughtcrime.securesms.notifications.profiles.NotificationProfile
|
||||
import org.thoughtcrime.securesms.notifications.profiles.NotificationProfiles
|
||||
import org.thoughtcrime.securesms.recipients.Recipient
|
||||
|
@ -84,20 +83,12 @@ class NotificationProfileDetailsViewModel(private val profileId: Long, private v
|
|||
}
|
||||
|
||||
fun toggleAllowAllMentions(): Single<NotificationProfile> {
|
||||
return repository.getProfile(profileId)
|
||||
.take(1)
|
||||
.singleOrError()
|
||||
.flatMap { repository.updateProfile(it.copy(allowAllMentions = !it.allowAllMentions)) }
|
||||
.map { (it as NotificationProfileDatabase.NotificationProfileChangeResult.Success).notificationProfile }
|
||||
return repository.toggleAllowAllMentions(profileId)
|
||||
.observeOn(AndroidSchedulers.mainThread())
|
||||
}
|
||||
|
||||
fun toggleAllowAllCalls(): Single<NotificationProfile> {
|
||||
return repository.getProfile(profileId)
|
||||
.take(1)
|
||||
.singleOrError()
|
||||
.flatMap { repository.updateProfile(it.copy(allowAllCalls = !it.allowAllCalls)) }
|
||||
.map { (it as NotificationProfileDatabase.NotificationProfileChangeResult.Success).notificationProfile }
|
||||
return repository.toggleAllowAllCalls(profileId)
|
||||
.observeOn(AndroidSchedulers.mainThread())
|
||||
}
|
||||
|
||||
|
|
|
@ -94,6 +94,22 @@ class NotificationProfilesRepository {
|
|||
.subscribeOn(Schedulers.io())
|
||||
}
|
||||
|
||||
fun toggleAllowAllMentions(profileId: Long): Single<NotificationProfile> {
|
||||
return getProfile(profileId)
|
||||
.take(1)
|
||||
.singleOrError()
|
||||
.flatMap { updateProfile(it.copy(allowAllMentions = !it.allowAllMentions)) }
|
||||
.map { (it as NotificationProfileDatabase.NotificationProfileChangeResult.Success).notificationProfile }
|
||||
}
|
||||
|
||||
fun toggleAllowAllCalls(profileId: Long): Single<NotificationProfile> {
|
||||
return getProfile(profileId)
|
||||
.take(1)
|
||||
.singleOrError()
|
||||
.flatMap { updateProfile(it.copy(allowAllCalls = !it.allowAllCalls)) }
|
||||
.map { (it as NotificationProfileDatabase.NotificationProfileChangeResult.Success).notificationProfile }
|
||||
}
|
||||
|
||||
fun manuallyToggleProfile(profile: NotificationProfile, now: Long = System.currentTimeMillis()): Completable {
|
||||
return manuallyToggleProfile(profile.id, profile.schedule, now)
|
||||
}
|
||||
|
|
|
@ -111,6 +111,7 @@ class NotificationProfileDatabase(context: Context, databaseHelper: SignalDataba
|
|||
put(NotificationProfileTable.EMOJI, emoji)
|
||||
put(NotificationProfileTable.COLOR, color.serialize())
|
||||
put(NotificationProfileTable.CREATED_AT, createdAt)
|
||||
put(NotificationProfileTable.ALLOW_ALL_CALLS, 1)
|
||||
}
|
||||
|
||||
val profileId = db.insert(NotificationProfileTable.TABLE_NAME, null, profileValues)
|
||||
|
@ -134,7 +135,8 @@ class NotificationProfileDatabase(context: Context, databaseHelper: SignalDataba
|
|||
name = name,
|
||||
emoji = emoji,
|
||||
createdAt = createdAt,
|
||||
schedule = getProfileSchedule(profileId)
|
||||
schedule = getProfileSchedule(profileId),
|
||||
allowAllCalls = true
|
||||
)
|
||||
)
|
||||
} finally {
|
||||
|
|
|
@ -9,7 +9,7 @@ data class NotificationProfile(
|
|||
val emoji: String,
|
||||
val color: AvatarColor = AvatarColor.A210,
|
||||
val createdAt: Long,
|
||||
val allowAllCalls: Boolean = false,
|
||||
val allowAllCalls: Boolean = true,
|
||||
val allowAllMentions: Boolean = false,
|
||||
val schedule: NotificationProfileSchedule,
|
||||
val allowedMembers: Set<RecipientId> = emptySet()
|
||||
|
|
|
@ -5079,6 +5079,12 @@
|
|||
<string name="AddAllowedMembers__add_people_and_groups_you_want_notifications_and_calls_from_when_this_profile_is_on">Add people and groups you want notifications and calls from when this profile is on</string>
|
||||
<!-- Button text that launches the contact picker to select from -->
|
||||
<string name="AddAllowedMembers__add_people_or_groups">Add people or groups</string>
|
||||
<!-- Title for exceptions section of add people to notification profile screen in create flow -->
|
||||
<string name="AddAllowedMembers__exceptions">Exceptions</string>
|
||||
<!-- List preference to toggle that allows calls through the notification profile during create flow -->
|
||||
<string name="AddAllowedMembers__allow_all_calls">Allow all calls</string>
|
||||
<!-- List preference to toggle that allows mentions through the notification profile during create flow -->
|
||||
<string name="AddAllowedMembers__notify_for_all_mentions">Notify for all mentions</string>
|
||||
|
||||
<!-- Call to action button on contact picker for adding to profile -->
|
||||
<string name="SelectRecipientsFragment__add">Add</string>
|
||||
|
|
Loading…
Add table
Reference in a new issue