1
0
Fork 0

For #9286 - Add isDefault to topsites

master
Tiger Oakes 2020-05-15 14:55:12 -07:00 committed by Emily Kager
parent ee62297b4c
commit cd64647a4d
2 changed files with 7 additions and 11 deletions

View File

@ -9,7 +9,6 @@ import androidx.lifecycle.LiveData
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.GlobalScope
import kotlinx.coroutines.launch
import kotlinx.coroutines.withContext
import mozilla.components.feature.top.sites.TopSite
import mozilla.components.feature.top.sites.TopSiteStorage
import mozilla.components.support.locale.LocaleManager
@ -34,8 +33,8 @@ class TopSiteStorage(private val context: Context) {
/**
* Adds a new [TopSite].
*/
fun addTopSite(title: String, url: String) {
storage.addTopSite(title, url)
fun addTopSite(title: String, url: String, isDefault: Boolean = false) {
storage.addTopSite(title, url, isDefault)
}
/**
@ -78,15 +77,12 @@ class TopSiteStorage(private val context: Context) {
)
)
GlobalScope.launch(Dispatchers.Main) {
withContext(Dispatchers.IO) {
topSiteCandidates.forEach {
addTopSite(it.first, it.second)
}
GlobalScope.launch(Dispatchers.IO) {
topSiteCandidates.forEach { (title, url) ->
addTopSite(title, url, isDefault = true)
}
}
context.settings().preferences.edit()
.putBoolean(context.getString(R.string.default_top_sites_added), true).apply()
context.settings().defaultTopSitesAdded = true
}
}
}

View File

@ -439,7 +439,7 @@ class Settings private constructor(
default = true
)
val defaultTopSitesAdded by booleanPreference(
var defaultTopSitesAdded by booleanPreference(
appContext.getPreferenceKey(R.string.default_top_sites_added),
default = false
)