From 92e809fa6d421e4cc780bbdf85926ad8d5fe9e3d Mon Sep 17 00:00:00 2001 From: Benoit Marty Date: Mon, 6 Jul 2020 21:57:28 +0200 Subject: [PATCH] Fix lint error, following the upgrade of the libs --- .../settings/troubleshoot/TestBatteryOptimization.kt | 3 ++- .../im/vector/riotx/core/preference/VectorListPreference.kt | 4 +--- .../src/main/java/im/vector/riotx/core/utils/SystemUtils.kt | 2 +- .../crypto/keysbackup/setup/KeysBackupSetupStep2Fragment.kt | 4 ++-- .../crypto/keysbackup/setup/KeysBackupSetupStep3Fragment.kt | 6 +++--- .../crypto/recover/BootstrapSaveRecoveryKeyFragment.kt | 2 +- .../riotx/features/home/room/detail/RoomDetailFragment.kt | 2 +- .../riotx/features/roomprofile/RoomProfileFragment.kt | 2 +- .../riotx/features/settings/VectorSettingsBaseFragment.kt | 4 ++-- .../features/settings/VectorSettingsGeneralFragment.kt | 4 ++-- .../VectorSettingsNotificationsTroubleshootFragment.kt | 2 +- .../features/settings/VectorSettingsPreferencesFragment.kt | 2 +- .../account/deactivation/DeactivateAccountFragment.kt | 2 +- 13 files changed, 19 insertions(+), 20 deletions(-) diff --git a/vector/src/fdroid/java/im/vector/riotx/fdroid/features/settings/troubleshoot/TestBatteryOptimization.kt b/vector/src/fdroid/java/im/vector/riotx/fdroid/features/settings/troubleshoot/TestBatteryOptimization.kt index 4d18beac8f..2abbf7a419 100644 --- a/vector/src/fdroid/java/im/vector/riotx/fdroid/features/settings/troubleshoot/TestBatteryOptimization.kt +++ b/vector/src/fdroid/java/im/vector/riotx/fdroid/features/settings/troubleshoot/TestBatteryOptimization.kt @@ -26,7 +26,8 @@ import im.vector.riotx.features.settings.troubleshoot.TroubleshootTest class TestBatteryOptimization(val fragment: Fragment) : TroubleshootTest(R.string.settings_troubleshoot_test_battery_title) { override fun perform() { - if (fragment.context != null && isIgnoringBatteryOptimizations(fragment.context!!)) { + val context = fragment.context + if (context != null && isIgnoringBatteryOptimizations(context)) { description = fragment.getString(R.string.settings_troubleshoot_test_battery_success) status = TestStatus.SUCCESS quickFix = null diff --git a/vector/src/main/java/im/vector/riotx/core/preference/VectorListPreference.kt b/vector/src/main/java/im/vector/riotx/core/preference/VectorListPreference.kt index d85d343155..174c52d831 100644 --- a/vector/src/main/java/im/vector/riotx/core/preference/VectorListPreference.kt +++ b/vector/src/main/java/im/vector/riotx/core/preference/VectorListPreference.kt @@ -90,8 +90,6 @@ class VectorListPreference : ListPreference { fun setWarningIconVisible(isVisible: Boolean) { mIsWarningIconVisible = isVisible - if (null != mWarningIconView) { - mWarningIconView!!.visibility = if (mIsWarningIconVisible) View.VISIBLE else View.GONE - } + mWarningIconView?.visibility = if (mIsWarningIconVisible) View.VISIBLE else View.GONE } } diff --git a/vector/src/main/java/im/vector/riotx/core/utils/SystemUtils.kt b/vector/src/main/java/im/vector/riotx/core/utils/SystemUtils.kt index 9e5af038ef..900d5565dc 100644 --- a/vector/src/main/java/im/vector/riotx/core/utils/SystemUtils.kt +++ b/vector/src/main/java/im/vector/riotx/core/utils/SystemUtils.kt @@ -162,7 +162,7 @@ fun startImportTextFromFileIntent(fragment: Fragment, requestCode: Int) { val intent = Intent(Intent.ACTION_GET_CONTENT).apply { type = "text/plain" } - if (intent.resolveActivity(fragment.activity!!.packageManager) != null) { + if (intent.resolveActivity(fragment.requireActivity().packageManager) != null) { fragment.startActivityForResult(intent, requestCode) } else { fragment.activity?.toast(R.string.error_no_external_application_found) diff --git a/vector/src/main/java/im/vector/riotx/features/crypto/keysbackup/setup/KeysBackupSetupStep2Fragment.kt b/vector/src/main/java/im/vector/riotx/features/crypto/keysbackup/setup/KeysBackupSetupStep2Fragment.kt index 93d6f43763..a3306677fe 100644 --- a/vector/src/main/java/im/vector/riotx/features/crypto/keysbackup/setup/KeysBackupSetupStep2Fragment.kt +++ b/vector/src/main/java/im/vector/riotx/features/crypto/keysbackup/setup/KeysBackupSetupStep2Fragment.kt @@ -176,7 +176,7 @@ class KeysBackupSetupStep2Fragment @Inject constructor() : VectorBaseFragment() else -> { viewModel.megolmBackupCreationInfo = null - viewModel.prepareRecoveryKey(activity!!, viewModel.passphrase.value) + viewModel.prepareRecoveryKey(requireActivity(), viewModel.passphrase.value) } } } @@ -188,7 +188,7 @@ class KeysBackupSetupStep2Fragment @Inject constructor() : VectorBaseFragment() // Generate a recovery key for the user viewModel.megolmBackupCreationInfo = null - viewModel.prepareRecoveryKey(activity!!, null) + viewModel.prepareRecoveryKey(requireActivity(), null) } else -> { // User has entered a passphrase but want to skip this step. diff --git a/vector/src/main/java/im/vector/riotx/features/crypto/keysbackup/setup/KeysBackupSetupStep3Fragment.kt b/vector/src/main/java/im/vector/riotx/features/crypto/keysbackup/setup/KeysBackupSetupStep3Fragment.kt index 1478b99d3b..21a25f1684 100644 --- a/vector/src/main/java/im/vector/riotx/features/crypto/keysbackup/setup/KeysBackupSetupStep3Fragment.kt +++ b/vector/src/main/java/im/vector/riotx/features/crypto/keysbackup/setup/KeysBackupSetupStep3Fragment.kt @@ -105,7 +105,7 @@ class KeysBackupSetupStep3Fragment @Inject constructor() : VectorBaseFragment() @OnClick(R.id.keys_backup_setup_step3_copy_button) fun onCopyButtonClicked() { - val dialog = BottomSheetDialog(activity!!) + val dialog = BottomSheetDialog(requireActivity()) dialog.setContentView(R.layout.bottom_sheet_save_recovery_key) dialog.setCanceledOnTouchOutside(true) val recoveryKey = viewModel.recoveryKey.value!! @@ -124,7 +124,7 @@ class KeysBackupSetupStep3Fragment @Inject constructor() : VectorBaseFragment() } it.debouncedClicks { - copyToClipboard(activity!!, recoveryKey) + copyToClipboard(requireActivity(), recoveryKey) } } } @@ -159,7 +159,7 @@ class KeysBackupSetupStep3Fragment @Inject constructor() : VectorBaseFragment() viewModel.recoveryKey.value?.let { viewModel.copyHasBeenMade = true - copyToClipboard(activity!!, it) + copyToClipboard(requireActivity(), it) } } diff --git a/vector/src/main/java/im/vector/riotx/features/crypto/recover/BootstrapSaveRecoveryKeyFragment.kt b/vector/src/main/java/im/vector/riotx/features/crypto/recover/BootstrapSaveRecoveryKeyFragment.kt index 3ab48e44ff..2c31474122 100644 --- a/vector/src/main/java/im/vector/riotx/features/crypto/recover/BootstrapSaveRecoveryKeyFragment.kt +++ b/vector/src/main/java/im/vector/riotx/features/crypto/recover/BootstrapSaveRecoveryKeyFragment.kt @@ -78,7 +78,7 @@ class BootstrapSaveRecoveryKeyFragment @Inject constructor( if (resultCode == RESULT_OK && uri != null) { GlobalScope.launch(Dispatchers.IO) { try { - sharedViewModel.handle(BootstrapActions.SaveKeyToUri(context!!.contentResolver!!.openOutputStream(uri)!!)) + sharedViewModel.handle(BootstrapActions.SaveKeyToUri(requireContext().contentResolver!!.openOutputStream(uri)!!)) } catch (failure: Throwable) { sharedViewModel.handle(BootstrapActions.SaveReqFailed) } diff --git a/vector/src/main/java/im/vector/riotx/features/home/room/detail/RoomDetailFragment.kt b/vector/src/main/java/im/vector/riotx/features/home/room/detail/RoomDetailFragment.kt index 9d7ea58bb5..8c075004a9 100644 --- a/vector/src/main/java/im/vector/riotx/features/home/room/detail/RoomDetailFragment.kt +++ b/vector/src/main/java/im/vector/riotx/features/home/room/detail/RoomDetailFragment.kt @@ -1541,7 +1541,7 @@ class RoomDetailFragment @Inject constructor( } private fun showSnackWithMessage(message: String, duration: Int = Snackbar.LENGTH_SHORT) { - Snackbar.make(view!!, message, duration).show() + Snackbar.make(requireView(), message, duration).show() } // VectorInviteView.Callback diff --git a/vector/src/main/java/im/vector/riotx/features/roomprofile/RoomProfileFragment.kt b/vector/src/main/java/im/vector/riotx/features/roomprofile/RoomProfileFragment.kt index f0cb29ea6b..aa414ec2a1 100644 --- a/vector/src/main/java/im/vector/riotx/features/roomprofile/RoomProfileFragment.kt +++ b/vector/src/main/java/im/vector/riotx/features/roomprofile/RoomProfileFragment.kt @@ -243,7 +243,7 @@ class RoomProfileFragment @Inject constructor( private fun onAvatarClicked(view: View, matrixItem: MatrixItem.RoomItem) = withState(roomProfileViewModel) { if (matrixItem.avatarUrl?.isNotEmpty() == true) { val intent = BigImageViewerActivity.newIntent(requireContext(), matrixItem.getBestName(), matrixItem.avatarUrl!!, it.canChangeAvatar) - val options = ActivityOptionsCompat.makeSceneTransitionAnimation(activity!!, view, ViewCompat.getTransitionName(view) ?: "") + val options = ActivityOptionsCompat.makeSceneTransitionAnimation(requireActivity(), view, ViewCompat.getTransitionName(view) ?: "") startActivityForResult(intent, BigImageViewerActivity.REQUEST_CODE, options.toBundle()) } else if (it.canChangeAvatar) { showAvatarSelector() diff --git a/vector/src/main/java/im/vector/riotx/features/settings/VectorSettingsBaseFragment.kt b/vector/src/main/java/im/vector/riotx/features/settings/VectorSettingsBaseFragment.kt index 85d32251b6..c43a6ab40d 100644 --- a/vector/src/main/java/im/vector/riotx/features/settings/VectorSettingsBaseFragment.kt +++ b/vector/src/main/java/im/vector/riotx/features/settings/VectorSettingsBaseFragment.kt @@ -83,8 +83,8 @@ abstract class VectorSettingsBaseFragment : PreferenceFragmentCompat(), HasScree * ========================================================================================== */ protected fun notImplemented() { - // Snackbar cannot be display on PreferenceFragment - // Snackbar.make(view!!, R.string.not_implemented, Snackbar.LENGTH_SHORT) + // Snackbar cannot be display on PreferenceFragment. TODO It's maybe because the show() method is not used... + // Snackbar.make(requireView(), R.string.not_implemented, Snackbar.LENGTH_SHORT) activity?.toast(R.string.not_implemented) } diff --git a/vector/src/main/java/im/vector/riotx/features/settings/VectorSettingsGeneralFragment.kt b/vector/src/main/java/im/vector/riotx/features/settings/VectorSettingsGeneralFragment.kt index 18fa9d95ed..6bfb88a480 100644 --- a/vector/src/main/java/im/vector/riotx/features/settings/VectorSettingsGeneralFragment.kt +++ b/vector/src/main/java/im/vector/riotx/features/settings/VectorSettingsGeneralFragment.kt @@ -221,7 +221,7 @@ class VectorSettingsGeneralFragment : VectorSettingsBaseFragment() { it.onPreferenceClickListener = Preference.OnPreferenceClickListener { displayLoadingView() - MainActivity.restartApp(activity!!, MainActivityArgs(clearCache = true)) + MainActivity.restartApp(requireActivity(), MainActivityArgs(clearCache = true)) false } } @@ -622,7 +622,7 @@ class VectorSettingsGeneralFragment : VectorSettingsBaseFragment() { var order = addEmailBtn.order for ((index, email3PID) in currentEmail3PID.withIndex()) { - val preference = VectorPreference(activity!!) + val preference = VectorPreference(requireActivity()) preference.title = getString(R.string.settings_email_address) preference.summary = "TODO" // email3PID.address diff --git a/vector/src/main/java/im/vector/riotx/features/settings/VectorSettingsNotificationsTroubleshootFragment.kt b/vector/src/main/java/im/vector/riotx/features/settings/VectorSettingsNotificationsTroubleshootFragment.kt index 04908e166f..3ac097abfe 100644 --- a/vector/src/main/java/im/vector/riotx/features/settings/VectorSettingsNotificationsTroubleshootFragment.kt +++ b/vector/src/main/java/im/vector/riotx/features/settings/VectorSettingsNotificationsTroubleshootFragment.kt @@ -72,7 +72,7 @@ class VectorSettingsNotificationsTroubleshootFragment @Inject constructor( mRecyclerView.addItemDecoration(dividerItemDecoration) mSummaryButton.debouncedClicks { - bugReporter.openBugReportScreen(activity!!) + bugReporter.openBugReportScreen(requireActivity()) } mRunButton.debouncedClicks { diff --git a/vector/src/main/java/im/vector/riotx/features/settings/VectorSettingsPreferencesFragment.kt b/vector/src/main/java/im/vector/riotx/features/settings/VectorSettingsPreferencesFragment.kt index ed8f15db98..5848caacdb 100644 --- a/vector/src/main/java/im/vector/riotx/features/settings/VectorSettingsPreferencesFragment.kt +++ b/vector/src/main/java/im/vector/riotx/features/settings/VectorSettingsPreferencesFragment.kt @@ -134,7 +134,7 @@ class VectorSettingsPreferencesFragment @Inject constructor( selectedLanguagePreference.summary = VectorLocale.localeToLocalisedString(VectorLocale.applicationLocale) // Text size - textSizePreference.summary = getString(FontScale.getFontScaleValue(activity!!).nameResId) + textSizePreference.summary = getString(FontScale.getFontScaleValue(requireActivity()).nameResId) textSizePreference.onPreferenceClickListener = Preference.OnPreferenceClickListener { activity?.let { displayTextSizeSelection(it) } diff --git a/vector/src/main/java/im/vector/riotx/features/settings/account/deactivation/DeactivateAccountFragment.kt b/vector/src/main/java/im/vector/riotx/features/settings/account/deactivation/DeactivateAccountFragment.kt index 8a8a5fa4e4..447f1086be 100644 --- a/vector/src/main/java/im/vector/riotx/features/settings/account/deactivation/DeactivateAccountFragment.kt +++ b/vector/src/main/java/im/vector/riotx/features/settings/account/deactivation/DeactivateAccountFragment.kt @@ -107,7 +107,7 @@ class DeactivateAccountFragment @Inject constructor( displayErrorDialog(it.throwable) } DeactivateAccountViewEvents.Done -> - MainActivity.restartApp(activity!!, MainActivityArgs(clearCredentials = true, isAccountDeactivated = true)) + MainActivity.restartApp(requireActivity(), MainActivityArgs(clearCredentials = true, isAccountDeactivated = true)) }.exhaustive } }