Fix crash when trying to persist expand status with null context

Change-Id: I4748445f4cf6701e417d137958859157fab72a38
This commit is contained in:
SpiritCroc 2021-08-18 12:12:04 +02:00
parent 387459ae6b
commit 86108b1031
1 changed files with 4 additions and 5 deletions

View File

@ -562,7 +562,7 @@ class RoomListFragment @Inject constructor(
} }
private fun persistExpandStatus() { private fun persistExpandStatus() {
val spEdit = getSharedPreferences().edit() val spEdit = getSharedPreferences()?.edit() ?: return
roomListViewModel.sections.forEach{section -> roomListViewModel.sections.forEach{section ->
val isExpanded = section.isExpanded.value val isExpanded = section.isExpanded.value
if (isExpanded != null) { if (isExpanded != null) {
@ -580,14 +580,13 @@ class RoomListFragment @Inject constructor(
} }
private fun shouldInitiallyExpand(section: RoomsSection): Boolean { private fun shouldInitiallyExpand(section: RoomsSection): Boolean {
val sp = getSharedPreferences() val sp = getSharedPreferences() ?: return true
val pref = getRoomListExpandedPref(section) val pref = getRoomListExpandedPref(section)
return sp.getBoolean(pref, true) return sp.getBoolean(pref, true)
} }
private fun getSharedPreferences(): SharedPreferences { private fun getSharedPreferences() = context?.let { PreferenceManager.getDefaultSharedPreferences(it) }
return PreferenceManager.getDefaultSharedPreferences(context)
}
private fun getRoomListExpandedPref(section: RoomsSection): String { private fun getRoomListExpandedPref(section: RoomsSection): String {
return "${ROOM_LIST_ROOM_EXPANDED_ANY_PREFIX}_${section.sectionName}_${roomListParams.displayMode}_${expandStatusSpaceId}" return "${ROOM_LIST_ROOM_EXPANDED_ANY_PREFIX}_${section.sectionName}_${roomListParams.displayMode}_${expandStatusSpaceId}"
} }