From 86108b1031fb3a97479d69452d6e67c1aa4a558f Mon Sep 17 00:00:00 2001 From: SpiritCroc Date: Wed, 18 Aug 2021 12:12:04 +0200 Subject: [PATCH] Fix crash when trying to persist expand status with null context Change-Id: I4748445f4cf6701e417d137958859157fab72a38 --- .../app/features/home/room/list/RoomListFragment.kt | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/vector/src/main/java/im/vector/app/features/home/room/list/RoomListFragment.kt b/vector/src/main/java/im/vector/app/features/home/room/list/RoomListFragment.kt index 1ddfe03e0e..59f5792a7d 100644 --- a/vector/src/main/java/im/vector/app/features/home/room/list/RoomListFragment.kt +++ b/vector/src/main/java/im/vector/app/features/home/room/list/RoomListFragment.kt @@ -562,7 +562,7 @@ class RoomListFragment @Inject constructor( } private fun persistExpandStatus() { - val spEdit = getSharedPreferences().edit() + val spEdit = getSharedPreferences()?.edit() ?: return roomListViewModel.sections.forEach{section -> val isExpanded = section.isExpanded.value if (isExpanded != null) { @@ -580,14 +580,13 @@ class RoomListFragment @Inject constructor( } private fun shouldInitiallyExpand(section: RoomsSection): Boolean { - val sp = getSharedPreferences() + val sp = getSharedPreferences() ?: return true val pref = getRoomListExpandedPref(section) return sp.getBoolean(pref, true) } - private fun getSharedPreferences(): SharedPreferences { - return PreferenceManager.getDefaultSharedPreferences(context) - } + private fun getSharedPreferences() = context?.let { PreferenceManager.getDefaultSharedPreferences(it) } + private fun getRoomListExpandedPref(section: RoomsSection): String { return "${ROOM_LIST_ROOM_EXPANDED_ANY_PREFIX}_${section.sectionName}_${roomListParams.displayMode}_${expandStatusSpaceId}" }