For #3323 Runs PublicSuffixList synchronously
parent
a58a77317e
commit
decacbfc97
|
@ -57,6 +57,8 @@ open class HomeActivity : AppCompatActivity() {
|
|||
|
||||
override fun onCreate(savedInstanceState: Bundle?) {
|
||||
super.onCreate(savedInstanceState)
|
||||
|
||||
components.publicSuffixList.prefetch()
|
||||
browsingModeManager = createBrowsingModeManager()
|
||||
themeManager = createThemeManager(
|
||||
when (browsingModeManager.isPrivate) {
|
||||
|
|
|
@ -747,7 +747,6 @@ class BrowserFragment : Fragment(), BackHandler, CoroutineScope {
|
|||
private fun showSaveToCollection() {
|
||||
val context = context ?: return
|
||||
getSessionById()?.let {
|
||||
launch(Dispatchers.Main) {
|
||||
val tabs = Tab(it.id, it.url, it.url.urlToTrimmedHost(context), it.title)
|
||||
val viewModel = activity?.run {
|
||||
ViewModelProviders.of(this).get(CreateCollectionViewModel::class.java)
|
||||
|
@ -765,7 +764,6 @@ class BrowserFragment : Fragment(), BackHandler, CoroutineScope {
|
|||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private fun assignSitePermissionsRules() {
|
||||
val settings = Settings.getInstance(requireContext())
|
||||
|
|
|
@ -25,7 +25,6 @@ import kotlinx.android.synthetic.main.component_collection_creation.view.*
|
|||
import kotlinx.coroutines.CoroutineScope
|
||||
import kotlinx.coroutines.Dispatchers
|
||||
import kotlinx.coroutines.Job
|
||||
import kotlinx.coroutines.launch
|
||||
import mozilla.components.support.ktx.android.view.hideKeyboard
|
||||
import mozilla.components.support.ktx.android.view.showKeyboard
|
||||
import org.mozilla.fenix.R
|
||||
|
@ -268,7 +267,6 @@ class CollectionCreationUIView(
|
|||
is SaveCollectionStep.RenameCollection -> {
|
||||
view.tab_list.isClickable = false
|
||||
|
||||
launch(Dispatchers.Main) {
|
||||
it.selectedTabCollection?.let { tabCollection ->
|
||||
tabCollection.tabs.map { tab ->
|
||||
Tab(
|
||||
|
@ -281,7 +279,6 @@ class CollectionCreationUIView(
|
|||
collectionCreationTabListAdapter.updateData(tabs, tabs.toSet(), true)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
back_button.setOnClickListener {
|
||||
name_collection_edittext.hideKeyboard()
|
||||
|
|
|
@ -16,7 +16,6 @@ import kotlinx.android.synthetic.main.collections_list_item.view.collection_icon
|
|||
import kotlinx.coroutines.CoroutineScope
|
||||
import kotlinx.coroutines.Dispatchers
|
||||
import kotlinx.coroutines.Job
|
||||
import kotlinx.coroutines.launch
|
||||
import org.mozilla.fenix.R
|
||||
import org.mozilla.fenix.components.description
|
||||
import org.mozilla.fenix.home.sessioncontrol.Tab
|
||||
|
@ -82,7 +81,6 @@ class CollectionViewHolder(
|
|||
|
||||
fun bind(collection: TabCollection) {
|
||||
this.collection = collection
|
||||
launch(Dispatchers.Main) {
|
||||
view.collection_item.text = collection.title
|
||||
view.collection_description.text = collection.description(view.context)
|
||||
|
||||
|
@ -94,7 +92,6 @@ class CollectionViewHolder(
|
|||
android.graphics.PorterDuff.Mode.SRC_IN
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
@Suppress("ComplexMethod", "MagicNumber")
|
||||
private fun getIconColor(id: Long): Int {
|
||||
|
|
|
@ -91,7 +91,7 @@ class TabCollectionStorage(
|
|||
}
|
||||
}
|
||||
|
||||
suspend fun TabCollection.description(context: Context): String {
|
||||
fun TabCollection.description(context: Context): String {
|
||||
return this.tabs
|
||||
.map { it.url.urlToTrimmedHost(context).capitalize() }
|
||||
.map {
|
||||
|
|
|
@ -8,6 +8,7 @@ package org.mozilla.fenix.ext
|
|||
|
||||
import android.content.Context
|
||||
import androidx.core.net.toUri
|
||||
import kotlinx.coroutines.runBlocking
|
||||
import java.net.MalformedURLException
|
||||
import java.net.URL
|
||||
import mozilla.components.support.ktx.android.net.hostWithoutCommonPrefixes
|
||||
|
@ -34,10 +35,12 @@ fun String?.getHostFromUrl(): String? = try {
|
|||
/**
|
||||
* Trim a host's prefix and suffix
|
||||
*/
|
||||
suspend fun String.urlToTrimmedHost(context: Context): String {
|
||||
fun String.urlToTrimmedHost(context: Context): String {
|
||||
return try {
|
||||
val host = toUri().hostWithoutCommonPrefixes ?: return this
|
||||
runBlocking {
|
||||
context.components.publicSuffixList.stripPublicSuffix(host).await()
|
||||
}
|
||||
} catch (e: MalformedURLException) {
|
||||
this
|
||||
}
|
||||
|
|
|
@ -283,7 +283,6 @@ class HomeFragment : Fragment(), CoroutineScope, AccountObserver {
|
|||
}
|
||||
}
|
||||
|
||||
launch(Dispatchers.Main) {
|
||||
getManagedEmitter<SessionControlChange>().onNext(
|
||||
SessionControlChange.Change(
|
||||
tabs = getListOfTabs(sessionManager = requireComponents.core.sessionManager),
|
||||
|
@ -291,7 +290,6 @@ class HomeFragment : Fragment(), CoroutineScope, AccountObserver {
|
|||
collections = requireComponents.core.tabCollectionStorage.cachedTabCollections
|
||||
)
|
||||
)
|
||||
}
|
||||
|
||||
requireComponents.core.tabCollectionStorage.register(collectionStorageObserver, this)
|
||||
sessionObserver.onStart()
|
||||
|
@ -566,7 +564,6 @@ class HomeFragment : Fragment(), CoroutineScope, AccountObserver {
|
|||
}
|
||||
|
||||
private fun removeTabWithUndo(sessionId: String) {
|
||||
launch(Dispatchers.Main) {
|
||||
val sessionManager = requireComponents.core.sessionManager
|
||||
|
||||
// Update the UI with the tab removed, but don't remove it from storage yet
|
||||
|
@ -608,21 +605,18 @@ class HomeFragment : Fragment(), CoroutineScope, AccountObserver {
|
|||
operation = deleteOperation
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
private fun emitSessionChanges() {
|
||||
val sessionManager = context?.components?.core?.sessionManager ?: return
|
||||
|
||||
launch(Dispatchers.Main) {
|
||||
getManagedEmitter<SessionControlChange>().onNext(
|
||||
SessionControlChange.TabsChange(
|
||||
getListOfTabs(sessionManager)
|
||||
)
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
private suspend fun getListOfTabs(sessionManager: SessionManager): List<Tab> {
|
||||
private fun getListOfTabs(sessionManager: SessionManager): List<Tab> {
|
||||
val context = context ?: return listOf()
|
||||
return sessionManager.sessions
|
||||
.filter { (activity as HomeActivity).browsingModeManager.isPrivate == it.private }
|
||||
|
@ -653,7 +647,6 @@ class HomeFragment : Fragment(), CoroutineScope, AccountObserver {
|
|||
|
||||
val context = context?.let { it } ?: return
|
||||
|
||||
launch(Dispatchers.Main) {
|
||||
val tabs = requireComponents.core.sessionManager.sessions.filter { !it.private }
|
||||
.map { Tab(it.id, it.url, it.url.urlToTrimmedHost(context), it.title) }
|
||||
|
||||
|
@ -675,7 +668,6 @@ class HomeFragment : Fragment(), CoroutineScope, AccountObserver {
|
|||
nav(R.id.homeFragment, directions)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private fun share(url: String? = null, tabs: List<ShareTab>? = null) {
|
||||
val directions =
|
||||
|
|
|
@ -16,7 +16,6 @@ import kotlinx.android.synthetic.main.collection_home_list_row.view.*
|
|||
import kotlinx.coroutines.CoroutineScope
|
||||
import kotlinx.coroutines.Dispatchers
|
||||
import kotlinx.coroutines.Job
|
||||
import kotlinx.coroutines.launch
|
||||
import mozilla.components.browser.menu.BrowserMenuBuilder
|
||||
import mozilla.components.browser.menu.item.SimpleBrowserMenuItem
|
||||
import org.mozilla.fenix.R
|
||||
|
@ -82,7 +81,6 @@ class CollectionViewHolder(
|
|||
}
|
||||
|
||||
private fun updateCollectionUI() {
|
||||
launch(Dispatchers.Main) {
|
||||
view.collection_title.text = collection.title
|
||||
view.collection_description.text = collection.description(view.context)
|
||||
|
||||
|
@ -109,7 +107,6 @@ class CollectionViewHolder(
|
|||
android.graphics.PorterDuff.Mode.SRC_IN
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
private fun handleExpansion(isExpanded: Boolean) {
|
||||
if (isExpanded) {
|
||||
|
|
|
@ -79,9 +79,8 @@ class TabInCollectionViewHolder(
|
|||
}
|
||||
|
||||
private fun updateTabUI() {
|
||||
launch(Dispatchers.Main) {
|
||||
collection_tab_hostname.text = tab.url.urlToTrimmedHost(view.context)
|
||||
}
|
||||
|
||||
collection_tab_title.text = tab.title
|
||||
launch(Dispatchers.IO) {
|
||||
val bitmap = collection_tab_icon.context.components.core.icons
|
||||
|
|
|
@ -25,7 +25,6 @@ import androidx.navigation.NavController
|
|||
import androidx.navigation.Navigation
|
||||
import kotlinx.android.synthetic.main.fragment_bookmark.view.*
|
||||
import kotlinx.coroutines.CoroutineScope
|
||||
import kotlinx.coroutines.Dispatchers
|
||||
import kotlinx.coroutines.Dispatchers.IO
|
||||
import kotlinx.coroutines.Dispatchers.Main
|
||||
import kotlinx.coroutines.Job
|
||||
|
@ -268,7 +267,6 @@ class BookmarkFragment : Fragment(), CoroutineScope, BackHandler, AccountObserve
|
|||
getManagedEmitter<BookmarkChange>()
|
||||
.onNext(BookmarkChange.Change(currentRoot - it.item.guid))
|
||||
|
||||
launch(Dispatchers.Main) {
|
||||
allowUndo(
|
||||
view!!,
|
||||
getString(R.string.bookmark_deletion_snackbar_message,
|
||||
|
@ -281,7 +279,6 @@ class BookmarkFragment : Fragment(), CoroutineScope, BackHandler, AccountObserve
|
|||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
is BookmarkAction.SwitchMode -> {
|
||||
if ((bookmarkComponent.uiView as BookmarkUIView).mode is BookmarkState.Mode.Normal) {
|
||||
getManagedEmitter<BookmarkChange>().onNext(BookmarkChange.ClearSelection)
|
||||
|
|
Loading…
Reference in New Issue