1
0
Fork 0

Use .orEmpty()

master
Tiger Oakes 2019-09-14 11:10:11 -07:00 committed by Emily Kager
parent 3e132f102c
commit 284cbab9ea
7 changed files with 16 additions and 23 deletions

View File

@ -114,9 +114,7 @@ open class FenixApplication : Application() {
private fun registerRxExceptionHandling() { private fun registerRxExceptionHandling() {
RxJavaPlugins.setErrorHandler { RxJavaPlugins.setErrorHandler {
it.cause?.run { throw it.cause ?: it
throw this
} ?: throw it
} }
} }

View File

@ -116,12 +116,10 @@ class LeanplumMetricsService(private val application: Application) : MetricsServ
private const val LOGTAG = "LeanplumMetricsService" private const val LOGTAG = "LeanplumMetricsService"
private val LeanplumId: String private val LeanplumId: String
@Suppress("USELESS_ELVIS")
// Debug builds have a null (nullable) LEANPLUM_ID // Debug builds have a null (nullable) LEANPLUM_ID
get() = BuildConfig.LEANPLUM_ID ?: "" get() = BuildConfig.LEANPLUM_ID.orEmpty()
private val LeanplumToken: String private val LeanplumToken: String
@Suppress("USELESS_ELVIS")
// Debug builds have a null (nullable) LEANPLUM_TOKEN // Debug builds have a null (nullable) LEANPLUM_TOKEN
get() = BuildConfig.LEANPLUM_TOKEN ?: "" get() = BuildConfig.LEANPLUM_TOKEN.orEmpty()
} }
} }

View File

@ -53,20 +53,17 @@ object MozillaProductDetector {
return true return true
} }
// Returns the default browser if and only if it is a Mozilla product /**
* Returns the default browser if and only if it is a Mozilla product.
*/
fun getMozillaBrowserDefault(context: Context): String? { fun getMozillaBrowserDefault(context: Context): String? {
val browserPackageName = Browsers.all(context).defaultBrowser?.packageName val browserPackageName = Browsers.all(context).defaultBrowser?.packageName
return if (isMozillaProduct(browserPackageName ?: "")) { browserPackageName } else { null } return if (isMozillaProduct(browserPackageName)) { browserPackageName } else { null }
} }
// Note: we intentionally do not use a-c `firefoxBrandedBrowser` as this only gives us the first from that list // Note: we intentionally do not use a-c `firefoxBrandedBrowser` as this only gives us the first from that list
private fun isMozillaProduct(packageName: String): Boolean { private fun isMozillaProduct(packageName: String?): Boolean {
for (product in MozillaProducts.values()) { packageName ?: return false
if (product.productName == packageName) { return MozillaProducts.values().any { product -> product.productName == packageName }
return true
}
}
return false
} }
} }

View File

@ -33,13 +33,13 @@ class BookmarkAdapter(val emptyView: View, val interactor: BookmarkViewInteracto
val diffUtil = DiffUtil.calculateDiff( val diffUtil = DiffUtil.calculateDiff(
BookmarkDiffUtil( BookmarkDiffUtil(
this.tree, this.tree,
tree?.children ?: listOf(), tree?.children.orEmpty(),
this.mode, this.mode,
mode mode
) )
) )
this.tree = tree?.children ?: listOf() this.tree = tree?.children.orEmpty()
isFirstRun = if (isFirstRun) false else { isFirstRun = if (isFirstRun) false else {
emptyView.isVisible = this.tree.isEmpty() emptyView.isVisible = this.tree.isEmpty()
false false

View File

@ -83,7 +83,7 @@ class SearchFragment : Fragment(), BackHandler {
?.let { it.showShortcutEnginePicker } ?: false ?.let { it.showShortcutEnginePicker } ?: false
val view = inflater.inflate(R.layout.fragment_search, container, false) val view = inflater.inflate(R.layout.fragment_search, container, false)
val url = session?.url ?: "" val url = session?.url.orEmpty()
val currentSearchEngine = SearchEngineSource.Default( val currentSearchEngine = SearchEngineSource.Default(
requireComponents.search.searchEngineManager.getDefaultSearchEngine(requireContext()) requireComponents.search.searchEngineManager.getDefaultSearchEngine(requireContext())
) )

View File

@ -116,7 +116,7 @@ class ToolbarView(
/* Only set the search terms if pasted text is null so that the search term doesn't /* Only set the search terms if pasted text is null so that the search term doesn't
overwrite pastedText when view enters `editMode` */ overwrite pastedText when view enters `editMode` */
if (searchState.pastedText.isNullOrEmpty()) { if (searchState.pastedText.isNullOrEmpty()) {
view.setSearchTerms(searchState.session?.searchTerms ?: "") view.setSearchTerms(searchState.session?.searchTerms.orEmpty())
} }
view.editMode() view.editMode()

View File

@ -119,7 +119,7 @@ class ShareFragment : AppCompatDialogFragment() {
throw IllegalStateException("URL and tabs cannot both be null.") throw IllegalStateException("URL and tabs cannot both be null.")
} }
val tabs = args.tabs?.toList() ?: listOf(ShareTab(args.url!!, args.title ?: "")) val tabs = args.tabs?.toList() ?: listOf(ShareTab(args.url!!, args.title.orEmpty()))
val accountManager = requireComponents.backgroundServices.accountManager val accountManager = requireComponents.backgroundServices.accountManager
shareInteractor = ShareInteractor( shareInteractor = ShareInteractor(
@ -167,7 +167,7 @@ class ShareFragment : AppCompatDialogFragment() {
resolveInfo.activityInfo.packageName, resolveInfo.activityInfo.packageName,
resolveInfo.activityInfo.name resolveInfo.activityInfo.name
) )
} ?: emptyList() }.orEmpty()
} }
@Suppress("ReturnCount") @Suppress("ReturnCount")