From e6a4b4c2272efa9092b2c5a65a83f6b6f0a3e46e Mon Sep 17 00:00:00 2001 From: Emily Kager Date: Wed, 13 Mar 2019 16:55:38 -0700 Subject: [PATCH] [fenix] No issue: update Androidx dependencies --- .../fenix/settings/AccountSettingsFragment.kt | 50 ++++++++++-------- .../fenix/settings/DataChoicesFragment.kt | 2 +- .../fenix/settings/SettingsFragment.kt | 51 ++++++++++--------- buildSrc/src/main/java/Dependencies.kt | 10 ++-- 4 files changed, 62 insertions(+), 51 deletions(-) diff --git a/app/src/main/java/org/mozilla/fenix/settings/AccountSettingsFragment.kt b/app/src/main/java/org/mozilla/fenix/settings/AccountSettingsFragment.kt index fff0f46749..3b091d2a02 100644 --- a/app/src/main/java/org/mozilla/fenix/settings/AccountSettingsFragment.kt +++ b/app/src/main/java/org/mozilla/fenix/settings/AccountSettingsFragment.kt @@ -44,22 +44,24 @@ class AccountSettingsFragment : PreferenceFragmentCompat(), CoroutineScope { setPreferencesFromResource(R.xml.account_settings_preferences, rootKey) // Sign out - val signOut = context?.getPreferenceKey(R.string.pref_key_sign_out) + val signOut = context!!.getPreferenceKey(R.string.pref_key_sign_out) val preferenceSignOut = findPreference(signOut) - preferenceSignOut.onPreferenceClickListener = getClickListenerForSignOut() + preferenceSignOut?.onPreferenceClickListener = getClickListenerForSignOut() // Sync now - val syncNow = context?.getPreferenceKey(R.string.pref_key_sync_now) + val syncNow = context!!.getPreferenceKey(R.string.pref_key_sync_now) val preferenceSyncNow = findPreference(syncNow) - preferenceSyncNow.onPreferenceClickListener = getClickListenerForSyncNow() + preferenceSyncNow?.let { + preferenceSyncNow.onPreferenceClickListener = getClickListenerForSyncNow() - // Current sync state - updateLastSyncedTimePref(context!!, preferenceSyncNow) - if (requireComponents.backgroundServices.syncManager.isSyncRunning()) { - preferenceSyncNow.title = getString(R.string.sync_syncing) - preferenceSyncNow.isEnabled = false - } else { - preferenceSyncNow.isEnabled = true + // Current sync state + updateLastSyncedTimePref(context!!, preferenceSyncNow) + if (requireComponents.backgroundServices.syncManager.isSyncRunning()) { + preferenceSyncNow.title = getString(R.string.sync_syncing) + preferenceSyncNow.isEnabled = false + } else { + preferenceSyncNow.isEnabled = true + } } // NB: ObserverRegistry will take care of cleaning up internal references to 'observer' and @@ -87,30 +89,34 @@ class AccountSettingsFragment : PreferenceFragmentCompat(), CoroutineScope { private val syncStatusObserver = object : SyncStatusObserver { override fun onStarted() { CoroutineScope(Dispatchers.Main).launch { - val pref = findPreference(context?.getPreferenceKey(R.string.pref_key_sync_now)) + val pref = findPreference(context!!.getPreferenceKey(R.string.pref_key_sync_now)) - pref.title = getString(R.string.sync_syncing) - pref.isEnabled = false + pref?.title = getString(R.string.sync_syncing) + pref?.isEnabled = false } } // Sync stopped successfully. override fun onIdle() { CoroutineScope(Dispatchers.Main).launch { - val pref = findPreference(context?.getPreferenceKey(R.string.pref_key_sync_now)) - pref.title = getString(R.string.preferences_sync_now) - pref.isEnabled = true - updateLastSyncedTimePref(context!!, pref, failed = false) + val pref = findPreference(context!!.getPreferenceKey(R.string.pref_key_sync_now)) + pref?.let { + pref.title = getString(R.string.preferences_sync_now) + pref.isEnabled = true + updateLastSyncedTimePref(context!!, pref, failed = false) + } } } // Sync stopped after encountering a problem. override fun onError(error: Exception?) { CoroutineScope(Dispatchers.Main).launch { - val pref = findPreference(context?.getPreferenceKey(R.string.pref_key_sync_now)) - pref.title = getString(R.string.preferences_sync_now) - pref.isEnabled = true - updateLastSyncedTimePref(context!!, pref, failed = true) + val pref = findPreference(context!!.getPreferenceKey(R.string.pref_key_sync_now)) + pref?.let { + pref.title = getString(R.string.preferences_sync_now) + pref.isEnabled = true + updateLastSyncedTimePref(context!!, pref, failed = true) + } } } } diff --git a/app/src/main/java/org/mozilla/fenix/settings/DataChoicesFragment.kt b/app/src/main/java/org/mozilla/fenix/settings/DataChoicesFragment.kt index 3b5fbe549f..da71d8a183 100644 --- a/app/src/main/java/org/mozilla/fenix/settings/DataChoicesFragment.kt +++ b/app/src/main/java/org/mozilla/fenix/settings/DataChoicesFragment.kt @@ -22,7 +22,7 @@ class DataChoicesFragment : PreferenceFragmentCompat() { override fun onCreatePreferences(savedInstanceState: Bundle?, rootKey: String?) { setPreferencesFromResource(R.xml.data_choices_preferences, rootKey) - findPreference(getString(R.string.pref_key_telemetry)).apply { + findPreference(getString(R.string.pref_key_telemetry))?.apply { isChecked = Settings.getInstance(context).isTelemetryEnabled } } diff --git a/app/src/main/java/org/mozilla/fenix/settings/SettingsFragment.kt b/app/src/main/java/org/mozilla/fenix/settings/SettingsFragment.kt index 2d65b88deb..e18a61d943 100644 --- a/app/src/main/java/org/mozilla/fenix/settings/SettingsFragment.kt +++ b/app/src/main/java/org/mozilla/fenix/settings/SettingsFragment.kt @@ -70,9 +70,9 @@ class SettingsFragment : PreferenceFragmentCompat(), CoroutineScope, AccountObse (activity as AppCompatActivity).supportActionBar?.show() val preference = - findPreference(getString(R.string.pref_key_make_default_browser)) as DefaultBrowserPreference + findPreference(getString(R.string.pref_key_make_default_browser)) - preference.updateSwitch() + preference?.updateSwitch() generateWordmark() setupPreferences() setupAccountUI() @@ -176,18 +176,18 @@ class SettingsFragment : PreferenceFragmentCompat(), CoroutineScope, AccountObse } private fun setupPreferences() { - val makeDefaultBrowserKey = context?.getPreferenceKey(pref_key_make_default_browser) - val leakKey = context?.getPreferenceKey(pref_key_leakcanary) + val makeDefaultBrowserKey = context!!.getPreferenceKey(pref_key_make_default_browser) + val leakKey = context!!.getPreferenceKey(pref_key_leakcanary) val preferenceMakeDefaultBrowser = findPreference(makeDefaultBrowserKey) val preferenceLeakCanary = findPreference(leakKey) - preferenceMakeDefaultBrowser.onPreferenceClickListener = + preferenceMakeDefaultBrowser?.onPreferenceClickListener = getClickListenerForMakeDefaultBrowser() - preferenceLeakCanary.isVisible = BuildConfig.DEBUG + preferenceLeakCanary?.isVisible = BuildConfig.DEBUG if (BuildConfig.DEBUG) { - preferenceLeakCanary.onPreferenceChangeListener = + preferenceLeakCanary?.onPreferenceChangeListener = Preference.OnPreferenceChangeListener { _, newValue -> (context?.applicationContext as FenixApplication).toggleLeakCanary(newValue as Boolean) true @@ -220,7 +220,8 @@ class SettingsFragment : PreferenceFragmentCompat(), CoroutineScope, AccountObse } private fun navigateToSitePermissions() { - val directions = SettingsFragmentDirections.actionSettingsFragmentToSitePermissionsFragment() + val directions = + SettingsFragmentDirections.actionSettingsFragmentToSitePermissionsFragment() Navigation.findNavController(view!!).navigate(directions) } @@ -242,7 +243,8 @@ class SettingsFragment : PreferenceFragmentCompat(), CoroutineScope, AccountObse } private fun navigateToAccountSettings() { - val directions = SettingsFragmentDirections.actionSettingsFragmentToAccountSettingsFragment() + val directions = + SettingsFragmentDirections.actionSettingsFragmentToAccountSettingsFragment() Navigation.findNavController(view!!).navigate(directions) } @@ -267,29 +269,32 @@ class SettingsFragment : PreferenceFragmentCompat(), CoroutineScope, AccountObse // --- Account UI helpers --- private fun updateAuthState(account: OAuthAccount? = null) { - val preferenceSignIn = findPreference(context?.getPreferenceKey(pref_key_sign_in)) - val preferenceFirefoxAccount = findPreference(context?.getPreferenceKey(pref_key_account)) + val preferenceSignIn = + findPreference(context!!.getPreferenceKey(pref_key_sign_in)) + val preferenceFirefoxAccount = + findPreference(context!!.getPreferenceKey(pref_key_account)) val accountPreferenceCategory = - findPreference(context?.getPreferenceKey(pref_key_account_category)) + findPreference(context!!.getPreferenceKey(pref_key_account_category)) if (account != null) { - preferenceSignIn.isVisible = false - preferenceSignIn.onPreferenceClickListener = null - preferenceFirefoxAccount.isVisible = true - accountPreferenceCategory.isVisible = true + preferenceSignIn?.isVisible = false + preferenceSignIn?.onPreferenceClickListener = null + preferenceFirefoxAccount?.isVisible = true + accountPreferenceCategory?.isVisible = true } else { - preferenceSignIn.isVisible = true - preferenceSignIn.onPreferenceClickListener = getClickListenerForSignIn() - preferenceFirefoxAccount.isVisible = false - accountPreferenceCategory.isVisible = false + preferenceSignIn?.isVisible = true + preferenceSignIn?.onPreferenceClickListener = getClickListenerForSignIn() + preferenceFirefoxAccount?.isVisible = false + accountPreferenceCategory?.isVisible = false } } private fun updateAccountProfile(profile: Profile) { launch { - val preferenceFirefoxAccount = findPreference(context?.getPreferenceKey(pref_key_account)) - preferenceFirefoxAccount.title = profile.displayName.orEmpty() - preferenceFirefoxAccount.summary = profile.email.orEmpty() + val preferenceFirefoxAccount = + findPreference(context!!.getPreferenceKey(pref_key_account)) + preferenceFirefoxAccount?.title = profile.displayName.orEmpty() + preferenceFirefoxAccount?.summary = profile.email.orEmpty() } } diff --git a/buildSrc/src/main/java/Dependencies.kt b/buildSrc/src/main/java/Dependencies.kt index 81c7d74ae1..f7c4c2425c 100644 --- a/buildSrc/src/main/java/Dependencies.kt +++ b/buildSrc/src/main/java/Dependencies.kt @@ -13,13 +13,13 @@ private object Versions { const val leakcanary = "1.6.3" const val leanplum = "4.3.1" - const val androidx_appcompat = "1.1.0-alpha02" + const val androidx_appcompat = "1.1.0-alpha03" const val androidx_constraint_layout = "2.0.0-alpha2" - const val androidx_preference = "1.1.0-alpha03" + const val androidx_preference = "1.1.0-alpha04" const val androidx_legacy = "1.0.0" - const val androidx_annotation = "1.0.1" - const val androidx_lifecycle = "2.0.0" - const val androidx_fragment = "1.1.0-alpha04" + const val androidx_annotation = "1.1.0-alpha02" + const val androidx_lifecycle = "2.1.0-alpha03" + const val androidx_fragment = "1.1.0-alpha05" const val androidx_safeargs = "1.0.0-beta01" const val androidx_navigation = "2.0.0-rc02"