From 3684b00fe240b5ed38d3ace1b228df1624993ee2 Mon Sep 17 00:00:00 2001 From: Sebastian Kaspari Date: Tue, 22 Jun 2021 15:25:10 +0200 Subject: [PATCH] Update AndroidX dependencies. --- app/build.gradle | 25 ++++++------- .../fragment/AddToHomescreenDialogFragment.kt | 1 + .../mozilla/focus/fragment/BrowserFragment.kt | 2 + .../focus/fragment/UrlInputFragment.kt | 1 + .../ui/SearchSuggestionsFragment.kt | 1 + .../focus/settings/GeneralSettingsFragment.kt | 8 ++-- .../InstalledSearchEnginesSettingsFragment.kt | 6 ++- .../ManualAddSearchEngineSettingsFragment.kt | 14 +++---- .../PrivacySecuritySettingsFragment.kt | 30 +++++++-------- .../RemoveSearchEnginesSettingsFragment.kt | 9 ++--- build.gradle | 2 - buildSrc/src/main/java/Dependencies.kt | 37 +++++++++++++++++++ service-telemetry/build.gradle | 2 +- 13 files changed, 89 insertions(+), 49 deletions(-) create mode 100644 buildSrc/src/main/java/Dependencies.kt diff --git a/app/build.gradle b/app/build.gradle index 4ffbd878242..23af36c7bda 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -151,17 +151,18 @@ configurations { } dependencies { - implementation "androidx.appcompat:appcompat:$support_libraries_version" - implementation "androidx.browser:browser:$support_libraries_version" - implementation "androidx.core:core-ktx:1.1.0" - implementation "com.google.android.material:material:$support_libraries_version" - implementation "androidx.cardview:cardview:$support_libraries_version" - implementation "androidx.recyclerview:recyclerview:$support_libraries_version" - implementation "androidx.legacy:legacy-support-v4:$support_libraries_version" - implementation "androidx.preference:preference:$support_libraries_version" - implementation 'io.sentry:sentry-android:1.7.21' + implementation Dependencies.androidx_appcompat + implementation Dependencies.androidx_browser + implementation Dependencies.androidx_cardview + implementation Dependencies.androidx_core_ktx + implementation Dependencies.androidx_lifecycle_extensions + implementation Dependencies.androidx_palette + implementation Dependencies.androidx_preferences + implementation Dependencies.androidx_recyclerview + + implementation Dependencies.google_material - implementation "androidx.lifecycle:lifecycle-extensions:$architecture_components_version" + implementation 'io.sentry:sentry-android:1.7.21' compileOnly 'net.jcip:jcip-annotations:1.0' implementation("com.google.code.findbugs:jsr305:3.0.2") @@ -198,8 +199,6 @@ dependencies { focusImplementation 'com.adjust.sdk:adjust-android:4.11.4' focusImplementation 'com.android.installreferrer:installreferrer:1.1' // Required by Adjust - implementation "androidx.palette:palette:$support_libraries_version" - jnaForTest "net.java.dev.jna:jna:${jna_version}@jar" testImplementation files(configurations.jnaForTest.copyRecursive().files) testImplementation "org.mozilla.telemetry:glean-forUnitTests:${project.ext.glean_version}" @@ -211,7 +210,7 @@ dependencies { testRuntimeOnly "org.junit.vintage:junit-vintage-engine:5.3.1" testImplementation "org.robolectric:robolectric:4.4" // required to support api level 28 testImplementation "org.mockito:mockito-core:3.11.0" - testImplementation "androidx.arch.core:core-testing:${architecture_components_version}" + testImplementation Dependencies.androidx_arch_core_testing androidTestImplementation "androidx.test.espresso:espresso-core:$espresso_version", { exclude group: 'com.android.support', module: 'support-annotations' diff --git a/app/src/main/java/org/mozilla/focus/fragment/AddToHomescreenDialogFragment.kt b/app/src/main/java/org/mozilla/focus/fragment/AddToHomescreenDialogFragment.kt index 6b6b3b104b2..8b86df5d533 100644 --- a/app/src/main/java/org/mozilla/focus/fragment/AddToHomescreenDialogFragment.kt +++ b/app/src/main/java/org/mozilla/focus/fragment/AddToHomescreenDialogFragment.kt @@ -93,6 +93,7 @@ class AddToHomescreenDialogFragment : DialogFragment() { return builder.create() } + @Suppress("DEPRECATION") // https://github.com/mozilla-mobile/focus-android/issues/4958 override fun onActivityCreated(savedInstanceState: Bundle?) { super.onActivityCreated(savedInstanceState) val dialog = dialog diff --git a/app/src/main/java/org/mozilla/focus/fragment/BrowserFragment.kt b/app/src/main/java/org/mozilla/focus/fragment/BrowserFragment.kt index aa3e536ca6a..caee0030571 100644 --- a/app/src/main/java/org/mozilla/focus/fragment/BrowserFragment.kt +++ b/app/src/main/java/org/mozilla/focus/fragment/BrowserFragment.kt @@ -218,6 +218,7 @@ class BrowserFragment : customTabId = tab.id, fragmentManager = parentFragmentManager, onNeedToRequestPermissions = { permissions -> + @Suppress("DEPRECATION") // https://github.com/mozilla-mobile/focus-android/issues/4959 requestPermissions(permissions, REQUEST_CODE_PROMPT_PERMISSIONS) } ), this, view) @@ -233,6 +234,7 @@ class BrowserFragment : DownloadService::class ), onNeedToRequestPermissions = { permissions -> + @Suppress("DEPRECATION") // https://github.com/mozilla-mobile/focus-android/issues/4959 requestPermissions(permissions, REQUEST_CODE_DOWNLOAD_PERMISSIONS) }, onDownloadStopped = { state, _, status -> diff --git a/app/src/main/java/org/mozilla/focus/fragment/UrlInputFragment.kt b/app/src/main/java/org/mozilla/focus/fragment/UrlInputFragment.kt index 011119dd33f..a773f4b2588 100644 --- a/app/src/main/java/org/mozilla/focus/fragment/UrlInputFragment.kt +++ b/app/src/main/java/org/mozilla/focus/fragment/UrlInputFragment.kt @@ -181,6 +181,7 @@ class UrlInputFragment : } } + @Suppress("DEPRECATION") // https://github.com/mozilla-mobile/focus-android/issues/4958 override fun onActivityCreated(savedInstanceState: Bundle?) { super.onActivityCreated(savedInstanceState) diff --git a/app/src/main/java/org/mozilla/focus/searchsuggestions/ui/SearchSuggestionsFragment.kt b/app/src/main/java/org/mozilla/focus/searchsuggestions/ui/SearchSuggestionsFragment.kt index d7895ead3ec..2da6a3a41c6 100644 --- a/app/src/main/java/org/mozilla/focus/searchsuggestions/ui/SearchSuggestionsFragment.kt +++ b/app/src/main/java/org/mozilla/focus/searchsuggestions/ui/SearchSuggestionsFragment.kt @@ -70,6 +70,7 @@ class SearchSuggestionsFragment : Fragment(), CoroutineScope { super.onPause() } + @Suppress("DEPRECATION") // https://github.com/mozilla-mobile/focus-android/issues/4958 override fun onActivityCreated(savedInstanceState: Bundle?) { super.onActivityCreated(savedInstanceState) diff --git a/app/src/main/java/org/mozilla/focus/settings/GeneralSettingsFragment.kt b/app/src/main/java/org/mozilla/focus/settings/GeneralSettingsFragment.kt index d30bc93963c..1e16a8b89b6 100644 --- a/app/src/main/java/org/mozilla/focus/settings/GeneralSettingsFragment.kt +++ b/app/src/main/java/org/mozilla/focus/settings/GeneralSettingsFragment.kt @@ -37,8 +37,8 @@ class GeneralSettingsFragment : BaseSettingsFragment(), super.onResume() val preference = - findPreference(getString(R.string.pref_key_default_browser)) as DefaultBrowserPreference - preference.update() + findPreference(getString(R.string.pref_key_default_browser)) as? DefaultBrowserPreference + preference?.update() preferenceManager.sharedPreferences.registerOnSharedPreferenceChangeListener(this) @@ -63,8 +63,8 @@ class GeneralSettingsFragment : BaseSettingsFragment(), InstalledSearchEnginesSettingsFragment.languageChanged = true val languagePreference = - findPreference(getString(R.string.pref_key_locale)) as ListPreference - val value = languagePreference.value + findPreference(getString(R.string.pref_key_locale)) as? ListPreference + val value = languagePreference?.value val localeManager = LocaleManager.getInstance() diff --git a/app/src/main/java/org/mozilla/focus/settings/InstalledSearchEnginesSettingsFragment.kt b/app/src/main/java/org/mozilla/focus/settings/InstalledSearchEnginesSettingsFragment.kt index 1de6ec09c8c..09d35827c71 100644 --- a/app/src/main/java/org/mozilla/focus/settings/InstalledSearchEnginesSettingsFragment.kt +++ b/app/src/main/java/org/mozilla/focus/settings/InstalledSearchEnginesSettingsFragment.kt @@ -100,8 +100,10 @@ class InstalledSearchEnginesSettingsFragment : BaseSettingsFragment() { preferenceScreen?.removeAll() addPreferencesFromResource(R.xml.search_engine_settings) - val pref = preferenceScreen.findPreference(resources.getString(R.string.pref_key_radio_search_engine_list)) - (pref as RadioSearchEngineListPreference).refetchSearchEngines() + val pref: RadioSearchEngineListPreference? = preferenceScreen.findPreference( + resources.getString(R.string.pref_key_radio_search_engine_list) + ) + pref?.refetchSearchEngines() } } diff --git a/app/src/main/java/org/mozilla/focus/settings/ManualAddSearchEngineSettingsFragment.kt b/app/src/main/java/org/mozilla/focus/settings/ManualAddSearchEngineSettingsFragment.kt index 61e30388146..f9ba6712339 100644 --- a/app/src/main/java/org/mozilla/focus/settings/ManualAddSearchEngineSettingsFragment.kt +++ b/app/src/main/java/org/mozilla/focus/settings/ManualAddSearchEngineSettingsFragment.kt @@ -98,8 +98,8 @@ class ManualAddSearchEngineSettingsFragment : BaseSettingsFragment() { val searchQuery = requireView().findViewById(R.id.edit_search_string).text.toString() val pref = findManualAddSearchEnginePreference(R.string.pref_key_manual_add_search_engine) - val engineValid = pref.validateEngineNameAndShowError(engineName) - val searchValid = pref.validateSearchQueryAndShowError(searchQuery) + val engineValid = pref?.validateEngineNameAndShowError(engineName) ?: false + val searchValid = pref?.validateSearchQueryAndShowError(searchQuery) ?: false val isPartialSuccess = engineValid && searchValid if (isPartialSuccess) { @@ -138,12 +138,12 @@ class ManualAddSearchEngineSettingsFragment : BaseSettingsFragment() { view?.alpha = DISABLED_ALPHA // Delay showing the loading indicator to prevent it flashing on the screen handler.postDelayed({ - pref.setProgressViewShown(isValidating) + pref?.setProgressViewShown(isValidating) }, LOADING_INDICATOR_DELAY) } else { view?.alpha = 1f handler.removeCallbacksAndMessages(null) - pref.setProgressViewShown(isValidating) + pref?.setProgressViewShown(isValidating) } // Disable text entry until done validating @@ -164,8 +164,8 @@ class ManualAddSearchEngineSettingsFragment : BaseSettingsFragment() { } } - private fun findManualAddSearchEnginePreference(id: Int): ManualAddSearchEnginePreference { - return findPreference(getString(id)) as ManualAddSearchEnginePreference + private fun findManualAddSearchEnginePreference(id: Int): ManualAddSearchEnginePreference? { + return findPreference(getString(id)) as? ManualAddSearchEnginePreference } companion object { @@ -264,7 +264,7 @@ class ManualAddSearchEngineSettingsFragment : BaseSettingsFragment() { private fun showServerError(that: ManualAddSearchEngineSettingsFragment) { val pref = that.findManualAddSearchEnginePreference(R.string.pref_key_manual_add_search_engine) - pref.setSearchQueryErrorText(that.getString(R.string.error_hostLookup_title)) + pref?.setSearchQueryErrorText(that.getString(R.string.error_hostLookup_title)) } } } diff --git a/app/src/main/java/org/mozilla/focus/settings/PrivacySecuritySettingsFragment.kt b/app/src/main/java/org/mozilla/focus/settings/PrivacySecuritySettingsFragment.kt index c760f6928a1..2e0713eeedf 100644 --- a/app/src/main/java/org/mozilla/focus/settings/PrivacySecuritySettingsFragment.kt +++ b/app/src/main/java/org/mozilla/focus/settings/PrivacySecuritySettingsFragment.kt @@ -22,9 +22,9 @@ class PrivacySecuritySettingsFragment : BaseSettingsFragment(), override fun onCreatePreferences(p0: Bundle?, p1: String?) { addPreferencesFromResource(R.xml.privacy_security_settings) - val biometricPreference = findPreference(getString(R.string.pref_key_biometric)) + val biometricPreference: SwitchPreferenceCompat? = findPreference(getString(R.string.pref_key_biometric)) val appName = getString(R.string.app_name) - biometricPreference.summary = + biometricPreference?.summary = getString(R.string.preference_security_biometric_summary, appName) // Remove the biometric toggle if the software or hardware do not support it @@ -36,9 +36,9 @@ class PrivacySecuritySettingsFragment : BaseSettingsFragment(), } val cookiesPreference = - findPreference(getString(R.string.pref_key_performance_enable_cookies)) as CookiesPreference + findPreference(getString(R.string.pref_key_performance_enable_cookies)) as? CookiesPreference - cookiesPreference.updateSummary() + cookiesPreference?.updateSummary() } override fun onResume() { @@ -65,26 +65,26 @@ class PrivacySecuritySettingsFragment : BaseSettingsFragment(), private fun updateBiometricsToggleAvailability() { val switch = preferenceScreen.findPreference(resources.getString(R.string.pref_key_biometric)) - as SwitchPreferenceCompat + as? SwitchPreferenceCompat if (!Biometrics.hasFingerprintHardware(requireContext())) { - switch.isChecked = false - switch.isEnabled = false + switch?.isChecked = false + switch?.isEnabled = false preferenceManager.sharedPreferences .edit() .putBoolean(resources.getString(R.string.pref_key_biometric), false) .apply() } else { - switch.isEnabled = true + switch?.isEnabled = true } } private fun updateExceptionSettingAvailability() { - val exceptionsPreference = findPreference(getString(R.string.pref_key_screen_exceptions)) - exceptionsPreference.isEnabled = false + val exceptionsPreference: Preference? = findPreference(getString(R.string.pref_key_screen_exceptions)) + exceptionsPreference?.isEnabled = false requireComponents.trackingProtectionUseCases.fetchExceptions.invoke { exceptions -> - exceptionsPreference.isEnabled = exceptions.isNotEmpty() + exceptionsPreference?.isEnabled = exceptions.isNotEmpty() } } @@ -107,7 +107,7 @@ class PrivacySecuritySettingsFragment : BaseSettingsFragment(), private fun updateStealthToggleAvailability() { val switch = - preferenceScreen.findPreference(resources.getString(R.string.pref_key_secure)) as SwitchPreferenceCompat + preferenceScreen.findPreference(resources.getString(R.string.pref_key_secure)) as? SwitchPreferenceCompat if (preferenceManager.sharedPreferences .getBoolean( resources.getString(R.string.pref_key_biometric), @@ -120,11 +120,11 @@ class PrivacySecuritySettingsFragment : BaseSettingsFragment(), true ).apply() // Disable the stealth switch - switch.isChecked = true - switch.isEnabled = false + switch?.isChecked = true + switch?.isEnabled = false } else { // Enable the stealth switch - switch.isEnabled = true + switch?.isEnabled = true } } diff --git a/app/src/main/java/org/mozilla/focus/settings/RemoveSearchEnginesSettingsFragment.kt b/app/src/main/java/org/mozilla/focus/settings/RemoveSearchEnginesSettingsFragment.kt index a0576139518..f672549e2a1 100644 --- a/app/src/main/java/org/mozilla/focus/settings/RemoveSearchEnginesSettingsFragment.kt +++ b/app/src/main/java/org/mozilla/focus/settings/RemoveSearchEnginesSettingsFragment.kt @@ -43,10 +43,10 @@ class RemoveSearchEnginesSettingsFragment : BaseSettingsFragment() { view?.post { val pref = preferenceScreen .findPreference(resources.getString(R.string.pref_key_multiselect_search_engine_list)) - as MultiselectSearchEngineListPreference + as? MultiselectSearchEngineListPreference menu.findItem(R.id.menu_delete_items)?.let { - ViewUtils.setMenuItemEnabled(it, pref.atLeastOneEngineChecked()) + ViewUtils.setMenuItemEnabled(it, pref!!.atLeastOneEngineChecked()) } } } @@ -54,11 +54,10 @@ class RemoveSearchEnginesSettingsFragment : BaseSettingsFragment() { override fun onOptionsItemSelected(item: MenuItem): Boolean { return when (item.itemId) { R.id.menu_delete_items -> { - val pref = preferenceScreen + val pref: MultiselectSearchEngineListPreference? = preferenceScreen .findPreference(resources.getString(R.string.pref_key_multiselect_search_engine_list)) - val enginesToRemove = - (pref as MultiselectSearchEngineListPreference).checkedEngineIds + val enginesToRemove = pref!!.checkedEngineIds TelemetryWrapper.removeSearchEnginesEvent(enginesToRemove.size) requireComponents.store.state.search.searchEngines.filter { searchEngine -> diff --git a/build.gradle b/build.gradle index fdff1adb23e..92f3b841b08 100644 --- a/build.gradle +++ b/build.gradle @@ -1,8 +1,6 @@ // Top-level build file where you can add configuration options common to all sub-projects/modules. buildscript { - ext.architecture_components_version = '2.1.0' - ext.support_libraries_version = '1.0.0' ext.espresso_version = '3.1.0-alpha4' ext.kotlin_version = '1.4.30' ext.coroutines_version = '1.4.2' diff --git a/buildSrc/src/main/java/Dependencies.kt b/buildSrc/src/main/java/Dependencies.kt new file mode 100644 index 00000000000..7c015a65f0b --- /dev/null +++ b/buildSrc/src/main/java/Dependencies.kt @@ -0,0 +1,37 @@ +/* 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/. */ + +object Versions { + object AndroidX { + const val annotation = "1.1.0" + const val appcompat = "1.3.0" + const val arch = "2.1.0" + const val browser = "1.3.0" + const val core = "1.3.2" + const val cardview = "1.0.0" + const val recyclerview = "1.2.0" + const val palette = "1.0.0" + const val preferences = "1.1.1" + const val lifecycle = "2.2.0" + } + + object Google { + const val material = "1.2.1" + } +} + +object Dependencies { + const val androidx_annotation = "androidx.annotation:annotation:${Versions.AndroidX.annotation}" + const val androidx_arch_core_testing = "androidx.arch.core:core-testing:${Versions.AndroidX.arch}" + const val androidx_appcompat = "androidx.appcompat:appcompat:${Versions.AndroidX.appcompat}" + const val androidx_browser = "androidx.browser:browser:${Versions.AndroidX.browser}" + const val androidx_cardview = "androidx.cardview:cardview:${Versions.AndroidX.cardview}" + const val androidx_core_ktx = "androidx.core:core-ktx:${Versions.AndroidX.core}" + const val androidx_palette = "androidx.palette:palette-ktx:${Versions.AndroidX.palette}" + const val androidx_preferences = "androidx.preference:preference-ktx:${Versions.AndroidX.preferences}" + const val androidx_recyclerview = "androidx.recyclerview:recyclerview:${Versions.AndroidX.recyclerview}" + const val androidx_lifecycle_extensions = "androidx.lifecycle:lifecycle-extensions:${Versions.AndroidX.lifecycle}" + + const val google_material = "com.google.android.material:material:${Versions.Google.material}" +} diff --git a/service-telemetry/build.gradle b/service-telemetry/build.gradle index df05c0affd9..7ee467d8970 100644 --- a/service-telemetry/build.gradle +++ b/service-telemetry/build.gradle @@ -25,7 +25,7 @@ dependencies { implementation "org.mozilla.components:support-base:${AndroidComponents.VERSION}" implementation "org.mozilla.components:concept-fetch:${AndroidComponents.VERSION}" - implementation "androidx.annotation:annotation:$support_libraries_version" + implementation Dependencies.androidx_annotation implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"