Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
41 commits
Select commit Hold shift + click to select a range
f73798c
Update navComponentVersion to 2.4.2
oguzkocer May 24, 2022
26b9c46
Ignore NullSafeMutableLiveData lint error
oguzkocer May 24, 2022
a6e9cc1
Disable NullSafeMutableLiveData from build.gradle
oguzkocer May 24, 2022
2d2973d
Fixes FragmentLiveDataObserve lint errors
oguzkocer May 24, 2022
51af542
Adds defaultValue @null to outputFileExtension in nav_graph
oguzkocer May 25, 2022
77940f8
Improve the comment for disabling NullSafeMutableLiveData lint check
oguzkocer May 25, 2022
e0ff59f
Analysis: Remove global disabling of null safe mutable live data
ParaskP7 May 26, 2022
693e6c2
Analysis: Resolve null safe mutable live data for base list use case
ParaskP7 May 26, 2022
500e18b
Analysis: Resolve null safe mutable live data for show error message
ParaskP7 May 26, 2022
bab68ef
Analysis: Resolve null safe mutable live data for supported states
ParaskP7 May 26, 2022
8389885
Refactor: Optimize import for feature announcement
ParaskP7 May 26, 2022
f1b21db
Analysis: Resolve null safe mutable live data for feature announcement
ParaskP7 May 26, 2022
e7f736d
Refactor: Remove unused live data extensions (from 2017)
ParaskP7 May 26, 2022
38ca284
Refactor: Suppress null safe mutable live data for live data utils
ParaskP7 May 26, 2022
e7e8d25
Analysis: Resolve null safe mutable live data for media picker
ParaskP7 May 26, 2022
94c5a39
Analysis: Resolve null safe mutable live data for photo picker
ParaskP7 May 26, 2022
164638f
Refactor: Optimize import for plans view model
ParaskP7 May 26, 2022
c0d5ff0
Refactor: Remove unused cached plans live data
ParaskP7 May 26, 2022
18f4d59
Analysis: Resolve null safe mutable live data for plans
ParaskP7 May 26, 2022
4223d9b
Analysis: Resolve null safe mutable live data for plugin browser
ParaskP7 May 26, 2022
69a34df
Analysis: Resolve null safe mutable live data for post list
ParaskP7 May 26, 2022
e1decef
Analysis: Resolve null safe mutable live data for add category
ParaskP7 May 26, 2022
dab2bc1
Analysis: Resolve null safe mutable live data for publish settings
ParaskP7 May 26, 2022
5b053fb
Analysis: Resolve null safe mutable live data for selected date provider
ParaskP7 May 26, 2022
b937b2e
Refactor: Optimize import for site creation intents view model
ParaskP7 May 26, 2022
4b1845f
Analysis: Resolve null safe mutable live data for site creation
ParaskP7 May 26, 2022
26111ef
Refactor: Rename mutable site changed to expected backing field syntax
ParaskP7 May 26, 2022
990cb35
Analysis: Suppress null safe mutable live data for stats site provider
ParaskP7 May 26, 2022
e0dda4b
Refactor: Rename mutable snackbar message to a backing field syntax
ParaskP7 May 26, 2022
02f29f2
Analysis: Suppress null safe mutable live data for stats view all
ParaskP7 May 26, 2022
6b34694
Refactor: Remove redundant let call from on subfilter page updated
ParaskP7 May 26, 2022
b298cdb
Analysis: Suppress false positive null safe mutable live data errors
ParaskP7 May 26, 2022
7ee2401
Build: Update lifecycle to 2.4.1
ParaskP7 May 26, 2022
5626d1c
Build: Remove duplicate lifecycle declaration and update to 2.4.1
ParaskP7 May 27, 2022
7f8a613
Analysis: Resolve null safe mutable live data for base list use case
ParaskP7 May 27, 2022
a80fff2
Refactor: Optimize import for page parent and search view model
ParaskP7 May 27, 2022
f3c580c
Analysis: Resolve null safe mutable live data for page parent search
ParaskP7 May 27, 2022
46eeeea
Analysis: Resolve null safe mutable live data for pages
ParaskP7 May 27, 2022
54770fb
Analysis: Suppress null safe mutable live data for stats screens
ParaskP7 May 27, 2022
22ac5b3
Analysis: Suppress null safe mutable live data for pages
ParaskP7 May 27, 2022
14e5729
Merge pull request #16647 from wordpress-mobile/lint/resolve-null-saf…
oguzkocer May 31, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion WordPress/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -334,7 +334,6 @@ dependencies {

implementation "androidx.core:core:$androidxCoreVersion"
implementation "androidx.core:core-ktx:$androidxCoreVersion"
implementation "androidx.lifecycle:lifecycle-extensions:$lifecycleVersion"
implementation "androidx.lifecycle:lifecycle-runtime-ktx:$lifecycleVersion"
implementation 'androidx.legacy:legacy-support-core-ui:1.0.0'
implementation "androidx.fragment:fragment:$fragmentVersion"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@ class ActivityLogListFragment : Fragment(R.layout.activity_log_list_fragment) {
}
})

viewModel.moveToTop.observe(this@ActivityLogListFragment, {
viewModel.moveToTop.observe(viewLifecycleOwner, {
logListView.scrollToPosition(0)
})

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ class DomainRegistrationDetailsViewModel @Inject constructor(
private var siteCheckTries = 0

private var supportedCountries: List<SupportedDomainCountry>? = null
private val _supportedStates = MutableLiveData<List<SupportedStateResponse>>()
private val _supportedStates = MutableLiveData<List<SupportedStateResponse>?>()

private val _uiState = MutableLiveData<DomainRegistrationDetailsUiState>()
val uiState: LiveData<DomainRegistrationDetailsUiState>
Expand Down Expand Up @@ -188,7 +188,7 @@ class DomainRegistrationDetailsViewModel @Inject constructor(
isStateProgressIndicatorVisible = false,
isDomainRegistrationButtonEnabled = true
)
_showErrorMessage.value = event.error.message
event.error?.message?.let { _showErrorMessage.value = it }
AppLog.e(T.DOMAIN_REGISTRATION, "An error occurred while fetching supported countries")
} else {
_uiState.value = uiState.value?.copy(
Expand Down Expand Up @@ -255,7 +255,7 @@ class DomainRegistrationDetailsViewModel @Inject constructor(
@Subscribe(threadMode = ThreadMode.MAIN)
fun onPrimaryDomainDesignated(event: OnPrimaryDomainDesignated) {
if (event.isError) { // in case of error we notify used and proceed to next step
_showErrorMessage.value = event.error.message
event.error?.message?.let { _showErrorMessage.value = it }
AppLog.e(
T.DOMAIN_REGISTRATION,
"An error occurred while redeeming a shopping cart : " + event.error.type +
Expand All @@ -273,7 +273,7 @@ class DomainRegistrationDetailsViewModel @Inject constructor(
T.DOMAIN_REGISTRATION,
"An error occurred while updating site details : " + event.error.message
)
_showErrorMessage.value = event.error.message
event.error?.message?.let { _showErrorMessage.value = it }
finishRegistration()
return
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package org.wordpress.android.ui.main

import android.annotation.SuppressLint
import androidx.lifecycle.LiveData
import androidx.lifecycle.MutableLiveData
import androidx.lifecycle.map
Expand Down Expand Up @@ -89,6 +90,7 @@ class MeViewModel
_showScanLoginCode.value = Event(true)
}

@SuppressLint("NullSafeMutableLiveData")
fun onRecommendTheApp() {
when (val state = _recommendUiState.value) {
is ApiFetchedResult -> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ class MediaPickerViewModel @Inject constructor(
private val loadActions = Channel<LoadAction>()
private var searchJob: Job? = null
private val _domainModel = MutableLiveData<DomainModel>()
private val _selectedIds = MutableLiveData<List<Identifier>>()
private val _selectedIds = MutableLiveData<List<Identifier>?>()
private val _onPermissionsRequested = MutableLiveData<Event<PermissionsRequested>>()
private val _softAskRequest = MutableLiveData<SoftAskRequest>()
private val _searchExpanded = MutableLiveData<Boolean>()
Expand Down Expand Up @@ -193,7 +193,7 @@ class MediaPickerViewModel @Inject constructor(
}

val fileExtension = it.mimeType?.let { mimeType ->
mediaUtilsWrapper.getExtensionForMimeType(mimeType).toUpperCase(localeManagerWrapper.getLocale())
mediaUtilsWrapper.getExtensionForMimeType(mimeType).uppercase(localeManagerWrapper.getLocale())
}
when (it.type) {
IMAGE -> PhotoItem(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -468,7 +468,7 @@ class PagesFragment : Fragment(R.layout.pages_fragment), ScrollableViewInitializ
}
})

viewModel.publishAction.observe(this@PagesFragment, {
viewModel.publishAction.observe(viewLifecycleOwner, {
it?.let {
uploadUtilsWrapper.publishPost(activity, it.post, it.site)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,6 @@ import org.wordpress.android.util.merge
import org.wordpress.android.viewmodel.Event
import org.wordpress.android.viewmodel.ResourceProvider
import org.wordpress.android.viewmodel.ScopedViewModel
import java.util.HashMap
import javax.inject.Inject
import javax.inject.Named

Expand All @@ -81,7 +80,7 @@ class PhotoPickerViewModel @Inject constructor(
private val _onInsert = MutableLiveData<Event<List<UriWrapper>>>()
private val _showPopupMenu = MutableLiveData<Event<PopupMenuUiModel>>()
private val _photoPickerItems = MutableLiveData<List<PhotoPickerItem>>()
private val _selectedIds = MutableLiveData<List<Long>>()
private val _selectedIds = MutableLiveData<List<Long>?>()
private val _onIconClicked = MutableLiveData<Event<IconClickEvent>>()
private val _onPermissionsRequested = MutableLiveData<Event<PermissionsRequested>>()
private val _softAskRequest = MutableLiveData<SoftAskRequest>()
Expand All @@ -94,7 +93,7 @@ class PhotoPickerViewModel @Inject constructor(
val onShowPopupMenu: LiveData<Event<PopupMenuUiModel>> = _showPopupMenu
val onPermissionsRequested: LiveData<Event<PermissionsRequested>> = _onPermissionsRequested

val selectedIds: LiveData<List<Long>> = _selectedIds
val selectedIds: LiveData<List<Long>?> = _selectedIds

val uiState: LiveData<PhotoPickerUiState> = merge(
_photoPickerItems.distinct(),
Expand Down Expand Up @@ -254,9 +253,7 @@ class PhotoPickerViewModel @Inject constructor(
lastTappedIcon: PhotoPickerIcon?,
site: SiteModel?
) {
selectedIds?.let {
_selectedIds.value = selectedIds
}
_selectedIds.value = selectedIds
this.browserType = browserType
this.lastTappedIcon = lastTappedIcon
this.site = site
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package org.wordpress.android.ui.plans
import androidx.lifecycle.LiveData
import androidx.lifecycle.MutableLiveData
import kotlinx.coroutines.CoroutineDispatcher
import kotlinx.coroutines.launch
import org.greenrobot.eventbus.Subscribe
import org.greenrobot.eventbus.ThreadMode
import org.wordpress.android.analytics.AnalyticsTracker.Stat
Expand Down Expand Up @@ -41,14 +40,11 @@ class PlansViewModel @Inject constructor(
val listStatus: LiveData<PlansListStatus>
get() = _listStatus

private val _plans = MutableLiveData<List<PlanOffersModel>>()
val plans: LiveData<List<PlanOffersModel>>
private val _plans = MutableLiveData<List<PlanOffersModel>?>()
private val _cachedPlans = MutableLiveData<List<PlanOffersModel>?>()
val plans: LiveData<List<PlanOffersModel>?>
get() = _plans

private val _cachedPlans = MutableLiveData<List<PlanOffersModel>>()
val cachedPlans: LiveData<List<PlanOffersModel>>
get() = _cachedPlans

private val _showDialog = SingleLiveEvent<PlanOffersModel>()
val showDialog: LiveData<PlanOffersModel>
get() = _showDialog
Expand Down Expand Up @@ -90,7 +86,7 @@ class PlansViewModel @Inject constructor(

fun onShowCachedPlansButtonClicked() {
_listStatus.value = DONE
_plans.value = cachedPlans.value
_plans.value = _cachedPlans.value
}

@Subscribe(threadMode = ThreadMode.MAIN)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package org.wordpress.android.ui.posts

import android.annotation.SuppressLint
import android.content.Context
import android.content.Intent
import androidx.lifecycle.Lifecycle
Expand Down Expand Up @@ -144,8 +145,8 @@ class PostListMainViewModel @Inject constructor(
private val _isSearchExpanded = MutableLiveData<Boolean>()
val isSearchExpanded: LiveData<Boolean> = _isSearchExpanded

private val _searchQuery = MutableLiveData<String>()
val searchQuery: LiveData<String> = _searchQuery
private val _searchQuery = MutableLiveData<String?>()
val searchQuery: LiveData<String?> = _searchQuery

private val _onFabClicked = MutableLiveData<Event<Unit>>()
val onFabClicked: LiveData<Event<Unit>> = _onFabClicked
Expand Down Expand Up @@ -507,6 +508,7 @@ class PostListMainViewModel @Inject constructor(
/**
* Only the non-null variables will be changed in the current state
*/
@SuppressLint("NullSafeMutableLiveData")
private fun updateViewStateTriggerPagerChange(
isFabVisible: Boolean? = null,
isAuthorFilterVisible: Boolean? = null,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@ class PrepublishingAddCategoryViewModel @Inject constructor(
private var closeKeyboard = true
private lateinit var siteModel: SiteModel

private val _navigateBack = MutableLiveData<Bundle>()
val navigateBack: LiveData<Bundle> = _navigateBack
private val _navigateBack = MutableLiveData<Bundle?>()
val navigateBack: LiveData<Bundle?> = _navigateBack

private val _dismissKeyboard = MutableLiveData<Event<Unit>>()
val dismissKeyboard: LiveData<Event<Unit>> = _dismissKeyboard
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,8 @@ constructor(
val onToast: LiveData<Event<String>> = _onToast
private val _onShowNotificationDialog = MutableLiveData<Event<Period?>>()
val onShowNotificationDialog: LiveData<Event<Period?>> = _onShowNotificationDialog
private val _onNotificationTime = MutableLiveData<Period>()
val onNotificationTime: LiveData<Period> = _onNotificationTime
private val _onNotificationTime = MutableLiveData<Period?>()
val onNotificationTime: LiveData<Period?> = _onNotificationTime
private val _onNotificationAdded = MutableLiveData<Event<Notification>>()
val onNotificationAdded: LiveData<Event<Notification>> = _onNotificationAdded
private val _onAddToCalendar = MutableLiveData<Event<CalendarEvent>>()
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package org.wordpress.android.ui.reader.subfilter

import android.annotation.SuppressLint
import android.os.Bundle
import androidx.annotation.VisibleForTesting
import androidx.lifecycle.LiveData
Expand Down Expand Up @@ -288,13 +289,10 @@ class SubFilterViewModel @Inject constructor(
changeSubfilter(getCurrentSubfilterValue(), false, mTagFragmentStartedWith)
}

@SuppressLint("NullSafeMutableLiveData")
fun onSubfilterPageUpdated(category: SubfilterCategory, count: Int) {
val currentValue = _filtersMatchCount.value

currentValue?.let {
it.put(category, count)
}

currentValue?.put(category, count)
_filtersMatchCount.postValue(currentValue)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ class SiteCreationActivity : LocaleAwareActivity(),
})
}

override fun onIntentSelected(intent: String) {
override fun onIntentSelected(intent: String?) {
mainViewModel.onSiteIntentSelected(intent)
if (!siteNameFeatureConfig.isEnabled()) {
ActivityUtils.hideKeyboard(this)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ class SiteCreationMainVM @Inject constructor(
outState.putParcelable(KEY_SITE_CREATION_STATE, siteCreationState)
}

fun onSiteIntentSelected(intent: String) {
fun onSiteIntentSelected(intent: String?) {
siteCreationState = siteCreationState.copy(siteIntent = intent)
wizardManager.showNextStep()
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
package org.wordpress.android.ui.sitecreation.verticals

interface IntentsScreenListener {
fun onIntentSelected(intent: String)
fun onIntentSelected(intent: String?)
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Job
import org.wordpress.android.R
import org.wordpress.android.modules.BG_THREAD
import org.wordpress.android.ui.sitecreation.verticals.SiteCreationIntentsViewModel.IntentsUiState.Content.DefaultItems
import org.wordpress.android.ui.sitecreation.misc.SiteCreationTracker
import org.wordpress.android.ui.sitecreation.verticals.SiteCreationIntentsViewModel.IntentsUiState.Content.DefaultItems
import org.wordpress.android.ui.sitecreation.verticals.SiteCreationIntentsViewModel.IntentsUiState.Content.FullItemsList
import org.wordpress.android.viewmodel.SingleLiveEvent
import javax.inject.Inject
Expand Down Expand Up @@ -40,8 +40,8 @@ class SiteCreationIntentsViewModel @Inject constructor(
private val _onBackButtonPressed = SingleLiveEvent<Unit>()
val onBackButtonPressed: LiveData<Unit> = _onBackButtonPressed

private val _onIntentSelected = SingleLiveEvent<String>()
val onIntentSelected: LiveData<String> = _onIntentSelected
private val _onIntentSelected = SingleLiveEvent<String?>()
val onIntentSelected: LiveData<String?> = _onIntentSelected

fun start() {
if (isInitialized) return
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package org.wordpress.android.ui.stats.refresh

import android.annotation.SuppressLint
import androidx.annotation.StringRes
import androidx.lifecycle.LiveData
import androidx.lifecycle.MutableLiveData
Expand Down Expand Up @@ -33,8 +34,6 @@ class StatsViewAllViewModel(
private val dateSelector: StatsDateSelector,
@StringRes val title: Int
) : ScopedViewModel(mainDispatcher) {
private val mutableSnackbarMessage = MutableLiveData<Event<SnackbarMessageHolder>>()

val selectedDate = dateSelector.selectedDate

val dateSelectorData: LiveData<DateSelectorUiModel> = dateSelector.dateSelectorData.mapNullable {
Expand All @@ -55,7 +54,8 @@ class StatsViewAllViewModel(
private val _isRefreshing = MutableLiveData<Boolean>()
val isRefreshing: LiveData<Boolean> = _isRefreshing

val showSnackbarMessage: LiveData<Event<SnackbarMessageHolder>> = mutableSnackbarMessage
private val _showSnackbarMessage = MutableLiveData<Event<SnackbarMessageHolder>>()
val showSnackbarMessage: LiveData<Event<SnackbarMessageHolder>> = _showSnackbarMessage

val toolbarHasShadow = dateSelectorData.map { !it.isVisible }

Expand All @@ -70,8 +70,9 @@ class StatsViewAllViewModel(
dateSelector.updateDateSelector()
}

@SuppressLint("NullSafeMutableLiveData")
fun onPullToRefresh() {
mutableSnackbarMessage.value = null
_showSnackbarMessage.value = null
refreshData()
}

Expand All @@ -88,15 +89,16 @@ class StatsViewAllViewModel(
if (statsSiteProvider.hasLoadedSite()) {
useCase.fetch(refresh, forced)
} else {
mutableSnackbarMessage.postValue(
_showSnackbarMessage.postValue(
Event(SnackbarMessageHolder(UiStringRes(R.string.stats_site_not_loaded_yet)))
)
}
}
}

@SuppressLint("NullSafeMutableLiveData")
override fun onCleared() {
mutableSnackbarMessage.value = null
_showSnackbarMessage.value = null
useCase.clear()
statsSiteProvider.reset()
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ class StatsViewAllViewModelFactory(
private val dateSelector: StatsDateSelector,
@StringRes private val titleResource: Int
) : ViewModelProvider.Factory {
override fun <T : ViewModel?> create(modelClass: Class<T>): T {
override fun <T : ViewModel> create(modelClass: Class<T>): T {
if (modelClass.isAssignableFrom(StatsViewAllViewModel::class.java)) {
@Suppress("UNCHECKED_CAST")
return StatsViewAllViewModel(
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package org.wordpress.android.ui.stats.refresh

import android.annotation.SuppressLint
import android.content.Intent
import android.os.Bundle
import androidx.lifecycle.LiveData
Expand Down Expand Up @@ -197,6 +198,7 @@ class StatsViewModel
_isRefreshing.value = false
}

@SuppressLint("NullSafeMutableLiveData")
fun onPullToRefresh() {
_showSnackbarMessage.value = null
statsSiteProvider.clear()
Expand Down Expand Up @@ -245,6 +247,7 @@ class StatsViewModel
}
}

@SuppressLint("NullSafeMutableLiveData")
override fun onCleared() {
super.onCleared()
_showSnackbarMessage.value = null
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ class BaseListUseCase(
useCases.associateBy { it.type }.mapValues { entry -> entry.value.liveData }
)
private val statsTypes = MutableLiveData<List<StatsType>>()
val data: MediatorLiveData<UiModel> = mergeAsyncNotNull(this, statsTypes, blockListData) { types, map ->
val data: MediatorLiveData<UiModel?> = mergeAsyncNotNull(this, statsTypes, blockListData) { types, map ->
val result = types.mapNotNull {
if (map.containsKey(it)) {
map[it]
Expand All @@ -69,9 +69,9 @@ class BaseListUseCase(
distinct = false
)

private val mutableSnackbarMessage = MutableLiveData<Int>()
private val mutableSnackbarMessage = MutableLiveData<Int?>()
val snackbarMessage: LiveData<SnackbarMessageHolder> = mutableSnackbarMessage.map {
SnackbarMessageHolder(UiStringRes(it))
it?.let { SnackbarMessageHolder(UiStringRes(it)) }
}

private val mutableListSelected = SingleLiveEvent<Unit>()
Expand Down
Loading