Room summary preview / unread kind depending on DMs vs groups

Closes https://github.com/SchildiChat/SchildiChat-android/issues/32

Change-Id: I4f4e3078e940dc80046d5d08628a1bdbed4fd55e
This commit is contained in:
SpiritCroc 2020-12-28 16:17:42 +01:00
parent a365850516
commit 0c37405278
7 changed files with 58 additions and 12 deletions

View file

@ -88,7 +88,7 @@ data class RoomSummary constructor(
// Fallback to default
return hasUnreadMessages
}
return when(preferenceProvider.getUnreadKind()) {
return when(preferenceProvider.getUnreadKind(isDirect)) {
UNREAD_KIND_ORIGINAL_CONTENT -> hasUnreadOriginalContentMessages
UNREAD_KIND_CONTENT -> hasUnreadContentMessages
// UNREAD_KIND_DEFAULT
@ -101,7 +101,7 @@ data class RoomSummary constructor(
// Fallback to default
return latestPreviewableEvent
}
return when(preferenceProvider.getUnreadKind()) {
return when(preferenceProvider.getUnreadKind(isDirect)) {
UNREAD_KIND_ORIGINAL_CONTENT -> latestPreviewableOriginalContentEvent
UNREAD_KIND_CONTENT -> latestPreviewableContentEvent
// UNREAD_KIND_DEFAULT
@ -119,6 +119,6 @@ data class RoomSummary constructor(
// SC addition
interface RoomSummaryPreferenceProvider {
fun getUnreadKind(): Int
fun getUnreadKind(isDirect: Boolean): Int
}
}

View file

@ -117,6 +117,9 @@ class HomeDrawerFragment @Inject constructor(
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
// SC: settings migration
vectorPreferences.scPreferenceUpdate()
// SC-Easy mode prompt
PromptSimplifiedModeActivity.showIfRequired(requireContext(), vectorPreferences)
}
}

View file

@ -9,7 +9,7 @@ class ScSdkPreferences @Inject constructor(private val vectorPreferences: Vector
constructor(context: Context?) : this(vectorPreferences = context?.let { VectorPreferences(it) })
override fun getUnreadKind(): Int {
return vectorPreferences?.roomUnreadKind() ?: RoomSummary.UNREAD_KIND_DEFAULT
override fun getUnreadKind(isDirect: Boolean): Int {
return vectorPreferences?.roomUnreadKind(isDirect) ?: RoomSummary.UNREAD_KIND_DEFAULT
}
}

View file

@ -27,6 +27,7 @@ import im.vector.app.core.di.DefaultSharedPreferences
import im.vector.app.features.disclaimer.SHARED_PREF_KEY
import im.vector.app.features.homeserver.ServerUrlsRepository
import im.vector.app.features.themes.ThemeUtils
import io.realm.annotations.Ignore
import org.matrix.android.sdk.api.extensions.tryOrNull
import org.matrix.android.sdk.api.session.room.model.RoomSummary
import timber.log.Timber
@ -182,7 +183,10 @@ class VectorPreferences @Inject constructor(private val context: Context) {
// SC additions
private const val SETTINGS_SINGLE_OVERVIEW = "SETTINGS_SINGLE_OVERVIEW"
@Deprecated("Please append _DM or _GROUP")
private const val SETTINGS_ROOM_UNREAD_KIND = "SETTINGS_ROOM_UNREAD_KIND"
private const val SETTINGS_ROOM_UNREAD_KIND_DM = "SETTINGS_ROOM_UNREAD_KIND_DM"
private const val SETTINGS_ROOM_UNREAD_KIND_GROUP = "SETTINGS_ROOM_UNREAD_KIND_GROUP"
private const val SETTINGS_UNIMPORTANT_COUNTER_BADGE = "SETTINGS_UNIMPORTANT_COUNTER_BADGE"
private const val SETTINGS_SIMPLIFIED_MODE = "SETTINGS_SIMPLIFIED_MODE"
private const val SETTINGS_LABS_ALLOW_MARK_UNREAD = "SETTINGS_LABS_ALLOW_MARK_UNREAD"
@ -878,14 +882,28 @@ class VectorPreferences @Inject constructor(private val context: Context) {
}
// SC addition
fun roomUnreadKind(): Int {
val kind = defaultPrefs.getString(SETTINGS_ROOM_UNREAD_KIND, RoomSummary.UNREAD_KIND_CONTENT.toString())
private fun roomUnreadKind(key: String): Int {
val default = RoomSummary.UNREAD_KIND_CONTENT
val kind = defaultPrefs.getString(key, default.toString())
return try {
Integer.parseInt(kind!!)
} catch (e: Exception) {
RoomSummary.UNREAD_KIND_CONTENT
default
}
}
fun roomUnreadKind(isDirect: Boolean): Int {
return if (isDirect) {
roomUnreadKindDm()
} else {
roomUnreadKindGroup()
}
}
fun roomUnreadKindDm(): Int {
return roomUnreadKind(SETTINGS_ROOM_UNREAD_KIND_DM)
}
fun roomUnreadKindGroup(): Int {
return roomUnreadKind(SETTINGS_ROOM_UNREAD_KIND_GROUP)
}
// SC addition
fun shouldShowUnimportantCounterBadge(): Boolean {
@ -911,6 +929,21 @@ class VectorPreferences @Inject constructor(private val context: Context) {
return defaultPrefs.getBoolean(SETTINGS_LABS_ALLOW_MARK_UNREAD, false)
}
// SC addition
@Suppress("DEPRECATION")
fun scPreferenceUpdate() {
if (defaultPrefs.contains(SETTINGS_ROOM_UNREAD_KIND)) {
// Migrate to split setting for DMs and groups
val unreadKindSetting = roomUnreadKind(SETTINGS_ROOM_UNREAD_KIND).toString()
defaultPrefs
.edit()
.putString(SETTINGS_ROOM_UNREAD_KIND_DM, unreadKindSetting)
.putString(SETTINGS_ROOM_UNREAD_KIND_GROUP, unreadKindSetting)
.remove(SETTINGS_ROOM_UNREAD_KIND)
.apply()
}
}
/**
* The user enable protecting app access with pin code.
* Currently we use the pin code store to know if the pin is enabled, so this is not used

View file

@ -8,7 +8,8 @@
<string name="settings_single_overview">Vereinte Chat-Übersicht</string>
<string name="settings_single_overview_summary">Zeige sowohl Direktnachrichten als auch Gruppenchats in einer gemeinsamen Übersicht</string>
<string name="settings_room_unread_kind">Chat-Vorschau</string>
<string name="settings_room_unread_kind_dm">Direktchat-Vorschau</string>
<string name="settings_room_unread_kind_group">Gruppenchat-Vorschau</string>
<string name="settings_room_unread_kind_default">Alle Ereignisse</string>
<string name="settings_room_unread_kind_content">Verstecke Teilnehmerveränderungen</string>
<string name="settings_room_unread_kind_original_content">Verstecke Teilnehmerveränderungen und Reaktionen</string>

View file

@ -8,7 +8,8 @@
<string name="settings_single_overview">Combined chat overview</string>
<string name="settings_single_overview_summary">View both direct messages and rooms on one page</string>
<string name="settings_room_unread_kind">Chat preview content</string>
<string name="settings_room_unread_kind_dm">Direct chat preview content</string>
<string name="settings_room_unread_kind_group">Group chat preview content</string>
<string name="settings_room_unread_kind_default">Show all events</string>
<string name="settings_room_unread_kind_content">Hide member changes</string>
<string name="settings_room_unread_kind_original_content">Hide member changes and reactions</string>

View file

@ -77,9 +77,17 @@
android:defaultValue="1"
android:entries="@array/room_unread_kind_entries"
android:entryValues="@array/room_unread_kind_values"
android:key="SETTINGS_ROOM_UNREAD_KIND"
android:key="SETTINGS_ROOM_UNREAD_KIND_DM"
android:summary="%s"
android:title="@string/settings_room_unread_kind" />
android:title="@string/settings_room_unread_kind_dm" />
<im.vector.app.core.preference.VectorListPreference
android:defaultValue="1"
android:entries="@array/room_unread_kind_entries"
android:entryValues="@array/room_unread_kind_values"
android:key="SETTINGS_ROOM_UNREAD_KIND_GROUP"
android:summary="%s"
android:title="@string/settings_room_unread_kind_group" />
<im.vector.app.core.preference.VectorSwitchPreference
android:defaultValue="true"