40 lines
1.3 KiB
Kotlin
40 lines
1.3 KiB
Kotlin
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
|
|
|
package org.mozilla.fenix.library
|
|
|
|
import androidx.fragment.app.Fragment
|
|
import androidx.navigation.fragment.findNavController
|
|
import org.mozilla.fenix.BrowsingModeManager
|
|
import org.mozilla.fenix.HomeActivity
|
|
import org.mozilla.fenix.R
|
|
import org.mozilla.fenix.ext.components
|
|
|
|
abstract class LibraryPageFragment<T> : Fragment() {
|
|
|
|
abstract val selectedItems: Set<T>
|
|
|
|
protected fun close() {
|
|
findNavController().popBackStack(R.id.libraryFragment, true)
|
|
}
|
|
|
|
protected fun openItemsInNewTab(private: Boolean = false, toUrl: (T) -> String?) {
|
|
context?.components?.useCases?.tabsUseCases?.let { tabsUseCases ->
|
|
val addTab = if (private) tabsUseCases.addPrivateTab else tabsUseCases.addTab
|
|
selectedItems.asSequence()
|
|
.mapNotNull(toUrl)
|
|
.forEach { url ->
|
|
addTab.invoke(url)
|
|
}
|
|
}
|
|
|
|
(activity as HomeActivity).browsingModeManager.mode = if (private) {
|
|
BrowsingModeManager.Mode.Private
|
|
} else {
|
|
BrowsingModeManager.Mode.Normal
|
|
}
|
|
(activity as HomeActivity).supportActionBar?.hide()
|
|
}
|
|
}
|