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

View File

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