mirror of
https://github.com/SchildiChat/SchildiChat-android.git
synced 2024-11-27 12:00:03 +03:00
Use when statement and modify the case to simplify the code
This commit is contained in:
parent
9c53f0f881
commit
0cfea40b24
1 changed files with 34 additions and 38 deletions
|
@ -473,67 +473,63 @@ class NoticeEventFormatter @Inject constructor(
|
||||||
val added = altAliases - prevAltAliases
|
val added = altAliases - prevAltAliases
|
||||||
val removed = prevAltAliases - altAliases
|
val removed = prevAltAliases - altAliases
|
||||||
|
|
||||||
return if (added.isEmpty() && removed.isEmpty() && canonicalAlias == prevCanonicalAlias) {
|
return when {
|
||||||
// in case there is no difference between the two events say something as we can't simply hide the event from here
|
added.isEmpty() && removed.isEmpty() && canonicalAlias == prevCanonicalAlias -> {
|
||||||
if (event.isSentByCurrentUser()) {
|
// No difference between the two events say something as we can't simply hide the event from here
|
||||||
sp.getString(R.string.notice_room_canonical_alias_no_change_by_you)
|
|
||||||
} else {
|
|
||||||
sp.getString(R.string.notice_room_canonical_alias_no_change, senderName)
|
|
||||||
}
|
|
||||||
} else if (added.isEmpty() && removed.isEmpty()) {
|
|
||||||
// Canonical has changed
|
|
||||||
if (canonicalAlias != null) {
|
|
||||||
if (event.isSentByCurrentUser()) {
|
if (event.isSentByCurrentUser()) {
|
||||||
sp.getString(R.string.notice_room_canonical_alias_set_by_you, canonicalAlias)
|
sp.getString(R.string.notice_room_canonical_alias_no_change_by_you)
|
||||||
} else {
|
} else {
|
||||||
sp.getString(R.string.notice_room_canonical_alias_set, senderName, canonicalAlias)
|
sp.getString(R.string.notice_room_canonical_alias_no_change, senderName)
|
||||||
}
|
|
||||||
} else {
|
|
||||||
if (event.isSentByCurrentUser()) {
|
|
||||||
sp.getString(R.string.notice_room_canonical_alias_unset_by_you)
|
|
||||||
} else {
|
|
||||||
sp.getString(R.string.notice_room_canonical_alias_unset, senderName)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else if (added.isEmpty()) {
|
added.isEmpty() && removed.isEmpty() -> {
|
||||||
if (canonicalAlias == prevCanonicalAlias) {
|
// Canonical has changed
|
||||||
|
if (canonicalAlias != null) {
|
||||||
|
if (event.isSentByCurrentUser()) {
|
||||||
|
sp.getString(R.string.notice_room_canonical_alias_set_by_you, canonicalAlias)
|
||||||
|
} else {
|
||||||
|
sp.getString(R.string.notice_room_canonical_alias_set, senderName, canonicalAlias)
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
if (event.isSentByCurrentUser()) {
|
||||||
|
sp.getString(R.string.notice_room_canonical_alias_unset_by_you)
|
||||||
|
} else {
|
||||||
|
sp.getString(R.string.notice_room_canonical_alias_unset, senderName)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
added.isEmpty() && canonicalAlias == prevCanonicalAlias -> {
|
||||||
// Some alternative has been removed
|
// Some alternative has been removed
|
||||||
if (event.isSentByCurrentUser()) {
|
if (event.isSentByCurrentUser()) {
|
||||||
sp.getQuantityString(R.plurals.notice_room_canonical_alias_alternative_removed_by_you, removed.size, removed.joinToString())
|
sp.getQuantityString(R.plurals.notice_room_canonical_alias_alternative_removed_by_you, removed.size, removed.joinToString())
|
||||||
} else {
|
} else {
|
||||||
sp.getQuantityString(R.plurals.notice_room_canonical_alias_alternative_removed, removed.size, senderName, removed.joinToString())
|
sp.getQuantityString(R.plurals.notice_room_canonical_alias_alternative_removed, removed.size, senderName, removed.joinToString())
|
||||||
}
|
}
|
||||||
} else {
|
|
||||||
// Main and removed
|
|
||||||
if (event.isSentByCurrentUser()) {
|
|
||||||
sp.getString(R.string.notice_room_canonical_alias_main_and_alternative_changed_by_you)
|
|
||||||
} else {
|
|
||||||
sp.getString(R.string.notice_room_canonical_alias_main_and_alternative_changed, senderName)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
} else if (removed.isEmpty()) {
|
removed.isEmpty() && canonicalAlias == prevCanonicalAlias -> {
|
||||||
if (canonicalAlias == prevCanonicalAlias) {
|
|
||||||
// Some alternative has been added
|
// Some alternative has been added
|
||||||
if (event.isSentByCurrentUser()) {
|
if (event.isSentByCurrentUser()) {
|
||||||
sp.getQuantityString(R.plurals.notice_room_canonical_alias_alternative_added_by_you, added.size, added.joinToString())
|
sp.getQuantityString(R.plurals.notice_room_canonical_alias_alternative_added_by_you, added.size, added.joinToString())
|
||||||
} else {
|
} else {
|
||||||
sp.getQuantityString(R.plurals.notice_room_canonical_alias_alternative_added, added.size, senderName, added.joinToString())
|
sp.getQuantityString(R.plurals.notice_room_canonical_alias_alternative_added, added.size, senderName, added.joinToString())
|
||||||
}
|
}
|
||||||
} else {
|
}
|
||||||
// Main and added
|
canonicalAlias == prevCanonicalAlias -> {
|
||||||
|
// Alternative added and removed
|
||||||
|
if (event.isSentByCurrentUser()) {
|
||||||
|
sp.getString(R.string.notice_room_canonical_alias_alternative_changed_by_you)
|
||||||
|
} else {
|
||||||
|
sp.getString(R.string.notice_room_canonical_alias_alternative_changed, senderName)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else -> {
|
||||||
|
// Main and removed, or main and added, or main and added and removed
|
||||||
if (event.isSentByCurrentUser()) {
|
if (event.isSentByCurrentUser()) {
|
||||||
sp.getString(R.string.notice_room_canonical_alias_main_and_alternative_changed_by_you)
|
sp.getString(R.string.notice_room_canonical_alias_main_and_alternative_changed_by_you)
|
||||||
} else {
|
} else {
|
||||||
sp.getString(R.string.notice_room_canonical_alias_main_and_alternative_changed, senderName)
|
sp.getString(R.string.notice_room_canonical_alias_main_and_alternative_changed, senderName)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
|
||||||
// Alternative added and removed
|
|
||||||
if (event.isSentByCurrentUser()) {
|
|
||||||
sp.getString(R.string.notice_room_canonical_alias_alternative_changed_by_you)
|
|
||||||
} else {
|
|
||||||
sp.getString(R.string.notice_room_canonical_alias_alternative_changed, senderName)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue