Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update compileSdkVersion to 33 #17842

Closed
wants to merge 14 commits into from
1 change: 1 addition & 0 deletions WordPress/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
<uses-permission android:name="android.permission.GET_ACCOUNTS" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED"/>
<uses-permission android:name="android.permission.POST_NOTIFICATIONS"/>

<!-- GCM all build types configuration -->
<uses-permission android:name="com.google.android.c2dm.permission.RECEIVE" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,13 @@ package org.wordpress.android.ui

import android.os.Bundle
import android.view.MenuItem
import androidx.activity.addCallback
import org.wordpress.android.R
import org.wordpress.android.analytics.AnalyticsTracker.Stat.INSTALL_JETPACK_CANCELLED
import org.wordpress.android.databinding.JetpackRemoteInstallActivityBinding
import org.wordpress.android.ui.JetpackConnectionUtils.trackWithSource
import org.wordpress.android.ui.JetpackRemoteInstallFragment.Companion.TRACKING_SOURCE_KEY
import org.wordpress.android.util.extensions.getSerializableExtraCompat

class JetpackRemoteInstallActivity : LocaleAwareActivity() {
public override fun onCreate(savedInstanceState: Bundle?) {
Expand All @@ -21,21 +23,20 @@ class JetpackRemoteInstallActivity : LocaleAwareActivity() {
it.setDisplayHomeAsUpEnabled(true)
it.setTitle(R.string.jetpack)
}

onBackPressedDispatcher.addCallback {
trackWithSource(
INSTALL_JETPACK_CANCELLED,
intent.getSerializableExtraCompat(TRACKING_SOURCE_KEY)
)
}
}

override fun onOptionsItemSelected(item: MenuItem): Boolean {
if (item.itemId == android.R.id.home) {
onBackPressed()
onBackPressedDispatcher.onBackPressed()
return true
}
return super.onOptionsItemSelected(item)
}

override fun onBackPressed() {
trackWithSource(
INSTALL_JETPACK_CANCELLED,
intent.getSerializableExtra(TRACKING_SOURCE_KEY) as JetpackConnectionSource
)
super.onBackPressed()
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ import org.wordpress.android.ui.JetpackRemoteInstallViewModel.JetpackResultActio
import org.wordpress.android.ui.RequestCodes.JETPACK_LOGIN
import org.wordpress.android.ui.accounts.LoginActivity
import org.wordpress.android.util.AppLog
import org.wordpress.android.util.extensions.getSerializableCompat
import org.wordpress.android.util.extensions.getSerializableExtraCompat
import javax.inject.Inject

class JetpackRemoteInstallFragment : Fragment(R.layout.jetpack_remote_install_fragment) {
Expand All @@ -44,25 +46,26 @@ class JetpackRemoteInstallFragment : Fragment(R.layout.jetpack_remote_install_fr
private fun JetpackRemoteInstallFragmentBinding.initViewModel(savedInstanceState: Bundle?) {
requireActivity().let { activity ->
val intent = activity.intent
val site = intent.getSerializableExtra(WordPress.SITE) as SiteModel
val source = intent.getSerializableExtra(TRACKING_SOURCE_KEY) as JetpackConnectionSource
val retrievedState = savedInstanceState?.getSerializable(VIEW_STATE) as? JetpackRemoteInstallViewState.Type
val site = intent.getSerializableExtraCompat<SiteModel>(WordPress.SITE)
val source = intent.getSerializableExtraCompat<JetpackConnectionSource>(TRACKING_SOURCE_KEY)
val retrievedState =
savedInstanceState?.getSerializableCompat<JetpackRemoteInstallViewState.Type>(VIEW_STATE)
viewModel = ViewModelProvider(
this@JetpackRemoteInstallFragment, viewModelFactory
).get(JetpackRemoteInstallViewModel::class.java)
viewModel.start(site, retrievedState)
)[JetpackRemoteInstallViewModel::class.java]
site?.let { viewModel.start(it, retrievedState) }

initLiveViewStateObserver()

viewModel.liveActionOnResult.observe(viewLifecycleOwner, Observer { result ->
if (result != null) {
viewModel.liveActionOnResult.observe(viewLifecycleOwner) { result ->
if (result != null && source != null) {
when (result.action) {
MANUAL_INSTALL -> onManualInstallResultAction(activity, source, result)
LOGIN -> onLoginResultAction(activity, source)
CONNECT -> onConnectResultAction(activity, source, result)
}
}
})
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ class WPTooltipView @JvmOverloads constructor(
.alpha(0f)
.setDuration(HIDE_ANIMATION_DURATION)
.setListener(object : AnimatorListenerAdapter() {
override fun onAnimationEnd(animation: Animator?) {
override fun onAnimationEnd(animation: Animator) {
super.onAnimationEnd(animation)
visibility = View.GONE
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import org.wordpress.android.ui.accounts.UnifiedLoginTracker
import org.wordpress.android.ui.accounts.UnifiedLoginTracker.Step
import org.wordpress.android.ui.accounts.login.jetpack.LoginNoSitesViewModel.State.NoUser
import org.wordpress.android.ui.accounts.login.jetpack.LoginNoSitesViewModel.State.ShowUser
import org.wordpress.android.util.extensions.getSerializableCompat
import org.wordpress.android.viewmodel.Event
import org.wordpress.android.viewmodel.ScopedViewModel
import java.io.Serializable
Expand Down Expand Up @@ -55,11 +56,11 @@ class LoginNoSitesViewModel @Inject constructor(
} else {
buildStateFromAccountStore()
}
_uiModel.postValue(UiModel(state = state))
state?.let { _uiModel.postValue(UiModel(state = it)) }
}

private fun buildStateFromSavedInstanceState(savedInstanceState: Bundle) =
savedInstanceState.getSerializable(KEY_STATE) as State
savedInstanceState.getSerializableCompat<State>(KEY_STATE)

private fun buildStateFromAccountStore() =
accountStore.account?.let {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ class ActivityLogDetailActivity : LocaleAwareActivity() {

override fun onOptionsItemSelected(item: MenuItem): Boolean {
if (item.itemId == android.R.id.home) {
onBackPressed()
onBackPressedDispatcher.onBackPressed()
return true
}
return super.onOptionsItemSelected(item)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ import org.wordpress.android.ui.notifications.utils.NotificationsUtilsWrapper
import org.wordpress.android.ui.reader.tracker.ReaderTracker
import org.wordpress.android.ui.utils.UiHelpers
import org.wordpress.android.util.JetpackBrandingUtils
import org.wordpress.android.util.extensions.getSerializableCompat
import org.wordpress.android.util.extensions.getSerializableExtraCompat
import org.wordpress.android.models.JetpackPoweredScreen
import org.wordpress.android.util.image.ImageManager
import org.wordpress.android.util.image.ImageType.AVATAR_WITH_BACKGROUND
Expand Down Expand Up @@ -84,7 +86,7 @@ class ActivityLogDetailFragment : Fragment(R.layout.activity_log_item_detail) {
val areButtonsVisible = areButtonsVisible(savedInstanceState, activity.intent)
val isRestoreHidden = isRestoreHidden(savedInstanceState, activity.intent)

viewModel.start(site, activityLogId, areButtonsVisible, isRestoreHidden)
site?.let { siteModel -> viewModel.start(siteModel, activityLogId, areButtonsVisible, isRestoreHidden) }
}

if (jetpackBrandingUtils.shouldShowJetpackBranding()) {
Expand Down Expand Up @@ -221,7 +223,7 @@ class ActivityLogDetailFragment : Fragment(R.layout.activity_log_item_detail) {

private fun sideAndActivityId(savedInstanceState: Bundle?, intent: Intent?) = when {
savedInstanceState != null -> {
val site = savedInstanceState.getSerializable(WordPress.SITE) as SiteModel
val site = savedInstanceState.getSerializableCompat<SiteModel>(WordPress.SITE)
val activityLogId = requireNotNull(
savedInstanceState.getString(
ACTIVITY_LOG_ID_KEY
Expand All @@ -230,7 +232,7 @@ class ActivityLogDetailFragment : Fragment(R.layout.activity_log_item_detail) {
site to activityLogId
}
intent != null -> {
val site = intent.getSerializableExtra(WordPress.SITE) as SiteModel
val site = intent.getSerializableExtraCompat<SiteModel>(WordPress.SITE)
val activityLogId = intent.getStringExtra(ACTIVITY_LOG_ID_KEY) as String
site to activityLogId
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ class ActivityLogListActivity : LocaleAwareActivity(), ScrollableViewInitialized

override fun onOptionsItemSelected(item: MenuItem): Boolean {
if (item.itemId == android.R.id.home) {
onBackPressed()
onBackPressedDispatcher.onBackPressed()
return true
}
return super.onOptionsItemSelected(item)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ import org.wordpress.android.ui.prefs.EmptyViewRecyclerView
import org.wordpress.android.ui.utils.UiHelpers
import org.wordpress.android.util.NetworkUtils
import org.wordpress.android.util.WPSwipeToRefreshHelper.buildSwipeToRefreshHelper
import org.wordpress.android.util.extensions.getSerializableCompat
import org.wordpress.android.util.extensions.getSerializableExtraCompat
import org.wordpress.android.util.helpers.SwipeToRefreshHelper
import org.wordpress.android.viewmodel.activitylog.ACTIVITY_LOG_REWINDABLE_ONLY_KEY
import org.wordpress.android.viewmodel.activitylog.ActivityLogViewModel
Expand Down Expand Up @@ -87,11 +89,11 @@ class ActivityLogListFragment : Fragment(R.layout.activity_log_list_fragment) {
}
}

val site = if (savedInstanceState == null) {
val site: SiteModel? = if (savedInstanceState == null) {
val nonNullIntent = checkNotNull(nonNullActivity.intent)
nonNullIntent.getSerializableExtra(WordPress.SITE) as SiteModel
nonNullIntent.getSerializableExtraCompat(WordPress.SITE)
} else {
savedInstanceState.getSerializable(WordPress.SITE) as SiteModel
savedInstanceState.getSerializableCompat(WordPress.SITE)
}
val rewindableOnly = nonNullActivity.intent.getBooleanExtra(ACTIVITY_LOG_REWINDABLE_ONLY_KEY, false)

Expand All @@ -106,7 +108,7 @@ class ActivityLogListFragment : Fragment(R.layout.activity_log_list_fragment) {

setupObservers()

viewModel.start(site, rewindableOnly)
site?.let { viewModel.start(it, rewindableOnly) }
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ import org.wordpress.android.util.SnackbarItem.Action
import org.wordpress.android.util.SnackbarItem.Info
import org.wordpress.android.util.SnackbarSequencer
import org.wordpress.android.util.extensions.exhaustive
import org.wordpress.android.util.extensions.getSerializableCompat
import org.wordpress.android.util.image.ImageManager
import org.wordpress.android.viewmodel.observeEvent
import javax.inject.Inject
Expand Down Expand Up @@ -96,9 +97,7 @@ class BloggingPromptsOnboardingDialogFragment : FeatureIntroductionDialogFragmen
@Suppress("UseCheckOrError")
override fun onAttach(context: Context) {
super.onAttach(context)
arguments?.let {
dialogType = it.getSerializable(KEY_DIALOG_TYPE) as DialogType
}
arguments?.getSerializableCompat<DialogType>(KEY_DIALOG_TYPE)?.let { dialogType = it }
(requireActivity().applicationContext as WordPress).component().inject(this)
if (dialogType == ONBOARDING && context !is BloggingPromptsReminderSchedulerListener) {
throw IllegalStateException(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,11 @@ class BloggingPromptsListActivity : LocaleAwareActivity() {
setContent {
AppTheme {
val uiState by viewModel.uiStateFlow.collectAsState()
BloggingPromptsListScreen(uiState, ::onBackPressed, viewModel::onPromptListItemClicked)
BloggingPromptsListScreen(
uiState,
{ onBackPressedDispatcher.onBackPressed() },
viewModel::onPromptListItemClicked
)
}
}
observeActions()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import org.wordpress.android.ui.bloggingreminders.BloggingRemindersAnalyticsTrac
import org.wordpress.android.ui.bloggingreminders.BloggingRemindersAnalyticsTracker.Source.PUBLISH_FLOW
import org.wordpress.android.ui.utils.ListItemInteraction
import org.wordpress.android.ui.utils.UiString
import org.wordpress.android.util.extensions.getSerializableCompat
import org.wordpress.android.util.merge
import org.wordpress.android.util.perform
import org.wordpress.android.viewmodel.Event
Expand Down Expand Up @@ -219,8 +220,8 @@ class BloggingRemindersViewModel @Inject constructor(
}

fun restoreState(state: Bundle) {
state.getSerializable(SELECTED_SCREEN)?.let {
_selectedScreen.value = it as Screen
state.getSerializableCompat<Screen>(SELECTED_SCREEN)?.let {
_selectedScreen.value = it
}
val siteId = state.getInt(SITE_ID)
if (siteId != 0) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,9 +73,10 @@ class CommentListActionModeCallback(
private fun setItemEnabled(menuItem: MenuItem, actionUiModel: ActionUiModel) {
menuItem.isVisible = actionUiModel.isVisible
menuItem.isEnabled = actionUiModel.isEnabled
if (menuItem.icon != null) {
val currentIcon = menuItem.icon
currentIcon?.let {
// must mutate the drawable to avoid affecting other instances of it
val icon = menuItem.icon.mutate()
val icon = currentIcon.mutate()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Minor (🔍): Consider using it.mutate instead.

icon.alpha = if (actionUiModel.isEnabled) ICON_ALPHA_ENABLED else ICON_ALPHA_DISABLED
menuItem.icon = icon
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ import org.wordpress.android.util.SnackbarItem.Info
import org.wordpress.android.util.SnackbarSequencer
import org.wordpress.android.util.WPSwipeToRefreshHelper
import org.wordpress.android.util.config.UnifiedCommentsDetailFeatureConfig
import org.wordpress.android.util.extensions.getSerializableCompat
import org.wordpress.android.util.helpers.SwipeToRefreshHelper
import javax.inject.Inject

Expand Down Expand Up @@ -70,14 +71,12 @@ class UnifiedCommentListFragment : Fragment(R.layout.unified_comment_list_fragme
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
(requireActivity().application as WordPress).component().inject(this)
viewModel = ViewModelProvider(this, viewModelFactory).get(UnifiedCommentListViewModel::class.java)
viewModel = ViewModelProvider(this, viewModelFactory)[UnifiedCommentListViewModel::class.java]
activityViewModel = ViewModelProvider(
requireActivity(),
viewModelFactory
).get(UnifiedCommentActivityViewModel::class.java)
arguments?.let {
commentListFilter = it.getSerializable(KEY_COMMENT_LIST_FILTER) as CommentFilter
}
)[UnifiedCommentActivityViewModel::class.java]
arguments?.getSerializableCompat<CommentFilter>(KEY_COMMENT_LIST_FILTER)?.let { commentListFilter = it }
}

override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ class UnifiedCommentsActivity : LocaleAwareActivity() {

override fun onOptionsItemSelected(item: MenuItem): Boolean {
if (item.itemId == android.R.id.home) {
onBackPressed()
onBackPressedDispatcher.onBackPressed()
return true
}
return super.onOptionsItemSelected(item)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ import org.wordpress.android.WordPress
import org.wordpress.android.databinding.UnifiedCommentsEditActivityBinding
import org.wordpress.android.fluxc.model.SiteModel
import org.wordpress.android.ui.LocaleAwareActivity
import org.wordpress.android.util.extensions.getParcelableExtraCompat
import org.wordpress.android.util.extensions.getSerializableExtraCompat

class UnifiedCommentsEditActivity : LocaleAwareActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
Expand All @@ -17,19 +19,22 @@ class UnifiedCommentsEditActivity : LocaleAwareActivity() {
setContentView(root)
}

val site = intent.getSerializableExtra(WordPress.SITE) as SiteModel
val commentIdentifier = requireNotNull(intent.getParcelableExtra<CommentIdentifier>(KEY_COMMENT_IDENTIFIER))
val site = intent.getSerializableExtraCompat<SiteModel>(WordPress.SITE)
val commentIdentifier =
requireNotNull(intent.getParcelableExtraCompat<CommentIdentifier>(KEY_COMMENT_IDENTIFIER))

val fm = supportFragmentManager
var editCommentFragment = fm.findFragmentByTag(
val editCommentFragment = fm.findFragmentByTag(
TAG_UNIFIED_EDIT_COMMENT_FRAGMENT
) as? UnifiedCommentsEditFragment

if (editCommentFragment == null) {
editCommentFragment = UnifiedCommentsEditFragment.newInstance(site, commentIdentifier)
fm.beginTransaction()
.add(R.id.fragment_container, editCommentFragment, TAG_UNIFIED_EDIT_COMMENT_FRAGMENT)
.commit()
site?.let {
val fragment = UnifiedCommentsEditFragment.newInstance(it, commentIdentifier)
fm.beginTransaction()
.add(R.id.fragment_container, fragment, TAG_UNIFIED_EDIT_COMMENT_FRAGMENT)
.commit()
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ import org.wordpress.android.util.SnackbarItem
import org.wordpress.android.util.SnackbarItem.Action
import org.wordpress.android.util.SnackbarItem.Info
import org.wordpress.android.util.SnackbarSequencer
import org.wordpress.android.util.extensions.getParcelableCompat
import org.wordpress.android.util.extensions.getSerializableCompat
import org.wordpress.android.viewmodel.observeEvent
import javax.inject.Inject

Expand Down Expand Up @@ -61,16 +63,16 @@ class UnifiedCommentsEditFragment : Fragment(R.layout.unified_comments_edit_frag
super.onViewCreated(view, savedInstanceState)
requireActivity().addMenuProvider(this, viewLifecycleOwner)

val site = requireArguments().getSerializable(WordPress.SITE) as SiteModel
val site = requireArguments().getSerializableCompat<SiteModel>(WordPress.SITE)
val commentIdentifier = requireNotNull(
requireArguments().getParcelable<CommentIdentifier>(
requireArguments().getParcelableCompat<CommentIdentifier>(
KEY_COMMENT_IDENTIFIER
)
)

UnifiedCommentsEditFragmentBinding.bind(view).apply {
setupToolbar()
setupObservers(site, commentIdentifier)
site?.let { setupObservers(it, commentIdentifier) }
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ class DebugSettingsActivity : LocaleAwareActivity() {

override fun onOptionsItemSelected(item: MenuItem): Boolean {
if (item.itemId == android.R.id.home) {
onBackPressed()
onBackPressedDispatcher.onBackPressed()
return true
}
return super.onOptionsItemSelected(item)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ class DebugCookiesActivity : LocaleAwareActivity() {

override fun onOptionsItemSelected(item: MenuItem) = when (item.itemId) {
android.R.id.home -> {
onBackPressed()
onBackPressedDispatcher.onBackPressed()
true
}
else -> super.onOptionsItemSelected(item)
Expand Down
Loading