Stop observing old FoldersLiveData instances
@@ -19,6 +19,7 @@ import com.fsck.k9.mailstore.DisplayFolder
import com.fsck.k9.mailstore.Folder
import com.fsck.k9.mailstore.FolderType
import com.fsck.k9.ui.folders.FolderNameFormatter
+import com.fsck.k9.ui.folders.FoldersLiveData
import com.fsck.k9.ui.messagelist.MessageListViewModel
import com.fsck.k9.ui.messagelist.MessageListViewModelFactory
import com.fsck.k9.ui.settings.SettingsActivity
@@ -57,6 +58,11 @@ class K9Drawer(private val parent: MessageList, savedInstanceState: Bundle?) {
private var unifiedInboxSelected: Boolean = false
private var openedFolderServerId: String? = null
+ private var foldersLiveData: FoldersLiveData? = null
+ private val foldersObserver = Observer<List<DisplayFolder>> { folders ->
+ setUserFolders(folders)
+ }
+
val layout: DrawerLayout
get() = drawer.drawerLayout
@@ -202,9 +208,12 @@ class K9Drawer(private val parent: MessageList, savedInstanceState: Bundle?) {
accountHeader.headerBackgroundView.setColorFilter(account.chipColor, PorterDuff.Mode.MULTIPLY)
val viewModelProvider = ViewModelProviders.of(parent, MessageListViewModelFactory())
val viewModel = viewModelProvider.get(MessageListViewModel::class.java)
- viewModel.getFolders(account).observe(parent, Observer {
- folders -> setUserFolders(folders)
- })
+
+ foldersLiveData?.removeObserver(foldersObserver)
+ foldersLiveData = viewModel.getFolders(account).apply {
+ observe(parent, foldersObserver)
+ }
+
updateFolderSettingsItem()
}
}
