From 5cfcfd1828fc6b8f2d21b8bb292a7dd15bb9fa9b Mon Sep 17 00:00:00 2001 From: Petros Paraskevopoulos Date: Tue, 7 Feb 2023 16:43:50 +0200 Subject: [PATCH 001/856] Deps: Extract indexos media for mobile version version --- WordPress/build.gradle | 2 +- build.gradle | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/WordPress/build.gradle b/WordPress/build.gradle index 93bfe0fef07a..f7c6839c77f0 100644 --- a/WordPress/build.gradle +++ b/WordPress/build.gradle @@ -433,7 +433,7 @@ dependencies { implementation "androidx.compose.material:material:$androidxComposeVersion" implementation "androidx.lifecycle:lifecycle-viewmodel-compose:$androidxComposeLifecycleVersion" implementation "io.coil-kt:coil-compose:$coilComposeVersion" - implementation ('com.github.indexos.media-for-mobile:android:43a9026f0973a2f0a74fa813132f6a16f7499c3a') + implementation "com.github.indexos.media-for-mobile:android:$indexosMediaForMobileVersion" implementation (group: 'com.zendesk', name: 'support', version: "$zendeskVersion") { exclude group: 'com.google.dagger' exclude group: 'com.android.support', module: 'support-annotations' diff --git a/build.gradle b/build.gradle index add16e93630b..bd2cff272e91 100644 --- a/build.gradle +++ b/build.gradle @@ -26,6 +26,7 @@ ext { wordPressLoginVersion = '1.0.0' wordPressPersistentEditTextVersion = '1.0.2' wordPressUtilsVersion = '3.2.0' + indexosMediaForMobileVersion = '43a9026f0973a2f0a74fa813132f6a16f7499c3a' // debug stethoVersion = '1.6.0' From 233ccdee4882375ce63f724f54a9a6815e7572d2 Mon Sep 17 00:00:00 2001 From: Petros Paraskevopoulos Date: Tue, 7 Feb 2023 16:47:22 +0200 Subject: [PATCH 002/856] Deps: Add media for mobile domain transitively used dependency It is generally recommended that transitively used dependencies should be declared directly. --- WordPress/build.gradle | 1 + 1 file changed, 1 insertion(+) diff --git a/WordPress/build.gradle b/WordPress/build.gradle index f7c6839c77f0..aff1bf202a8f 100644 --- a/WordPress/build.gradle +++ b/WordPress/build.gradle @@ -433,6 +433,7 @@ dependencies { implementation "androidx.compose.material:material:$androidxComposeVersion" implementation "androidx.lifecycle:lifecycle-viewmodel-compose:$androidxComposeLifecycleVersion" implementation "io.coil-kt:coil-compose:$coilComposeVersion" + implementation "com.github.indexos.media-for-mobile:domain:$indexosMediaForMobileVersion" implementation "com.github.indexos.media-for-mobile:android:$indexosMediaForMobileVersion" implementation (group: 'com.zendesk', name: 'support', version: "$zendeskVersion") { exclude group: 'com.google.dagger' From d40542d3dd294230e46017fd517dd854f125c404 Mon Sep 17 00:00:00 2001 From: Petros Paraskevopoulos Date: Tue, 7 Feb 2023 16:52:51 +0200 Subject: [PATCH 003/856] Cleanup: Remove unused m4m video optimizer --- .../android/ui/uploads/M4mVideoOptimizer.java | 106 ------------------ 1 file changed, 106 deletions(-) delete mode 100644 WordPress/src/main/java/org/wordpress/android/ui/uploads/M4mVideoOptimizer.java diff --git a/WordPress/src/main/java/org/wordpress/android/ui/uploads/M4mVideoOptimizer.java b/WordPress/src/main/java/org/wordpress/android/ui/uploads/M4mVideoOptimizer.java deleted file mode 100644 index da09ed327ece..000000000000 --- a/WordPress/src/main/java/org/wordpress/android/ui/uploads/M4mVideoOptimizer.java +++ /dev/null @@ -1,106 +0,0 @@ -package org.wordpress.android.ui.uploads; - -import androidx.annotation.NonNull; - -import org.m4m.MediaComposer; -import org.wordpress.android.analytics.AnalyticsTracker; -import org.wordpress.android.fluxc.model.MediaModel; -import org.wordpress.android.ui.prefs.AppPrefs; -import org.wordpress.android.util.AppLog; -import org.wordpress.android.util.WPVideoUtils; -import org.wordpress.android.util.analytics.AnalyticsUtils; - -import java.util.Map; - -import static org.wordpress.android.analytics.AnalyticsTracker.Stat.MEDIA_VIDEO_CANT_OPTIMIZE; - -public class M4mVideoOptimizer extends VideoOptimizerBase implements org.m4m.IProgressListener { - public M4mVideoOptimizer( - @NonNull MediaModel media, - @NonNull VideoOptimizationListener listener) { - super(media, listener); - } - - /* - * IProgressListener handlers - */ - @Override - public void onMediaStart() { - mStartTimeMS = System.currentTimeMillis(); - } - - @Override - public void onMediaProgress(float progress) { - sendProgressIfNeeded(progress); - } - - @Override - public void onMediaDone() { - trackVideoProcessingEvents(false, null); - selectMediaAndSendCompletionToListener(); - } - - @Override - public void onMediaPause() { - AppLog.d(AppLog.T.MEDIA, "VideoOptimizer > paused"); - } - - @Override - public void onMediaStop() { - // This seems to be called called in 2 cases. Do not use to check if we've manually stopped the composer. - // 1. When the encoding is done without errors, before onMediaDone - // 2. When we call 'stop' on the media composer - AppLog.d(AppLog.T.MEDIA, "VideoOptimizer > stopped"); - } - - @Override - public void onError(Exception e) { - AppLog.e(AppLog.T.MEDIA, "VideoOptimizer > Can't optimize the video", e); - trackVideoProcessingEvents(true, e); - mListener.onVideoOptimizationCompleted(mMedia); - } - - @Override - public void start() { - if (!arePathsValidated()) return; - - MediaComposer mediaComposer = null; - boolean wasNpeDetected = false; - - try { - mediaComposer = WPVideoUtils.getVideoOptimizationComposer( - getContext(), - mInputPath, - mOutputPath, - this, - AppPrefs.getVideoOptimizeWidth(), - AppPrefs.getVideoOptimizeQuality()); - } catch (NullPointerException npe) { - AppLog.w( - AppLog.T.MEDIA, - "VideoOptimizer > NullPointerException while getting composer " + npe.getMessage() - ); - wasNpeDetected = true; - } - - if (mediaComposer == null) { - AppLog.w(AppLog.T.MEDIA, "VideoOptimizer > null composer"); - Map properties = AnalyticsUtils.getMediaProperties(getContext(), true, - null, mInputPath); - properties.put("was_npe_detected", wasNpeDetected); - properties.put("optimizer_lib", "m4m"); - AnalyticsTracker.track(MEDIA_VIDEO_CANT_OPTIMIZE, properties); - mListener.onVideoOptimizationCompleted(mMedia); - return; - } - - // setup done. We're ready to optimize! - try { - mediaComposer.start(); - AppLog.d(AppLog.T.MEDIA, "VideoOptimizer > composer started"); - } catch (IllegalStateException e) { - AppLog.e(AppLog.T.MEDIA, "VideoOptimizer > failed to start composer", e); - mListener.onVideoOptimizationCompleted(mMedia); - } - } -} From 225b7748eaa9e8deba69676067afe5eea6bfc61e Mon Sep 17 00:00:00 2001 From: Irfan Omur Date: Fri, 10 Feb 2023 17:50:01 +0300 Subject: [PATCH 004/856] Update compileSdk to 33 --- build.gradle | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/build.gradle b/build.gradle index b44275f1b974..5fcda1fc36bf 100644 --- a/build.gradle +++ b/build.gradle @@ -10,7 +10,7 @@ plugins { ext { minSdkVersion = 24 - compileSdkVersion = 31 + compileSdkVersion = 33 targetSdkVersion = 31 } From 69f1fb8786af5ab5479c2f662bea6fc5033f8082 Mon Sep 17 00:00:00 2001 From: Irfan Omur Date: Fri, 10 Feb 2023 18:23:38 +0300 Subject: [PATCH 005/856] Disable all warnings as errors for temporary fix Errors were disabled temporarily to be able to fix all errors in separate PRS. It'll be re-enabled after all errors have been fixed. --- build.gradle | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/build.gradle b/build.gradle index 5fcda1fc36bf..30df2a0b63e2 100644 --- a/build.gradle +++ b/build.gradle @@ -151,7 +151,7 @@ allprojects { tasks.withType(KotlinCompile).all { kotlinOptions { jvmTarget = JavaVersion.VERSION_1_8 - allWarningsAsErrors = true + allWarningsAsErrors = false freeCompilerArgs += [ "-Xopt-in=kotlin.RequiresOptIn", "-Xjvm-default=all" From f4af1c48d67e54ad83348f158c77a121258ba929 Mon Sep 17 00:00:00 2001 From: Irfan Omur Date: Sun, 29 Jan 2023 13:45:39 +0300 Subject: [PATCH 006/856] Update changed functions of AnimatorListener These functions were changed with Android 13. --- .../org/wordpress/android/ui/WPTooltipView.kt | 2 +- .../ui/people/WPEditTextWithChipsOutlined.kt | 16 ++++++++-------- .../previews/SiteCreationPreviewFragment.kt | 2 +- 3 files changed, 10 insertions(+), 10 deletions(-) diff --git a/WordPress/src/main/java/org/wordpress/android/ui/WPTooltipView.kt b/WordPress/src/main/java/org/wordpress/android/ui/WPTooltipView.kt index dcaf4e163818..093b7315d7cd 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/WPTooltipView.kt +++ b/WordPress/src/main/java/org/wordpress/android/ui/WPTooltipView.kt @@ -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 } diff --git a/WordPress/src/main/java/org/wordpress/android/ui/people/WPEditTextWithChipsOutlined.kt b/WordPress/src/main/java/org/wordpress/android/ui/people/WPEditTextWithChipsOutlined.kt index f6244b156306..b7f05a833746 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/people/WPEditTextWithChipsOutlined.kt +++ b/WordPress/src/main/java/org/wordpress/android/ui/people/WPEditTextWithChipsOutlined.kt @@ -551,18 +551,18 @@ class WPEditTextWithChipsOutlined @JvmOverloads constructor( .scaleY(1f) .setDuration(LABEL_ANIMATION_DURATION) .setListener(object : Animator.AnimatorListener { - override fun onAnimationStart(animation: Animator?) { + override fun onAnimationStart(animation: Animator) { label.visibility = View.INVISIBLE hint.visibility = View.VISIBLE } - override fun onAnimationEnd(animation: Animator?) { + override fun onAnimationEnd(animation: Animator) { } - override fun onAnimationCancel(animation: Animator?) { + override fun onAnimationCancel(animation: Animator) { } - override fun onAnimationRepeat(animation: Animator?) { + override fun onAnimationRepeat(animation: Animator) { } }).start() } @@ -581,21 +581,21 @@ class WPEditTextWithChipsOutlined @JvmOverloads constructor( .scaleY(label.height.toFloat() / hint.height) .setDuration(LABEL_ANIMATION_DURATION) .setListener(object : Animator.AnimatorListener { - override fun onAnimationStart(animation: Animator?) { + override fun onAnimationStart(animation: Animator) { setLabelColor(label, colorSurface, outlineColorAlphaFocused) label.visibility = View.VISIBLE hint.visibility = View.VISIBLE } - override fun onAnimationEnd(animation: Animator?) { + override fun onAnimationEnd(animation: Animator) { hint.visibility = View.INVISIBLE setLabelColor(label, outlineColorFocused, outlineColorAlphaFocused) } - override fun onAnimationCancel(animation: Animator?) { + override fun onAnimationCancel(animation: Animator) { } - override fun onAnimationRepeat(animation: Animator?) { + override fun onAnimationRepeat(animation: Animator) { } }).start() } diff --git a/WordPress/src/main/java/org/wordpress/android/ui/sitecreation/previews/SiteCreationPreviewFragment.kt b/WordPress/src/main/java/org/wordpress/android/ui/sitecreation/previews/SiteCreationPreviewFragment.kt index 24c002fdb551..d4aa6e19a9f0 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/sitecreation/previews/SiteCreationPreviewFragment.kt +++ b/WordPress/src/main/java/org/wordpress/android/ui/sitecreation/previews/SiteCreationPreviewFragment.kt @@ -268,7 +268,7 @@ class SiteCreationPreviewFragment : SiteCreationBaseFormFragment(), progressText.text = newText } - override fun onAnimationEnd(animation: Animator?) { + override fun onAnimationEnd(animation: Animator) { super.onAnimationEnd(animation) animatorSet = null } From dfddd9a96dc279d0321b2acc6a63c3aaaa822518 Mon Sep 17 00:00:00 2001 From: Irfan Omur Date: Sat, 11 Feb 2023 15:33:01 +0300 Subject: [PATCH 007/856] Update changed functions of MenuItem These functions were changed with Android 13. --- .../unified/CommentListActionModeCallback.kt | 5 +++-- .../mediapicker/MediaPickerActionModeCallback.kt | 15 ++++++++------- .../android/ui/mediapicker/MediaPickerFragment.kt | 4 ++-- .../wordpress/android/ui/mysite/MySiteFragment.kt | 2 +- .../android/ui/pages/PageParentFragment.kt | 8 ++++---- .../wordpress/android/ui/pages/PagesFragment.kt | 8 ++++---- .../android/ui/posts/PostsListActivity.kt | 4 ++-- .../wordpress/android/ui/reader/ReaderFragment.kt | 6 +++--- 8 files changed, 27 insertions(+), 25 deletions(-) diff --git a/WordPress/src/main/java/org/wordpress/android/ui/comments/unified/CommentListActionModeCallback.kt b/WordPress/src/main/java/org/wordpress/android/ui/comments/unified/CommentListActionModeCallback.kt index 0db7bbf278e0..05708b9972ae 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/comments/unified/CommentListActionModeCallback.kt +++ b/WordPress/src/main/java/org/wordpress/android/ui/comments/unified/CommentListActionModeCallback.kt @@ -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 = it.mutate() icon.alpha = if (actionUiModel.isEnabled) ICON_ALPHA_ENABLED else ICON_ALPHA_DISABLED menuItem.icon = icon } diff --git a/WordPress/src/main/java/org/wordpress/android/ui/mediapicker/MediaPickerActionModeCallback.kt b/WordPress/src/main/java/org/wordpress/android/ui/mediapicker/MediaPickerActionModeCallback.kt index b0d467bc7972..722efe7d75f6 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/mediapicker/MediaPickerActionModeCallback.kt +++ b/WordPress/src/main/java/org/wordpress/android/ui/mediapicker/MediaPickerActionModeCallback.kt @@ -42,19 +42,20 @@ class MediaPickerActionModeCallback(private val viewModel: MediaPickerViewModel) if (editItemUiModel.isVisible) { editItem.isVisible = true - editItem.actionView.let { actionView -> + editItem.actionView?.let { actionView -> actionView.setOnClickListener { onActionItemClicked(actionMode, editItem) } TooltipCompat.setTooltipText(actionView, editItem.title) } - val editItemBadge = editItem.actionView.findViewById(R.id.customize_icon_count) - if (editItemUiModel.isCounterBadgeVisible) { - editItemBadge.visibility = View.VISIBLE - editItemBadge.text = editItemUiModel.counterBadgeValue.toString() - } else { - editItemBadge.visibility = View.GONE + editItem.actionView?.findViewById(R.id.customize_icon_count)?.let { editItemBadge -> + if (editItemUiModel.isCounterBadgeVisible) { + editItemBadge.visibility = View.VISIBLE + editItemBadge.text = editItemUiModel.counterBadgeValue.toString() + } else { + editItemBadge.visibility = View.GONE + } } } else { editItem.isVisible = false diff --git a/WordPress/src/main/java/org/wordpress/android/ui/mediapicker/MediaPickerFragment.kt b/WordPress/src/main/java/org/wordpress/android/ui/mediapicker/MediaPickerFragment.kt index 949150a3d3e2..cd57a3bdb2ec 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/mediapicker/MediaPickerFragment.kt +++ b/WordPress/src/main/java/org/wordpress/android/ui/mediapicker/MediaPickerFragment.kt @@ -416,13 +416,13 @@ class MediaPickerFragment : Fragment(), MenuProvider { private fun initializeSearchView(actionMenuItem: MenuItem) { var isExpanding = false actionMenuItem.setOnActionExpandListener(object : OnActionExpandListener { - override fun onMenuItemActionExpand(item: MenuItem?): Boolean { + override fun onMenuItemActionExpand(item: MenuItem): Boolean { viewModel.onSearchExpanded() isExpanding = true return true } - override fun onMenuItemActionCollapse(item: MenuItem?): Boolean { + override fun onMenuItemActionCollapse(item: MenuItem): Boolean { viewModel.onSearchCollapsed() return true } diff --git a/WordPress/src/main/java/org/wordpress/android/ui/mysite/MySiteFragment.kt b/WordPress/src/main/java/org/wordpress/android/ui/mysite/MySiteFragment.kt index 9f50ca206e34..386accb55434 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/mysite/MySiteFragment.kt +++ b/WordPress/src/main/java/org/wordpress/android/ui/mysite/MySiteFragment.kt @@ -100,7 +100,7 @@ class MySiteFragment : Fragment(R.layout.my_site_fragment), toolbarMain.let { toolbar -> toolbar.inflateMenu(R.menu.my_site_menu) toolbar.menu.findItem(R.id.me_item)?.let { meMenu -> - meMenu.actionView.let { actionView -> + meMenu.actionView?.let { actionView -> actionView.contentDescription = meMenu.title actionView.setOnClickListener { viewModel.onAvatarPressed() } TooltipCompat.setTooltipText(actionView, meMenu.title) diff --git a/WordPress/src/main/java/org/wordpress/android/ui/pages/PageParentFragment.kt b/WordPress/src/main/java/org/wordpress/android/ui/pages/PageParentFragment.kt index cdeb85212eab..b2c1fae51378 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/pages/PageParentFragment.kt +++ b/WordPress/src/main/java/org/wordpress/android/ui/pages/PageParentFragment.kt @@ -92,12 +92,12 @@ class PageParentFragment : Fragment(R.layout.page_parent_fragment), MenuProvider private fun PageParentFragmentBinding.initializeSearchView() { searchAction.setOnActionExpandListener(object : OnActionExpandListener { - override fun onMenuItemActionExpand(item: MenuItem?): Boolean { + override fun onMenuItemActionExpand(item: MenuItem): Boolean { viewModel.onSearchExpanded(restorePreviousSearch) return true } - override fun onMenuItemActionCollapse(item: MenuItem?): Boolean { + override fun onMenuItemActionCollapse(item: MenuItem): Boolean { viewModel.onSearchCollapsed() return true } @@ -121,8 +121,8 @@ class PageParentFragment : Fragment(R.layout.page_parent_fragment), MenuProvider } }) - val searchEditFrame = searchAction.actionView.findViewById(R.id.search_edit_frame) - (searchEditFrame.layoutParams as LinearLayout.LayoutParams) + val searchEditFrame = searchAction.actionView?.findViewById(R.id.search_edit_frame) + (searchEditFrame?.layoutParams as LinearLayout.LayoutParams) .apply { this.leftMargin = DisplayUtils.dpToPx(activity, SEARCH_ACTION_LEFT_MARGIN_DP) } viewModel.isSearchExpanded.observe(this@PageParentFragment) { diff --git a/WordPress/src/main/java/org/wordpress/android/ui/pages/PagesFragment.kt b/WordPress/src/main/java/org/wordpress/android/ui/pages/PagesFragment.kt index 6ac305ed0b2f..b8774f5738ab 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/pages/PagesFragment.kt +++ b/WordPress/src/main/java/org/wordpress/android/ui/pages/PagesFragment.kt @@ -264,12 +264,12 @@ class PagesFragment : Fragment(R.layout.pages_fragment), ScrollableViewInitializ private fun PagesFragmentBinding.initializeSearchView() { actionMenuItem.setOnActionExpandListener(object : OnActionExpandListener { - override fun onMenuItemActionExpand(item: MenuItem?): Boolean { + override fun onMenuItemActionExpand(item: MenuItem): Boolean { viewModel.onSearchExpanded(restorePreviousSearch) return true } - override fun onMenuItemActionCollapse(item: MenuItem?): Boolean { + override fun onMenuItemActionCollapse(item: MenuItem): Boolean { viewModel.onSearchCollapsed() return true } @@ -294,8 +294,8 @@ class PagesFragment : Fragment(R.layout.pages_fragment), ScrollableViewInitializ }) // fix the search view margins to match the action bar - val searchEditFrame = actionMenuItem.actionView.findViewById(R.id.search_edit_frame) - (searchEditFrame.layoutParams as LinearLayout.LayoutParams) + val searchEditFrame = actionMenuItem.actionView?.findViewById(R.id.search_edit_frame) + (searchEditFrame?.layoutParams as LinearLayout.LayoutParams) .apply { this.leftMargin = DisplayUtils.dpToPx(activity, -8) } viewModel.isSearchExpanded.observe(this@PagesFragment, Observer { diff --git a/WordPress/src/main/java/org/wordpress/android/ui/posts/PostsListActivity.kt b/WordPress/src/main/java/org/wordpress/android/ui/posts/PostsListActivity.kt index aa859fe19c3c..fe1b7266c218 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/posts/PostsListActivity.kt +++ b/WordPress/src/main/java/org/wordpress/android/ui/posts/PostsListActivity.kt @@ -575,12 +575,12 @@ class PostsListActivity : LocaleAwareActivity(), private fun PostListActivityBinding.initSearchView() { searchActionButton.setOnActionExpandListener(object : OnActionExpandListener { - override fun onMenuItemActionExpand(item: MenuItem?): Boolean { + override fun onMenuItemActionExpand(item: MenuItem): Boolean { viewModel.onSearchExpanded(restorePreviousSearch) return true } - override fun onMenuItemActionCollapse(item: MenuItem?): Boolean { + override fun onMenuItemActionCollapse(item: MenuItem): Boolean { viewModel.onSearchCollapsed() return true } diff --git a/WordPress/src/main/java/org/wordpress/android/ui/reader/ReaderFragment.kt b/WordPress/src/main/java/org/wordpress/android/ui/reader/ReaderFragment.kt index 706d83a6b680..28b304990b40 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/reader/ReaderFragment.kt +++ b/WordPress/src/main/java/org/wordpress/android/ui/reader/ReaderFragment.kt @@ -24,6 +24,7 @@ import org.greenrobot.eventbus.ThreadMode.MAIN import org.wordpress.android.R import org.wordpress.android.R.string import org.wordpress.android.databinding.ReaderFragmentLayoutBinding +import org.wordpress.android.models.JetpackPoweredScreen import org.wordpress.android.models.ReaderTagList import org.wordpress.android.ui.ScrollableViewInitializedListener import org.wordpress.android.ui.jetpackoverlay.JetpackFeatureFullScreenOverlayFragment @@ -44,7 +45,6 @@ import org.wordpress.android.ui.reader.viewmodels.ReaderViewModel.ReaderUiState. import org.wordpress.android.ui.utils.UiHelpers import org.wordpress.android.ui.utils.UiString.UiStringText import org.wordpress.android.util.JetpackBrandingUtils -import org.wordpress.android.models.JetpackPoweredScreen import org.wordpress.android.util.QuickStartUtilsWrapper import org.wordpress.android.util.SnackbarItem import org.wordpress.android.util.SnackbarItem.Action @@ -126,11 +126,11 @@ class ReaderFragment : Fragment(R.layout.reader_fragment_layout), MenuProvider, } menu.findItem(R.id.menu_settings).apply { settingsMenuItem = this - settingsMenuItemFocusPoint = this.actionView.findViewById(R.id.menu_quick_start_focus_point) + settingsMenuItemFocusPoint = this.actionView?.findViewById(R.id.menu_quick_start_focus_point) this.isVisible = viewModel.uiState.value?.settingsMenuItemUiState?.isVisible ?: false settingsMenuItemFocusPoint?.isVisible = viewModel.uiState.value?.settingsMenuItemUiState?.showQuickStartFocusPoint ?: false - this.actionView.setOnClickListener { viewModel.onSettingsActionClicked() } + this.actionView?.setOnClickListener { viewModel.onSettingsActionClicked() } } } From a57595c5b99bce36187c7fa2390532419966032c Mon Sep 17 00:00:00 2001 From: Irfan Omur Date: Sun, 29 Jan 2023 14:07:13 +0300 Subject: [PATCH 008/856] Update changed functions of SimpleOnGestureListener These functions were changed with Android 13. --- .../cards/quicklinksribbon/QuickLinkRibbonViewHolder.kt | 6 +++--- .../quickstart/QuickStartDynamicCardViewHolder.kt | 6 +++--- .../discover/viewholders/ReaderInterestsCardViewHolder.kt | 6 +++--- 3 files changed, 9 insertions(+), 9 deletions(-) diff --git a/WordPress/src/main/java/org/wordpress/android/ui/mysite/cards/quicklinksribbon/QuickLinkRibbonViewHolder.kt b/WordPress/src/main/java/org/wordpress/android/ui/mysite/cards/quicklinksribbon/QuickLinkRibbonViewHolder.kt index 0bd36bd70177..2f899c5a1260 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/mysite/cards/quicklinksribbon/QuickLinkRibbonViewHolder.kt +++ b/WordPress/src/main/java/org/wordpress/android/ui/mysite/cards/quicklinksribbon/QuickLinkRibbonViewHolder.kt @@ -66,14 +66,14 @@ class QuickLinkRibbonViewHolder( * We need to do this immediately, because if we don't, then the next move event could potentially * trigger the viewPager to switch tabs */ - override fun onDown(e: MotionEvent?): Boolean = with(binding) { + override fun onDown(e: MotionEvent): Boolean = with(binding) { quickLinkRibbonItemList.parent.requestDisallowInterceptTouchEvent(true) return super.onDown(e) } override fun onScroll( - e1: MotionEvent?, - e2: MotionEvent?, + e1: MotionEvent, + e2: MotionEvent, distanceX: Float, distanceY: Float ): Boolean = with(binding) { diff --git a/WordPress/src/main/java/org/wordpress/android/ui/mysite/dynamiccards/quickstart/QuickStartDynamicCardViewHolder.kt b/WordPress/src/main/java/org/wordpress/android/ui/mysite/dynamiccards/quickstart/QuickStartDynamicCardViewHolder.kt index 8be75b0c0ba0..6d66724e3f32 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/mysite/dynamiccards/quickstart/QuickStartDynamicCardViewHolder.kt +++ b/WordPress/src/main/java/org/wordpress/android/ui/mysite/dynamiccards/quickstart/QuickStartDynamicCardViewHolder.kt @@ -127,14 +127,14 @@ class QuickStartDynamicCardViewHolder( * We need to do this immediately, because if we don't, then the next move event could potentially * trigger the viewPager to switch tabs */ - override fun onDown(e: MotionEvent?): Boolean = with(binding) { + override fun onDown(e: MotionEvent): Boolean = with(binding) { quickStartCardRecyclerView.parent.requestDisallowInterceptTouchEvent(true) return super.onDown(e) } override fun onScroll( - e1: MotionEvent?, - e2: MotionEvent?, + e1: MotionEvent, + e2: MotionEvent, distanceX: Float, distanceY: Float ): Boolean = with(binding) { diff --git a/WordPress/src/main/java/org/wordpress/android/ui/reader/discover/viewholders/ReaderInterestsCardViewHolder.kt b/WordPress/src/main/java/org/wordpress/android/ui/reader/discover/viewholders/ReaderInterestsCardViewHolder.kt index 8507fbf875b1..0ad4b9ad5c32 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/reader/discover/viewholders/ReaderInterestsCardViewHolder.kt +++ b/WordPress/src/main/java/org/wordpress/android/ui/reader/discover/viewholders/ReaderInterestsCardViewHolder.kt @@ -58,14 +58,14 @@ class ReaderInterestsCardViewHolder( * We need to do this immediately, because if we don't, then the next move event could potentially * trigger the viewPager to switch tabs */ - override fun onDown(e: MotionEvent?): Boolean = with(binding) { + override fun onDown(e: MotionEvent): Boolean = with(binding) { interestsList.parent.requestDisallowInterceptTouchEvent(true) return super.onDown(e) } override fun onScroll( - e1: MotionEvent?, - e2: MotionEvent?, + e1: MotionEvent, + e2: MotionEvent, distanceX: Float, distanceY: Float ): Boolean = with(binding) { From 2b2b024fa4339ed9a89d6914230ca09c4037d243 Mon Sep 17 00:00:00 2001 From: Irfan Omur Date: Sun, 12 Feb 2023 11:09:16 +0300 Subject: [PATCH 009/856] Remove redundant SAM-constructors --- .../android/ui/mediapicker/MediaPickerActionModeCallback.kt | 4 ++-- .../main/java/org/wordpress/android/ui/pages/PagesFragment.kt | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/WordPress/src/main/java/org/wordpress/android/ui/mediapicker/MediaPickerActionModeCallback.kt b/WordPress/src/main/java/org/wordpress/android/ui/mediapicker/MediaPickerActionModeCallback.kt index 722efe7d75f6..54932874d13b 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/mediapicker/MediaPickerActionModeCallback.kt +++ b/WordPress/src/main/java/org/wordpress/android/ui/mediapicker/MediaPickerActionModeCallback.kt @@ -29,7 +29,7 @@ class MediaPickerActionModeCallback(private val viewModel: MediaPickerViewModel) lifecycleRegistry.handleLifecycleEvent(ON_START) val inflater = actionMode.menuInflater inflater.inflate(R.menu.photo_picker_action_mode, menu) - viewModel.uiState.observe(this, Observer { uiState -> + viewModel.uiState.observe(this) { uiState -> when (val uiModel = uiState.actionModeUiModel) { is ActionModeUiModel.Hidden -> { actionMode.finish() @@ -68,7 +68,7 @@ class MediaPickerActionModeCallback(private val viewModel: MediaPickerViewModel) } } } - }) + } return true } diff --git a/WordPress/src/main/java/org/wordpress/android/ui/pages/PagesFragment.kt b/WordPress/src/main/java/org/wordpress/android/ui/pages/PagesFragment.kt index b8774f5738ab..30741316dc11 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/pages/PagesFragment.kt +++ b/WordPress/src/main/java/org/wordpress/android/ui/pages/PagesFragment.kt @@ -298,13 +298,13 @@ class PagesFragment : Fragment(R.layout.pages_fragment), ScrollableViewInitializ (searchEditFrame?.layoutParams as LinearLayout.LayoutParams) .apply { this.leftMargin = DisplayUtils.dpToPx(activity, -8) } - viewModel.isSearchExpanded.observe(this@PagesFragment, Observer { + viewModel.isSearchExpanded.observe(this@PagesFragment) { if (it == true) { showSearchList(actionMenuItem) } else { hideSearchList(actionMenuItem) } - }) + } } private fun PagesFragmentBinding.initializeViewModelObservers( From 41557cd02a380a305d66d1095affa128d6182704 Mon Sep 17 00:00:00 2001 From: Irfan Omur Date: Sun, 12 Feb 2023 10:59:37 +0300 Subject: [PATCH 010/856] Move lambda argument out of parentheses in PostListActivity --- .../java/org/wordpress/android/ui/posts/PostsListActivity.kt | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/WordPress/src/main/java/org/wordpress/android/ui/posts/PostsListActivity.kt b/WordPress/src/main/java/org/wordpress/android/ui/posts/PostsListActivity.kt index fe1b7266c218..2730030c96a8 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/posts/PostsListActivity.kt +++ b/WordPress/src/main/java/org/wordpress/android/ui/posts/PostsListActivity.kt @@ -604,10 +604,10 @@ class PostsListActivity : LocaleAwareActivity(), } }) - viewModel.isSearchExpanded.observe(this@PostsListActivity, { isExpanded -> + viewModel.isSearchExpanded.observe(this@PostsListActivity) { isExpanded -> toggleViewLayoutMenuItem.isVisible = !isExpanded toggleSearch(isExpanded) - }) + } } private fun PostListActivityBinding.toggleSearch(isExpanded: Boolean) { From dcec3d3e06f4c06b15ca0fffab45d9457155e734 Mon Sep 17 00:00:00 2001 From: Irfan Omur Date: Sun, 12 Feb 2023 17:42:25 +0300 Subject: [PATCH 011/856] Remove unused import from MediaPickerActionModeCallback --- .../android/ui/mediapicker/MediaPickerActionModeCallback.kt | 1 - 1 file changed, 1 deletion(-) diff --git a/WordPress/src/main/java/org/wordpress/android/ui/mediapicker/MediaPickerActionModeCallback.kt b/WordPress/src/main/java/org/wordpress/android/ui/mediapicker/MediaPickerActionModeCallback.kt index 54932874d13b..20b76d875dcf 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/mediapicker/MediaPickerActionModeCallback.kt +++ b/WordPress/src/main/java/org/wordpress/android/ui/mediapicker/MediaPickerActionModeCallback.kt @@ -12,7 +12,6 @@ import androidx.lifecycle.Lifecycle.Event.ON_START import androidx.lifecycle.Lifecycle.Event.ON_STOP import androidx.lifecycle.LifecycleOwner import androidx.lifecycle.LifecycleRegistry -import androidx.lifecycle.Observer import org.wordpress.android.R import org.wordpress.android.ui.mediapicker.MediaPickerViewModel.ActionModeUiModel import org.wordpress.android.ui.utils.UiString.UiStringRes From 8648d0bbb9b7994c6ce6f783bfadd164abb9f585 Mon Sep 17 00:00:00 2001 From: Irfan Omur Date: Sat, 11 Feb 2023 18:35:30 +0300 Subject: [PATCH 012/856] Use onBackPressedDispatcher to trigger onBackPressed() Activity's onBackPressed was deprecated on Android 13. --- .../android/ui/AddQuickPressShortcutActivity.java | 2 +- .../wordpress/android/ui/JetpackRemoteInstallActivity.kt | 2 +- .../org/wordpress/android/ui/accounts/HelpActivity.kt | 2 +- .../org/wordpress/android/ui/accounts/LoginActivity.java | 2 +- .../ui/activitylog/detail/ActivityLogDetailActivity.kt | 2 +- .../ui/activitylog/list/ActivityLogListActivity.kt | 2 +- .../promptslist/BloggingPromptsListActivity.kt | 6 +++++- .../android/ui/comments/EditCommentActivity.java | 2 +- .../ui/comments/unified/UnifiedCommentsActivity.kt | 2 +- .../wordpress/android/ui/debug/DebugSettingsActivity.kt | 2 +- .../android/ui/debug/cookies/DebugCookiesActivity.kt | 2 +- .../android/ui/domains/DomainRegistrationActivity.kt | 2 +- .../android/ui/domains/DomainsDashboardActivity.kt | 2 +- .../android/ui/engagement/EngagedPeopleListActivity.kt | 2 +- .../ui/jetpack/backup/download/BackupDownloadActivity.kt | 2 +- .../android/ui/jetpack/restore/RestoreActivity.kt | 2 +- .../org/wordpress/android/ui/jetpack/scan/ScanActivity.kt | 2 +- .../ui/jetpack/scan/details/ThreatDetailsActivity.kt | 2 +- .../ui/jetpack/scan/history/ScanHistoryFragment.kt | 2 +- .../main/java/org/wordpress/android/ui/main/MeActivity.kt | 2 +- .../org/wordpress/android/ui/main/SitePickerActivity.java | 2 +- .../wordpress/android/ui/media/MediaBrowserActivity.java | 2 +- .../wordpress/android/ui/media/MediaPreviewActivity.java | 2 +- .../wordpress/android/ui/media/MediaSettingsActivity.java | 6 +++--- .../org/wordpress/android/ui/pages/PageParentFragment.kt | 4 ++-- .../java/org/wordpress/android/ui/pages/PagesActivity.kt | 2 +- .../android/ui/people/PeopleManagementActivity.java | 2 +- .../android/ui/plugins/PluginBrowserActivity.java | 4 ++-- .../android/ui/plugins/PluginDetailActivity.java | 4 ++-- .../org/wordpress/android/ui/posts/PostsListActivity.kt | 2 +- .../android/ui/prefs/AccountSettingsActivity.java | 2 +- .../wordpress/android/ui/prefs/AppSettingsActivity.java | 2 +- .../org/wordpress/android/ui/prefs/MyProfileActivity.java | 2 +- .../android/ui/prefs/SiteSettingsTagListActivity.java | 2 +- .../ui/prefs/categories/detail/CategoryDetailActivity.kt | 2 +- .../ui/prefs/categories/list/CategoriesListActivity.kt | 2 +- .../prefs/notifications/NotificationsSettingsActivity.kt | 2 +- .../android/ui/publicize/PublicizeListActivity.java | 2 +- .../android/ui/reader/ReaderPhotoViewerActivity.java | 2 +- .../android/ui/reader/ReaderPostDetailFragment.kt | 2 +- .../android/ui/reader/ReaderPostListActivity.java | 2 +- .../wordpress/android/ui/reader/ReaderSubsActivity.java | 2 +- .../android/ui/reader/ReaderUserListActivity.java | 8 +------- .../reader/discover/interests/ReaderInterestsActivity.kt | 2 +- .../android/ui/sitecreation/SiteCreationActivity.kt | 4 ++-- .../wordpress/android/ui/stats/refresh/StatsActivity.kt | 2 +- .../android/ui/stats/refresh/StatsViewAllActivity.kt | 2 +- .../ui/stats/refresh/lists/detail/StatsDetailActivity.kt | 2 +- .../insights/management/InsightsManagementActivity.kt | 2 +- .../widget/alltime/StatsAllTimeWidgetConfigureActivity.kt | 2 +- .../minified/StatsMinifiedWidgetConfigureActivity.kt | 2 +- .../widget/today/StatsTodayWidgetConfigureActivity.kt | 2 +- .../widget/views/StatsViewsWidgetConfigureActivity.kt | 2 +- .../widget/weeks/StatsWeekWidgetConfigureActivity.kt | 2 +- .../wordpress/android/ui/themes/ThemeBrowserActivity.java | 2 +- .../wordpress/android/imageeditor/EditImageActivity.kt | 4 ++-- 56 files changed, 67 insertions(+), 69 deletions(-) diff --git a/WordPress/src/main/java/org/wordpress/android/ui/AddQuickPressShortcutActivity.java b/WordPress/src/main/java/org/wordpress/android/ui/AddQuickPressShortcutActivity.java index da9489a8c9af..b6e3cd7ad806 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/AddQuickPressShortcutActivity.java +++ b/WordPress/src/main/java/org/wordpress/android/ui/AddQuickPressShortcutActivity.java @@ -71,7 +71,7 @@ public void onCreate(Bundle savedInstanceState) { @Override public boolean onOptionsItemSelected(final MenuItem item) { if (item.getItemId() == android.R.id.home) { - onBackPressed(); + getOnBackPressedDispatcher().onBackPressed(); return true; } return super.onOptionsItemSelected(item); diff --git a/WordPress/src/main/java/org/wordpress/android/ui/JetpackRemoteInstallActivity.kt b/WordPress/src/main/java/org/wordpress/android/ui/JetpackRemoteInstallActivity.kt index 273062232db3..7bfd7ab2b0f2 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/JetpackRemoteInstallActivity.kt +++ b/WordPress/src/main/java/org/wordpress/android/ui/JetpackRemoteInstallActivity.kt @@ -25,7 +25,7 @@ class JetpackRemoteInstallActivity : LocaleAwareActivity() { override fun onOptionsItemSelected(item: MenuItem): Boolean { if (item.itemId == android.R.id.home) { - onBackPressed() + onBackPressedDispatcher.onBackPressed() return true } return super.onOptionsItemSelected(item) diff --git a/WordPress/src/main/java/org/wordpress/android/ui/accounts/HelpActivity.kt b/WordPress/src/main/java/org/wordpress/android/ui/accounts/HelpActivity.kt index 7326ebbbd912..980c3942db95 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/accounts/HelpActivity.kt +++ b/WordPress/src/main/java/org/wordpress/android/ui/accounts/HelpActivity.kt @@ -146,7 +146,7 @@ class HelpActivity : LocaleAwareActivity() { override fun onOptionsItemSelected(item: MenuItem): Boolean { if (item.itemId == android.R.id.home) { - onBackPressed() + onBackPressedDispatcher.onBackPressed() return true } return super.onOptionsItemSelected(item) diff --git a/WordPress/src/main/java/org/wordpress/android/ui/accounts/LoginActivity.java b/WordPress/src/main/java/org/wordpress/android/ui/accounts/LoginActivity.java index d2600a781836..59717972a4e9 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/accounts/LoginActivity.java +++ b/WordPress/src/main/java/org/wordpress/android/ui/accounts/LoginActivity.java @@ -295,7 +295,7 @@ private LoginEmailFragment getLoginEmailFragment() { @Override public boolean onOptionsItemSelected(MenuItem item) { if (item.getItemId() == android.R.id.home) { - onBackPressed(); + getOnBackPressedDispatcher().onBackPressed(); return true; } diff --git a/WordPress/src/main/java/org/wordpress/android/ui/activitylog/detail/ActivityLogDetailActivity.kt b/WordPress/src/main/java/org/wordpress/android/ui/activitylog/detail/ActivityLogDetailActivity.kt index 38c9e1c9924f..981d9833b900 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/activitylog/detail/ActivityLogDetailActivity.kt +++ b/WordPress/src/main/java/org/wordpress/android/ui/activitylog/detail/ActivityLogDetailActivity.kt @@ -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) diff --git a/WordPress/src/main/java/org/wordpress/android/ui/activitylog/list/ActivityLogListActivity.kt b/WordPress/src/main/java/org/wordpress/android/ui/activitylog/list/ActivityLogListActivity.kt index b944b25eadcd..abcb2aa59998 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/activitylog/list/ActivityLogListActivity.kt +++ b/WordPress/src/main/java/org/wordpress/android/ui/activitylog/list/ActivityLogListActivity.kt @@ -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) diff --git a/WordPress/src/main/java/org/wordpress/android/ui/bloggingprompts/promptslist/BloggingPromptsListActivity.kt b/WordPress/src/main/java/org/wordpress/android/ui/bloggingprompts/promptslist/BloggingPromptsListActivity.kt index 1f47dbdfd643..f8f13b932d6e 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/bloggingprompts/promptslist/BloggingPromptsListActivity.kt +++ b/WordPress/src/main/java/org/wordpress/android/ui/bloggingprompts/promptslist/BloggingPromptsListActivity.kt @@ -26,7 +26,11 @@ class BloggingPromptsListActivity : LocaleAwareActivity() { setContent { AppTheme { val uiState by viewModel.uiStateFlow.collectAsState() - BloggingPromptsListScreen(uiState, ::onBackPressed, viewModel::onPromptListItemClicked) + BloggingPromptsListScreen( + uiState, + { onBackPressedDispatcher.onBackPressed() }, + viewModel::onPromptListItemClicked + ) } } observeActions() diff --git a/WordPress/src/main/java/org/wordpress/android/ui/comments/EditCommentActivity.java b/WordPress/src/main/java/org/wordpress/android/ui/comments/EditCommentActivity.java index 83a59cc8fbf2..d7e639227cbe 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/comments/EditCommentActivity.java +++ b/WordPress/src/main/java/org/wordpress/android/ui/comments/EditCommentActivity.java @@ -194,7 +194,7 @@ public boolean onCreateOptionsMenu(Menu menu) { public boolean onOptionsItemSelected(final MenuItem item) { int i = item.getItemId(); if (i == android.R.id.home) { - onBackPressed(); + getOnBackPressedDispatcher().onBackPressed(); return true; } else if (i == R.id.menu_save_comment) { saveComment(); diff --git a/WordPress/src/main/java/org/wordpress/android/ui/comments/unified/UnifiedCommentsActivity.kt b/WordPress/src/main/java/org/wordpress/android/ui/comments/unified/UnifiedCommentsActivity.kt index e87cc567be71..4381983c9e73 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/comments/unified/UnifiedCommentsActivity.kt +++ b/WordPress/src/main/java/org/wordpress/android/ui/comments/unified/UnifiedCommentsActivity.kt @@ -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) diff --git a/WordPress/src/main/java/org/wordpress/android/ui/debug/DebugSettingsActivity.kt b/WordPress/src/main/java/org/wordpress/android/ui/debug/DebugSettingsActivity.kt index f344f01d6256..87de1bfdb12a 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/debug/DebugSettingsActivity.kt +++ b/WordPress/src/main/java/org/wordpress/android/ui/debug/DebugSettingsActivity.kt @@ -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) diff --git a/WordPress/src/main/java/org/wordpress/android/ui/debug/cookies/DebugCookiesActivity.kt b/WordPress/src/main/java/org/wordpress/android/ui/debug/cookies/DebugCookiesActivity.kt index 569b62f095ea..1772ba413e06 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/debug/cookies/DebugCookiesActivity.kt +++ b/WordPress/src/main/java/org/wordpress/android/ui/debug/cookies/DebugCookiesActivity.kt @@ -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) diff --git a/WordPress/src/main/java/org/wordpress/android/ui/domains/DomainRegistrationActivity.kt b/WordPress/src/main/java/org/wordpress/android/ui/domains/DomainRegistrationActivity.kt index 30e777de2edf..f600c249e07b 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/domains/DomainRegistrationActivity.kt +++ b/WordPress/src/main/java/org/wordpress/android/ui/domains/DomainRegistrationActivity.kt @@ -134,7 +134,7 @@ class DomainRegistrationActivity : LocaleAwareActivity(), ScrollableViewInitiali override fun onOptionsItemSelected(item: MenuItem): Boolean { if (item.itemId == android.R.id.home) { - onBackPressed() + onBackPressedDispatcher.onBackPressed() return true } return super.onOptionsItemSelected(item) diff --git a/WordPress/src/main/java/org/wordpress/android/ui/domains/DomainsDashboardActivity.kt b/WordPress/src/main/java/org/wordpress/android/ui/domains/DomainsDashboardActivity.kt index b7a81a7e8f6b..9a8b55e2331e 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/domains/DomainsDashboardActivity.kt +++ b/WordPress/src/main/java/org/wordpress/android/ui/domains/DomainsDashboardActivity.kt @@ -24,7 +24,7 @@ class DomainsDashboardActivity : LocaleAwareActivity() { override fun onOptionsItemSelected(item: MenuItem): Boolean { if (item.itemId == android.R.id.home) { - onBackPressed() + onBackPressedDispatcher.onBackPressed() return true } return super.onOptionsItemSelected(item) diff --git a/WordPress/src/main/java/org/wordpress/android/ui/engagement/EngagedPeopleListActivity.kt b/WordPress/src/main/java/org/wordpress/android/ui/engagement/EngagedPeopleListActivity.kt index f96bcad38ac6..d8c90a366bc5 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/engagement/EngagedPeopleListActivity.kt +++ b/WordPress/src/main/java/org/wordpress/android/ui/engagement/EngagedPeopleListActivity.kt @@ -59,7 +59,7 @@ class EngagedPeopleListActivity : LocaleAwareActivity() { override fun onOptionsItemSelected(item: MenuItem): Boolean { if (item.itemId == android.R.id.home) { - onBackPressed() + onBackPressedDispatcher.onBackPressed() return true } return super.onOptionsItemSelected(item) diff --git a/WordPress/src/main/java/org/wordpress/android/ui/jetpack/backup/download/BackupDownloadActivity.kt b/WordPress/src/main/java/org/wordpress/android/ui/jetpack/backup/download/BackupDownloadActivity.kt index 1b84f71d463f..e240c9bea30b 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/jetpack/backup/download/BackupDownloadActivity.kt +++ b/WordPress/src/main/java/org/wordpress/android/ui/jetpack/backup/download/BackupDownloadActivity.kt @@ -18,7 +18,7 @@ class BackupDownloadActivity : LocaleAwareActivity() { override fun onOptionsItemSelected(item: MenuItem): Boolean { if (item.itemId == id.home) { - onBackPressed() + onBackPressedDispatcher.onBackPressed() return true } return super.onOptionsItemSelected(item) diff --git a/WordPress/src/main/java/org/wordpress/android/ui/jetpack/restore/RestoreActivity.kt b/WordPress/src/main/java/org/wordpress/android/ui/jetpack/restore/RestoreActivity.kt index 705aa2ed00b1..436ae6875f5e 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/jetpack/restore/RestoreActivity.kt +++ b/WordPress/src/main/java/org/wordpress/android/ui/jetpack/restore/RestoreActivity.kt @@ -17,7 +17,7 @@ class RestoreActivity : LocaleAwareActivity() { override fun onOptionsItemSelected(item: MenuItem): Boolean { if (item.itemId == android.R.id.home) { - onBackPressed() + onBackPressedDispatcher.onBackPressed() return true } return false diff --git a/WordPress/src/main/java/org/wordpress/android/ui/jetpack/scan/ScanActivity.kt b/WordPress/src/main/java/org/wordpress/android/ui/jetpack/scan/ScanActivity.kt index bca93e35c0fe..2c6a78bd5ef3 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/jetpack/scan/ScanActivity.kt +++ b/WordPress/src/main/java/org/wordpress/android/ui/jetpack/scan/ScanActivity.kt @@ -83,7 +83,7 @@ class ScanActivity : AppCompatActivity(), ScrollableViewInitializedListener { override fun onOptionsItemSelected(item: MenuItem): Boolean { if (item.itemId == android.R.id.home) { - onBackPressed() + onBackPressedDispatcher.onBackPressed() return true } else if (item.itemId == R.id.menu_scan_history) { // todo malinjir is it worth introducing a vm? diff --git a/WordPress/src/main/java/org/wordpress/android/ui/jetpack/scan/details/ThreatDetailsActivity.kt b/WordPress/src/main/java/org/wordpress/android/ui/jetpack/scan/details/ThreatDetailsActivity.kt index eb7b96ab3ff2..14f3c0043f1a 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/jetpack/scan/details/ThreatDetailsActivity.kt +++ b/WordPress/src/main/java/org/wordpress/android/ui/jetpack/scan/details/ThreatDetailsActivity.kt @@ -20,7 +20,7 @@ class ThreatDetailsActivity : AppCompatActivity() { override fun onOptionsItemSelected(item: MenuItem): Boolean { if (item.itemId == android.R.id.home) { - onBackPressed() + onBackPressedDispatcher.onBackPressed() return true } return super.onOptionsItemSelected(item) diff --git a/WordPress/src/main/java/org/wordpress/android/ui/jetpack/scan/history/ScanHistoryFragment.kt b/WordPress/src/main/java/org/wordpress/android/ui/jetpack/scan/history/ScanHistoryFragment.kt index 50174c191801..a099bc760a6d 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/jetpack/scan/history/ScanHistoryFragment.kt +++ b/WordPress/src/main/java/org/wordpress/android/ui/jetpack/scan/history/ScanHistoryFragment.kt @@ -139,7 +139,7 @@ class ScanHistoryFragment : Fragment(R.layout.scan_history_fragment), MenuProvid override fun onMenuItemSelected(menuItem: MenuItem) = when (menuItem.itemId) { android.R.id.home -> { - requireActivity().onBackPressed() + requireActivity().onBackPressedDispatcher.onBackPressed() true } else -> false diff --git a/WordPress/src/main/java/org/wordpress/android/ui/main/MeActivity.kt b/WordPress/src/main/java/org/wordpress/android/ui/main/MeActivity.kt index d2924eb91d2e..a35fcd146b78 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/main/MeActivity.kt +++ b/WordPress/src/main/java/org/wordpress/android/ui/main/MeActivity.kt @@ -18,7 +18,7 @@ class MeActivity : LocaleAwareActivity() { override fun onOptionsItemSelected(item: MenuItem): Boolean { if (item.itemId == android.R.id.home) { - onBackPressed() + onBackPressedDispatcher.onBackPressed() return true } return super.onOptionsItemSelected(item) diff --git a/WordPress/src/main/java/org/wordpress/android/ui/main/SitePickerActivity.java b/WordPress/src/main/java/org/wordpress/android/ui/main/SitePickerActivity.java index 85eb8dc5003a..d1fa5dd5ef66 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/main/SitePickerActivity.java +++ b/WordPress/src/main/java/org/wordpress/android/ui/main/SitePickerActivity.java @@ -274,7 +274,7 @@ public boolean onOptionsItemSelected(final MenuItem item) { int itemId = item.getItemId(); if (itemId == android.R.id.home) { AnalyticsTracker.track(Stat.SITE_SWITCHER_DISMISSED); - onBackPressed(); + getOnBackPressedDispatcher().onBackPressed(); return true; } else if (itemId == R.id.menu_edit) { AnalyticsTracker.track(Stat.SITE_SWITCHER_TOGGLED_EDIT_TAPPED, diff --git a/WordPress/src/main/java/org/wordpress/android/ui/media/MediaBrowserActivity.java b/WordPress/src/main/java/org/wordpress/android/ui/media/MediaBrowserActivity.java index 80502a557e6a..8396fc0ceb84 100755 --- a/WordPress/src/main/java/org/wordpress/android/ui/media/MediaBrowserActivity.java +++ b/WordPress/src/main/java/org/wordpress/android/ui/media/MediaBrowserActivity.java @@ -639,7 +639,7 @@ public boolean onCreateOptionsMenu(Menu menu) { public boolean onOptionsItemSelected(MenuItem item) { switch (item.getItemId()) { case android.R.id.home: - onBackPressed(); + getOnBackPressedDispatcher().onBackPressed(); return true; case R.id.menu_new_media: // Do Nothing (handled in action view click listener) diff --git a/WordPress/src/main/java/org/wordpress/android/ui/media/MediaPreviewActivity.java b/WordPress/src/main/java/org/wordpress/android/ui/media/MediaPreviewActivity.java index 2cb4b8a8fe39..5f3a70a4f110 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/media/MediaPreviewActivity.java +++ b/WordPress/src/main/java/org/wordpress/android/ui/media/MediaPreviewActivity.java @@ -222,7 +222,7 @@ protected void onCreate(@Nullable Bundle savedInstanceState) { @Override public boolean onOptionsItemSelected(MenuItem item) { if (item.getItemId() == android.R.id.home) { - onBackPressed(); + getOnBackPressedDispatcher().onBackPressed(); return true; } return super.onOptionsItemSelected(item); diff --git a/WordPress/src/main/java/org/wordpress/android/ui/media/MediaSettingsActivity.java b/WordPress/src/main/java/org/wordpress/android/ui/media/MediaSettingsActivity.java index 8836a8d76e66..d4c43cd6ab12 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/media/MediaSettingsActivity.java +++ b/WordPress/src/main/java/org/wordpress/android/ui/media/MediaSettingsActivity.java @@ -74,7 +74,6 @@ import org.wordpress.android.util.AppLog; import org.wordpress.android.util.AppLog.T; import org.wordpress.android.util.ColorUtils; -import org.wordpress.android.util.extensions.ContextExtensionsKt; import org.wordpress.android.util.DateTimeUtils; import org.wordpress.android.util.DisplayUtils; import org.wordpress.android.util.EditTextUtils; @@ -86,9 +85,10 @@ import org.wordpress.android.util.SiteUtils; import org.wordpress.android.util.StringUtils; import org.wordpress.android.util.ToastUtils; -import org.wordpress.android.util.extensions.ViewExtensionsKt; import org.wordpress.android.util.WPMediaUtils; import org.wordpress.android.util.WPPermissionUtils; +import org.wordpress.android.util.extensions.ContextExtensionsKt; +import org.wordpress.android.util.extensions.ViewExtensionsKt; import org.wordpress.android.util.image.ImageManager; import org.wordpress.android.util.image.ImageManager.RequestListener; import org.wordpress.android.util.image.ImageType; @@ -545,7 +545,7 @@ public boolean onPrepareOptionsMenu(Menu menu) { @Override public boolean onOptionsItemSelected(MenuItem item) { if (item.getItemId() == android.R.id.home) { - onBackPressed(); + getOnBackPressedDispatcher().onBackPressed(); return true; } else if (item.getItemId() == R.id.menu_save) { saveMediaToDevice(); diff --git a/WordPress/src/main/java/org/wordpress/android/ui/pages/PageParentFragment.kt b/WordPress/src/main/java/org/wordpress/android/ui/pages/PageParentFragment.kt index b2c1fae51378..a254f54df2b8 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/pages/PageParentFragment.kt +++ b/WordPress/src/main/java/org/wordpress/android/ui/pages/PageParentFragment.kt @@ -60,7 +60,7 @@ class PageParentFragment : Fragment(R.layout.page_parent_fragment), MenuProvider override fun onMenuItemSelected(menuItem: MenuItem) = when (menuItem.itemId) { android.R.id.home -> { - activity?.onBackPressed() + activity?.onBackPressedDispatcher?.onBackPressed() true } R.id.save_parent -> { @@ -87,7 +87,7 @@ class PageParentFragment : Fragment(R.layout.page_parent_fragment), MenuProvider result.putExtra(EXTRA_PAGE_REMOTE_ID_KEY, pageId) result.putExtra(EXTRA_PAGE_PARENT_ID_KEY, viewModel.currentParent.id) activity?.setResult(Activity.RESULT_OK, result) - activity?.onBackPressed() + activity?.onBackPressedDispatcher?.onBackPressed() } private fun PageParentFragmentBinding.initializeSearchView() { diff --git a/WordPress/src/main/java/org/wordpress/android/ui/pages/PagesActivity.kt b/WordPress/src/main/java/org/wordpress/android/ui/pages/PagesActivity.kt index 70caf8d0bbb8..323c0638557d 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/pages/PagesActivity.kt +++ b/WordPress/src/main/java/org/wordpress/android/ui/pages/PagesActivity.kt @@ -54,7 +54,7 @@ class PagesActivity : LocaleAwareActivity(), override fun onOptionsItemSelected(item: MenuItem): Boolean { if (item.itemId == android.R.id.home) { - onBackPressed() + onBackPressedDispatcher.onBackPressed() return true } return super.onOptionsItemSelected(item) diff --git a/WordPress/src/main/java/org/wordpress/android/ui/people/PeopleManagementActivity.java b/WordPress/src/main/java/org/wordpress/android/ui/people/PeopleManagementActivity.java index 0f0f8c69a615..d2f8289cde61 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/people/PeopleManagementActivity.java +++ b/WordPress/src/main/java/org/wordpress/android/ui/people/PeopleManagementActivity.java @@ -227,7 +227,7 @@ public void onBackPressed() { @Override public boolean onOptionsItemSelected(final MenuItem item) { if (item.getItemId() == android.R.id.home) { - onBackPressed(); + getOnBackPressedDispatcher().onBackPressed(); return true; } else if (item.getItemId() == R.id.remove_person) { confirmRemovePerson(); diff --git a/WordPress/src/main/java/org/wordpress/android/ui/plugins/PluginBrowserActivity.java b/WordPress/src/main/java/org/wordpress/android/ui/plugins/PluginBrowserActivity.java index 75d16600eefa..1cbbab6331b8 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/plugins/PluginBrowserActivity.java +++ b/WordPress/src/main/java/org/wordpress/android/ui/plugins/PluginBrowserActivity.java @@ -225,7 +225,7 @@ public boolean onCreateOptionsMenu(Menu menu) { @Override public boolean onOptionsItemSelected(final MenuItem item) { if (item.getItemId() == android.R.id.home) { - onBackPressed(); + getOnBackPressedDispatcher().onBackPressed(); return true; } return super.onOptionsItemSelected(item); @@ -315,7 +315,7 @@ private void showListFragment(@NonNull PluginListType listType) { private void hideListFragment() { if (getSupportFragmentManager().getBackStackEntryCount() > 0) { - onBackPressed(); + getOnBackPressedDispatcher().onBackPressed(); } } diff --git a/WordPress/src/main/java/org/wordpress/android/ui/plugins/PluginDetailActivity.java b/WordPress/src/main/java/org/wordpress/android/ui/plugins/PluginDetailActivity.java index f218343e1467..e9ca8483951d 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/plugins/PluginDetailActivity.java +++ b/WordPress/src/main/java/org/wordpress/android/ui/plugins/PluginDetailActivity.java @@ -80,7 +80,6 @@ import org.wordpress.android.util.AniUtils; import org.wordpress.android.util.AppLog; import org.wordpress.android.util.AppLog.T; -import org.wordpress.android.util.extensions.ContextExtensionsKt; import org.wordpress.android.util.DateTimeUtils; import org.wordpress.android.util.DisplayUtils; import org.wordpress.android.util.FormatUtils; @@ -91,6 +90,7 @@ import org.wordpress.android.util.ToastUtils.Duration; import org.wordpress.android.util.WPLinkMovementMethod; import org.wordpress.android.util.analytics.AnalyticsUtils; +import org.wordpress.android.util.extensions.ContextExtensionsKt; import org.wordpress.android.util.image.ImageManager; import org.wordpress.android.util.image.ImageType; import org.wordpress.android.widgets.WPSnackbar; @@ -413,7 +413,7 @@ public boolean onOptionsItemSelected(final MenuItem item) { // user is leaving the page dispatchConfigurePluginAction(true); } - onBackPressed(); + getOnBackPressedDispatcher().onBackPressed(); return true; } else if (item.getItemId() == R.id.menu_trash) { if (NetworkUtils.checkConnection(this)) { diff --git a/WordPress/src/main/java/org/wordpress/android/ui/posts/PostsListActivity.kt b/WordPress/src/main/java/org/wordpress/android/ui/posts/PostsListActivity.kt index 2730030c96a8..f5008ce92eaf 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/posts/PostsListActivity.kt +++ b/WordPress/src/main/java/org/wordpress/android/ui/posts/PostsListActivity.kt @@ -532,7 +532,7 @@ class PostsListActivity : LocaleAwareActivity(), override fun onOptionsItemSelected(item: MenuItem): Boolean { if (item.itemId == android.R.id.home) { - onBackPressed() + onBackPressedDispatcher.onBackPressed() return true } else if (item.itemId == R.id.toggle_post_list_item_layout) { viewModel.toggleViewLayout() diff --git a/WordPress/src/main/java/org/wordpress/android/ui/prefs/AccountSettingsActivity.java b/WordPress/src/main/java/org/wordpress/android/ui/prefs/AccountSettingsActivity.java index c5b9fb9d979a..6fd2a3b7a3cf 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/prefs/AccountSettingsActivity.java +++ b/WordPress/src/main/java/org/wordpress/android/ui/prefs/AccountSettingsActivity.java @@ -29,7 +29,7 @@ public void onCreate(Bundle savedInstanceState) { @Override public boolean onOptionsItemSelected(final MenuItem item) { if (item.getItemId() == android.R.id.home) { - onBackPressed(); + getOnBackPressedDispatcher().onBackPressed(); return true; } return super.onOptionsItemSelected(item); diff --git a/WordPress/src/main/java/org/wordpress/android/ui/prefs/AppSettingsActivity.java b/WordPress/src/main/java/org/wordpress/android/ui/prefs/AppSettingsActivity.java index 19066a83c25f..37a291651a38 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/prefs/AppSettingsActivity.java +++ b/WordPress/src/main/java/org/wordpress/android/ui/prefs/AppSettingsActivity.java @@ -35,7 +35,7 @@ public void onCreate(Bundle savedInstanceState) { @Override public boolean onOptionsItemSelected(final MenuItem item) { if (item.getItemId() == android.R.id.home) { - onBackPressed(); + getOnBackPressedDispatcher().onBackPressed(); return true; } return super.onOptionsItemSelected(item); diff --git a/WordPress/src/main/java/org/wordpress/android/ui/prefs/MyProfileActivity.java b/WordPress/src/main/java/org/wordpress/android/ui/prefs/MyProfileActivity.java index b16ea68032ef..03e50ff2e6b1 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/prefs/MyProfileActivity.java +++ b/WordPress/src/main/java/org/wordpress/android/ui/prefs/MyProfileActivity.java @@ -39,7 +39,7 @@ public void onCreate(Bundle savedInstanceState) { @Override public boolean onOptionsItemSelected(final MenuItem item) { if (item.getItemId() == android.R.id.home) { - onBackPressed(); + getOnBackPressedDispatcher().onBackPressed(); return true; } return super.onOptionsItemSelected(item); diff --git a/WordPress/src/main/java/org/wordpress/android/ui/prefs/SiteSettingsTagListActivity.java b/WordPress/src/main/java/org/wordpress/android/ui/prefs/SiteSettingsTagListActivity.java index 3b567c9c4a0c..29e9751c914f 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/prefs/SiteSettingsTagListActivity.java +++ b/WordPress/src/main/java/org/wordpress/android/ui/prefs/SiteSettingsTagListActivity.java @@ -217,7 +217,7 @@ public boolean onCreateOptionsMenu(Menu menu) { @Override public boolean onOptionsItemSelected(final MenuItem item) { if (item.getItemId() == android.R.id.home) { - onBackPressed(); + getOnBackPressedDispatcher().onBackPressed(); return true; } else { return super.onOptionsItemSelected(item); diff --git a/WordPress/src/main/java/org/wordpress/android/ui/prefs/categories/detail/CategoryDetailActivity.kt b/WordPress/src/main/java/org/wordpress/android/ui/prefs/categories/detail/CategoryDetailActivity.kt index d7a9c347a051..80d8e1d9a497 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/prefs/categories/detail/CategoryDetailActivity.kt +++ b/WordPress/src/main/java/org/wordpress/android/ui/prefs/categories/detail/CategoryDetailActivity.kt @@ -22,7 +22,7 @@ class CategoryDetailActivity : LocaleAwareActivity() { override fun onOptionsItemSelected(item: MenuItem): Boolean { if (item.itemId == android.R.id.home) { - onBackPressed() + onBackPressedDispatcher.onBackPressed() return true } return super.onOptionsItemSelected(item) diff --git a/WordPress/src/main/java/org/wordpress/android/ui/prefs/categories/list/CategoriesListActivity.kt b/WordPress/src/main/java/org/wordpress/android/ui/prefs/categories/list/CategoriesListActivity.kt index 5cf95ad7e8d2..ace469515a1f 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/prefs/categories/list/CategoriesListActivity.kt +++ b/WordPress/src/main/java/org/wordpress/android/ui/prefs/categories/list/CategoriesListActivity.kt @@ -22,7 +22,7 @@ class CategoriesListActivity : LocaleAwareActivity() { override fun onOptionsItemSelected(item: MenuItem): Boolean { if (item.itemId == android.R.id.home) { - onBackPressed() + onBackPressedDispatcher.onBackPressed() return true } return super.onOptionsItemSelected(item) diff --git a/WordPress/src/main/java/org/wordpress/android/ui/prefs/notifications/NotificationsSettingsActivity.kt b/WordPress/src/main/java/org/wordpress/android/ui/prefs/notifications/NotificationsSettingsActivity.kt index 6f0a71f774a9..09d5663e78e1 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/prefs/notifications/NotificationsSettingsActivity.kt +++ b/WordPress/src/main/java/org/wordpress/android/ui/prefs/notifications/NotificationsSettingsActivity.kt @@ -76,7 +76,7 @@ class NotificationsSettingsActivity : LocaleAwareActivity(), MainSwitchToolbarLi override fun onOptionsItemSelected(item: MenuItem): Boolean { when (item.itemId) { android.R.id.home -> { - onBackPressed() + onBackPressedDispatcher.onBackPressed() return true } } diff --git a/WordPress/src/main/java/org/wordpress/android/ui/publicize/PublicizeListActivity.java b/WordPress/src/main/java/org/wordpress/android/ui/publicize/PublicizeListActivity.java index 0c8a7d88bdea..0161ef713021 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/publicize/PublicizeListActivity.java +++ b/WordPress/src/main/java/org/wordpress/android/ui/publicize/PublicizeListActivity.java @@ -209,7 +209,7 @@ private void closeWebViewFragment() { public boolean onOptionsItemSelected(final MenuItem item) { int itemId = item.getItemId(); if (itemId == android.R.id.home) { - onBackPressed(); + getOnBackPressedDispatcher().onBackPressed(); return true; } return super.onOptionsItemSelected(item); diff --git a/WordPress/src/main/java/org/wordpress/android/ui/reader/ReaderPhotoViewerActivity.java b/WordPress/src/main/java/org/wordpress/android/ui/reader/ReaderPhotoViewerActivity.java index 3fa2eedc8b54..9e8dc104c46c 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/reader/ReaderPhotoViewerActivity.java +++ b/WordPress/src/main/java/org/wordpress/android/ui/reader/ReaderPhotoViewerActivity.java @@ -158,7 +158,7 @@ public void onAnimationRepeat(Animation animation) { @Override public boolean onOptionsItemSelected(MenuItem item) { if (item.getItemId() == android.R.id.home) { - onBackPressed(); + getOnBackPressedDispatcher().onBackPressed(); return true; } return super.onOptionsItemSelected(item); diff --git a/WordPress/src/main/java/org/wordpress/android/ui/reader/ReaderPostDetailFragment.kt b/WordPress/src/main/java/org/wordpress/android/ui/reader/ReaderPostDetailFragment.kt index f090619b06e0..56d209c47ccb 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/reader/ReaderPostDetailFragment.kt +++ b/WordPress/src/main/java/org/wordpress/android/ui/reader/ReaderPostDetailFragment.kt @@ -400,7 +400,7 @@ class ReaderPostDetailFragment : ViewPagerFragment(), toolBar.setTitle(R.string.reader_title_related_post_detail) } else { toolBar.setNavigationIcon(R.drawable.ic_arrow_back_white_24dp) - toolBar.setNavigationOnClickListener { requireActivity().onBackPressed() } + toolBar.setNavigationOnClickListener { requireActivity().onBackPressedDispatcher.onBackPressed() } } } diff --git a/WordPress/src/main/java/org/wordpress/android/ui/reader/ReaderPostListActivity.java b/WordPress/src/main/java/org/wordpress/android/ui/reader/ReaderPostListActivity.java index f84c7c373756..d4c6c023c8b7 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/reader/ReaderPostListActivity.java +++ b/WordPress/src/main/java/org/wordpress/android/ui/reader/ReaderPostListActivity.java @@ -209,7 +209,7 @@ public boolean onCreateOptionsMenu(Menu menu) { public boolean onOptionsItemSelected(MenuItem item) { switch (item.getItemId()) { case android.R.id.home: - onBackPressed(); + getOnBackPressedDispatcher().onBackPressed(); return true; case R.id.menu_share: shareSite(); diff --git a/WordPress/src/main/java/org/wordpress/android/ui/reader/ReaderSubsActivity.java b/WordPress/src/main/java/org/wordpress/android/ui/reader/ReaderSubsActivity.java index f07cb273da73..e2d36209592a 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/reader/ReaderSubsActivity.java +++ b/WordPress/src/main/java/org/wordpress/android/ui/reader/ReaderSubsActivity.java @@ -107,7 +107,7 @@ protected void onCreate(Bundle savedInstanceState) { Toolbar toolbar = findViewById(R.id.toolbar_main); if (toolbar != null) { setSupportActionBar(toolbar); - toolbar.setNavigationOnClickListener(v -> onBackPressed()); + toolbar.setNavigationOnClickListener(v -> getOnBackPressedDispatcher().onBackPressed()); } ActionBar actionBar = getSupportActionBar(); diff --git a/WordPress/src/main/java/org/wordpress/android/ui/reader/ReaderUserListActivity.java b/WordPress/src/main/java/org/wordpress/android/ui/reader/ReaderUserListActivity.java index e7f47bf31dca..eaf13a0a0171 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/reader/ReaderUserListActivity.java +++ b/WordPress/src/main/java/org/wordpress/android/ui/reader/ReaderUserListActivity.java @@ -1,7 +1,6 @@ package org.wordpress.android.ui.reader; import android.os.Bundle; -import android.view.View; import androidx.appcompat.app.ActionBar; import androidx.appcompat.widget.Toolbar; @@ -41,12 +40,7 @@ protected void onCreate(Bundle savedInstanceState) { Toolbar toolbar = findViewById(R.id.toolbar_main); if (toolbar != null) { setSupportActionBar(toolbar); - toolbar.setNavigationOnClickListener(new View.OnClickListener() { - @Override - public void onClick(View v) { - onBackPressed(); - } - }); + toolbar.setNavigationOnClickListener(v -> getOnBackPressedDispatcher().onBackPressed()); } ActionBar actionBar = getSupportActionBar(); diff --git a/WordPress/src/main/java/org/wordpress/android/ui/reader/discover/interests/ReaderInterestsActivity.kt b/WordPress/src/main/java/org/wordpress/android/ui/reader/discover/interests/ReaderInterestsActivity.kt index 5aad63751ee0..3f082043b856 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/reader/discover/interests/ReaderInterestsActivity.kt +++ b/WordPress/src/main/java/org/wordpress/android/ui/reader/discover/interests/ReaderInterestsActivity.kt @@ -23,7 +23,7 @@ class ReaderInterestsActivity : LocaleAwareActivity() { override fun onOptionsItemSelected(item: MenuItem): Boolean { if (item.itemId == android.R.id.home) { - onBackPressed() + onBackPressedDispatcher.onBackPressed() return true } return super.onOptionsItemSelected(item) diff --git a/WordPress/src/main/java/org/wordpress/android/ui/sitecreation/SiteCreationActivity.kt b/WordPress/src/main/java/org/wordpress/android/ui/sitecreation/SiteCreationActivity.kt index 4a929ca4672f..a069aaff7cfa 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/sitecreation/SiteCreationActivity.kt +++ b/WordPress/src/main/java/org/wordpress/android/ui/sitecreation/SiteCreationActivity.kt @@ -134,7 +134,7 @@ class SiteCreationActivity : LocaleAwareActivity(), }) mainViewModel.onBackPressedObservable.observe(this, Observer { ActivityUtils.hideKeyboard(this) - super.onBackPressed() + onBackPressedDispatcher.onBackPressed() }) siteCreationIntentsViewModel.onBackButtonPressed.observe(this, Observer { mainViewModel.onBackPressed() @@ -274,7 +274,7 @@ class SiteCreationActivity : LocaleAwareActivity(), override fun onOptionsItemSelected(item: MenuItem): Boolean { if (item.itemId == android.R.id.home) { - onBackPressed() + onBackPressedDispatcher.onBackPressed() return true } return false diff --git a/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/StatsActivity.kt b/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/StatsActivity.kt index 25ab3eaed2ee..80385f36a3c8 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/StatsActivity.kt +++ b/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/StatsActivity.kt @@ -34,7 +34,7 @@ class StatsActivity : LocaleAwareActivity() { override fun onOptionsItemSelected(item: MenuItem): Boolean { if (item.itemId == android.R.id.home) { - onBackPressed() + onBackPressedDispatcher.onBackPressed() return true } return super.onOptionsItemSelected(item) diff --git a/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/StatsViewAllActivity.kt b/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/StatsViewAllActivity.kt index ee070223d926..fb82be62354e 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/StatsViewAllActivity.kt +++ b/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/StatsViewAllActivity.kt @@ -23,7 +23,7 @@ class StatsViewAllActivity : LocaleAwareActivity() { override fun onOptionsItemSelected(item: MenuItem): Boolean { if (item.itemId == android.R.id.home) { - onBackPressed() + onBackPressedDispatcher.onBackPressed() return true } return super.onOptionsItemSelected(item) diff --git a/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/lists/detail/StatsDetailActivity.kt b/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/lists/detail/StatsDetailActivity.kt index 6dbacf1e9eeb..96cd7188653a 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/lists/detail/StatsDetailActivity.kt +++ b/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/lists/detail/StatsDetailActivity.kt @@ -51,7 +51,7 @@ class StatsDetailActivity : LocaleAwareActivity() { override fun onOptionsItemSelected(item: MenuItem): Boolean { if (item.itemId == android.R.id.home) { - onBackPressed() + onBackPressedDispatcher.onBackPressed() return true } return super.onOptionsItemSelected(item) diff --git a/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/lists/sections/insights/management/InsightsManagementActivity.kt b/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/lists/sections/insights/management/InsightsManagementActivity.kt index fbb3d52ec2a1..3842d273eed2 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/lists/sections/insights/management/InsightsManagementActivity.kt +++ b/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/lists/sections/insights/management/InsightsManagementActivity.kt @@ -24,7 +24,7 @@ class InsightsManagementActivity : LocaleAwareActivity() { override fun onOptionsItemSelected(item: MenuItem): Boolean { if (item.itemId == android.R.id.home) { - onBackPressed() + onBackPressedDispatcher.onBackPressed() return true } return super.onOptionsItemSelected(item) diff --git a/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/lists/widget/alltime/StatsAllTimeWidgetConfigureActivity.kt b/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/lists/widget/alltime/StatsAllTimeWidgetConfigureActivity.kt index 2d8364d7ce9a..0c888fe3013d 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/lists/widget/alltime/StatsAllTimeWidgetConfigureActivity.kt +++ b/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/lists/widget/alltime/StatsAllTimeWidgetConfigureActivity.kt @@ -21,7 +21,7 @@ class StatsAllTimeWidgetConfigureActivity : LocaleAwareActivity() { override fun onOptionsItemSelected(item: MenuItem): Boolean { if (item.itemId == android.R.id.home) { - onBackPressed() + onBackPressedDispatcher.onBackPressed() return true } return super.onOptionsItemSelected(item) diff --git a/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/lists/widget/minified/StatsMinifiedWidgetConfigureActivity.kt b/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/lists/widget/minified/StatsMinifiedWidgetConfigureActivity.kt index 4402a1769655..7ef15a5ff49f 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/lists/widget/minified/StatsMinifiedWidgetConfigureActivity.kt +++ b/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/lists/widget/minified/StatsMinifiedWidgetConfigureActivity.kt @@ -21,7 +21,7 @@ class StatsMinifiedWidgetConfigureActivity : LocaleAwareActivity() { override fun onOptionsItemSelected(item: MenuItem): Boolean { if (item.itemId == android.R.id.home) { - onBackPressed() + onBackPressedDispatcher.onBackPressed() return true } return super.onOptionsItemSelected(item) diff --git a/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/lists/widget/today/StatsTodayWidgetConfigureActivity.kt b/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/lists/widget/today/StatsTodayWidgetConfigureActivity.kt index 6f8cadff4fb2..2097a7472246 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/lists/widget/today/StatsTodayWidgetConfigureActivity.kt +++ b/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/lists/widget/today/StatsTodayWidgetConfigureActivity.kt @@ -21,7 +21,7 @@ class StatsTodayWidgetConfigureActivity : LocaleAwareActivity() { override fun onOptionsItemSelected(item: MenuItem): Boolean { if (item.itemId == android.R.id.home) { - onBackPressed() + onBackPressedDispatcher.onBackPressed() return true } return super.onOptionsItemSelected(item) diff --git a/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/lists/widget/views/StatsViewsWidgetConfigureActivity.kt b/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/lists/widget/views/StatsViewsWidgetConfigureActivity.kt index 057ea12aaa37..321d789fe963 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/lists/widget/views/StatsViewsWidgetConfigureActivity.kt +++ b/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/lists/widget/views/StatsViewsWidgetConfigureActivity.kt @@ -21,7 +21,7 @@ class StatsViewsWidgetConfigureActivity : LocaleAwareActivity() { override fun onOptionsItemSelected(item: MenuItem): Boolean { if (item.itemId == android.R.id.home) { - onBackPressed() + onBackPressedDispatcher.onBackPressed() return true } return super.onOptionsItemSelected(item) diff --git a/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/lists/widget/weeks/StatsWeekWidgetConfigureActivity.kt b/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/lists/widget/weeks/StatsWeekWidgetConfigureActivity.kt index f6fe3e596baa..d6e0b0236b75 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/lists/widget/weeks/StatsWeekWidgetConfigureActivity.kt +++ b/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/lists/widget/weeks/StatsWeekWidgetConfigureActivity.kt @@ -21,7 +21,7 @@ class StatsWeekWidgetConfigureActivity : LocaleAwareActivity() { override fun onOptionsItemSelected(item: MenuItem): Boolean { if (item.itemId == android.R.id.home) { - onBackPressed() + onBackPressedDispatcher.onBackPressed() return true } return super.onOptionsItemSelected(item) diff --git a/WordPress/src/main/java/org/wordpress/android/ui/themes/ThemeBrowserActivity.java b/WordPress/src/main/java/org/wordpress/android/ui/themes/ThemeBrowserActivity.java index 2c6f5026b560..d27dac19701d 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/themes/ThemeBrowserActivity.java +++ b/WordPress/src/main/java/org/wordpress/android/ui/themes/ThemeBrowserActivity.java @@ -129,7 +129,7 @@ protected void onSaveInstanceState(@NotNull Bundle outState) { public boolean onOptionsItemSelected(MenuItem item) { int i = item.getItemId(); if (i == android.R.id.home) { - onBackPressed(); + getOnBackPressedDispatcher().onBackPressed(); return true; } diff --git a/libs/image-editor/src/main/kotlin/org/wordpress/android/imageeditor/EditImageActivity.kt b/libs/image-editor/src/main/kotlin/org/wordpress/android/imageeditor/EditImageActivity.kt index ed0e7a729d12..4ad84dba4ca9 100644 --- a/libs/image-editor/src/main/kotlin/org/wordpress/android/imageeditor/EditImageActivity.kt +++ b/libs/image-editor/src/main/kotlin/org/wordpress/android/imageeditor/EditImageActivity.kt @@ -40,7 +40,7 @@ class EditImageActivity : AppCompatActivity() { // Passing in an empty set of top-level destination to display back button on the start destination appBarConfiguration = AppBarConfiguration.Builder().setFallbackOnNavigateUpListener { // Handle app bar's back button on start destination - onBackPressed() + onBackPressedDispatcher.onBackPressed() true }.build() @@ -53,7 +53,7 @@ class EditImageActivity : AppCompatActivity() { // Using popUpToInclusive for popping the start destination of the graph off the back stack // in a multi-module project doesn't seem to be working. Explicitly invoking back action as a workaround. // Related issue: https://issuetracker.google.com/issues/147312109 - onBackPressed() + onBackPressedDispatcher.onBackPressed() true } else { navController.navigateUp(appBarConfiguration) || super.onSupportNavigateUp() From 3bca5a7943c0a1e51ef15ea981cae2b0fdb26ecd Mon Sep 17 00:00:00 2001 From: Irfan Omur Date: Sat, 11 Feb 2023 19:21:52 +0300 Subject: [PATCH 013/856] Migrate activities to OnBackPressedCallback Activity's onBackPressed was deprecated on Android 13. --- .../ui/JetpackConnectionResultActivity.java | 17 ++++--- .../ui/JetpackRemoteInstallActivity.kt | 18 ++++---- .../android/ui/WPWebViewActivity.java | 29 +++++++----- .../wordpress/android/ui/WebViewActivity.java | 25 ++++++---- .../PostSignupInterstitialActivity.kt | 8 ++-- .../ui/comments/CommentsDetailActivity.java | 29 +++++++----- .../ui/comments/EditCommentActivity.java | 24 ++++++---- .../DeepLinkingIntentReceiverActivity.java | 18 +++++--- .../ui/history/HistoryDetailActivity.kt | 9 ++-- .../JetpackFullPluginInstallActivity.kt | 8 ++-- .../android/ui/main/WPMainActivity.java | 46 +++++++++++-------- .../ui/media/MediaSettingsActivity.java | 17 ++++--- .../NotificationsDetailActivity.java | 35 ++++++++------ .../ui/people/PeopleManagementActivity.java | 19 +++++--- .../ui/plugins/PluginBrowserActivity.java | 27 ++++++----- .../android/ui/posts/EditPostActivity.java | 15 ++++-- .../posts/JetpackSecuritySettingsActivity.kt | 11 +++-- .../ui/posts/PostSettingsTagsActivity.java | 17 ++++--- .../ui/posts/SelectCategoriesActivity.java | 18 +++++--- .../ui/prefs/SiteSettingsTagListActivity.java | 35 ++++++++------ .../ui/publicize/PublicizeListActivity.java | 23 ++++++---- .../ui/reader/ReaderCommentListActivity.java | 31 +++++++------ .../ui/reader/ReaderPostListActivity.java | 21 +++++---- .../ui/reader/ReaderPostPagerActivity.java | 35 ++++++++------ .../android/ui/reader/ReaderSubsActivity.java | 23 ++++++---- .../ui/sitecreation/SiteCreationActivity.kt | 8 ++-- .../ui/suggestion/SuggestionActivity.kt | 8 ++-- .../ui/themes/ThemeBrowserActivity.java | 25 ++++++---- .../android/imageeditor/EditImageActivity.kt | 16 ++++--- 29 files changed, 364 insertions(+), 251 deletions(-) diff --git a/WordPress/src/main/java/org/wordpress/android/ui/JetpackConnectionResultActivity.java b/WordPress/src/main/java/org/wordpress/android/ui/JetpackConnectionResultActivity.java index 69159dc25f3f..19362744c966 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/JetpackConnectionResultActivity.java +++ b/WordPress/src/main/java/org/wordpress/android/ui/JetpackConnectionResultActivity.java @@ -5,6 +5,7 @@ import android.os.Bundle; import android.text.TextUtils; +import androidx.activity.OnBackPressedCallback; import androidx.appcompat.app.ActionBar; import androidx.appcompat.widget.Toolbar; @@ -54,6 +55,16 @@ protected void onCreate(Bundle savedInstanceState) { setContentView(R.layout.stats_loading_activity); + OnBackPressedCallback callback = new OnBackPressedCallback(true) { + @Override + public void handleOnBackPressed() { + setEnabled(false); + getOnBackPressedDispatcher().onBackPressed(); + finishAndGoBackToSource(); + } + }; + + getOnBackPressedDispatcher().addCallback(this, callback); Toolbar toolbar = findViewById(R.id.toolbar_main); setSupportActionBar(toolbar); @@ -109,12 +120,6 @@ protected void onActivityResult(int requestCode, int resultCode, Intent data) { } } - @Override - public void onBackPressed() { - super.onBackPressed(); - finishAndGoBackToSource(); - } - private void trackResult() { if (!TextUtils.isEmpty(mReason)) { if (mReason.equals(ALREADY_CONNECTED)) { diff --git a/WordPress/src/main/java/org/wordpress/android/ui/JetpackRemoteInstallActivity.kt b/WordPress/src/main/java/org/wordpress/android/ui/JetpackRemoteInstallActivity.kt index 7bfd7ab2b0f2..accce847a68f 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/JetpackRemoteInstallActivity.kt +++ b/WordPress/src/main/java/org/wordpress/android/ui/JetpackRemoteInstallActivity.kt @@ -2,6 +2,7 @@ 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 @@ -16,6 +17,15 @@ class JetpackRemoteInstallActivity : LocaleAwareActivity() { setSupportActionBar(toolbarLayout.toolbarMain) } + onBackPressedDispatcher.addCallback(this) { + trackWithSource( + INSTALL_JETPACK_CANCELLED, + intent.getSerializableExtra(TRACKING_SOURCE_KEY) as JetpackConnectionSource + ) + isEnabled = false + onBackPressedDispatcher.onBackPressed() + } + supportActionBar?.let { it.setHomeButtonEnabled(true) it.setDisplayHomeAsUpEnabled(true) @@ -30,12 +40,4 @@ class JetpackRemoteInstallActivity : LocaleAwareActivity() { } return super.onOptionsItemSelected(item) } - - override fun onBackPressed() { - trackWithSource( - INSTALL_JETPACK_CANCELLED, - intent.getSerializableExtra(TRACKING_SOURCE_KEY) as JetpackConnectionSource - ) - super.onBackPressed() - } } diff --git a/WordPress/src/main/java/org/wordpress/android/ui/WPWebViewActivity.java b/WordPress/src/main/java/org/wordpress/android/ui/WPWebViewActivity.java index 1dc437490e16..8a0a24828f74 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/WPWebViewActivity.java +++ b/WordPress/src/main/java/org/wordpress/android/ui/WPWebViewActivity.java @@ -22,6 +22,7 @@ import android.widget.RelativeLayout.LayoutParams; import android.widget.TextView; +import androidx.activity.OnBackPressedCallback; import androidx.annotation.Nullable; import androidx.appcompat.app.ActionBar; import androidx.appcompat.widget.Toolbar; @@ -161,6 +162,22 @@ public class WPWebViewActivity extends WebViewActivity implements ErrorManagedWe public void onCreate(Bundle savedInstanceState) { ((WordPress) getApplication()).component().inject(this); super.onCreate(savedInstanceState); + + OnBackPressedCallback callback = new OnBackPressedCallback(true) { + @Override + public void handleOnBackPressed() { + if (mWebView.canGoBack()) { + mWebView.goBack(); + refreshBackForwardNavButtons(); + } else { + setEnabled(false); + getOnBackPressedDispatcher().onBackPressed(); + mViewModel.track(Stat.WEBVIEW_DISMISSED); + setResultIfNeeded(); + } + } + }; + getOnBackPressedDispatcher().addCallback(this, callback); } @Override @@ -916,18 +933,6 @@ private void setResultIfNeededAndFinish() { finish(); } - @Override - public void onBackPressed() { - if (mWebView.canGoBack()) { - mWebView.goBack(); - refreshBackForwardNavButtons(); - } else { - super.onBackPressed(); - mViewModel.track(Stat.WEBVIEW_DISMISSED); - setResultIfNeeded(); - } - } - @Override public void onStart() { super.onStart(); diff --git a/WordPress/src/main/java/org/wordpress/android/ui/WebViewActivity.java b/WordPress/src/main/java/org/wordpress/android/ui/WebViewActivity.java index 43ccf8c2f184..d8824ed71af5 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/WebViewActivity.java +++ b/WordPress/src/main/java/org/wordpress/android/ui/WebViewActivity.java @@ -6,6 +6,7 @@ import android.view.Window; import android.webkit.WebView; +import androidx.activity.OnBackPressedCallback; import androidx.appcompat.app.ActionBar; import androidx.appcompat.widget.Toolbar; @@ -39,6 +40,20 @@ public void onCreate(Bundle savedInstanceState) { configureView(); + OnBackPressedCallback callback = new OnBackPressedCallback(true) { + @Override + public void handleOnBackPressed() { + if (mWebView != null && mWebView.canGoBack()) { + mWebView.goBack(); + } else { + cancel(); + setEnabled(false); + getOnBackPressedDispatcher().onBackPressed(); + } + } + }; + getOnBackPressedDispatcher().addCallback(this, callback); + mWebView = (WebView) findViewById(R.id.webView); mWebView.setScrollBarStyle(View.SCROLLBARS_INSIDE_OVERLAY); // Setting this user agent makes Calypso sites hide any WordPress UIs (e.g. Masterbar, banners, etc.). @@ -145,16 +160,6 @@ public void loadUrl(String url, Map additionalHttpHeaders) { mWebView.loadUrl(url, additionalHttpHeaders); } - @Override - public void onBackPressed() { - if (mWebView != null && mWebView.canGoBack()) { - mWebView.goBack(); - } else { - cancel(); - super.onBackPressed(); - } - } - @Override public boolean onOptionsItemSelected(final MenuItem item) { if (item.getItemId() == android.R.id.home) { diff --git a/WordPress/src/main/java/org/wordpress/android/ui/accounts/PostSignupInterstitialActivity.kt b/WordPress/src/main/java/org/wordpress/android/ui/accounts/PostSignupInterstitialActivity.kt index 63f831845130..c5cfab96d284 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/accounts/PostSignupInterstitialActivity.kt +++ b/WordPress/src/main/java/org/wordpress/android/ui/accounts/PostSignupInterstitialActivity.kt @@ -1,6 +1,7 @@ package org.wordpress.android.ui.accounts import android.os.Bundle +import androidx.activity.addCallback import androidx.lifecycle.ViewModelProvider import com.google.android.material.button.MaterialButton import org.wordpress.android.R @@ -31,6 +32,9 @@ class PostSignupInterstitialActivity : LocaleAwareActivity() { .get(PostSignupInterstitialViewModel::class.java) val binding = PostSignupInterstitialActivityBinding.inflate(layoutInflater) setContentView(binding.root) + + onBackPressedDispatcher.addCallback(this) { viewModel.onBackButtonPressed() } + with(binding) { viewModel.onInterstitialShown() createNewSiteButton().setOnClickListener { viewModel.onCreateNewSiteButtonPressed() } @@ -50,10 +54,6 @@ class PostSignupInterstitialActivity : LocaleAwareActivity() { private fun PostSignupInterstitialActivityBinding.dismissButton() = root.findViewById(R.id.dismiss_button) - override fun onBackPressed() { - viewModel.onBackButtonPressed() - } - private fun executeAction(navigationAction: NavigationAction) = when (navigationAction) { START_SITE_CREATION_FLOW -> startSiteCreationFlow() START_SITE_CONNECTION_FLOW -> startSiteConnectionFlow() diff --git a/WordPress/src/main/java/org/wordpress/android/ui/comments/CommentsDetailActivity.java b/WordPress/src/main/java/org/wordpress/android/ui/comments/CommentsDetailActivity.java index cd37f943beb6..bb5af81cf12c 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/comments/CommentsDetailActivity.java +++ b/WordPress/src/main/java/org/wordpress/android/ui/comments/CommentsDetailActivity.java @@ -8,6 +8,7 @@ import android.view.View; import android.widget.ProgressBar; +import androidx.activity.OnBackPressedCallback; import androidx.appcompat.app.ActionBar; import androidx.appcompat.widget.Toolbar; import androidx.viewpager.widget.ViewPager; @@ -73,18 +74,6 @@ public class CommentsDetailActivity extends LocaleAwareActivity private boolean mIsUpdatingComments; private boolean mCanLoadMoreComments = true; - @Override - public void onBackPressed() { - CollapseFullScreenDialogFragment fragment = (CollapseFullScreenDialogFragment) - getSupportFragmentManager().findFragmentByTag(CollapseFullScreenDialogFragment.TAG); - - if (fragment != null) { - fragment.onBackPressed(); - } else { - super.onBackPressed(); - } - } - @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); @@ -94,6 +83,22 @@ public void onCreate(Bundle savedInstanceState) { setContentView(R.layout.comments_detail_activity); + OnBackPressedCallback callback = new OnBackPressedCallback(true) { + @Override + public void handleOnBackPressed() { + CollapseFullScreenDialogFragment fragment = (CollapseFullScreenDialogFragment) + getSupportFragmentManager().findFragmentByTag(CollapseFullScreenDialogFragment.TAG); + + if (fragment != null) { + fragment.onBackPressed(); + } else { + setEnabled(false); + getOnBackPressedDispatcher().onBackPressed(); + } + } + }; + getOnBackPressedDispatcher().addCallback(this, callback); + Toolbar toolbar = findViewById(R.id.toolbar_main); setSupportActionBar(toolbar); ActionBar actionBar = getSupportActionBar(); diff --git a/WordPress/src/main/java/org/wordpress/android/ui/comments/EditCommentActivity.java b/WordPress/src/main/java/org/wordpress/android/ui/comments/EditCommentActivity.java index d7e639227cbe..1a2a3e9746ba 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/comments/EditCommentActivity.java +++ b/WordPress/src/main/java/org/wordpress/android/ui/comments/EditCommentActivity.java @@ -13,6 +13,7 @@ import android.widget.EditText; import android.widget.ProgressBar; +import androidx.activity.OnBackPressedCallback; import androidx.appcompat.app.ActionBar; import androidx.appcompat.app.AlertDialog; import androidx.appcompat.widget.Toolbar; @@ -73,6 +74,20 @@ public void onCreate(Bundle icicle) { ((WordPress) getApplication()).component().inject(this); setContentView(R.layout.comment_edit_activity); + + OnBackPressedCallback callback = new OnBackPressedCallback(true) { + @Override + public void handleOnBackPressed() { + if (isCommentEdited()) { + cancelEditCommentConfirmation(); + } else { + setEnabled(false); + getOnBackPressedDispatcher().onBackPressed(); + } + } + }; + getOnBackPressedDispatcher().addCallback(this, callback); + Toolbar toolbar = findViewById(R.id.toolbar_main); setSupportActionBar(toolbar); ActionBar actionBar = getSupportActionBar(); @@ -293,15 +308,6 @@ private void setFetchProgressVisible(boolean progressVisible) { editContainer.setVisibility(progressVisible ? View.GONE : View.VISIBLE); } - @Override - public void onBackPressed() { - if (isCommentEdited()) { - cancelEditCommentConfirmation(); - } else { - super.onBackPressed(); - } - } - private void cancelEditCommentConfirmation() { if (mCancelEditCommentDialog != null) { mCancelEditCommentDialog.show(); diff --git a/WordPress/src/main/java/org/wordpress/android/ui/deeplinks/DeepLinkingIntentReceiverActivity.java b/WordPress/src/main/java/org/wordpress/android/ui/deeplinks/DeepLinkingIntentReceiverActivity.java index 5da594ae58eb..b8fedb502287 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/deeplinks/DeepLinkingIntentReceiverActivity.java +++ b/WordPress/src/main/java/org/wordpress/android/ui/deeplinks/DeepLinkingIntentReceiverActivity.java @@ -4,6 +4,7 @@ import android.net.Uri; import android.os.Bundle; +import androidx.activity.OnBackPressedCallback; import androidx.annotation.NonNull; import androidx.lifecycle.ViewModelProvider; @@ -49,6 +50,17 @@ public class DeepLinkingIntentReceiverActivity extends LocaleAwareActivity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); + + OnBackPressedCallback callback = new OnBackPressedCallback(true) { + @Override + public void handleOnBackPressed() { + setEnabled(false); + getOnBackPressedDispatcher().onBackPressed(); + finish(); + } + }; + getOnBackPressedDispatcher().addCallback(this, callback); + mViewModel = new ViewModelProvider(this).get(DeepLinkingIntentReceiverViewModel.class); mJetpackFullScreenViewModel = new ViewModelProvider(this).get(JetpackFeatureFullScreenOverlayViewModel.class); setupObservers(); @@ -139,10 +151,4 @@ protected void onActivityResult(int requestCode, int resultCode, Intent data) { finish(); } } - - @Override - public void onBackPressed() { - super.onBackPressed(); - finish(); - } } diff --git a/WordPress/src/main/java/org/wordpress/android/ui/history/HistoryDetailActivity.kt b/WordPress/src/main/java/org/wordpress/android/ui/history/HistoryDetailActivity.kt index 1f8537ee3772..814b0607d868 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/history/HistoryDetailActivity.kt +++ b/WordPress/src/main/java/org/wordpress/android/ui/history/HistoryDetailActivity.kt @@ -1,6 +1,7 @@ package org.wordpress.android.ui.history import android.os.Bundle +import androidx.activity.addCallback import org.wordpress.android.R import org.wordpress.android.analytics.AnalyticsTracker import org.wordpress.android.analytics.AnalyticsTracker.Stat @@ -19,6 +20,9 @@ class HistoryDetailActivity : LocaleAwareActivity() { setContentView(root) setSupportActionBar(toolbarMain) } + + onBackPressedDispatcher.addCallback(this) { AnalyticsTracker.track(Stat.REVISIONS_DETAIL_CANCELLED) } + supportActionBar?.setDisplayHomeAsUpEnabled(true) val extras = requireNotNull(intent.extras) @@ -44,9 +48,4 @@ class HistoryDetailActivity : LocaleAwareActivity() { finish() return true } - - override fun onBackPressed() { - AnalyticsTracker.track(Stat.REVISIONS_DETAIL_CANCELLED) - super.onBackPressed() - } } diff --git a/WordPress/src/main/java/org/wordpress/android/ui/jpfullplugininstall/install/JetpackFullPluginInstallActivity.kt b/WordPress/src/main/java/org/wordpress/android/ui/jpfullplugininstall/install/JetpackFullPluginInstallActivity.kt index cc658489747c..2368d425de27 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/jpfullplugininstall/install/JetpackFullPluginInstallActivity.kt +++ b/WordPress/src/main/java/org/wordpress/android/ui/jpfullplugininstall/install/JetpackFullPluginInstallActivity.kt @@ -3,6 +3,7 @@ package org.wordpress.android.ui.jpfullplugininstall.install import android.content.Context import android.content.Intent import android.os.Bundle +import androidx.activity.addCallback import androidx.activity.viewModels import androidx.appcompat.app.AppCompatActivity import androidx.compose.material.Scaffold @@ -36,11 +37,10 @@ class JetpackFullPluginInstallActivity : AppCompatActivity() { JetpackFullPluginInstallScreen() } } - observeActionEvents() - } - override fun onBackPressed() { - viewModel.onBackPressed() + onBackPressedDispatcher.addCallback(this) { viewModel.onBackPressed() } + + observeActionEvents() } @Composable diff --git a/WordPress/src/main/java/org/wordpress/android/ui/main/WPMainActivity.java b/WordPress/src/main/java/org/wordpress/android/ui/main/WPMainActivity.java index 590379164055..afc3f2adeb12 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/main/WPMainActivity.java +++ b/WordPress/src/main/java/org/wordpress/android/ui/main/WPMainActivity.java @@ -16,6 +16,7 @@ import android.widget.TextView; import android.widget.Toast; +import androidx.activity.OnBackPressedCallback; import androidx.annotation.NonNull; import androidx.annotation.Nullable; import androidx.core.app.NotificationManagerCompat; @@ -309,6 +310,7 @@ public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main_activity); + initBackPressHandler(); mConnectionBar = findViewById(R.id.connection_bar); mConnectionBar.setOnClickListener(v -> { @@ -490,6 +492,31 @@ && getIntent().getExtras().getBoolean(ARG_CONTINUE_JETPACK_CONNECT, false)) { displayJetpackFeatureCollectionOverlayIfNeeded(); } + private void initBackPressHandler() { + OnBackPressedCallback callback = new OnBackPressedCallback(true) { + @Override + public void handleOnBackPressed() { + // let the fragment handle the back button if it implements our OnParentBackPressedListener + if (mBottomNav != null) { + Fragment fragment = mBottomNav.getActiveFragment(); + if (fragment instanceof OnActivityBackPressedListener) { + boolean handled = ((OnActivityBackPressedListener) fragment).onActivityBackPressed(); + if (handled) { + return; + } + } + } + + if (isTaskRoot() && DeviceUtils.getInstance().isChromebook(WPMainActivity.this)) { + return; // don't close app in Main Activity + } + setEnabled(false); + getOnBackPressedDispatcher().onBackPressed(); + } + }; + getOnBackPressedDispatcher().addCallback(this, callback); + } + private void showJetpackOverlayIfNeeded(String action) { if (!mJetpackFeatureRemovalOverlayUtil.shouldHideJetpackFeatures()) { return; @@ -1107,25 +1134,6 @@ private void announceTitleForAccessibility(PageType pageType) { getWindow().getDecorView().announceForAccessibility(mBottomNav.getContentDescriptionForPageType(pageType)); } - @Override - public void onBackPressed() { - // let the fragment handle the back button if it implements our OnParentBackPressedListener - if (mBottomNav != null) { - Fragment fragment = mBottomNav.getActiveFragment(); - if (fragment instanceof OnActivityBackPressedListener) { - boolean handled = ((OnActivityBackPressedListener) fragment).onActivityBackPressed(); - if (handled) { - return; - } - } - } - - if (isTaskRoot() && DeviceUtils.getInstance().isChromebook(this)) { - return; // don't close app in Main Activity - } - super.onBackPressed(); - } - @Override public void onRequestShowBottomNavigation() { showBottomNav(true); diff --git a/WordPress/src/main/java/org/wordpress/android/ui/media/MediaSettingsActivity.java b/WordPress/src/main/java/org/wordpress/android/ui/media/MediaSettingsActivity.java index d4c43cd6ab12..3c9aa0ccef29 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/media/MediaSettingsActivity.java +++ b/WordPress/src/main/java/org/wordpress/android/ui/media/MediaSettingsActivity.java @@ -34,6 +34,7 @@ import android.widget.TextView; import android.widget.Toast; +import androidx.activity.OnBackPressedCallback; import androidx.annotation.DrawableRes; import androidx.annotation.IntegerRes; import androidx.annotation.NonNull; @@ -215,6 +216,16 @@ protected void onCreate(@Nullable Bundle savedInstanceState) { setContentView(R.layout.media_settings_activity); + OnBackPressedCallback callback = new OnBackPressedCallback(true) { + @Override + public void handleOnBackPressed() { + saveChanges(); + setEnabled(false); + getOnBackPressedDispatcher().onBackPressed(); + } + }; + getOnBackPressedDispatcher().addCallback(this, callback); + setSupportActionBar(findViewById(R.id.toolbar)); ActionBar actionBar = getSupportActionBar(); if (actionBar != null) { @@ -507,12 +518,6 @@ private void showProgress(boolean show) { findViewById(R.id.progress).setVisibility(show ? View.VISIBLE : View.GONE); } - @Override - public void onBackPressed() { - saveChanges(); - super.onBackPressed(); - } - @Override public boolean onCreateOptionsMenu(Menu menu) { getMenuInflater().inflate(R.menu.media_settings, menu); diff --git a/WordPress/src/main/java/org/wordpress/android/ui/notifications/NotificationsDetailActivity.java b/WordPress/src/main/java/org/wordpress/android/ui/notifications/NotificationsDetailActivity.java index 5d305470d934..5cec9ca5e318 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/notifications/NotificationsDetailActivity.java +++ b/WordPress/src/main/java/org/wordpress/android/ui/notifications/NotificationsDetailActivity.java @@ -9,6 +9,7 @@ import android.view.WindowManager; import android.widget.ProgressBar; +import androidx.activity.OnBackPressedCallback; import androidx.annotation.NonNull; import androidx.annotation.Nullable; import androidx.appcompat.app.ActionBar; @@ -57,13 +58,13 @@ import org.wordpress.android.ui.reader.comments.ThreadedCommentsActionSource; import org.wordpress.android.ui.reader.tracker.ReaderTracker; import org.wordpress.android.ui.stats.StatsViewType; -import org.wordpress.android.util.extensions.AppBarLayoutExtensionsKt; import org.wordpress.android.util.AppLog; import org.wordpress.android.util.StringUtils; import org.wordpress.android.util.ToastUtils; import org.wordpress.android.util.analytics.AnalyticsUtils; import org.wordpress.android.util.analytics.AnalyticsUtils.AnalyticsCommentActionSource; import org.wordpress.android.util.config.LikesEnhancementsFeatureConfig; +import org.wordpress.android.util.extensions.AppBarLayoutExtensionsKt; import org.wordpress.android.widgets.WPSwipeSnackbar; import org.wordpress.android.widgets.WPViewPager; import org.wordpress.android.widgets.WPViewPagerTransformer; @@ -74,14 +75,14 @@ import javax.inject.Inject; -import dagger.hilt.android.AndroidEntryPoint; - import static org.wordpress.android.models.Note.NOTE_COMMENT_LIKE_TYPE; import static org.wordpress.android.models.Note.NOTE_COMMENT_TYPE; import static org.wordpress.android.models.Note.NOTE_FOLLOW_TYPE; import static org.wordpress.android.models.Note.NOTE_LIKE_TYPE; import static org.wordpress.android.ui.notifications.services.NotificationsUpdateServiceStarter.IS_TAPPED_ON_NOTIFICATION; +import dagger.hilt.android.AndroidEntryPoint; + @AndroidEntryPoint public class NotificationsDetailActivity extends LocaleAwareActivity implements CommentActions.OnNoteCommentActionListener, @@ -105,18 +106,6 @@ public class NotificationsDetailActivity extends LocaleAwareActivity implements private AppBarLayout mAppBarLayout; private Toolbar mToolbar; - @Override - public void onBackPressed() { - CollapseFullScreenDialogFragment fragment = (CollapseFullScreenDialogFragment) - getSupportFragmentManager().findFragmentByTag(CollapseFullScreenDialogFragment.TAG); - - if (fragment != null) { - fragment.onBackPressed(); - } else { - super.onBackPressed(); - } - } - @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); @@ -125,6 +114,22 @@ public void onCreate(Bundle savedInstanceState) { setContentView(R.layout.notifications_detail_activity); + OnBackPressedCallback callback = new OnBackPressedCallback(true) { + @Override + public void handleOnBackPressed() { + CollapseFullScreenDialogFragment fragment = (CollapseFullScreenDialogFragment) + getSupportFragmentManager().findFragmentByTag(CollapseFullScreenDialogFragment.TAG); + + if (fragment != null) { + fragment.onBackPressed(); + } else { + setEnabled(false); + getOnBackPressedDispatcher().onBackPressed(); + } + } + }; + getOnBackPressedDispatcher().addCallback(this, callback); + mToolbar = findViewById(R.id.toolbar_main); setSupportActionBar(mToolbar); diff --git a/WordPress/src/main/java/org/wordpress/android/ui/people/PeopleManagementActivity.java b/WordPress/src/main/java/org/wordpress/android/ui/people/PeopleManagementActivity.java index d2f8289cde61..c6aea4da301e 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/people/PeopleManagementActivity.java +++ b/WordPress/src/main/java/org/wordpress/android/ui/people/PeopleManagementActivity.java @@ -4,6 +4,7 @@ import android.os.Bundle; import android.view.MenuItem; +import androidx.activity.OnBackPressedCallback; import androidx.appcompat.app.ActionBar; import androidx.appcompat.app.AlertDialog; import androidx.fragment.app.Fragment; @@ -100,6 +101,17 @@ public void onCreate(Bundle savedInstanceState) { setContentView(R.layout.people_management_activity); + OnBackPressedCallback callback = new OnBackPressedCallback(true) { + @Override + public void handleOnBackPressed() { + if (!navigateBackToPeopleListFragment()) { + setEnabled(false); + getOnBackPressedDispatcher().onBackPressed(); + } + } + }; + getOnBackPressedDispatcher().addCallback(this, callback); + if (savedInstanceState == null) { mSite = (SiteModel) getIntent().getSerializableExtra(WordPress.SITE); } else { @@ -217,13 +229,6 @@ public void onStop() { super.onStop(); } - @Override - public void onBackPressed() { - if (!navigateBackToPeopleListFragment()) { - super.onBackPressed(); - } - } - @Override public boolean onOptionsItemSelected(final MenuItem item) { if (item.getItemId() == android.R.id.home) { diff --git a/WordPress/src/main/java/org/wordpress/android/ui/plugins/PluginBrowserActivity.java b/WordPress/src/main/java/org/wordpress/android/ui/plugins/PluginBrowserActivity.java index 1cbbab6331b8..a16d381f30bf 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/plugins/PluginBrowserActivity.java +++ b/WordPress/src/main/java/org/wordpress/android/ui/plugins/PluginBrowserActivity.java @@ -11,6 +11,7 @@ import android.widget.RatingBar; import android.widget.TextView; +import androidx.activity.OnBackPressedCallback; import androidx.annotation.ColorRes; import androidx.annotation.DrawableRes; import androidx.annotation.NonNull; @@ -40,13 +41,13 @@ import org.wordpress.android.ui.LocaleAwareActivity; import org.wordpress.android.util.ActivityUtils; import org.wordpress.android.util.AniUtils; -import org.wordpress.android.util.extensions.AppBarLayoutExtensionsKt; import org.wordpress.android.util.ColorUtils; -import org.wordpress.android.util.extensions.ContextExtensionsKt; import org.wordpress.android.util.NetworkUtils; import org.wordpress.android.util.StringUtils; import org.wordpress.android.util.ToastUtils; import org.wordpress.android.util.analytics.AnalyticsUtils; +import org.wordpress.android.util.extensions.AppBarLayoutExtensionsKt; +import org.wordpress.android.util.extensions.ContextExtensionsKt; import org.wordpress.android.util.image.ImageManager; import org.wordpress.android.util.image.ImageType; import org.wordpress.android.viewmodel.plugins.PluginBrowserViewModel; @@ -80,6 +81,19 @@ public void onCreate(Bundle savedInstanceState) { ((WordPress) getApplication()).component().inject(this); setContentView(R.layout.plugin_browser_activity); + OnBackPressedCallback callback = new OnBackPressedCallback(true) { + @Override + public void handleOnBackPressed() { + if (getSupportFragmentManager().getBackStackEntryCount() > 0) { + // update the lift on scroll target id when we return to the root fragment + AppBarLayoutExtensionsKt.setLiftOnScrollTargetViewIdAndRequestLayout(mAppBar, R.id.scroll_view); + } + setEnabled(false); + getOnBackPressedDispatcher().onBackPressed(); + } + }; + getOnBackPressedDispatcher().addCallback(this, callback); + mViewModel = new ViewModelProvider(this, mViewModelFactory).get(PluginBrowserViewModel.class); mSitePluginsRecycler = findViewById(R.id.installed_plugins_recycler); @@ -231,15 +245,6 @@ public boolean onOptionsItemSelected(final MenuItem item) { return super.onOptionsItemSelected(item); } - @Override - public void onBackPressed() { - if (getSupportFragmentManager().getBackStackEntryCount() > 0) { - // update the lift on scroll target id when we return to the root fragment - AppBarLayoutExtensionsKt.setLiftOnScrollTargetViewIdAndRequestLayout(mAppBar, R.id.scroll_view); - } - super.onBackPressed(); - } - private void reloadPluginAdapterAndVisibility(@NonNull PluginListType pluginType, @Nullable ListState listState) { if (listState == null) { diff --git a/WordPress/src/main/java/org/wordpress/android/ui/posts/EditPostActivity.java b/WordPress/src/main/java/org/wordpress/android/ui/posts/EditPostActivity.java index 327aa55dda41..d2f5199073fe 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/posts/EditPostActivity.java +++ b/WordPress/src/main/java/org/wordpress/android/ui/posts/EditPostActivity.java @@ -18,6 +18,7 @@ import android.webkit.MimeTypeMap; import android.widget.Toast; +import androidx.activity.OnBackPressedCallback; import androidx.annotation.NonNull; import androidx.annotation.Nullable; import androidx.annotation.StringRes; @@ -524,6 +525,15 @@ private void createPostEditorAnalyticsSessionTracker(boolean showGutenbergEditor protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); ((WordPress) getApplication()).component().inject(this); + + OnBackPressedCallback callback = new OnBackPressedCallback(true) { + @Override + public void handleOnBackPressed() { + handleBackPressed(); + } + }; + getOnBackPressedDispatcher().addCallback(this, callback); + mDispatcher.register(this); mViewModel = new ViewModelProvider(this, mViewModelFactory).get(StorePostViewModel.class); mStorageUtilsViewModel = new ViewModelProvider(this, mViewModelFactory).get(StorageUtilsViewModel.class); @@ -1968,11 +1978,6 @@ public interface OnPostUpdatedFromUIListener { void onPostUpdatedFromUI(@Nullable UpdatePostResult updatePostResult); } - @Override - public void onBackPressed() { - handleBackPressed(); - } - @Override public void onHistoryItemClicked(@NonNull Revision revision, @NonNull List revisions) { AnalyticsTracker.track(Stat.REVISIONS_DETAIL_VIEWED_FROM_LIST); diff --git a/WordPress/src/main/java/org/wordpress/android/ui/posts/JetpackSecuritySettingsActivity.kt b/WordPress/src/main/java/org/wordpress/android/ui/posts/JetpackSecuritySettingsActivity.kt index e9d911010b89..2816b22a829d 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/posts/JetpackSecuritySettingsActivity.kt +++ b/WordPress/src/main/java/org/wordpress/android/ui/posts/JetpackSecuritySettingsActivity.kt @@ -2,6 +2,7 @@ package org.wordpress.android.ui.posts import android.os.Bundle import android.view.MenuItem +import androidx.activity.addCallback import androidx.appcompat.app.AppCompatActivity import org.wordpress.android.R.string import org.wordpress.android.databinding.FragmentJetpackSecuritySettingsBinding @@ -13,6 +14,11 @@ class JetpackSecuritySettingsActivity : AppCompatActivity() { setContentView(root) setupToolbar() } + + onBackPressedDispatcher.addCallback(this) { + setResult(RESULT_OK, null) + finish() + } } private fun FragmentJetpackSecuritySettingsBinding.setupToolbar() { @@ -35,11 +41,6 @@ class JetpackSecuritySettingsActivity : AppCompatActivity() { return super.onOptionsItemSelected(item) } - override fun onBackPressed() { - setResult(RESULT_OK, null) - finish() - } - companion object { const val JETPACK_SECURITY_SETTINGS_REQUEST_CODE = 101 } diff --git a/WordPress/src/main/java/org/wordpress/android/ui/posts/PostSettingsTagsActivity.java b/WordPress/src/main/java/org/wordpress/android/ui/posts/PostSettingsTagsActivity.java index db3e82ff28a8..18521ed6b389 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/posts/PostSettingsTagsActivity.java +++ b/WordPress/src/main/java/org/wordpress/android/ui/posts/PostSettingsTagsActivity.java @@ -4,6 +4,7 @@ import android.os.Bundle; import android.view.MenuItem; +import androidx.activity.OnBackPressedCallback; import androidx.annotation.NonNull; import androidx.appcompat.app.ActionBar; import androidx.appcompat.widget.Toolbar; @@ -25,6 +26,16 @@ public class PostSettingsTagsActivity extends LocaleAwareActivity implements Tag public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); + OnBackPressedCallback callback = new OnBackPressedCallback(true) { + @Override + public void handleOnBackPressed() { + saveAndFinish(); + setEnabled(false); + getOnBackPressedDispatcher().onBackPressed(); + } + }; + getOnBackPressedDispatcher().addCallback(this, callback); + if (savedInstanceState == null) { mSite = (SiteModel) getIntent().getSerializableExtra(WordPress.SITE); mTags = getIntent().getStringExtra(KEY_TAGS); @@ -77,12 +88,6 @@ public boolean onOptionsItemSelected(final MenuItem item) { return super.onOptionsItemSelected(item); } - @Override - public void onBackPressed() { - saveAndFinish(); - super.onBackPressed(); - } - private void saveAndFinish() { closeKeyboard(); diff --git a/WordPress/src/main/java/org/wordpress/android/ui/posts/SelectCategoriesActivity.java b/WordPress/src/main/java/org/wordpress/android/ui/posts/SelectCategoriesActivity.java index f71f0af6dcaf..a9e6e4677a08 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/posts/SelectCategoriesActivity.java +++ b/WordPress/src/main/java/org/wordpress/android/ui/posts/SelectCategoriesActivity.java @@ -10,6 +10,7 @@ import android.widget.ListView; import android.widget.TextView; +import androidx.activity.OnBackPressedCallback; import androidx.appcompat.app.ActionBar; import androidx.appcompat.widget.Toolbar; import androidx.fragment.app.Fragment; @@ -69,6 +70,17 @@ public class SelectCategoriesActivity extends LocaleAwareActivity { public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); ((WordPress) getApplication()).component().inject(this); + + OnBackPressedCallback callback = new OnBackPressedCallback(true) { + @Override + public void handleOnBackPressed() { + saveAndFinish(); + setEnabled(false); + getOnBackPressedDispatcher().onBackPressed(); + } + }; + getOnBackPressedDispatcher().addCallback(this, callback); + mDispatcher.register(this); if (savedInstanceState == null) { @@ -237,12 +249,6 @@ private void refreshCategories() { mDispatcher.dispatch(TaxonomyActionBuilder.newFetchCategoriesAction(mSite)); } - @Override - public void onBackPressed() { - saveAndFinish(); - super.onBackPressed(); - } - private void updateSelectedCategoryList() { SparseBooleanArray selectedItems = mListView.getCheckedItemPositions(); for (int i = 0; i < selectedItems.size(); i++) { diff --git a/WordPress/src/main/java/org/wordpress/android/ui/prefs/SiteSettingsTagListActivity.java b/WordPress/src/main/java/org/wordpress/android/ui/prefs/SiteSettingsTagListActivity.java index 29e9751c914f..c667cb1319b8 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/prefs/SiteSettingsTagListActivity.java +++ b/WordPress/src/main/java/org/wordpress/android/ui/prefs/SiteSettingsTagListActivity.java @@ -16,6 +16,7 @@ import android.widget.TextView; import android.widget.Toast; +import androidx.activity.OnBackPressedCallback; import androidx.annotation.NonNull; import androidx.annotation.Nullable; import androidx.annotation.StringRes; @@ -98,6 +99,25 @@ public void onCreate(Bundle savedInstanceState) { setContentView(R.layout.site_settings_tag_list_activity); + OnBackPressedCallback callback = new OnBackPressedCallback(true) { + @Override + public void handleOnBackPressed() { + if (getFragmentManager().getBackStackEntryCount() > 0) { + SiteSettingsTagDetailFragment fragment = getDetailFragment(); + if (fragment != null && fragment.hasChanges()) { + saveTag(fragment.getTerm(), fragment.isNewTerm()); + } else { + hideDetailFragment(); + loadTags(); + } + } else { + setEnabled(false); + getOnBackPressedDispatcher().onBackPressed(); + } + } + }; + getOnBackPressedDispatcher().addCallback(this, callback); + Toolbar toolbar = findViewById(R.id.toolbar_main); setSupportActionBar(toolbar); @@ -224,21 +244,6 @@ public boolean onOptionsItemSelected(final MenuItem item) { } } - @Override - public void onBackPressed() { - if (getFragmentManager().getBackStackEntryCount() > 0) { - SiteSettingsTagDetailFragment fragment = getDetailFragment(); - if (fragment != null && fragment.hasChanges()) { - saveTag(fragment.getTerm(), fragment.isNewTerm()); - } else { - hideDetailFragment(); - loadTags(); - } - } else { - super.onBackPressed(); - } - } - private void showFabIfHidden() { // redisplay hidden fab after a short delay long delayMs = getResources().getInteger(R.integer.fab_animation_delay); diff --git a/WordPress/src/main/java/org/wordpress/android/ui/publicize/PublicizeListActivity.java b/WordPress/src/main/java/org/wordpress/android/ui/publicize/PublicizeListActivity.java index 0161ef713021..aeaea943d077 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/publicize/PublicizeListActivity.java +++ b/WordPress/src/main/java/org/wordpress/android/ui/publicize/PublicizeListActivity.java @@ -4,6 +4,7 @@ import android.os.Bundle; import android.view.MenuItem; +import androidx.activity.OnBackPressedCallback; import androidx.appcompat.app.ActionBar; import androidx.appcompat.app.AlertDialog; import androidx.appcompat.widget.Toolbar; @@ -67,6 +68,19 @@ public void onCreate(Bundle savedInstanceState) { setContentView(R.layout.publicize_list_activity); + OnBackPressedCallback callback = new OnBackPressedCallback(true) { + @Override + public void handleOnBackPressed() { + if (getSupportFragmentManager().getBackStackEntryCount() > 0) { + getSupportFragmentManager().popBackStack(); + } else { + setEnabled(false); + getOnBackPressedDispatcher().onBackPressed(); + } + } + }; + getOnBackPressedDispatcher().addCallback(this, callback); + Toolbar toolbar = findViewById(R.id.toolbar_main); setSupportActionBar(toolbar); @@ -215,15 +229,6 @@ public boolean onOptionsItemSelected(final MenuItem item) { return super.onOptionsItemSelected(item); } - @Override - public void onBackPressed() { - if (getSupportFragmentManager().getBackStackEntryCount() > 0) { - getSupportFragmentManager().popBackStack(); - } else { - super.onBackPressed(); - } - } - /* * user tapped a service in the list fragment */ diff --git a/WordPress/src/main/java/org/wordpress/android/ui/reader/ReaderCommentListActivity.java b/WordPress/src/main/java/org/wordpress/android/ui/reader/ReaderCommentListActivity.java index 754090bed0eb..5228444ceed3 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/reader/ReaderCommentListActivity.java +++ b/WordPress/src/main/java/org/wordpress/android/ui/reader/ReaderCommentListActivity.java @@ -18,6 +18,7 @@ import android.widget.TextView; import android.widget.Toast; +import androidx.activity.OnBackPressedCallback; import androidx.annotation.NonNull; import androidx.annotation.Nullable; import androidx.appcompat.app.ActionBar; @@ -86,10 +87,10 @@ import org.wordpress.android.util.EditTextUtils; import org.wordpress.android.util.NetworkUtils; import org.wordpress.android.util.ToastUtils; -import org.wordpress.android.util.extensions.ViewExtensionsKt; import org.wordpress.android.util.WPActivityUtils; import org.wordpress.android.util.analytics.AnalyticsUtils; import org.wordpress.android.util.analytics.AnalyticsUtils.AnalyticsCommentActionSource; +import org.wordpress.android.util.extensions.ViewExtensionsKt; import org.wordpress.android.util.helpers.SwipeToRefreshHelper; import org.wordpress.android.widgets.RecyclerItemDecoration; import org.wordpress.android.widgets.SuggestionAutoCompleteText; @@ -150,24 +151,28 @@ public class ReaderCommentListActivity extends LocaleAwareActivity implements On private ReaderCommentListViewModel mViewModel; private ConversationNotificationsViewModel mConversationViewModel; - @Override - public void onBackPressed() { - CollapseFullScreenDialogFragment fragment = (CollapseFullScreenDialogFragment) - getSupportFragmentManager().findFragmentByTag(CollapseFullScreenDialogFragment.TAG); - - if (fragment != null) { - fragment.onBackPressed(); - } else { - super.onBackPressed(); - } - } - @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); ((WordPress) getApplication()).component().inject(this); setContentView(R.layout.reader_activity_comment_list); + OnBackPressedCallback callback = new OnBackPressedCallback(true) { + @Override + public void handleOnBackPressed() { + CollapseFullScreenDialogFragment fragment = (CollapseFullScreenDialogFragment) + getSupportFragmentManager().findFragmentByTag(CollapseFullScreenDialogFragment.TAG); + + if (fragment != null) { + fragment.onBackPressed(); + } else { + setEnabled(false); + getOnBackPressedDispatcher().onBackPressed(); + } + } + }; + getOnBackPressedDispatcher().addCallback(this, callback); + Toolbar toolbar = findViewById(R.id.toolbar_main); setSupportActionBar(toolbar); diff --git a/WordPress/src/main/java/org/wordpress/android/ui/reader/ReaderPostListActivity.java b/WordPress/src/main/java/org/wordpress/android/ui/reader/ReaderPostListActivity.java index d4c6c023c8b7..ae8b4c046442 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/reader/ReaderPostListActivity.java +++ b/WordPress/src/main/java/org/wordpress/android/ui/reader/ReaderPostListActivity.java @@ -8,6 +8,7 @@ import android.view.MenuItem; import android.view.View; +import androidx.activity.OnBackPressedCallback; import androidx.annotation.NonNull; import androidx.appcompat.app.ActionBar; import androidx.appcompat.widget.Toolbar; @@ -67,6 +68,18 @@ public void onCreate(Bundle savedInstanceState) { setContentView(R.layout.reader_activity_post_list); + OnBackPressedCallback callback = new OnBackPressedCallback(true) { + @Override + public void handleOnBackPressed() { + ReaderPostListFragment fragment = getListFragment(); + if (fragment == null || !fragment.onActivityBackPressed()) { + setEnabled(false); + getOnBackPressedDispatcher().onBackPressed(); + } + } + }; + getOnBackPressedDispatcher().addCallback(this, callback); + Toolbar toolbar = findViewById(R.id.toolbar_main); setSupportActionBar(toolbar); ActionBar actionBar = getSupportActionBar(); @@ -188,14 +201,6 @@ public void onSaveInstanceState(@NonNull Bundle outState) { super.onSaveInstanceState(outState); } - @Override - public void onBackPressed() { - ReaderPostListFragment fragment = getListFragment(); - if (fragment == null || !fragment.onActivityBackPressed()) { - super.onBackPressed(); - } - } - @Override public boolean onCreateOptionsMenu(Menu menu) { if (getPostListType() == ReaderPostListType.BLOG_PREVIEW) { diff --git a/WordPress/src/main/java/org/wordpress/android/ui/reader/ReaderPostPagerActivity.java b/WordPress/src/main/java/org/wordpress/android/ui/reader/ReaderPostPagerActivity.java index 4b0d69038fc5..c5b6c67c66aa 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/reader/ReaderPostPagerActivity.java +++ b/WordPress/src/main/java/org/wordpress/android/ui/reader/ReaderPostPagerActivity.java @@ -13,6 +13,7 @@ import android.view.ViewGroup; import android.widget.ProgressBar; +import androidx.activity.OnBackPressedCallback; import androidx.annotation.NonNull; import androidx.fragment.app.Fragment; import androidx.fragment.app.FragmentManager; @@ -177,6 +178,25 @@ public void onCreate(Bundle savedInstanceState) { setContentView(R.layout.reader_activity_post_pager); + OnBackPressedCallback callback = new OnBackPressedCallback(true) { + @Override + public void handleOnBackPressed() { + ReaderPostDetailFragment fragment = getActiveDetailFragment(); + if (fragment != null && fragment.isCustomViewShowing()) { + // if full screen video is showing, hide the custom view rather than navigate back + fragment.hideCustomView(); + } else { + if (fragment != null && fragment.goBackInPostHistory()) { + // noop - fragment moved back to a previous post + } else { + setEnabled(false); + getOnBackPressedDispatcher().onBackPressed(); + } + } + } + }; + getOnBackPressedDispatcher().addCallback(this, callback); + // Start migration flow passing deep link data if requirements are met if (mJetpackAppMigrationFlowUtils.shouldShowMigrationFlow()) { PreMigrationDeepLinkData deepLinkData = new PreMigrationDeepLinkData( @@ -693,21 +713,6 @@ private ReaderBlogIdPostId getAdapterBlogIdPostIdAtPosition(int position) { return adapter.getBlogIdPostIdAtPosition(position); } - @Override - public void onBackPressed() { - ReaderPostDetailFragment fragment = getActiveDetailFragment(); - if (fragment != null && fragment.isCustomViewShowing()) { - // if full screen video is showing, hide the custom view rather than navigate back - fragment.hideCustomView(); - } else { - if (fragment != null && fragment.goBackInPostHistory()) { - // noop - fragment moved back to a previous post - } else { - super.onBackPressed(); - } - } - } - /* * perform analytics tracking and bump the page view for the post at the passed position * if it hasn't already been done diff --git a/WordPress/src/main/java/org/wordpress/android/ui/reader/ReaderSubsActivity.java b/WordPress/src/main/java/org/wordpress/android/ui/reader/ReaderSubsActivity.java index e2d36209592a..3fc75974f8d5 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/reader/ReaderSubsActivity.java +++ b/WordPress/src/main/java/org/wordpress/android/ui/reader/ReaderSubsActivity.java @@ -10,6 +10,7 @@ import android.widget.EditText; import android.widget.ProgressBar; +import androidx.activity.OnBackPressedCallback; import androidx.annotation.NonNull; import androidx.annotation.Nullable; import androidx.appcompat.app.ActionBar; @@ -93,6 +94,19 @@ protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); ((WordPress) getApplication()).component().inject(this); + OnBackPressedCallback callback = new OnBackPressedCallback(true) { + @Override + public void handleOnBackPressed() { + if (!TextUtils.isEmpty(mLastAddedTagName)) { + EventBus.getDefault().postSticky(new ReaderEvents.TagAdded(mLastAddedTagName)); + } + mReaderTracker.track(Stat.READER_MANAGE_VIEW_DISMISSED); + setEnabled(false); + getOnBackPressedDispatcher().onBackPressed(); + } + }; + getOnBackPressedDispatcher().addCallback(this, callback); + setContentView(R.layout.reader_activity_subs); restoreState(savedInstanceState); @@ -236,15 +250,6 @@ public void onSaveInstanceState(@NonNull Bundle outState) { super.onSaveInstanceState(outState); } - @Override - public void onBackPressed() { - if (!TextUtils.isEmpty(mLastAddedTagName)) { - EventBus.getDefault().postSticky(new ReaderEvents.TagAdded(mLastAddedTagName)); - } - mReaderTracker.track(Stat.READER_MANAGE_VIEW_DISMISSED); - super.onBackPressed(); - } - /* * follow the tag or url the user typed into the EditText */ diff --git a/WordPress/src/main/java/org/wordpress/android/ui/sitecreation/SiteCreationActivity.kt b/WordPress/src/main/java/org/wordpress/android/ui/sitecreation/SiteCreationActivity.kt index a069aaff7cfa..70c141624f4c 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/sitecreation/SiteCreationActivity.kt +++ b/WordPress/src/main/java/org/wordpress/android/ui/sitecreation/SiteCreationActivity.kt @@ -4,6 +4,7 @@ import android.app.Activity import android.content.Intent import android.os.Bundle import android.view.MenuItem +import androidx.activity.addCallback import androidx.activity.viewModels import androidx.fragment.app.Fragment import androidx.lifecycle.Observer @@ -82,6 +83,9 @@ class SiteCreationActivity : LocaleAwareActivity(), override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) setContentView(R.layout.site_creation_activity) + + onBackPressedDispatcher.addCallback(this) { mainViewModel.onBackPressed() } + mainViewModel.start(savedInstanceState, getSiteCreationSource()) mainViewModel.preloadThumbnails(this) @@ -280,10 +284,6 @@ class SiteCreationActivity : LocaleAwareActivity(), return false } - override fun onBackPressed() { - mainViewModel.onBackPressed() - } - companion object { const val ARG_CREATE_SITE_SOURCE = "ARG_CREATE_SITE_SOURCE" } diff --git a/WordPress/src/main/java/org/wordpress/android/ui/suggestion/SuggestionActivity.kt b/WordPress/src/main/java/org/wordpress/android/ui/suggestion/SuggestionActivity.kt index b39947890415..ed8d3bdfd391 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/suggestion/SuggestionActivity.kt +++ b/WordPress/src/main/java/org/wordpress/android/ui/suggestion/SuggestionActivity.kt @@ -9,6 +9,7 @@ import android.text.Editable import android.text.TextWatcher import android.view.KeyEvent import android.view.inputmethod.EditorInfo +import androidx.activity.addCallback import org.greenrobot.eventbus.EventBus import org.greenrobot.eventbus.Subscribe import org.wordpress.android.R @@ -42,6 +43,8 @@ class SuggestionActivity : LocaleAwareActivity() { binding = this } + onBackPressedDispatcher.addCallback(this) { viewModel.trackExit(false) } + val siteModel = intent.getSerializableExtra(INTENT_KEY_SITE_MODEL) as? SiteModel val suggestionType = intent.getSerializableExtra(INTENT_KEY_SUGGESTION_TYPE) as? SuggestionType when { @@ -57,11 +60,6 @@ class SuggestionActivity : LocaleAwareActivity() { finish() } - override fun onBackPressed() { - viewModel.trackExit(false) - super.onBackPressed() - } - private fun initializeActivity(siteModel: SiteModel, suggestionType: SuggestionType) { siteId = siteModel.siteId viewModel.init(suggestionType, siteModel).let { supportsSuggestions -> diff --git a/WordPress/src/main/java/org/wordpress/android/ui/themes/ThemeBrowserActivity.java b/WordPress/src/main/java/org/wordpress/android/ui/themes/ThemeBrowserActivity.java index d27dac19701d..0a309ce3a12c 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/themes/ThemeBrowserActivity.java +++ b/WordPress/src/main/java/org/wordpress/android/ui/themes/ThemeBrowserActivity.java @@ -8,6 +8,7 @@ import android.view.View.OnScrollChangeListener; import android.widget.TextView; +import androidx.activity.OnBackPressedCallback; import androidx.annotation.NonNull; import androidx.appcompat.app.ActionBar; import androidx.appcompat.app.AlertDialog; @@ -93,6 +94,20 @@ public void onCreate(Bundle savedInstanceState) { setContentView(R.layout.theme_browser_activity); + OnBackPressedCallback callback = new OnBackPressedCallback(true) { + @Override + public void handleOnBackPressed() { + FragmentManager fm = getSupportFragmentManager(); + if (fm.getBackStackEntryCount() > 0) { + fm.popBackStack(); + } else { + setEnabled(false); + getOnBackPressedDispatcher().onBackPressed(); + } + } + }; + getOnBackPressedDispatcher().addCallback(this, callback); + if (savedInstanceState == null) { addBrowserFragment(); fetchInstalledThemesIfJetpackSite(); @@ -136,16 +151,6 @@ public boolean onOptionsItemSelected(MenuItem item) { return super.onOptionsItemSelected(item); } - @Override - public void onBackPressed() { - FragmentManager fm = getSupportFragmentManager(); - if (fm.getBackStackEntryCount() > 0) { - fm.popBackStack(); - } else { - super.onBackPressed(); - } - } - @Override protected void onActivityResult(int requestCode, int resultCode, Intent data) { super.onActivityResult(requestCode, resultCode, data); diff --git a/libs/image-editor/src/main/kotlin/org/wordpress/android/imageeditor/EditImageActivity.kt b/libs/image-editor/src/main/kotlin/org/wordpress/android/imageeditor/EditImageActivity.kt index 4ad84dba4ca9..ae411866b315 100644 --- a/libs/image-editor/src/main/kotlin/org/wordpress/android/imageeditor/EditImageActivity.kt +++ b/libs/image-editor/src/main/kotlin/org/wordpress/android/imageeditor/EditImageActivity.kt @@ -1,6 +1,7 @@ package org.wordpress.android.imageeditor import android.os.Bundle +import androidx.activity.addCallback import androidx.appcompat.app.AppCompatActivity import androidx.appcompat.widget.Toolbar import androidx.lifecycle.ViewModelProvider @@ -25,6 +26,14 @@ class EditImageActivity : AppCompatActivity() { viewModel = ViewModelProvider(this).get(EditImageViewModel::class.java) setContentView(R.layout.activity_edit_image) + onBackPressedDispatcher.addCallback(this) { + isEnabled = false + onBackPressedDispatcher.onBackPressed() + if (hostFragment.childFragmentManager.backStackEntryCount == 0) { + ImageEditor.instance.onEditorAction(EditorCancelled) + } + } + hostFragment = supportFragmentManager .findFragmentById(R.id.nav_host_fragment) as NavHostFragment? ?: throw (NullPointerException("Host fragment is null inside ${this::class.java.simpleName} onCreate.")) @@ -59,11 +68,4 @@ class EditImageActivity : AppCompatActivity() { navController.navigateUp(appBarConfiguration) || super.onSupportNavigateUp() } } - - override fun onBackPressed() { - super.onBackPressed() - if (hostFragment.childFragmentManager.backStackEntryCount == 0) { - ImageEditor.instance.onEditorAction(EditorCancelled) - } - } } From bf693ec6077d0a708982a158e9361fc4ad125df7 Mon Sep 17 00:00:00 2001 From: Irfan Omur Date: Tue, 28 Feb 2023 01:02:20 +0300 Subject: [PATCH 014/856] Migrate dialogs to OnBackPressedCallback --- .../android/ui/CollapseFullScreenDialogFragment.java | 8 ++++++-- .../android/ui/FullScreenDialogFragment.java | 8 ++++++-- .../FeatureIntroductionDialogFragment.kt | 10 ++++++---- ...etpackFullPluginInstallOnboardingDialogFragment.kt | 11 +++++++---- 4 files changed, 25 insertions(+), 12 deletions(-) diff --git a/WordPress/src/main/java/org/wordpress/android/ui/CollapseFullScreenDialogFragment.java b/WordPress/src/main/java/org/wordpress/android/ui/CollapseFullScreenDialogFragment.java index 808cacf81de9..4379f114d01f 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/CollapseFullScreenDialogFragment.java +++ b/WordPress/src/main/java/org/wordpress/android/ui/CollapseFullScreenDialogFragment.java @@ -14,6 +14,8 @@ import android.view.ViewGroup; import android.view.Window; +import androidx.activity.ComponentDialog; +import androidx.activity.OnBackPressedCallback; import androidx.annotation.NonNull; import androidx.annotation.Nullable; import androidx.annotation.StringRes; @@ -146,12 +148,14 @@ public void setConfirmEnabled(boolean enabled) { public Dialog onCreateDialog(Bundle savedInstanceState) { initBuilderArguments(); - Dialog dialog = new Dialog(requireContext(), getTheme()) { + Dialog dialog = super.onCreateDialog(savedInstanceState); + OnBackPressedCallback callback = new OnBackPressedCallback(true) { @Override - public void onBackPressed() { + public void handleOnBackPressed() { onCollapseClicked(); } }; + ((ComponentDialog) dialog).getOnBackPressedDispatcher().addCallback(this, callback); dialog.requestWindowFeature(Window.FEATURE_NO_TITLE); return dialog; diff --git a/WordPress/src/main/java/org/wordpress/android/ui/FullScreenDialogFragment.java b/WordPress/src/main/java/org/wordpress/android/ui/FullScreenDialogFragment.java index b07b8084ac39..8695c369be04 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/FullScreenDialogFragment.java +++ b/WordPress/src/main/java/org/wordpress/android/ui/FullScreenDialogFragment.java @@ -14,6 +14,8 @@ import android.view.ViewGroup; import android.view.Window; +import androidx.activity.ComponentDialog; +import androidx.activity.OnBackPressedCallback; import androidx.annotation.ColorRes; import androidx.annotation.NonNull; import androidx.annotation.Nullable; @@ -166,12 +168,14 @@ public void dismiss() { public Dialog onCreateDialog(Bundle savedInstanceState) { initBuilderArguments(); - Dialog dialog = new Dialog(getActivity(), getTheme()) { + Dialog dialog = super.onCreateDialog(savedInstanceState); + OnBackPressedCallback callback = new OnBackPressedCallback(true) { @Override - public void onBackPressed() { + public void handleOnBackPressed() { onDismissClicked(); } }; + ((ComponentDialog) dialog).getOnBackPressedDispatcher().addCallback(this, callback); dialog.requestWindowFeature(Window.FEATURE_NO_TITLE); return dialog; diff --git a/WordPress/src/main/java/org/wordpress/android/ui/featureintroduction/FeatureIntroductionDialogFragment.kt b/WordPress/src/main/java/org/wordpress/android/ui/featureintroduction/FeatureIntroductionDialogFragment.kt index 2806fdf6fc22..a3f8a33e663d 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/featureintroduction/FeatureIntroductionDialogFragment.kt +++ b/WordPress/src/main/java/org/wordpress/android/ui/featureintroduction/FeatureIntroductionDialogFragment.kt @@ -5,6 +5,8 @@ import android.os.Bundle import android.view.LayoutInflater import android.view.View import android.view.ViewGroup +import androidx.activity.ComponentDialog +import androidx.activity.addCallback import androidx.annotation.DrawableRes import androidx.annotation.StringRes import androidx.fragment.app.DialogFragment @@ -31,12 +33,12 @@ abstract class FeatureIntroductionDialogFragment : DialogFragment() { } override fun onCreateDialog(savedInstanceState: Bundle?): Dialog = - object : Dialog(requireContext(), theme) { - override fun onBackPressed() { + super.onCreateDialog(savedInstanceState).apply { + (this as ComponentDialog).onBackPressedDispatcher.addCallback(this@FeatureIntroductionDialogFragment) { viewModel.onBackButtonClick() - super.onBackPressed() + isEnabled = false + onBackPressedDispatcher.onBackPressed() } - }.apply { setStatusBarAsSurfaceColor() } diff --git a/WordPress/src/main/java/org/wordpress/android/ui/jpfullplugininstall/onboarding/JetpackFullPluginInstallOnboardingDialogFragment.kt b/WordPress/src/main/java/org/wordpress/android/ui/jpfullplugininstall/onboarding/JetpackFullPluginInstallOnboardingDialogFragment.kt index 92c7a6bf6360..1a696cad4d0f 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/jpfullplugininstall/onboarding/JetpackFullPluginInstallOnboardingDialogFragment.kt +++ b/WordPress/src/main/java/org/wordpress/android/ui/jpfullplugininstall/onboarding/JetpackFullPluginInstallOnboardingDialogFragment.kt @@ -5,6 +5,8 @@ import android.os.Bundle import android.view.LayoutInflater import android.view.View import android.view.ViewGroup +import androidx.activity.ComponentDialog +import androidx.activity.addCallback import androidx.compose.runtime.Composable import androidx.compose.runtime.collectAsState import androidx.compose.runtime.getValue @@ -59,12 +61,13 @@ class JetpackFullPluginInstallOnboardingDialogFragment : DialogFragment() { } override fun onCreateDialog(savedInstanceState: Bundle?): Dialog = - object : Dialog(requireContext(), theme) { - override fun onBackPressed() { + super.onCreateDialog(savedInstanceState).apply { + val componentDialog = dialog as ComponentDialog + componentDialog.onBackPressedDispatcher.addCallback(this@JetpackFullPluginInstallOnboardingDialogFragment) { viewModel.onDismissScreenClick() - super.onBackPressed() + isEnabled = false + componentDialog.onBackPressedDispatcher.onBackPressed() } - }.apply { setStatusBarAsSurfaceColor() } From b1607f096c28756e5d7ba2f6c649af262308f31d Mon Sep 17 00:00:00 2001 From: Irfan Omur Date: Sat, 11 Feb 2023 20:20:25 +0300 Subject: [PATCH 015/856] Use extension function for OnBackPressedCallback This just makes the code shorter by using an extension function. --- .../login/jetpack/LoginNoSitesFragment.kt | 16 ++------------ .../jetpack/LoginSiteCheckErrorFragment.kt | 16 ++------------ .../unified/UnifiedCommentsEditFragment.kt | 12 ++-------- .../DomainRegistrationResultFragment.kt | 12 ++-------- .../backup/download/BackupDownloadFragment.kt | 22 ++++--------------- .../ui/jetpack/restore/RestoreFragment.kt | 20 ++--------------- .../migration/JetpackMigrationFragment.kt | 12 ++-------- .../ui/qrcodeauth/QRCodeAuthFragment.kt | 13 ++++------- .../management/InsightsManagementFragment.kt | 8 ++----- 9 files changed, 22 insertions(+), 109 deletions(-) diff --git a/WordPress/src/main/java/org/wordpress/android/ui/accounts/login/jetpack/LoginNoSitesFragment.kt b/WordPress/src/main/java/org/wordpress/android/ui/accounts/login/jetpack/LoginNoSitesFragment.kt index cc9b6983e869..2c024a02a88f 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/accounts/login/jetpack/LoginNoSitesFragment.kt +++ b/WordPress/src/main/java/org/wordpress/android/ui/accounts/login/jetpack/LoginNoSitesFragment.kt @@ -3,7 +3,7 @@ package org.wordpress.android.ui.accounts.login.jetpack import android.content.Context import android.os.Bundle import android.view.View -import androidx.activity.OnBackPressedCallback +import androidx.activity.addCallback import androidx.fragment.app.Fragment import androidx.fragment.app.viewModels import dagger.hilt.android.AndroidEntryPoint @@ -42,7 +42,7 @@ class LoginNoSitesFragment : Fragment(R.layout.jetpack_login_empty_view) { override fun onViewCreated(view: View, savedInstanceState: Bundle?) { super.onViewCreated(view, savedInstanceState) - initBackPressHandler() + requireActivity().onBackPressedDispatcher.addCallback(this) { viewModel.onBackPressed() } with(JetpackLoginEmptyViewBinding.bind(view)) { initContentViews() initClickListeners() @@ -141,16 +141,4 @@ class LoginNoSitesFragment : Fragment(R.layout.jetpack_login_empty_view) { super.onResume() viewModel.onFragmentResume() } - - private fun initBackPressHandler() { - requireActivity().onBackPressedDispatcher.addCallback( - viewLifecycleOwner, - object : OnBackPressedCallback( - true - ) { - override fun handleOnBackPressed() { - viewModel.onBackPressed() - } - }) - } } diff --git a/WordPress/src/main/java/org/wordpress/android/ui/accounts/login/jetpack/LoginSiteCheckErrorFragment.kt b/WordPress/src/main/java/org/wordpress/android/ui/accounts/login/jetpack/LoginSiteCheckErrorFragment.kt index 8e78cdb78f0d..81646d32dd90 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/accounts/login/jetpack/LoginSiteCheckErrorFragment.kt +++ b/WordPress/src/main/java/org/wordpress/android/ui/accounts/login/jetpack/LoginSiteCheckErrorFragment.kt @@ -3,7 +3,7 @@ package org.wordpress.android.ui.accounts.login.jetpack import android.content.Context import android.os.Bundle import android.view.View -import androidx.activity.OnBackPressedCallback +import androidx.activity.addCallback import androidx.fragment.app.Fragment import androidx.fragment.app.viewModels import dagger.hilt.android.AndroidEntryPoint @@ -54,7 +54,7 @@ class LoginSiteCheckErrorFragment : Fragment(R.layout.jetpack_login_empty_view) override fun onViewCreated(view: View, savedInstanceState: Bundle?) { super.onViewCreated(view, savedInstanceState) - initBackPressHandler() + requireActivity().onBackPressedDispatcher.addCallback(this) { viewModel.onBackPressed() } with(JetpackLoginEmptyViewBinding.bind(view)) { ActivityUtils.hideKeyboardForced(view) initErrorMessageView() @@ -113,16 +113,4 @@ class LoginSiteCheckErrorFragment : Fragment(R.layout.jetpack_login_empty_view) unifiedLoginTracker.track(step = Step.NOT_A_JETPACK_SITE) } - - private fun initBackPressHandler() { - requireActivity().onBackPressedDispatcher.addCallback( - viewLifecycleOwner, - object : OnBackPressedCallback( - true - ) { - override fun handleOnBackPressed() { - viewModel.onBackPressed() - } - }) - } } diff --git a/WordPress/src/main/java/org/wordpress/android/ui/comments/unified/UnifiedCommentsEditFragment.kt b/WordPress/src/main/java/org/wordpress/android/ui/comments/unified/UnifiedCommentsEditFragment.kt index 704f3c1d03b1..420febb10266 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/comments/unified/UnifiedCommentsEditFragment.kt +++ b/WordPress/src/main/java/org/wordpress/android/ui/comments/unified/UnifiedCommentsEditFragment.kt @@ -6,7 +6,7 @@ import android.view.Menu import android.view.MenuInflater import android.view.MenuItem import android.view.View -import androidx.activity.OnBackPressedCallback +import androidx.activity.addCallback import androidx.appcompat.app.AppCompatActivity import androidx.core.view.MenuProvider import androidx.core.widget.doAfterTextChanged @@ -82,15 +82,7 @@ class UnifiedCommentsEditFragment : Fragment(R.layout.unified_comments_edit_frag it.setDisplayHomeAsUpEnabled(true) it.setHomeAsUpIndicator(R.drawable.ic_cross_white_24dp) } - activity.onBackPressedDispatcher.addCallback( - viewLifecycleOwner, - object : OnBackPressedCallback( - true - ) { - override fun handleOnBackPressed() { - viewModel.onBackPressed() - } - }) + activity.onBackPressedDispatcher.addCallback(this@UnifiedCommentsEditFragment) { viewModel.onBackPressed() } } private fun hideKeyboard() { diff --git a/WordPress/src/main/java/org/wordpress/android/ui/domains/DomainRegistrationResultFragment.kt b/WordPress/src/main/java/org/wordpress/android/ui/domains/DomainRegistrationResultFragment.kt index b0691a90e18d..68f8fa0d1ae1 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/domains/DomainRegistrationResultFragment.kt +++ b/WordPress/src/main/java/org/wordpress/android/ui/domains/DomainRegistrationResultFragment.kt @@ -2,7 +2,7 @@ package org.wordpress.android.ui.domains import android.os.Bundle import android.view.View -import androidx.activity.OnBackPressedCallback +import androidx.activity.addCallback import androidx.appcompat.app.AppCompatActivity import androidx.core.text.HtmlCompat.FROM_HTML_MODE_COMPACT import androidx.core.text.parseAsHtml @@ -49,8 +49,8 @@ class DomainRegistrationResultFragment : Fragment(R.layout.domain_registration_r with(DomainRegistrationResultFragmentBinding.bind(view)) { setupViews(domainName, email) - setupObservers(domainName, email) } + requireActivity().onBackPressedDispatcher.addCallback(this) { finishRegistration(domainName, email) } } private fun setupWindow() = with(requireAppCompatActivity()) { @@ -78,14 +78,6 @@ class DomainRegistrationResultFragment : Fragment(R.layout.domain_registration_r ).parseAsHtml(FROM_HTML_MODE_COMPACT) } - private fun setupObservers(domainName: String, email: String) = with(requireActivity()) { - onBackPressedDispatcher.addCallback(viewLifecycleOwner, object : OnBackPressedCallback(true) { - override fun handleOnBackPressed() { - finishRegistration(domainName, email) - } - }) - } - private fun finishRegistration(domainName: String, email: String) { mainViewModel.finishDomainRegistration(DomainRegistrationCompletedEvent(domainName, email)) } diff --git a/WordPress/src/main/java/org/wordpress/android/ui/jetpack/backup/download/BackupDownloadFragment.kt b/WordPress/src/main/java/org/wordpress/android/ui/jetpack/backup/download/BackupDownloadFragment.kt index fafe0b4f4249..a657dabf573f 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/jetpack/backup/download/BackupDownloadFragment.kt +++ b/WordPress/src/main/java/org/wordpress/android/ui/jetpack/backup/download/BackupDownloadFragment.kt @@ -5,7 +5,7 @@ import android.app.Activity.RESULT_OK import android.content.Intent import android.os.Bundle import android.view.View -import androidx.activity.OnBackPressedCallback +import androidx.activity.addCallback import androidx.appcompat.app.AppCompatActivity import androidx.fragment.app.Fragment import androidx.lifecycle.ViewModelProvider @@ -51,7 +51,9 @@ class BackupDownloadFragment : Fragment(R.layout.jetpack_backup_restore_fragment super.onViewCreated(view, savedInstanceState) with(JetpackBackupRestoreFragmentBinding.bind(view)) { initDagger() - initBackPressHandler() + requireActivity().onBackPressedDispatcher.addCallback(this@BackupDownloadFragment) { + viewModel.onBackPressed() + } initAdapter() initViewModel(savedInstanceState) } @@ -61,22 +63,6 @@ class BackupDownloadFragment : Fragment(R.layout.jetpack_backup_restore_fragment (requireActivity().application as WordPress).component().inject(this) } - private fun initBackPressHandler() { - requireActivity().onBackPressedDispatcher.addCallback( - viewLifecycleOwner, - object : OnBackPressedCallback( - true - ) { - override fun handleOnBackPressed() { - onBackPressed() - } - }) - } - - private fun onBackPressed() { - viewModel.onBackPressed() - } - private fun JetpackBackupRestoreFragmentBinding.initAdapter() { recyclerView.adapter = JetpackBackupRestoreAdapter(imageManager, uiHelpers) recyclerView.itemAnimator = null diff --git a/WordPress/src/main/java/org/wordpress/android/ui/jetpack/restore/RestoreFragment.kt b/WordPress/src/main/java/org/wordpress/android/ui/jetpack/restore/RestoreFragment.kt index 49f05461e035..9d86d8b074b4 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/jetpack/restore/RestoreFragment.kt +++ b/WordPress/src/main/java/org/wordpress/android/ui/jetpack/restore/RestoreFragment.kt @@ -5,7 +5,7 @@ import android.app.Activity.RESULT_OK import android.content.Intent import android.os.Bundle import android.view.View -import androidx.activity.OnBackPressedCallback +import androidx.activity.addCallback import androidx.appcompat.app.AppCompatActivity import androidx.fragment.app.Fragment import androidx.lifecycle.ViewModelProvider @@ -50,7 +50,7 @@ class RestoreFragment : Fragment(R.layout.jetpack_backup_restore_fragment) { super.onViewCreated(view, savedInstanceState) with(JetpackBackupRestoreFragmentBinding.bind(view)) { initDagger() - initBackPressHandler() + requireActivity().onBackPressedDispatcher.addCallback(this@RestoreFragment) { viewModel.onBackPressed() } initAdapter() initViewModel(savedInstanceState) } @@ -60,22 +60,6 @@ class RestoreFragment : Fragment(R.layout.jetpack_backup_restore_fragment) { (requireActivity().application as WordPress).component().inject(this) } - private fun initBackPressHandler() { - requireActivity().onBackPressedDispatcher.addCallback( - viewLifecycleOwner, - object : OnBackPressedCallback( - true - ) { - override fun handleOnBackPressed() { - onBackPressed() - } - }) - } - - private fun onBackPressed() { - viewModel.onBackPressed() - } - private fun JetpackBackupRestoreFragmentBinding.initAdapter() { recyclerView.adapter = JetpackBackupRestoreAdapter(imageManager, uiHelpers) recyclerView.itemAnimator = null diff --git a/WordPress/src/main/java/org/wordpress/android/ui/main/jetpack/migration/JetpackMigrationFragment.kt b/WordPress/src/main/java/org/wordpress/android/ui/main/jetpack/migration/JetpackMigrationFragment.kt index 701179832f2e..25e43df28d34 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/main/jetpack/migration/JetpackMigrationFragment.kt +++ b/WordPress/src/main/java/org/wordpress/android/ui/main/jetpack/migration/JetpackMigrationFragment.kt @@ -4,7 +4,7 @@ import android.os.Bundle import android.view.LayoutInflater import android.view.View import android.view.ViewGroup -import androidx.activity.OnBackPressedCallback +import androidx.activity.addCallback import androidx.compose.animation.Crossfade import androidx.compose.foundation.layout.Box import androidx.compose.runtime.Composable @@ -127,15 +127,7 @@ class JetpackMigrationFragment : Fragment() { private fun initBackPressHandler(showDeleteWpState: Boolean) { if (showDeleteWpState) return - requireActivity().onBackPressedDispatcher.addCallback( - viewLifecycleOwner, - object : OnBackPressedCallback( - true - ) { - override fun handleOnBackPressed() { - viewModel.logoutAndFallbackToLogin() - } - }) + requireActivity().onBackPressedDispatcher.addCallback(this) { viewModel.logoutAndFallbackToLogin() } } companion object { diff --git a/WordPress/src/main/java/org/wordpress/android/ui/qrcodeauth/QRCodeAuthFragment.kt b/WordPress/src/main/java/org/wordpress/android/ui/qrcodeauth/QRCodeAuthFragment.kt index 1398c43c489d..2ecb5e21c959 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/qrcodeauth/QRCodeAuthFragment.kt +++ b/WordPress/src/main/java/org/wordpress/android/ui/qrcodeauth/QRCodeAuthFragment.kt @@ -4,7 +4,7 @@ import android.os.Bundle import android.view.LayoutInflater import android.view.View import android.view.ViewGroup -import androidx.activity.OnBackPressedCallback +import androidx.activity.addCallback import androidx.compose.foundation.layout.fillMaxSize import androidx.compose.runtime.Composable import androidx.compose.runtime.collectAsState @@ -115,14 +115,9 @@ class QRCodeAuthFragment : Fragment() { } private fun initBackPressHandler() { - requireActivity().onBackPressedDispatcher.addCallback( - viewLifecycleOwner, - object : OnBackPressedCallback(true) { - override fun handleOnBackPressed() { - qrCodeAuthViewModel.onBackPressed() - } - } - ) + requireActivity().onBackPressedDispatcher.addCallback(this) { + qrCodeAuthViewModel.onBackPressed() + } } override fun onSaveInstanceState(outState: Bundle) { diff --git a/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/lists/sections/insights/management/InsightsManagementFragment.kt b/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/lists/sections/insights/management/InsightsManagementFragment.kt index 100a95759b20..7b4f060d2345 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/lists/sections/insights/management/InsightsManagementFragment.kt +++ b/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/lists/sections/insights/management/InsightsManagementFragment.kt @@ -5,7 +5,7 @@ import android.view.Menu import android.view.MenuInflater import android.view.MenuItem import android.view.View -import androidx.activity.OnBackPressedCallback +import androidx.activity.addCallback import androidx.core.view.MenuProvider import androidx.fragment.app.FragmentActivity import androidx.lifecycle.ViewModelProvider @@ -33,11 +33,7 @@ class InsightsManagementFragment : DaggerFragment(R.layout.insights_management_f initializeViews() initializeViewModels(requireActivity(), siteId) } - activity?.onBackPressedDispatcher?.addCallback(viewLifecycleOwner, object : OnBackPressedCallback(true) { - override fun handleOnBackPressed() { - viewModel.onBackPressed() - } - }) + requireActivity().onBackPressedDispatcher.addCallback(this) { viewModel.onBackPressed() } } override fun onCreateMenu(menu: Menu, menuInflater: MenuInflater) { From 864b7db3219e9fe4806e23cb348166bfac35b2b0 Mon Sep 17 00:00:00 2001 From: Irfan Omur Date: Sun, 12 Feb 2023 11:22:08 +0300 Subject: [PATCH 016/856] Move lambda argument out pf parentheses --- .../PostSignupInterstitialActivity.kt | 2 +- .../ui/sitecreation/SiteCreationActivity.kt | 47 +++++++++---------- 2 files changed, 24 insertions(+), 25 deletions(-) diff --git a/WordPress/src/main/java/org/wordpress/android/ui/accounts/PostSignupInterstitialActivity.kt b/WordPress/src/main/java/org/wordpress/android/ui/accounts/PostSignupInterstitialActivity.kt index c5cfab96d284..7086e85b4116 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/accounts/PostSignupInterstitialActivity.kt +++ b/WordPress/src/main/java/org/wordpress/android/ui/accounts/PostSignupInterstitialActivity.kt @@ -42,7 +42,7 @@ class PostSignupInterstitialActivity : LocaleAwareActivity() { dismissButton().setOnClickListener { viewModel.onDismissButtonPressed() } } - viewModel.navigationAction.observe(this, { executeAction(it) }) + viewModel.navigationAction.observe(this) { executeAction(it) } } private fun PostSignupInterstitialActivityBinding.createNewSiteButton() = diff --git a/WordPress/src/main/java/org/wordpress/android/ui/sitecreation/SiteCreationActivity.kt b/WordPress/src/main/java/org/wordpress/android/ui/sitecreation/SiteCreationActivity.kt index 70c141624f4c..1f054356a63d 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/sitecreation/SiteCreationActivity.kt +++ b/WordPress/src/main/java/org/wordpress/android/ui/sitecreation/SiteCreationActivity.kt @@ -7,7 +7,6 @@ import android.view.MenuItem import androidx.activity.addCallback import androidx.activity.viewModels import androidx.fragment.app.Fragment -import androidx.lifecycle.Observer import dagger.hilt.android.AndroidEntryPoint import kotlinx.coroutines.cancel import org.wordpress.android.R @@ -100,8 +99,8 @@ class SiteCreationActivity : LocaleAwareActivity(), @Suppress("LongMethod") private fun observeVMState() { mainViewModel.navigationTargetObservable - .observe(this, Observer { target -> target?.let { showStep(target) } }) - mainViewModel.wizardFinishedObservable.observe(this, Observer { createSiteState -> + .observe(this) { target -> target?.let { showStep(target) } } + mainViewModel.wizardFinishedObservable.observe(this) { createSiteState -> createSiteState?.let { val intent = Intent() val (siteCreated, localSiteId, titleTaskComplete) = when (createSiteState) { @@ -114,8 +113,8 @@ class SiteCreationActivity : LocaleAwareActivity(), Triple(true, null, createSiteState.isSiteTitleTaskComplete) } is SiteCreationCompleted -> Triple( - true, createSiteState.localSiteId, - createSiteState.isSiteTitleTaskComplete + true, createSiteState.localSiteId, + createSiteState.isSiteTitleTaskComplete ) } intent.putExtra(SitePickerActivity.KEY_SITE_LOCAL_ID, localSiteId) @@ -123,43 +122,43 @@ class SiteCreationActivity : LocaleAwareActivity(), setResult(if (siteCreated) Activity.RESULT_OK else Activity.RESULT_CANCELED, intent) finish() } - }) - mainViewModel.dialogActionObservable.observe(this, Observer { dialogHolder -> + } + mainViewModel.dialogActionObservable.observe(this) { dialogHolder -> dialogHolder?.let { val supportFragmentManager = requireNotNull(supportFragmentManager) { "FragmentManager can't be null at this point" } dialogHolder.show(this, supportFragmentManager, uiHelpers) } - }) - mainViewModel.exitFlowObservable.observe(this, Observer { + } + mainViewModel.exitFlowObservable.observe(this) { setResult(Activity.RESULT_CANCELED) finish() - }) - mainViewModel.onBackPressedObservable.observe(this, Observer { + } + mainViewModel.onBackPressedObservable.observe(this) { ActivityUtils.hideKeyboard(this) onBackPressedDispatcher.onBackPressed() - }) - siteCreationIntentsViewModel.onBackButtonPressed.observe(this, Observer { + } + siteCreationIntentsViewModel.onBackButtonPressed.observe(this) { mainViewModel.onBackPressed() - }) - siteCreationIntentsViewModel.onSkipButtonPressed.observe(this, Observer { + } + siteCreationIntentsViewModel.onSkipButtonPressed.observe(this) { mainViewModel.onSiteIntentSkipped() - }) - siteCreationSiteNameViewModel.onBackButtonPressed.observe(this, Observer { + } + siteCreationSiteNameViewModel.onBackButtonPressed.observe(this) { mainViewModel.onBackPressed() ActivityUtils.hideKeyboard(this) - }) - siteCreationSiteNameViewModel.onSkipButtonPressed.observe(this, Observer { + } + siteCreationSiteNameViewModel.onSkipButtonPressed.observe(this) { ActivityUtils.hideKeyboard(this) mainViewModel.onSiteNameSkipped() - }) - hppViewModel.onBackButtonPressed.observe(this, Observer { + } + hppViewModel.onBackButtonPressed.observe(this) { mainViewModel.onBackPressed() - }) - hppViewModel.onDesignActionPressed.observe(this, Observer { design -> + } + hppViewModel.onDesignActionPressed.observe(this) { design -> mainViewModel.onSiteDesignSelected(design.template) - }) + } observeOverlayEvents() } From 0afe7378637e0a7e7c23006ffbb417b2268b8b54 Mon Sep 17 00:00:00 2001 From: Irfan Omur Date: Sun, 12 Feb 2023 11:30:24 +0300 Subject: [PATCH 017/856] Remove redundant null checks --- .../android/ui/people/PeopleManagementActivity.java | 2 +- .../android/ui/reader/ReaderCommentListActivity.java | 4 +--- .../android/ui/sitecreation/SiteCreationActivity.kt | 9 ++------- 3 files changed, 4 insertions(+), 11 deletions(-) diff --git a/WordPress/src/main/java/org/wordpress/android/ui/people/PeopleManagementActivity.java b/WordPress/src/main/java/org/wordpress/android/ui/people/PeopleManagementActivity.java index c6aea4da301e..77c67e402270 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/people/PeopleManagementActivity.java +++ b/WordPress/src/main/java/org/wordpress/android/ui/people/PeopleManagementActivity.java @@ -244,7 +244,7 @@ public boolean onOptionsItemSelected(final MenuItem item) { if (peopleInviteFragment == null) { peopleInviteFragment = PeopleInviteFragment.newInstance(mSite); } - if (peopleInviteFragment != null && !peopleInviteFragment.isAdded()) { + if (!peopleInviteFragment.isAdded()) { FragmentTransaction fragmentTransaction = getSupportFragmentManager().beginTransaction(); fragmentTransaction.replace(R.id.fragment_container, peopleInviteFragment, KEY_PEOPLE_INVITE_FRAGMENT); fragmentTransaction.addToBackStack(null); diff --git a/WordPress/src/main/java/org/wordpress/android/ui/reader/ReaderCommentListActivity.java b/WordPress/src/main/java/org/wordpress/android/ui/reader/ReaderCommentListActivity.java index 5228444ceed3..8552349e36d0 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/reader/ReaderCommentListActivity.java +++ b/WordPress/src/main/java/org/wordpress/android/ui/reader/ReaderCommentListActivity.java @@ -253,9 +253,7 @@ public void afterTextChanged(Editable s) { mSuggestionServiceConnectionManager, mPost.isWP() ); - if (mSuggestionAdapter != null) { - mEditComment.setAdapter(mSuggestionAdapter); - } + mEditComment.setAdapter(mSuggestionAdapter); mReaderTracker.trackPost(AnalyticsTracker.Stat.READER_ARTICLE_COMMENTS_OPENED, mPost, mSource); diff --git a/WordPress/src/main/java/org/wordpress/android/ui/sitecreation/SiteCreationActivity.kt b/WordPress/src/main/java/org/wordpress/android/ui/sitecreation/SiteCreationActivity.kt index 1f054356a63d..6d399d76a28d 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/sitecreation/SiteCreationActivity.kt +++ b/WordPress/src/main/java/org/wordpress/android/ui/sitecreation/SiteCreationActivity.kt @@ -123,13 +123,8 @@ class SiteCreationActivity : LocaleAwareActivity(), finish() } } - mainViewModel.dialogActionObservable.observe(this) { dialogHolder -> - dialogHolder?.let { - val supportFragmentManager = requireNotNull(supportFragmentManager) { - "FragmentManager can't be null at this point" - } - dialogHolder.show(this, supportFragmentManager, uiHelpers) - } + mainViewModel.dialogActionObservable.observe(this) { + it?.show(this, supportFragmentManager, uiHelpers) } mainViewModel.exitFlowObservable.observe(this) { setResult(Activity.RESULT_CANCELED) From cc9f2e9b0570f21c1bb4d4dd6ba2b159a8cdcb31 Mon Sep 17 00:00:00 2001 From: Irfan Omur Date: Wed, 1 Mar 2023 18:13:53 +0300 Subject: [PATCH 018/856] Add missing super.onBackPressed() behaviors --- .../wordpress/android/ui/history/HistoryDetailActivity.kt | 6 +++++- .../wordpress/android/ui/suggestion/SuggestionActivity.kt | 6 +++++- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/WordPress/src/main/java/org/wordpress/android/ui/history/HistoryDetailActivity.kt b/WordPress/src/main/java/org/wordpress/android/ui/history/HistoryDetailActivity.kt index 814b0607d868..f6d2afd0efc4 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/history/HistoryDetailActivity.kt +++ b/WordPress/src/main/java/org/wordpress/android/ui/history/HistoryDetailActivity.kt @@ -21,7 +21,11 @@ class HistoryDetailActivity : LocaleAwareActivity() { setSupportActionBar(toolbarMain) } - onBackPressedDispatcher.addCallback(this) { AnalyticsTracker.track(Stat.REVISIONS_DETAIL_CANCELLED) } + onBackPressedDispatcher.addCallback(this) { + AnalyticsTracker.track(Stat.REVISIONS_DETAIL_CANCELLED) + isEnabled = false + onBackPressedDispatcher.onBackPressed() + } supportActionBar?.setDisplayHomeAsUpEnabled(true) diff --git a/WordPress/src/main/java/org/wordpress/android/ui/suggestion/SuggestionActivity.kt b/WordPress/src/main/java/org/wordpress/android/ui/suggestion/SuggestionActivity.kt index ed8d3bdfd391..671248a55879 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/suggestion/SuggestionActivity.kt +++ b/WordPress/src/main/java/org/wordpress/android/ui/suggestion/SuggestionActivity.kt @@ -43,7 +43,11 @@ class SuggestionActivity : LocaleAwareActivity() { binding = this } - onBackPressedDispatcher.addCallback(this) { viewModel.trackExit(false) } + onBackPressedDispatcher.addCallback(this) { + viewModel.trackExit(false) + isEnabled = false + onBackPressedDispatcher.onBackPressed() + } val siteModel = intent.getSerializableExtra(INTENT_KEY_SITE_MODEL) as? SiteModel val suggestionType = intent.getSerializableExtra(INTENT_KEY_SUGGESTION_TYPE) as? SuggestionType From 3a3110e41098bce85f6d8cfd900ef481c7801279 Mon Sep 17 00:00:00 2001 From: Irfan Omur Date: Thu, 2 Mar 2023 18:09:24 +0300 Subject: [PATCH 019/856] Fix loop issue of OnBackPressedCallback in SiteCreationActivity OnBackPressedCallback was temporarily disabled to allow the system to handle the back button event. --- .../android/ui/sitecreation/SiteCreationActivity.kt | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/WordPress/src/main/java/org/wordpress/android/ui/sitecreation/SiteCreationActivity.kt b/WordPress/src/main/java/org/wordpress/android/ui/sitecreation/SiteCreationActivity.kt index 6d399d76a28d..795dae6baabe 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/sitecreation/SiteCreationActivity.kt +++ b/WordPress/src/main/java/org/wordpress/android/ui/sitecreation/SiteCreationActivity.kt @@ -4,7 +4,7 @@ import android.app.Activity import android.content.Intent import android.os.Bundle import android.view.MenuItem -import androidx.activity.addCallback +import androidx.activity.OnBackPressedCallback import androidx.activity.viewModels import androidx.fragment.app.Fragment import dagger.hilt.android.AndroidEntryPoint @@ -79,11 +79,17 @@ class SiteCreationActivity : LocaleAwareActivity(), @Inject internal lateinit var jetpackFeatureRemovalOverlayUtil: JetpackFeatureRemovalOverlayUtil @Inject internal lateinit var activityLauncherWrapper: ActivityLauncherWrapper + private val backPressedCallback = object : OnBackPressedCallback(true) { + override fun handleOnBackPressed() { + mainViewModel.onBackPressed() + } + } + override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) setContentView(R.layout.site_creation_activity) - onBackPressedDispatcher.addCallback(this) { mainViewModel.onBackPressed() } + onBackPressedDispatcher.addCallback(this, backPressedCallback) mainViewModel.start(savedInstanceState, getSiteCreationSource()) mainViewModel.preloadThumbnails(this) @@ -132,7 +138,9 @@ class SiteCreationActivity : LocaleAwareActivity(), } mainViewModel.onBackPressedObservable.observe(this) { ActivityUtils.hideKeyboard(this) + backPressedCallback.isEnabled = false onBackPressedDispatcher.onBackPressed() + backPressedCallback.isEnabled = true } siteCreationIntentsViewModel.onBackButtonPressed.observe(this) { mainViewModel.onBackPressed() From 1808fd4a471d71b87f598ddbc4c4e6f9aa2d64dc Mon Sep 17 00:00:00 2001 From: Irfan Omur Date: Wed, 1 Mar 2023 18:39:56 +0300 Subject: [PATCH 020/856] Fix the crash on JetpackFullPluginInstallOnboardingDialogFragment --- ...packFullPluginInstallOnboardingDialogFragment.kt | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/WordPress/src/main/java/org/wordpress/android/ui/jpfullplugininstall/onboarding/JetpackFullPluginInstallOnboardingDialogFragment.kt b/WordPress/src/main/java/org/wordpress/android/ui/jpfullplugininstall/onboarding/JetpackFullPluginInstallOnboardingDialogFragment.kt index 1a696cad4d0f..24f5c48b7326 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/jpfullplugininstall/onboarding/JetpackFullPluginInstallOnboardingDialogFragment.kt +++ b/WordPress/src/main/java/org/wordpress/android/ui/jpfullplugininstall/onboarding/JetpackFullPluginInstallOnboardingDialogFragment.kt @@ -62,16 +62,15 @@ class JetpackFullPluginInstallOnboardingDialogFragment : DialogFragment() { override fun onCreateDialog(savedInstanceState: Bundle?): Dialog = super.onCreateDialog(savedInstanceState).apply { - val componentDialog = dialog as ComponentDialog - componentDialog.onBackPressedDispatcher.addCallback(this@JetpackFullPluginInstallOnboardingDialogFragment) { - viewModel.onDismissScreenClick() - isEnabled = false - componentDialog.onBackPressedDispatcher.onBackPressed() - } + (this as ComponentDialog).onBackPressedDispatcher + .addCallback(this@JetpackFullPluginInstallOnboardingDialogFragment) { + viewModel.onDismissScreenClick() + isEnabled = false + onBackPressedDispatcher.onBackPressed() + } setStatusBarAsSurfaceColor() } - @Composable private fun JetpackFullPluginInstallOnboardingScreen( viewModel: JetpackFullPluginInstallOnboardingViewModel = viewModel() From 1749865ed8a954c7dda33e64f2ea430cf5e93458 Mon Sep 17 00:00:00 2001 From: Irfan Omur Date: Thu, 2 Mar 2023 18:54:36 +0300 Subject: [PATCH 021/856] Refactor ComponentDialog casting --- .../android/ui/CollapseFullScreenDialogFragment.java | 4 ++-- .../org/wordpress/android/ui/FullScreenDialogFragment.java | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/WordPress/src/main/java/org/wordpress/android/ui/CollapseFullScreenDialogFragment.java b/WordPress/src/main/java/org/wordpress/android/ui/CollapseFullScreenDialogFragment.java index 4379f114d01f..dc9af5150ba9 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/CollapseFullScreenDialogFragment.java +++ b/WordPress/src/main/java/org/wordpress/android/ui/CollapseFullScreenDialogFragment.java @@ -148,14 +148,14 @@ public void setConfirmEnabled(boolean enabled) { public Dialog onCreateDialog(Bundle savedInstanceState) { initBuilderArguments(); - Dialog dialog = super.onCreateDialog(savedInstanceState); + ComponentDialog dialog = (ComponentDialog) super.onCreateDialog(savedInstanceState); OnBackPressedCallback callback = new OnBackPressedCallback(true) { @Override public void handleOnBackPressed() { onCollapseClicked(); } }; - ((ComponentDialog) dialog).getOnBackPressedDispatcher().addCallback(this, callback); + dialog.getOnBackPressedDispatcher().addCallback(this, callback); dialog.requestWindowFeature(Window.FEATURE_NO_TITLE); return dialog; diff --git a/WordPress/src/main/java/org/wordpress/android/ui/FullScreenDialogFragment.java b/WordPress/src/main/java/org/wordpress/android/ui/FullScreenDialogFragment.java index 8695c369be04..394602206859 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/FullScreenDialogFragment.java +++ b/WordPress/src/main/java/org/wordpress/android/ui/FullScreenDialogFragment.java @@ -168,14 +168,14 @@ public void dismiss() { public Dialog onCreateDialog(Bundle savedInstanceState) { initBuilderArguments(); - Dialog dialog = super.onCreateDialog(savedInstanceState); + ComponentDialog dialog = (ComponentDialog) super.onCreateDialog(savedInstanceState); OnBackPressedCallback callback = new OnBackPressedCallback(true) { @Override public void handleOnBackPressed() { onDismissClicked(); } }; - ((ComponentDialog) dialog).getOnBackPressedDispatcher().addCallback(this, callback); + dialog.getOnBackPressedDispatcher().addCallback(this, callback); dialog.requestWindowFeature(Window.FEATURE_NO_TITLE); return dialog; From fb7a69c9b73653838f56ff7d1bd3ffc3de2bbb56 Mon Sep 17 00:00:00 2001 From: Irfan Omur Date: Mon, 6 Mar 2023 00:49:44 +0300 Subject: [PATCH 022/856] Refactor onBackPressed function in CollapseFullScreenDialogFragment --- .../android/ui/CollapseFullScreenDialogFragment.java | 2 +- .../org/wordpress/android/ui/FullScreenDialogFragment.java | 6 ------ .../android/ui/comments/CommentsDetailActivity.java | 2 +- .../ui/notifications/NotificationsDetailActivity.java | 2 +- .../android/ui/reader/ReaderCommentListActivity.java | 2 +- 5 files changed, 4 insertions(+), 10 deletions(-) diff --git a/WordPress/src/main/java/org/wordpress/android/ui/CollapseFullScreenDialogFragment.java b/WordPress/src/main/java/org/wordpress/android/ui/CollapseFullScreenDialogFragment.java index dc9af5150ba9..7e694dfa9634 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/CollapseFullScreenDialogFragment.java +++ b/WordPress/src/main/java/org/wordpress/android/ui/CollapseFullScreenDialogFragment.java @@ -301,7 +301,7 @@ private void initToolbar(View view) { } } - public void onBackPressed() { + public void collapse() { if (isAdded()) { onCollapseClicked(); } diff --git a/WordPress/src/main/java/org/wordpress/android/ui/FullScreenDialogFragment.java b/WordPress/src/main/java/org/wordpress/android/ui/FullScreenDialogFragment.java index 394602206859..42f7004390a8 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/FullScreenDialogFragment.java +++ b/WordPress/src/main/java/org/wordpress/android/ui/FullScreenDialogFragment.java @@ -333,12 +333,6 @@ private void initToolbar(View view) { } } - public void onBackPressed() { - if (isAdded()) { - onDismissClicked(); - } - } - protected void onConfirmClicked() { boolean isConsumed = ((FullScreenDialogContent) mFragment).onConfirmClicked(mController); diff --git a/WordPress/src/main/java/org/wordpress/android/ui/comments/CommentsDetailActivity.java b/WordPress/src/main/java/org/wordpress/android/ui/comments/CommentsDetailActivity.java index bb5af81cf12c..dc570356accd 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/comments/CommentsDetailActivity.java +++ b/WordPress/src/main/java/org/wordpress/android/ui/comments/CommentsDetailActivity.java @@ -90,7 +90,7 @@ public void handleOnBackPressed() { getSupportFragmentManager().findFragmentByTag(CollapseFullScreenDialogFragment.TAG); if (fragment != null) { - fragment.onBackPressed(); + fragment.collapse(); } else { setEnabled(false); getOnBackPressedDispatcher().onBackPressed(); diff --git a/WordPress/src/main/java/org/wordpress/android/ui/notifications/NotificationsDetailActivity.java b/WordPress/src/main/java/org/wordpress/android/ui/notifications/NotificationsDetailActivity.java index 5cec9ca5e318..2f46d2152fe9 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/notifications/NotificationsDetailActivity.java +++ b/WordPress/src/main/java/org/wordpress/android/ui/notifications/NotificationsDetailActivity.java @@ -121,7 +121,7 @@ public void handleOnBackPressed() { getSupportFragmentManager().findFragmentByTag(CollapseFullScreenDialogFragment.TAG); if (fragment != null) { - fragment.onBackPressed(); + fragment.collapse(); } else { setEnabled(false); getOnBackPressedDispatcher().onBackPressed(); diff --git a/WordPress/src/main/java/org/wordpress/android/ui/reader/ReaderCommentListActivity.java b/WordPress/src/main/java/org/wordpress/android/ui/reader/ReaderCommentListActivity.java index 8552349e36d0..ad307b5f0be7 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/reader/ReaderCommentListActivity.java +++ b/WordPress/src/main/java/org/wordpress/android/ui/reader/ReaderCommentListActivity.java @@ -164,7 +164,7 @@ public void handleOnBackPressed() { getSupportFragmentManager().findFragmentByTag(CollapseFullScreenDialogFragment.TAG); if (fragment != null) { - fragment.onBackPressed(); + fragment.collapse(); } else { setEnabled(false); getOnBackPressedDispatcher().onBackPressed(); From bfcf01d2e320bba9894ace5677b6d43b865584f5 Mon Sep 17 00:00:00 2001 From: Irfan Omur Date: Mon, 6 Mar 2023 02:03:40 +0300 Subject: [PATCH 023/856] Use CompatExtensions functions for migrating super.onBackPressed --- .../ui/JetpackConnectionResultActivity.java | 4 ++-- .../ui/JetpackRemoteInstallActivity.kt | 4 ++-- .../android/ui/WPWebViewActivity.java | 4 ++-- .../wordpress/android/ui/WebViewActivity.java | 4 ++-- .../ui/comments/CommentsDetailActivity.java | 4 ++-- .../ui/comments/EditCommentActivity.java | 4 ++-- .../DeepLinkingIntentReceiverActivity.java | 4 ++-- .../FeatureIntroductionDialogFragment.kt | 4 ++-- .../ui/history/HistoryDetailActivity.kt | 4 ++-- ...llPluginInstallOnboardingDialogFragment.kt | 4 ++-- .../android/ui/main/WPMainActivity.java | 4 ++-- .../ui/media/MediaSettingsActivity.java | 4 ++-- .../NotificationsDetailActivity.java | 4 ++-- .../ui/people/PeopleManagementActivity.java | 4 ++-- .../ui/plugins/PluginBrowserActivity.java | 4 ++-- .../ui/posts/PostSettingsTagsActivity.java | 4 ++-- .../ui/posts/SelectCategoriesActivity.java | 4 ++-- .../ui/prefs/SiteSettingsTagListActivity.java | 4 ++-- .../ui/publicize/PublicizeListActivity.java | 4 ++-- .../ui/reader/ReaderCommentListActivity.java | 4 ++-- .../ui/reader/ReaderPostListActivity.java | 4 ++-- .../ui/reader/ReaderPostPagerActivity.java | 4 ++-- .../android/ui/reader/ReaderSubsActivity.java | 4 ++-- .../ui/sitecreation/SiteCreationActivity.kt | 5 ++--- .../ui/suggestion/SuggestionActivity.kt | 4 ++-- .../ui/themes/ThemeBrowserActivity.java | 4 ++-- .../util/extensions/CompatExtensions.kt | 20 +++++++++++++++++++ .../android/imageeditor/EditImageActivity.kt | 4 ++-- .../imageeditor/utils/CompatExtensions.kt | 20 +++++++++++++++++++ 29 files changed, 94 insertions(+), 55 deletions(-) create mode 100644 WordPress/src/main/java/org/wordpress/android/util/extensions/CompatExtensions.kt create mode 100644 libs/image-editor/src/main/kotlin/org/wordpress/android/imageeditor/utils/CompatExtensions.kt diff --git a/WordPress/src/main/java/org/wordpress/android/ui/JetpackConnectionResultActivity.java b/WordPress/src/main/java/org/wordpress/android/ui/JetpackConnectionResultActivity.java index 19362744c966..93dc0b76cc6f 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/JetpackConnectionResultActivity.java +++ b/WordPress/src/main/java/org/wordpress/android/ui/JetpackConnectionResultActivity.java @@ -23,6 +23,7 @@ import org.wordpress.android.util.SiteUtils; import org.wordpress.android.util.ToastUtils; import org.wordpress.android.util.analytics.AnalyticsUtils; +import org.wordpress.android.util.extensions.CompatExtensionsKt; import javax.inject.Inject; @@ -58,8 +59,7 @@ protected void onCreate(Bundle savedInstanceState) { OnBackPressedCallback callback = new OnBackPressedCallback(true) { @Override public void handleOnBackPressed() { - setEnabled(false); - getOnBackPressedDispatcher().onBackPressed(); + CompatExtensionsKt.onBackPressedCompat(getOnBackPressedDispatcher(), this); finishAndGoBackToSource(); } }; diff --git a/WordPress/src/main/java/org/wordpress/android/ui/JetpackRemoteInstallActivity.kt b/WordPress/src/main/java/org/wordpress/android/ui/JetpackRemoteInstallActivity.kt index accce847a68f..fbeaed7dbb3b 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/JetpackRemoteInstallActivity.kt +++ b/WordPress/src/main/java/org/wordpress/android/ui/JetpackRemoteInstallActivity.kt @@ -8,6 +8,7 @@ import org.wordpress.android.analytics.AnalyticsTracker.Stat.INSTALL_JETPACK_CAN 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.onBackPressedCompat class JetpackRemoteInstallActivity : LocaleAwareActivity() { public override fun onCreate(savedInstanceState: Bundle?) { @@ -22,8 +23,7 @@ class JetpackRemoteInstallActivity : LocaleAwareActivity() { INSTALL_JETPACK_CANCELLED, intent.getSerializableExtra(TRACKING_SOURCE_KEY) as JetpackConnectionSource ) - isEnabled = false - onBackPressedDispatcher.onBackPressed() + onBackPressedDispatcher.onBackPressedCompat(this) } supportActionBar?.let { diff --git a/WordPress/src/main/java/org/wordpress/android/ui/WPWebViewActivity.java b/WordPress/src/main/java/org/wordpress/android/ui/WPWebViewActivity.java index 8a0a24828f74..f12310eba6ea 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/WPWebViewActivity.java +++ b/WordPress/src/main/java/org/wordpress/android/ui/WPWebViewActivity.java @@ -61,6 +61,7 @@ import org.wordpress.android.util.UrlUtils; import org.wordpress.android.util.WPUrlUtils; import org.wordpress.android.util.WPWebViewClient; +import org.wordpress.android.util.extensions.CompatExtensionsKt; import org.wordpress.android.viewmodel.wpwebview.WPWebViewViewModel; import org.wordpress.android.viewmodel.wpwebview.WPWebViewViewModel.NavBarUiState; import org.wordpress.android.viewmodel.wpwebview.WPWebViewViewModel.PreviewModeSelectorStatus; @@ -170,8 +171,7 @@ public void handleOnBackPressed() { mWebView.goBack(); refreshBackForwardNavButtons(); } else { - setEnabled(false); - getOnBackPressedDispatcher().onBackPressed(); + CompatExtensionsKt.onBackPressedCompat(getOnBackPressedDispatcher(), this); mViewModel.track(Stat.WEBVIEW_DISMISSED); setResultIfNeeded(); } diff --git a/WordPress/src/main/java/org/wordpress/android/ui/WebViewActivity.java b/WordPress/src/main/java/org/wordpress/android/ui/WebViewActivity.java index d8824ed71af5..cb67fdb3f6f0 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/WebViewActivity.java +++ b/WordPress/src/main/java/org/wordpress/android/ui/WebViewActivity.java @@ -12,6 +12,7 @@ import org.wordpress.android.R; import org.wordpress.android.WordPress; +import org.wordpress.android.util.extensions.CompatExtensionsKt; import java.util.Map; @@ -47,8 +48,7 @@ public void handleOnBackPressed() { mWebView.goBack(); } else { cancel(); - setEnabled(false); - getOnBackPressedDispatcher().onBackPressed(); + CompatExtensionsKt.onBackPressedCompat(getOnBackPressedDispatcher(), this); } } }; diff --git a/WordPress/src/main/java/org/wordpress/android/ui/comments/CommentsDetailActivity.java b/WordPress/src/main/java/org/wordpress/android/ui/comments/CommentsDetailActivity.java index dc570356accd..f4348e7d239c 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/comments/CommentsDetailActivity.java +++ b/WordPress/src/main/java/org/wordpress/android/ui/comments/CommentsDetailActivity.java @@ -39,6 +39,7 @@ import org.wordpress.android.util.ToastUtils; import org.wordpress.android.util.analytics.AnalyticsUtils; import org.wordpress.android.util.analytics.AnalyticsUtils.AnalyticsCommentActionSource; +import org.wordpress.android.util.extensions.CompatExtensionsKt; import org.wordpress.android.widgets.WPViewPager; import org.wordpress.android.widgets.WPViewPagerTransformer; @@ -92,8 +93,7 @@ public void handleOnBackPressed() { if (fragment != null) { fragment.collapse(); } else { - setEnabled(false); - getOnBackPressedDispatcher().onBackPressed(); + CompatExtensionsKt.onBackPressedCompat(getOnBackPressedDispatcher(), this); } } }; diff --git a/WordPress/src/main/java/org/wordpress/android/ui/comments/EditCommentActivity.java b/WordPress/src/main/java/org/wordpress/android/ui/comments/EditCommentActivity.java index 1a2a3e9746ba..af88e79c01ae 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/comments/EditCommentActivity.java +++ b/WordPress/src/main/java/org/wordpress/android/ui/comments/EditCommentActivity.java @@ -42,6 +42,7 @@ import org.wordpress.android.util.EditTextUtils; import org.wordpress.android.util.NetworkUtils; import org.wordpress.android.util.ToastUtils; +import org.wordpress.android.util.extensions.CompatExtensionsKt; import javax.inject.Inject; @@ -81,8 +82,7 @@ public void handleOnBackPressed() { if (isCommentEdited()) { cancelEditCommentConfirmation(); } else { - setEnabled(false); - getOnBackPressedDispatcher().onBackPressed(); + CompatExtensionsKt.onBackPressedCompat(getOnBackPressedDispatcher(), this); } } }; diff --git a/WordPress/src/main/java/org/wordpress/android/ui/deeplinks/DeepLinkingIntentReceiverActivity.java b/WordPress/src/main/java/org/wordpress/android/ui/deeplinks/DeepLinkingIntentReceiverActivity.java index b8fedb502287..28066e7cf893 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/deeplinks/DeepLinkingIntentReceiverActivity.java +++ b/WordPress/src/main/java/org/wordpress/android/ui/deeplinks/DeepLinkingIntentReceiverActivity.java @@ -21,6 +21,7 @@ import org.wordpress.android.util.PackageManagerWrapper; import org.wordpress.android.util.ToastUtils; import org.wordpress.android.util.UriWrapper; +import org.wordpress.android.util.extensions.CompatExtensionsKt; import javax.inject.Inject; @@ -54,8 +55,7 @@ protected void onCreate(Bundle savedInstanceState) { OnBackPressedCallback callback = new OnBackPressedCallback(true) { @Override public void handleOnBackPressed() { - setEnabled(false); - getOnBackPressedDispatcher().onBackPressed(); + CompatExtensionsKt.onBackPressedCompat(getOnBackPressedDispatcher(), this); finish(); } }; diff --git a/WordPress/src/main/java/org/wordpress/android/ui/featureintroduction/FeatureIntroductionDialogFragment.kt b/WordPress/src/main/java/org/wordpress/android/ui/featureintroduction/FeatureIntroductionDialogFragment.kt index a3f8a33e663d..f2e8a2e41dbf 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/featureintroduction/FeatureIntroductionDialogFragment.kt +++ b/WordPress/src/main/java/org/wordpress/android/ui/featureintroduction/FeatureIntroductionDialogFragment.kt @@ -15,6 +15,7 @@ import org.wordpress.android.R import org.wordpress.android.analytics.AnalyticsTracker.Stat import org.wordpress.android.databinding.FeatureIntroductionDialogFragmentBinding import org.wordpress.android.ui.utils.UiHelpers +import org.wordpress.android.util.extensions.onBackPressedCompat import org.wordpress.android.util.extensions.setStatusBarAsSurfaceColor import javax.inject.Inject @@ -36,8 +37,7 @@ abstract class FeatureIntroductionDialogFragment : DialogFragment() { super.onCreateDialog(savedInstanceState).apply { (this as ComponentDialog).onBackPressedDispatcher.addCallback(this@FeatureIntroductionDialogFragment) { viewModel.onBackButtonClick() - isEnabled = false - onBackPressedDispatcher.onBackPressed() + onBackPressedDispatcher.onBackPressedCompat(this) } setStatusBarAsSurfaceColor() } diff --git a/WordPress/src/main/java/org/wordpress/android/ui/history/HistoryDetailActivity.kt b/WordPress/src/main/java/org/wordpress/android/ui/history/HistoryDetailActivity.kt index f6d2afd0efc4..7610f74109d1 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/history/HistoryDetailActivity.kt +++ b/WordPress/src/main/java/org/wordpress/android/ui/history/HistoryDetailActivity.kt @@ -8,6 +8,7 @@ import org.wordpress.android.analytics.AnalyticsTracker.Stat import org.wordpress.android.databinding.HistoryDetailActivityBinding import org.wordpress.android.ui.LocaleAwareActivity import org.wordpress.android.ui.history.HistoryListItem.Revision +import org.wordpress.android.util.extensions.onBackPressedCompat class HistoryDetailActivity : LocaleAwareActivity() { companion object { @@ -23,8 +24,7 @@ class HistoryDetailActivity : LocaleAwareActivity() { onBackPressedDispatcher.addCallback(this) { AnalyticsTracker.track(Stat.REVISIONS_DETAIL_CANCELLED) - isEnabled = false - onBackPressedDispatcher.onBackPressed() + onBackPressedDispatcher.onBackPressedCompat(this) } supportActionBar?.setDisplayHomeAsUpEnabled(true) diff --git a/WordPress/src/main/java/org/wordpress/android/ui/jpfullplugininstall/onboarding/JetpackFullPluginInstallOnboardingDialogFragment.kt b/WordPress/src/main/java/org/wordpress/android/ui/jpfullplugininstall/onboarding/JetpackFullPluginInstallOnboardingDialogFragment.kt index 24f5c48b7326..54a840dd5c54 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/jpfullplugininstall/onboarding/JetpackFullPluginInstallOnboardingDialogFragment.kt +++ b/WordPress/src/main/java/org/wordpress/android/ui/jpfullplugininstall/onboarding/JetpackFullPluginInstallOnboardingDialogFragment.kt @@ -32,6 +32,7 @@ import org.wordpress.android.ui.jpfullplugininstall.onboarding.JetpackFullPlugin import org.wordpress.android.ui.jpfullplugininstall.onboarding.compose.state.LoadedState import org.wordpress.android.util.WPUrlUtils import org.wordpress.android.util.extensions.exhaustive +import org.wordpress.android.util.extensions.onBackPressedCompat import org.wordpress.android.util.extensions.setStatusBarAsSurfaceColor @AndroidEntryPoint @@ -65,8 +66,7 @@ class JetpackFullPluginInstallOnboardingDialogFragment : DialogFragment() { (this as ComponentDialog).onBackPressedDispatcher .addCallback(this@JetpackFullPluginInstallOnboardingDialogFragment) { viewModel.onDismissScreenClick() - isEnabled = false - onBackPressedDispatcher.onBackPressed() + onBackPressedDispatcher.onBackPressedCompat(this) } setStatusBarAsSurfaceColor() } diff --git a/WordPress/src/main/java/org/wordpress/android/ui/main/WPMainActivity.java b/WordPress/src/main/java/org/wordpress/android/ui/main/WPMainActivity.java index afc3f2adeb12..a82abd94e4bf 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/main/WPMainActivity.java +++ b/WordPress/src/main/java/org/wordpress/android/ui/main/WPMainActivity.java @@ -151,6 +151,7 @@ import org.wordpress.android.util.config.MySiteDashboardTodaysStatsCardFeatureConfig; import org.wordpress.android.util.config.OpenWebLinksWithJetpackFlowFeatureConfig; import org.wordpress.android.util.config.QRCodeAuthFlowFeatureConfig; +import org.wordpress.android.util.extensions.CompatExtensionsKt; import org.wordpress.android.util.extensions.ViewExtensionsKt; import org.wordpress.android.viewmodel.main.WPMainActivityViewModel; import org.wordpress.android.viewmodel.main.WPMainActivityViewModel.FocusPointInfo; @@ -510,8 +511,7 @@ public void handleOnBackPressed() { if (isTaskRoot() && DeviceUtils.getInstance().isChromebook(WPMainActivity.this)) { return; // don't close app in Main Activity } - setEnabled(false); - getOnBackPressedDispatcher().onBackPressed(); + CompatExtensionsKt.onBackPressedCompat(getOnBackPressedDispatcher(), this); } }; getOnBackPressedDispatcher().addCallback(this, callback); diff --git a/WordPress/src/main/java/org/wordpress/android/ui/media/MediaSettingsActivity.java b/WordPress/src/main/java/org/wordpress/android/ui/media/MediaSettingsActivity.java index 3c9aa0ccef29..2dec39e84ab3 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/media/MediaSettingsActivity.java +++ b/WordPress/src/main/java/org/wordpress/android/ui/media/MediaSettingsActivity.java @@ -88,6 +88,7 @@ import org.wordpress.android.util.ToastUtils; import org.wordpress.android.util.WPMediaUtils; import org.wordpress.android.util.WPPermissionUtils; +import org.wordpress.android.util.extensions.CompatExtensionsKt; import org.wordpress.android.util.extensions.ContextExtensionsKt; import org.wordpress.android.util.extensions.ViewExtensionsKt; import org.wordpress.android.util.image.ImageManager; @@ -220,8 +221,7 @@ protected void onCreate(@Nullable Bundle savedInstanceState) { @Override public void handleOnBackPressed() { saveChanges(); - setEnabled(false); - getOnBackPressedDispatcher().onBackPressed(); + CompatExtensionsKt.onBackPressedCompat(getOnBackPressedDispatcher(), this); } }; getOnBackPressedDispatcher().addCallback(this, callback); diff --git a/WordPress/src/main/java/org/wordpress/android/ui/notifications/NotificationsDetailActivity.java b/WordPress/src/main/java/org/wordpress/android/ui/notifications/NotificationsDetailActivity.java index 2f46d2152fe9..faee35b34051 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/notifications/NotificationsDetailActivity.java +++ b/WordPress/src/main/java/org/wordpress/android/ui/notifications/NotificationsDetailActivity.java @@ -65,6 +65,7 @@ import org.wordpress.android.util.analytics.AnalyticsUtils.AnalyticsCommentActionSource; import org.wordpress.android.util.config.LikesEnhancementsFeatureConfig; import org.wordpress.android.util.extensions.AppBarLayoutExtensionsKt; +import org.wordpress.android.util.extensions.CompatExtensionsKt; import org.wordpress.android.widgets.WPSwipeSnackbar; import org.wordpress.android.widgets.WPViewPager; import org.wordpress.android.widgets.WPViewPagerTransformer; @@ -123,8 +124,7 @@ public void handleOnBackPressed() { if (fragment != null) { fragment.collapse(); } else { - setEnabled(false); - getOnBackPressedDispatcher().onBackPressed(); + CompatExtensionsKt.onBackPressedCompat(getOnBackPressedDispatcher(), this); } } }; diff --git a/WordPress/src/main/java/org/wordpress/android/ui/people/PeopleManagementActivity.java b/WordPress/src/main/java/org/wordpress/android/ui/people/PeopleManagementActivity.java index 77c67e402270..4d2214c3a7ca 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/people/PeopleManagementActivity.java +++ b/WordPress/src/main/java/org/wordpress/android/ui/people/PeopleManagementActivity.java @@ -33,6 +33,7 @@ import org.wordpress.android.util.NetworkUtils; import org.wordpress.android.util.ToastUtils; import org.wordpress.android.util.analytics.AnalyticsUtils; +import org.wordpress.android.util.extensions.CompatExtensionsKt; import java.util.List; @@ -105,8 +106,7 @@ public void onCreate(Bundle savedInstanceState) { @Override public void handleOnBackPressed() { if (!navigateBackToPeopleListFragment()) { - setEnabled(false); - getOnBackPressedDispatcher().onBackPressed(); + CompatExtensionsKt.onBackPressedCompat(getOnBackPressedDispatcher(), this); } } }; diff --git a/WordPress/src/main/java/org/wordpress/android/ui/plugins/PluginBrowserActivity.java b/WordPress/src/main/java/org/wordpress/android/ui/plugins/PluginBrowserActivity.java index a16d381f30bf..9100438a7a41 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/plugins/PluginBrowserActivity.java +++ b/WordPress/src/main/java/org/wordpress/android/ui/plugins/PluginBrowserActivity.java @@ -47,6 +47,7 @@ import org.wordpress.android.util.ToastUtils; import org.wordpress.android.util.analytics.AnalyticsUtils; import org.wordpress.android.util.extensions.AppBarLayoutExtensionsKt; +import org.wordpress.android.util.extensions.CompatExtensionsKt; import org.wordpress.android.util.extensions.ContextExtensionsKt; import org.wordpress.android.util.image.ImageManager; import org.wordpress.android.util.image.ImageType; @@ -88,8 +89,7 @@ public void handleOnBackPressed() { // update the lift on scroll target id when we return to the root fragment AppBarLayoutExtensionsKt.setLiftOnScrollTargetViewIdAndRequestLayout(mAppBar, R.id.scroll_view); } - setEnabled(false); - getOnBackPressedDispatcher().onBackPressed(); + CompatExtensionsKt.onBackPressedCompat(getOnBackPressedDispatcher(), this); } }; getOnBackPressedDispatcher().addCallback(this, callback); diff --git a/WordPress/src/main/java/org/wordpress/android/ui/posts/PostSettingsTagsActivity.java b/WordPress/src/main/java/org/wordpress/android/ui/posts/PostSettingsTagsActivity.java index 18521ed6b389..6c6d0674db5d 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/posts/PostSettingsTagsActivity.java +++ b/WordPress/src/main/java/org/wordpress/android/ui/posts/PostSettingsTagsActivity.java @@ -15,6 +15,7 @@ import org.wordpress.android.fluxc.model.SiteModel; import org.wordpress.android.ui.LocaleAwareActivity; import org.wordpress.android.util.ToastUtils; +import org.wordpress.android.util.extensions.CompatExtensionsKt; public class PostSettingsTagsActivity extends LocaleAwareActivity implements TagsSelectedListener { public static final String KEY_TAGS = "KEY_TAGS"; @@ -30,8 +31,7 @@ public void onCreate(Bundle savedInstanceState) { @Override public void handleOnBackPressed() { saveAndFinish(); - setEnabled(false); - getOnBackPressedDispatcher().onBackPressed(); + CompatExtensionsKt.onBackPressedCompat(getOnBackPressedDispatcher(), this); } }; getOnBackPressedDispatcher().addCallback(this, callback); diff --git a/WordPress/src/main/java/org/wordpress/android/ui/posts/SelectCategoriesActivity.java b/WordPress/src/main/java/org/wordpress/android/ui/posts/SelectCategoriesActivity.java index a9e6e4677a08..3042107eacc8 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/posts/SelectCategoriesActivity.java +++ b/WordPress/src/main/java/org/wordpress/android/ui/posts/SelectCategoriesActivity.java @@ -36,6 +36,7 @@ import org.wordpress.android.util.NetworkUtils; import org.wordpress.android.util.ToastUtils; import org.wordpress.android.util.ToastUtils.Duration; +import org.wordpress.android.util.extensions.CompatExtensionsKt; import org.wordpress.android.util.helpers.ListScrollPositionManager; import org.wordpress.android.util.helpers.SwipeToRefreshHelper; import org.wordpress.android.util.helpers.SwipeToRefreshHelper.RefreshListener; @@ -75,8 +76,7 @@ public void onCreate(Bundle savedInstanceState) { @Override public void handleOnBackPressed() { saveAndFinish(); - setEnabled(false); - getOnBackPressedDispatcher().onBackPressed(); + CompatExtensionsKt.onBackPressedCompat(getOnBackPressedDispatcher(), this); } }; getOnBackPressedDispatcher().addCallback(this, callback); diff --git a/WordPress/src/main/java/org/wordpress/android/ui/prefs/SiteSettingsTagListActivity.java b/WordPress/src/main/java/org/wordpress/android/ui/prefs/SiteSettingsTagListActivity.java index c667cb1319b8..fa56f4935322 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/prefs/SiteSettingsTagListActivity.java +++ b/WordPress/src/main/java/org/wordpress/android/ui/prefs/SiteSettingsTagListActivity.java @@ -51,6 +51,7 @@ import org.wordpress.android.util.NetworkUtils; import org.wordpress.android.util.StringUtils; import org.wordpress.android.util.ToastUtils; +import org.wordpress.android.util.extensions.CompatExtensionsKt; import org.wordpress.android.util.extensions.ViewExtensionsKt; import java.util.ArrayList; @@ -111,8 +112,7 @@ public void handleOnBackPressed() { loadTags(); } } else { - setEnabled(false); - getOnBackPressedDispatcher().onBackPressed(); + CompatExtensionsKt.onBackPressedCompat(getOnBackPressedDispatcher(), this); } } }; diff --git a/WordPress/src/main/java/org/wordpress/android/ui/publicize/PublicizeListActivity.java b/WordPress/src/main/java/org/wordpress/android/ui/publicize/PublicizeListActivity.java index aeaea943d077..f81060a7077e 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/publicize/PublicizeListActivity.java +++ b/WordPress/src/main/java/org/wordpress/android/ui/publicize/PublicizeListActivity.java @@ -39,6 +39,7 @@ import org.wordpress.android.util.ToastUtils; import org.wordpress.android.util.analytics.AnalyticsUtils; import org.wordpress.android.util.extensions.AppBarLayoutExtensionsKt; +import org.wordpress.android.util.extensions.CompatExtensionsKt; import java.util.HashMap; import java.util.Map; @@ -74,8 +75,7 @@ public void handleOnBackPressed() { if (getSupportFragmentManager().getBackStackEntryCount() > 0) { getSupportFragmentManager().popBackStack(); } else { - setEnabled(false); - getOnBackPressedDispatcher().onBackPressed(); + CompatExtensionsKt.onBackPressedCompat(getOnBackPressedDispatcher(), this); } } }; diff --git a/WordPress/src/main/java/org/wordpress/android/ui/reader/ReaderCommentListActivity.java b/WordPress/src/main/java/org/wordpress/android/ui/reader/ReaderCommentListActivity.java index ad307b5f0be7..1d367c951a46 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/reader/ReaderCommentListActivity.java +++ b/WordPress/src/main/java/org/wordpress/android/ui/reader/ReaderCommentListActivity.java @@ -90,6 +90,7 @@ import org.wordpress.android.util.WPActivityUtils; import org.wordpress.android.util.analytics.AnalyticsUtils; import org.wordpress.android.util.analytics.AnalyticsUtils.AnalyticsCommentActionSource; +import org.wordpress.android.util.extensions.CompatExtensionsKt; import org.wordpress.android.util.extensions.ViewExtensionsKt; import org.wordpress.android.util.helpers.SwipeToRefreshHelper; import org.wordpress.android.widgets.RecyclerItemDecoration; @@ -166,8 +167,7 @@ public void handleOnBackPressed() { if (fragment != null) { fragment.collapse(); } else { - setEnabled(false); - getOnBackPressedDispatcher().onBackPressed(); + CompatExtensionsKt.onBackPressedCompat(getOnBackPressedDispatcher(), this); } } }; diff --git a/WordPress/src/main/java/org/wordpress/android/ui/reader/ReaderPostListActivity.java b/WordPress/src/main/java/org/wordpress/android/ui/reader/ReaderPostListActivity.java index ae8b4c046442..9f3a8e422bfe 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/reader/ReaderPostListActivity.java +++ b/WordPress/src/main/java/org/wordpress/android/ui/reader/ReaderPostListActivity.java @@ -42,6 +42,7 @@ import org.wordpress.android.ui.uploads.UploadUtils; import org.wordpress.android.ui.uploads.UploadUtilsWrapper; import org.wordpress.android.util.ToastUtils; +import org.wordpress.android.util.extensions.CompatExtensionsKt; import javax.inject.Inject; @@ -73,8 +74,7 @@ public void onCreate(Bundle savedInstanceState) { public void handleOnBackPressed() { ReaderPostListFragment fragment = getListFragment(); if (fragment == null || !fragment.onActivityBackPressed()) { - setEnabled(false); - getOnBackPressedDispatcher().onBackPressed(); + CompatExtensionsKt.onBackPressedCompat(getOnBackPressedDispatcher(), this); } } }; diff --git a/WordPress/src/main/java/org/wordpress/android/ui/reader/ReaderPostPagerActivity.java b/WordPress/src/main/java/org/wordpress/android/ui/reader/ReaderPostPagerActivity.java index c5b6c67c66aa..405526da76d2 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/reader/ReaderPostPagerActivity.java +++ b/WordPress/src/main/java/org/wordpress/android/ui/reader/ReaderPostPagerActivity.java @@ -79,6 +79,7 @@ import org.wordpress.android.util.WPActivityUtils; import org.wordpress.android.util.analytics.AnalyticsUtilsWrapper; import org.wordpress.android.util.config.SeenUnseenWithCounterFeatureConfig; +import org.wordpress.android.util.extensions.CompatExtensionsKt; import org.wordpress.android.widgets.WPSwipeSnackbar; import org.wordpress.android.widgets.WPViewPager; import org.wordpress.android.widgets.WPViewPagerTransformer; @@ -189,8 +190,7 @@ public void handleOnBackPressed() { if (fragment != null && fragment.goBackInPostHistory()) { // noop - fragment moved back to a previous post } else { - setEnabled(false); - getOnBackPressedDispatcher().onBackPressed(); + CompatExtensionsKt.onBackPressedCompat(getOnBackPressedDispatcher(), this); } } } diff --git a/WordPress/src/main/java/org/wordpress/android/ui/reader/ReaderSubsActivity.java b/WordPress/src/main/java/org/wordpress/android/ui/reader/ReaderSubsActivity.java index 3fc75974f8d5..b3fa4d9de841 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/reader/ReaderSubsActivity.java +++ b/WordPress/src/main/java/org/wordpress/android/ui/reader/ReaderSubsActivity.java @@ -55,6 +55,7 @@ import org.wordpress.android.util.EditTextUtils; import org.wordpress.android.util.NetworkUtils; import org.wordpress.android.util.UrlUtils; +import org.wordpress.android.util.extensions.CompatExtensionsKt; import org.wordpress.android.widgets.WPSnackbar; import org.wordpress.android.widgets.WPViewPager; @@ -101,8 +102,7 @@ public void handleOnBackPressed() { EventBus.getDefault().postSticky(new ReaderEvents.TagAdded(mLastAddedTagName)); } mReaderTracker.track(Stat.READER_MANAGE_VIEW_DISMISSED); - setEnabled(false); - getOnBackPressedDispatcher().onBackPressed(); + CompatExtensionsKt.onBackPressedCompat(getOnBackPressedDispatcher(), this); } }; getOnBackPressedDispatcher().addCallback(this, callback); diff --git a/WordPress/src/main/java/org/wordpress/android/ui/sitecreation/SiteCreationActivity.kt b/WordPress/src/main/java/org/wordpress/android/ui/sitecreation/SiteCreationActivity.kt index 795dae6baabe..307540aa63ac 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/sitecreation/SiteCreationActivity.kt +++ b/WordPress/src/main/java/org/wordpress/android/ui/sitecreation/SiteCreationActivity.kt @@ -53,6 +53,7 @@ import org.wordpress.android.ui.utils.UiHelpers import org.wordpress.android.util.ActivityUtils import org.wordpress.android.util.config.SiteNameFeatureConfig import org.wordpress.android.util.extensions.exhaustive +import org.wordpress.android.util.extensions.onBackPressedCompat import org.wordpress.android.util.wizard.WizardNavigationTarget import org.wordpress.android.viewmodel.observeEvent import javax.inject.Inject @@ -138,9 +139,7 @@ class SiteCreationActivity : LocaleAwareActivity(), } mainViewModel.onBackPressedObservable.observe(this) { ActivityUtils.hideKeyboard(this) - backPressedCallback.isEnabled = false - onBackPressedDispatcher.onBackPressed() - backPressedCallback.isEnabled = true + onBackPressedDispatcher.onBackPressedCompat(backPressedCallback) } siteCreationIntentsViewModel.onBackButtonPressed.observe(this) { mainViewModel.onBackPressed() diff --git a/WordPress/src/main/java/org/wordpress/android/ui/suggestion/SuggestionActivity.kt b/WordPress/src/main/java/org/wordpress/android/ui/suggestion/SuggestionActivity.kt index 671248a55879..7239d8b0378f 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/suggestion/SuggestionActivity.kt +++ b/WordPress/src/main/java/org/wordpress/android/ui/suggestion/SuggestionActivity.kt @@ -24,6 +24,7 @@ import org.wordpress.android.ui.suggestion.adapters.SuggestionAdapter import org.wordpress.android.util.AppLog import org.wordpress.android.util.AppLog.T import org.wordpress.android.util.ToastUtils +import org.wordpress.android.util.extensions.onBackPressedCompat import org.wordpress.android.widgets.SuggestionAutoCompleteText import javax.inject.Inject @@ -45,8 +46,7 @@ class SuggestionActivity : LocaleAwareActivity() { onBackPressedDispatcher.addCallback(this) { viewModel.trackExit(false) - isEnabled = false - onBackPressedDispatcher.onBackPressed() + onBackPressedDispatcher.onBackPressedCompat(this) } val siteModel = intent.getSerializableExtra(INTENT_KEY_SITE_MODEL) as? SiteModel diff --git a/WordPress/src/main/java/org/wordpress/android/ui/themes/ThemeBrowserActivity.java b/WordPress/src/main/java/org/wordpress/android/ui/themes/ThemeBrowserActivity.java index 0a309ce3a12c..e5429f3a0fba 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/themes/ThemeBrowserActivity.java +++ b/WordPress/src/main/java/org/wordpress/android/ui/themes/ThemeBrowserActivity.java @@ -48,6 +48,7 @@ import org.wordpress.android.util.JetpackBrandingUtils; import org.wordpress.android.util.ToastUtils; import org.wordpress.android.util.analytics.AnalyticsUtils; +import org.wordpress.android.util.extensions.CompatExtensionsKt; import org.wordpress.android.widgets.HeaderGridView; import java.util.HashMap; @@ -101,8 +102,7 @@ public void handleOnBackPressed() { if (fm.getBackStackEntryCount() > 0) { fm.popBackStack(); } else { - setEnabled(false); - getOnBackPressedDispatcher().onBackPressed(); + CompatExtensionsKt.onBackPressedCompat(getOnBackPressedDispatcher(), this); } } }; diff --git a/WordPress/src/main/java/org/wordpress/android/util/extensions/CompatExtensions.kt b/WordPress/src/main/java/org/wordpress/android/util/extensions/CompatExtensions.kt new file mode 100644 index 000000000000..622eb8f7234f --- /dev/null +++ b/WordPress/src/main/java/org/wordpress/android/util/extensions/CompatExtensions.kt @@ -0,0 +1,20 @@ +package org.wordpress.android.util.extensions + +import androidx.activity.OnBackPressedCallback +import androidx.activity.OnBackPressedDispatcher + +/** + * This is a temporary workaround for the issue described here: https://issuetracker.google.com/issues/247982487 + * This function temporary disables the callback to allow the system to handle the back pressed event. + * + * TODO: Replace this temporary workaround before enabling predictive back gesture on this project + * (android:enableOnBackInvokedCallback="true"). + * + * Related Issue: https://github.com/wordpress-mobile/WordPress-Android/issues/18053 + */ +@Suppress("ForbiddenComment") +fun OnBackPressedDispatcher.onBackPressedCompat(onBackPressedCallback: OnBackPressedCallback) { + onBackPressedCallback.isEnabled = false + onBackPressed() + onBackPressedCallback.isEnabled = true +} diff --git a/libs/image-editor/src/main/kotlin/org/wordpress/android/imageeditor/EditImageActivity.kt b/libs/image-editor/src/main/kotlin/org/wordpress/android/imageeditor/EditImageActivity.kt index ae411866b315..a4e594eadbdc 100644 --- a/libs/image-editor/src/main/kotlin/org/wordpress/android/imageeditor/EditImageActivity.kt +++ b/libs/image-editor/src/main/kotlin/org/wordpress/android/imageeditor/EditImageActivity.kt @@ -11,6 +11,7 @@ import androidx.navigation.ui.AppBarConfiguration import androidx.navigation.ui.NavigationUI.setupActionBarWithNavController import androidx.navigation.ui.navigateUp import org.wordpress.android.imageeditor.ImageEditor.EditorAction.EditorCancelled +import org.wordpress.android.imageeditor.utils.onBackPressedCompat class EditImageActivity : AppCompatActivity() { private lateinit var viewModel: EditImageViewModel @@ -27,8 +28,7 @@ class EditImageActivity : AppCompatActivity() { setContentView(R.layout.activity_edit_image) onBackPressedDispatcher.addCallback(this) { - isEnabled = false - onBackPressedDispatcher.onBackPressed() + onBackPressedDispatcher.onBackPressedCompat(this) if (hostFragment.childFragmentManager.backStackEntryCount == 0) { ImageEditor.instance.onEditorAction(EditorCancelled) } diff --git a/libs/image-editor/src/main/kotlin/org/wordpress/android/imageeditor/utils/CompatExtensions.kt b/libs/image-editor/src/main/kotlin/org/wordpress/android/imageeditor/utils/CompatExtensions.kt new file mode 100644 index 000000000000..db3b81fb7561 --- /dev/null +++ b/libs/image-editor/src/main/kotlin/org/wordpress/android/imageeditor/utils/CompatExtensions.kt @@ -0,0 +1,20 @@ +package org.wordpress.android.imageeditor.utils + +import androidx.activity.OnBackPressedCallback +import androidx.activity.OnBackPressedDispatcher + +/** + * This is a temporary workaround for the issue described here: https://issuetracker.google.com/issues/247982487 + * This function temporary disables the callback to allow the system to handle the back pressed event. + * + * TODO: Replace this temporary workaround before enabling predictive back gesture on this project + * (android:enableOnBackInvokedCallback="true"). + * + * Related Issue: https://github.com/wordpress-mobile/WordPress-Android/issues/18053 + */ +@Suppress("ForbiddenComment") +fun OnBackPressedDispatcher.onBackPressedCompat(onBackPressedCallback: OnBackPressedCallback) { + onBackPressedCallback.isEnabled = false + onBackPressed() + onBackPressedCallback.isEnabled = true +} From 34890193581c5486f6d00bbdd9a4e9c8e3559cde Mon Sep 17 00:00:00 2001 From: Irfan Omur Date: Tue, 28 Feb 2023 15:17:54 +0300 Subject: [PATCH 024/856] Add CompatExtensions CompatExtensions contains extension functions for deprecated functions of Bundle and Intent. --- .../util/extensions/CompatExtensions.kt | 57 +++++++++++++++++++ .../imageeditor/utils/CompatExtensions.kt | 40 +++++++++++++ 2 files changed, 97 insertions(+) diff --git a/WordPress/src/main/java/org/wordpress/android/util/extensions/CompatExtensions.kt b/WordPress/src/main/java/org/wordpress/android/util/extensions/CompatExtensions.kt index 622eb8f7234f..9f695e3a5201 100644 --- a/WordPress/src/main/java/org/wordpress/android/util/extensions/CompatExtensions.kt +++ b/WordPress/src/main/java/org/wordpress/android/util/extensions/CompatExtensions.kt @@ -1,7 +1,12 @@ package org.wordpress.android.util.extensions +import android.content.Intent +import android.os.Build +import android.os.Bundle +import android.os.Parcelable import androidx.activity.OnBackPressedCallback import androidx.activity.OnBackPressedDispatcher +import java.io.Serializable /** * This is a temporary workaround for the issue described here: https://issuetracker.google.com/issues/247982487 @@ -18,3 +23,55 @@ fun OnBackPressedDispatcher.onBackPressedCompat(onBackPressedCallback: OnBackPre onBackPressed() onBackPressedCallback.isEnabled = true } + +/** + * TODO: Remove this when stable androidx.core 1.10 is released. Use IntentCompat instead. + */ +@Suppress("ForbiddenComment") +inline fun Intent.getParcelableExtraCompat(key: String): T? = + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) { + getParcelableExtra(key, T::class.java) + } else { + @Suppress("DEPRECATION") + getParcelableExtra(key) as T? + } + +inline fun Intent.getSerializableExtraCompat(key: String): T? = + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) { + getSerializableExtra(key, T::class.java) + } else { + @Suppress("DEPRECATION") + getSerializableExtra(key) as T? + } + +/** + * TODO: Remove this when stable androidx.core 1.10 is released. Use BundleCompat instead. + */ +@Suppress("ForbiddenComment") +inline fun Bundle.getParcelableCompat(key: String): T? = + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) { + getParcelable(key, T::class.java) + } else { + @Suppress("DEPRECATION") + getParcelable(key) + } + +/** + * TODO: Remove this when stable androidx.core 1.10 is released. Use IntentCompat instead. + */ +@Suppress("ForbiddenComment") +inline fun Bundle.getParcelableArrayListCompat(key: String): ArrayList? = + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) { + getParcelableArrayList(key, T::class.java) + } else { + @Suppress("DEPRECATION") + getParcelableArrayList(key) + } + +inline fun Bundle.getSerializableCompat(key: String): T? = + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) { + getSerializable(key, T::class.java) + } else { + @Suppress("DEPRECATION") + getSerializable(key) as T + } diff --git a/libs/image-editor/src/main/kotlin/org/wordpress/android/imageeditor/utils/CompatExtensions.kt b/libs/image-editor/src/main/kotlin/org/wordpress/android/imageeditor/utils/CompatExtensions.kt index db3b81fb7561..6acead63ae35 100644 --- a/libs/image-editor/src/main/kotlin/org/wordpress/android/imageeditor/utils/CompatExtensions.kt +++ b/libs/image-editor/src/main/kotlin/org/wordpress/android/imageeditor/utils/CompatExtensions.kt @@ -1,5 +1,9 @@ package org.wordpress.android.imageeditor.utils +import android.content.Intent +import android.os.Build +import android.os.Bundle +import android.os.Parcelable import androidx.activity.OnBackPressedCallback import androidx.activity.OnBackPressedDispatcher @@ -18,3 +22,39 @@ fun OnBackPressedDispatcher.onBackPressedCompat(onBackPressedCallback: OnBackPre onBackPressed() onBackPressedCallback.isEnabled = true } + +/** + * TODO: Remove this when stable androidx.core 1.10 is released. Use IntentCompat instead. + */ +@Suppress("ForbiddenComment") +inline fun Intent.getParcelableExtraCompat(key: String): T? = + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) { + getParcelableExtra(key, T::class.java) + } else { + @Suppress("DEPRECATION") + getParcelableExtra(key) as T? + } + +/** + * TODO: Remove this when stable androidx.core 1.10 is released. Use IntentCompat instead. + */ +@Suppress("ForbiddenComment") +inline fun Intent.getParcelableArrayListExtraCompat(key: String): ArrayList? = + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) { + getParcelableArrayListExtra(key, T::class.java) + } else { + @Suppress("DEPRECATION") + getParcelableArrayListExtra(key) + } + +/** + * TODO: Remove this when stable androidx.core 1.10 is released. Use BundleCompat instead. + */ +@Suppress("ForbiddenComment") +inline fun Bundle.getParcelableCompat(key: String): T? = + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) { + getParcelable(key, T::class.java) + } else { + @Suppress("DEPRECATION") + getParcelable(key) + } From 851a4489f738643754e89735cda6a6d97fea67ea Mon Sep 17 00:00:00 2001 From: Irfan Omur Date: Tue, 7 Mar 2023 20:18:25 +0300 Subject: [PATCH 025/856] Update deprecated functions of Intent and Bundle --- .../ui/JetpackRemoteInstallActivity.kt | 3 +- .../ui/JetpackRemoteInstallFragment.kt | 11 +++--- .../login/jetpack/LoginNoSitesViewModel.kt | 6 ++-- .../detail/ActivityLogDetailFragment.kt | 10 ++++-- .../list/ActivityLogListFragment.kt | 16 +++++---- .../android/ui/blaze/BlazeParentActivity.kt | 6 ++-- ...BloggingPromptsOnboardingDialogFragment.kt | 5 ++- .../BloggingRemindersViewModel.kt | 5 ++- .../unified/UnifiedCommentListFragment.kt | 3 +- .../unified/UnifiedCommentsEditActivity.kt | 7 ++-- .../unified/UnifiedCommentsEditFragment.kt | 6 ++-- .../DeepLinkingIntentReceiverViewModel.kt | 10 +++--- .../ui/domains/DomainRegistrationActivity.kt | 8 +++-- .../DomainRegistrationDetailsFragment.kt | 3 +- .../ui/domains/DomainSuggestionsFragment.kt | 8 +++-- .../ui/domains/DomainsDashboardFragment.kt | 3 +- .../engagement/EngagedPeopleListActivity.kt | 3 +- .../engagement/EngagedPeopleListFragment.kt | 7 ++-- .../ui/history/HistoryDetailActivity.kt | 3 +- .../ui/history/HistoryDetailFragment.kt | 5 +-- .../backup/download/BackupDownloadFragment.kt | 5 ++- .../download/BackupDownloadViewModel.kt | 3 +- .../ui/jetpack/restore/RestoreFragment.kt | 3 +- .../ui/jetpack/restore/RestoreViewModel.kt | 3 +- .../android/ui/jetpack/scan/ScanActivity.kt | 4 +-- .../android/ui/jetpack/scan/ScanFragment.kt | 9 +++-- .../scan/details/ThreatDetailsFragment.kt | 7 ++-- .../scan/history/ScanHistoryFragment.kt | 11 +++--- .../scan/history/ScanHistoryListFragment.kt | 12 ++++--- ...JetpackFeatureFullScreenOverlayFragment.kt | 14 ++++---- .../ui/layoutpicker/LayoutPickerViewModel.kt | 10 +++--- .../ui/layoutpicker/LayoutsRowViewHolder.kt | 3 +- .../migration/JetpackMigrationActivity.kt | 3 +- .../migration/JetpackMigrationFragment.kt | 3 +- .../ui/mediapicker/MediaPickerActivity.kt | 6 ++-- .../ui/mediapicker/MediaPickerFragment.kt | 9 +++-- .../QuickStartDynamicCardViewHolder.kt | 3 +- .../JetpackPoweredBottomSheetFragment.kt | 29 ++++++++-------- .../ui/mysite/tabs/MySiteTabFragment.kt | 3 +- .../DismissNotificationReceiver.kt | 3 +- .../android/ui/pages/PageListFragment.kt | 10 +++--- .../android/ui/pages/PageParentFragment.kt | 9 ++--- .../ui/pages/PageParentSearchFragment.kt | 3 +- .../android/ui/pages/PagesActivity.kt | 6 ++-- .../android/ui/pages/PagesFragment.kt | 18 ++++++---- .../android/ui/pages/SearchListFragment.kt | 3 +- .../ui/people/PeopleInviteDialogFragment.kt | 3 +- .../ui/photopicker/PhotoPickerFragment.kt | 10 ++++-- .../android/ui/plans/PlanDetailsFragment.kt | 5 +-- .../wordpress/android/ui/posts/BasicDialog.kt | 3 +- .../android/ui/posts/HistoryListFragment.kt | 4 ++- .../ui/posts/PostDatePickerDialogFragment.kt | 3 +- .../android/ui/posts/PostListFragment.kt | 6 ++-- ...tNotificationScheduleTimeDialogFragment.kt | 3 +- .../ui/posts/PostTimePickerDialogFragment.kt | 3 +- .../android/ui/posts/PostsListActivity.kt | 23 +++++++------ .../posts/PrepublishingAddCategoryFragment.kt | 3 +- .../posts/PrepublishingBottomSheetFragment.kt | 7 ++-- .../posts/PrepublishingCategoriesFragment.kt | 6 ++-- .../categories/list/CategoriesListFragment.kt | 9 +++-- .../QuickStartFullScreenDialogFragment.kt | 6 ++-- .../ui/reader/ReaderPostDetailFragment.kt | 17 ++++++---- .../ui/reader/SubfilterBottomSheetFragment.kt | 6 ++-- .../interests/ReaderInterestsFragment.kt | 3 +- .../discover/ReaderDiscoverService.kt | 3 +- .../reader/subfilter/SubfilterPageFragment.kt | 3 +- .../ui/sitecreation/SiteCreationMainVM.kt | 3 +- .../previews/SiteCreationPreviewFragment.kt | 3 +- .../previews/SitePreviewViewModel.kt | 3 +- .../services/SiteCreationService.kt | 3 +- .../ui/stats/StatsConnectJetpackActivity.kt | 11 ++++-- .../ui/stats/refresh/StatsViewAllFragment.kt | 34 +++++++++++-------- .../ui/stats/refresh/StatsViewModel.kt | 7 ++-- .../stats/refresh/lists/StatsListFragment.kt | 11 +++--- .../lists/detail/InsightsDetailFragment.kt | 8 +++-- .../lists/detail/StatsDetailActivity.kt | 4 ++- .../lists/detail/StatsDetailFragment.kt | 6 ++-- .../sections/granular/SelectedDateProvider.kt | 3 +- .../StoriesMediaPickerResultHandler.kt | 7 ++-- .../ui/stories/StoriesTrackerHelper.kt | 3 +- .../ui/stories/StoryComposerActivity.kt | 19 ++++++----- .../intro/StoriesIntroDialogFragment.kt | 3 +- .../media/StoryMediaSaveUploadBridge.kt | 3 +- .../ui/suggestion/SuggestionActivity.kt | 5 +-- .../plugins/PluginBrowserViewModel.kt | 3 +- .../jetpack/LoginNoSitesViewModelTest.kt | 5 +-- .../download/BackupDownloadViewModelTest.kt | 7 ++-- .../jetpack/restore/RestoreViewModelTest.kt | 3 +- .../ui/sitecreation/SiteCreationMainVMTest.kt | 7 ++-- .../previews/SitePreviewViewModelTest.kt | 13 +++---- .../android/imageeditor/crop/CropViewModel.kt | 6 ++-- .../preview/PreviewImageFragment.kt | 6 ++-- 92 files changed, 390 insertions(+), 242 deletions(-) diff --git a/WordPress/src/main/java/org/wordpress/android/ui/JetpackRemoteInstallActivity.kt b/WordPress/src/main/java/org/wordpress/android/ui/JetpackRemoteInstallActivity.kt index fbeaed7dbb3b..47bf1cd4f1ce 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/JetpackRemoteInstallActivity.kt +++ b/WordPress/src/main/java/org/wordpress/android/ui/JetpackRemoteInstallActivity.kt @@ -9,6 +9,7 @@ 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.onBackPressedCompat +import org.wordpress.android.util.extensions.getSerializableExtraCompat class JetpackRemoteInstallActivity : LocaleAwareActivity() { public override fun onCreate(savedInstanceState: Bundle?) { @@ -21,7 +22,7 @@ class JetpackRemoteInstallActivity : LocaleAwareActivity() { onBackPressedDispatcher.addCallback(this) { trackWithSource( INSTALL_JETPACK_CANCELLED, - intent.getSerializableExtra(TRACKING_SOURCE_KEY) as JetpackConnectionSource + intent.getSerializableExtraCompat(TRACKING_SOURCE_KEY) ) onBackPressedDispatcher.onBackPressedCompat(this) } diff --git a/WordPress/src/main/java/org/wordpress/android/ui/JetpackRemoteInstallFragment.kt b/WordPress/src/main/java/org/wordpress/android/ui/JetpackRemoteInstallFragment.kt index e12f6b5a29fd..73be72492857 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/JetpackRemoteInstallFragment.kt +++ b/WordPress/src/main/java/org/wordpress/android/ui/JetpackRemoteInstallFragment.kt @@ -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) { @@ -44,9 +46,10 @@ 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 = requireNotNull(intent.getSerializableExtraCompat(WordPress.SITE)) + val source = requireNotNull(intent.getSerializableExtraCompat(TRACKING_SOURCE_KEY)) + val retrievedState = + savedInstanceState?.getSerializableCompat(VIEW_STATE) viewModel = ViewModelProvider( this@JetpackRemoteInstallFragment, viewModelFactory ).get(JetpackRemoteInstallViewModel::class.java) @@ -139,7 +142,7 @@ class JetpackRemoteInstallFragment : Fragment(R.layout.jetpack_remote_install_fr override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) { super.onActivityResult(requestCode, resultCode, data) if (requestCode == JETPACK_LOGIN && resultCode == Activity.RESULT_OK) { - val site = requireActivity().intent!!.getSerializableExtra(WordPress.SITE) as SiteModel + val site = requireNotNull(activity?.intent?.getSerializableExtraCompat(WordPress.SITE)) viewModel.onLogin(site.id) } } diff --git a/WordPress/src/main/java/org/wordpress/android/ui/accounts/login/jetpack/LoginNoSitesViewModel.kt b/WordPress/src/main/java/org/wordpress/android/ui/accounts/login/jetpack/LoginNoSitesViewModel.kt index b879e5c0bc9f..a3f2ae9dc7b9 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/accounts/login/jetpack/LoginNoSitesViewModel.kt +++ b/WordPress/src/main/java/org/wordpress/android/ui/accounts/login/jetpack/LoginNoSitesViewModel.kt @@ -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 @@ -58,8 +59,9 @@ class LoginNoSitesViewModel @Inject constructor( _uiModel.postValue(UiModel(state = state)) } - private fun buildStateFromSavedInstanceState(savedInstanceState: Bundle) = - savedInstanceState.getSerializable(KEY_STATE) as State + private fun buildStateFromSavedInstanceState(savedInstanceState: Bundle) = requireNotNull( + savedInstanceState.getSerializableCompat(KEY_STATE) + ) private fun buildStateFromAccountStore() = accountStore.account?.let { diff --git a/WordPress/src/main/java/org/wordpress/android/ui/activitylog/detail/ActivityLogDetailFragment.kt b/WordPress/src/main/java/org/wordpress/android/ui/activitylog/detail/ActivityLogDetailFragment.kt index b542ce477863..36956d10766e 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/activitylog/detail/ActivityLogDetailFragment.kt +++ b/WordPress/src/main/java/org/wordpress/android/ui/activitylog/detail/ActivityLogDetailFragment.kt @@ -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 @@ -221,7 +223,9 @@ 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 = requireNotNull( + savedInstanceState.getSerializableCompat(WordPress.SITE) + ) val activityLogId = requireNotNull( savedInstanceState.getString( ACTIVITY_LOG_ID_KEY @@ -230,7 +234,9 @@ class ActivityLogDetailFragment : Fragment(R.layout.activity_log_item_detail) { site to activityLogId } intent != null -> { - val site = intent.getSerializableExtra(WordPress.SITE) as SiteModel + val site = requireNotNull( + intent.getSerializableExtraCompat(WordPress.SITE) + ) val activityLogId = intent.getStringExtra(ACTIVITY_LOG_ID_KEY) as String site to activityLogId } diff --git a/WordPress/src/main/java/org/wordpress/android/ui/activitylog/list/ActivityLogListFragment.kt b/WordPress/src/main/java/org/wordpress/android/ui/activitylog/list/ActivityLogListFragment.kt index 473037a21c0b..4263b8444580 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/activitylog/list/ActivityLogListFragment.kt +++ b/WordPress/src/main/java/org/wordpress/android/ui/activitylog/list/ActivityLogListFragment.kt @@ -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 @@ -87,12 +89,14 @@ class ActivityLogListFragment : Fragment(R.layout.activity_log_list_fragment) { } } - val site = if (savedInstanceState == null) { - val nonNullIntent = checkNotNull(nonNullActivity.intent) - nonNullIntent.getSerializableExtra(WordPress.SITE) as SiteModel - } else { - savedInstanceState.getSerializable(WordPress.SITE) as SiteModel - } + val site: SiteModel = requireNotNull( + if (savedInstanceState == null) { + val nonNullIntent = checkNotNull(nonNullActivity.intent) + nonNullIntent.getSerializableExtraCompat(WordPress.SITE) + } else { + savedInstanceState.getSerializableCompat(WordPress.SITE) + } + ) val rewindableOnly = nonNullActivity.intent.getBooleanExtra(ACTIVITY_LOG_REWINDABLE_ONLY_KEY, false) logListView.setEmptyView(actionableEmptyView) diff --git a/WordPress/src/main/java/org/wordpress/android/ui/blaze/BlazeParentActivity.kt b/WordPress/src/main/java/org/wordpress/android/ui/blaze/BlazeParentActivity.kt index dcddc767ea3c..031fdf84bf64 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/blaze/BlazeParentActivity.kt +++ b/WordPress/src/main/java/org/wordpress/android/ui/blaze/BlazeParentActivity.kt @@ -8,6 +8,8 @@ import org.wordpress.android.R import org.wordpress.android.ui.blaze.ui.blazeoverlay.BlazeOverlayFragment import org.wordpress.android.ui.blaze.ui.blazeoverlay.BlazeViewModel import org.wordpress.android.ui.blaze.ui.blazewebview.BlazeWebViewFragment +import org.wordpress.android.util.extensions.getParcelableExtraCompat +import org.wordpress.android.util.extensions.getSerializableExtraCompat const val ARG_EXTRA_BLAZE_UI_MODEL = "blaze_ui_model" const val ARG_BLAZE_FLOW_SOURCE = "blaze_flow_source" @@ -45,10 +47,10 @@ class BlazeParentActivity : AppCompatActivity() { } private fun getSource(): BlazeFlowSource { - return intent.getSerializableExtra(ARG_BLAZE_FLOW_SOURCE) as BlazeFlowSource + return requireNotNull(intent.getSerializableExtraCompat(ARG_BLAZE_FLOW_SOURCE)) } private fun getBlazeUiModel(): BlazeUIModel? { - return intent.getParcelableExtra(ARG_EXTRA_BLAZE_UI_MODEL) + return intent.getParcelableExtraCompat(ARG_EXTRA_BLAZE_UI_MODEL) } } diff --git a/WordPress/src/main/java/org/wordpress/android/ui/bloggingprompts/onboarding/BloggingPromptsOnboardingDialogFragment.kt b/WordPress/src/main/java/org/wordpress/android/ui/bloggingprompts/onboarding/BloggingPromptsOnboardingDialogFragment.kt index 7771b6f351bc..74f0b2edc958 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/bloggingprompts/onboarding/BloggingPromptsOnboardingDialogFragment.kt +++ b/WordPress/src/main/java/org/wordpress/android/ui/bloggingprompts/onboarding/BloggingPromptsOnboardingDialogFragment.kt @@ -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 @@ -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?.let { dialogType = requireNotNull(it.getSerializableCompat(KEY_DIALOG_TYPE)) } (requireActivity().applicationContext as WordPress).component().inject(this) if (dialogType == ONBOARDING && context !is BloggingPromptsReminderSchedulerListener) { throw IllegalStateException( diff --git a/WordPress/src/main/java/org/wordpress/android/ui/bloggingreminders/BloggingRemindersViewModel.kt b/WordPress/src/main/java/org/wordpress/android/ui/bloggingreminders/BloggingRemindersViewModel.kt index 0d84aa28fba8..9ee9631943b7 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/bloggingreminders/BloggingRemindersViewModel.kt +++ b/WordPress/src/main/java/org/wordpress/android/ui/bloggingreminders/BloggingRemindersViewModel.kt @@ -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 @@ -220,9 +221,7 @@ class BloggingRemindersViewModel @Inject constructor( } fun restoreState(state: Bundle) { - state.getSerializable(SELECTED_SCREEN)?.let { - _selectedScreen.value = it as Screen - } + state.getSerializableCompat(SELECTED_SCREEN)?.let { _selectedScreen.value = it } val siteId = state.getInt(SITE_ID) if (siteId != 0) { val enabledDays = state.getStringArrayList(SELECTED_DAYS)?.map { DayOfWeek.valueOf(it) }?.toSet() ?: setOf() diff --git a/WordPress/src/main/java/org/wordpress/android/ui/comments/unified/UnifiedCommentListFragment.kt b/WordPress/src/main/java/org/wordpress/android/ui/comments/unified/UnifiedCommentListFragment.kt index 67259b28128d..3cdace123e93 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/comments/unified/UnifiedCommentListFragment.kt +++ b/WordPress/src/main/java/org/wordpress/android/ui/comments/unified/UnifiedCommentListFragment.kt @@ -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 @@ -76,7 +77,7 @@ class UnifiedCommentListFragment : Fragment(R.layout.unified_comment_list_fragme viewModelFactory ).get(UnifiedCommentActivityViewModel::class.java) arguments?.let { - commentListFilter = it.getSerializable(KEY_COMMENT_LIST_FILTER) as CommentFilter + commentListFilter = requireNotNull(it.getSerializableCompat(KEY_COMMENT_LIST_FILTER)) } } diff --git a/WordPress/src/main/java/org/wordpress/android/ui/comments/unified/UnifiedCommentsEditActivity.kt b/WordPress/src/main/java/org/wordpress/android/ui/comments/unified/UnifiedCommentsEditActivity.kt index 807718b2c3a3..0b1dc7c9c0c1 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/comments/unified/UnifiedCommentsEditActivity.kt +++ b/WordPress/src/main/java/org/wordpress/android/ui/comments/unified/UnifiedCommentsEditActivity.kt @@ -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?) { @@ -17,8 +19,9 @@ class UnifiedCommentsEditActivity : LocaleAwareActivity() { setContentView(root) } - val site = intent.getSerializableExtra(WordPress.SITE) as SiteModel - val commentIdentifier = requireNotNull(intent.getParcelableExtra(KEY_COMMENT_IDENTIFIER)) + val site = requireNotNull(intent.getSerializableExtraCompat(WordPress.SITE)) + val commentIdentifier = + requireNotNull(intent.getParcelableExtraCompat(KEY_COMMENT_IDENTIFIER)) val fm = supportFragmentManager var editCommentFragment = fm.findFragmentByTag( diff --git a/WordPress/src/main/java/org/wordpress/android/ui/comments/unified/UnifiedCommentsEditFragment.kt b/WordPress/src/main/java/org/wordpress/android/ui/comments/unified/UnifiedCommentsEditFragment.kt index 420febb10266..ef7b77c16434 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/comments/unified/UnifiedCommentsEditFragment.kt +++ b/WordPress/src/main/java/org/wordpress/android/ui/comments/unified/UnifiedCommentsEditFragment.kt @@ -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 @@ -61,9 +63,9 @@ 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 = requireNotNull(arguments?.getSerializableCompat(WordPress.SITE)) val commentIdentifier = requireNotNull( - requireArguments().getParcelable( + requireArguments().getParcelableCompat( KEY_COMMENT_IDENTIFIER ) ) diff --git a/WordPress/src/main/java/org/wordpress/android/ui/deeplinks/DeepLinkingIntentReceiverViewModel.kt b/WordPress/src/main/java/org/wordpress/android/ui/deeplinks/DeepLinkingIntentReceiverViewModel.kt index 1d9c7c6e06c1..978c941d4251 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/deeplinks/DeepLinkingIntentReceiverViewModel.kt +++ b/WordPress/src/main/java/org/wordpress/android/ui/deeplinks/DeepLinkingIntentReceiverViewModel.kt @@ -20,6 +20,7 @@ import org.wordpress.android.ui.deeplinks.handlers.DeepLinkHandlers import org.wordpress.android.ui.deeplinks.handlers.ServerTrackingHandler import org.wordpress.android.util.UriWrapper import org.wordpress.android.util.analytics.AnalyticsUtilsWrapper +import org.wordpress.android.util.extensions.getParcelableCompat import org.wordpress.android.viewmodel.Event import org.wordpress.android.viewmodel.ScopedViewModel import javax.inject.Inject @@ -147,12 +148,11 @@ class DeepLinkingIntentReceiverViewModel private fun extractSavedInstanceStateIfNeeded(savedInstanceState: Bundle?) { savedInstanceState?.let { - val uri: Uri? = savedInstanceState.getParcelable(URI_KEY) + val uri = savedInstanceState.getParcelableCompat(URI_KEY) uriWrapper = uri?.let { UriWrapper(it) } - deepLinkEntryPoint = - DeepLinkEntryPoint.valueOf( - savedInstanceState.getString(DEEP_LINK_ENTRY_POINT_KEY, DeepLinkEntryPoint.DEFAULT.name) - ) + deepLinkEntryPoint = DeepLinkEntryPoint.valueOf( + savedInstanceState.getString(DEEP_LINK_ENTRY_POINT_KEY, DeepLinkEntryPoint.DEFAULT.name) + ) } } diff --git a/WordPress/src/main/java/org/wordpress/android/ui/domains/DomainRegistrationActivity.kt b/WordPress/src/main/java/org/wordpress/android/ui/domains/DomainRegistrationActivity.kt index f600c249e07b..e9e56dbf80fc 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/domains/DomainRegistrationActivity.kt +++ b/WordPress/src/main/java/org/wordpress/android/ui/domains/DomainRegistrationActivity.kt @@ -17,6 +17,7 @@ import org.wordpress.android.ui.domains.DomainRegistrationNavigationAction.OpenD import org.wordpress.android.ui.domains.DomainRegistrationNavigationAction.OpenDomainRegistrationDetails import org.wordpress.android.ui.domains.DomainRegistrationNavigationAction.OpenDomainRegistrationResult import org.wordpress.android.ui.domains.DomainRegistrationNavigationAction.OpenDomainSuggestions +import org.wordpress.android.util.extensions.getSerializableExtraCompat import org.wordpress.android.viewmodel.observeEvent import javax.inject.Inject @@ -50,9 +51,10 @@ class DomainRegistrationActivity : LocaleAwareActivity(), ScrollableViewInitiali setContentView(root) binding = this - val site = intent.getSerializableExtra(WordPress.SITE) as SiteModel - val domainRegistrationPurpose = intent.getSerializableExtra(DOMAIN_REGISTRATION_PURPOSE_KEY) - as DomainRegistrationPurpose + val site = requireNotNull(intent.getSerializableExtraCompat(WordPress.SITE)) + val domainRegistrationPurpose = requireNotNull( + intent.getSerializableExtraCompat(DOMAIN_REGISTRATION_PURPOSE_KEY) + ) setupToolbar() setupViewModel(site, domainRegistrationPurpose) diff --git a/WordPress/src/main/java/org/wordpress/android/ui/domains/DomainRegistrationDetailsFragment.kt b/WordPress/src/main/java/org/wordpress/android/ui/domains/DomainRegistrationDetailsFragment.kt index 459c93964a19..b0391271d8bd 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/domains/DomainRegistrationDetailsFragment.kt +++ b/WordPress/src/main/java/org/wordpress/android/ui/domains/DomainRegistrationDetailsFragment.kt @@ -47,6 +47,7 @@ import org.wordpress.android.ui.domains.DomainRegistrationDetailsViewModel.Domai import org.wordpress.android.util.StringUtils import org.wordpress.android.util.ToastUtils import org.wordpress.android.util.WPUrlUtils +import org.wordpress.android.util.extensions.getSerializableExtraCompat import javax.inject.Inject class DomainRegistrationDetailsFragment : Fragment() { @@ -100,7 +101,7 @@ class DomainRegistrationDetailsFragment : Fragment() { val domainProductDetails = requireNotNull( arguments?.getParcelable(EXTRA_DOMAIN_PRODUCT_DETAILS) ) - val site = requireActivity().intent?.getSerializableExtra(WordPress.SITE) as SiteModel + val site = requireNotNull(activity?.intent?.getSerializableExtraCompat(WordPress.SITE)) viewModel.start(site, domainProductDetails) diff --git a/WordPress/src/main/java/org/wordpress/android/ui/domains/DomainSuggestionsFragment.kt b/WordPress/src/main/java/org/wordpress/android/ui/domains/DomainSuggestionsFragment.kt index 09d64744f0b1..8354c8d5ae17 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/domains/DomainSuggestionsFragment.kt +++ b/WordPress/src/main/java/org/wordpress/android/ui/domains/DomainSuggestionsFragment.kt @@ -18,6 +18,7 @@ import org.wordpress.android.ui.ScrollableViewInitializedListener import org.wordpress.android.ui.domains.DomainRegistrationActivity.Companion.DOMAIN_REGISTRATION_PURPOSE_KEY import org.wordpress.android.ui.domains.DomainRegistrationActivity.DomainRegistrationPurpose import org.wordpress.android.util.ToastUtils +import org.wordpress.android.util.extensions.getSerializableExtraCompat import org.wordpress.android.viewmodel.observeEvent import javax.inject.Inject @@ -46,9 +47,10 @@ class DomainSuggestionsFragment : Fragment(R.layout.domain_suggestions_fragment) with(DomainSuggestionsFragmentBinding.bind(view)) { val intent = requireActivity().intent - val site = intent.getSerializableExtra(WordPress.SITE) as SiteModel - val domainRegistrationPurpose = intent.getSerializableExtra(DOMAIN_REGISTRATION_PURPOSE_KEY) - as DomainRegistrationPurpose + val site = requireNotNull(intent.getSerializableExtraCompat(WordPress.SITE)) + val domainRegistrationPurpose = requireNotNull( + intent.getSerializableExtraCompat(DOMAIN_REGISTRATION_PURPOSE_KEY) + ) setupViews() setupObservers() diff --git a/WordPress/src/main/java/org/wordpress/android/ui/domains/DomainsDashboardFragment.kt b/WordPress/src/main/java/org/wordpress/android/ui/domains/DomainsDashboardFragment.kt index b656a32509b2..f48f58315d33 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/domains/DomainsDashboardFragment.kt +++ b/WordPress/src/main/java/org/wordpress/android/ui/domains/DomainsDashboardFragment.kt @@ -18,6 +18,7 @@ import org.wordpress.android.ui.domains.DomainRegistrationActivity.DomainRegistr import org.wordpress.android.ui.domains.DomainsDashboardNavigationAction.ClaimDomain import org.wordpress.android.ui.domains.DomainsDashboardNavigationAction.GetDomain import org.wordpress.android.ui.utils.UiHelpers +import org.wordpress.android.util.extensions.getSerializableExtraCompat import org.wordpress.android.viewmodel.observeEvent import javax.inject.Inject @@ -46,7 +47,7 @@ class DomainsDashboardFragment : Fragment(R.layout.domains_dashboard_fragment) { private fun setupViewModel() { val intent = requireActivity().intent - val site = intent.getSerializableExtra(WordPress.SITE) as SiteModel + val site = requireNotNull(intent.getSerializableExtraCompat(WordPress.SITE)) viewModel = ViewModelProvider(requireActivity(), viewModelFactory).get(DomainsDashboardViewModel::class.java) viewModel.start(site) } diff --git a/WordPress/src/main/java/org/wordpress/android/ui/engagement/EngagedPeopleListActivity.kt b/WordPress/src/main/java/org/wordpress/android/ui/engagement/EngagedPeopleListActivity.kt index d8c90a366bc5..36c4417a872a 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/engagement/EngagedPeopleListActivity.kt +++ b/WordPress/src/main/java/org/wordpress/android/ui/engagement/EngagedPeopleListActivity.kt @@ -7,6 +7,7 @@ import org.wordpress.android.WordPress import org.wordpress.android.databinding.EngagedPeopleListActivityBinding import org.wordpress.android.ui.LocaleAwareActivity import org.wordpress.android.util.analytics.AnalyticsUtilsWrapper +import org.wordpress.android.util.extensions.getParcelableExtraCompat import javax.inject.Inject class EngagedPeopleListActivity : LocaleAwareActivity() { @@ -22,7 +23,7 @@ class EngagedPeopleListActivity : LocaleAwareActivity() { setSupportActionBar(toolbarMain) } - val listScenario = intent.getParcelableExtra(KEY_LIST_SCENARIO) + val listScenario = intent.getParcelableExtraCompat(KEY_LIST_SCENARIO) ?: throw IllegalArgumentException( "List Scenario cannot be null. Make sure to pass a valid List Scenario in the intent" ) diff --git a/WordPress/src/main/java/org/wordpress/android/ui/engagement/EngagedPeopleListFragment.kt b/WordPress/src/main/java/org/wordpress/android/ui/engagement/EngagedPeopleListFragment.kt index fb0b3bbbed83..3b2d0af7fbf3 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/engagement/EngagedPeopleListFragment.kt +++ b/WordPress/src/main/java/org/wordpress/android/ui/engagement/EngagedPeopleListFragment.kt @@ -39,6 +39,7 @@ import org.wordpress.android.util.SnackbarItem.Info import org.wordpress.android.util.SnackbarSequencer import org.wordpress.android.util.WPUrlUtils import org.wordpress.android.util.analytics.AnalyticsUtilsWrapper +import org.wordpress.android.util.extensions.getParcelableCompat import org.wordpress.android.util.image.ImageManager import org.wordpress.android.viewmodel.ResourceProvider import org.wordpress.android.viewmodel.observeEvent @@ -93,11 +94,11 @@ class EngagedPeopleListFragment : Fragment() { loadingView = view.findViewById(R.id.loading_view) emptyView = view.findViewById(R.id.actionable_empty_view) - val listScenario = requireArguments().getParcelable(KEY_LIST_SCENARIO) + val listScenario = requireNotNull(arguments?.getParcelableCompat(KEY_LIST_SCENARIO)) val layoutManager = LinearLayoutManager(activity) - savedInstanceState?.getParcelable(KEY_LIST_STATE)?.let { + savedInstanceState?.getParcelableCompat(KEY_LIST_STATE)?.let { layoutManager.onRestoreInstanceState(it) } @@ -144,7 +145,7 @@ class EngagedPeopleListFragment : Fragment() { manageServiceRequest(serviceRequest) }) - viewModel.start(listScenario!!) + viewModel.start(listScenario) } @Suppress("ForbiddenComment") diff --git a/WordPress/src/main/java/org/wordpress/android/ui/history/HistoryDetailActivity.kt b/WordPress/src/main/java/org/wordpress/android/ui/history/HistoryDetailActivity.kt index 7610f74109d1..09f053a4982a 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/history/HistoryDetailActivity.kt +++ b/WordPress/src/main/java/org/wordpress/android/ui/history/HistoryDetailActivity.kt @@ -8,6 +8,7 @@ import org.wordpress.android.analytics.AnalyticsTracker.Stat import org.wordpress.android.databinding.HistoryDetailActivityBinding import org.wordpress.android.ui.LocaleAwareActivity import org.wordpress.android.ui.history.HistoryListItem.Revision +import org.wordpress.android.util.extensions.getParcelableCompat import org.wordpress.android.util.extensions.onBackPressedCompat class HistoryDetailActivity : LocaleAwareActivity() { @@ -30,7 +31,7 @@ class HistoryDetailActivity : LocaleAwareActivity() { supportActionBar?.setDisplayHomeAsUpEnabled(true) val extras = requireNotNull(intent.extras) - val revision = extras.getParcelable(HistoryDetailContainerFragment.EXTRA_CURRENT_REVISION) + val revision = extras.getParcelableCompat(HistoryDetailContainerFragment.EXTRA_CURRENT_REVISION) val previousRevisionsIds = extras.getLongArray(HistoryDetailContainerFragment.EXTRA_PREVIOUS_REVISIONS_IDS) val postId = extras.getLong(HistoryDetailContainerFragment.EXTRA_POST_ID) diff --git a/WordPress/src/main/java/org/wordpress/android/ui/history/HistoryDetailFragment.kt b/WordPress/src/main/java/org/wordpress/android/ui/history/HistoryDetailFragment.kt index 3b1db67f62cc..64c8a4072b0c 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/history/HistoryDetailFragment.kt +++ b/WordPress/src/main/java/org/wordpress/android/ui/history/HistoryDetailFragment.kt @@ -7,6 +7,7 @@ import android.view.ViewGroup import androidx.fragment.app.Fragment import org.wordpress.android.R import org.wordpress.android.ui.history.HistoryListItem.Revision +import org.wordpress.android.util.extensions.getParcelableCompat import org.wordpress.android.widgets.DiffView class HistoryDetailFragment : Fragment() { @@ -16,9 +17,9 @@ class HistoryDetailFragment : Fragment() { super.onCreate(savedInstanceState) mRevision = if (savedInstanceState != null) { - savedInstanceState.getParcelable(KEY_REVISION) + savedInstanceState.getParcelableCompat(KEY_REVISION) } else { - arguments?.getParcelable(EXTRA_REVISION) + arguments?.getParcelableCompat(EXTRA_REVISION) } } diff --git a/WordPress/src/main/java/org/wordpress/android/ui/jetpack/backup/download/BackupDownloadFragment.kt b/WordPress/src/main/java/org/wordpress/android/ui/jetpack/backup/download/BackupDownloadFragment.kt index a657dabf573f..fa2374243cf6 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/jetpack/backup/download/BackupDownloadFragment.kt +++ b/WordPress/src/main/java/org/wordpress/android/ui/jetpack/backup/download/BackupDownloadFragment.kt @@ -27,6 +27,7 @@ import org.wordpress.android.ui.pages.SnackbarMessageHolder import org.wordpress.android.ui.utils.UiHelpers import org.wordpress.android.util.AppLog import org.wordpress.android.util.AppLog.T +import org.wordpress.android.util.extensions.getSerializableCompat import org.wordpress.android.util.image.ImageManager import org.wordpress.android.viewmodel.observeEvent import org.wordpress.android.widgets.WPSnackbar @@ -79,7 +80,9 @@ class BackupDownloadFragment : Fragment(R.layout.jetpack_backup_restore_fragment val (site, activityId) = when { requireActivity().intent?.extras != null -> { - val site = requireNotNull(requireActivity().intent.extras).getSerializable(WordPress.SITE) as SiteModel + val site = requireNotNull( + requireActivity().intent.extras?.getSerializableCompat(WordPress.SITE) + ) val activityId = requireNotNull(requireActivity().intent.extras).getString( KEY_BACKUP_DOWNLOAD_ACTIVITY_ID_KEY ) as String diff --git a/WordPress/src/main/java/org/wordpress/android/ui/jetpack/backup/download/BackupDownloadViewModel.kt b/WordPress/src/main/java/org/wordpress/android/ui/jetpack/backup/download/BackupDownloadViewModel.kt index 3ea0109e2d30..cbbefc8ec3e5 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/jetpack/backup/download/BackupDownloadViewModel.kt +++ b/WordPress/src/main/java/org/wordpress/android/ui/jetpack/backup/download/BackupDownloadViewModel.kt @@ -58,6 +58,7 @@ import org.wordpress.android.ui.jetpack.usecases.GetActivityLogItemUseCase import org.wordpress.android.ui.pages.SnackbarMessageHolder import org.wordpress.android.ui.utils.UiString.UiStringRes import org.wordpress.android.ui.utils.UiString.UiStringText +import org.wordpress.android.util.extensions.getParcelableCompat import org.wordpress.android.util.text.PercentFormatter import org.wordpress.android.util.wizard.WizardManager import org.wordpress.android.util.wizard.WizardNavigationTarget @@ -139,7 +140,7 @@ class BackupDownloadViewModel @Inject constructor( // Show the next step only if it's a fresh activity so we can handle the navigation wizardManager.showNextStep() } else { - backupDownloadState = requireNotNull(savedInstanceState.getParcelable(KEY_BACKUP_DOWNLOAD_STATE)) + backupDownloadState = requireNotNull(savedInstanceState.getParcelableCompat(KEY_BACKUP_DOWNLOAD_STATE)) val currentStepIndex = savedInstanceState.getInt(KEY_BACKUP_DOWNLOAD_CURRENT_STEP) wizardManager.setCurrentStepIndex(currentStepIndex) } diff --git a/WordPress/src/main/java/org/wordpress/android/ui/jetpack/restore/RestoreFragment.kt b/WordPress/src/main/java/org/wordpress/android/ui/jetpack/restore/RestoreFragment.kt index 9d86d8b074b4..65b526d4d52c 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/jetpack/restore/RestoreFragment.kt +++ b/WordPress/src/main/java/org/wordpress/android/ui/jetpack/restore/RestoreFragment.kt @@ -27,6 +27,7 @@ import org.wordpress.android.ui.pages.SnackbarMessageHolder import org.wordpress.android.ui.utils.UiHelpers import org.wordpress.android.util.AppLog import org.wordpress.android.util.AppLog.T +import org.wordpress.android.util.extensions.getSerializableCompat import org.wordpress.android.util.image.ImageManager import org.wordpress.android.viewmodel.observeEvent import org.wordpress.android.widgets.WPSnackbar @@ -73,7 +74,7 @@ class RestoreFragment : Fragment(R.layout.jetpack_backup_restore_fragment) { val (site, activityId) = when { requireActivity().intent?.extras != null -> { - val site = requireNotNull(requireActivity().intent.extras).getSerializable(WordPress.SITE) as SiteModel + val site = requireNotNull(activity?.intent?.extras?.getSerializableCompat(WordPress.SITE)) val activityId = requireNotNull(requireActivity().intent.extras).getString( KEY_RESTORE_ACTIVITY_ID_KEY ) as String diff --git a/WordPress/src/main/java/org/wordpress/android/ui/jetpack/restore/RestoreViewModel.kt b/WordPress/src/main/java/org/wordpress/android/ui/jetpack/restore/RestoreViewModel.kt index 39f3d2422fea..744e81f45b16 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/jetpack/restore/RestoreViewModel.kt +++ b/WordPress/src/main/java/org/wordpress/android/ui/jetpack/restore/RestoreViewModel.kt @@ -61,6 +61,7 @@ import org.wordpress.android.ui.jetpack.usecases.GetActivityLogItemUseCase import org.wordpress.android.ui.pages.SnackbarMessageHolder import org.wordpress.android.ui.utils.UiString.UiStringRes import org.wordpress.android.ui.utils.UiString.UiStringText +import org.wordpress.android.util.extensions.getParcelableCompat import org.wordpress.android.util.text.PercentFormatter import org.wordpress.android.util.wizard.WizardManager import org.wordpress.android.util.wizard.WizardNavigationTarget @@ -142,7 +143,7 @@ class RestoreViewModel @Inject constructor( // Show the next step only if it's a fresh activity so we can handle the navigation wizardManager.showNextStep() } else { - restoreState = requireNotNull(savedInstanceState.getParcelable(KEY_RESTORE_STATE)) + restoreState = requireNotNull(savedInstanceState.getParcelableCompat(KEY_RESTORE_STATE)) val currentStepIndex = savedInstanceState.getInt(KEY_RESTORE_CURRENT_STEP) wizardManager.setCurrentStepIndex(currentStepIndex) } diff --git a/WordPress/src/main/java/org/wordpress/android/ui/jetpack/scan/ScanActivity.kt b/WordPress/src/main/java/org/wordpress/android/ui/jetpack/scan/ScanActivity.kt index 2c6a78bd5ef3..5cad6f80f220 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/jetpack/scan/ScanActivity.kt +++ b/WordPress/src/main/java/org/wordpress/android/ui/jetpack/scan/ScanActivity.kt @@ -11,13 +11,13 @@ import dagger.hilt.android.AndroidEntryPoint import org.wordpress.android.R import org.wordpress.android.WordPress import org.wordpress.android.databinding.ScanActivityBinding -import org.wordpress.android.fluxc.model.SiteModel import org.wordpress.android.ui.ActivityLauncher import org.wordpress.android.ui.ScrollableViewInitializedListener import org.wordpress.android.ui.mysite.jetpackbadge.JetpackPoweredBottomSheetFragment import org.wordpress.android.ui.utils.UiHelpers import org.wordpress.android.util.JetpackBrandingUtils import org.wordpress.android.models.JetpackPoweredScreen +import org.wordpress.android.util.extensions.getSerializableExtraCompat import javax.inject.Inject @AndroidEntryPoint @@ -87,7 +87,7 @@ class ScanActivity : AppCompatActivity(), ScrollableViewInitializedListener { return true } else if (item.itemId == R.id.menu_scan_history) { // todo malinjir is it worth introducing a vm? - ActivityLauncher.viewScanHistory(this, intent.getSerializableExtra(WordPress.SITE) as SiteModel) + ActivityLauncher.viewScanHistory(this, intent.getSerializableExtraCompat(WordPress.SITE)) } return super.onOptionsItemSelected(item) } diff --git a/WordPress/src/main/java/org/wordpress/android/ui/jetpack/scan/ScanFragment.kt b/WordPress/src/main/java/org/wordpress/android/ui/jetpack/scan/ScanFragment.kt index eda56fb2aa2c..3aee277c80f5 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/jetpack/scan/ScanFragment.kt +++ b/WordPress/src/main/java/org/wordpress/android/ui/jetpack/scan/ScanFragment.kt @@ -30,6 +30,8 @@ import org.wordpress.android.ui.pages.SnackbarMessageHolder import org.wordpress.android.ui.prefs.EmptyViewRecyclerView import org.wordpress.android.ui.utils.UiHelpers import org.wordpress.android.util.ColorUtils +import org.wordpress.android.util.extensions.getSerializableCompat +import org.wordpress.android.util.extensions.getSerializableExtraCompat import org.wordpress.android.util.image.ImageManager import org.wordpress.android.viewmodel.observeEvent import org.wordpress.android.widgets.WPSnackbar @@ -175,11 +177,12 @@ class ScanFragment : Fragment(R.layout.scan_fragment) { } private fun getSite(savedInstanceState: Bundle?): SiteModel { - return if (savedInstanceState == null) { - requireActivity().intent.getSerializableExtra(WordPress.SITE) as SiteModel + val site: SiteModel? = if (savedInstanceState == null) { + requireActivity().intent.getSerializableExtraCompat(WordPress.SITE) } else { - savedInstanceState.getSerializable(WordPress.SITE) as SiteModel + savedInstanceState.getSerializableCompat(WordPress.SITE) } + return requireNotNull(site) } override fun onSaveInstanceState(outState: Bundle) { diff --git a/WordPress/src/main/java/org/wordpress/android/ui/jetpack/scan/details/ThreatDetailsFragment.kt b/WordPress/src/main/java/org/wordpress/android/ui/jetpack/scan/details/ThreatDetailsFragment.kt index 9aa46a8794ed..3f276480ed22 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/jetpack/scan/details/ThreatDetailsFragment.kt +++ b/WordPress/src/main/java/org/wordpress/android/ui/jetpack/scan/details/ThreatDetailsFragment.kt @@ -22,6 +22,7 @@ import org.wordpress.android.ui.jetpack.scan.details.ThreatDetailsViewModel.UiSt import org.wordpress.android.ui.jetpack.scan.details.adapters.ThreatDetailsAdapter import org.wordpress.android.ui.pages.SnackbarMessageHolder import org.wordpress.android.ui.utils.UiHelpers +import org.wordpress.android.util.extensions.getSerializableCompat import org.wordpress.android.util.image.ImageManager import org.wordpress.android.viewmodel.observeEvent import org.wordpress.android.widgets.WPSnackbar @@ -85,13 +86,11 @@ class ThreatDetailsFragment : Fragment(R.layout.threat_details_fragment) { is OpenThreatActionDialog -> showThreatActionDialog(events) is ShowUpdatedScanStateWithMessage -> { - val site = requireNotNull(requireActivity().intent.extras) - .getSerializable(WordPress.SITE) as SiteModel + val site = requireNotNull(activity?.intent?.extras).getSerializableCompat(WordPress.SITE) ActivityLauncher.viewScanRequestScanState(requireActivity(), site, events.messageRes) } is ShowUpdatedFixState -> { - val site = requireNotNull(requireActivity().intent.extras) - .getSerializable(WordPress.SITE) as SiteModel + val site = requireNotNull(activity?.intent?.extras).getSerializableCompat(WordPress.SITE) ActivityLauncher.viewScanRequestFixState(requireActivity(), site, events.threatId) } is ShowGetFreeEstimate -> { diff --git a/WordPress/src/main/java/org/wordpress/android/ui/jetpack/scan/history/ScanHistoryFragment.kt b/WordPress/src/main/java/org/wordpress/android/ui/jetpack/scan/history/ScanHistoryFragment.kt index a099bc760a6d..3316fa00e20c 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/jetpack/scan/history/ScanHistoryFragment.kt +++ b/WordPress/src/main/java/org/wordpress/android/ui/jetpack/scan/history/ScanHistoryFragment.kt @@ -20,6 +20,7 @@ import org.wordpress.android.WordPress import org.wordpress.android.databinding.FullscreenErrorWithRetryBinding import org.wordpress.android.databinding.ScanHistoryFragmentBinding import org.wordpress.android.fluxc.model.SiteModel +import org.wordpress.android.models.JetpackPoweredScreen import org.wordpress.android.ui.ScrollableViewInitializedListener import org.wordpress.android.ui.jetpack.scan.history.ScanHistoryViewModel.TabUiState import org.wordpress.android.ui.jetpack.scan.history.ScanHistoryViewModel.UiState.ContentUiState @@ -27,8 +28,9 @@ import org.wordpress.android.ui.jetpack.scan.history.ScanHistoryViewModel.UiStat import org.wordpress.android.ui.mysite.jetpackbadge.JetpackPoweredBottomSheetFragment import org.wordpress.android.ui.utils.UiHelpers import org.wordpress.android.util.JetpackBrandingUtils -import org.wordpress.android.models.JetpackPoweredScreen import org.wordpress.android.util.LocaleManagerWrapper +import org.wordpress.android.util.extensions.getSerializableCompat +import org.wordpress.android.util.extensions.getSerializableExtraCompat import javax.inject.Inject @AndroidEntryPoint @@ -121,11 +123,12 @@ class ScanHistoryFragment : Fragment(R.layout.scan_history_fragment), MenuProvid } private fun getSite(savedInstanceState: Bundle?): SiteModel { - return if (savedInstanceState == null) { - requireActivity().intent.getSerializableExtra(WordPress.SITE) as SiteModel + val site: SiteModel? = if (savedInstanceState == null) { + requireActivity().intent.getSerializableExtraCompat(WordPress.SITE) } else { - savedInstanceState.getSerializable(WordPress.SITE) as SiteModel + savedInstanceState.getSerializableCompat(WordPress.SITE) } + return requireNotNull(site) } override fun onSaveInstanceState(outState: Bundle) { diff --git a/WordPress/src/main/java/org/wordpress/android/ui/jetpack/scan/history/ScanHistoryListFragment.kt b/WordPress/src/main/java/org/wordpress/android/ui/jetpack/scan/history/ScanHistoryListFragment.kt index 65346ae58a5d..7687cdb59fc0 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/jetpack/scan/history/ScanHistoryListFragment.kt +++ b/WordPress/src/main/java/org/wordpress/android/ui/jetpack/scan/history/ScanHistoryListFragment.kt @@ -17,6 +17,9 @@ import org.wordpress.android.ui.jetpack.scan.history.ScanHistoryListViewModel.Sc import org.wordpress.android.ui.jetpack.scan.history.ScanHistoryListViewModel.ScanHistoryUiState.EmptyUiState.EmptyHistory import org.wordpress.android.ui.jetpack.scan.history.ScanHistoryViewModel.ScanHistoryTabType import org.wordpress.android.ui.utils.UiHelpers +import org.wordpress.android.util.extensions.getParcelableCompat +import org.wordpress.android.util.extensions.getSerializableCompat +import org.wordpress.android.util.extensions.getSerializableExtraCompat import org.wordpress.android.util.image.ImageManager import org.wordpress.android.viewmodel.observeEvent import javax.inject.Inject @@ -78,14 +81,15 @@ class ScanHistoryListFragment : ViewPagerFragment(R.layout.scan_history_list_fra } private fun getSite(savedInstanceState: Bundle?): SiteModel { - return if (savedInstanceState == null) { - requireActivity().intent.getSerializableExtra(WordPress.SITE) as SiteModel + val site: SiteModel? = if (savedInstanceState == null) { + requireActivity().intent.getSerializableExtraCompat(WordPress.SITE) } else { - savedInstanceState.getSerializable(WordPress.SITE) as SiteModel + savedInstanceState.getSerializableCompat(WordPress.SITE) } + return requireNotNull(site) } - private fun getTabType(): ScanHistoryTabType = requireNotNull(arguments?.getParcelable(ARG_TAB_TYPE)) + private fun getTabType() = requireNotNull(arguments?.getParcelableCompat(ARG_TAB_TYPE)) override fun getScrollableViewForUniqueIdProvision(): View? = binding?.recyclerView diff --git a/WordPress/src/main/java/org/wordpress/android/ui/jetpackoverlay/JetpackFeatureFullScreenOverlayFragment.kt b/WordPress/src/main/java/org/wordpress/android/ui/jetpackoverlay/JetpackFeatureFullScreenOverlayFragment.kt index 0d12c1e9d646..aaa73a1cc89b 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/jetpackoverlay/JetpackFeatureFullScreenOverlayFragment.kt +++ b/WordPress/src/main/java/org/wordpress/android/ui/jetpackoverlay/JetpackFeatureFullScreenOverlayFragment.kt @@ -27,6 +27,7 @@ import org.wordpress.android.ui.utils.UiHelpers import org.wordpress.android.util.RtlUtils import org.wordpress.android.util.UrlUtils import org.wordpress.android.util.extensions.exhaustive +import org.wordpress.android.util.extensions.getSerializableCompat import org.wordpress.android.util.extensions.setVisible import javax.inject.Inject @@ -93,8 +94,7 @@ class JetpackFeatureFullScreenOverlayFragment : BottomSheetDialogFragment() { bottomSheetBehavior.state = BottomSheetBehavior.STATE_EXPANDED } - private fun getSiteScreen() = - arguments?.getSerializable(OVERLAY_SCREEN_TYPE) as JetpackFeatureOverlayScreenType? + private fun getSiteScreen() = arguments?.getSerializableCompat(OVERLAY_SCREEN_TYPE) private fun getIfSiteCreationOverlay() = arguments?.getSerializable(IS_SITE_CREATION_OVERLAY) as Boolean @@ -102,14 +102,16 @@ class JetpackFeatureFullScreenOverlayFragment : BottomSheetDialogFragment() { private fun getIfDeepLinkOverlay() = arguments?.getSerializable(IS_DEEP_LINK_OVERLAY) as Boolean - private fun getSiteCreationSource() = - arguments?.getSerializable(SITE_CREATION_OVERLAY_SOURCE) as SiteCreationSource + private fun getSiteCreationSource() = requireNotNull( + arguments?.getSerializableCompat(SITE_CREATION_OVERLAY_SOURCE) + ) private fun getIfFeatureCollectionOverlay() = arguments?.getSerializable(IS_FEATURE_COLLECTION_OVERLAY) as Boolean - private fun getFeatureCollectionOverlaysSource() = - arguments?.getSerializable(FEATURE_COLLECTION_OVERLAY_SOURCE) as JetpackFeatureCollectionOverlaySource + private fun getFeatureCollectionOverlaysSource() = requireNotNull( + arguments?.getSerializableCompat(FEATURE_COLLECTION_OVERLAY_SOURCE) + ) private fun JetpackFeatureRemovalOverlayBinding.setupObservers() { viewModel.uiState.observe(viewLifecycleOwner) { diff --git a/WordPress/src/main/java/org/wordpress/android/ui/layoutpicker/LayoutPickerViewModel.kt b/WordPress/src/main/java/org/wordpress/android/ui/layoutpicker/LayoutPickerViewModel.kt index 5444b173a926..9a2115fda4a9 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/layoutpicker/LayoutPickerViewModel.kt +++ b/WordPress/src/main/java/org/wordpress/android/ui/layoutpicker/LayoutPickerViewModel.kt @@ -15,6 +15,8 @@ import org.wordpress.android.ui.PreviewModeHandler import org.wordpress.android.ui.layoutpicker.LayoutPickerUiState.Content import org.wordpress.android.ui.layoutpicker.LayoutPickerUiState.Error import org.wordpress.android.util.NetworkUtilsWrapper +import org.wordpress.android.util.extensions.getParcelableArrayListCompat +import org.wordpress.android.util.extensions.getSerializableCompat import org.wordpress.android.viewmodel.Event import org.wordpress.android.viewmodel.ScopedViewModel import org.wordpress.android.viewmodel.SingleLiveEvent @@ -307,11 +309,11 @@ abstract class LayoutPickerViewModel( fun loadSavedState(savedInstanceState: Bundle?) { if (savedInstanceState == null) return - val layouts = savedInstanceState.getParcelableArrayList(FETCHED_LAYOUTS) - val categories = savedInstanceState.getParcelableArrayList(FETCHED_CATEGORIES) + val layouts = savedInstanceState.getParcelableArrayListCompat(FETCHED_LAYOUTS) + val categories = savedInstanceState.getParcelableArrayListCompat(FETCHED_CATEGORIES) val selected = savedInstanceState.getString(SELECTED_LAYOUT) - val selectedCategories = (savedInstanceState.getSerializable(SELECTED_CATEGORIES) as? List<*>) - ?.filterIsInstance() ?: listOf() + val selectedCategories = (savedInstanceState.getSerializableCompat>(SELECTED_CATEGORIES)) + ?: listOf() val previewMode = savedInstanceState.getString(PREVIEW_MODE, MOBILE.name) resetState(selected, ArrayList(selectedCategories.toMutableList()), previewMode) if (layouts == null || categories == null || layouts.isEmpty()) { diff --git a/WordPress/src/main/java/org/wordpress/android/ui/layoutpicker/LayoutsRowViewHolder.kt b/WordPress/src/main/java/org/wordpress/android/ui/layoutpicker/LayoutsRowViewHolder.kt index f6a6f69cf547..f63280a6f9b3 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/layoutpicker/LayoutsRowViewHolder.kt +++ b/WordPress/src/main/java/org/wordpress/android/ui/layoutpicker/LayoutsRowViewHolder.kt @@ -14,6 +14,7 @@ import androidx.recyclerview.widget.RecyclerView import androidx.recyclerview.widget.RecyclerView.OnScrollListener import org.wordpress.android.R import org.wordpress.android.R.dimen +import org.wordpress.android.util.extensions.getParcelableCompat import org.wordpress.android.util.extensions.setVisible sealed class LayoutsRowViewHolder(view: View) : RecyclerView.ViewHolder(view) @@ -100,7 +101,7 @@ class LayoutsItemViewHolder( private fun restoreScrollState(recyclerView: RecyclerView, key: String) { recyclerView.layoutManager?.apply { - val scrollState = nestedScrollStates.getParcelable(key) + val scrollState = nestedScrollStates.getParcelableCompat(key) if (scrollState != null) { onRestoreInstanceState(scrollState) } else { diff --git a/WordPress/src/main/java/org/wordpress/android/ui/main/jetpack/migration/JetpackMigrationActivity.kt b/WordPress/src/main/java/org/wordpress/android/ui/main/jetpack/migration/JetpackMigrationActivity.kt index 109109bac25a..f8604ff640bb 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/main/jetpack/migration/JetpackMigrationActivity.kt +++ b/WordPress/src/main/java/org/wordpress/android/ui/main/jetpack/migration/JetpackMigrationActivity.kt @@ -8,6 +8,7 @@ import dagger.hilt.android.AndroidEntryPoint import org.wordpress.android.R import org.wordpress.android.databinding.ActivityJetpackMigrationBinding import org.wordpress.android.ui.utils.PreMigrationDeepLinkData +import org.wordpress.android.util.extensions.getParcelableExtraCompat @AndroidEntryPoint class JetpackMigrationActivity : AppCompatActivity() { @@ -18,7 +19,7 @@ class JetpackMigrationActivity : AppCompatActivity() { setContentView(root) if (savedInstanceState == null) { val showDeleteWpState = intent.getBooleanExtra(KEY_SHOW_DELETE_WP_STATE, false) - val deepLinkData = intent.getParcelableExtra(KEY_DEEP_LINK_DATA) + val deepLinkData = intent.getParcelableExtraCompat(KEY_DEEP_LINK_DATA) val fragment = JetpackMigrationFragment.newInstance(showDeleteWpState, deepLinkData) supportFragmentManager.beginTransaction() .replace(R.id.fragment_container, fragment) diff --git a/WordPress/src/main/java/org/wordpress/android/ui/main/jetpack/migration/JetpackMigrationFragment.kt b/WordPress/src/main/java/org/wordpress/android/ui/main/jetpack/migration/JetpackMigrationFragment.kt index 998d9cdfc15e..91f9e78ca712 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/main/jetpack/migration/JetpackMigrationFragment.kt +++ b/WordPress/src/main/java/org/wordpress/android/ui/main/jetpack/migration/JetpackMigrationFragment.kt @@ -44,6 +44,7 @@ import org.wordpress.android.ui.utils.PreMigrationDeepLinkData import org.wordpress.android.util.AppThemeUtils import org.wordpress.android.util.LocaleManager import org.wordpress.android.util.UriWrapper +import org.wordpress.android.util.extensions.getParcelableCompat import javax.inject.Inject @AndroidEntryPoint @@ -77,7 +78,7 @@ class JetpackMigrationFragment : Fragment() { observeViewModelEvents() observeRefreshAppThemeEvents() val showDeleteWpState = arguments?.getBoolean(KEY_SHOW_DELETE_WP_STATE, false) ?: false - val deepLinkData = arguments?.getParcelable(KEY_DEEP_LINK_DATA) + val deepLinkData = arguments?.getParcelableCompat(KEY_DEEP_LINK_DATA) initBackPressHandler(showDeleteWpState) viewModel.start( showDeleteWpState, diff --git a/WordPress/src/main/java/org/wordpress/android/ui/mediapicker/MediaPickerActivity.kt b/WordPress/src/main/java/org/wordpress/android/ui/mediapicker/MediaPickerActivity.kt index 5e25e003eab9..8adde6b7060a 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/mediapicker/MediaPickerActivity.kt +++ b/WordPress/src/main/java/org/wordpress/android/ui/mediapicker/MediaPickerActivity.kt @@ -50,6 +50,8 @@ import org.wordpress.android.ui.utils.UiHelpers import org.wordpress.android.util.AppLog import org.wordpress.android.util.AppLog.T.MEDIA import org.wordpress.android.util.WPMediaUtils +import org.wordpress.android.util.extensions.getSerializableCompat +import org.wordpress.android.util.extensions.getSerializableExtraCompat import java.io.File import javax.inject.Inject @@ -118,11 +120,11 @@ class MediaPickerActivity : LocaleAwareActivity(), MediaPickerListener { } if (savedInstanceState == null) { mediaPickerSetup = MediaPickerSetup.fromIntent(intent) - site = intent.getSerializableExtra(WordPress.SITE) as? SiteModel + site = intent.getSerializableExtraCompat(WordPress.SITE) localPostId = intent.getIntExtra(LOCAL_POST_ID, EMPTY_LOCAL_POST_ID) } else { mediaPickerSetup = MediaPickerSetup.fromBundle(savedInstanceState) - site = savedInstanceState.getSerializable(WordPress.SITE) as? SiteModel + site = savedInstanceState.getSerializableCompat(WordPress.SITE) localPostId = savedInstanceState.getInt(LOCAL_POST_ID, EMPTY_LOCAL_POST_ID) } var fragment = pickerFragment diff --git a/WordPress/src/main/java/org/wordpress/android/ui/mediapicker/MediaPickerFragment.kt b/WordPress/src/main/java/org/wordpress/android/ui/mediapicker/MediaPickerFragment.kt index cd57a3bdb2ec..ded23422bb0a 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/mediapicker/MediaPickerFragment.kt +++ b/WordPress/src/main/java/org/wordpress/android/ui/mediapicker/MediaPickerFragment.kt @@ -74,6 +74,9 @@ import org.wordpress.android.util.WPLinkMovementMethod import org.wordpress.android.util.WPMediaUtils import org.wordpress.android.util.WPPermissionUtils import org.wordpress.android.util.WPSwipeToRefreshHelper +import org.wordpress.android.util.extensions.getParcelableArrayListCompat +import org.wordpress.android.util.extensions.getParcelableCompat +import org.wordpress.android.util.extensions.getSerializableCompat import org.wordpress.android.util.image.ImageManager import org.wordpress.android.viewmodel.observeEvent import javax.inject.Inject @@ -224,13 +227,13 @@ class MediaPickerFragment : Fragment(), MenuProvider { requireActivity().addMenuProvider(this, viewLifecycleOwner) val mediaPickerSetup = MediaPickerSetup.fromBundle(requireArguments()) - val site = requireArguments().getSerializable(WordPress.SITE) as? SiteModel + val site = requireArguments().getSerializableCompat(WordPress.SITE) var selectedIds: List? = null var lastTappedIcon: MediaPickerIcon? = null if (savedInstanceState != null) { lastTappedIcon = MediaPickerIcon.fromBundle(savedInstanceState) if (savedInstanceState.containsKey(KEY_SELECTED_IDS)) { - selectedIds = savedInstanceState.getParcelableArrayList(KEY_SELECTED_IDS)?.map { it } + selectedIds = savedInstanceState.getParcelableArrayListCompat(KEY_SELECTED_IDS)?.map { it } } } @@ -239,7 +242,7 @@ class MediaPickerFragment : Fragment(), MenuProvider { NUM_COLUMNS ) - savedInstanceState?.getParcelable(KEY_LIST_STATE)?.let { + savedInstanceState?.getParcelableCompat(KEY_LIST_STATE)?.let { layoutManager.onRestoreInstanceState(it) } with(MediaPickerFragmentBinding.bind(view)) { diff --git a/WordPress/src/main/java/org/wordpress/android/ui/mysite/dynamiccards/quickstart/QuickStartDynamicCardViewHolder.kt b/WordPress/src/main/java/org/wordpress/android/ui/mysite/dynamiccards/quickstart/QuickStartDynamicCardViewHolder.kt index 6d66724e3f32..c78f9b01b5c5 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/mysite/dynamiccards/quickstart/QuickStartDynamicCardViewHolder.kt +++ b/WordPress/src/main/java/org/wordpress/android/ui/mysite/dynamiccards/quickstart/QuickStartDynamicCardViewHolder.kt @@ -22,6 +22,7 @@ import org.wordpress.android.ui.mysite.MySiteCardAndItem.DynamicCard.QuickStartD import org.wordpress.android.ui.mysite.MySiteCardAndItemViewHolder import org.wordpress.android.ui.utils.UiHelpers import org.wordpress.android.util.ColorUtils +import org.wordpress.android.util.extensions.getParcelableCompat import org.wordpress.android.util.extensions.viewBinding private const val Y_BUFFER = 10 @@ -90,7 +91,7 @@ class QuickStartDynamicCardViewHolder( private fun restoreScrollState(recyclerView: RecyclerView, key: String) { recyclerView.layoutManager?.apply { - val scrollState = nestedScrollStates.getParcelable(key) + val scrollState = nestedScrollStates.getParcelableCompat(key) if (scrollState != null) { onRestoreInstanceState(scrollState) } else { diff --git a/WordPress/src/main/java/org/wordpress/android/ui/mysite/jetpackbadge/JetpackPoweredBottomSheetFragment.kt b/WordPress/src/main/java/org/wordpress/android/ui/mysite/jetpackbadge/JetpackPoweredBottomSheetFragment.kt index 6945317669b4..038bc8c61d1d 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/mysite/jetpackbadge/JetpackPoweredBottomSheetFragment.kt +++ b/WordPress/src/main/java/org/wordpress/android/ui/mysite/jetpackbadge/JetpackPoweredBottomSheetFragment.kt @@ -14,8 +14,6 @@ import com.google.android.material.bottomsheet.BottomSheetDialog import com.google.android.material.bottomsheet.BottomSheetDialogFragment import dagger.hilt.android.AndroidEntryPoint import org.wordpress.android.R -import org.wordpress.android.R.raw -import org.wordpress.android.R.string import org.wordpress.android.databinding.JetpackPoweredBottomSheetBinding import org.wordpress.android.databinding.JetpackPoweredExpandedBottomSheetBinding import org.wordpress.android.ui.ActivityLauncherWrapper @@ -27,6 +25,7 @@ import org.wordpress.android.ui.main.WPMainNavigationView.PageType.READER import org.wordpress.android.ui.mysite.jetpackbadge.JetpackPoweredDialogAction.DismissDialog import org.wordpress.android.ui.mysite.jetpackbadge.JetpackPoweredDialogAction.OpenPlayStore import org.wordpress.android.util.extensions.exhaustive +import org.wordpress.android.util.extensions.getSerializableCompat import javax.inject.Inject @AndroidEntryPoint @@ -85,27 +84,27 @@ class JetpackPoweredBottomSheetFragment : BottomSheetDialogFragment() { private fun setupFullScreenViews(view: View) { with(JetpackPoweredExpandedBottomSheetBinding.bind(view)) { - when (arguments?.getSerializable(KEY_SITE_SCREEN) as? PageType ?: MY_SITE) { + when (arguments?.getSerializableCompat(KEY_SITE_SCREEN) ?: MY_SITE) { MY_SITE -> { - val animRes = if (rtlLayout(view)) raw.jp_stats_rtl else raw.jp_stats_left + val animRes = if (rtlLayout(view)) R.raw.jp_stats_rtl else R.raw.jp_stats_left illustrationView.setAnimation(animRes) - title.text = getString(string.wp_jetpack_powered_stats_powered_by_jetpack) - caption.text = getString(string.wp_jetpack_powered_stats_powered_by_jetpack_caption) - secondaryButton.text = getString(string.wp_jetpack_continue_to_stats) + title.text = getString(R.string.wp_jetpack_powered_stats_powered_by_jetpack) + caption.text = getString(R.string.wp_jetpack_powered_stats_powered_by_jetpack_caption) + secondaryButton.text = getString(R.string.wp_jetpack_continue_to_stats) } READER -> { - val animRes = if (rtlLayout(view)) raw.jp_reader_rtl else raw.jp_reader_left + val animRes = if (rtlLayout(view)) R.raw.jp_reader_rtl else R.raw.jp_reader_left illustrationView.setAnimation(animRes) - title.text = getString(string.wp_jetpack_powered_reader_powered_by_jetpack) - caption.text = getString(string.wp_jetpack_powered_reader_powered_by_jetpack_caption) - secondaryButton.text = getString(string.wp_jetpack_continue_to_reader) + title.text = getString(R.string.wp_jetpack_powered_reader_powered_by_jetpack) + caption.text = getString(R.string.wp_jetpack_powered_reader_powered_by_jetpack_caption) + secondaryButton.text = getString(R.string.wp_jetpack_continue_to_reader) } NOTIFS -> { - val animRes = if (rtlLayout(view)) raw.jp_notifications_rtl else raw.jp_notifications_left + val animRes = if (rtlLayout(view)) R.raw.jp_notifications_rtl else R.raw.jp_notifications_left illustrationView.setAnimation(animRes) - title.text = getString(string.wp_jetpack_powered_notifications_powered_by_jetpack) - caption.text = getString(string.wp_jetpack_powered_notifications_powered_by_jetpack_caption) - secondaryButton.text = getString(string.wp_jetpack_continue_to_notifications) + title.text = getString(R.string.wp_jetpack_powered_notifications_powered_by_jetpack) + caption.text = getString(R.string.wp_jetpack_powered_notifications_powered_by_jetpack_caption) + secondaryButton.text = getString(R.string.wp_jetpack_continue_to_notifications) } } primaryButton.setOnClickListener { viewModel.openJetpackAppDownloadLink() } diff --git a/WordPress/src/main/java/org/wordpress/android/ui/mysite/tabs/MySiteTabFragment.kt b/WordPress/src/main/java/org/wordpress/android/ui/mysite/tabs/MySiteTabFragment.kt index 3bfa3ba7352f..87d7a01d323f 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/mysite/tabs/MySiteTabFragment.kt +++ b/WordPress/src/main/java/org/wordpress/android/ui/mysite/tabs/MySiteTabFragment.kt @@ -87,6 +87,7 @@ import org.wordpress.android.util.SnackbarSequencer import org.wordpress.android.util.UriWrapper import org.wordpress.android.util.WPSwipeToRefreshHelper.buildSwipeToRefreshHelper import org.wordpress.android.util.extensions.getColorFromAttribute +import org.wordpress.android.util.extensions.getSerializableCompat import org.wordpress.android.util.extensions.setVisible import org.wordpress.android.util.helpers.SwipeToRefreshHelper import org.wordpress.android.util.image.ImageManager @@ -737,7 +738,7 @@ class MySiteTabFragment : Fragment(R.layout.my_site_tab_fragment), } override fun onConfirm(result: Bundle?) { - val task = result?.getSerializable(QuickStartFullScreenDialogFragment.RESULT_TASK) as? QuickStartTask + val task = result?.getSerializableCompat(QuickStartFullScreenDialogFragment.RESULT_TASK) as? QuickStartTask task?.let { viewModel.onQuickStartTaskCardClick(it) } } diff --git a/WordPress/src/main/java/org/wordpress/android/ui/notifications/DismissNotificationReceiver.kt b/WordPress/src/main/java/org/wordpress/android/ui/notifications/DismissNotificationReceiver.kt index 88d6f30af644..2a1125c4fabc 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/notifications/DismissNotificationReceiver.kt +++ b/WordPress/src/main/java/org/wordpress/android/ui/notifications/DismissNotificationReceiver.kt @@ -7,6 +7,7 @@ import androidx.core.app.NotificationManagerCompat import org.wordpress.android.WordPress import org.wordpress.android.analytics.AnalyticsTracker.Stat import org.wordpress.android.util.analytics.AnalyticsTrackerWrapper +import org.wordpress.android.util.extensions.getSerializableExtraCompat import javax.inject.Inject class DismissNotificationReceiver : BroadcastReceiver() { @@ -21,7 +22,7 @@ class DismissNotificationReceiver : BroadcastReceiver() { } private fun trackAnalyticsEvent(intent: Intent) { - val stat = intent.getSerializableExtra(EXTRA_STAT_TO_TRACK) as Stat? + val stat = intent.getSerializableExtraCompat(EXTRA_STAT_TO_TRACK) if (stat != null) { analyticsTrackerWrapper.track(stat) } diff --git a/WordPress/src/main/java/org/wordpress/android/ui/pages/PageListFragment.kt b/WordPress/src/main/java/org/wordpress/android/ui/pages/PageListFragment.kt index 98709e268b61..1cc2642d6bff 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/pages/PageListFragment.kt +++ b/WordPress/src/main/java/org/wordpress/android/ui/pages/PageListFragment.kt @@ -17,6 +17,8 @@ import org.wordpress.android.ui.utils.UiHelpers import org.wordpress.android.util.DisplayUtils import org.wordpress.android.util.QuickStartUtilsWrapper import org.wordpress.android.util.SnackbarSequencer +import org.wordpress.android.util.extensions.getParcelableCompat +import org.wordpress.android.util.extensions.getSerializableCompat import org.wordpress.android.util.image.ImageManager import org.wordpress.android.viewmodel.pages.PageListViewModel import org.wordpress.android.viewmodel.pages.PageListViewModel.PageListType @@ -90,9 +92,9 @@ class PageListFragment : ViewPagerFragment(R.layout.pages_list_fragment) { private fun PagesListFragmentBinding.initializeViewModels(activity: FragmentActivity) { val pagesViewModel = ViewModelProvider(activity, viewModelFactory).get(PagesViewModel::class.java) - val listType = arguments?.getSerializable(typeKey) as PageListType - viewModel = ViewModelProvider(this@PageListFragment, viewModelFactory) - .get(listType.name, PageListViewModel::class.java) + val listType = requireNotNull(arguments?.getSerializableCompat(typeKey)) + viewModel = + ViewModelProvider(this@PageListFragment, viewModelFactory)[listType.name, PageListViewModel::class.java] viewModel.start(listType, pagesViewModel) @@ -101,7 +103,7 @@ class PageListFragment : ViewPagerFragment(R.layout.pages_list_fragment) { private fun PagesListFragmentBinding.initializeViews(savedInstanceState: Bundle?) { val layoutManager = LinearLayoutManager(activity, RecyclerView.VERTICAL, false) - savedInstanceState?.getParcelable(listStateKey)?.let { + savedInstanceState?.getParcelableCompat(listStateKey)?.let { layoutManager.onRestoreInstanceState(it) } diff --git a/WordPress/src/main/java/org/wordpress/android/ui/pages/PageParentFragment.kt b/WordPress/src/main/java/org/wordpress/android/ui/pages/PageParentFragment.kt index a254f54df2b8..c18356012d82 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/pages/PageParentFragment.kt +++ b/WordPress/src/main/java/org/wordpress/android/ui/pages/PageParentFragment.kt @@ -25,6 +25,8 @@ import org.wordpress.android.WordPress import org.wordpress.android.databinding.PageParentFragmentBinding import org.wordpress.android.fluxc.model.SiteModel import org.wordpress.android.util.DisplayUtils +import org.wordpress.android.util.extensions.getParcelableCompat +import org.wordpress.android.util.extensions.getSerializableExtraCompat import org.wordpress.android.viewmodel.pages.PageParentViewModel import org.wordpress.android.widgets.RecyclerItemDecoration import javax.inject.Inject @@ -158,7 +160,7 @@ class PageParentFragment : Fragment(R.layout.page_parent_fragment), MenuProvider private fun PageParentFragmentBinding.initializeViews(activity: FragmentActivity, savedInstanceState: Bundle?) { val layoutManager = LinearLayoutManager(activity, RecyclerView.VERTICAL, false) - savedInstanceState?.getParcelable(listStateKey)?.let { + savedInstanceState?.getParcelableCompat(listStateKey)?.let { layoutManager.onRestoreInstanceState(it) } @@ -184,9 +186,8 @@ class PageParentFragment : Fragment(R.layout.page_parent_fragment), MenuProvider setupObservers() if (isFirstStart) { - val site = activity.intent?.getSerializableExtra(WordPress.SITE) as SiteModel? - val nonNullSite = checkNotNull(site) - viewModel.start(nonNullSite, pageId) + val site = requireNotNull(activity.intent?.getSerializableExtraCompat(WordPress.SITE)) + viewModel.start(site, pageId) } else { restorePreviousSearch = true } diff --git a/WordPress/src/main/java/org/wordpress/android/ui/pages/PageParentSearchFragment.kt b/WordPress/src/main/java/org/wordpress/android/ui/pages/PageParentSearchFragment.kt index 6dd9857a8ee6..43fad8ba2caa 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/pages/PageParentSearchFragment.kt +++ b/WordPress/src/main/java/org/wordpress/android/ui/pages/PageParentSearchFragment.kt @@ -16,6 +16,7 @@ import org.wordpress.android.R import org.wordpress.android.WordPress import org.wordpress.android.databinding.PagesListFragmentBinding import org.wordpress.android.util.DisplayUtils +import org.wordpress.android.util.extensions.getParcelableCompat import org.wordpress.android.viewmodel.pages.PageParentSearchViewModel import org.wordpress.android.viewmodel.pages.PageParentViewModel import org.wordpress.android.widgets.RecyclerItemDecoration @@ -71,7 +72,7 @@ class PageParentSearchFragment : Fragment(R.layout.pages_list_fragment), Corouti private fun PagesListFragmentBinding.initializeViews(savedInstanceState: Bundle?) { val layoutManager = LinearLayoutManager(activity, RecyclerView.VERTICAL, false) - savedInstanceState?.getParcelable(listStateKey)?.let { + savedInstanceState?.getParcelableCompat(listStateKey)?.let { layoutManager.onRestoreInstanceState(it) } diff --git a/WordPress/src/main/java/org/wordpress/android/ui/pages/PagesActivity.kt b/WordPress/src/main/java/org/wordpress/android/ui/pages/PagesActivity.kt index 323c0638557d..f7a52adb5ece 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/pages/PagesActivity.kt +++ b/WordPress/src/main/java/org/wordpress/android/ui/pages/PagesActivity.kt @@ -12,6 +12,7 @@ import org.wordpress.android.ui.LocaleAwareActivity import org.wordpress.android.ui.notifications.SystemNotificationsTracker import org.wordpress.android.ui.posts.BasicFragmentDialog.BasicDialogNegativeClickInterface import org.wordpress.android.ui.posts.BasicFragmentDialog.BasicDialogPositiveClickInterface +import org.wordpress.android.util.extensions.getSerializableExtraCompat import javax.inject.Inject const val EXTRA_PAGE_REMOTE_ID_KEY = "extra_page_remote_id_key" @@ -39,8 +40,9 @@ class PagesActivity : LocaleAwareActivity(), private fun handleIntent(intent: Intent) { if (intent.hasExtra(ARG_NOTIFICATION_TYPE)) { - val notificationType: NotificationType = - intent.getSerializableExtra(ARG_NOTIFICATION_TYPE) as NotificationType + val notificationType = requireNotNull( + intent.getSerializableExtraCompat(ARG_NOTIFICATION_TYPE) + ) systemNotificationTracker.trackTappedNotification(notificationType) } diff --git a/WordPress/src/main/java/org/wordpress/android/ui/pages/PagesFragment.kt b/WordPress/src/main/java/org/wordpress/android/ui/pages/PagesFragment.kt index f594bc7d603d..4fb4501ee04c 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/pages/PagesFragment.kt +++ b/WordPress/src/main/java/org/wordpress/android/ui/pages/PagesFragment.kt @@ -56,6 +56,8 @@ import org.wordpress.android.ui.utils.UiHelpers import org.wordpress.android.util.DisplayUtils import org.wordpress.android.util.ToastUtils.Duration import org.wordpress.android.util.WPSwipeToRefreshHelper +import org.wordpress.android.util.extensions.getSerializableCompat +import org.wordpress.android.util.extensions.getSerializableExtraCompat import org.wordpress.android.util.extensions.redirectContextClickToLongPressListener import org.wordpress.android.util.extensions.setLiftOnScrollTargetViewIdAndRequestLayout import org.wordpress.android.util.helpers.SwipeToRefreshHelper @@ -316,13 +318,15 @@ class PagesFragment : Fragment(R.layout.pages_fragment), ScrollableViewInitializ setupActions(activity) setupMlpObservers(activity) - val site = if (savedInstanceState == null) { - val nonNullIntent = checkNotNull(activity.intent) - nonNullIntent.getSerializableExtra(WordPress.SITE) as SiteModel - } else { - restorePreviousSearch = true - savedInstanceState.getSerializable(WordPress.SITE) as SiteModel - } + val site: SiteModel = requireNotNull( + if (savedInstanceState == null) { + val nonNullIntent = checkNotNull(activity.intent) + nonNullIntent.getSerializableExtraCompat(WordPress.SITE) + } else { + restorePreviousSearch = true + savedInstanceState.getSerializableCompat(WordPress.SITE) + } + ) viewModel.authorUIState.observe(activity, Observer { state -> state?.let { diff --git a/WordPress/src/main/java/org/wordpress/android/ui/pages/SearchListFragment.kt b/WordPress/src/main/java/org/wordpress/android/ui/pages/SearchListFragment.kt index d5ce0ee83b76..a22325336b8f 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/pages/SearchListFragment.kt +++ b/WordPress/src/main/java/org/wordpress/android/ui/pages/SearchListFragment.kt @@ -14,6 +14,7 @@ import org.wordpress.android.WordPress import org.wordpress.android.databinding.PagesListFragmentBinding import org.wordpress.android.ui.utils.UiHelpers import org.wordpress.android.util.DisplayUtils +import org.wordpress.android.util.extensions.getParcelableCompat import org.wordpress.android.viewmodel.pages.PagesViewModel import org.wordpress.android.viewmodel.pages.SearchListViewModel import org.wordpress.android.widgets.RecyclerItemDecoration @@ -66,7 +67,7 @@ class SearchListFragment : Fragment(R.layout.pages_list_fragment) { private fun PagesListFragmentBinding.initializeViews(savedInstanceState: Bundle?) { val layoutManager = LinearLayoutManager(activity, RecyclerView.VERTICAL, false) - savedInstanceState?.getParcelable(listStateKey)?.let { + savedInstanceState?.getParcelableCompat(listStateKey)?.let { layoutManager.onRestoreInstanceState(it) } diff --git a/WordPress/src/main/java/org/wordpress/android/ui/people/PeopleInviteDialogFragment.kt b/WordPress/src/main/java/org/wordpress/android/ui/people/PeopleInviteDialogFragment.kt index c286635c31ba..2c4b56c41421 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/people/PeopleInviteDialogFragment.kt +++ b/WordPress/src/main/java/org/wordpress/android/ui/people/PeopleInviteDialogFragment.kt @@ -11,6 +11,7 @@ import org.wordpress.android.R import org.wordpress.android.WordPress import org.wordpress.android.ui.people.PeopleInviteDialogFragment.DialogMode.DISABLE_INVITE_LINKS_CONFIRMATION import org.wordpress.android.ui.people.PeopleInviteDialogFragment.DialogMode.INVITE_LINKS_ROLE_SELECTION +import org.wordpress.android.util.extensions.getSerializableCompat import org.wordpress.android.viewmodel.ContextProvider import javax.inject.Inject @@ -45,7 +46,7 @@ class PeopleInviteDialogFragment : DialogFragment() { targetFragment as ViewModelStoreOwner, viewModelFactory ).get(PeopleInviteViewModel::class.java) - val dialogMode = arguments?.getSerializable(ARG_DIALOG_MODE) as? DialogMode + val dialogMode = arguments?.getSerializableCompat(ARG_DIALOG_MODE) val roles = arguments?.getStringArray(ARG_ROLES) val builder = MaterialAlertDialogBuilder(requireActivity()) diff --git a/WordPress/src/main/java/org/wordpress/android/ui/photopicker/PhotoPickerFragment.kt b/WordPress/src/main/java/org/wordpress/android/ui/photopicker/PhotoPickerFragment.kt index 3ad1acb4abae..a49ea878679d 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/photopicker/PhotoPickerFragment.kt +++ b/WordPress/src/main/java/org/wordpress/android/ui/photopicker/PhotoPickerFragment.kt @@ -35,6 +35,8 @@ import org.wordpress.android.util.UriWrapper import org.wordpress.android.util.ViewWrapper import org.wordpress.android.util.WPMediaUtils import org.wordpress.android.util.WPPermissionUtils +import org.wordpress.android.util.extensions.getParcelableCompat +import org.wordpress.android.util.extensions.getSerializableCompat import org.wordpress.android.util.image.ImageManager import org.wordpress.android.viewmodel.observeEvent import javax.inject.Inject @@ -90,8 +92,10 @@ class PhotoPickerFragment : Fragment(R.layout.photo_picker_fragment) { override fun onViewCreated(view: View, savedInstanceState: Bundle?) { super.onViewCreated(view, savedInstanceState) - val browserType = requireArguments().getSerializable(MediaBrowserActivity.ARG_BROWSER_TYPE) as MediaBrowserType - val site = requireArguments().getSerializable(WordPress.SITE) as? SiteModel + val browserType = requireNotNull( + arguments?.getSerializableCompat(MediaBrowserActivity.ARG_BROWSER_TYPE) + ) + val site = requireArguments().getSerializableCompat(WordPress.SITE) var selectedIds: List? = null var lastTappedIcon: PhotoPickerIcon? = null if (savedInstanceState != null) { @@ -111,7 +115,7 @@ class PhotoPickerFragment : Fragment(R.layout.photo_picker_fragment) { NUM_COLUMNS ) - savedInstanceState?.getParcelable(KEY_LIST_STATE)?.let { + savedInstanceState?.getParcelableCompat(KEY_LIST_STATE)?.let { layoutManager.onRestoreInstanceState(it) } diff --git a/WordPress/src/main/java/org/wordpress/android/ui/plans/PlanDetailsFragment.kt b/WordPress/src/main/java/org/wordpress/android/ui/plans/PlanDetailsFragment.kt index 7de5b92db14a..23a6411ad2f8 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/plans/PlanDetailsFragment.kt +++ b/WordPress/src/main/java/org/wordpress/android/ui/plans/PlanDetailsFragment.kt @@ -14,6 +14,7 @@ import org.wordpress.android.fluxc.model.plans.PlanOffersModel import org.wordpress.android.ui.FullScreenDialogFragment.FullScreenDialogContent import org.wordpress.android.ui.FullScreenDialogFragment.FullScreenDialogController import org.wordpress.android.util.StringUtils +import org.wordpress.android.util.extensions.getParcelableCompat import org.wordpress.android.util.image.ImageManager import org.wordpress.android.util.image.ImageType import javax.inject.Inject @@ -42,9 +43,9 @@ class PlanDetailsFragment : Fragment(), FullScreenDialogContent { (requireActivity().application as WordPress).component().inject(this) plan = if (savedInstanceState != null) { - savedInstanceState.getParcelable(KEY_PLAN) + savedInstanceState.getParcelableCompat(KEY_PLAN) } else { - arguments?.getParcelable(EXTRA_PLAN) + arguments?.getParcelableCompat(EXTRA_PLAN) } } diff --git a/WordPress/src/main/java/org/wordpress/android/ui/posts/BasicDialog.kt b/WordPress/src/main/java/org/wordpress/android/ui/posts/BasicDialog.kt index 671faa0af244..88f658045a55 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/posts/BasicDialog.kt +++ b/WordPress/src/main/java/org/wordpress/android/ui/posts/BasicDialog.kt @@ -9,6 +9,7 @@ import androidx.lifecycle.ViewModelProvider import com.google.android.material.dialog.MaterialAlertDialogBuilder import dagger.android.support.AndroidSupportInjection import org.wordpress.android.ui.posts.BasicDialogViewModel.BasicDialogModel +import org.wordpress.android.util.extensions.getParcelableCompat import javax.inject.Inject /** @@ -34,7 +35,7 @@ class BasicDialog : AppCompatDialogFragment() { setStyle(STYLE_NORMAL, theme) if (savedInstanceState != null) { - model = requireNotNull(savedInstanceState.getParcelable(STATE_KEY_MODEL)) + model = requireNotNull(savedInstanceState.getParcelableCompat(STATE_KEY_MODEL)) } } diff --git a/WordPress/src/main/java/org/wordpress/android/ui/posts/HistoryListFragment.kt b/WordPress/src/main/java/org/wordpress/android/ui/posts/HistoryListFragment.kt index f406562bf047..0cd075c2dd97 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/posts/HistoryListFragment.kt +++ b/WordPress/src/main/java/org/wordpress/android/ui/posts/HistoryListFragment.kt @@ -17,6 +17,7 @@ import org.wordpress.android.ui.history.HistoryAdapter import org.wordpress.android.ui.history.HistoryListItem import org.wordpress.android.ui.history.HistoryListItem.Revision import org.wordpress.android.util.WPSwipeToRefreshHelper +import org.wordpress.android.util.extensions.getSerializableCompat import org.wordpress.android.util.helpers.SwipeToRefreshHelper import org.wordpress.android.viewmodel.history.HistoryViewModel import org.wordpress.android.viewmodel.history.HistoryViewModel.HistoryListStatus @@ -85,9 +86,10 @@ class HistoryListFragment : Fragment(R.layout.history_list_fragment) { (nonNullActivity.application as WordPress).component().inject(this@HistoryListFragment) viewModel = ViewModelProvider(this@HistoryListFragment, viewModelFactory).get(HistoryViewModel::class.java) + val site = requireNotNull(arguments?.getSerializableCompat(KEY_SITE)) viewModel.create( localPostId = arguments?.getInt(KEY_POST_LOCAL_ID) ?: 0, - site = arguments?.get(KEY_SITE) as SiteModel + site = site ) updatePostOrPageEmptyView() setObservers() diff --git a/WordPress/src/main/java/org/wordpress/android/ui/posts/PostDatePickerDialogFragment.kt b/WordPress/src/main/java/org/wordpress/android/ui/posts/PostDatePickerDialogFragment.kt index 6ccc4df769ac..80e88b9f6f4d 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/posts/PostDatePickerDialogFragment.kt +++ b/WordPress/src/main/java/org/wordpress/android/ui/posts/PostDatePickerDialogFragment.kt @@ -10,6 +10,7 @@ import androidx.lifecycle.ViewModelProvider import org.wordpress.android.R import org.wordpress.android.WordPress import org.wordpress.android.ui.posts.prepublishing.PrepublishingPublishSettingsViewModel +import org.wordpress.android.util.extensions.getParcelableCompat import javax.inject.Inject class PostDatePickerDialogFragment : DialogFragment() { @@ -18,7 +19,7 @@ class PostDatePickerDialogFragment : DialogFragment() { private lateinit var viewModel: PublishSettingsViewModel override fun onCreateDialog(savedInstanceState: Bundle?): Dialog { - val publishSettingsFragmentType = arguments?.getParcelable( + val publishSettingsFragmentType = arguments?.getParcelableCompat( ARG_PUBLISH_SETTINGS_FRAGMENT_TYPE ) diff --git a/WordPress/src/main/java/org/wordpress/android/ui/posts/PostListFragment.kt b/WordPress/src/main/java/org/wordpress/android/ui/posts/PostListFragment.kt index 7d88c9d37027..22e4986bac12 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/posts/PostListFragment.kt +++ b/WordPress/src/main/java/org/wordpress/android/ui/posts/PostListFragment.kt @@ -27,6 +27,8 @@ import org.wordpress.android.util.DisplayUtils import org.wordpress.android.util.NetworkUtils import org.wordpress.android.util.ToastUtils 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.util.image.ImageManager import org.wordpress.android.util.widgets.CustomSwipeRefreshLayout @@ -80,7 +82,7 @@ class PostListFragment : ViewPagerFragment() { (nonNullActivity.application as WordPress).component().inject(this) val nonNullIntent = checkNotNull(nonNullActivity.intent) - val site: SiteModel? = nonNullIntent.getSerializableExtra(WordPress.SITE) as SiteModel? + val site = nonNullIntent.getSerializableExtraCompat(WordPress.SITE) if (site == null) { ToastUtils.showToast(nonNullActivity, R.string.blog_not_found, ToastUtils.Duration.SHORT) @@ -97,7 +99,7 @@ class PostListFragment : ViewPagerFragment() { override fun onViewCreated(view: View, savedInstanceState: Bundle?) { super.onViewCreated(view, savedInstanceState) - postListType = requireNotNull(arguments).getSerializable(EXTRA_POST_LIST_TYPE) as PostListType + postListType = requireNotNull(arguments?.getSerializableCompat(EXTRA_POST_LIST_TYPE)) if (postListType == SEARCH) { recyclerView?.id = R.id.posts_search_recycler_view_id diff --git a/WordPress/src/main/java/org/wordpress/android/ui/posts/PostNotificationScheduleTimeDialogFragment.kt b/WordPress/src/main/java/org/wordpress/android/ui/posts/PostNotificationScheduleTimeDialogFragment.kt index 2f736ec0a560..9eb70b8d579a 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/posts/PostNotificationScheduleTimeDialogFragment.kt +++ b/WordPress/src/main/java/org/wordpress/android/ui/posts/PostNotificationScheduleTimeDialogFragment.kt @@ -15,6 +15,7 @@ import org.wordpress.android.fluxc.store.PostSchedulingNotificationStore.Schedul import org.wordpress.android.fluxc.store.PostSchedulingNotificationStore.SchedulingReminderModel.Period.TEN_MINUTES import org.wordpress.android.fluxc.store.PostSchedulingNotificationStore.SchedulingReminderModel.Period.WHEN_PUBLISHED import org.wordpress.android.ui.posts.prepublishing.PrepublishingPublishSettingsViewModel +import org.wordpress.android.util.extensions.getParcelableCompat import javax.inject.Inject class PostNotificationScheduleTimeDialogFragment : DialogFragment() { @@ -23,7 +24,7 @@ class PostNotificationScheduleTimeDialogFragment : DialogFragment() { private lateinit var viewModel: PublishSettingsViewModel override fun onCreateDialog(savedInstanceState: Bundle?): Dialog { - val publishSettingsFragmentType = arguments?.getParcelable( + val publishSettingsFragmentType = arguments?.getParcelableCompat( ARG_PUBLISH_SETTINGS_FRAGMENT_TYPE ) diff --git a/WordPress/src/main/java/org/wordpress/android/ui/posts/PostTimePickerDialogFragment.kt b/WordPress/src/main/java/org/wordpress/android/ui/posts/PostTimePickerDialogFragment.kt index 43da4c08fff9..16af9a1bfe97 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/posts/PostTimePickerDialogFragment.kt +++ b/WordPress/src/main/java/org/wordpress/android/ui/posts/PostTimePickerDialogFragment.kt @@ -13,6 +13,7 @@ import org.wordpress.android.R.style import org.wordpress.android.WordPress import org.wordpress.android.ui.posts.prepublishing.PrepublishingPublishSettingsViewModel +import org.wordpress.android.util.extensions.getParcelableCompat import javax.inject.Inject class PostTimePickerDialogFragment : DialogFragment() { @@ -21,7 +22,7 @@ class PostTimePickerDialogFragment : DialogFragment() { private lateinit var viewModel: PublishSettingsViewModel override fun onCreateDialog(savedInstanceState: Bundle?): Dialog { - val publishSettingsFragmentType = arguments?.getParcelable( + val publishSettingsFragmentType = arguments?.getParcelableCompat( ARG_PUBLISH_SETTINGS_FRAGMENT_TYPE ) diff --git a/WordPress/src/main/java/org/wordpress/android/ui/posts/PostsListActivity.kt b/WordPress/src/main/java/org/wordpress/android/ui/posts/PostsListActivity.kt index 282acad1e59a..49a806cfd899 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/posts/PostsListActivity.kt +++ b/WordPress/src/main/java/org/wordpress/android/ui/posts/PostsListActivity.kt @@ -60,6 +60,8 @@ import org.wordpress.android.ui.utils.UiString import org.wordpress.android.util.AppLog import org.wordpress.android.util.SnackbarItem import org.wordpress.android.util.SnackbarSequencer +import org.wordpress.android.util.extensions.getSerializableCompat +import org.wordpress.android.util.extensions.getSerializableExtraCompat import org.wordpress.android.util.extensions.redirectContextClickToLongPressListener import org.wordpress.android.util.extensions.setLiftOnScrollTargetViewIdAndRequestLayout import org.wordpress.android.viewmodel.observeEvent @@ -165,7 +167,7 @@ class PostsListActivity : LocaleAwareActivity(), } private fun restartWhenSiteHasChanged(intent: Intent) { - val site = intent.getSerializableExtra(WordPress.SITE) as SiteModel + val site = requireNotNull(intent.getSerializableExtraCompat(WordPress.SITE)) if (site.id != this.site.id) { finish() startActivity(intent) @@ -180,14 +182,14 @@ class PostsListActivity : LocaleAwareActivity(), setContentView(root) binding = this - site = if (savedInstanceState == null) { - checkNotNull(intent.getSerializableExtra(WordPress.SITE) as? SiteModel) { - "SiteModel cannot be null, check the PendingIntent starting PostsListActivity" + site = requireNotNull( + if (savedInstanceState == null) { + intent.getSerializableExtraCompat(WordPress.SITE) + } else { + restorePreviousSearch = true + savedInstanceState.getSerializableCompat(WordPress.SITE) } - } else { - restorePreviousSearch = true - savedInstanceState.getSerializable(WordPress.SITE) as SiteModel - } + ) { "SiteModel cannot be null, check the PendingIntent starting PostsListActivity" } val initPreviewState = if (savedInstanceState == null) { PostListRemotePreviewState.NONE @@ -477,8 +479,9 @@ class PostsListActivity : LocaleAwareActivity(), private fun loadIntentData(intent: Intent) { if (intent.hasExtra(ARG_NOTIFICATION_TYPE)) { - val notificationType: NotificationType = - intent.getSerializableExtra(ARG_NOTIFICATION_TYPE) as NotificationType + val notificationType = requireNotNull( + intent.getSerializableExtraCompat(ARG_NOTIFICATION_TYPE) + ) systemNotificationTracker.trackTappedNotification(notificationType) } diff --git a/WordPress/src/main/java/org/wordpress/android/ui/posts/PrepublishingAddCategoryFragment.kt b/WordPress/src/main/java/org/wordpress/android/ui/posts/PrepublishingAddCategoryFragment.kt index ed5e7b3b89e0..d804e6f0f6e2 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/posts/PrepublishingAddCategoryFragment.kt +++ b/WordPress/src/main/java/org/wordpress/android/ui/posts/PrepublishingAddCategoryFragment.kt @@ -21,6 +21,7 @@ import org.wordpress.android.ui.utils.UiHelpers import org.wordpress.android.util.ActivityUtils import org.wordpress.android.util.ToastUtils import org.wordpress.android.util.ToastUtils.Duration.SHORT +import org.wordpress.android.util.extensions.getSerializableCompat import org.wordpress.android.viewmodel.observeEvent import javax.inject.Inject @@ -145,7 +146,7 @@ class PrepublishingAddCategoryFragment : Fragment(R.layout.prepublishing_add_cat startObserving() val needsRequestLayout = requireArguments().getBoolean(PrepublishingTagsFragment.NEEDS_REQUEST_LAYOUT) - val siteModel = requireArguments().getSerializable(WordPress.SITE) as SiteModel + val siteModel = requireNotNull(arguments?.getSerializableCompat(WordPress.SITE)) viewModel.start(siteModel, !needsRequestLayout) } diff --git a/WordPress/src/main/java/org/wordpress/android/ui/posts/PrepublishingBottomSheetFragment.kt b/WordPress/src/main/java/org/wordpress/android/ui/posts/PrepublishingBottomSheetFragment.kt index cf6d17cb2e6c..af12ca7bfc27 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/posts/PrepublishingBottomSheetFragment.kt +++ b/WordPress/src/main/java/org/wordpress/android/ui/posts/PrepublishingBottomSheetFragment.kt @@ -28,6 +28,8 @@ import org.wordpress.android.ui.posts.prepublishing.PrepublishingPublishSettings import org.wordpress.android.util.ActivityUtils import org.wordpress.android.util.KeyboardResizeViewUtil import org.wordpress.android.util.analytics.AnalyticsTrackerWrapper +import org.wordpress.android.util.extensions.getParcelableCompat +import org.wordpress.android.util.extensions.getSerializableCompat import org.wordpress.android.viewmodel.observeEvent import javax.inject.Inject @@ -152,11 +154,10 @@ class PrepublishingBottomSheetFragment : WPBottomSheetDialogFragment(), ActivityUtils.hideKeyboardForced(view) }) - val prepublishingScreenState = savedInstanceState?.getParcelable( + val prepublishingScreenState = savedInstanceState?.getParcelableCompat( KEY_SCREEN_STATE ) - val site = arguments?.getSerializable(SITE) as SiteModel - + val site = requireNotNull(arguments?.getSerializableCompat(SITE)) viewModel.start(site, prepublishingScreenState) } diff --git a/WordPress/src/main/java/org/wordpress/android/ui/posts/PrepublishingCategoriesFragment.kt b/WordPress/src/main/java/org/wordpress/android/ui/posts/PrepublishingCategoriesFragment.kt index 509fe77e4fb3..457935e512b5 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/posts/PrepublishingCategoriesFragment.kt +++ b/WordPress/src/main/java/org/wordpress/android/ui/posts/PrepublishingCategoriesFragment.kt @@ -24,6 +24,7 @@ import org.wordpress.android.ui.posts.PrepublishingHomeItemUiState.ActionType.AD import org.wordpress.android.ui.utils.UiHelpers import org.wordpress.android.util.ToastUtils import org.wordpress.android.util.ToastUtils.Duration.SHORT +import org.wordpress.android.util.extensions.getSerializableCompat import org.wordpress.android.viewmodel.observeEvent import javax.inject.Inject @@ -121,9 +122,8 @@ class PrepublishingCategoriesFragment : Fragment(R.layout.prepublishing_categori parentViewModel = ViewModelProvider(requireParentFragment(), viewModelFactory) .get(PrepublishingViewModel::class.java) startObserving() - val siteModel = requireArguments().getSerializable(WordPress.SITE) as SiteModel - val addCategoryRequest: PrepublishingAddCategoryRequest? = - arguments?.getSerializable(ADD_CATEGORY_REQUEST) as? PrepublishingAddCategoryRequest + val siteModel = requireNotNull(arguments?.getSerializableCompat(WordPress.SITE)) + val addCategoryRequest = arguments?.getSerializableCompat(ADD_CATEGORY_REQUEST) val selectedCategoryIds: List = arguments?.getLongArray(SELECTED_CATEGORY_IDS)?.toList() ?: listOf() diff --git a/WordPress/src/main/java/org/wordpress/android/ui/prefs/categories/list/CategoriesListFragment.kt b/WordPress/src/main/java/org/wordpress/android/ui/prefs/categories/list/CategoriesListFragment.kt index 78eb781534f4..fe1b430bf1e4 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/prefs/categories/list/CategoriesListFragment.kt +++ b/WordPress/src/main/java/org/wordpress/android/ui/prefs/categories/list/CategoriesListFragment.kt @@ -17,6 +17,8 @@ import org.wordpress.android.ui.prefs.categories.list.CategoryDetailNavigation.E import org.wordpress.android.ui.prefs.categories.list.UiState.Content import org.wordpress.android.ui.prefs.categories.list.UiState.Loading import org.wordpress.android.ui.utils.UiHelpers +import org.wordpress.android.util.extensions.getSerializableCompat +import org.wordpress.android.util.extensions.getSerializableExtraCompat import javax.inject.Inject @AndroidEntryPoint @@ -68,11 +70,12 @@ class CategoriesListFragment : Fragment(R.layout.site_settings_categories_list_f } private fun getSite(savedInstanceState: Bundle?): SiteModel { - return if (savedInstanceState == null) { - requireActivity().intent.getSerializableExtra(WordPress.SITE) as SiteModel + val site: SiteModel? = if (savedInstanceState == null) { + requireActivity().intent.getSerializableExtraCompat(WordPress.SITE) } else { - savedInstanceState.getSerializable(WordPress.SITE) as SiteModel + savedInstanceState.getSerializableCompat(WordPress.SITE) } + return requireNotNull(site) } private fun SiteSettingsCategoriesListFragmentBinding.setupObservers() { diff --git a/WordPress/src/main/java/org/wordpress/android/ui/quickstart/QuickStartFullScreenDialogFragment.kt b/WordPress/src/main/java/org/wordpress/android/ui/quickstart/QuickStartFullScreenDialogFragment.kt index 6b36462f4e75..6b13a36ff9a7 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/quickstart/QuickStartFullScreenDialogFragment.kt +++ b/WordPress/src/main/java/org/wordpress/android/ui/quickstart/QuickStartFullScreenDialogFragment.kt @@ -15,7 +15,6 @@ import org.wordpress.android.fluxc.store.QuickStartStore import org.wordpress.android.fluxc.store.QuickStartStore.QuickStartNewSiteTask.CREATE_SITE import org.wordpress.android.fluxc.store.QuickStartStore.QuickStartTask import org.wordpress.android.fluxc.store.QuickStartStore.QuickStartTaskType -import org.wordpress.android.fluxc.store.QuickStartStore.QuickStartTaskType.UNKNOWN import org.wordpress.android.ui.FullScreenDialogFragment.FullScreenDialogContent import org.wordpress.android.ui.FullScreenDialogFragment.FullScreenDialogController import org.wordpress.android.ui.mysite.SelectedSiteRepository @@ -28,6 +27,7 @@ import org.wordpress.android.ui.utils.UiString.UiStringRes import org.wordpress.android.util.DisplayUtilsWrapper import org.wordpress.android.util.QuickStartUtils.getQuickStartListSkippedTracker import org.wordpress.android.util.QuickStartUtils.getQuickStartListTappedTracker +import org.wordpress.android.util.extensions.getSerializableCompat import org.wordpress.android.widgets.WPSnackbar.Companion.make import java.io.Serializable import javax.inject.Inject @@ -74,7 +74,7 @@ class QuickStartFullScreenDialogFragment : Fragment(R.layout.quick_start_dialog_ } override fun onViewCreated(view: View, savedInstanceState: Bundle?) { - tasksType = arguments?.getSerializable(EXTRA_TYPE) as QuickStartTaskType? ?: QuickStartTaskType.UNKNOWN + tasksType = arguments?.getSerializableCompat(EXTRA_TYPE) ?: QuickStartTaskType.UNKNOWN quickStartTracker.trackQuickStartListViewed(tasksType) binding.setupQuickStartList() } @@ -150,7 +150,7 @@ class QuickStartFullScreenDialogFragment : Fragment(R.layout.quick_start_dialog_ ) private fun buildTaskCards(): List { - val tasks = QuickStartTask.getTasksByTaskType(tasksType).filterNot { it.taskType == UNKNOWN } + val tasks = QuickStartTask.getTasksByTaskType(tasksType).filterNot { it.taskType == QuickStartTaskType.UNKNOWN } val selectedSiteLocalId = selectedSiteRepository.getSelectedSiteLocalId().toLong() val tasksCompleted = quickStartStore.getCompletedTasksByType(selectedSiteLocalId, tasksType) return tasks.mapToQuickStartTaskCard(tasksCompleted) diff --git a/WordPress/src/main/java/org/wordpress/android/ui/reader/ReaderPostDetailFragment.kt b/WordPress/src/main/java/org/wordpress/android/ui/reader/ReaderPostDetailFragment.kt index 56d209c47ccb..4485c9e38b5d 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/reader/ReaderPostDetailFragment.kt +++ b/WordPress/src/main/java/org/wordpress/android/ui/reader/ReaderPostDetailFragment.kt @@ -132,6 +132,8 @@ import org.wordpress.android.util.WPSwipeToRefreshHelper.buildSwipeToRefreshHelp import org.wordpress.android.util.config.CommentsSnippetFeatureConfig import org.wordpress.android.util.config.LikesEnhancementsFeatureConfig import org.wordpress.android.util.extensions.getColorFromAttribute +import org.wordpress.android.util.extensions.getParcelableCompat +import org.wordpress.android.util.extensions.getSerializableCompat import org.wordpress.android.util.extensions.isDarkTheme import org.wordpress.android.util.extensions.setVisible import org.wordpress.android.util.helpers.SwipeToRefreshHelper @@ -317,12 +319,14 @@ class ReaderPostDetailFragment : ViewPagerFragment(), if (args != null) { blogId = args.getLong(ReaderConstants.ARG_BLOG_ID) postId = args.getLong(ReaderConstants.ARG_POST_ID) - directOperation = args.getSerializable(ReaderConstants.ARG_DIRECT_OPERATION) as? DirectOperation + directOperation = args.getSerializableCompat(ReaderConstants.ARG_DIRECT_OPERATION) commentId = args.getInt(ReaderConstants.ARG_COMMENT_ID) isRelatedPost = args.getBoolean(ReaderConstants.ARG_IS_RELATED_POST) interceptedUri = args.getString(ReaderConstants.ARG_INTERCEPTED_URI) if (args.containsKey(ReaderConstants.ARG_POST_LIST_TYPE)) { - this.postListType = args.getSerializable(ReaderConstants.ARG_POST_LIST_TYPE) as ReaderPostListType + postListType = requireNotNull( + args.getSerializableCompat(ReaderConstants.ARG_POST_LIST_TYPE) + ) } postSlugsResolutionUnderway = args.getBoolean(ReaderConstants.KEY_POST_SLUGS_RESOLUTION_UNDERWAY) } @@ -499,7 +503,7 @@ class ReaderPostDetailFragment : ViewPagerFragment(), private fun initLikeFacesRecycler(savedInstanceState: Bundle?) { if (!likesEnhancementsFeatureConfig.isEnabled()) return val layoutManager = LinearLayoutManager(activity, LinearLayoutManager.HORIZONTAL, false) - savedInstanceState?.getParcelable(KEY_LIKERS_LIST_STATE)?.let { + savedInstanceState?.getParcelableCompat(KEY_LIKERS_LIST_STATE)?.let { layoutManager.onRestoreInstanceState(it) } @@ -518,7 +522,7 @@ class ReaderPostDetailFragment : ViewPagerFragment(), if (!commentsSnippetFeatureConfig.isEnabled()) return val layoutManager = LinearLayoutManager(activity) - savedInstanceState?.getParcelable(KEY_COMMENTS_SNIPPET_LIST_STATE)?.let { + savedInstanceState?.getParcelableCompat(KEY_COMMENTS_SNIPPET_LIST_STATE)?.let { layoutManager.onRestoreInstanceState(it) } @@ -1082,8 +1086,7 @@ class ReaderPostDetailFragment : ViewPagerFragment(), savedInstanceState?.let { blogId = it.getLong(ReaderConstants.ARG_BLOG_ID) postId = it.getLong(ReaderConstants.ARG_POST_ID) - directOperation = it - .getSerializable(ReaderConstants.ARG_DIRECT_OPERATION) as? DirectOperation + directOperation = it.getSerializableCompat(ReaderConstants.ARG_DIRECT_OPERATION) commentId = it.getInt(ReaderConstants.ARG_COMMENT_ID) isRelatedPost = it.getBoolean(ReaderConstants.ARG_IS_RELATED_POST) interceptedUri = it.getString(ReaderConstants.ARG_INTERCEPTED_URI) @@ -1092,7 +1095,7 @@ class ReaderPostDetailFragment : ViewPagerFragment(), hasTrackedGlobalRelatedPosts = it.getBoolean(ReaderConstants.KEY_ALREADY_TRACKED_GLOBAL_RELATED_POSTS) hasTrackedLocalRelatedPosts = it.getBoolean(ReaderConstants.KEY_ALREADY_TRACKED_LOCAL_RELATED_POSTS) if (it.containsKey(ReaderConstants.ARG_POST_LIST_TYPE)) { - this.postListType = it.getSerializable(ReaderConstants.ARG_POST_LIST_TYPE) as ReaderPostListType + postListType = requireNotNull(it.getSerializableCompat(ReaderConstants.ARG_POST_LIST_TYPE)) } if (it.containsKey(ReaderConstants.KEY_ERROR_MESSAGE)) { errorMessage = it.getString(ReaderConstants.KEY_ERROR_MESSAGE) diff --git a/WordPress/src/main/java/org/wordpress/android/ui/reader/SubfilterBottomSheetFragment.kt b/WordPress/src/main/java/org/wordpress/android/ui/reader/SubfilterBottomSheetFragment.kt index d183bf67fa3f..8f3c49226f1a 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/reader/SubfilterBottomSheetFragment.kt +++ b/WordPress/src/main/java/org/wordpress/android/ui/reader/SubfilterBottomSheetFragment.kt @@ -24,6 +24,7 @@ import org.wordpress.android.ui.reader.subfilter.SubfilterCategory.SITES import org.wordpress.android.ui.reader.subfilter.SubfilterCategory.TAGS import org.wordpress.android.ui.reader.subfilter.SubfilterListItem.Tag import org.wordpress.android.ui.reader.subfilter.SubfilterPagerAdapter +import org.wordpress.android.util.extensions.getParcelableArrayListCompat import javax.inject.Inject class SubfilterBottomSheetFragment : BottomSheetDialogFragment() { @@ -66,8 +67,9 @@ class SubfilterBottomSheetFragment : BottomSheetDialogFragment() { val subfilterVmKey = requireArguments().getString(SUBFILTER_VIEW_MODEL_KEY)!! val bottomSheetTitle = requireArguments().getCharSequence(SUBFILTER_TITLE_KEY)!! - val categories: ArrayList = requireArguments() - .getParcelableArrayList(SUBFILTER_CATEGORIES_KEY)!! + val categories = requireNotNull( + requireArguments().getParcelableArrayListCompat(SUBFILTER_CATEGORIES_KEY) + ) viewModel = ViewModelProvider(parentFragment as ViewModelStoreOwner, viewModelFactory) .get(subfilterVmKey, SubFilterViewModel::class.java) diff --git a/WordPress/src/main/java/org/wordpress/android/ui/reader/discover/interests/ReaderInterestsFragment.kt b/WordPress/src/main/java/org/wordpress/android/ui/reader/discover/interests/ReaderInterestsFragment.kt index 9679ce2f978d..29415dce9f88 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/reader/discover/interests/ReaderInterestsFragment.kt +++ b/WordPress/src/main/java/org/wordpress/android/ui/reader/discover/interests/ReaderInterestsFragment.kt @@ -17,6 +17,7 @@ import org.wordpress.android.ui.reader.discover.interests.ReaderInterestsViewMod import org.wordpress.android.ui.reader.viewmodels.ReaderViewModel import org.wordpress.android.ui.utils.UiHelpers import org.wordpress.android.util.LocaleManager +import org.wordpress.android.util.extensions.getSerializableExtraCompat import org.wordpress.android.viewmodel.observeEvent import org.wordpress.android.widgets.WPSnackbar import javax.inject.Inject @@ -37,7 +38,7 @@ class ReaderInterestsFragment : Fragment(R.layout.reader_interests_fragment_layo override fun onViewCreated(view: View, savedInstanceState: Bundle?) { super.onViewCreated(view, savedInstanceState) - val entryPoint = requireActivity().intent.getSerializableExtra(READER_INTEREST_ENTRY_POINT) as? EntryPoint + val entryPoint = requireActivity().intent.getSerializableExtraCompat(READER_INTEREST_ENTRY_POINT) ?: EntryPoint.DISCOVER with(ReaderInterestsFragmentLayoutBinding.bind(view)) { initDoneButton() diff --git a/WordPress/src/main/java/org/wordpress/android/ui/reader/services/discover/ReaderDiscoverService.kt b/WordPress/src/main/java/org/wordpress/android/ui/reader/services/discover/ReaderDiscoverService.kt index 05853601af7d..6b1dfe14eb0f 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/reader/services/discover/ReaderDiscoverService.kt +++ b/WordPress/src/main/java/org/wordpress/android/ui/reader/services/discover/ReaderDiscoverService.kt @@ -14,6 +14,7 @@ import org.wordpress.android.ui.reader.services.discover.ReaderDiscoverServiceSt import org.wordpress.android.util.AppLog import org.wordpress.android.util.AppLog.T.READER import org.wordpress.android.util.LocaleManager +import org.wordpress.android.util.extensions.getSerializableExtraCompat import javax.inject.Inject import javax.inject.Named import kotlin.coroutines.CoroutineContext @@ -56,7 +57,7 @@ class ReaderDiscoverService : Service(), ServiceCompletionListener, CoroutineSco override fun onStartCommand(intent: Intent?, flags: Int, startId: Int): Int { if (intent != null && intent.hasExtra(ARG_DISCOVER_TASK)) { - val task = intent.getSerializableExtra(ARG_DISCOVER_TASK) as DiscoverTasks + val task = requireNotNull(intent.getSerializableExtraCompat(ARG_DISCOVER_TASK)) readerDiscoverLogic.performTasks(task, null, this, this) } return START_NOT_STICKY diff --git a/WordPress/src/main/java/org/wordpress/android/ui/reader/subfilter/SubfilterPageFragment.kt b/WordPress/src/main/java/org/wordpress/android/ui/reader/subfilter/SubfilterPageFragment.kt index 5059cf202a3f..4754376d1a62 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/reader/subfilter/SubfilterPageFragment.kt +++ b/WordPress/src/main/java/org/wordpress/android/ui/reader/subfilter/SubfilterPageFragment.kt @@ -35,6 +35,7 @@ import org.wordpress.android.ui.reader.viewmodels.SubfilterPageViewModel import org.wordpress.android.ui.stats.refresh.utils.StatsUtils import org.wordpress.android.ui.utils.UiHelpers import org.wordpress.android.util.config.SeenUnseenWithCounterFeatureConfig +import org.wordpress.android.util.extensions.getSerializableCompat import org.wordpress.android.widgets.WPTextView import java.lang.ref.WeakReference import javax.inject.Inject @@ -80,7 +81,7 @@ class SubfilterPageFragment : DaggerFragment() { override fun onViewCreated(view: View, savedInstanceState: Bundle?) { super.onViewCreated(view, savedInstanceState) - val category = requireArguments().getSerializable(CATEGORY_KEY) as SubfilterCategory + val category = requireNotNull(arguments?.getSerializableCompat(CATEGORY_KEY)) val subfilterVmKey = requireArguments().getString(SUBFILTER_VIEW_MODEL_KEY)!! viewModel = ViewModelProvider(this, viewModelFactory).get(SubfilterPageViewModel::class.java) diff --git a/WordPress/src/main/java/org/wordpress/android/ui/sitecreation/SiteCreationMainVM.kt b/WordPress/src/main/java/org/wordpress/android/ui/sitecreation/SiteCreationMainVM.kt index 26a0d4ea9fa5..6190a3fefaff 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/sitecreation/SiteCreationMainVM.kt +++ b/WordPress/src/main/java/org/wordpress/android/ui/sitecreation/SiteCreationMainVM.kt @@ -32,6 +32,7 @@ import org.wordpress.android.util.AppLog.T import org.wordpress.android.util.NetworkUtilsWrapper import org.wordpress.android.util.config.SiteCreationDomainPurchasingFeatureConfig import org.wordpress.android.util.experiments.SiteCreationDomainPurchasingExperiment +import org.wordpress.android.util.extensions.getParcelableCompat import org.wordpress.android.util.image.ImageManager import org.wordpress.android.util.wizard.WizardManager import org.wordpress.android.util.wizard.WizardNavigationTarget @@ -128,7 +129,7 @@ class SiteCreationMainVM @Inject constructor( showSiteCreationNextStep() } else { siteCreationCompleted = savedInstanceState.getBoolean(KEY_SITE_CREATION_COMPLETED, false) - siteCreationState = requireNotNull(savedInstanceState.getParcelable(KEY_SITE_CREATION_STATE)) + siteCreationState = requireNotNull(savedInstanceState.getParcelableCompat(KEY_SITE_CREATION_STATE)) val currentStepIndex = savedInstanceState.getInt(KEY_CURRENT_STEP) wizardManager.setCurrentStepIndex(currentStepIndex) } diff --git a/WordPress/src/main/java/org/wordpress/android/ui/sitecreation/previews/SiteCreationPreviewFragment.kt b/WordPress/src/main/java/org/wordpress/android/ui/sitecreation/previews/SiteCreationPreviewFragment.kt index d4aa6e19a9f0..785da3cb29d9 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/sitecreation/previews/SiteCreationPreviewFragment.kt +++ b/WordPress/src/main/java/org/wordpress/android/ui/sitecreation/previews/SiteCreationPreviewFragment.kt @@ -41,6 +41,7 @@ import org.wordpress.android.util.AppLog import org.wordpress.android.util.AutoForeground.ServiceEventConnection import org.wordpress.android.util.ErrorManagedWebViewClient.ErrorManagedWebViewClientListener import org.wordpress.android.util.URLFilteredWebViewClient +import org.wordpress.android.util.extensions.getParcelableCompat import javax.inject.Inject private const val ARG_DATA = "arg_site_creation_data" @@ -97,7 +98,7 @@ class SiteCreationPreviewFragment : SiteCreationBaseFormFragment(), super.onViewCreated(view, savedInstanceState) (requireActivity() as AppCompatActivity).supportActionBar?.hide() - viewModel.start(requireArguments()[ARG_DATA] as SiteCreationState, savedInstanceState) + viewModel.start(requireNotNull(arguments?.getParcelableCompat(ARG_DATA)), savedInstanceState) } override fun getContentLayout(): Int { diff --git a/WordPress/src/main/java/org/wordpress/android/ui/sitecreation/previews/SitePreviewViewModel.kt b/WordPress/src/main/java/org/wordpress/android/ui/sitecreation/previews/SitePreviewViewModel.kt index e78740aa5e8b..ccd6a2370f21 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/sitecreation/previews/SitePreviewViewModel.kt +++ b/WordPress/src/main/java/org/wordpress/android/ui/sitecreation/previews/SitePreviewViewModel.kt @@ -49,6 +49,7 @@ import org.wordpress.android.util.AppLog import org.wordpress.android.util.AppLog.T import org.wordpress.android.util.NetworkUtilsWrapper import org.wordpress.android.util.UrlUtilsWrapper +import org.wordpress.android.util.extensions.getParcelableCompat import org.wordpress.android.viewmodel.SingleLiveEvent import javax.inject.Inject import javax.inject.Named @@ -137,7 +138,7 @@ class SitePreviewViewModel @Inject constructor( urlWithoutScheme = siteCreationState.domain siteTitle = siteCreationState.siteName - val restoredState = savedState?.getParcelable(KEY_CREATE_SITE_STATE) + val restoredState = savedState?.getParcelableCompat(KEY_CREATE_SITE_STATE) init(restoredState ?: SiteNotCreated) } diff --git a/WordPress/src/main/java/org/wordpress/android/ui/sitecreation/services/SiteCreationService.kt b/WordPress/src/main/java/org/wordpress/android/ui/sitecreation/services/SiteCreationService.kt index 958c79f64157..3e6556dc90d0 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/sitecreation/services/SiteCreationService.kt +++ b/WordPress/src/main/java/org/wordpress/android/ui/sitecreation/services/SiteCreationService.kt @@ -17,6 +17,7 @@ import org.wordpress.android.util.AppLog.T import org.wordpress.android.util.AutoForeground import org.wordpress.android.util.LocaleManager import org.wordpress.android.util.LocaleManagerWrapper +import org.wordpress.android.util.extensions.getParcelableExtraCompat import javax.inject.Inject private val INITIAL_STATE = IDLE @@ -47,7 +48,7 @@ class SiteCreationService : AutoForeground(SiteCreatio return Service.START_NOT_STICKY } - val data = intent.getParcelableExtra(ARG_DATA)!! + val data = requireNotNull(intent.getParcelableExtraCompat(ARG_DATA)) manager.onStart( LocaleManager.getLanguageWordPressId(this), localeManagerWrapper.getTimeZone().id, diff --git a/WordPress/src/main/java/org/wordpress/android/ui/stats/StatsConnectJetpackActivity.kt b/WordPress/src/main/java/org/wordpress/android/ui/stats/StatsConnectJetpackActivity.kt index 4a41baa16a05..e63d0018f31a 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/stats/StatsConnectJetpackActivity.kt +++ b/WordPress/src/main/java/org/wordpress/android/ui/stats/StatsConnectJetpackActivity.kt @@ -22,6 +22,7 @@ import org.wordpress.android.ui.WPWebViewActivity import org.wordpress.android.util.AppLog import org.wordpress.android.util.AppLog.T.API import org.wordpress.android.util.WPUrlUtils +import org.wordpress.android.util.extensions.getSerializableExtraCompat import javax.inject.Inject /** @@ -72,14 +73,18 @@ class StatsConnectJetpackActivity : LocaleAwareActivity() { if (TextUtils.isEmpty(mAccountStore.account.userName)) { mDispatcher.dispatch(AccountActionBuilder.newFetchAccountAction()) } else { - startJetpackConnectionFlow(intent.getSerializableExtra(WordPress.SITE) as SiteModel) + startJetpackConnectionFlow( + requireNotNull(intent.getSerializableExtraCompat(WordPress.SITE)) + ) } } } private fun StatsJetpackConnectionActivityBinding.initViews() { jetpackSetup.setOnClickListener { - startJetpackConnectionFlow(intent.getSerializableExtra(WordPress.SITE) as SiteModel) + startJetpackConnectionFlow( + requireNotNull(intent.getSerializableExtraCompat(WordPress.SITE)) + ) } jetpackFaq.setOnClickListener { WPWebViewActivity.openURL(this@StatsConnectJetpackActivity, FAQ_URL) @@ -133,7 +138,7 @@ class StatsConnectJetpackActivity : LocaleAwareActivity() { event.causeOfChange == FETCH_ACCOUNT && !TextUtils.isEmpty(mAccountStore.account.userName) ) { - startJetpackConnectionFlow(intent.getSerializableExtra(WordPress.SITE) as SiteModel) + startJetpackConnectionFlow(requireNotNull(intent.getSerializableExtraCompat(WordPress.SITE))) } } } diff --git a/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/StatsViewAllFragment.kt b/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/StatsViewAllFragment.kt index 016d5fe6d934..2761693c1d14 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/StatsViewAllFragment.kt +++ b/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/StatsViewAllFragment.kt @@ -34,6 +34,10 @@ import org.wordpress.android.ui.stats.refresh.utils.StatsSiteProvider import org.wordpress.android.ui.stats.refresh.utils.drawDateSelector import org.wordpress.android.ui.utils.UiHelpers import org.wordpress.android.util.WPSwipeToRefreshHelper +import org.wordpress.android.util.extensions.getParcelableCompat +import org.wordpress.android.util.extensions.getParcelableExtraCompat +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.util.image.ImageManager import org.wordpress.android.viewmodel.observeEvent @@ -78,13 +82,13 @@ class StatsViewAllFragment : DaggerFragment(R.layout.stats_view_all_fragment) { if (intent.hasExtra(ARGS_VIEW_TYPE)) { outState.putSerializable( ARGS_VIEW_TYPE, - intent.getSerializableExtra(ARGS_VIEW_TYPE) + intent.getSerializableExtraCompat(ARGS_VIEW_TYPE) ) } if (intent.hasExtra(ARGS_TIMEFRAME)) { outState.putSerializable( ARGS_TIMEFRAME, - intent.getSerializableExtra(ARGS_TIMEFRAME) + intent.getSerializableExtraCompat(ARGS_TIMEFRAME) ) } outState.putInt(WordPress.LOCAL_SITE_ID, intent.getIntExtra(WordPress.LOCAL_SITE_ID, 0)) @@ -96,7 +100,7 @@ class StatsViewAllFragment : DaggerFragment(R.layout.stats_view_all_fragment) { private fun StatsViewAllFragmentBinding.initializeViews(savedInstanceState: Bundle?) { val layoutManager = LinearLayoutManager(activity, RecyclerView.VERTICAL, false) - savedInstanceState?.getParcelable(listStateKey)?.let { + savedInstanceState?.getParcelableCompat(listStateKey)?.let { layoutManager.onRestoreInstanceState(it) } with(statsListFragment) { @@ -153,16 +157,18 @@ class StatsViewAllFragment : DaggerFragment(R.layout.stats_view_all_fragment) { savedInstanceState: Bundle? ) { val nonNullIntent = checkNotNull(activity.intent) - val type = if (savedInstanceState == null) { - nonNullIntent.getSerializableExtra(ARGS_VIEW_TYPE) as StatsViewType - } else { - savedInstanceState.getSerializable(ARGS_VIEW_TYPE) as StatsViewType - } + val type: StatsViewType = requireNotNull( + if (savedInstanceState == null) { + nonNullIntent.getSerializableExtraCompat(ARGS_VIEW_TYPE) + } else { + savedInstanceState.getSerializableCompat(ARGS_VIEW_TYPE) + } + ) - val granularity = if (savedInstanceState == null) { - nonNullIntent.getSerializableExtra(ARGS_TIMEFRAME) as StatsGranularity? + val granularity: StatsGranularity? = if (savedInstanceState == null) { + nonNullIntent.getSerializableExtraCompat(ARGS_TIMEFRAME) } else { - savedInstanceState.getSerializable(ARGS_TIMEFRAME) as StatsGranularity? + savedInstanceState.getSerializableCompat(ARGS_TIMEFRAME) } val siteId = savedInstanceState?.getInt(WordPress.LOCAL_SITE_ID, 0) @@ -172,10 +178,10 @@ class StatsViewAllFragment : DaggerFragment(R.layout.stats_view_all_fragment) { val viewModelFactory = viewModelFactoryBuilder.build(type, granularity) viewModel = ViewModelProvider(activity, viewModelFactory).get(StatsViewAllViewModel::class.java) - val selectedDate = if (savedInstanceState == null) { - nonNullIntent.getParcelableExtra(ARGS_SELECTED_DATE) as SelectedDate? + val selectedDate: SelectedDate? = if (savedInstanceState == null) { + nonNullIntent.getParcelableExtraCompat(ARGS_SELECTED_DATE) } else { - savedInstanceState.getParcelable(ARGS_SELECTED_DATE) as SelectedDate? + savedInstanceState.getParcelableCompat(ARGS_SELECTED_DATE) } setupObservers(activity) diff --git a/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/StatsViewModel.kt b/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/StatsViewModel.kt index fb785a27f043..9ebc14e5b248 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/StatsViewModel.kt +++ b/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/StatsViewModel.kt @@ -53,6 +53,7 @@ import org.wordpress.android.util.JetpackBrandingUtils import org.wordpress.android.util.NetworkUtilsWrapper import org.wordpress.android.util.analytics.AnalyticsTrackerWrapper import org.wordpress.android.util.config.MySiteDashboardTodaysStatsCardFeatureConfig +import org.wordpress.android.util.extensions.getSerializableExtraCompat import org.wordpress.android.util.mapNullable import org.wordpress.android.util.mergeNotNull import org.wordpress.android.viewmodel.Event @@ -114,10 +115,10 @@ class StatsViewModel fun start(intent: Intent, restart: Boolean = false) { val localSiteId = intent.getIntExtra(WordPress.LOCAL_SITE_ID, 0) - val launchedFrom = intent.getSerializableExtra(StatsActivity.ARG_LAUNCHED_FROM) + val launchedFrom = intent.getSerializableExtraCompat(StatsActivity.ARG_LAUNCHED_FROM) val initialTimeFrame = getInitialTimeFrame(intent) val initialSelectedPeriod = intent.getStringExtra(StatsActivity.INITIAL_SELECTED_PERIOD_KEY) - val notificationType = intent.getSerializableExtra(ARG_NOTIFICATION_TYPE) as? NotificationType + val notificationType = intent.getSerializableExtraCompat(ARG_NOTIFICATION_TYPE) start(localSiteId, launchedFrom, initialTimeFrame, initialSelectedPeriod, restart, notificationType) } @@ -135,7 +136,7 @@ class StatsViewModel } private fun getInitialTimeFrame(intent: Intent): StatsSection? { - return when (intent.getSerializableExtra(StatsActivity.ARG_DESIRED_TIMEFRAME)) { + return when (intent.getSerializableExtraCompat(StatsActivity.ARG_DESIRED_TIMEFRAME)) { StatsTimeframe.INSIGHTS -> StatsSection.INSIGHTS DAY -> StatsSection.DAYS WEEK -> StatsSection.WEEKS diff --git a/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/lists/StatsListFragment.kt b/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/lists/StatsListFragment.kt index 5cec079d6b34..37d05e639033 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/lists/StatsListFragment.kt +++ b/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/lists/StatsListFragment.kt @@ -27,6 +27,9 @@ import org.wordpress.android.ui.stats.refresh.lists.detail.DetailListViewModel import org.wordpress.android.ui.stats.refresh.utils.StatsDateFormatter import org.wordpress.android.ui.stats.refresh.utils.StatsNavigator import org.wordpress.android.ui.stats.refresh.utils.drawDateSelector +import org.wordpress.android.util.extensions.getParcelableCompat +import org.wordpress.android.util.extensions.getSerializableCompat +import org.wordpress.android.util.extensions.getSerializableExtraCompat import org.wordpress.android.util.extensions.setVisible import org.wordpress.android.util.image.ImageManager import org.wordpress.android.viewmodel.observeEvent @@ -68,8 +71,8 @@ class StatsListFragment : ViewPagerFragment(R.layout.stats_list_fragment) { override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) - statsSection = arguments?.getSerializable(LIST_TYPE) as? StatsSection - ?: activity?.intent?.getSerializableExtra(LIST_TYPE) as? StatsSection + statsSection = arguments?.getSerializableCompat(LIST_TYPE) + ?: activity?.intent?.getSerializableExtraCompat(LIST_TYPE) ?: StatsSection.INSIGHTS setHasOptionsMenu(statsSection == StatsSection.INSIGHTS) @@ -80,7 +83,7 @@ class StatsListFragment : ViewPagerFragment(R.layout.stats_list_fragment) { layoutManager?.let { outState.putParcelable(listStateKey, it.onSaveInstanceState()) } - (activity?.intent?.getSerializableExtra(LIST_TYPE) as? StatsSection)?.let { sectionFromIntent -> + (activity?.intent?.getSerializableExtraCompat(LIST_TYPE))?.let { sectionFromIntent -> outState.putSerializable(LIST_TYPE, sectionFromIntent) } super.onSaveInstanceState(outState) @@ -110,7 +113,7 @@ class StatsListFragment : ViewPagerFragment(R.layout.stats_list_fragment) { } else { StaggeredGridLayoutManager(columns, StaggeredGridLayoutManager.VERTICAL) } - savedInstanceState?.getParcelable(listStateKey)?.let { + savedInstanceState?.getParcelableCompat(listStateKey)?.let { layoutManager.onRestoreInstanceState(it) } diff --git a/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/lists/detail/InsightsDetailFragment.kt b/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/lists/detail/InsightsDetailFragment.kt index 6a360420730e..45f709eef9d6 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/lists/detail/InsightsDetailFragment.kt +++ b/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/lists/detail/InsightsDetailFragment.kt @@ -13,7 +13,9 @@ import org.wordpress.android.databinding.StatsDetailFragmentBinding import org.wordpress.android.ui.stats.refresh.lists.StatsListFragment import org.wordpress.android.ui.stats.refresh.lists.StatsListViewModel.StatsSection import org.wordpress.android.util.WPSwipeToRefreshHelper +import org.wordpress.android.util.extensions.getSerializableCompat import org.wordpress.android.util.helpers.SwipeToRefreshHelper +import java.io.Serializable @AndroidEntryPoint class InsightsDetailFragment : Fragment(R.layout.stats_detail_fragment) { @@ -29,7 +31,9 @@ class InsightsDetailFragment : Fragment(R.layout.stats_detail_fragment) { super.onViewCreated(view, savedInstanceState) val nonNullActivity = requireActivity() - val listType = nonNullActivity.intent.extras?.get(StatsListFragment.LIST_TYPE) as StatsSection + val listType = requireNotNull( + nonNullActivity.intent.extras?.getSerializableCompat(StatsListFragment.LIST_TYPE) + ) with(StatsDetailFragmentBinding.bind(view)) { with(nonNullActivity as AppCompatActivity) { setSupportActionBar(toolbar) @@ -52,7 +56,7 @@ class InsightsDetailFragment : Fragment(R.layout.stats_detail_fragment) { private fun initializeViewModels(activity: FragmentActivity) { val siteId = activity.intent?.getIntExtra(WordPress.LOCAL_SITE_ID, 0) ?: 0 - val listType = activity.intent.extras?.get(StatsListFragment.LIST_TYPE) + val listType = activity.intent.extras?.getSerializableCompat(StatsListFragment.LIST_TYPE) viewModel = when (listType) { StatsSection.INSIGHT_DETAIL -> viewsVisitorsDetailViewModel diff --git a/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/lists/detail/StatsDetailActivity.kt b/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/lists/detail/StatsDetailActivity.kt index 96cd7188653a..0391ba1e0474 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/lists/detail/StatsDetailActivity.kt +++ b/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/lists/detail/StatsDetailActivity.kt @@ -20,6 +20,8 @@ import org.wordpress.android.ui.stats.refresh.lists.StatsListFragment import org.wordpress.android.ui.stats.refresh.lists.StatsListViewModel.StatsSection import org.wordpress.android.ui.stats.refresh.lists.sections.granular.SelectedDateProvider.SelectedDate import org.wordpress.android.util.analytics.AnalyticsUtils +import org.wordpress.android.util.extensions.getSerializableCompat +import java.io.Serializable const val POST_ID = "POST_ID" const val POST_TYPE = "POST_TYPE" @@ -33,7 +35,7 @@ class StatsDetailActivity : LocaleAwareActivity() { val binding = StatsDetailActivityBinding.inflate(layoutInflater) setContentView(binding.root) - val listType = intent.extras?.get(StatsListFragment.LIST_TYPE) + val listType = intent.extras?.getSerializableCompat(StatsListFragment.LIST_TYPE) if (savedInstanceState == null) { supportFragmentManager.commit { diff --git a/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/lists/detail/StatsDetailFragment.kt b/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/lists/detail/StatsDetailFragment.kt index 28995aa27790..abd848737dbd 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/lists/detail/StatsDetailFragment.kt +++ b/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/lists/detail/StatsDetailFragment.kt @@ -94,9 +94,9 @@ class StatsDetailFragment : DaggerFragment(R.layout.stats_detail_fragment) { statsSiteProvider.start(siteId) val postId = activity.intent?.getLongExtra(POST_ID, 0L) - val postType = activity.intent?.getSerializableExtra(POST_TYPE) as String? - val postTitle = activity.intent?.getSerializableExtra(POST_TITLE) as String? - val postUrl = activity.intent?.getSerializableExtra(POST_URL) as String? + val postType = activity.intent?.getStringExtra(POST_TYPE) + val postTitle = activity.intent?.getStringExtra(POST_TITLE) + val postUrl = activity.intent?.getStringExtra(POST_URL) viewModel = ViewModelProvider(this, viewModelFactory) .get(StatsSection.DETAIL.name, StatsDetailViewModel::class.java) diff --git a/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/lists/sections/granular/SelectedDateProvider.kt b/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/lists/sections/granular/SelectedDateProvider.kt index f77b236a5ce8..3bb2e2a5a0eb 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/lists/sections/granular/SelectedDateProvider.kt +++ b/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/lists/sections/granular/SelectedDateProvider.kt @@ -20,6 +20,7 @@ import org.wordpress.android.ui.stats.refresh.utils.StatsDateFormatter import org.wordpress.android.ui.stats.refresh.utils.toStatsSection import org.wordpress.android.ui.stats.refresh.utils.trackWithSection import org.wordpress.android.util.analytics.AnalyticsTrackerWrapper +import org.wordpress.android.util.extensions.getParcelableCompat import org.wordpress.android.util.filter import java.util.Date import javax.inject.Inject @@ -172,7 +173,7 @@ class SelectedDateProvider fun onRestoreInstanceState(savedState: Bundle) { for (period in listOf(DAYS, WEEKS, MONTHS, YEARS)) { - val selectedDate: SelectedDate? = savedState.getParcelable(buildStateKey(period)) as SelectedDate? + val selectedDate = savedState.getParcelableCompat(buildStateKey(period)) if (selectedDate != null) { mutableDates[period] = selectedDate } diff --git a/WordPress/src/main/java/org/wordpress/android/ui/stories/StoriesMediaPickerResultHandler.kt b/WordPress/src/main/java/org/wordpress/android/ui/stories/StoriesMediaPickerResultHandler.kt index 1c8d265a4170..fd6b57d8626b 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/stories/StoriesMediaPickerResultHandler.kt +++ b/WordPress/src/main/java/org/wordpress/android/ui/stories/StoriesMediaPickerResultHandler.kt @@ -16,6 +16,7 @@ import org.wordpress.android.ui.mysite.SiteNavigationAction.AddNewStoryWithMedia import org.wordpress.android.ui.photopicker.MediaPickerConstants import org.wordpress.android.util.AppLog import org.wordpress.android.util.AppLog.T.UTILS +import org.wordpress.android.util.extensions.getSerializableExtraCompat import org.wordpress.android.viewmodel.Event import javax.inject.Inject @@ -109,8 +110,10 @@ class StoriesMediaPickerResultHandler private fun isWPStoriesMediaBrowserTypeResult(data: Intent): Boolean { if (data.hasExtra(MediaBrowserActivity.ARG_BROWSER_TYPE)) { - val browserType = data.getSerializableExtra(MediaBrowserActivity.ARG_BROWSER_TYPE) - return (browserType as MediaBrowserType).isWPStoriesPicker + val browserType = requireNotNull( + data.getSerializableExtraCompat(MediaBrowserActivity.ARG_BROWSER_TYPE) + ) + return browserType.isWPStoriesPicker } return false } diff --git a/WordPress/src/main/java/org/wordpress/android/ui/stories/StoriesTrackerHelper.kt b/WordPress/src/main/java/org/wordpress/android/ui/stories/StoriesTrackerHelper.kt index a71e8bae6a26..d85a287721d2 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/stories/StoriesTrackerHelper.kt +++ b/WordPress/src/main/java/org/wordpress/android/ui/stories/StoriesTrackerHelper.kt @@ -6,6 +6,7 @@ import org.wordpress.android.analytics.AnalyticsTracker import org.wordpress.android.analytics.AnalyticsTracker.Stat import org.wordpress.android.fluxc.model.SiteModel import org.wordpress.android.util.analytics.AnalyticsUtils +import org.wordpress.android.util.extensions.getSerializableCompat import javax.inject.Inject class StoriesTrackerHelper @Inject constructor() { @@ -33,7 +34,7 @@ class StoriesTrackerHelper @Inject constructor() { val properties = getCommonProperties(event) var siteModel: SiteModel? = null event.metadata?.let { - siteModel = it.getSerializable(WordPress.SITE) as SiteModel + siteModel = it.getSerializableCompat(WordPress.SITE) } siteModel?.let { diff --git a/WordPress/src/main/java/org/wordpress/android/ui/stories/StoryComposerActivity.kt b/WordPress/src/main/java/org/wordpress/android/ui/stories/StoryComposerActivity.kt index 6e377a93d654..cc0ab302ab3f 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/stories/StoryComposerActivity.kt +++ b/WordPress/src/main/java/org/wordpress/android/ui/stories/StoryComposerActivity.kt @@ -86,6 +86,10 @@ import org.wordpress.android.util.WPMediaUtils import org.wordpress.android.util.WPPermissionUtils import org.wordpress.android.util.analytics.AnalyticsTrackerWrapper import org.wordpress.android.util.analytics.AnalyticsUtilsWrapper +import org.wordpress.android.util.extensions.getParcelableCompat +import org.wordpress.android.util.extensions.getParcelableExtraCompat +import org.wordpress.android.util.extensions.getSerializableCompat +import org.wordpress.android.util.extensions.getSerializableExtraCompat import org.wordpress.android.util.helpers.MediaFile import org.wordpress.android.viewmodel.observeEvent import org.wordpress.android.widgets.WPSnackbar @@ -197,10 +201,10 @@ class StoryComposerActivity : ComposeLoopFrameActivity(), } private fun initSite(savedInstanceState: Bundle?) { - if (savedInstanceState == null) { - site = intent.getSerializableExtra(WordPress.SITE) as SiteModel + site = if (savedInstanceState == null) { + intent.getSerializableExtraCompat(WordPress.SITE) } else { - site = savedInstanceState.getSerializable(WordPress.SITE) as SiteModel + savedInstanceState.getSerializableCompat(WordPress.SITE) } } @@ -211,10 +215,10 @@ class StoryComposerActivity : ComposeLoopFrameActivity(), if (savedInstanceState == null) { localPostId = getBackingPostIdFromIntent() - originalStorySaveResult = intent.getParcelableExtra(KEY_STORY_SAVE_RESULT) as StorySaveResult? + originalStorySaveResult = intent.getParcelableExtraCompat(KEY_STORY_SAVE_RESULT) if (intent.hasExtra(ARG_NOTIFICATION_TYPE)) { - notificationType = intent.getSerializableExtra(ARG_NOTIFICATION_TYPE) as NotificationType + notificationType = intent.getSerializableExtraCompat(ARG_NOTIFICATION_TYPE) } } else { if (savedInstanceState.containsKey(STATE_KEY_POST_LOCAL_ID)) { @@ -222,7 +226,7 @@ class StoryComposerActivity : ComposeLoopFrameActivity(), } if (savedInstanceState.containsKey(STATE_KEY_ORIGINAL_STORY_SAVE_RESULT)) { originalStorySaveResult = - savedInstanceState.getParcelable(STATE_KEY_ORIGINAL_STORY_SAVE_RESULT) as StorySaveResult? + savedInstanceState.getParcelableCompat(STATE_KEY_ORIGINAL_STORY_SAVE_RESULT) } } @@ -370,8 +374,7 @@ class StoryComposerActivity : ComposeLoopFrameActivity(), var localPostId = intent.getIntExtra(KEY_POST_LOCAL_ID, 0) if (localPostId == 0) { if (intent.hasExtra(KEY_STORY_SAVE_RESULT)) { - val storySaveResult = - intent.getParcelableExtra(KEY_STORY_SAVE_RESULT) as StorySaveResult? + val storySaveResult = intent.getParcelableExtraCompat(KEY_STORY_SAVE_RESULT) storySaveResult?.let { localPostId = it.metadata?.getInt(KEY_POST_LOCAL_ID, 0) ?: 0 } diff --git a/WordPress/src/main/java/org/wordpress/android/ui/stories/intro/StoriesIntroDialogFragment.kt b/WordPress/src/main/java/org/wordpress/android/ui/stories/intro/StoriesIntroDialogFragment.kt index e33508182de2..48434305d4aa 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/stories/intro/StoriesIntroDialogFragment.kt +++ b/WordPress/src/main/java/org/wordpress/android/ui/stories/intro/StoriesIntroDialogFragment.kt @@ -15,6 +15,7 @@ import org.wordpress.android.databinding.StoriesIntroDialogFragmentBinding import org.wordpress.android.fluxc.model.SiteModel import org.wordpress.android.ui.ActivityLauncher import org.wordpress.android.ui.photopicker.MediaPickerLauncher +import org.wordpress.android.util.extensions.getSerializableCompat import org.wordpress.android.util.extensions.setStatusBarAsSurfaceColor import javax.inject.Inject @@ -59,7 +60,7 @@ class StoriesIntroDialogFragment : DialogFragment() { override fun onViewCreated(view: View, savedInstanceState: Bundle?) { super.onViewCreated(view, savedInstanceState) - val site = requireArguments().getSerializable(WordPress.SITE) as SiteModel + val site = requireArguments().getSerializableCompat(WordPress.SITE) with(StoriesIntroDialogFragmentBinding.bind(view)) { createStoryIntroButton.setOnClickListener { viewModel.onCreateStoryButtonPressed() } storiesIntroBackButton.setOnClickListener { viewModel.onBackButtonPressed() } diff --git a/WordPress/src/main/java/org/wordpress/android/ui/stories/media/StoryMediaSaveUploadBridge.kt b/WordPress/src/main/java/org/wordpress/android/ui/stories/media/StoryMediaSaveUploadBridge.kt index 72c008aaddc4..5fa9fa173fd8 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/stories/media/StoryMediaSaveUploadBridge.kt +++ b/WordPress/src/main/java/org/wordpress/android/ui/stories/media/StoryMediaSaveUploadBridge.kt @@ -36,6 +36,7 @@ import org.wordpress.android.util.EventBusWrapper import org.wordpress.android.util.NetworkUtilsWrapper import org.wordpress.android.util.ToastUtils import org.wordpress.android.util.ToastUtils.Duration.LONG +import org.wordpress.android.util.extensions.getSerializableCompat import org.wordpress.android.util.helpers.MediaFile import javax.inject.Inject import javax.inject.Named @@ -239,7 +240,7 @@ class StoryMediaSaveUploadBridge @Inject constructor( storiesTrackerHelper.trackStorySaveResultEvent(event) event.metadata?.let { - val site = it.getSerializable(WordPress.SITE) as SiteModel + val site = requireNotNull(it.getSerializableCompat(WordPress.SITE)) val story = storyRepositoryWrapper.getStoryAtIndex(event.storyIndex) saveStoryGutenbergBlockUseCase.saveNewLocalFilesToStoriesPrefsTempSlides( site, diff --git a/WordPress/src/main/java/org/wordpress/android/ui/suggestion/SuggestionActivity.kt b/WordPress/src/main/java/org/wordpress/android/ui/suggestion/SuggestionActivity.kt index 7239d8b0378f..9e160c569cdb 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/suggestion/SuggestionActivity.kt +++ b/WordPress/src/main/java/org/wordpress/android/ui/suggestion/SuggestionActivity.kt @@ -24,6 +24,7 @@ import org.wordpress.android.ui.suggestion.adapters.SuggestionAdapter import org.wordpress.android.util.AppLog import org.wordpress.android.util.AppLog.T import org.wordpress.android.util.ToastUtils +import org.wordpress.android.util.extensions.getSerializableExtraCompat import org.wordpress.android.util.extensions.onBackPressedCompat import org.wordpress.android.widgets.SuggestionAutoCompleteText import javax.inject.Inject @@ -49,8 +50,8 @@ class SuggestionActivity : LocaleAwareActivity() { onBackPressedDispatcher.onBackPressedCompat(this) } - val siteModel = intent.getSerializableExtra(INTENT_KEY_SITE_MODEL) as? SiteModel - val suggestionType = intent.getSerializableExtra(INTENT_KEY_SUGGESTION_TYPE) as? SuggestionType + val siteModel = intent.getSerializableExtraCompat(INTENT_KEY_SITE_MODEL) + val suggestionType = intent.getSerializableExtraCompat(INTENT_KEY_SUGGESTION_TYPE) when { siteModel == null -> abortDueToMissingIntentExtra(INTENT_KEY_SITE_MODEL) suggestionType == null -> abortDueToMissingIntentExtra(INTENT_KEY_SUGGESTION_TYPE) diff --git a/WordPress/src/main/java/org/wordpress/android/viewmodel/plugins/PluginBrowserViewModel.kt b/WordPress/src/main/java/org/wordpress/android/viewmodel/plugins/PluginBrowserViewModel.kt index be200abd07fc..8290e4ad2561 100644 --- a/WordPress/src/main/java/org/wordpress/android/viewmodel/plugins/PluginBrowserViewModel.kt +++ b/WordPress/src/main/java/org/wordpress/android/viewmodel/plugins/PluginBrowserViewModel.kt @@ -30,6 +30,7 @@ import org.wordpress.android.ui.ListDiffCallback import org.wordpress.android.util.AppLog import org.wordpress.android.util.AppLog.T import org.wordpress.android.util.SiteUtils +import org.wordpress.android.util.extensions.getSerializableCompat import org.wordpress.android.viewmodel.plugins.PluginBrowserViewModel.PluginListType.FEATURED import org.wordpress.android.viewmodel.plugins.PluginBrowserViewModel.PluginListType.NEW import org.wordpress.android.viewmodel.plugins.PluginBrowserViewModel.PluginListType.POPULAR @@ -138,7 +139,7 @@ class PluginBrowserViewModel @Inject constructor( // read from the bundle return } - site = savedInstanceState.getSerializable(WordPress.SITE) as SiteModel + site = requireNotNull(savedInstanceState.getSerializableCompat(WordPress.SITE)) searchQuery = requireNotNull(savedInstanceState.getString(KEY_SEARCH_QUERY)) setTitle(savedInstanceState.getString(KEY_TITLE)) } diff --git a/WordPress/src/test/java/org/wordpress/android/ui/accounts/login/jetpack/LoginNoSitesViewModelTest.kt b/WordPress/src/test/java/org/wordpress/android/ui/accounts/login/jetpack/LoginNoSitesViewModelTest.kt index 43560b33d49c..7a267b1a8799 100644 --- a/WordPress/src/test/java/org/wordpress/android/ui/accounts/login/jetpack/LoginNoSitesViewModelTest.kt +++ b/WordPress/src/test/java/org/wordpress/android/ui/accounts/login/jetpack/LoginNoSitesViewModelTest.kt @@ -21,6 +21,7 @@ import org.wordpress.android.ui.accounts.UnifiedLoginTracker 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.ui.accounts.login.jetpack.LoginNoSitesViewModel.UiModel +import org.wordpress.android.util.extensions.getSerializableCompat private const val USERNAME = "username" private const val DISPLAY_NAME = "display_name" @@ -152,11 +153,11 @@ class LoginNoSitesViewModelTest : BaseUnitTest() { } private fun setupInstanceStateForNoUser() { - whenever(savedInstanceState.getSerializable(KEY_STATE)).thenReturn(NoUser) + whenever(savedInstanceState.getSerializableCompat(KEY_STATE)).thenReturn(NoUser) } private fun setupInstanceStateForShowUser() { - whenever(savedInstanceState.getSerializable(KEY_STATE)).thenReturn( + whenever(savedInstanceState.getSerializableCompat(KEY_STATE)).thenReturn( ShowUser( userName = USERNAME, displayName = DISPLAY_NAME, diff --git a/WordPress/src/test/java/org/wordpress/android/ui/jetpack/backup/download/BackupDownloadViewModelTest.kt b/WordPress/src/test/java/org/wordpress/android/ui/jetpack/backup/download/BackupDownloadViewModelTest.kt index 48f14274e95e..aa6290a639b4 100644 --- a/WordPress/src/test/java/org/wordpress/android/ui/jetpack/backup/download/BackupDownloadViewModelTest.kt +++ b/WordPress/src/test/java/org/wordpress/android/ui/jetpack/backup/download/BackupDownloadViewModelTest.kt @@ -42,6 +42,7 @@ import org.wordpress.android.ui.jetpack.common.providers.JetpackAvailableItemsPr import org.wordpress.android.ui.jetpack.usecases.GetActivityLogItemUseCase import org.wordpress.android.ui.pages.SnackbarMessageHolder import org.wordpress.android.ui.utils.UiString.UiStringRes +import org.wordpress.android.util.extensions.getParcelableCompat import org.wordpress.android.util.text.PercentFormatter import org.wordpress.android.util.wizard.WizardManager import org.wordpress.android.util.wizard.WizardNavigationTarget @@ -426,7 +427,7 @@ class BackupDownloadViewModelTest : BaseUnitTest() { private fun startViewModelForProgress() { whenever(savedInstanceState.getInt(KEY_BACKUP_DOWNLOAD_CURRENT_STEP)) .thenReturn(BackupDownloadStep.PROGRESS.id) - whenever(savedInstanceState.getParcelable(KEY_BACKUP_DOWNLOAD_STATE)) + whenever(savedInstanceState.getParcelableCompat(KEY_BACKUP_DOWNLOAD_STATE)) .thenReturn(backupDownloadState) whenever(percentFormatter.format(30)) .thenReturn("30%") @@ -439,7 +440,7 @@ class BackupDownloadViewModelTest : BaseUnitTest() { private fun startViewModelForComplete(backupDownloadState: BackupDownloadState? = null) { whenever(savedInstanceState.getInt(KEY_BACKUP_DOWNLOAD_CURRENT_STEP)) .thenReturn(BackupDownloadStep.COMPLETE.id) - whenever(savedInstanceState.getParcelable(KEY_BACKUP_DOWNLOAD_STATE)) + whenever(savedInstanceState.getParcelableCompat(KEY_BACKUP_DOWNLOAD_STATE)) .thenReturn(backupDownloadState) startViewModel(savedInstanceState) } @@ -447,7 +448,7 @@ class BackupDownloadViewModelTest : BaseUnitTest() { private fun startViewModelForError() { whenever(savedInstanceState.getInt(KEY_BACKUP_DOWNLOAD_CURRENT_STEP)) .thenReturn(BackupDownloadStep.ERROR.id) - whenever(savedInstanceState.getParcelable(KEY_BACKUP_DOWNLOAD_STATE)) + whenever(savedInstanceState.getParcelableCompat(KEY_BACKUP_DOWNLOAD_STATE)) .thenReturn(backupDownloadState) startViewModel(savedInstanceState) } diff --git a/WordPress/src/test/java/org/wordpress/android/ui/jetpack/restore/RestoreViewModelTest.kt b/WordPress/src/test/java/org/wordpress/android/ui/jetpack/restore/RestoreViewModelTest.kt index b676056375cc..0c50149d97b9 100644 --- a/WordPress/src/test/java/org/wordpress/android/ui/jetpack/restore/RestoreViewModelTest.kt +++ b/WordPress/src/test/java/org/wordpress/android/ui/jetpack/restore/RestoreViewModelTest.kt @@ -60,6 +60,7 @@ import org.wordpress.android.ui.pages.SnackbarMessageHolder import org.wordpress.android.ui.utils.HtmlMessageUtils import org.wordpress.android.ui.utils.UiString.UiStringRes import org.wordpress.android.ui.utils.UiString.UiStringText +import org.wordpress.android.util.extensions.getParcelableCompat import org.wordpress.android.util.text.PercentFormatter import org.wordpress.android.util.wizard.WizardManager import org.wordpress.android.util.wizard.WizardNavigationTarget @@ -459,7 +460,7 @@ class RestoreViewModelTest : BaseUnitTest() { private fun startViewModelForStep(step: RestoreStep, restoreState: RestoreState? = null) { whenever(savedInstanceState.getInt(KEY_RESTORE_CURRENT_STEP)) .thenReturn(step.id) - whenever(savedInstanceState.getParcelable(KEY_RESTORE_STATE)) + whenever(savedInstanceState.getParcelableCompat(KEY_RESTORE_STATE)) .thenReturn(restoreState ?: this.restoreState) startViewModel(savedInstanceState) } diff --git a/WordPress/src/test/java/org/wordpress/android/ui/sitecreation/SiteCreationMainVMTest.kt b/WordPress/src/test/java/org/wordpress/android/ui/sitecreation/SiteCreationMainVMTest.kt index 70bee937febc..8ac0ea6a7103 100644 --- a/WordPress/src/test/java/org/wordpress/android/ui/sitecreation/SiteCreationMainVMTest.kt +++ b/WordPress/src/test/java/org/wordpress/android/ui/sitecreation/SiteCreationMainVMTest.kt @@ -39,6 +39,7 @@ import org.wordpress.android.ui.sitecreation.usecases.FetchHomePageLayoutsUseCas import org.wordpress.android.util.NetworkUtilsWrapper import org.wordpress.android.util.config.SiteCreationDomainPurchasingFeatureConfig import org.wordpress.android.util.experiments.SiteCreationDomainPurchasingExperiment +import org.wordpress.android.util.extensions.getParcelableCompat import org.wordpress.android.util.image.ImageManager import org.wordpress.android.util.wizard.WizardManager import org.wordpress.android.viewmodel.SingleLiveEvent @@ -245,7 +246,7 @@ class SiteCreationMainVMTest : BaseUnitTest() { /* we need to model a real use case of data only existing for steps the user has visited (Segment only in this case). Otherwise, subsequent steps' state will be cleared and make the test fail. (issue #10189)*/ val expectedState = SiteCreationState(segmentId = SEGMENT_ID) - whenever(savedInstanceState.getParcelable(KEY_SITE_CREATION_STATE)) + whenever(savedInstanceState.getParcelableCompat(KEY_SITE_CREATION_STATE)) .thenReturn(expectedState) // we need to create a new instance of the VM as the `viewModel` has already been started in setUp() @@ -266,7 +267,7 @@ class SiteCreationMainVMTest : BaseUnitTest() { whenever(savedInstanceState.getInt(KEY_CURRENT_STEP)).thenReturn(index) // siteCreationState is not nullable - we need to set it - whenever(savedInstanceState.getParcelable(KEY_SITE_CREATION_STATE)) + whenever(savedInstanceState.getParcelableCompat(KEY_SITE_CREATION_STATE)) .thenReturn(SiteCreationState()) // we need to create a new instance of the VM as the `viewModel` has already been started in setUp() @@ -290,7 +291,7 @@ class SiteCreationMainVMTest : BaseUnitTest() { @Test fun `given instance state is not null, when start, then site creation accessed is not tracked`() { val expectedState = SiteCreationState(segmentId = SEGMENT_ID) - whenever(savedInstanceState.getParcelable(KEY_SITE_CREATION_STATE)) + whenever(savedInstanceState.getParcelableCompat(KEY_SITE_CREATION_STATE)) .thenReturn(expectedState) val newViewModel = getNewViewModel() diff --git a/WordPress/src/test/java/org/wordpress/android/ui/sitecreation/previews/SitePreviewViewModelTest.kt b/WordPress/src/test/java/org/wordpress/android/ui/sitecreation/previews/SitePreviewViewModelTest.kt index edbb991c60d2..9c31c26cfd3b 100644 --- a/WordPress/src/test/java/org/wordpress/android/ui/sitecreation/previews/SitePreviewViewModelTest.kt +++ b/WordPress/src/test/java/org/wordpress/android/ui/sitecreation/previews/SitePreviewViewModelTest.kt @@ -45,6 +45,7 @@ import org.wordpress.android.ui.sitecreation.services.SiteCreationServiceState.S import org.wordpress.android.ui.sitecreation.theme.defaultTemplateSlug import org.wordpress.android.util.NetworkUtilsWrapper import org.wordpress.android.util.UrlUtilsWrapper +import org.wordpress.android.util.extensions.getParcelableCompat private const val SUB_DOMAIN = "test" private const val DOMAIN = ".wordpress.com" @@ -302,7 +303,7 @@ class SitePreviewViewModelTest : BaseUnitTest() { @Test fun `show fullscreen progress when restoring from SiteNotCreated state`() = testWithSuccessResponse { - whenever(bundle.getParcelable(KEY_CREATE_SITE_STATE)).thenReturn(SiteNotCreated) + whenever(bundle.getParcelableCompat(KEY_CREATE_SITE_STATE)).thenReturn(SiteNotCreated) initViewModel(bundle) assertThat(viewModel.uiState.value).isInstanceOf(SitePreviewFullscreenProgressUiState::class.java) @@ -311,7 +312,7 @@ class SitePreviewViewModelTest : BaseUnitTest() { @Test fun `service started when restoring from SiteNotCreated state`() { - whenever(bundle.getParcelable(KEY_CREATE_SITE_STATE)).thenReturn(SiteNotCreated) + whenever(bundle.getParcelableCompat(KEY_CREATE_SITE_STATE)).thenReturn(SiteNotCreated) initViewModel(bundle) assertThat(viewModel.startCreateSiteService.value).isNotNull @@ -319,7 +320,7 @@ class SitePreviewViewModelTest : BaseUnitTest() { @Test fun `show fullscreen progress when restoring from SiteNotInLocalDb state`() = testWithSuccessResponse { - whenever(bundle.getParcelable(KEY_CREATE_SITE_STATE)).thenReturn(SiteNotCreated) + whenever(bundle.getParcelableCompat(KEY_CREATE_SITE_STATE)).thenReturn(SiteNotCreated) initViewModel(bundle) assertThat(viewModel.uiState.value).isInstanceOf(SitePreviewFullscreenProgressUiState::class.java) @@ -328,7 +329,7 @@ class SitePreviewViewModelTest : BaseUnitTest() { @Test fun `start pre-loading WebView when restoring from SiteNotInLocalDb state`() = testWithSuccessResponse { - whenever(bundle.getParcelable(KEY_CREATE_SITE_STATE)) + whenever(bundle.getParcelableCompat(KEY_CREATE_SITE_STATE)) .thenReturn(SiteNotInLocalDb(REMOTE_SITE_ID, false)) initViewModel(bundle) @@ -337,7 +338,7 @@ class SitePreviewViewModelTest : BaseUnitTest() { @Test fun `fetch newly created SiteModel when restoring from SiteNotInLocalDb state`() = testWithSuccessResponse { - whenever(bundle.getParcelable(KEY_CREATE_SITE_STATE)) + whenever(bundle.getParcelableCompat(KEY_CREATE_SITE_STATE)) .thenReturn(SiteNotInLocalDb(REMOTE_SITE_ID, false)) initViewModel(bundle) @@ -346,7 +347,7 @@ class SitePreviewViewModelTest : BaseUnitTest() { @Test fun `start pre-loading WebView when restoring from SiteCreationCompleted state`() { - whenever(bundle.getParcelable(KEY_CREATE_SITE_STATE)) + whenever(bundle.getParcelableCompat(KEY_CREATE_SITE_STATE)) .thenReturn(SiteCreationCompleted(LOCAL_SITE_ID, false)) initViewModel(bundle) diff --git a/libs/image-editor/src/main/kotlin/org/wordpress/android/imageeditor/crop/CropViewModel.kt b/libs/image-editor/src/main/kotlin/org/wordpress/android/imageeditor/crop/CropViewModel.kt index 9a435262331d..34935886c9e9 100644 --- a/libs/image-editor/src/main/kotlin/org/wordpress/android/imageeditor/crop/CropViewModel.kt +++ b/libs/image-editor/src/main/kotlin/org/wordpress/android/imageeditor/crop/CropViewModel.kt @@ -23,6 +23,8 @@ import org.wordpress.android.imageeditor.crop.CropViewModel.ImageCropAndSaveStat import org.wordpress.android.imageeditor.crop.CropViewModel.UiState.UiLoadedState import org.wordpress.android.imageeditor.crop.CropViewModel.UiState.UiStartLoadingWithBundleState import org.wordpress.android.imageeditor.preview.PreviewImageFragment.Companion.EditImageData.OutputData +import org.wordpress.android.imageeditor.utils.getParcelableCompat +import org.wordpress.android.imageeditor.utils.getParcelableExtraCompat import org.wordpress.android.imageeditor.viewmodel.Event import java.io.File import java.io.Serializable @@ -158,10 +160,10 @@ class CropViewModel : ViewModel() { private fun createCropResult(cropResultCode: Int, cropData: Intent) = CropResult(cropResultCode, cropData) private fun getOutputPath(): String = - cropOptionsBundleWithFilesInfo.getParcelable(UCrop.EXTRA_OUTPUT_URI)?.path ?: "" + cropOptionsBundleWithFilesInfo.getParcelableCompat(UCrop.EXTRA_OUTPUT_URI)?.path ?: "" fun getOutputData(cropResult: CropResult): ArrayList { - val imageUri: Uri? = cropResult.data.getParcelableExtra(UCrop.EXTRA_OUTPUT_URI) + val imageUri = cropResult.data.getParcelableExtraCompat(UCrop.EXTRA_OUTPUT_URI) return if (imageUri != null) { arrayListOf(OutputData(imageUri.toString())) diff --git a/libs/image-editor/src/main/kotlin/org/wordpress/android/imageeditor/preview/PreviewImageFragment.kt b/libs/image-editor/src/main/kotlin/org/wordpress/android/imageeditor/preview/PreviewImageFragment.kt index 995f4f6d1145..9bc2e25e7e89 100644 --- a/libs/image-editor/src/main/kotlin/org/wordpress/android/imageeditor/preview/PreviewImageFragment.kt +++ b/libs/image-editor/src/main/kotlin/org/wordpress/android/imageeditor/preview/PreviewImageFragment.kt @@ -40,6 +40,8 @@ import org.wordpress.android.imageeditor.preview.PreviewImageViewModel.UiState import org.wordpress.android.imageeditor.utils.ToastUtils import org.wordpress.android.imageeditor.utils.ToastUtils.Duration import org.wordpress.android.imageeditor.utils.UiHelpers +import org.wordpress.android.imageeditor.utils.getParcelableArrayListExtraCompat +import org.wordpress.android.imageeditor.utils.getParcelableExtraCompat import java.io.File class PreviewImageFragment : Fragment(R.layout.preview_image_fragment), MenuProvider { @@ -150,7 +152,7 @@ class PreviewImageFragment : Fragment(R.layout.preview_image_fragment), MenuProv viewModel = ViewModelProvider(this@PreviewImageFragment).get(PreviewImageViewModel::class.java) parentViewModel = ViewModelProvider(requireActivity()).get(EditImageViewModel::class.java) setupObservers() - val inputData = nonNullIntent.getParcelableArrayListExtra(ARG_EDIT_IMAGE_DATA) + val inputData = nonNullIntent.getParcelableArrayListExtraCompat(ARG_EDIT_IMAGE_DATA) inputData?.let { viewModel.onCreateView(it, ImageEditor.instance) } } @@ -186,7 +188,7 @@ class PreviewImageFragment : Fragment(R.layout.preview_image_fragment), MenuProv if (it.resultCode == RESULT_OK) { val data: Intent = it.data if (data.hasExtra(UCrop.EXTRA_OUTPUT_URI)) { - val imageUri = data.getParcelableExtra(UCrop.EXTRA_OUTPUT_URI) as? Uri + val imageUri = data.getParcelableExtraCompat(UCrop.EXTRA_OUTPUT_URI) imageUri?.let { uri -> viewModel.onCropResult(uri.toString()) } From f34517cb8ce74dea11094a0850ab0fc694b07c21 Mon Sep 17 00:00:00 2001 From: Irfan Omur Date: Tue, 7 Mar 2023 22:38:19 +0300 Subject: [PATCH 026/856] Use type-safe functions for Bundle --- .../JetpackFeatureFullScreenOverlayFragment.kt | 9 +++------ .../android/ui/prefs/homepage/HomepageSettingsDialog.kt | 6 +++--- .../reader/services/discover/ReaderDiscoverJobService.kt | 2 +- 3 files changed, 7 insertions(+), 10 deletions(-) diff --git a/WordPress/src/main/java/org/wordpress/android/ui/jetpackoverlay/JetpackFeatureFullScreenOverlayFragment.kt b/WordPress/src/main/java/org/wordpress/android/ui/jetpackoverlay/JetpackFeatureFullScreenOverlayFragment.kt index aaa73a1cc89b..7b8cdae5cb72 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/jetpackoverlay/JetpackFeatureFullScreenOverlayFragment.kt +++ b/WordPress/src/main/java/org/wordpress/android/ui/jetpackoverlay/JetpackFeatureFullScreenOverlayFragment.kt @@ -96,18 +96,15 @@ class JetpackFeatureFullScreenOverlayFragment : BottomSheetDialogFragment() { private fun getSiteScreen() = arguments?.getSerializableCompat(OVERLAY_SCREEN_TYPE) - private fun getIfSiteCreationOverlay() = - arguments?.getSerializable(IS_SITE_CREATION_OVERLAY) as Boolean + private fun getIfSiteCreationOverlay() = arguments?.getBoolean(IS_SITE_CREATION_OVERLAY) ?: false - private fun getIfDeepLinkOverlay() = - arguments?.getSerializable(IS_DEEP_LINK_OVERLAY) as Boolean + private fun getIfDeepLinkOverlay() = arguments?.getBoolean(IS_DEEP_LINK_OVERLAY) ?: false private fun getSiteCreationSource() = requireNotNull( arguments?.getSerializableCompat(SITE_CREATION_OVERLAY_SOURCE) ) - private fun getIfFeatureCollectionOverlay() = - arguments?.getSerializable(IS_FEATURE_COLLECTION_OVERLAY) as Boolean + private fun getIfFeatureCollectionOverlay() = arguments?.getBoolean(IS_FEATURE_COLLECTION_OVERLAY) ?: false private fun getFeatureCollectionOverlaysSource() = requireNotNull( arguments?.getSerializableCompat(FEATURE_COLLECTION_OVERLAY_SOURCE) diff --git a/WordPress/src/main/java/org/wordpress/android/ui/prefs/homepage/HomepageSettingsDialog.kt b/WordPress/src/main/java/org/wordpress/android/ui/prefs/homepage/HomepageSettingsDialog.kt index 4f15c7c921d0..109641838839 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/prefs/homepage/HomepageSettingsDialog.kt +++ b/WordPress/src/main/java/org/wordpress/android/ui/prefs/homepage/HomepageSettingsDialog.kt @@ -39,9 +39,9 @@ class HomepageSettingsDialog : DialogFragment() { var pageForPostsId: Long? = null (arguments ?: savedInstanceState)?.let { bundle -> siteId = bundle.getInt(KEY_SITE_ID) - isClassicBlog = bundle.get(KEY_IS_CLASSIC_BLOG)?.let { it as Boolean } - pageOnFrontId = bundle.get(KEY_PAGE_ON_FRONT)?.let { it as Long } - pageForPostsId = bundle.get(KEY_PAGE_FOR_POSTS)?.let { it as Long } + isClassicBlog = bundle.getBoolean(KEY_IS_CLASSIC_BLOG) + pageOnFrontId = bundle.getLong(KEY_PAGE_ON_FRONT) + pageForPostsId = bundle.getLong(KEY_PAGE_FOR_POSTS) } ?: throw IllegalArgumentException("Site has to be initialized") val builder = MaterialAlertDialogBuilder(requireActivity()) builder.setPositiveButton(R.string.site_settings_accept_homepage) { _, _ -> } diff --git a/WordPress/src/main/java/org/wordpress/android/ui/reader/services/discover/ReaderDiscoverJobService.kt b/WordPress/src/main/java/org/wordpress/android/ui/reader/services/discover/ReaderDiscoverJobService.kt index 64bc0036f843..8513c880565d 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/reader/services/discover/ReaderDiscoverJobService.kt +++ b/WordPress/src/main/java/org/wordpress/android/ui/reader/services/discover/ReaderDiscoverJobService.kt @@ -37,7 +37,7 @@ class ReaderDiscoverJobService : JobService(), ServiceCompletionListener, Corout override fun onStartJob(params: JobParameters): Boolean { AppLog.i(READER, "reader discover job service > started") - val task = DiscoverTasks.values()[(params.extras[ReaderDiscoverServiceStarter.ARG_DISCOVER_TASK] as Int)] + val task = DiscoverTasks.values()[params.extras.getInt(ReaderDiscoverServiceStarter.ARG_DISCOVER_TASK)] readerDiscoverLogic.performTasks(task, params, this, this) return true From dcb6e30569383c8b0de3b6d8c4363b7d679d1a77 Mon Sep 17 00:00:00 2001 From: Irfan Omur Date: Tue, 7 Mar 2023 22:19:29 +0300 Subject: [PATCH 027/856] Replace get calls with indexing operator --- .../ui/JetpackRemoteInstallFragment.kt | 2 +- .../list/ActivityLogListFragment.kt | 2 +- .../unified/UnifiedCommentListFragment.kt | 4 ++-- .../DomainRegistrationDetailsFragment.kt | 7 +++---- .../ui/domains/DomainSuggestionsFragment.kt | 7 +++---- .../ui/domains/DomainsDashboardFragment.kt | 2 +- .../backup/download/BackupDownloadFragment.kt | 2 +- .../ui/jetpack/restore/RestoreFragment.kt | 2 +- .../android/ui/pages/PageListFragment.kt | 2 +- .../android/ui/pages/PageParentFragment.kt | 3 +-- .../ui/people/PeopleInviteDialogFragment.kt | 2 +- .../android/ui/posts/HistoryListFragment.kt | 2 +- .../ui/posts/PostDatePickerDialogFragment.kt | 12 +++++++---- .../android/ui/posts/PostListFragment.kt | 5 ++--- ...tNotificationScheduleTimeDialogFragment.kt | 12 +++++++---- .../ui/posts/PostTimePickerDialogFragment.kt | 20 +++++++++---------- .../posts/PrepublishingAddCategoryFragment.kt | 10 ++++++---- .../posts/PrepublishingBottomSheetFragment.kt | 3 +-- .../posts/PrepublishingCategoriesFragment.kt | 10 ++++++---- .../prefs/homepage/HomepageSettingsDialog.kt | 4 ++-- .../ui/reader/SubfilterBottomSheetFragment.kt | 6 ++++-- .../reader/subfilter/SubfilterPageFragment.kt | 2 +- .../ui/stories/StoryComposerActivity.kt | 3 +-- 23 files changed, 66 insertions(+), 58 deletions(-) diff --git a/WordPress/src/main/java/org/wordpress/android/ui/JetpackRemoteInstallFragment.kt b/WordPress/src/main/java/org/wordpress/android/ui/JetpackRemoteInstallFragment.kt index 73be72492857..83998d3ec898 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/JetpackRemoteInstallFragment.kt +++ b/WordPress/src/main/java/org/wordpress/android/ui/JetpackRemoteInstallFragment.kt @@ -52,7 +52,7 @@ class JetpackRemoteInstallFragment : Fragment(R.layout.jetpack_remote_install_fr savedInstanceState?.getSerializableCompat(VIEW_STATE) viewModel = ViewModelProvider( this@JetpackRemoteInstallFragment, viewModelFactory - ).get(JetpackRemoteInstallViewModel::class.java) + )[JetpackRemoteInstallViewModel::class.java] viewModel.start(site, retrievedState) initLiveViewStateObserver() diff --git a/WordPress/src/main/java/org/wordpress/android/ui/activitylog/list/ActivityLogListFragment.kt b/WordPress/src/main/java/org/wordpress/android/ui/activitylog/list/ActivityLogListFragment.kt index 4263b8444580..6e9c7e848abe 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/activitylog/list/ActivityLogListFragment.kt +++ b/WordPress/src/main/java/org/wordpress/android/ui/activitylog/list/ActivityLogListFragment.kt @@ -75,7 +75,7 @@ class ActivityLogListFragment : Fragment(R.layout.activity_log_list_fragment) { viewModel = ViewModelProvider( this@ActivityLogListFragment, viewModelFactory - ).get(ActivityLogViewModel::class.java) + )[ActivityLogViewModel::class.java] with(ActivityLogListFragmentBinding.bind(view)) { listView = logListView diff --git a/WordPress/src/main/java/org/wordpress/android/ui/comments/unified/UnifiedCommentListFragment.kt b/WordPress/src/main/java/org/wordpress/android/ui/comments/unified/UnifiedCommentListFragment.kt index 3cdace123e93..678a92899610 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/comments/unified/UnifiedCommentListFragment.kt +++ b/WordPress/src/main/java/org/wordpress/android/ui/comments/unified/UnifiedCommentListFragment.kt @@ -71,11 +71,11 @@ 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) + )[UnifiedCommentActivityViewModel::class.java] arguments?.let { commentListFilter = requireNotNull(it.getSerializableCompat(KEY_COMMENT_LIST_FILTER)) } diff --git a/WordPress/src/main/java/org/wordpress/android/ui/domains/DomainRegistrationDetailsFragment.kt b/WordPress/src/main/java/org/wordpress/android/ui/domains/DomainRegistrationDetailsFragment.kt index b0391271d8bd..f82d45b7ade7 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/domains/DomainRegistrationDetailsFragment.kt +++ b/WordPress/src/main/java/org/wordpress/android/ui/domains/DomainRegistrationDetailsFragment.kt @@ -90,10 +90,9 @@ class DomainRegistrationDetailsFragment : Fragment() { override fun onViewCreated(view: View, savedInstanceState: Bundle?) { super.onViewCreated(view, savedInstanceState) - mainViewModel = ViewModelProvider(requireActivity(), viewModelFactory) - .get(DomainRegistrationMainViewModel::class.java) - viewModel = ViewModelProvider(this, viewModelFactory) - .get(DomainRegistrationDetailsViewModel::class.java) + mainViewModel = + ViewModelProvider(requireActivity(), viewModelFactory)[DomainRegistrationMainViewModel::class.java] + viewModel = ViewModelProvider(this, viewModelFactory)[DomainRegistrationDetailsViewModel::class.java] with(DomainRegistrationDetailsFragmentBinding.bind(view)) { binding = this setupObservers() diff --git a/WordPress/src/main/java/org/wordpress/android/ui/domains/DomainSuggestionsFragment.kt b/WordPress/src/main/java/org/wordpress/android/ui/domains/DomainSuggestionsFragment.kt index 8354c8d5ae17..cd154d27602e 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/domains/DomainSuggestionsFragment.kt +++ b/WordPress/src/main/java/org/wordpress/android/ui/domains/DomainSuggestionsFragment.kt @@ -39,11 +39,10 @@ class DomainSuggestionsFragment : Fragment(R.layout.domain_suggestions_fragment) super.onViewCreated(view, savedInstanceState) (requireActivity().application as WordPress).component().inject(this) - mainViewModel = ViewModelProvider(requireActivity(), viewModelFactory) - .get(DomainRegistrationMainViewModel::class.java) + mainViewModel = + ViewModelProvider(requireActivity(), viewModelFactory)[DomainRegistrationMainViewModel::class.java] - viewModel = ViewModelProvider(this, viewModelFactory) - .get(DomainSuggestionsViewModel::class.java) + viewModel = ViewModelProvider(this, viewModelFactory)[DomainSuggestionsViewModel::class.java] with(DomainSuggestionsFragmentBinding.bind(view)) { val intent = requireActivity().intent diff --git a/WordPress/src/main/java/org/wordpress/android/ui/domains/DomainsDashboardFragment.kt b/WordPress/src/main/java/org/wordpress/android/ui/domains/DomainsDashboardFragment.kt index f48f58315d33..79dff8216353 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/domains/DomainsDashboardFragment.kt +++ b/WordPress/src/main/java/org/wordpress/android/ui/domains/DomainsDashboardFragment.kt @@ -48,7 +48,7 @@ class DomainsDashboardFragment : Fragment(R.layout.domains_dashboard_fragment) { private fun setupViewModel() { val intent = requireActivity().intent val site = requireNotNull(intent.getSerializableExtraCompat(WordPress.SITE)) - viewModel = ViewModelProvider(requireActivity(), viewModelFactory).get(DomainsDashboardViewModel::class.java) + viewModel = ViewModelProvider(requireActivity(), viewModelFactory)[DomainsDashboardViewModel::class.java] viewModel.start(site) } diff --git a/WordPress/src/main/java/org/wordpress/android/ui/jetpack/backup/download/BackupDownloadFragment.kt b/WordPress/src/main/java/org/wordpress/android/ui/jetpack/backup/download/BackupDownloadFragment.kt index fa2374243cf6..7c8914fee3fd 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/jetpack/backup/download/BackupDownloadFragment.kt +++ b/WordPress/src/main/java/org/wordpress/android/ui/jetpack/backup/download/BackupDownloadFragment.kt @@ -76,7 +76,7 @@ class BackupDownloadFragment : Fragment(R.layout.jetpack_backup_restore_fragment viewModel = ViewModelProvider( this@BackupDownloadFragment, viewModelFactory - ).get(BackupDownloadViewModel::class.java) + )[BackupDownloadViewModel::class.java] val (site, activityId) = when { requireActivity().intent?.extras != null -> { diff --git a/WordPress/src/main/java/org/wordpress/android/ui/jetpack/restore/RestoreFragment.kt b/WordPress/src/main/java/org/wordpress/android/ui/jetpack/restore/RestoreFragment.kt index 65b526d4d52c..a9fe86a5eff9 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/jetpack/restore/RestoreFragment.kt +++ b/WordPress/src/main/java/org/wordpress/android/ui/jetpack/restore/RestoreFragment.kt @@ -70,7 +70,7 @@ class RestoreFragment : Fragment(R.layout.jetpack_backup_restore_fragment) { } private fun JetpackBackupRestoreFragmentBinding.initViewModel(savedInstanceState: Bundle?) { - viewModel = ViewModelProvider(this@RestoreFragment, viewModelFactory).get(RestoreViewModel::class.java) + viewModel = ViewModelProvider(this@RestoreFragment, viewModelFactory)[RestoreViewModel::class.java] val (site, activityId) = when { requireActivity().intent?.extras != null -> { diff --git a/WordPress/src/main/java/org/wordpress/android/ui/pages/PageListFragment.kt b/WordPress/src/main/java/org/wordpress/android/ui/pages/PageListFragment.kt index 1cc2642d6bff..75aba3fbaa73 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/pages/PageListFragment.kt +++ b/WordPress/src/main/java/org/wordpress/android/ui/pages/PageListFragment.kt @@ -90,7 +90,7 @@ class PageListFragment : ViewPagerFragment(R.layout.pages_list_fragment) { } private fun PagesListFragmentBinding.initializeViewModels(activity: FragmentActivity) { - val pagesViewModel = ViewModelProvider(activity, viewModelFactory).get(PagesViewModel::class.java) + val pagesViewModel = ViewModelProvider(activity, viewModelFactory)[PagesViewModel::class.java] val listType = requireNotNull(arguments?.getSerializableCompat(typeKey)) viewModel = diff --git a/WordPress/src/main/java/org/wordpress/android/ui/pages/PageParentFragment.kt b/WordPress/src/main/java/org/wordpress/android/ui/pages/PageParentFragment.kt index c18356012d82..02628c31f887 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/pages/PageParentFragment.kt +++ b/WordPress/src/main/java/org/wordpress/android/ui/pages/PageParentFragment.kt @@ -180,8 +180,7 @@ class PageParentFragment : Fragment(R.layout.page_parent_fragment), MenuProvider pageId: Long, isFirstStart: Boolean ) { - viewModel = ViewModelProvider(activity, viewModelFactory) - .get(PageParentViewModel::class.java) + viewModel = ViewModelProvider(activity, viewModelFactory)[PageParentViewModel::class.java] setupObservers() diff --git a/WordPress/src/main/java/org/wordpress/android/ui/people/PeopleInviteDialogFragment.kt b/WordPress/src/main/java/org/wordpress/android/ui/people/PeopleInviteDialogFragment.kt index 2c4b56c41421..85455ab0c6c0 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/people/PeopleInviteDialogFragment.kt +++ b/WordPress/src/main/java/org/wordpress/android/ui/people/PeopleInviteDialogFragment.kt @@ -44,7 +44,7 @@ class PeopleInviteDialogFragment : DialogFragment() { override fun onCreateDialog(savedInstanceState: Bundle?): Dialog { viewModel = ViewModelProvider( targetFragment as ViewModelStoreOwner, viewModelFactory - ).get(PeopleInviteViewModel::class.java) + )[PeopleInviteViewModel::class.java] val dialogMode = arguments?.getSerializableCompat(ARG_DIALOG_MODE) val roles = arguments?.getStringArray(ARG_ROLES) diff --git a/WordPress/src/main/java/org/wordpress/android/ui/posts/HistoryListFragment.kt b/WordPress/src/main/java/org/wordpress/android/ui/posts/HistoryListFragment.kt index 0cd075c2dd97..ba5fb62aabb4 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/posts/HistoryListFragment.kt +++ b/WordPress/src/main/java/org/wordpress/android/ui/posts/HistoryListFragment.kt @@ -85,7 +85,7 @@ class HistoryListFragment : Fragment(R.layout.history_list_fragment) { (nonNullActivity.application as WordPress).component().inject(this@HistoryListFragment) - viewModel = ViewModelProvider(this@HistoryListFragment, viewModelFactory).get(HistoryViewModel::class.java) + viewModel = ViewModelProvider(this@HistoryListFragment, viewModelFactory)[HistoryViewModel::class.java] val site = requireNotNull(arguments?.getSerializableCompat(KEY_SITE)) viewModel.create( localPostId = arguments?.getInt(KEY_POST_LOCAL_ID) ?: 0, diff --git a/WordPress/src/main/java/org/wordpress/android/ui/posts/PostDatePickerDialogFragment.kt b/WordPress/src/main/java/org/wordpress/android/ui/posts/PostDatePickerDialogFragment.kt index 80e88b9f6f4d..c40d280a8cc1 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/posts/PostDatePickerDialogFragment.kt +++ b/WordPress/src/main/java/org/wordpress/android/ui/posts/PostDatePickerDialogFragment.kt @@ -24,10 +24,14 @@ class PostDatePickerDialogFragment : DialogFragment() { ) viewModel = when (publishSettingsFragmentType) { - PublishSettingsFragmentType.EDIT_POST -> ViewModelProvider(requireActivity(), viewModelFactory) - .get(EditPostPublishSettingsViewModel::class.java) - PublishSettingsFragmentType.PREPUBLISHING_NUDGES -> ViewModelProvider(requireActivity(), viewModelFactory) - .get(PrepublishingPublishSettingsViewModel::class.java) + PublishSettingsFragmentType.EDIT_POST -> ViewModelProvider( + requireActivity(), + viewModelFactory + )[EditPostPublishSettingsViewModel::class.java] + PublishSettingsFragmentType.PREPUBLISHING_NUDGES -> ViewModelProvider( + requireActivity(), + viewModelFactory + )[PrepublishingPublishSettingsViewModel::class.java] null -> error("PublishSettingsViewModel not initialized") } diff --git a/WordPress/src/main/java/org/wordpress/android/ui/posts/PostListFragment.kt b/WordPress/src/main/java/org/wordpress/android/ui/posts/PostListFragment.kt index 22e4986bac12..a8483cfaed16 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/posts/PostListFragment.kt +++ b/WordPress/src/main/java/org/wordpress/android/ui/posts/PostListFragment.kt @@ -105,8 +105,7 @@ class PostListFragment : ViewPagerFragment() { recyclerView?.id = R.id.posts_search_recycler_view_id } - mainViewModel = ViewModelProvider(nonNullActivity, viewModelFactory) - .get(PostListMainViewModel::class.java) + mainViewModel = ViewModelProvider(nonNullActivity, viewModelFactory)[PostListMainViewModel::class.java] mainViewModel.viewLayoutType.observe(viewLifecycleOwner, Observer { optionaLayoutType -> optionaLayoutType?.let { layoutType -> @@ -140,7 +139,7 @@ class PostListFragment : ViewPagerFragment() { val postListViewModelConnector = mainViewModel.getPostListViewModelConnector(postListType) - viewModel = ViewModelProvider(this, viewModelFactory).get(PostListViewModel::class.java) + viewModel = ViewModelProvider(this, viewModelFactory)[PostListViewModel::class.java] val displayWidth = DisplayUtils.getWindowPixelWidth(requireContext()) val contentSpacing = nonNullActivity.resources.getDimensionPixelSize(R.dimen.content_margin) diff --git a/WordPress/src/main/java/org/wordpress/android/ui/posts/PostNotificationScheduleTimeDialogFragment.kt b/WordPress/src/main/java/org/wordpress/android/ui/posts/PostNotificationScheduleTimeDialogFragment.kt index 9eb70b8d579a..1b408616310f 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/posts/PostNotificationScheduleTimeDialogFragment.kt +++ b/WordPress/src/main/java/org/wordpress/android/ui/posts/PostNotificationScheduleTimeDialogFragment.kt @@ -29,10 +29,14 @@ class PostNotificationScheduleTimeDialogFragment : DialogFragment() { ) viewModel = when (publishSettingsFragmentType) { - PublishSettingsFragmentType.EDIT_POST -> ViewModelProvider(requireActivity(), viewModelFactory) - .get(EditPostPublishSettingsViewModel::class.java) - PublishSettingsFragmentType.PREPUBLISHING_NUDGES -> ViewModelProvider(requireActivity(), viewModelFactory) - .get(PrepublishingPublishSettingsViewModel::class.java) + PublishSettingsFragmentType.EDIT_POST -> ViewModelProvider( + requireActivity(), + viewModelFactory + )[EditPostPublishSettingsViewModel::class.java] + PublishSettingsFragmentType.PREPUBLISHING_NUDGES -> ViewModelProvider( + requireActivity(), + viewModelFactory + )[PrepublishingPublishSettingsViewModel::class.java] null -> error("PublishSettingsViewModel not initialized") } diff --git a/WordPress/src/main/java/org/wordpress/android/ui/posts/PostTimePickerDialogFragment.kt b/WordPress/src/main/java/org/wordpress/android/ui/posts/PostTimePickerDialogFragment.kt index 16af9a1bfe97..f22fff7d9373 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/posts/PostTimePickerDialogFragment.kt +++ b/WordPress/src/main/java/org/wordpress/android/ui/posts/PostTimePickerDialogFragment.kt @@ -2,7 +2,6 @@ package org.wordpress.android.ui.posts import android.app.Dialog import android.app.TimePickerDialog -import android.app.TimePickerDialog.OnTimeSetListener import android.content.Context import android.os.Bundle import android.text.format.DateFormat @@ -27,25 +26,26 @@ class PostTimePickerDialogFragment : DialogFragment() { ) viewModel = when (publishSettingsFragmentType) { - PublishSettingsFragmentType.EDIT_POST -> ViewModelProvider(requireActivity(), viewModelFactory) - .get(EditPostPublishSettingsViewModel::class.java) - PublishSettingsFragmentType.PREPUBLISHING_NUDGES -> ViewModelProvider(requireActivity(), viewModelFactory) - .get(PrepublishingPublishSettingsViewModel::class.java) + PublishSettingsFragmentType.EDIT_POST -> ViewModelProvider( + requireActivity(), + viewModelFactory + )[EditPostPublishSettingsViewModel::class.java] + PublishSettingsFragmentType.PREPUBLISHING_NUDGES -> ViewModelProvider( + requireActivity(), + viewModelFactory + )[PrepublishingPublishSettingsViewModel::class.java] null -> error("PublishSettingsViewModel not initialized") } val is24HrFormat = DateFormat.is24HourFormat(activity) val context = ContextThemeWrapper(activity, style.PostSettingsCalendar) - val timePickerDialog = TimePickerDialog( + return TimePickerDialog( context, - OnTimeSetListener { _, selectedHour, selectedMinute -> - viewModel.onTimeSelected(selectedHour, selectedMinute) - }, + { _, selectedHour, selectedMinute -> viewModel.onTimeSelected(selectedHour, selectedMinute) }, viewModel.hour ?: 0, viewModel.minute ?: 0, is24HrFormat ) - return timePickerDialog } override fun onAttach(context: Context) { diff --git a/WordPress/src/main/java/org/wordpress/android/ui/posts/PrepublishingAddCategoryFragment.kt b/WordPress/src/main/java/org/wordpress/android/ui/posts/PrepublishingAddCategoryFragment.kt index d804e6f0f6e2..22ab45239d3d 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/posts/PrepublishingAddCategoryFragment.kt +++ b/WordPress/src/main/java/org/wordpress/android/ui/posts/PrepublishingAddCategoryFragment.kt @@ -138,10 +138,12 @@ class PrepublishingAddCategoryFragment : Fragment(R.layout.prepublishing_add_cat } private fun PrepublishingAddCategoryFragmentBinding.initViewModel() { - viewModel = ViewModelProvider(this@PrepublishingAddCategoryFragment, viewModelFactory) - .get(PrepublishingAddCategoryViewModel::class.java) - parentViewModel = ViewModelProvider(requireParentFragment(), viewModelFactory) - .get(PrepublishingViewModel::class.java) + viewModel = ViewModelProvider( + this@PrepublishingAddCategoryFragment, + viewModelFactory + )[PrepublishingAddCategoryViewModel::class.java] + parentViewModel = + ViewModelProvider(requireParentFragment(), viewModelFactory)[PrepublishingViewModel::class.java] startObserving() diff --git a/WordPress/src/main/java/org/wordpress/android/ui/posts/PrepublishingBottomSheetFragment.kt b/WordPress/src/main/java/org/wordpress/android/ui/posts/PrepublishingBottomSheetFragment.kt index af12ca7bfc27..78e4bda55382 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/posts/PrepublishingBottomSheetFragment.kt +++ b/WordPress/src/main/java/org/wordpress/android/ui/posts/PrepublishingBottomSheetFragment.kt @@ -135,8 +135,7 @@ class PrepublishingBottomSheetFragment : WPBottomSheetDialogFragment(), } private fun initViewModel(savedInstanceState: Bundle?) { - viewModel = ViewModelProvider(this, viewModelFactory) - .get(PrepublishingViewModel::class.java) + viewModel = ViewModelProvider(this, viewModelFactory)[PrepublishingViewModel::class.java] viewModel.navigationTarget.observeEvent(this, { navigationState -> navigateToScreen(navigationState) diff --git a/WordPress/src/main/java/org/wordpress/android/ui/posts/PrepublishingCategoriesFragment.kt b/WordPress/src/main/java/org/wordpress/android/ui/posts/PrepublishingCategoriesFragment.kt index 457935e512b5..5aadd5cd6e42 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/posts/PrepublishingCategoriesFragment.kt +++ b/WordPress/src/main/java/org/wordpress/android/ui/posts/PrepublishingCategoriesFragment.kt @@ -117,10 +117,12 @@ class PrepublishingCategoriesFragment : Fragment(R.layout.prepublishing_categori } private fun PrepublishingCategoriesFragmentBinding.initViewModel() { - viewModel = ViewModelProvider(this@PrepublishingCategoriesFragment, viewModelFactory) - .get(PrepublishingCategoriesViewModel::class.java) - parentViewModel = ViewModelProvider(requireParentFragment(), viewModelFactory) - .get(PrepublishingViewModel::class.java) + viewModel = ViewModelProvider( + this@PrepublishingCategoriesFragment, + viewModelFactory + )[PrepublishingCategoriesViewModel::class.java] + parentViewModel = + ViewModelProvider(requireParentFragment(), viewModelFactory)[PrepublishingViewModel::class.java] startObserving() val siteModel = requireNotNull(arguments?.getSerializableCompat(WordPress.SITE)) val addCategoryRequest = arguments?.getSerializableCompat(ADD_CATEGORY_REQUEST) diff --git a/WordPress/src/main/java/org/wordpress/android/ui/prefs/homepage/HomepageSettingsDialog.kt b/WordPress/src/main/java/org/wordpress/android/ui/prefs/homepage/HomepageSettingsDialog.kt index 109641838839..ab6ba5f61351 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/prefs/homepage/HomepageSettingsDialog.kt +++ b/WordPress/src/main/java/org/wordpress/android/ui/prefs/homepage/HomepageSettingsDialog.kt @@ -55,8 +55,8 @@ class HomepageSettingsDialog : DialogFragment() { } builder.setView(root) - viewModel = ViewModelProvider(this@HomepageSettingsDialog, viewModelFactory) - .get(HomepageSettingsViewModel::class.java) + viewModel = + ViewModelProvider(this@HomepageSettingsDialog, viewModelFactory)[HomepageSettingsViewModel::class.java] viewModel.uiState.observe(this@HomepageSettingsDialog) { uiState -> uiState?.let { loadingPages.visibility = if (uiState.isLoading) View.VISIBLE else View.GONE diff --git a/WordPress/src/main/java/org/wordpress/android/ui/reader/SubfilterBottomSheetFragment.kt b/WordPress/src/main/java/org/wordpress/android/ui/reader/SubfilterBottomSheetFragment.kt index 8f3c49226f1a..438701ca1492 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/reader/SubfilterBottomSheetFragment.kt +++ b/WordPress/src/main/java/org/wordpress/android/ui/reader/SubfilterBottomSheetFragment.kt @@ -71,8 +71,10 @@ class SubfilterBottomSheetFragment : BottomSheetDialogFragment() { requireArguments().getParcelableArrayListCompat(SUBFILTER_CATEGORIES_KEY) ) - viewModel = ViewModelProvider(parentFragment as ViewModelStoreOwner, viewModelFactory) - .get(subfilterVmKey, SubFilterViewModel::class.java) + viewModel = ViewModelProvider( + parentFragment as ViewModelStoreOwner, + viewModelFactory + )[subfilterVmKey, SubFilterViewModel::class.java] val pager = view.findViewById(R.id.view_pager) val tabLayout = view.findViewById(R.id.tab_layout) diff --git a/WordPress/src/main/java/org/wordpress/android/ui/reader/subfilter/SubfilterPageFragment.kt b/WordPress/src/main/java/org/wordpress/android/ui/reader/subfilter/SubfilterPageFragment.kt index 4754376d1a62..7fa7bbd13aa3 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/reader/subfilter/SubfilterPageFragment.kt +++ b/WordPress/src/main/java/org/wordpress/android/ui/reader/subfilter/SubfilterPageFragment.kt @@ -84,7 +84,7 @@ class SubfilterPageFragment : DaggerFragment() { val category = requireNotNull(arguments?.getSerializableCompat(CATEGORY_KEY)) val subfilterVmKey = requireArguments().getString(SUBFILTER_VIEW_MODEL_KEY)!! - viewModel = ViewModelProvider(this, viewModelFactory).get(SubfilterPageViewModel::class.java) + viewModel = ViewModelProvider(this, viewModelFactory)[SubfilterPageViewModel::class.java] viewModel.start(category) recyclerView = view.findViewById(R.id.content_recycler_view) diff --git a/WordPress/src/main/java/org/wordpress/android/ui/stories/StoryComposerActivity.kt b/WordPress/src/main/java/org/wordpress/android/ui/stories/StoryComposerActivity.kt index cc0ab302ab3f..e4105c4014e2 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/stories/StoryComposerActivity.kt +++ b/WordPress/src/main/java/org/wordpress/android/ui/stories/StoryComposerActivity.kt @@ -234,8 +234,7 @@ class StoryComposerActivity : ComposeLoopFrameActivity(), PostEditorAnalyticsSession.fromBundle(bundle, STATE_KEY_EDITOR_SESSION_DATA, analyticsTrackerWrapper) } - viewModel = ViewModelProvider(this, viewModelFactory) - .get(StoryComposerViewModel::class.java) + viewModel = ViewModelProvider(this, viewModelFactory)[StoryComposerViewModel::class.java] site?.let { val postInitialized = viewModel.start( From b6a43736591157a07f3f4a82d364295c99db849c Mon Sep 17 00:00:00 2001 From: Irfan Omur Date: Tue, 7 Mar 2023 22:34:53 +0300 Subject: [PATCH 028/856] Move lambda arguments out of parentheses --- .../ui/JetpackRemoteInstallFragment.kt | 4 +- .../engagement/EngagedPeopleListFragment.kt | 20 +++---- .../scan/details/ThreatDetailsFragment.kt | 52 +++++++++---------- .../android/ui/posts/PostListFragment.kt | 4 +- .../posts/PrepublishingBottomSheetFragment.kt | 16 +++--- .../reader/subfilter/SubfilterPageFragment.kt | 9 ++-- .../intro/StoriesIntroDialogFragment.kt | 13 +++-- 7 files changed, 56 insertions(+), 62 deletions(-) diff --git a/WordPress/src/main/java/org/wordpress/android/ui/JetpackRemoteInstallFragment.kt b/WordPress/src/main/java/org/wordpress/android/ui/JetpackRemoteInstallFragment.kt index 83998d3ec898..a37180f9759f 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/JetpackRemoteInstallFragment.kt +++ b/WordPress/src/main/java/org/wordpress/android/ui/JetpackRemoteInstallFragment.kt @@ -57,7 +57,7 @@ class JetpackRemoteInstallFragment : Fragment(R.layout.jetpack_remote_install_fr initLiveViewStateObserver() - viewModel.liveActionOnResult.observe(viewLifecycleOwner, Observer { result -> + viewModel.liveActionOnResult.observe(viewLifecycleOwner) { result -> if (result != null) { when (result.action) { MANUAL_INSTALL -> onManualInstallResultAction(activity, source, result) @@ -65,7 +65,7 @@ class JetpackRemoteInstallFragment : Fragment(R.layout.jetpack_remote_install_fr CONNECT -> onConnectResultAction(activity, source, result) } } - }) + } } } diff --git a/WordPress/src/main/java/org/wordpress/android/ui/engagement/EngagedPeopleListFragment.kt b/WordPress/src/main/java/org/wordpress/android/ui/engagement/EngagedPeopleListFragment.kt index 3b2d0af7fbf3..3c5937d693f3 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/engagement/EngagedPeopleListFragment.kt +++ b/WordPress/src/main/java/org/wordpress/android/ui/engagement/EngagedPeopleListFragment.kt @@ -104,7 +104,7 @@ class EngagedPeopleListFragment : Fragment() { recycler.layoutManager = layoutManager - userProfileViewModel.onBottomSheetAction.observeEvent(viewLifecycleOwner, { state -> + userProfileViewModel.onBottomSheetAction.observeEvent(viewLifecycleOwner) { state -> var bottomSheet = childFragmentManager.findFragmentByTag(USER_PROFILE_BOTTOM_SHEET_TAG) as? UserProfileBottomSheetFragment @@ -119,31 +119,31 @@ class EngagedPeopleListFragment : Fragment() { bottomSheet?.apply { this.dismiss() } } } - }) + } - viewModel.uiState.observe(viewLifecycleOwner, { state -> + viewModel.uiState.observe(viewLifecycleOwner) { state -> if (!isAdded) return@observe updateUiState(state) - }) + } - viewModel.onNavigationEvent.observeEvent(viewLifecycleOwner, { event -> + viewModel.onNavigationEvent.observeEvent(viewLifecycleOwner) { event -> if (!isAdded) return@observeEvent manageNavigation(event) - }) + } - viewModel.onSnackbarMessage.observeEvent(viewLifecycleOwner, { messageHolder -> + viewModel.onSnackbarMessage.observeEvent(viewLifecycleOwner) { messageHolder -> if (!isAdded || !lifecycle.currentState.isAtLeast(State.RESUMED)) return@observeEvent showSnackbar(messageHolder) - }) + } - viewModel.onServiceRequestEvent.observeEvent(viewLifecycleOwner, { serviceRequest -> + viewModel.onServiceRequestEvent.observeEvent(viewLifecycleOwner) { serviceRequest -> if (!isAdded) return@observeEvent manageServiceRequest(serviceRequest) - }) + } viewModel.start(listScenario) } diff --git a/WordPress/src/main/java/org/wordpress/android/ui/jetpack/scan/details/ThreatDetailsFragment.kt b/WordPress/src/main/java/org/wordpress/android/ui/jetpack/scan/details/ThreatDetailsFragment.kt index 3f276480ed22..85fdefdedeb3 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/jetpack/scan/details/ThreatDetailsFragment.kt +++ b/WordPress/src/main/java/org/wordpress/android/ui/jetpack/scan/details/ThreatDetailsFragment.kt @@ -69,37 +69,33 @@ class ThreatDetailsFragment : Fragment(R.layout.threat_details_fragment) { private fun ThreatDetailsFragmentBinding.setupObservers() { viewModel.uiState.observe( - viewLifecycleOwner, - { uiState -> - if (uiState is Content) { - refreshContentScreen(uiState) - } + viewLifecycleOwner + ) { uiState -> + if (uiState is Content) { + refreshContentScreen(uiState) } - ) - - viewModel.snackbarEvents.observeEvent(viewLifecycleOwner, { it.showSnackbar() }) - - viewModel.navigationEvents.observeEvent( - viewLifecycleOwner, - { events -> - when (events) { - is OpenThreatActionDialog -> showThreatActionDialog(events) - - is ShowUpdatedScanStateWithMessage -> { - val site = requireNotNull(activity?.intent?.extras).getSerializableCompat(WordPress.SITE) - ActivityLauncher.viewScanRequestScanState(requireActivity(), site, events.messageRes) - } - is ShowUpdatedFixState -> { - val site = requireNotNull(activity?.intent?.extras).getSerializableCompat(WordPress.SITE) - ActivityLauncher.viewScanRequestFixState(requireActivity(), site, events.threatId) - } - is ShowGetFreeEstimate -> { - ActivityLauncher.openUrlExternal(context, events.url()) - } - is ShowJetpackSettings -> ActivityLauncher.openUrlExternal(context, events.url) + } + + viewModel.snackbarEvents.observeEvent(viewLifecycleOwner) { it.showSnackbar() } + + viewModel.navigationEvents.observeEvent(viewLifecycleOwner) { events -> + when (events) { + is OpenThreatActionDialog -> showThreatActionDialog(events) + + is ShowUpdatedScanStateWithMessage -> { + val site = requireNotNull(activity?.intent?.extras).getSerializableCompat(WordPress.SITE) + ActivityLauncher.viewScanRequestScanState(requireActivity(), site, events.messageRes) + } + is ShowUpdatedFixState -> { + val site = requireNotNull(activity?.intent?.extras).getSerializableCompat(WordPress.SITE) + ActivityLauncher.viewScanRequestFixState(requireActivity(), site, events.threatId) } + is ShowGetFreeEstimate -> { + ActivityLauncher.openUrlExternal(context, events.url()) + } + is ShowJetpackSettings -> ActivityLauncher.openUrlExternal(context, events.url) } - ) + } } private fun ThreatDetailsFragmentBinding.refreshContentScreen(content: Content) { diff --git a/WordPress/src/main/java/org/wordpress/android/ui/posts/PostListFragment.kt b/WordPress/src/main/java/org/wordpress/android/ui/posts/PostListFragment.kt index a8483cfaed16..619c6f24ba92 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/posts/PostListFragment.kt +++ b/WordPress/src/main/java/org/wordpress/android/ui/posts/PostListFragment.kt @@ -127,13 +127,13 @@ class PostListFragment : ViewPagerFragment() { } }) - mainViewModel.authorSelectionUpdated.observe(viewLifecycleOwner, Observer { + mainViewModel.authorSelectionUpdated.observe(viewLifecycleOwner) { if (it != null) { if (viewModel.updateAuthorFilterIfNotSearch(it)) { recyclerView?.scrollToPosition(0) } } - }) + } actionableEmptyView?.updateLayoutForSearch(postListType == SEARCH, 0) diff --git a/WordPress/src/main/java/org/wordpress/android/ui/posts/PrepublishingBottomSheetFragment.kt b/WordPress/src/main/java/org/wordpress/android/ui/posts/PrepublishingBottomSheetFragment.kt index 78e4bda55382..bd1094d0b0ee 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/posts/PrepublishingBottomSheetFragment.kt +++ b/WordPress/src/main/java/org/wordpress/android/ui/posts/PrepublishingBottomSheetFragment.kt @@ -137,21 +137,21 @@ class PrepublishingBottomSheetFragment : WPBottomSheetDialogFragment(), private fun initViewModel(savedInstanceState: Bundle?) { viewModel = ViewModelProvider(this, viewModelFactory)[PrepublishingViewModel::class.java] - viewModel.navigationTarget.observeEvent(this, { navigationState -> + viewModel.navigationTarget.observeEvent(this) { navigationState -> navigateToScreen(navigationState) - }) + } - viewModel.dismissBottomSheet.observeEvent(this, { + viewModel.dismissBottomSheet.observeEvent(this) { dismiss() - }) + } - viewModel.triggerOnSubmitButtonClickedListener.observeEvent(this, { publishPost -> + viewModel.triggerOnSubmitButtonClickedListener.observeEvent(this) { publishPost -> prepublishingBottomSheetListener?.onSubmitButtonClicked(publishPost) - }) + } - viewModel.dismissKeyboard.observeEvent(this, { + viewModel.dismissKeyboard.observeEvent(this) { ActivityUtils.hideKeyboardForced(view) - }) + } val prepublishingScreenState = savedInstanceState?.getParcelableCompat( KEY_SCREEN_STATE diff --git a/WordPress/src/main/java/org/wordpress/android/ui/reader/subfilter/SubfilterPageFragment.kt b/WordPress/src/main/java/org/wordpress/android/ui/reader/subfilter/SubfilterPageFragment.kt index 7fa7bbd13aa3..17eadd6a39bd 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/reader/subfilter/SubfilterPageFragment.kt +++ b/WordPress/src/main/java/org/wordpress/android/ui/reader/subfilter/SubfilterPageFragment.kt @@ -16,7 +16,6 @@ import androidx.annotation.StringRes import androidx.fragment.app.Fragment import androidx.fragment.app.FragmentManager import androidx.fragment.app.FragmentPagerAdapter -import androidx.lifecycle.Observer import androidx.lifecycle.ViewModelProvider import androidx.lifecycle.ViewModelStoreOwner import androidx.recyclerview.widget.LinearLayoutManager @@ -100,7 +99,7 @@ class SubfilterPageFragment : DaggerFragment() { viewModelFactory ).get(subfilterVmKey, SubFilterViewModel::class.java) - subFilterViewModel.subFilters.observe(viewLifecycleOwner, Observer { + subFilterViewModel.subFilters.observe(viewLifecycleOwner) { (recyclerView.adapter as? SubfilterListAdapter)?.let { adapter -> var items = it?.filter { it.type == category.type } ?: listOf() @@ -117,9 +116,9 @@ class SubfilterPageFragment : DaggerFragment() { adapter.update(items) subFilterViewModel.onSubfilterPageUpdated(category, items.size) } - }) + } - viewModel.emptyState.observe(viewLifecycleOwner, Observer { uiState -> + viewModel.emptyState.observe(viewLifecycleOwner) { uiState -> if (isAdded) { when (uiState) { HiddenEmptyUiState -> emptyStateContainer.visibility = View.GONE @@ -133,7 +132,7 @@ class SubfilterPageFragment : DaggerFragment() { } } } - }) + } } fun setNestedScrollBehavior(enable: Boolean) { diff --git a/WordPress/src/main/java/org/wordpress/android/ui/stories/intro/StoriesIntroDialogFragment.kt b/WordPress/src/main/java/org/wordpress/android/ui/stories/intro/StoriesIntroDialogFragment.kt index 48434305d4aa..9067133bfc45 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/stories/intro/StoriesIntroDialogFragment.kt +++ b/WordPress/src/main/java/org/wordpress/android/ui/stories/intro/StoriesIntroDialogFragment.kt @@ -7,7 +7,6 @@ import android.view.LayoutInflater import android.view.View import android.view.ViewGroup import androidx.fragment.app.DialogFragment -import androidx.lifecycle.Observer import androidx.lifecycle.ViewModelProvider import org.wordpress.android.R import org.wordpress.android.WordPress @@ -68,20 +67,20 @@ class StoriesIntroDialogFragment : DialogFragment() { storyImageFirst.setOnClickListener { viewModel.onStoryPreviewTapped1() } storyImageSecond.setOnClickListener { viewModel.onStoryPreviewTapped2() } } - viewModel.onCreateButtonClicked.observe(this, Observer { + viewModel.onCreateButtonClicked.observe(this) { activity?.let { mediaPickerLauncher.showStoriesPhotoPickerForResultAndTrack(it, site) } dismiss() - }) + } - viewModel.onDialogClosed.observe(this, Observer { + viewModel.onDialogClosed.observe(this) { dismiss() - }) + } - viewModel.onStoryOpenRequested.observe(this, Observer { storyUrl -> + viewModel.onStoryOpenRequested.observe(this) { storyUrl -> ActivityLauncher.openUrlExternal(context, storyUrl) - }) + } viewModel.start() } From 8d8edaca07cb06154dfb73414a792d3b9e7f8a61 Mon Sep 17 00:00:00 2001 From: Irfan Omur Date: Wed, 8 Mar 2023 20:59:22 +0300 Subject: [PATCH 029/856] Add types to CompatExtensions functions --- .../onboarding/BloggingPromptsOnboardingDialogFragment.kt | 2 +- .../android/ui/comments/unified/UnifiedCommentListFragment.kt | 2 +- .../ui/mysite/jetpackbadge/JetpackPoweredBottomSheetFragment.kt | 2 +- .../org/wordpress/android/ui/stories/StoriesTrackerHelper.kt | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/WordPress/src/main/java/org/wordpress/android/ui/bloggingprompts/onboarding/BloggingPromptsOnboardingDialogFragment.kt b/WordPress/src/main/java/org/wordpress/android/ui/bloggingprompts/onboarding/BloggingPromptsOnboardingDialogFragment.kt index 74f0b2edc958..5e2ac3f8c626 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/bloggingprompts/onboarding/BloggingPromptsOnboardingDialogFragment.kt +++ b/WordPress/src/main/java/org/wordpress/android/ui/bloggingprompts/onboarding/BloggingPromptsOnboardingDialogFragment.kt @@ -97,7 +97,7 @@ class BloggingPromptsOnboardingDialogFragment : FeatureIntroductionDialogFragmen @Suppress("UseCheckOrError") override fun onAttach(context: Context) { super.onAttach(context) - arguments?.let { dialogType = requireNotNull(it.getSerializableCompat(KEY_DIALOG_TYPE)) } + arguments?.let { dialogType = requireNotNull(it.getSerializableCompat(KEY_DIALOG_TYPE)) } (requireActivity().applicationContext as WordPress).component().inject(this) if (dialogType == ONBOARDING && context !is BloggingPromptsReminderSchedulerListener) { throw IllegalStateException( diff --git a/WordPress/src/main/java/org/wordpress/android/ui/comments/unified/UnifiedCommentListFragment.kt b/WordPress/src/main/java/org/wordpress/android/ui/comments/unified/UnifiedCommentListFragment.kt index 678a92899610..3c91ccf6ea39 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/comments/unified/UnifiedCommentListFragment.kt +++ b/WordPress/src/main/java/org/wordpress/android/ui/comments/unified/UnifiedCommentListFragment.kt @@ -77,7 +77,7 @@ class UnifiedCommentListFragment : Fragment(R.layout.unified_comment_list_fragme viewModelFactory )[UnifiedCommentActivityViewModel::class.java] arguments?.let { - commentListFilter = requireNotNull(it.getSerializableCompat(KEY_COMMENT_LIST_FILTER)) + commentListFilter = requireNotNull(it.getSerializableCompat(KEY_COMMENT_LIST_FILTER)) } } diff --git a/WordPress/src/main/java/org/wordpress/android/ui/mysite/jetpackbadge/JetpackPoweredBottomSheetFragment.kt b/WordPress/src/main/java/org/wordpress/android/ui/mysite/jetpackbadge/JetpackPoweredBottomSheetFragment.kt index 038bc8c61d1d..40e52ccb47b2 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/mysite/jetpackbadge/JetpackPoweredBottomSheetFragment.kt +++ b/WordPress/src/main/java/org/wordpress/android/ui/mysite/jetpackbadge/JetpackPoweredBottomSheetFragment.kt @@ -84,7 +84,7 @@ class JetpackPoweredBottomSheetFragment : BottomSheetDialogFragment() { private fun setupFullScreenViews(view: View) { with(JetpackPoweredExpandedBottomSheetBinding.bind(view)) { - when (arguments?.getSerializableCompat(KEY_SITE_SCREEN) ?: MY_SITE) { + when (arguments?.getSerializableCompat(KEY_SITE_SCREEN) ?: MY_SITE) { MY_SITE -> { val animRes = if (rtlLayout(view)) R.raw.jp_stats_rtl else R.raw.jp_stats_left illustrationView.setAnimation(animRes) diff --git a/WordPress/src/main/java/org/wordpress/android/ui/stories/StoriesTrackerHelper.kt b/WordPress/src/main/java/org/wordpress/android/ui/stories/StoriesTrackerHelper.kt index d85a287721d2..76771fed8ad1 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/stories/StoriesTrackerHelper.kt +++ b/WordPress/src/main/java/org/wordpress/android/ui/stories/StoriesTrackerHelper.kt @@ -34,7 +34,7 @@ class StoriesTrackerHelper @Inject constructor() { val properties = getCommonProperties(event) var siteModel: SiteModel? = null event.metadata?.let { - siteModel = it.getSerializableCompat(WordPress.SITE) + siteModel = it.getSerializableCompat(WordPress.SITE) } siteModel?.let { From ae617dcfd0e759138815b37452f32dd0f24bccc4 Mon Sep 17 00:00:00 2001 From: Irfan Omur Date: Wed, 8 Mar 2023 21:04:33 +0300 Subject: [PATCH 030/856] Reformat lines of commentIdentifier --- .../ui/comments/unified/UnifiedCommentsEditActivity.kt | 5 +++-- .../ui/comments/unified/UnifiedCommentsEditFragment.kt | 4 +--- 2 files changed, 4 insertions(+), 5 deletions(-) diff --git a/WordPress/src/main/java/org/wordpress/android/ui/comments/unified/UnifiedCommentsEditActivity.kt b/WordPress/src/main/java/org/wordpress/android/ui/comments/unified/UnifiedCommentsEditActivity.kt index 0b1dc7c9c0c1..d8a4e70dab6f 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/comments/unified/UnifiedCommentsEditActivity.kt +++ b/WordPress/src/main/java/org/wordpress/android/ui/comments/unified/UnifiedCommentsEditActivity.kt @@ -20,8 +20,9 @@ class UnifiedCommentsEditActivity : LocaleAwareActivity() { } val site = requireNotNull(intent.getSerializableExtraCompat(WordPress.SITE)) - val commentIdentifier = - requireNotNull(intent.getParcelableExtraCompat(KEY_COMMENT_IDENTIFIER)) + val commentIdentifier = requireNotNull( + intent.getParcelableExtraCompat(KEY_COMMENT_IDENTIFIER) + ) val fm = supportFragmentManager var editCommentFragment = fm.findFragmentByTag( diff --git a/WordPress/src/main/java/org/wordpress/android/ui/comments/unified/UnifiedCommentsEditFragment.kt b/WordPress/src/main/java/org/wordpress/android/ui/comments/unified/UnifiedCommentsEditFragment.kt index ef7b77c16434..90d5addf8199 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/comments/unified/UnifiedCommentsEditFragment.kt +++ b/WordPress/src/main/java/org/wordpress/android/ui/comments/unified/UnifiedCommentsEditFragment.kt @@ -65,9 +65,7 @@ class UnifiedCommentsEditFragment : Fragment(R.layout.unified_comments_edit_frag val site = requireNotNull(arguments?.getSerializableCompat(WordPress.SITE)) val commentIdentifier = requireNotNull( - requireArguments().getParcelableCompat( - KEY_COMMENT_IDENTIFIER - ) + requireArguments().getParcelableCompat(KEY_COMMENT_IDENTIFIER) ) UnifiedCommentsEditFragmentBinding.bind(view).apply { From 0f4d5671e2d9ff4ab5f0b9abb681f73ce86d7a42 Mon Sep 17 00:00:00 2001 From: Irfan Omur Date: Wed, 8 Mar 2023 21:25:32 +0300 Subject: [PATCH 031/856] Reformat lines for ViewModelProviders --- .../android/ui/domains/DomainRegistrationDetailsFragment.kt | 6 ++++-- .../android/ui/domains/DomainSuggestionsFragment.kt | 6 ++++-- .../java/org/wordpress/android/ui/pages/PageListFragment.kt | 6 ++++-- .../android/ui/posts/PrepublishingAddCategoryFragment.kt | 6 ++++-- .../android/ui/posts/PrepublishingCategoriesFragment.kt | 6 ++++-- .../android/ui/prefs/homepage/HomepageSettingsDialog.kt | 6 ++++-- 6 files changed, 24 insertions(+), 12 deletions(-) diff --git a/WordPress/src/main/java/org/wordpress/android/ui/domains/DomainRegistrationDetailsFragment.kt b/WordPress/src/main/java/org/wordpress/android/ui/domains/DomainRegistrationDetailsFragment.kt index f82d45b7ade7..60d8e7d04710 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/domains/DomainRegistrationDetailsFragment.kt +++ b/WordPress/src/main/java/org/wordpress/android/ui/domains/DomainRegistrationDetailsFragment.kt @@ -90,8 +90,10 @@ class DomainRegistrationDetailsFragment : Fragment() { override fun onViewCreated(view: View, savedInstanceState: Bundle?) { super.onViewCreated(view, savedInstanceState) - mainViewModel = - ViewModelProvider(requireActivity(), viewModelFactory)[DomainRegistrationMainViewModel::class.java] + mainViewModel = ViewModelProvider( + requireActivity(), + viewModelFactory + )[DomainRegistrationMainViewModel::class.java] viewModel = ViewModelProvider(this, viewModelFactory)[DomainRegistrationDetailsViewModel::class.java] with(DomainRegistrationDetailsFragmentBinding.bind(view)) { binding = this diff --git a/WordPress/src/main/java/org/wordpress/android/ui/domains/DomainSuggestionsFragment.kt b/WordPress/src/main/java/org/wordpress/android/ui/domains/DomainSuggestionsFragment.kt index cd154d27602e..c96d63dedaf4 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/domains/DomainSuggestionsFragment.kt +++ b/WordPress/src/main/java/org/wordpress/android/ui/domains/DomainSuggestionsFragment.kt @@ -39,8 +39,10 @@ class DomainSuggestionsFragment : Fragment(R.layout.domain_suggestions_fragment) super.onViewCreated(view, savedInstanceState) (requireActivity().application as WordPress).component().inject(this) - mainViewModel = - ViewModelProvider(requireActivity(), viewModelFactory)[DomainRegistrationMainViewModel::class.java] + mainViewModel = ViewModelProvider( + requireActivity(), + viewModelFactory + )[DomainRegistrationMainViewModel::class.java] viewModel = ViewModelProvider(this, viewModelFactory)[DomainSuggestionsViewModel::class.java] diff --git a/WordPress/src/main/java/org/wordpress/android/ui/pages/PageListFragment.kt b/WordPress/src/main/java/org/wordpress/android/ui/pages/PageListFragment.kt index 75aba3fbaa73..3f1c488ce4b7 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/pages/PageListFragment.kt +++ b/WordPress/src/main/java/org/wordpress/android/ui/pages/PageListFragment.kt @@ -93,8 +93,10 @@ class PageListFragment : ViewPagerFragment(R.layout.pages_list_fragment) { val pagesViewModel = ViewModelProvider(activity, viewModelFactory)[PagesViewModel::class.java] val listType = requireNotNull(arguments?.getSerializableCompat(typeKey)) - viewModel = - ViewModelProvider(this@PageListFragment, viewModelFactory)[listType.name, PageListViewModel::class.java] + viewModel = ViewModelProvider( + this@PageListFragment, + viewModelFactory + )[listType.name, PageListViewModel::class.java] viewModel.start(listType, pagesViewModel) diff --git a/WordPress/src/main/java/org/wordpress/android/ui/posts/PrepublishingAddCategoryFragment.kt b/WordPress/src/main/java/org/wordpress/android/ui/posts/PrepublishingAddCategoryFragment.kt index 22ab45239d3d..abcacf66bc18 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/posts/PrepublishingAddCategoryFragment.kt +++ b/WordPress/src/main/java/org/wordpress/android/ui/posts/PrepublishingAddCategoryFragment.kt @@ -142,8 +142,10 @@ class PrepublishingAddCategoryFragment : Fragment(R.layout.prepublishing_add_cat this@PrepublishingAddCategoryFragment, viewModelFactory )[PrepublishingAddCategoryViewModel::class.java] - parentViewModel = - ViewModelProvider(requireParentFragment(), viewModelFactory)[PrepublishingViewModel::class.java] + parentViewModel = ViewModelProvider( + requireParentFragment(), + viewModelFactory + )[PrepublishingViewModel::class.java] startObserving() diff --git a/WordPress/src/main/java/org/wordpress/android/ui/posts/PrepublishingCategoriesFragment.kt b/WordPress/src/main/java/org/wordpress/android/ui/posts/PrepublishingCategoriesFragment.kt index 5aadd5cd6e42..00d787313280 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/posts/PrepublishingCategoriesFragment.kt +++ b/WordPress/src/main/java/org/wordpress/android/ui/posts/PrepublishingCategoriesFragment.kt @@ -121,8 +121,10 @@ class PrepublishingCategoriesFragment : Fragment(R.layout.prepublishing_categori this@PrepublishingCategoriesFragment, viewModelFactory )[PrepublishingCategoriesViewModel::class.java] - parentViewModel = - ViewModelProvider(requireParentFragment(), viewModelFactory)[PrepublishingViewModel::class.java] + parentViewModel = ViewModelProvider( + requireParentFragment(), + viewModelFactory + )[PrepublishingViewModel::class.java] startObserving() val siteModel = requireNotNull(arguments?.getSerializableCompat(WordPress.SITE)) val addCategoryRequest = arguments?.getSerializableCompat(ADD_CATEGORY_REQUEST) diff --git a/WordPress/src/main/java/org/wordpress/android/ui/prefs/homepage/HomepageSettingsDialog.kt b/WordPress/src/main/java/org/wordpress/android/ui/prefs/homepage/HomepageSettingsDialog.kt index ab6ba5f61351..58525591ee05 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/prefs/homepage/HomepageSettingsDialog.kt +++ b/WordPress/src/main/java/org/wordpress/android/ui/prefs/homepage/HomepageSettingsDialog.kt @@ -55,8 +55,10 @@ class HomepageSettingsDialog : DialogFragment() { } builder.setView(root) - viewModel = - ViewModelProvider(this@HomepageSettingsDialog, viewModelFactory)[HomepageSettingsViewModel::class.java] + viewModel = ViewModelProvider( + this@HomepageSettingsDialog, + viewModelFactory + )[HomepageSettingsViewModel::class.java] viewModel.uiState.observe(this@HomepageSettingsDialog) { uiState -> uiState?.let { loadingPages.visibility = if (uiState.isLoading) View.VISIBLE else View.GONE From 3b9109d349455efd166cbd70ad0fd3dffa3f0cac Mon Sep 17 00:00:00 2001 From: Irfan Omur Date: Wed, 8 Mar 2023 22:09:05 +0300 Subject: [PATCH 032/856] Add null check for tracking source key --- .../org/wordpress/android/ui/JetpackRemoteInstallActivity.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/WordPress/src/main/java/org/wordpress/android/ui/JetpackRemoteInstallActivity.kt b/WordPress/src/main/java/org/wordpress/android/ui/JetpackRemoteInstallActivity.kt index 47bf1cd4f1ce..f7780a329726 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/JetpackRemoteInstallActivity.kt +++ b/WordPress/src/main/java/org/wordpress/android/ui/JetpackRemoteInstallActivity.kt @@ -22,7 +22,7 @@ class JetpackRemoteInstallActivity : LocaleAwareActivity() { onBackPressedDispatcher.addCallback(this) { trackWithSource( INSTALL_JETPACK_CANCELLED, - intent.getSerializableExtraCompat(TRACKING_SOURCE_KEY) + requireNotNull(intent.getSerializableExtraCompat(TRACKING_SOURCE_KEY)) ) onBackPressedDispatcher.onBackPressedCompat(this) } From d16d34d395b88d39a1ba90b7ebc7762afd0efca3 Mon Sep 17 00:00:00 2001 From: Irfan Omur Date: Wed, 8 Mar 2023 22:16:32 +0300 Subject: [PATCH 033/856] Fix a comment in CompatExtensions --- .../org/wordpress/android/util/extensions/CompatExtensions.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/WordPress/src/main/java/org/wordpress/android/util/extensions/CompatExtensions.kt b/WordPress/src/main/java/org/wordpress/android/util/extensions/CompatExtensions.kt index 9f695e3a5201..7759f6f8f08b 100644 --- a/WordPress/src/main/java/org/wordpress/android/util/extensions/CompatExtensions.kt +++ b/WordPress/src/main/java/org/wordpress/android/util/extensions/CompatExtensions.kt @@ -57,7 +57,7 @@ inline fun Bundle.getParcelableCompat(key: String): T? } /** - * TODO: Remove this when stable androidx.core 1.10 is released. Use IntentCompat instead. + * TODO: Remove this when stable androidx.core 1.10 is released. Use BundleCompat instead. */ @Suppress("ForbiddenComment") inline fun Bundle.getParcelableArrayListCompat(key: String): ArrayList? = From ff3699ab5306708736b260638d74049ba69373a4 Mon Sep 17 00:00:00 2001 From: Irfan Omur Date: Wed, 8 Mar 2023 14:49:09 +0300 Subject: [PATCH 034/856] Update androidx.core version to 1.9.0 --- build.gradle | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/build.gradle b/build.gradle index 043a2984f76d..12d996bb1d45 100644 --- a/build.gradle +++ b/build.gradle @@ -41,7 +41,7 @@ ext { androidxCardviewVersion = '1.0.0' androidxConstraintlayoutVersion = '1.1.3' androidxConstraintlayoutComposeVersion = '1.0.1' - androidxCoreVersion = '1.8.0' + androidxCoreVersion = '1.9.0' androidxActivityVersion = '1.5.1' androidxFragmentVersion = '1.5.5' androidxGridlayoutVersion = '1.0.0' From 86dd01a566d5b392c8d46a3587c5fde1831ee1de Mon Sep 17 00:00:00 2001 From: Irfan Omur Date: Wed, 8 Mar 2023 15:04:32 +0300 Subject: [PATCH 035/856] Add android.permission.POST_NOTIFICATIONS --- WordPress/src/main/AndroidManifest.xml | 1 + 1 file changed, 1 insertion(+) diff --git a/WordPress/src/main/AndroidManifest.xml b/WordPress/src/main/AndroidManifest.xml index a714e365f593..6c46bd3d6488 100644 --- a/WordPress/src/main/AndroidManifest.xml +++ b/WordPress/src/main/AndroidManifest.xml @@ -19,6 +19,7 @@ + From d33a1999fc17e2ea833b0a4e6e6b65f7e69fbb20 Mon Sep 17 00:00:00 2001 From: Irfan Omur Date: Wed, 8 Mar 2023 14:50:01 +0300 Subject: [PATCH 036/856] Use ParcelCompat for Android 13 changes --- .../android/ui/mediapicker/MediaItem.kt | 21 +++++++++++++++++-- .../sections/granular/SelectedDateProvider.kt | 3 ++- 2 files changed, 21 insertions(+), 3 deletions(-) diff --git a/WordPress/src/main/java/org/wordpress/android/ui/mediapicker/MediaItem.kt b/WordPress/src/main/java/org/wordpress/android/ui/mediapicker/MediaItem.kt index 2987ced93581..f399f66be3f8 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/mediapicker/MediaItem.kt +++ b/WordPress/src/main/java/org/wordpress/android/ui/mediapicker/MediaItem.kt @@ -4,6 +4,7 @@ import android.net.Uri import android.os.Parcel import android.os.Parcelable import android.os.Parcelable.Creator +import androidx.core.os.ParcelCompat import org.wordpress.android.ui.mediapicker.MediaItem.IdentifierType.GIF_MEDIA_IDENTIFIER import org.wordpress.android.ui.mediapicker.MediaItem.IdentifierType.LOCAL_ID import org.wordpress.android.ui.mediapicker.MediaItem.IdentifierType.LOCAL_URI @@ -82,7 +83,15 @@ data class MediaItem( return when (type) { LOCAL_URI -> { LocalUri( - UriWrapper(requireNotNull(parcel.readParcelable(Uri::class.java.classLoader))), + UriWrapper( + requireNotNull( + ParcelCompat.readParcelable( + parcel, + Uri::class.java.classLoader, + Uri::class.java + ) + ) + ), parcel.readInt() != 0 ) } @@ -97,7 +106,15 @@ data class MediaItem( } GIF_MEDIA_IDENTIFIER -> { GifMediaIdentifier( - UriWrapper(requireNotNull(parcel.readParcelable(Uri::class.java.classLoader))), + UriWrapper( + requireNotNull( + ParcelCompat.readParcelable( + parcel, + Uri::class.java.classLoader, + Uri::class.java + ) + ) + ), parcel.readString() ) } diff --git a/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/lists/sections/granular/SelectedDateProvider.kt b/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/lists/sections/granular/SelectedDateProvider.kt index f77b236a5ce8..7c6b116b1164 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/lists/sections/granular/SelectedDateProvider.kt +++ b/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/lists/sections/granular/SelectedDateProvider.kt @@ -4,6 +4,7 @@ import android.annotation.SuppressLint import android.os.Bundle import android.os.Parcel import android.os.Parcelable +import androidx.core.os.ParcelCompat import androidx.lifecycle.LiveData import androidx.lifecycle.MutableLiveData import kotlinx.parcelize.Parceler @@ -223,7 +224,7 @@ class SelectedDateProvider null } val availableTimeStamps = mutableListOf() - parcel.readList(availableTimeStamps, null) + ParcelCompat.readList(parcel, availableTimeStamps, null, Any::class.java) val availableDates = availableTimeStamps.map { Date(it as Long) } val loading = parcel.readValue(null) as Boolean val error = parcel.readValue(null) as Boolean From 62375b25b5aa531d01075bca43101c913fa708ee Mon Sep 17 00:00:00 2001 From: Irfan Omur Date: Thu, 9 Mar 2023 14:30:53 +0300 Subject: [PATCH 037/856] Optimize type references on CompatExtensions functions --- .../ui/activitylog/list/ActivityLogListFragment.kt | 6 +++--- .../android/ui/jetpack/scan/ScanFragment.kt | 14 ++++++++------ .../ui/jetpack/scan/history/ScanHistoryFragment.kt | 14 ++++++++------ .../scan/history/ScanHistoryListFragment.kt | 14 ++++++++------ .../wordpress/android/ui/pages/PagesFragment.kt | 6 +++--- .../categories/list/CategoriesListFragment.kt | 14 ++++++++------ .../ui/stats/refresh/StatsViewAllFragment.kt | 6 +++--- 7 files changed, 41 insertions(+), 33 deletions(-) diff --git a/WordPress/src/main/java/org/wordpress/android/ui/activitylog/list/ActivityLogListFragment.kt b/WordPress/src/main/java/org/wordpress/android/ui/activitylog/list/ActivityLogListFragment.kt index 6e9c7e848abe..c2a1e68566f3 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/activitylog/list/ActivityLogListFragment.kt +++ b/WordPress/src/main/java/org/wordpress/android/ui/activitylog/list/ActivityLogListFragment.kt @@ -89,12 +89,12 @@ class ActivityLogListFragment : Fragment(R.layout.activity_log_list_fragment) { } } - val site: SiteModel = requireNotNull( + val site = requireNotNull( if (savedInstanceState == null) { val nonNullIntent = checkNotNull(nonNullActivity.intent) - nonNullIntent.getSerializableExtraCompat(WordPress.SITE) + nonNullIntent.getSerializableExtraCompat(WordPress.SITE) } else { - savedInstanceState.getSerializableCompat(WordPress.SITE) + savedInstanceState.getSerializableCompat(WordPress.SITE) } ) val rewindableOnly = nonNullActivity.intent.getBooleanExtra(ACTIVITY_LOG_REWINDABLE_ONLY_KEY, false) diff --git a/WordPress/src/main/java/org/wordpress/android/ui/jetpack/scan/ScanFragment.kt b/WordPress/src/main/java/org/wordpress/android/ui/jetpack/scan/ScanFragment.kt index 3aee277c80f5..305967806c9c 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/jetpack/scan/ScanFragment.kt +++ b/WordPress/src/main/java/org/wordpress/android/ui/jetpack/scan/ScanFragment.kt @@ -177,12 +177,14 @@ class ScanFragment : Fragment(R.layout.scan_fragment) { } private fun getSite(savedInstanceState: Bundle?): SiteModel { - val site: SiteModel? = if (savedInstanceState == null) { - requireActivity().intent.getSerializableExtraCompat(WordPress.SITE) - } else { - savedInstanceState.getSerializableCompat(WordPress.SITE) - } - return requireNotNull(site) + val site = requireNotNull( + if (savedInstanceState == null) { + requireActivity().intent.getSerializableExtraCompat(WordPress.SITE) + } else { + savedInstanceState.getSerializableCompat(WordPress.SITE) + } + ) + return site } override fun onSaveInstanceState(outState: Bundle) { diff --git a/WordPress/src/main/java/org/wordpress/android/ui/jetpack/scan/history/ScanHistoryFragment.kt b/WordPress/src/main/java/org/wordpress/android/ui/jetpack/scan/history/ScanHistoryFragment.kt index 3316fa00e20c..67ca756018e3 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/jetpack/scan/history/ScanHistoryFragment.kt +++ b/WordPress/src/main/java/org/wordpress/android/ui/jetpack/scan/history/ScanHistoryFragment.kt @@ -123,12 +123,14 @@ class ScanHistoryFragment : Fragment(R.layout.scan_history_fragment), MenuProvid } private fun getSite(savedInstanceState: Bundle?): SiteModel { - val site: SiteModel? = if (savedInstanceState == null) { - requireActivity().intent.getSerializableExtraCompat(WordPress.SITE) - } else { - savedInstanceState.getSerializableCompat(WordPress.SITE) - } - return requireNotNull(site) + val site = requireNotNull( + if (savedInstanceState == null) { + requireActivity().intent.getSerializableExtraCompat(WordPress.SITE) + } else { + savedInstanceState.getSerializableCompat(WordPress.SITE) + } + ) + return site } override fun onSaveInstanceState(outState: Bundle) { diff --git a/WordPress/src/main/java/org/wordpress/android/ui/jetpack/scan/history/ScanHistoryListFragment.kt b/WordPress/src/main/java/org/wordpress/android/ui/jetpack/scan/history/ScanHistoryListFragment.kt index 7687cdb59fc0..4017c1043a73 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/jetpack/scan/history/ScanHistoryListFragment.kt +++ b/WordPress/src/main/java/org/wordpress/android/ui/jetpack/scan/history/ScanHistoryListFragment.kt @@ -81,12 +81,14 @@ class ScanHistoryListFragment : ViewPagerFragment(R.layout.scan_history_list_fra } private fun getSite(savedInstanceState: Bundle?): SiteModel { - val site: SiteModel? = if (savedInstanceState == null) { - requireActivity().intent.getSerializableExtraCompat(WordPress.SITE) - } else { - savedInstanceState.getSerializableCompat(WordPress.SITE) - } - return requireNotNull(site) + val site = requireNotNull( + if (savedInstanceState == null) { + requireActivity().intent.getSerializableExtraCompat(WordPress.SITE) + } else { + savedInstanceState.getSerializableCompat(WordPress.SITE) + } + ) + return site } private fun getTabType() = requireNotNull(arguments?.getParcelableCompat(ARG_TAB_TYPE)) diff --git a/WordPress/src/main/java/org/wordpress/android/ui/pages/PagesFragment.kt b/WordPress/src/main/java/org/wordpress/android/ui/pages/PagesFragment.kt index 4fb4501ee04c..adfcd63c6e6b 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/pages/PagesFragment.kt +++ b/WordPress/src/main/java/org/wordpress/android/ui/pages/PagesFragment.kt @@ -318,13 +318,13 @@ class PagesFragment : Fragment(R.layout.pages_fragment), ScrollableViewInitializ setupActions(activity) setupMlpObservers(activity) - val site: SiteModel = requireNotNull( + val site = requireNotNull( if (savedInstanceState == null) { val nonNullIntent = checkNotNull(activity.intent) - nonNullIntent.getSerializableExtraCompat(WordPress.SITE) + nonNullIntent.getSerializableExtraCompat(WordPress.SITE) } else { restorePreviousSearch = true - savedInstanceState.getSerializableCompat(WordPress.SITE) + savedInstanceState.getSerializableCompat(WordPress.SITE) } ) diff --git a/WordPress/src/main/java/org/wordpress/android/ui/prefs/categories/list/CategoriesListFragment.kt b/WordPress/src/main/java/org/wordpress/android/ui/prefs/categories/list/CategoriesListFragment.kt index fe1b430bf1e4..3f1b5666f233 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/prefs/categories/list/CategoriesListFragment.kt +++ b/WordPress/src/main/java/org/wordpress/android/ui/prefs/categories/list/CategoriesListFragment.kt @@ -70,12 +70,14 @@ class CategoriesListFragment : Fragment(R.layout.site_settings_categories_list_f } private fun getSite(savedInstanceState: Bundle?): SiteModel { - val site: SiteModel? = if (savedInstanceState == null) { - requireActivity().intent.getSerializableExtraCompat(WordPress.SITE) - } else { - savedInstanceState.getSerializableCompat(WordPress.SITE) - } - return requireNotNull(site) + val site = requireNotNull( + if (savedInstanceState == null) { + requireActivity().intent.getSerializableExtraCompat(WordPress.SITE) + } else { + savedInstanceState.getSerializableCompat(WordPress.SITE) + } + ) + return site } private fun SiteSettingsCategoriesListFragmentBinding.setupObservers() { diff --git a/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/StatsViewAllFragment.kt b/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/StatsViewAllFragment.kt index 2761693c1d14..75113bc59a81 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/StatsViewAllFragment.kt +++ b/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/StatsViewAllFragment.kt @@ -157,11 +157,11 @@ class StatsViewAllFragment : DaggerFragment(R.layout.stats_view_all_fragment) { savedInstanceState: Bundle? ) { val nonNullIntent = checkNotNull(activity.intent) - val type: StatsViewType = requireNotNull( + val type = requireNotNull( if (savedInstanceState == null) { - nonNullIntent.getSerializableExtraCompat(ARGS_VIEW_TYPE) + nonNullIntent.getSerializableExtraCompat(ARGS_VIEW_TYPE) } else { - savedInstanceState.getSerializableCompat(ARGS_VIEW_TYPE) + savedInstanceState.getSerializableCompat(ARGS_VIEW_TYPE) } ) From de3e50530a458f1e0534196cab37390eb22164d9 Mon Sep 17 00:00:00 2001 From: Irfan Omur Date: Thu, 9 Mar 2023 14:33:39 +0300 Subject: [PATCH 038/856] Reformat lines for ViewModelProviders --- .../org/wordpress/android/ui/JetpackRemoteInstallFragment.kt | 3 ++- .../wordpress/android/ui/people/PeopleInviteDialogFragment.kt | 3 ++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/WordPress/src/main/java/org/wordpress/android/ui/JetpackRemoteInstallFragment.kt b/WordPress/src/main/java/org/wordpress/android/ui/JetpackRemoteInstallFragment.kt index a37180f9759f..d3e4f9a713ee 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/JetpackRemoteInstallFragment.kt +++ b/WordPress/src/main/java/org/wordpress/android/ui/JetpackRemoteInstallFragment.kt @@ -51,7 +51,8 @@ class JetpackRemoteInstallFragment : Fragment(R.layout.jetpack_remote_install_fr val retrievedState = savedInstanceState?.getSerializableCompat(VIEW_STATE) viewModel = ViewModelProvider( - this@JetpackRemoteInstallFragment, viewModelFactory + this@JetpackRemoteInstallFragment, + viewModelFactory )[JetpackRemoteInstallViewModel::class.java] viewModel.start(site, retrievedState) diff --git a/WordPress/src/main/java/org/wordpress/android/ui/people/PeopleInviteDialogFragment.kt b/WordPress/src/main/java/org/wordpress/android/ui/people/PeopleInviteDialogFragment.kt index 85455ab0c6c0..1c55fbda758f 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/people/PeopleInviteDialogFragment.kt +++ b/WordPress/src/main/java/org/wordpress/android/ui/people/PeopleInviteDialogFragment.kt @@ -43,7 +43,8 @@ class PeopleInviteDialogFragment : DialogFragment() { @Suppress("DEPRECATION") override fun onCreateDialog(savedInstanceState: Bundle?): Dialog { viewModel = ViewModelProvider( - targetFragment as ViewModelStoreOwner, viewModelFactory + targetFragment as ViewModelStoreOwner, + viewModelFactory )[PeopleInviteViewModel::class.java] val dialogMode = arguments?.getSerializableCompat(ARG_DIALOG_MODE) From 4c32fd4d100884124bfe6df69ef915c3a4ff0311 Mon Sep 17 00:00:00 2001 From: Irfan Omur Date: Thu, 9 Mar 2023 15:43:37 +0300 Subject: [PATCH 039/856] Add comments to functions in CompatExtensions --- .../wordpress/android/util/extensions/CompatExtensions.kt | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/WordPress/src/main/java/org/wordpress/android/util/extensions/CompatExtensions.kt b/WordPress/src/main/java/org/wordpress/android/util/extensions/CompatExtensions.kt index 7759f6f8f08b..5eed2f0eb0a1 100644 --- a/WordPress/src/main/java/org/wordpress/android/util/extensions/CompatExtensions.kt +++ b/WordPress/src/main/java/org/wordpress/android/util/extensions/CompatExtensions.kt @@ -36,6 +36,9 @@ inline fun Intent.getParcelableExtraCompat(key: String) getParcelableExtra(key) as T? } +/** + * This is an Android 13 compatibility function that is not included in IntentCompat. + */ inline fun Intent.getSerializableExtraCompat(key: String): T? = if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) { getSerializableExtra(key, T::class.java) @@ -68,6 +71,9 @@ inline fun Bundle.getParcelableArrayListCompat(key: Str getParcelableArrayList(key) } +/** + * This is an Android 13 compatibility function that is not included in BundleCompat. + */ inline fun Bundle.getSerializableCompat(key: String): T? = if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) { getSerializable(key, T::class.java) From d98d281795001c9894f76e31893657d25c077a1b Mon Sep 17 00:00:00 2001 From: Irfan Omur Date: Thu, 9 Mar 2023 16:03:06 +0300 Subject: [PATCH 040/856] Revert "Update androidx.core version to 1.9.0" This reverts commit ff3699ab5306708736b260638d74049ba69373a4. --- build.gradle | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/build.gradle b/build.gradle index 12d996bb1d45..043a2984f76d 100644 --- a/build.gradle +++ b/build.gradle @@ -41,7 +41,7 @@ ext { androidxCardviewVersion = '1.0.0' androidxConstraintlayoutVersion = '1.1.3' androidxConstraintlayoutComposeVersion = '1.0.1' - androidxCoreVersion = '1.9.0' + androidxCoreVersion = '1.8.0' androidxActivityVersion = '1.5.1' androidxFragmentVersion = '1.5.5' androidxGridlayoutVersion = '1.0.0' From 28fff0b94b0ae3594f705101e2d8b1e923b05106 Mon Sep 17 00:00:00 2001 From: Irfan Omur Date: Thu, 9 Mar 2023 16:03:10 +0300 Subject: [PATCH 041/856] Revert "Add android.permission.POST_NOTIFICATIONS" This reverts commit 86dd01a566d5b392c8d46a3587c5fde1831ee1de. --- WordPress/src/main/AndroidManifest.xml | 1 - 1 file changed, 1 deletion(-) diff --git a/WordPress/src/main/AndroidManifest.xml b/WordPress/src/main/AndroidManifest.xml index 6c46bd3d6488..a714e365f593 100644 --- a/WordPress/src/main/AndroidManifest.xml +++ b/WordPress/src/main/AndroidManifest.xml @@ -19,7 +19,6 @@ - From 4047e5a0dea172d0bfff7fbf15ded897ffe2c7bf Mon Sep 17 00:00:00 2001 From: Irfan Omur Date: Thu, 9 Mar 2023 16:03:11 +0300 Subject: [PATCH 042/856] Revert "Use ParcelCompat for Android 13 changes" This reverts commit d33a1999fc17e2ea833b0a4e6e6b65f7e69fbb20. --- .../android/ui/mediapicker/MediaItem.kt | 21 ++----------------- .../sections/granular/SelectedDateProvider.kt | 3 +-- 2 files changed, 3 insertions(+), 21 deletions(-) diff --git a/WordPress/src/main/java/org/wordpress/android/ui/mediapicker/MediaItem.kt b/WordPress/src/main/java/org/wordpress/android/ui/mediapicker/MediaItem.kt index f399f66be3f8..2987ced93581 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/mediapicker/MediaItem.kt +++ b/WordPress/src/main/java/org/wordpress/android/ui/mediapicker/MediaItem.kt @@ -4,7 +4,6 @@ import android.net.Uri import android.os.Parcel import android.os.Parcelable import android.os.Parcelable.Creator -import androidx.core.os.ParcelCompat import org.wordpress.android.ui.mediapicker.MediaItem.IdentifierType.GIF_MEDIA_IDENTIFIER import org.wordpress.android.ui.mediapicker.MediaItem.IdentifierType.LOCAL_ID import org.wordpress.android.ui.mediapicker.MediaItem.IdentifierType.LOCAL_URI @@ -83,15 +82,7 @@ data class MediaItem( return when (type) { LOCAL_URI -> { LocalUri( - UriWrapper( - requireNotNull( - ParcelCompat.readParcelable( - parcel, - Uri::class.java.classLoader, - Uri::class.java - ) - ) - ), + UriWrapper(requireNotNull(parcel.readParcelable(Uri::class.java.classLoader))), parcel.readInt() != 0 ) } @@ -106,15 +97,7 @@ data class MediaItem( } GIF_MEDIA_IDENTIFIER -> { GifMediaIdentifier( - UriWrapper( - requireNotNull( - ParcelCompat.readParcelable( - parcel, - Uri::class.java.classLoader, - Uri::class.java - ) - ) - ), + UriWrapper(requireNotNull(parcel.readParcelable(Uri::class.java.classLoader))), parcel.readString() ) } diff --git a/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/lists/sections/granular/SelectedDateProvider.kt b/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/lists/sections/granular/SelectedDateProvider.kt index 7c6b116b1164..f77b236a5ce8 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/lists/sections/granular/SelectedDateProvider.kt +++ b/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/lists/sections/granular/SelectedDateProvider.kt @@ -4,7 +4,6 @@ import android.annotation.SuppressLint import android.os.Bundle import android.os.Parcel import android.os.Parcelable -import androidx.core.os.ParcelCompat import androidx.lifecycle.LiveData import androidx.lifecycle.MutableLiveData import kotlinx.parcelize.Parceler @@ -224,7 +223,7 @@ class SelectedDateProvider null } val availableTimeStamps = mutableListOf() - ParcelCompat.readList(parcel, availableTimeStamps, null, Any::class.java) + parcel.readList(availableTimeStamps, null) val availableDates = availableTimeStamps.map { Date(it as Long) } val loading = parcel.readValue(null) as Boolean val error = parcel.readValue(null) as Boolean From 64f591a0cf639284963ae2a10d82d7c651431a77 Mon Sep 17 00:00:00 2001 From: Irfan Omur Date: Thu, 9 Mar 2023 16:21:04 +0300 Subject: [PATCH 043/856] Add Android 13 compatibility functions for Parcel --- .../util/extensions/CompatExtensions.kt | 21 +++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/WordPress/src/main/java/org/wordpress/android/util/extensions/CompatExtensions.kt b/WordPress/src/main/java/org/wordpress/android/util/extensions/CompatExtensions.kt index 622eb8f7234f..1e6484148040 100644 --- a/WordPress/src/main/java/org/wordpress/android/util/extensions/CompatExtensions.kt +++ b/WordPress/src/main/java/org/wordpress/android/util/extensions/CompatExtensions.kt @@ -1,5 +1,8 @@ package org.wordpress.android.util.extensions +import android.os.Build +import android.os.Parcel +import android.os.Parcelable import androidx.activity.OnBackPressedCallback import androidx.activity.OnBackPressedDispatcher @@ -18,3 +21,21 @@ fun OnBackPressedDispatcher.onBackPressedCompat(onBackPressedCallback: OnBackPre onBackPressed() onBackPressedCallback.isEnabled = true } + +inline fun Parcel.readParcelableCompat(loader: ClassLoader?): T? { + return if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) { + readParcelable(loader, T::class.java) + } else { + @Suppress("DEPRECATION") + readParcelable(loader) + } +} + +inline fun Parcel.readListCompat(outVal: MutableList, loader: ClassLoader?) { + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) { + readList(outVal, loader, T::class.java) + } else { + @Suppress("DEPRECATION") + readList(outVal, loader) + } +} From 21ad20991220b53dece9c59a72c1ae5b7dfb32ea Mon Sep 17 00:00:00 2001 From: Irfan Omur Date: Thu, 9 Mar 2023 16:22:39 +0300 Subject: [PATCH 044/856] Update deprecated Parcel functions --- .../java/org/wordpress/android/ui/mediapicker/MediaItem.kt | 5 +++-- .../refresh/lists/sections/granular/SelectedDateProvider.kt | 3 ++- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/WordPress/src/main/java/org/wordpress/android/ui/mediapicker/MediaItem.kt b/WordPress/src/main/java/org/wordpress/android/ui/mediapicker/MediaItem.kt index 2987ced93581..878b9abb1b7a 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/mediapicker/MediaItem.kt +++ b/WordPress/src/main/java/org/wordpress/android/ui/mediapicker/MediaItem.kt @@ -10,6 +10,7 @@ import org.wordpress.android.ui.mediapicker.MediaItem.IdentifierType.LOCAL_URI import org.wordpress.android.ui.mediapicker.MediaItem.IdentifierType.REMOTE_ID import org.wordpress.android.ui.mediapicker.MediaItem.IdentifierType.STOCK_MEDIA_IDENTIFIER import org.wordpress.android.util.UriWrapper +import org.wordpress.android.util.extensions.readParcelableCompat data class MediaItem( val identifier: Identifier, @@ -82,7 +83,7 @@ data class MediaItem( return when (type) { LOCAL_URI -> { LocalUri( - UriWrapper(requireNotNull(parcel.readParcelable(Uri::class.java.classLoader))), + UriWrapper(requireNotNull(parcel.readParcelableCompat(Uri::class.java.classLoader))), parcel.readInt() != 0 ) } @@ -97,7 +98,7 @@ data class MediaItem( } GIF_MEDIA_IDENTIFIER -> { GifMediaIdentifier( - UriWrapper(requireNotNull(parcel.readParcelable(Uri::class.java.classLoader))), + UriWrapper(requireNotNull(parcel.readParcelableCompat(Uri::class.java.classLoader))), parcel.readString() ) } diff --git a/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/lists/sections/granular/SelectedDateProvider.kt b/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/lists/sections/granular/SelectedDateProvider.kt index f77b236a5ce8..2aadc2da7c01 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/lists/sections/granular/SelectedDateProvider.kt +++ b/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/lists/sections/granular/SelectedDateProvider.kt @@ -20,6 +20,7 @@ import org.wordpress.android.ui.stats.refresh.utils.StatsDateFormatter import org.wordpress.android.ui.stats.refresh.utils.toStatsSection import org.wordpress.android.ui.stats.refresh.utils.trackWithSection import org.wordpress.android.util.analytics.AnalyticsTrackerWrapper +import org.wordpress.android.util.extensions.readListCompat import org.wordpress.android.util.filter import java.util.Date import javax.inject.Inject @@ -223,7 +224,7 @@ class SelectedDateProvider null } val availableTimeStamps = mutableListOf() - parcel.readList(availableTimeStamps, null) + parcel.readListCompat(availableTimeStamps, null) val availableDates = availableTimeStamps.map { Date(it as Long) } val loading = parcel.readValue(null) as Boolean val error = parcel.readValue(null) as Boolean From b194387be742fd9b26e0920b597676eec67f1134 Mon Sep 17 00:00:00 2001 From: Irfan Omur Date: Thu, 9 Mar 2023 16:37:58 +0300 Subject: [PATCH 045/856] Add comments to functions in CompatExtensions --- .../wordpress/android/util/extensions/CompatExtensions.kt | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/WordPress/src/main/java/org/wordpress/android/util/extensions/CompatExtensions.kt b/WordPress/src/main/java/org/wordpress/android/util/extensions/CompatExtensions.kt index 1e6484148040..e1f6bdd2b764 100644 --- a/WordPress/src/main/java/org/wordpress/android/util/extensions/CompatExtensions.kt +++ b/WordPress/src/main/java/org/wordpress/android/util/extensions/CompatExtensions.kt @@ -22,6 +22,10 @@ fun OnBackPressedDispatcher.onBackPressedCompat(onBackPressedCallback: OnBackPre onBackPressedCallback.isEnabled = true } +/** + * TODO: Remove this when upgrading to androidx.core 1.9.0. Use ParcelCompat instead. + */ +@Suppress("ForbiddenComment") inline fun Parcel.readParcelableCompat(loader: ClassLoader?): T? { return if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) { readParcelable(loader, T::class.java) @@ -31,6 +35,10 @@ inline fun Parcel.readParcelableCompat(loader: ClassLoa } } +/** + * TODO: Remove this when upgrading to androidx.core 1.9.0. Use ParcelCompat instead. + */ +@Suppress("ForbiddenComment") inline fun Parcel.readListCompat(outVal: MutableList, loader: ClassLoader?) { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) { readList(outVal, loader, T::class.java) From d3b5463bdd9afeb56fa8c1a90184e73a1255c890 Mon Sep 17 00:00:00 2001 From: Petros Paraskevopoulos Date: Thu, 9 Mar 2023 16:42:58 +0200 Subject: [PATCH 046/856] Deps: Update google auto service to 1.0.1 Release Notes: https://github.com/google/auto/releases/tag/ auto-service-1.0.1 --- build.gradle | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/build.gradle b/build.gradle index 66fd4a5acdec..98326d41ac6e 100644 --- a/build.gradle +++ b/build.gradle @@ -62,7 +62,7 @@ ext { glassfishJavaxAnnotationVersion = '10.0-b28' glideVersion = '4.10.0' glideVolleyVersion = '4.6.1@aar' - googleAutoServiceVersion = '1.0' + googleAutoServiceVersion = '1.0.1' googleExoPlayerVersion = '2.13.3' googleGsonVersion = '2.6.2' googleMaterialVersion = '1.2.1' From 1fbf19a7ffa340e0229f927176ddc80af03c2df0 Mon Sep 17 00:00:00 2001 From: Irfan Omur Date: Thu, 9 Mar 2023 20:04:43 +0300 Subject: [PATCH 047/856] Add Android 13 compatibility functions for PackageManager --- .../util/extensions/CompatExtensions.kt | 20 +++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/WordPress/src/main/java/org/wordpress/android/util/extensions/CompatExtensions.kt b/WordPress/src/main/java/org/wordpress/android/util/extensions/CompatExtensions.kt index 6e0237f1e51a..d9095bfcdbd0 100644 --- a/WordPress/src/main/java/org/wordpress/android/util/extensions/CompatExtensions.kt +++ b/WordPress/src/main/java/org/wordpress/android/util/extensions/CompatExtensions.kt @@ -1,6 +1,10 @@ package org.wordpress.android.util.extensions +import android.content.ComponentName import android.content.Intent +import android.content.pm.ActivityInfo +import android.content.pm.PackageInfo +import android.content.pm.PackageManager import android.os.Build import android.os.Bundle import android.os.Parcel @@ -108,3 +112,19 @@ inline fun Parcel.readListCompat(outVal: MutableList, loader: Cl readList(outVal, loader) } } + +fun PackageManager.getActivityInfoCompat(componentName: ComponentName, flags: Int): ActivityInfo = + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) { + getActivityInfo(componentName, PackageManager.ComponentInfoFlags.of(flags.toLong())) + } else { + @Suppress("DEPRECATION") + getActivityInfo(componentName, flags) + } + +fun PackageManager.getPackageInfoCompat(packageName: String, flags: Int): PackageInfo? = + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) { + getPackageInfo(packageName, PackageManager.PackageInfoFlags.of(flags.toLong())) + } else { + @Suppress("DEPRECATION") + getPackageInfo(packageName, flags) + } From 6c1911c7723f4a2f2d769419c6076355b831bdea Mon Sep 17 00:00:00 2001 From: Irfan Omur Date: Thu, 9 Mar 2023 20:05:23 +0300 Subject: [PATCH 048/856] Update deprecated PackageManager functions These functions were deprecated on Android 13. --- .../org/wordpress/android/util/PackageManagerWrapper.kt | 3 ++- .../android/util/publicdata/PackageManagerWrapper.kt | 3 ++- .../wordpress/android/util/signature/SignatureUtils.kt | 8 ++++++-- 3 files changed, 10 insertions(+), 4 deletions(-) diff --git a/WordPress/src/main/java/org/wordpress/android/util/PackageManagerWrapper.kt b/WordPress/src/main/java/org/wordpress/android/util/PackageManagerWrapper.kt index b2aceb345ad5..8b5c8f2932c6 100644 --- a/WordPress/src/main/java/org/wordpress/android/util/PackageManagerWrapper.kt +++ b/WordPress/src/main/java/org/wordpress/android/util/PackageManagerWrapper.kt @@ -4,6 +4,7 @@ import android.content.ComponentName import android.content.Intent import android.content.pm.PackageManager import org.wordpress.android.util.AppLog.T +import org.wordpress.android.util.extensions.getActivityInfoCompat import org.wordpress.android.viewmodel.ContextProvider import javax.inject.Inject import javax.inject.Singleton @@ -38,7 +39,7 @@ class PackageManagerWrapper @Inject constructor( intent.component?.let { try { val context = contextProvider.getContext() - val activityInfo = context.packageManager.getActivityInfo(it, PackageManager.GET_META_DATA) + val activityInfo = context.packageManager.getActivityInfoCompat(it, PackageManager.GET_META_DATA) return activityInfo.labelRes } catch (ex: PackageManager.NameNotFoundException) { AppLog.e(T.UTILS, "Unable to extract label res from activity info") diff --git a/WordPress/src/main/java/org/wordpress/android/util/publicdata/PackageManagerWrapper.kt b/WordPress/src/main/java/org/wordpress/android/util/publicdata/PackageManagerWrapper.kt index a996ccbca90a..abaa20bce5d7 100644 --- a/WordPress/src/main/java/org/wordpress/android/util/publicdata/PackageManagerWrapper.kt +++ b/WordPress/src/main/java/org/wordpress/android/util/publicdata/PackageManagerWrapper.kt @@ -1,10 +1,11 @@ package org.wordpress.android.util.publicdata import android.content.pm.PackageInfo +import org.wordpress.android.util.extensions.getPackageInfoCompat import org.wordpress.android.viewmodel.ContextProvider import javax.inject.Inject class PackageManagerWrapper @Inject constructor(private val contextProvider: ContextProvider) { fun getPackageInfo(packageName: String, flags: Int = 0): PackageInfo? = - contextProvider.getContext().packageManager.getPackageInfo(packageName, flags) + contextProvider.getContext().packageManager.getPackageInfoCompat(packageName, flags) } diff --git a/WordPress/src/main/java/org/wordpress/android/util/signature/SignatureUtils.kt b/WordPress/src/main/java/org/wordpress/android/util/signature/SignatureUtils.kt index f693c397b394..2095bf4aedc8 100644 --- a/WordPress/src/main/java/org/wordpress/android/util/signature/SignatureUtils.kt +++ b/WordPress/src/main/java/org/wordpress/android/util/signature/SignatureUtils.kt @@ -4,6 +4,7 @@ import android.annotation.TargetApi import android.content.pm.PackageManager import android.os.Build.VERSION import android.os.Build.VERSION_CODES +import org.wordpress.android.util.extensions.getPackageInfoCompat import org.wordpress.android.viewmodel.ContextProvider import java.security.MessageDigest import javax.inject.Inject @@ -28,8 +29,11 @@ class SignatureUtils @Inject constructor( trustedPackageId: String, trustedSignatureHash: String ): Boolean = try { - val signingInfo = contextProvider.getContext().packageManager.getPackageInfo( - trustedPackageId, PackageManager.GET_SIGNING_CERTIFICATES + val signingInfo = requireNotNull( + contextProvider.getContext().packageManager.getPackageInfoCompat( + trustedPackageId, + PackageManager.GET_SIGNING_CERTIFICATES + ) ).signingInfo if (signingInfo.hasMultipleSigners()) { throw SignatureNotFoundException() From 1040767b1b59f404bd5dd4dbcf06be8c61fdc907 Mon Sep 17 00:00:00 2001 From: Annmarie Ziegler Date: Fri, 10 Mar 2023 11:21:50 -0500 Subject: [PATCH 049/856] Fix view not scrolling for large font size/displays --- .../ui/blazeoverlay/BlazeOverlayFragment.kt | 57 ++++++++++++------- 1 file changed, 36 insertions(+), 21 deletions(-) diff --git a/WordPress/src/main/java/org/wordpress/android/ui/blaze/ui/blazeoverlay/BlazeOverlayFragment.kt b/WordPress/src/main/java/org/wordpress/android/ui/blaze/ui/blazeoverlay/BlazeOverlayFragment.kt index 7bd94cffad0b..8063b6e76fe2 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/blaze/ui/blazeoverlay/BlazeOverlayFragment.kt +++ b/WordPress/src/main/java/org/wordpress/android/ui/blaze/ui/blazeoverlay/BlazeOverlayFragment.kt @@ -13,13 +13,13 @@ import androidx.compose.foundation.layout.Box import androidx.compose.foundation.layout.Column import androidx.compose.foundation.layout.Row import androidx.compose.foundation.layout.Spacer +import androidx.compose.foundation.layout.fillMaxSize import androidx.compose.foundation.layout.fillMaxWidth import androidx.compose.foundation.layout.height import androidx.compose.foundation.layout.padding import androidx.compose.foundation.layout.size import androidx.compose.foundation.layout.wrapContentHeight import androidx.compose.foundation.lazy.LazyColumn -import androidx.compose.foundation.lazy.items import androidx.compose.foundation.shape.RoundedCornerShape import androidx.compose.material.Icon import androidx.compose.material.IconButton @@ -107,7 +107,8 @@ class BlazeOverlayFragment : Fragment() { Scaffold( topBar = { OverlayTopBar(blazeUIModel) }, ) { - BlazeOverlayContent(blazeUIModel, isDarkTheme) + ScrollableBox(blazeUIModel, isDarkTheme) + // BlazeOverlayContent(blazeUIModel, isDarkTheme) } } @@ -205,6 +206,18 @@ class BlazeOverlayFragment : Fragment() { } } + @Composable + fun ScrollableBox(uiModel: BlazeUIModel?, + isDarkTheme: Boolean) { + Box(Modifier.fillMaxSize()) { + LazyColumn(Modifier.fillMaxSize()) { + items(1) { + BlazeOverlayContent(uiModel, isDarkTheme) + } + } + } + } + private fun getPrimaryButtonColor(isInDarkTheme: Boolean): Color { return if (isInDarkTheme) darkModePrimaryButtonColor else AppColor.Black @@ -244,8 +257,23 @@ class BlazeOverlayFragment : Fragment() { end.linkTo(postContainer.end, 15.dp) }) Title( - title = uiModel.title, modifier = Modifier.constrainAs(title) { - top.linkTo(postContainer.top, 15.dp) + title = uiModel.title, modifier = Modifier + .constrainAs(title) { + top.linkTo(postContainer.top, 15.dp) + start.linkTo(postContainer.start, 20.dp) + uiModel.featuredImageUrl?.run { + end.linkTo(featuredImage.start, margin = 15.dp) + } ?: run { + end.linkTo(postContainer.end, margin = 20.dp) + } + width = Dimension.fillToConstraints + } + .wrapContentHeight() + ) + val url = createRef() + Url(url = uiModel.url, modifier = Modifier + .constrainAs(url) { + top.linkTo(title.bottom) start.linkTo(postContainer.start, 20.dp) uiModel.featuredImageUrl?.run { end.linkTo(featuredImage.start, margin = 15.dp) @@ -253,20 +281,9 @@ class BlazeOverlayFragment : Fragment() { end.linkTo(postContainer.end, margin = 20.dp) } width = Dimension.fillToConstraints - }.wrapContentHeight() - ) - val url = createRef() - Url(url = uiModel.url, modifier = Modifier.constrainAs(url) { - top.linkTo(title.bottom) - start.linkTo(postContainer.start, 20.dp) - uiModel.featuredImageUrl?.run { - end.linkTo(featuredImage.start, margin = 15.dp) - } ?: run { - end.linkTo(postContainer.end, margin = 20.dp) + height = Dimension.wrapContent } - width = Dimension.fillToConstraints - height = Dimension.wrapContent - }.padding(bottom = 15.dp)) + .padding(bottom = 15.dp)) } } @@ -320,16 +337,14 @@ class BlazeOverlayFragment : Fragment() { @Composable fun Subtitles(list: List, modifier: Modifier = Modifier) { - LazyColumn( + Column( verticalArrangement = Arrangement.spacedBy(16.dp), modifier = modifier.padding( top = Margin.ExtraLarge.value, bottom = Margin.ExtraLarge.value ) ) { - items(list) { - BulletedText(it) - } + list.forEach { BulletedText(it) } } } From 5d6dc760afc10cf3b8f9f7e4af9f3e6f9fc4d1f5 Mon Sep 17 00:00:00 2001 From: Annmarie Ziegler Date: Fri, 10 Mar 2023 11:26:37 -0500 Subject: [PATCH 050/856] Refactor: remove commented out code --- .../android/ui/blaze/ui/blazeoverlay/BlazeOverlayFragment.kt | 1 - 1 file changed, 1 deletion(-) diff --git a/WordPress/src/main/java/org/wordpress/android/ui/blaze/ui/blazeoverlay/BlazeOverlayFragment.kt b/WordPress/src/main/java/org/wordpress/android/ui/blaze/ui/blazeoverlay/BlazeOverlayFragment.kt index 8063b6e76fe2..7fd6d9f112d9 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/blaze/ui/blazeoverlay/BlazeOverlayFragment.kt +++ b/WordPress/src/main/java/org/wordpress/android/ui/blaze/ui/blazeoverlay/BlazeOverlayFragment.kt @@ -108,7 +108,6 @@ class BlazeOverlayFragment : Fragment() { topBar = { OverlayTopBar(blazeUIModel) }, ) { ScrollableBox(blazeUIModel, isDarkTheme) - // BlazeOverlayContent(blazeUIModel, isDarkTheme) } } From f2da1606237ce75a494de7ea4e7c972ebe1794a4 Mon Sep 17 00:00:00 2001 From: Annmarie Ziegler Date: Fri, 10 Mar 2023 14:21:37 -0500 Subject: [PATCH 051/856] Refactor: remove box and apply modifiers directly to column --- .../ui/blazeoverlay/BlazeOverlayFragment.kt | 28 +++++-------------- 1 file changed, 7 insertions(+), 21 deletions(-) diff --git a/WordPress/src/main/java/org/wordpress/android/ui/blaze/ui/blazeoverlay/BlazeOverlayFragment.kt b/WordPress/src/main/java/org/wordpress/android/ui/blaze/ui/blazeoverlay/BlazeOverlayFragment.kt index 7fd6d9f112d9..f1cf0f951d29 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/blaze/ui/blazeoverlay/BlazeOverlayFragment.kt +++ b/WordPress/src/main/java/org/wordpress/android/ui/blaze/ui/blazeoverlay/BlazeOverlayFragment.kt @@ -19,8 +19,9 @@ import androidx.compose.foundation.layout.height import androidx.compose.foundation.layout.padding import androidx.compose.foundation.layout.size import androidx.compose.foundation.layout.wrapContentHeight -import androidx.compose.foundation.lazy.LazyColumn +import androidx.compose.foundation.rememberScrollState import androidx.compose.foundation.shape.RoundedCornerShape +import androidx.compose.foundation.verticalScroll import androidx.compose.material.Icon import androidx.compose.material.IconButton import androidx.compose.material.MaterialTheme @@ -106,9 +107,7 @@ class BlazeOverlayFragment : Fragment() { } Scaffold( topBar = { OverlayTopBar(blazeUIModel) }, - ) { - ScrollableBox(blazeUIModel, isDarkTheme) - } + ) { BlazeOverlayContent(blazeUIModel, isDarkTheme) } } @Composable @@ -146,11 +145,10 @@ class BlazeOverlayFragment : Fragment() { ) { Column( horizontalAlignment = Alignment.CenterHorizontally, - modifier = Modifier.padding( - top = Margin.ExtraLarge.value, - start = Margin.ExtraLarge.value, - end = Margin.ExtraLarge.value - ) + modifier = Modifier + .fillMaxSize() + .verticalScroll(rememberScrollState()) + .padding(Margin.ExtraLarge.value) ) { Image( painterResource(id = R.drawable.ic_blaze_overlay_image), @@ -205,18 +203,6 @@ class BlazeOverlayFragment : Fragment() { } } - @Composable - fun ScrollableBox(uiModel: BlazeUIModel?, - isDarkTheme: Boolean) { - Box(Modifier.fillMaxSize()) { - LazyColumn(Modifier.fillMaxSize()) { - items(1) { - BlazeOverlayContent(uiModel, isDarkTheme) - } - } - } - } - private fun getPrimaryButtonColor(isInDarkTheme: Boolean): Color { return if (isInDarkTheme) darkModePrimaryButtonColor else AppColor.Black From 4723afabdb39c3b722aa53ea77dcf6d161e0535e Mon Sep 17 00:00:00 2001 From: Thomas Horta Date: Thu, 2 Mar 2023 11:43:57 -0300 Subject: [PATCH 052/856] using compose screens for old flow, needs clean-up --- .../ui/JetpackRemoteInstallActivity.kt | 2 + .../ui/JetpackRemoteInstallComposeFragment.kt | 138 ++++++++++++ .../JetpackRemoteInstallComposeViewModel.kt | 203 ++++++++++++++++++ .../JetpackFullPluginInstallActivity.kt | 70 ++---- .../install/JetpackFullPluginInstallScreen.kt | 69 ++++++ .../jetpack_remote_install_activity.xml | 2 +- 6 files changed, 427 insertions(+), 57 deletions(-) create mode 100644 WordPress/src/main/java/org/wordpress/android/ui/JetpackRemoteInstallComposeFragment.kt create mode 100644 WordPress/src/main/java/org/wordpress/android/ui/JetpackRemoteInstallComposeViewModel.kt create mode 100644 WordPress/src/main/java/org/wordpress/android/ui/jpfullplugininstall/install/JetpackFullPluginInstallScreen.kt diff --git a/WordPress/src/main/java/org/wordpress/android/ui/JetpackRemoteInstallActivity.kt b/WordPress/src/main/java/org/wordpress/android/ui/JetpackRemoteInstallActivity.kt index 273062232db3..535cb6feb874 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/JetpackRemoteInstallActivity.kt +++ b/WordPress/src/main/java/org/wordpress/android/ui/JetpackRemoteInstallActivity.kt @@ -2,12 +2,14 @@ package org.wordpress.android.ui import android.os.Bundle import android.view.MenuItem +import dagger.hilt.android.AndroidEntryPoint 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 +@AndroidEntryPoint class JetpackRemoteInstallActivity : LocaleAwareActivity() { public override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) diff --git a/WordPress/src/main/java/org/wordpress/android/ui/JetpackRemoteInstallComposeFragment.kt b/WordPress/src/main/java/org/wordpress/android/ui/JetpackRemoteInstallComposeFragment.kt new file mode 100644 index 000000000000..9907f8758465 --- /dev/null +++ b/WordPress/src/main/java/org/wordpress/android/ui/JetpackRemoteInstallComposeFragment.kt @@ -0,0 +1,138 @@ +package org.wordpress.android.ui + +import android.app.Activity +import android.content.Intent +import android.os.Bundle +import android.view.LayoutInflater +import android.view.View +import android.view.ViewGroup +import androidx.compose.runtime.getValue +import androidx.compose.runtime.livedata.observeAsState +import androidx.compose.ui.platform.ComposeView +import androidx.fragment.app.Fragment +import androidx.fragment.app.FragmentActivity +import androidx.fragment.app.viewModels +import dagger.hilt.android.AndroidEntryPoint +import org.wordpress.android.R +import org.wordpress.android.WordPress +import org.wordpress.android.fluxc.model.SiteModel +import org.wordpress.android.login.LoginMode +import org.wordpress.android.ui.JetpackRemoteInstallComposeViewModel.JetpackResultActionData.Action.CONNECT +import org.wordpress.android.ui.JetpackRemoteInstallComposeViewModel.JetpackResultActionData.Action.LOGIN +import org.wordpress.android.ui.JetpackRemoteInstallComposeViewModel.JetpackResultActionData.Action.MANUAL_INSTALL +import org.wordpress.android.ui.accounts.LoginActivity +import org.wordpress.android.ui.compose.theme.AppTheme +import org.wordpress.android.ui.jpfullplugininstall.install.JetpackFullPluginInstallScreen +import org.wordpress.android.ui.jpfullplugininstall.install.UiState + +@AndroidEntryPoint +class JetpackRemoteInstallComposeFragment : Fragment() { + private val viewModel: JetpackRemoteInstallComposeViewModel by viewModels() + + override fun onCreateView( + inflater: LayoutInflater, + container: ViewGroup?, + savedInstanceState: Bundle? + ): View = ComposeView(requireContext()).apply { + setContent { + AppTheme { + val uiState by viewModel.liveViewState.observeAsState() + JetpackFullPluginInstallScreen( + uiState = uiState ?: UiState.Initial(R.string.install_jetpack_continue), + onDismissScreenClick = {}, + onContinueClick = viewModel::start, + onDoneClick = viewModel::connect, + onRetryClick = viewModel::restart, + onContactSupportClick = {}, + ) + } + } + } + + override fun onViewCreated(view: View, savedInstanceState: Bundle?) { + super.onViewCreated(view, savedInstanceState) + initViewModel(savedInstanceState) + } + + + private fun 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? JetpackRemoteInstallComposeViewModel.Type + viewModel.initialize(site, retrievedState) + + viewModel.liveActionOnResult.observe(viewLifecycleOwner) { result -> + if (result != null) { + when (result.action) { + MANUAL_INSTALL -> onManualInstallResultAction(activity, source, result) + LOGIN -> onLoginResultAction(activity, source) + CONNECT -> onConnectResultAction(activity, source, result) + } + } + } + } + } + + private fun onManualInstallResultAction( + activity: FragmentActivity, + source: JetpackConnectionSource, + result: JetpackRemoteInstallComposeViewModel.JetpackResultActionData + ) { + JetpackConnectionWebViewActivity.startManualFlow( + activity, + source, + result.site, + result.loggedIn + ) + activity.finish() + } + + @Suppress("DEPRECATION") + private fun onLoginResultAction( + activity: FragmentActivity, + source: JetpackConnectionSource + ) { + val loginIntent = Intent(activity, LoginActivity::class.java) + LoginMode.JETPACK_STATS.putInto(loginIntent) + loginIntent.putExtra(LoginActivity.ARG_JETPACK_CONNECT_SOURCE, source) + startActivityForResult(loginIntent, RequestCodes.JETPACK_LOGIN) + } + + private fun onConnectResultAction( + activity: FragmentActivity, + source: JetpackConnectionSource, + result: JetpackRemoteInstallComposeViewModel.JetpackResultActionData + ) { + JetpackConnectionWebViewActivity.startJetpackConnectionFlow( + activity, + source, + result.site, + result.loggedIn + ) + activity.finish() + } + + @Suppress("DEPRECATION", "OVERRIDE_DEPRECATION") + override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) { + super.onActivityResult(requestCode, resultCode, data) + if (requestCode == RequestCodes.JETPACK_LOGIN && resultCode == Activity.RESULT_OK) { + val site = requireActivity().intent!!.getSerializableExtra(WordPress.SITE) as SiteModel + viewModel.onLogin(site.id) + } + } + + override fun onSaveInstanceState(outState: Bundle) { + super.onSaveInstanceState(outState) + viewModel.liveViewState.value?.let { + outState.putSerializable(VIEW_STATE, JetpackRemoteInstallComposeViewModel.Type.fromState(it)) + } + } + + companion object { + const val TRACKING_SOURCE_KEY = "tracking_source_key" + private const val VIEW_STATE = "view_state_key" + } +} diff --git a/WordPress/src/main/java/org/wordpress/android/ui/JetpackRemoteInstallComposeViewModel.kt b/WordPress/src/main/java/org/wordpress/android/ui/JetpackRemoteInstallComposeViewModel.kt new file mode 100644 index 000000000000..cb6b04618b1f --- /dev/null +++ b/WordPress/src/main/java/org/wordpress/android/ui/JetpackRemoteInstallComposeViewModel.kt @@ -0,0 +1,203 @@ +package org.wordpress.android.ui + +import androidx.lifecycle.LiveData +import androidx.lifecycle.MutableLiveData +import androidx.lifecycle.ViewModel +import dagger.hilt.android.lifecycle.HiltViewModel +import org.greenrobot.eventbus.Subscribe +import org.greenrobot.eventbus.ThreadMode +import org.wordpress.android.R +import org.wordpress.android.analytics.AnalyticsTracker +import org.wordpress.android.analytics.AnalyticsTracker.Stat.INSTALL_JETPACK_REMOTE_RESTART +import org.wordpress.android.analytics.AnalyticsTracker.Stat.INSTALL_JETPACK_REMOTE_START +import org.wordpress.android.fluxc.Dispatcher +import org.wordpress.android.fluxc.generated.JetpackActionBuilder +import org.wordpress.android.fluxc.model.SiteModel +import org.wordpress.android.fluxc.store.AccountStore +import org.wordpress.android.fluxc.store.JetpackStore +import org.wordpress.android.fluxc.store.JetpackStore.OnJetpackInstalled +import org.wordpress.android.fluxc.store.SiteStore +import org.wordpress.android.ui.JetpackRemoteInstallComposeViewModel.JetpackResultActionData.Action +import org.wordpress.android.ui.JetpackRemoteInstallComposeViewModel.JetpackResultActionData.Action.CONNECT +import org.wordpress.android.ui.JetpackRemoteInstallComposeViewModel.JetpackResultActionData.Action.LOGIN +import org.wordpress.android.ui.JetpackRemoteInstallComposeViewModel.JetpackResultActionData.Action.MANUAL_INSTALL +import org.wordpress.android.ui.JetpackRemoteInstallComposeViewModel.Type.ERROR +import org.wordpress.android.ui.JetpackRemoteInstallComposeViewModel.Type.INSTALLED +import org.wordpress.android.ui.JetpackRemoteInstallComposeViewModel.Type.INSTALLING +import org.wordpress.android.ui.JetpackRemoteInstallComposeViewModel.Type.START +import org.wordpress.android.ui.jpfullplugininstall.install.UiState +import org.wordpress.android.viewmodel.SingleLiveEvent +import javax.inject.Inject + +private const val INVALID_CREDENTIALS = "INVALID_CREDENTIALS" +private const val FORBIDDEN = "FORBIDDEN" +private const val INSTALL_FAILURE = "INSTALL_FAILURE" +private const val INSTALL_RESPONSE_ERROR = "INSTALL_RESPONSE_ERROR" +private const val LOGIN_FAILURE = "LOGIN_FAILURE" +private const val SITE_IS_JETPACK = "SITE_IS_JETPACK" +private const val ACTIVATION_ON_INSTALL_FAILURE = "ACTIVATION_ON_INSTALL_FAILURE" +private const val ACTIVATION_RESPONSE_ERROR = "ACTIVATION_RESPONSE_ERROR" +private const val ACTIVATION_FAILURE = "ACTIVATION_FAILURE" +private val BLOCKING_FAILURES = listOf( + FORBIDDEN, + INSTALL_FAILURE, + INSTALL_RESPONSE_ERROR, + LOGIN_FAILURE, + INVALID_CREDENTIALS, + ACTIVATION_ON_INSTALL_FAILURE, + ACTIVATION_RESPONSE_ERROR, + ACTIVATION_FAILURE +) +private const val CONTEXT = "JetpackRemoteInstall" +private const val EMPTY_TYPE = "EMPTY_TYPE" +private const val EMPTY_MESSAGE = "EMPTY_MESSAGE" + +@HiltViewModel +class JetpackRemoteInstallComposeViewModel +@Inject constructor( + private val dispatcher: Dispatcher, + private val accountStore: AccountStore, + private val siteStore: SiteStore, + //JetpackStore needs to be injected here as otherwise FluxC doesn't accept emitted events. + @Suppress("unused") private val jetpackStore: JetpackStore +) : ViewModel() { + private val mutableViewState = MutableLiveData() + val liveViewState: LiveData = mutableViewState + private val mutableActionOnResult = SingleLiveEvent() + val liveActionOnResult: LiveData = mutableActionOnResult + private lateinit var siteModel: SiteModel + + init { + dispatcher.register(this) + } + + fun initialize(site: SiteModel, type: Type?) { + siteModel = site + // Init state only if it's empty + if (mutableViewState.value == null) { + mutableViewState.value = type.toState() + if (type == INSTALLING) startRemoteInstall(site) + } + } + + override fun onCleared() { + super.onCleared() + dispatcher.unregister(this) + } + + fun onLogin(siteId: Int) { + connect(siteId) + } + + private fun Type?.toState(): UiState { + if (this == null) { + return UiState.Initial(R.string.install_jetpack_continue) + } + return when (this) { + START -> UiState.Initial(R.string.install_jetpack_continue) + INSTALLING -> UiState.Installing + INSTALLED -> UiState.Done(R.string.install_jetpack_continue) + ERROR -> UiState.Error( + R.string.install_jetpack_retry, + R.string.jetpack_full_plugin_install_error_button_contact_support + ) + } + } + + fun start() { + AnalyticsTracker.track(INSTALL_JETPACK_REMOTE_START) + startRemoteInstall(siteModel) + } + + fun restart() { + AnalyticsTracker.track(INSTALL_JETPACK_REMOTE_RESTART) + startRemoteInstall(siteModel) + } + + fun connect(siteId: Int = siteModel.id) { + val hasAccessToken = accountStore.hasAccessToken() + val action = if (hasAccessToken) { + AnalyticsTracker.track(AnalyticsTracker.Stat.INSTALL_JETPACK_REMOTE_CONNECT) + CONNECT + } else { + AnalyticsTracker.track(AnalyticsTracker.Stat.INSTALL_JETPACK_REMOTE_LOGIN) + LOGIN + } + triggerResultAction(siteId, action, hasAccessToken) + } + + private fun startRemoteInstall(site: SiteModel) { + mutableViewState.postValue(INSTALLING.toState()) + dispatcher.dispatch(JetpackActionBuilder.newInstallJetpackAction(site)) + } + + private fun triggerResultAction( + siteId: Int, + action: Action, + hasAccessToken: Boolean = accountStore.hasAccessToken() + ) { + mutableActionOnResult.postValue( + JetpackResultActionData( + siteStore.getSiteByLocalId(siteId)!!, + hasAccessToken, + action + ) + ) + } + + // Network Callbacks + @Suppress("unused") + @Subscribe(threadMode = ThreadMode.BACKGROUND) + fun onEventsUpdated(event: OnJetpackInstalled) { + val site = siteModel + if (event.isError) { + AnalyticsTracker.track( + AnalyticsTracker.Stat.INSTALL_JETPACK_REMOTE_FAILED, + CONTEXT, + event.error?.apiError ?: EMPTY_TYPE, + event.error?.message ?: EMPTY_MESSAGE + ) + when { + event.error?.apiError == SITE_IS_JETPACK -> { + AnalyticsTracker.track(AnalyticsTracker.Stat.INSTALL_JETPACK_REMOTE_COMPLETED) + mutableViewState.postValue(INSTALLED.toState()) + } + BLOCKING_FAILURES.contains(event.error?.apiError) -> { + AnalyticsTracker.track(AnalyticsTracker.Stat.INSTALL_JETPACK_REMOTE_START_MANUAL_FLOW) + triggerResultAction(site.id, MANUAL_INSTALL) + } + else -> mutableViewState.postValue(ERROR.toState()) + } + return + } + if (event.success) { + AnalyticsTracker.track(AnalyticsTracker.Stat.INSTALL_JETPACK_REMOTE_COMPLETED) + mutableViewState.postValue(INSTALLED.toState()) + } else { + AnalyticsTracker.track(AnalyticsTracker.Stat.INSTALL_JETPACK_REMOTE_FAILED) + mutableViewState.postValue(ERROR.toState()) + } + } + + data class JetpackResultActionData(val site: SiteModel, val loggedIn: Boolean, val action: Action) { + enum class Action { + LOGIN, MANUAL_INSTALL, CONNECT + } + } + + enum class Type { + START, INSTALLING, INSTALLED, ERROR; + + companion object { + fun fromState(state: UiState): Type { + return when (state) { + is UiState.Initial -> START + is UiState.Installing -> INSTALLING + is UiState.Done -> INSTALLED + is UiState.Error -> ERROR + } + } + } + } +} + diff --git a/WordPress/src/main/java/org/wordpress/android/ui/jpfullplugininstall/install/JetpackFullPluginInstallActivity.kt b/WordPress/src/main/java/org/wordpress/android/ui/jpfullplugininstall/install/JetpackFullPluginInstallActivity.kt index 55a257ca694e..2b6d95157ddd 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/jpfullplugininstall/install/JetpackFullPluginInstallActivity.kt +++ b/WordPress/src/main/java/org/wordpress/android/ui/jpfullplugininstall/install/JetpackFullPluginInstallActivity.kt @@ -5,23 +5,14 @@ import android.content.Intent import android.os.Bundle import androidx.activity.viewModels import androidx.appcompat.app.AppCompatActivity -import androidx.compose.material.Scaffold -import androidx.compose.runtime.Composable import androidx.compose.runtime.collectAsState import androidx.compose.runtime.getValue -import androidx.compose.ui.res.stringResource import androidx.lifecycle.lifecycleScope import dagger.hilt.android.AndroidEntryPoint import kotlinx.coroutines.flow.launchIn import kotlinx.coroutines.flow.onEach import org.wordpress.android.ui.ActivityLauncher -import org.wordpress.android.ui.compose.components.MainTopAppBar -import org.wordpress.android.ui.compose.components.NavigationIcons import org.wordpress.android.ui.compose.theme.AppTheme -import org.wordpress.android.ui.jpfullplugininstall.install.compose.state.DoneState -import org.wordpress.android.ui.jpfullplugininstall.install.compose.state.ErrorState -import org.wordpress.android.ui.jpfullplugininstall.install.compose.state.InitialState -import org.wordpress.android.ui.jpfullplugininstall.install.compose.state.InstallingState import org.wordpress.android.util.extensions.exhaustive import org.wordpress.android.util.extensions.setContent @@ -33,7 +24,19 @@ class JetpackFullPluginInstallActivity : AppCompatActivity() { super.onCreate(savedInstanceState) setContent { AppTheme { - JetpackFullPluginInstallScreen() + val uiState by viewModel.uiState.collectAsState() + JetpackFullPluginInstallScreen( + uiState = uiState, + onDismissScreenClick = viewModel::onDismissScreenClick, + onContinueClick = viewModel::onContinueClick, + onDoneClick = viewModel::onDoneClick, + onRetryClick = viewModel::onRetryClick, + onContactSupportClick = viewModel::onContactSupportClick, + onInitialShown = viewModel::onInitialShown, + onInstallingShown = viewModel::onInstallingShown, + onErrorShown = viewModel::onErrorShown, + + ) } } observeActionEvents() @@ -43,52 +46,6 @@ class JetpackFullPluginInstallActivity : AppCompatActivity() { viewModel.onBackPressed() } - @Composable - private fun JetpackFullPluginInstallScreen() { - val uiState by viewModel.uiState.collectAsState() - uiState.apply { - Scaffold( - topBar = { - MainTopAppBar( - title = stringResource(toolbarTitle), - navigationIcon = NavigationIcons.CloseIcon.takeIf { uiState.showCloseButton }, - onNavigationIconClick = viewModel::onDismissScreenClick - ) - }, - ) { - when (this) { - is UiState.Initial -> { - InitialState( - uiState = this, - onContinueClick = viewModel::onContinueClick, - ) - viewModel.onInitialShown() - } - is UiState.Installing -> { - InstallingState( - uiState = this, - ) - viewModel.onInstallingShown() - } - is UiState.Done -> { - DoneState( - uiState = this, - onDoneClick = viewModel::onDoneClick, - ) - } - is UiState.Error -> { - ErrorState( - uiState = this, - onRetryClick = viewModel::onRetryClick, - onContactSupportClick = viewModel::onContactSupportClick, - ) - viewModel.onErrorShown() - } - } - } - } - } - private fun observeActionEvents() { viewModel.actionEvents.onEach(this::handleActionEvents).launchIn(lifecycleScope) } @@ -103,6 +60,7 @@ class JetpackFullPluginInstallActivity : AppCompatActivity() { null ) } + is ActionEvent.Dismiss -> { ActivityLauncher.showMainActivity(this) finish() diff --git a/WordPress/src/main/java/org/wordpress/android/ui/jpfullplugininstall/install/JetpackFullPluginInstallScreen.kt b/WordPress/src/main/java/org/wordpress/android/ui/jpfullplugininstall/install/JetpackFullPluginInstallScreen.kt new file mode 100644 index 000000000000..66a52814e7c8 --- /dev/null +++ b/WordPress/src/main/java/org/wordpress/android/ui/jpfullplugininstall/install/JetpackFullPluginInstallScreen.kt @@ -0,0 +1,69 @@ +package org.wordpress.android.ui.jpfullplugininstall.install + +import androidx.compose.material.Scaffold +import androidx.compose.runtime.Composable +import androidx.compose.ui.res.stringResource +import org.wordpress.android.ui.compose.components.MainTopAppBar +import org.wordpress.android.ui.compose.components.NavigationIcons +import org.wordpress.android.ui.jpfullplugininstall.install.compose.state.DoneState +import org.wordpress.android.ui.jpfullplugininstall.install.compose.state.ErrorState +import org.wordpress.android.ui.jpfullplugininstall.install.compose.state.InitialState +import org.wordpress.android.ui.jpfullplugininstall.install.compose.state.InstallingState + +@Composable +fun JetpackFullPluginInstallScreen( + uiState: UiState, + onDismissScreenClick: () -> Unit, + onContinueClick: () -> Unit, + onDoneClick: () -> Unit, + onRetryClick: () -> Unit, + onContactSupportClick: () -> Unit, + onInitialShown: () -> Unit = {}, + onInstallingShown: () -> Unit = {}, + onErrorShown: () -> Unit = {}, +) { + uiState.apply { + Scaffold( + topBar = { + MainTopAppBar( + title = stringResource(toolbarTitle), + navigationIcon = NavigationIcons.CloseIcon.takeIf { uiState.showCloseButton }, + onNavigationIconClick = onDismissScreenClick + ) + }, + ) { + when (this) { + is UiState.Initial -> { + InitialState( + uiState = this, + onContinueClick = onContinueClick, + ) + onInitialShown() + } + + is UiState.Installing -> { + InstallingState( + uiState = this, + ) + onInstallingShown() + } + + is UiState.Done -> { + DoneState( + uiState = this, + onDoneClick = onDoneClick, + ) + } + + is UiState.Error -> { + ErrorState( + uiState = this, + onRetryClick = onRetryClick, + onContactSupportClick = onContactSupportClick, + ) + onErrorShown() + } + } + } + } +} diff --git a/WordPress/src/main/res/layout/jetpack_remote_install_activity.xml b/WordPress/src/main/res/layout/jetpack_remote_install_activity.xml index 86e303340664..1b1851cd152d 100644 --- a/WordPress/src/main/res/layout/jetpack_remote_install_activity.xml +++ b/WordPress/src/main/res/layout/jetpack_remote_install_activity.xml @@ -9,7 +9,7 @@ From cf36be64f49a6324786f936f19baa1cd8060e989 Mon Sep 17 00:00:00 2001 From: Thomas Horta Date: Thu, 2 Mar 2023 16:33:22 -0300 Subject: [PATCH 053/856] clean up usage of Compose screen for remote and full plugin install --- .../android/modules/AppComponent.java | 3 - .../android/modules/ViewModelModule.java | 6 - .../android/ui/ActivityLauncher.java | 2 +- .../ui/JetpackRemoteInstallActivity.kt | 142 ++++++++++-- .../ui/JetpackRemoteInstallComposeFragment.kt | 138 ------------ .../JetpackRemoteInstallComposeViewModel.kt | 203 ------------------ .../ui/JetpackRemoteInstallFragment.kt | 158 -------------- .../ui/JetpackRemoteInstallViewModel.kt | 110 ++++++---- .../JetpackFullPluginInstallActivity.kt | 10 +- .../JetpackFullPluginInstallUiStateMapper.kt | 9 +- ...creen.kt => JetpackPluginInstallScreen.kt} | 18 +- .../ui/jpfullplugininstall/install/UiState.kt | 25 +-- .../install/compose/state/DoneState.kt | 3 +- .../install/compose/state/ErrorState.kt | 4 +- .../install/compose/state/InitialState.kt | 2 +- .../jetpack_remote_install_activity.xml | 16 -- .../jetpack_remote_install_fragment.xml | 67 ------ WordPress/src/main/res/values-ar/strings.xml | 4 +- WordPress/src/main/res/values-cs/strings.xml | 4 +- WordPress/src/main/res/values-de/strings.xml | 4 +- .../src/main/res/values-en-rAU/strings.xml | 4 +- .../src/main/res/values-en-rCA/strings.xml | 4 +- .../src/main/res/values-en-rGB/strings.xml | 4 +- .../src/main/res/values-es-rCO/strings.xml | 4 +- .../src/main/res/values-es-rMX/strings.xml | 4 +- .../src/main/res/values-es-rVE/strings.xml | 4 +- WordPress/src/main/res/values-es/strings.xml | 6 +- .../src/main/res/values-fr-rCA/strings.xml | 4 +- WordPress/src/main/res/values-fr/strings.xml | 4 +- WordPress/src/main/res/values-gl/strings.xml | 30 +-- WordPress/src/main/res/values-he/strings.xml | 4 +- WordPress/src/main/res/values-id/strings.xml | 6 +- WordPress/src/main/res/values-it/strings.xml | 4 +- WordPress/src/main/res/values-ja/strings.xml | 4 +- WordPress/src/main/res/values-kmr/strings.xml | 4 +- WordPress/src/main/res/values-ko/strings.xml | 4 +- WordPress/src/main/res/values-lv/strings.xml | 4 +- WordPress/src/main/res/values-nb/strings.xml | 4 +- WordPress/src/main/res/values-nl/strings.xml | 4 +- WordPress/src/main/res/values-pl/strings.xml | 4 +- .../src/main/res/values-pt-rBR/strings.xml | 4 +- WordPress/src/main/res/values-ro/strings.xml | 32 +-- WordPress/src/main/res/values-ru/strings.xml | 4 +- WordPress/src/main/res/values-sq/strings.xml | 4 +- WordPress/src/main/res/values-sr/strings.xml | 2 +- WordPress/src/main/res/values-sv/strings.xml | 30 +-- WordPress/src/main/res/values-tr/strings.xml | 32 +-- WordPress/src/main/res/values-vi/strings.xml | 4 +- .../src/main/res/values-zh-rCN/strings.xml | 4 +- .../src/main/res/values-zh-rHK/strings.xml | 4 +- .../src/main/res/values-zh-rTW/strings.xml | 4 +- WordPress/src/main/res/values/strings.xml | 42 ++-- .../ui/JetpackRemoteInstallViewModelTest.kt | 98 ++++----- ...tpackFullPluginInstallUiStateMapperTest.kt | 32 +-- 54 files changed, 429 insertions(+), 905 deletions(-) delete mode 100644 WordPress/src/main/java/org/wordpress/android/ui/JetpackRemoteInstallComposeFragment.kt delete mode 100644 WordPress/src/main/java/org/wordpress/android/ui/JetpackRemoteInstallComposeViewModel.kt delete mode 100644 WordPress/src/main/java/org/wordpress/android/ui/JetpackRemoteInstallFragment.kt rename WordPress/src/main/java/org/wordpress/android/ui/jpfullplugininstall/install/{JetpackFullPluginInstallScreen.kt => JetpackPluginInstallScreen.kt} (84%) delete mode 100644 WordPress/src/main/res/layout/jetpack_remote_install_activity.xml delete mode 100644 WordPress/src/main/res/layout/jetpack_remote_install_fragment.xml diff --git a/WordPress/src/main/java/org/wordpress/android/modules/AppComponent.java b/WordPress/src/main/java/org/wordpress/android/modules/AppComponent.java index a5c8d3f49c06..0947e4604d6f 100644 --- a/WordPress/src/main/java/org/wordpress/android/modules/AppComponent.java +++ b/WordPress/src/main/java/org/wordpress/android/modules/AppComponent.java @@ -5,7 +5,6 @@ import org.wordpress.android.ui.AddQuickPressShortcutActivity; import org.wordpress.android.ui.CommentFullScreenDialogFragment; import org.wordpress.android.ui.JetpackConnectionResultActivity; -import org.wordpress.android.ui.JetpackRemoteInstallFragment; import org.wordpress.android.ui.ShareIntentReceiverActivity; import org.wordpress.android.ui.ShareIntentReceiverFragment; import org.wordpress.android.ui.WPWebViewActivity; @@ -418,8 +417,6 @@ public interface AppComponent { void inject(PublicizeServiceAdapter object); - void inject(JetpackRemoteInstallFragment jetpackRemoteInstallFragment); - void inject(PlansListAdapter object); void inject(PlanDetailsFragment object); diff --git a/WordPress/src/main/java/org/wordpress/android/modules/ViewModelModule.java b/WordPress/src/main/java/org/wordpress/android/modules/ViewModelModule.java index e0f80248ddfa..c4a3a4893e8f 100644 --- a/WordPress/src/main/java/org/wordpress/android/modules/ViewModelModule.java +++ b/WordPress/src/main/java/org/wordpress/android/modules/ViewModelModule.java @@ -3,7 +3,6 @@ import androidx.lifecycle.ViewModel; import androidx.lifecycle.ViewModelProvider; -import org.wordpress.android.ui.JetpackRemoteInstallViewModel; import org.wordpress.android.ui.accounts.LoginEpilogueViewModel; import org.wordpress.android.ui.accounts.LoginViewModel; import org.wordpress.android.ui.activitylog.list.filter.ActivityLogTypeFilterViewModel; @@ -148,11 +147,6 @@ abstract class ViewModelModule { @ViewModelKey(SubfilterPageViewModel.class) abstract ViewModel subfilterPageViewModel(SubfilterPageViewModel viewModel); - @Binds - @IntoMap - @ViewModelKey(JetpackRemoteInstallViewModel.class) - abstract ViewModel jetpackRemoteInstallViewModel(JetpackRemoteInstallViewModel viewModel); - @Binds @IntoMap @ViewModelKey(QuickStartViewModel.class) diff --git a/WordPress/src/main/java/org/wordpress/android/ui/ActivityLauncher.java b/WordPress/src/main/java/org/wordpress/android/ui/ActivityLauncher.java index f77b6237990e..7f06f94cc7a5 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/ActivityLauncher.java +++ b/WordPress/src/main/java/org/wordpress/android/ui/ActivityLauncher.java @@ -289,7 +289,7 @@ public static void showStockMediaPickerForResult(Activity activity, public static void startJetpackInstall(Context context, JetpackConnectionSource source, SiteModel site) { Intent intent = new Intent(context, JetpackRemoteInstallActivity.class); intent.putExtra(WordPress.SITE, site); - intent.putExtra(JetpackRemoteInstallFragment.TRACKING_SOURCE_KEY, source); + intent.putExtra(JetpackRemoteInstallActivity.TRACKING_SOURCE_KEY, source); context.startActivity(intent); } diff --git a/WordPress/src/main/java/org/wordpress/android/ui/JetpackRemoteInstallActivity.kt b/WordPress/src/main/java/org/wordpress/android/ui/JetpackRemoteInstallActivity.kt index 535cb6feb874..e6f798526173 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/JetpackRemoteInstallActivity.kt +++ b/WordPress/src/main/java/org/wordpress/android/ui/JetpackRemoteInstallActivity.kt @@ -1,36 +1,49 @@ package org.wordpress.android.ui +import android.app.Activity +import android.content.Intent import android.os.Bundle -import android.view.MenuItem +import androidx.activity.viewModels +import androidx.compose.runtime.getValue +import androidx.compose.runtime.livedata.observeAsState import dagger.hilt.android.AndroidEntryPoint import org.wordpress.android.R +import org.wordpress.android.WordPress import org.wordpress.android.analytics.AnalyticsTracker.Stat.INSTALL_JETPACK_CANCELLED -import org.wordpress.android.databinding.JetpackRemoteInstallActivityBinding +import org.wordpress.android.fluxc.model.SiteModel +import org.wordpress.android.login.LoginMode import org.wordpress.android.ui.JetpackConnectionUtils.trackWithSource -import org.wordpress.android.ui.JetpackRemoteInstallFragment.Companion.TRACKING_SOURCE_KEY +import org.wordpress.android.ui.JetpackRemoteInstallViewModel.JetpackResultActionData.Action.CONNECT +import org.wordpress.android.ui.JetpackRemoteInstallViewModel.JetpackResultActionData.Action.CONTACT_SUPPORT +import org.wordpress.android.ui.JetpackRemoteInstallViewModel.JetpackResultActionData.Action.LOGIN +import org.wordpress.android.ui.JetpackRemoteInstallViewModel.JetpackResultActionData.Action.MANUAL_INSTALL +import org.wordpress.android.ui.accounts.HelpActivity +import org.wordpress.android.ui.accounts.LoginActivity +import org.wordpress.android.ui.compose.theme.AppTheme +import org.wordpress.android.ui.jpfullplugininstall.install.JetpackPluginInstallScreen +import org.wordpress.android.ui.jpfullplugininstall.install.UiState +import org.wordpress.android.util.extensions.setContent @AndroidEntryPoint class JetpackRemoteInstallActivity : LocaleAwareActivity() { + private val viewModel: JetpackRemoteInstallViewModel by viewModels() + public override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) - with(JetpackRemoteInstallActivityBinding.inflate(layoutInflater)) { - setContentView(root) - setSupportActionBar(toolbarLayout.toolbarMain) - } - - supportActionBar?.let { - it.setHomeButtonEnabled(true) - it.setDisplayHomeAsUpEnabled(true) - it.setTitle(R.string.jetpack) - } - } - - override fun onOptionsItemSelected(item: MenuItem): Boolean { - if (item.itemId == android.R.id.home) { - onBackPressed() - return true + setContent { + AppTheme { + val uiState by viewModel.liveViewState.observeAsState() + JetpackPluginInstallScreen( + uiState = uiState ?: UiState.Initial(R.string.jetpack_plugin_install_remote_plugin_button), + onDismissScreenClick = ::onBackPressed, + onInitialButtonClick = viewModel::onInitialButtonClick, + onDoneButtonClick = viewModel::onDoneButtonClick, + onRetryButtonClick = viewModel::onRetryButtonClick, + onContactSupportButtonClick = viewModel::onContactSupportButtonClick, + ) + } } - return super.onOptionsItemSelected(item) + initViewModel(savedInstanceState) } override fun onBackPressed() { @@ -40,4 +53,93 @@ class JetpackRemoteInstallActivity : LocaleAwareActivity() { ) super.onBackPressed() } + + private fun initViewModel(savedInstanceState: Bundle?) { + val site = intent.getSerializableExtra(WordPress.SITE) as SiteModel + val source = intent.getSerializableExtra(TRACKING_SOURCE_KEY) as JetpackConnectionSource + val retrievedState = savedInstanceState + ?.getSerializable(VIEW_STATE) as? JetpackRemoteInstallViewModel.Type + viewModel.initialize(site, retrievedState) + + viewModel.liveActionOnResult.observe(this) { result -> + if (result != null) { + when (result.action) { + MANUAL_INSTALL -> onManualInstallResultAction(source, result) + LOGIN -> onLoginResultAction(source) + CONNECT -> onConnectResultAction(source, result) + CONTACT_SUPPORT -> onContactSupportResultAction(result) + } + } + } + } + + private fun onManualInstallResultAction( + source: JetpackConnectionSource, + result: JetpackRemoteInstallViewModel.JetpackResultActionData + ) { + JetpackConnectionWebViewActivity.startManualFlow( + this, + source, + result.site, + result.loggedIn + ) + finish() + } + + @Suppress("DEPRECATION") + private fun onLoginResultAction( + source: JetpackConnectionSource + ) { + val loginIntent = Intent(this, LoginActivity::class.java) + LoginMode.JETPACK_STATS.putInto(loginIntent) + loginIntent.putExtra(LoginActivity.ARG_JETPACK_CONNECT_SOURCE, source) + startActivityForResult(loginIntent, RequestCodes.JETPACK_LOGIN) + } + + private fun onConnectResultAction( + source: JetpackConnectionSource, + result: JetpackRemoteInstallViewModel.JetpackResultActionData + ) { + JetpackConnectionWebViewActivity.startJetpackConnectionFlow( + this, + source, + result.site, + result.loggedIn + ) + finish() + } + + private fun onContactSupportResultAction( + result: JetpackRemoteInstallViewModel.JetpackResultActionData + ) { + // TODO thomashorta confirm this is the correct tracking origin + val origin = HelpActivity.Origin.JETPACK_INSTALL_FULL_PLUGIN_ERROR + ActivityLauncher.viewHelp( + this, + origin, + result.site, + null + ) + } + + @Suppress("DEPRECATION", "OVERRIDE_DEPRECATION") + override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) { + super.onActivityResult(requestCode, resultCode, data) + if (requestCode == RequestCodes.JETPACK_LOGIN && resultCode == Activity.RESULT_OK) { + val site = intent!!.getSerializableExtra(WordPress.SITE) as SiteModel + viewModel.onLogin(site.id) + } + } + + override fun onSaveInstanceState(outState: Bundle) { + super.onSaveInstanceState(outState) + viewModel.liveViewState.value?.let { + outState.putSerializable(VIEW_STATE, JetpackRemoteInstallViewModel.Type.fromState(it)) + } + } + + companion object { + const val TRACKING_SOURCE_KEY = "tracking_source_key" + private const val VIEW_STATE = "view_state_key" + } } diff --git a/WordPress/src/main/java/org/wordpress/android/ui/JetpackRemoteInstallComposeFragment.kt b/WordPress/src/main/java/org/wordpress/android/ui/JetpackRemoteInstallComposeFragment.kt deleted file mode 100644 index 9907f8758465..000000000000 --- a/WordPress/src/main/java/org/wordpress/android/ui/JetpackRemoteInstallComposeFragment.kt +++ /dev/null @@ -1,138 +0,0 @@ -package org.wordpress.android.ui - -import android.app.Activity -import android.content.Intent -import android.os.Bundle -import android.view.LayoutInflater -import android.view.View -import android.view.ViewGroup -import androidx.compose.runtime.getValue -import androidx.compose.runtime.livedata.observeAsState -import androidx.compose.ui.platform.ComposeView -import androidx.fragment.app.Fragment -import androidx.fragment.app.FragmentActivity -import androidx.fragment.app.viewModels -import dagger.hilt.android.AndroidEntryPoint -import org.wordpress.android.R -import org.wordpress.android.WordPress -import org.wordpress.android.fluxc.model.SiteModel -import org.wordpress.android.login.LoginMode -import org.wordpress.android.ui.JetpackRemoteInstallComposeViewModel.JetpackResultActionData.Action.CONNECT -import org.wordpress.android.ui.JetpackRemoteInstallComposeViewModel.JetpackResultActionData.Action.LOGIN -import org.wordpress.android.ui.JetpackRemoteInstallComposeViewModel.JetpackResultActionData.Action.MANUAL_INSTALL -import org.wordpress.android.ui.accounts.LoginActivity -import org.wordpress.android.ui.compose.theme.AppTheme -import org.wordpress.android.ui.jpfullplugininstall.install.JetpackFullPluginInstallScreen -import org.wordpress.android.ui.jpfullplugininstall.install.UiState - -@AndroidEntryPoint -class JetpackRemoteInstallComposeFragment : Fragment() { - private val viewModel: JetpackRemoteInstallComposeViewModel by viewModels() - - override fun onCreateView( - inflater: LayoutInflater, - container: ViewGroup?, - savedInstanceState: Bundle? - ): View = ComposeView(requireContext()).apply { - setContent { - AppTheme { - val uiState by viewModel.liveViewState.observeAsState() - JetpackFullPluginInstallScreen( - uiState = uiState ?: UiState.Initial(R.string.install_jetpack_continue), - onDismissScreenClick = {}, - onContinueClick = viewModel::start, - onDoneClick = viewModel::connect, - onRetryClick = viewModel::restart, - onContactSupportClick = {}, - ) - } - } - } - - override fun onViewCreated(view: View, savedInstanceState: Bundle?) { - super.onViewCreated(view, savedInstanceState) - initViewModel(savedInstanceState) - } - - - private fun 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? JetpackRemoteInstallComposeViewModel.Type - viewModel.initialize(site, retrievedState) - - viewModel.liveActionOnResult.observe(viewLifecycleOwner) { result -> - if (result != null) { - when (result.action) { - MANUAL_INSTALL -> onManualInstallResultAction(activity, source, result) - LOGIN -> onLoginResultAction(activity, source) - CONNECT -> onConnectResultAction(activity, source, result) - } - } - } - } - } - - private fun onManualInstallResultAction( - activity: FragmentActivity, - source: JetpackConnectionSource, - result: JetpackRemoteInstallComposeViewModel.JetpackResultActionData - ) { - JetpackConnectionWebViewActivity.startManualFlow( - activity, - source, - result.site, - result.loggedIn - ) - activity.finish() - } - - @Suppress("DEPRECATION") - private fun onLoginResultAction( - activity: FragmentActivity, - source: JetpackConnectionSource - ) { - val loginIntent = Intent(activity, LoginActivity::class.java) - LoginMode.JETPACK_STATS.putInto(loginIntent) - loginIntent.putExtra(LoginActivity.ARG_JETPACK_CONNECT_SOURCE, source) - startActivityForResult(loginIntent, RequestCodes.JETPACK_LOGIN) - } - - private fun onConnectResultAction( - activity: FragmentActivity, - source: JetpackConnectionSource, - result: JetpackRemoteInstallComposeViewModel.JetpackResultActionData - ) { - JetpackConnectionWebViewActivity.startJetpackConnectionFlow( - activity, - source, - result.site, - result.loggedIn - ) - activity.finish() - } - - @Suppress("DEPRECATION", "OVERRIDE_DEPRECATION") - override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) { - super.onActivityResult(requestCode, resultCode, data) - if (requestCode == RequestCodes.JETPACK_LOGIN && resultCode == Activity.RESULT_OK) { - val site = requireActivity().intent!!.getSerializableExtra(WordPress.SITE) as SiteModel - viewModel.onLogin(site.id) - } - } - - override fun onSaveInstanceState(outState: Bundle) { - super.onSaveInstanceState(outState) - viewModel.liveViewState.value?.let { - outState.putSerializable(VIEW_STATE, JetpackRemoteInstallComposeViewModel.Type.fromState(it)) - } - } - - companion object { - const val TRACKING_SOURCE_KEY = "tracking_source_key" - private const val VIEW_STATE = "view_state_key" - } -} diff --git a/WordPress/src/main/java/org/wordpress/android/ui/JetpackRemoteInstallComposeViewModel.kt b/WordPress/src/main/java/org/wordpress/android/ui/JetpackRemoteInstallComposeViewModel.kt deleted file mode 100644 index cb6b04618b1f..000000000000 --- a/WordPress/src/main/java/org/wordpress/android/ui/JetpackRemoteInstallComposeViewModel.kt +++ /dev/null @@ -1,203 +0,0 @@ -package org.wordpress.android.ui - -import androidx.lifecycle.LiveData -import androidx.lifecycle.MutableLiveData -import androidx.lifecycle.ViewModel -import dagger.hilt.android.lifecycle.HiltViewModel -import org.greenrobot.eventbus.Subscribe -import org.greenrobot.eventbus.ThreadMode -import org.wordpress.android.R -import org.wordpress.android.analytics.AnalyticsTracker -import org.wordpress.android.analytics.AnalyticsTracker.Stat.INSTALL_JETPACK_REMOTE_RESTART -import org.wordpress.android.analytics.AnalyticsTracker.Stat.INSTALL_JETPACK_REMOTE_START -import org.wordpress.android.fluxc.Dispatcher -import org.wordpress.android.fluxc.generated.JetpackActionBuilder -import org.wordpress.android.fluxc.model.SiteModel -import org.wordpress.android.fluxc.store.AccountStore -import org.wordpress.android.fluxc.store.JetpackStore -import org.wordpress.android.fluxc.store.JetpackStore.OnJetpackInstalled -import org.wordpress.android.fluxc.store.SiteStore -import org.wordpress.android.ui.JetpackRemoteInstallComposeViewModel.JetpackResultActionData.Action -import org.wordpress.android.ui.JetpackRemoteInstallComposeViewModel.JetpackResultActionData.Action.CONNECT -import org.wordpress.android.ui.JetpackRemoteInstallComposeViewModel.JetpackResultActionData.Action.LOGIN -import org.wordpress.android.ui.JetpackRemoteInstallComposeViewModel.JetpackResultActionData.Action.MANUAL_INSTALL -import org.wordpress.android.ui.JetpackRemoteInstallComposeViewModel.Type.ERROR -import org.wordpress.android.ui.JetpackRemoteInstallComposeViewModel.Type.INSTALLED -import org.wordpress.android.ui.JetpackRemoteInstallComposeViewModel.Type.INSTALLING -import org.wordpress.android.ui.JetpackRemoteInstallComposeViewModel.Type.START -import org.wordpress.android.ui.jpfullplugininstall.install.UiState -import org.wordpress.android.viewmodel.SingleLiveEvent -import javax.inject.Inject - -private const val INVALID_CREDENTIALS = "INVALID_CREDENTIALS" -private const val FORBIDDEN = "FORBIDDEN" -private const val INSTALL_FAILURE = "INSTALL_FAILURE" -private const val INSTALL_RESPONSE_ERROR = "INSTALL_RESPONSE_ERROR" -private const val LOGIN_FAILURE = "LOGIN_FAILURE" -private const val SITE_IS_JETPACK = "SITE_IS_JETPACK" -private const val ACTIVATION_ON_INSTALL_FAILURE = "ACTIVATION_ON_INSTALL_FAILURE" -private const val ACTIVATION_RESPONSE_ERROR = "ACTIVATION_RESPONSE_ERROR" -private const val ACTIVATION_FAILURE = "ACTIVATION_FAILURE" -private val BLOCKING_FAILURES = listOf( - FORBIDDEN, - INSTALL_FAILURE, - INSTALL_RESPONSE_ERROR, - LOGIN_FAILURE, - INVALID_CREDENTIALS, - ACTIVATION_ON_INSTALL_FAILURE, - ACTIVATION_RESPONSE_ERROR, - ACTIVATION_FAILURE -) -private const val CONTEXT = "JetpackRemoteInstall" -private const val EMPTY_TYPE = "EMPTY_TYPE" -private const val EMPTY_MESSAGE = "EMPTY_MESSAGE" - -@HiltViewModel -class JetpackRemoteInstallComposeViewModel -@Inject constructor( - private val dispatcher: Dispatcher, - private val accountStore: AccountStore, - private val siteStore: SiteStore, - //JetpackStore needs to be injected here as otherwise FluxC doesn't accept emitted events. - @Suppress("unused") private val jetpackStore: JetpackStore -) : ViewModel() { - private val mutableViewState = MutableLiveData() - val liveViewState: LiveData = mutableViewState - private val mutableActionOnResult = SingleLiveEvent() - val liveActionOnResult: LiveData = mutableActionOnResult - private lateinit var siteModel: SiteModel - - init { - dispatcher.register(this) - } - - fun initialize(site: SiteModel, type: Type?) { - siteModel = site - // Init state only if it's empty - if (mutableViewState.value == null) { - mutableViewState.value = type.toState() - if (type == INSTALLING) startRemoteInstall(site) - } - } - - override fun onCleared() { - super.onCleared() - dispatcher.unregister(this) - } - - fun onLogin(siteId: Int) { - connect(siteId) - } - - private fun Type?.toState(): UiState { - if (this == null) { - return UiState.Initial(R.string.install_jetpack_continue) - } - return when (this) { - START -> UiState.Initial(R.string.install_jetpack_continue) - INSTALLING -> UiState.Installing - INSTALLED -> UiState.Done(R.string.install_jetpack_continue) - ERROR -> UiState.Error( - R.string.install_jetpack_retry, - R.string.jetpack_full_plugin_install_error_button_contact_support - ) - } - } - - fun start() { - AnalyticsTracker.track(INSTALL_JETPACK_REMOTE_START) - startRemoteInstall(siteModel) - } - - fun restart() { - AnalyticsTracker.track(INSTALL_JETPACK_REMOTE_RESTART) - startRemoteInstall(siteModel) - } - - fun connect(siteId: Int = siteModel.id) { - val hasAccessToken = accountStore.hasAccessToken() - val action = if (hasAccessToken) { - AnalyticsTracker.track(AnalyticsTracker.Stat.INSTALL_JETPACK_REMOTE_CONNECT) - CONNECT - } else { - AnalyticsTracker.track(AnalyticsTracker.Stat.INSTALL_JETPACK_REMOTE_LOGIN) - LOGIN - } - triggerResultAction(siteId, action, hasAccessToken) - } - - private fun startRemoteInstall(site: SiteModel) { - mutableViewState.postValue(INSTALLING.toState()) - dispatcher.dispatch(JetpackActionBuilder.newInstallJetpackAction(site)) - } - - private fun triggerResultAction( - siteId: Int, - action: Action, - hasAccessToken: Boolean = accountStore.hasAccessToken() - ) { - mutableActionOnResult.postValue( - JetpackResultActionData( - siteStore.getSiteByLocalId(siteId)!!, - hasAccessToken, - action - ) - ) - } - - // Network Callbacks - @Suppress("unused") - @Subscribe(threadMode = ThreadMode.BACKGROUND) - fun onEventsUpdated(event: OnJetpackInstalled) { - val site = siteModel - if (event.isError) { - AnalyticsTracker.track( - AnalyticsTracker.Stat.INSTALL_JETPACK_REMOTE_FAILED, - CONTEXT, - event.error?.apiError ?: EMPTY_TYPE, - event.error?.message ?: EMPTY_MESSAGE - ) - when { - event.error?.apiError == SITE_IS_JETPACK -> { - AnalyticsTracker.track(AnalyticsTracker.Stat.INSTALL_JETPACK_REMOTE_COMPLETED) - mutableViewState.postValue(INSTALLED.toState()) - } - BLOCKING_FAILURES.contains(event.error?.apiError) -> { - AnalyticsTracker.track(AnalyticsTracker.Stat.INSTALL_JETPACK_REMOTE_START_MANUAL_FLOW) - triggerResultAction(site.id, MANUAL_INSTALL) - } - else -> mutableViewState.postValue(ERROR.toState()) - } - return - } - if (event.success) { - AnalyticsTracker.track(AnalyticsTracker.Stat.INSTALL_JETPACK_REMOTE_COMPLETED) - mutableViewState.postValue(INSTALLED.toState()) - } else { - AnalyticsTracker.track(AnalyticsTracker.Stat.INSTALL_JETPACK_REMOTE_FAILED) - mutableViewState.postValue(ERROR.toState()) - } - } - - data class JetpackResultActionData(val site: SiteModel, val loggedIn: Boolean, val action: Action) { - enum class Action { - LOGIN, MANUAL_INSTALL, CONNECT - } - } - - enum class Type { - START, INSTALLING, INSTALLED, ERROR; - - companion object { - fun fromState(state: UiState): Type { - return when (state) { - is UiState.Initial -> START - is UiState.Installing -> INSTALLING - is UiState.Done -> INSTALLED - is UiState.Error -> ERROR - } - } - } - } -} - diff --git a/WordPress/src/main/java/org/wordpress/android/ui/JetpackRemoteInstallFragment.kt b/WordPress/src/main/java/org/wordpress/android/ui/JetpackRemoteInstallFragment.kt deleted file mode 100644 index e12f6b5a29fd..000000000000 --- a/WordPress/src/main/java/org/wordpress/android/ui/JetpackRemoteInstallFragment.kt +++ /dev/null @@ -1,158 +0,0 @@ -package org.wordpress.android.ui - -import android.app.Activity -import android.content.Intent -import android.content.res.ColorStateList -import android.os.Bundle -import android.view.View -import androidx.core.content.ContextCompat -import androidx.fragment.app.Fragment -import androidx.fragment.app.FragmentActivity -import androidx.lifecycle.Observer -import androidx.lifecycle.ViewModelProvider -import org.wordpress.android.R -import org.wordpress.android.WordPress -import org.wordpress.android.databinding.JetpackRemoteInstallFragmentBinding -import org.wordpress.android.fluxc.model.SiteModel -import org.wordpress.android.login.LoginMode -import org.wordpress.android.ui.JetpackRemoteInstallViewModel.JetpackResultActionData -import org.wordpress.android.ui.JetpackRemoteInstallViewModel.JetpackResultActionData.Action.CONNECT -import org.wordpress.android.ui.JetpackRemoteInstallViewModel.JetpackResultActionData.Action.LOGIN -import org.wordpress.android.ui.JetpackRemoteInstallViewModel.JetpackResultActionData.Action.MANUAL_INSTALL -import org.wordpress.android.ui.RequestCodes.JETPACK_LOGIN -import org.wordpress.android.ui.accounts.LoginActivity -import org.wordpress.android.util.AppLog -import javax.inject.Inject - -class JetpackRemoteInstallFragment : Fragment(R.layout.jetpack_remote_install_fragment) { - @Inject - lateinit var viewModelFactory: ViewModelProvider.Factory - private lateinit var viewModel: JetpackRemoteInstallViewModel - - override fun onViewCreated(view: View, savedInstanceState: Bundle?) { - super.onViewCreated(view, savedInstanceState) - with(JetpackRemoteInstallFragmentBinding.bind(view)) { - initDagger() - initViewModel(savedInstanceState) - } - } - - private fun initDagger() { - (requireActivity().application as WordPress).component().inject(this) - } - - 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 - viewModel = ViewModelProvider( - this@JetpackRemoteInstallFragment, viewModelFactory - ).get(JetpackRemoteInstallViewModel::class.java) - viewModel.start(site, retrievedState) - - initLiveViewStateObserver() - - viewModel.liveActionOnResult.observe(viewLifecycleOwner, Observer { result -> - if (result != null) { - when (result.action) { - MANUAL_INSTALL -> onManualInstallResultAction(activity, source, result) - LOGIN -> onLoginResultAction(activity, source) - CONNECT -> onConnectResultAction(activity, source, result) - } - } - }) - } - } - - private fun onManualInstallResultAction( - activity: FragmentActivity, - source: JetpackConnectionSource, - result: JetpackResultActionData - ) { - JetpackConnectionWebViewActivity.startManualFlow( - activity, - source, - result.site, - result.loggedIn - ) - activity.finish() - } - - @Suppress("DEPRECATION") - private fun onLoginResultAction( - activity: FragmentActivity, - source: JetpackConnectionSource - ) { - val loginIntent = Intent(activity, LoginActivity::class.java) - LoginMode.JETPACK_STATS.putInto(loginIntent) - loginIntent.putExtra(LoginActivity.ARG_JETPACK_CONNECT_SOURCE, source) - startActivityForResult(loginIntent, JETPACK_LOGIN) - } - - private fun onConnectResultAction( - activity: FragmentActivity, - source: JetpackConnectionSource, - result: JetpackResultActionData - ) { - JetpackConnectionWebViewActivity.startJetpackConnectionFlow( - activity, - source, - result.site, - result.loggedIn - ) - activity.finish() - } - - private fun JetpackRemoteInstallFragmentBinding.initLiveViewStateObserver() { - viewModel.liveViewState.observe(viewLifecycleOwner, Observer { viewState -> - if (viewState != null) { - if (viewState is JetpackRemoteInstallViewState.Error) { - AppLog.e(AppLog.T.JETPACK_REMOTE_INSTALL, "An error occurred while installing Jetpack") - } - jetpackInstallIcon.setImageResource(viewState.icon) - if (viewState.iconTint != null) { - jetpackInstallIcon.imageTintList = ColorStateList.valueOf( - ContextCompat.getColor( - jetpackInstallIcon.context, viewState.iconTint - ) - ) - } else { - jetpackInstallIcon.imageTintList = null - } - jetpackInstallTitle.setText(viewState.titleResource) - jetpackInstallMessage.setText(viewState.messageResource) - if (viewState.buttonResource != null) { - jetpackInstallButton.visibility = View.VISIBLE - jetpackInstallButton.setText(viewState.buttonResource) - } else { - jetpackInstallButton.visibility = View.GONE - } - jetpackInstallButton.setOnClickListener { viewState.onClick() } - jetpackInstallProgress.visibility = if (viewState.progressBarVisible) View.VISIBLE else View.GONE - } - }) - } - - @Suppress("DEPRECATION", "OVERRIDE_DEPRECATION") - override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) { - super.onActivityResult(requestCode, resultCode, data) - if (requestCode == JETPACK_LOGIN && resultCode == Activity.RESULT_OK) { - val site = requireActivity().intent!!.getSerializableExtra(WordPress.SITE) as SiteModel - viewModel.onLogin(site.id) - } - } - - override fun onSaveInstanceState(outState: Bundle) { - super.onSaveInstanceState(outState) - viewModel.liveViewState.value?.type?.let { - outState.putSerializable(VIEW_STATE, it) - } - } - - companion object { - const val TRACKING_SOURCE_KEY = "tracking_source_key" - private const val VIEW_STATE = "view_state_key" - } -} diff --git a/WordPress/src/main/java/org/wordpress/android/ui/JetpackRemoteInstallViewModel.kt b/WordPress/src/main/java/org/wordpress/android/ui/JetpackRemoteInstallViewModel.kt index 2af7a3f6dd80..dc61c7b6770d 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/JetpackRemoteInstallViewModel.kt +++ b/WordPress/src/main/java/org/wordpress/android/ui/JetpackRemoteInstallViewModel.kt @@ -3,8 +3,10 @@ package org.wordpress.android.ui import androidx.lifecycle.LiveData import androidx.lifecycle.MutableLiveData import androidx.lifecycle.ViewModel +import dagger.hilt.android.lifecycle.HiltViewModel import org.greenrobot.eventbus.Subscribe import org.greenrobot.eventbus.ThreadMode +import org.wordpress.android.R import org.wordpress.android.analytics.AnalyticsTracker import org.wordpress.android.analytics.AnalyticsTracker.Stat.INSTALL_JETPACK_REMOTE_RESTART import org.wordpress.android.analytics.AnalyticsTracker.Stat.INSTALL_JETPACK_REMOTE_START @@ -17,16 +19,14 @@ import org.wordpress.android.fluxc.store.JetpackStore.OnJetpackInstalled import org.wordpress.android.fluxc.store.SiteStore import org.wordpress.android.ui.JetpackRemoteInstallViewModel.JetpackResultActionData.Action import org.wordpress.android.ui.JetpackRemoteInstallViewModel.JetpackResultActionData.Action.CONNECT +import org.wordpress.android.ui.JetpackRemoteInstallViewModel.JetpackResultActionData.Action.CONTACT_SUPPORT import org.wordpress.android.ui.JetpackRemoteInstallViewModel.JetpackResultActionData.Action.LOGIN import org.wordpress.android.ui.JetpackRemoteInstallViewModel.JetpackResultActionData.Action.MANUAL_INSTALL -import org.wordpress.android.ui.JetpackRemoteInstallViewState.Error -import org.wordpress.android.ui.JetpackRemoteInstallViewState.Installed -import org.wordpress.android.ui.JetpackRemoteInstallViewState.Start -import org.wordpress.android.ui.JetpackRemoteInstallViewState.Type -import org.wordpress.android.ui.JetpackRemoteInstallViewState.Type.ERROR -import org.wordpress.android.ui.JetpackRemoteInstallViewState.Type.INSTALLED -import org.wordpress.android.ui.JetpackRemoteInstallViewState.Type.INSTALLING -import org.wordpress.android.ui.JetpackRemoteInstallViewState.Type.START +import org.wordpress.android.ui.JetpackRemoteInstallViewModel.Type.ERROR +import org.wordpress.android.ui.JetpackRemoteInstallViewModel.Type.INSTALLED +import org.wordpress.android.ui.JetpackRemoteInstallViewModel.Type.INSTALLING +import org.wordpress.android.ui.JetpackRemoteInstallViewModel.Type.START +import org.wordpress.android.ui.jpfullplugininstall.install.UiState import org.wordpress.android.viewmodel.SingleLiveEvent import javax.inject.Inject @@ -53,31 +53,31 @@ private const val CONTEXT = "JetpackRemoteInstall" private const val EMPTY_TYPE = "EMPTY_TYPE" private const val EMPTY_MESSAGE = "EMPTY_MESSAGE" +@HiltViewModel class JetpackRemoteInstallViewModel @Inject constructor( private val dispatcher: Dispatcher, private val accountStore: AccountStore, private val siteStore: SiteStore, - /** - * JetpackStore needs to be injected here as otherwise FluxC doesn't accept emitted events. - */ + //JetpackStore needs to be injected here as otherwise FluxC doesn't accept emitted events. @Suppress("unused") private val jetpackStore: JetpackStore ) : ViewModel() { - private val mutableViewState = MutableLiveData() - val liveViewState: LiveData = mutableViewState + private val mutableViewState = MutableLiveData() + val liveViewState: LiveData = mutableViewState private val mutableActionOnResult = SingleLiveEvent() val liveActionOnResult: LiveData = mutableActionOnResult - private var siteModel: SiteModel? = null + private lateinit var siteModel: SiteModel init { dispatcher.register(this) } - fun start(site: SiteModel, type: Type?) { + fun initialize(site: SiteModel, type: Type?) { siteModel = site // Init state only if it's empty if (mutableViewState.value == null) { - mutableViewState.value = type.toState(site) + mutableViewState.value = type.toState() + if (type == INSTALLING) startRemoteInstall(site) } } @@ -87,35 +87,39 @@ class JetpackRemoteInstallViewModel } fun onLogin(siteId: Int) { - connect(siteId) + onDoneButtonClick(siteId) } - private fun Type?.toState(site: SiteModel): JetpackRemoteInstallViewState { + private fun Type?.toState(): UiState { if (this == null) { - return Start { start(site) } + return UiState.Initial(R.string.jetpack_plugin_install_remote_plugin_button) } return when (this) { - START -> Start { start(site) } - INSTALLING -> { - startRemoteInstall(site) - JetpackRemoteInstallViewState.Installing - } - INSTALLED -> Installed { connect(site.id) } - ERROR -> Error { restart(site) } + START -> UiState.Initial(R.string.jetpack_plugin_install_remote_plugin_button) + INSTALLING -> UiState.Installing + INSTALLED -> UiState.Done( + R.string.jetpack_plugin_install_remote_plugin_done_description, + R.string.jetpack_plugin_install_remote_plugin_button + ) + + ERROR -> UiState.Error( + R.string.jetpack_plugin_install_error_button_retry, + R.string.jetpack_plugin_install_error_button_contact_support + ) } } - private fun start(site: SiteModel) { + fun onInitialButtonClick() { AnalyticsTracker.track(INSTALL_JETPACK_REMOTE_START) - startRemoteInstall(site) + startRemoteInstall(siteModel) } - private fun restart(site: SiteModel) { + fun onRetryButtonClick() { AnalyticsTracker.track(INSTALL_JETPACK_REMOTE_RESTART) - startRemoteInstall(site) + startRemoteInstall(siteModel) } - private fun connect(siteId: Int) { + fun onDoneButtonClick(siteId: Int = siteModel.id) { val hasAccessToken = accountStore.hasAccessToken() val action = if (hasAccessToken) { AnalyticsTracker.track(AnalyticsTracker.Stat.INSTALL_JETPACK_REMOTE_CONNECT) @@ -127,8 +131,18 @@ class JetpackRemoteInstallViewModel triggerResultAction(siteId, action, hasAccessToken) } + fun onContactSupportButtonClick() { + mutableActionOnResult.postValue( + JetpackResultActionData( + siteModel, + accountStore.hasAccessToken(), + CONTACT_SUPPORT + ) + ) + } + private fun startRemoteInstall(site: SiteModel) { - mutableViewState.postValue(JetpackRemoteInstallViewState.Installing) + mutableViewState.postValue(INSTALLING.toState()) dispatcher.dispatch(JetpackActionBuilder.newInstallJetpackAction(site)) } @@ -150,7 +164,7 @@ class JetpackRemoteInstallViewModel @Suppress("unused") @Subscribe(threadMode = ThreadMode.BACKGROUND) fun onEventsUpdated(event: OnJetpackInstalled) { - val site = siteModel ?: return + val site = siteModel if (event.isError) { AnalyticsTracker.track( AnalyticsTracker.Stat.INSTALL_JETPACK_REMOTE_FAILED, @@ -161,30 +175,46 @@ class JetpackRemoteInstallViewModel when { event.error?.apiError == SITE_IS_JETPACK -> { AnalyticsTracker.track(AnalyticsTracker.Stat.INSTALL_JETPACK_REMOTE_COMPLETED) - mutableViewState.postValue(Installed { connect(site.id) }) + mutableViewState.postValue(INSTALLED.toState()) } + BLOCKING_FAILURES.contains(event.error?.apiError) -> { AnalyticsTracker.track(AnalyticsTracker.Stat.INSTALL_JETPACK_REMOTE_START_MANUAL_FLOW) triggerResultAction(site.id, MANUAL_INSTALL) } - else -> mutableViewState.postValue(Error { - restart(site) - }) + + else -> mutableViewState.postValue(ERROR.toState()) } return } if (event.success) { AnalyticsTracker.track(AnalyticsTracker.Stat.INSTALL_JETPACK_REMOTE_COMPLETED) - mutableViewState.postValue(Installed { connect(site.id) }) + mutableViewState.postValue(INSTALLED.toState()) } else { AnalyticsTracker.track(AnalyticsTracker.Stat.INSTALL_JETPACK_REMOTE_FAILED) - mutableViewState.postValue(Error { restart(site) }) + mutableViewState.postValue(ERROR.toState()) } } data class JetpackResultActionData(val site: SiteModel, val loggedIn: Boolean, val action: Action) { enum class Action { - LOGIN, MANUAL_INSTALL, CONNECT + LOGIN, MANUAL_INSTALL, CONNECT, CONTACT_SUPPORT + } + } + + enum class Type { + START, INSTALLING, INSTALLED, ERROR; + + companion object { + fun fromState(state: UiState): Type { + return when (state) { + is UiState.Initial -> START + is UiState.Installing -> INSTALLING + is UiState.Done -> INSTALLED + is UiState.Error -> ERROR + } + } } } } + diff --git a/WordPress/src/main/java/org/wordpress/android/ui/jpfullplugininstall/install/JetpackFullPluginInstallActivity.kt b/WordPress/src/main/java/org/wordpress/android/ui/jpfullplugininstall/install/JetpackFullPluginInstallActivity.kt index 2b6d95157ddd..40bf6095857f 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/jpfullplugininstall/install/JetpackFullPluginInstallActivity.kt +++ b/WordPress/src/main/java/org/wordpress/android/ui/jpfullplugininstall/install/JetpackFullPluginInstallActivity.kt @@ -25,13 +25,13 @@ class JetpackFullPluginInstallActivity : AppCompatActivity() { setContent { AppTheme { val uiState by viewModel.uiState.collectAsState() - JetpackFullPluginInstallScreen( + JetpackPluginInstallScreen( uiState = uiState, onDismissScreenClick = viewModel::onDismissScreenClick, - onContinueClick = viewModel::onContinueClick, - onDoneClick = viewModel::onDoneClick, - onRetryClick = viewModel::onRetryClick, - onContactSupportClick = viewModel::onContactSupportClick, + onInitialButtonClick = viewModel::onContinueClick, + onDoneButtonClick = viewModel::onDoneClick, + onRetryButtonClick = viewModel::onRetryClick, + onContactSupportButtonClick = viewModel::onContactSupportClick, onInitialShown = viewModel::onInitialShown, onInstallingShown = viewModel::onInstallingShown, onErrorShown = viewModel::onErrorShown, diff --git a/WordPress/src/main/java/org/wordpress/android/ui/jpfullplugininstall/install/JetpackFullPluginInstallUiStateMapper.kt b/WordPress/src/main/java/org/wordpress/android/ui/jpfullplugininstall/install/JetpackFullPluginInstallUiStateMapper.kt index e6a93e1d9d6e..1325fb5df4a8 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/jpfullplugininstall/install/JetpackFullPluginInstallUiStateMapper.kt +++ b/WordPress/src/main/java/org/wordpress/android/ui/jpfullplugininstall/install/JetpackFullPluginInstallUiStateMapper.kt @@ -6,19 +6,20 @@ import javax.inject.Inject class JetpackFullPluginInstallUiStateMapper @Inject constructor() { fun mapInitial(): UiState.Initial = UiState.Initial( - buttonText = R.string.jetpack_full_plugin_install_initial_button, + buttonText = R.string.jetpack_plugin_install_full_plugin_initial_button, ) fun mapInstalling(): UiState.Installing = UiState.Installing fun mapDone(): UiState.Done = UiState.Done( - buttonText = R.string.jetpack_full_plugin_install_done_button, + descriptionText = R.string.jetpack_plugin_install_full_plugin_done_description, + buttonText = R.string.jetpack_plugin_install_full_plugin_done_button, ) fun mapError(): UiState.Error = UiState.Error( - retryButtonText = R.string.jetpack_full_plugin_install_error_button_retry, - contactSupportButtonText = R.string.jetpack_full_plugin_install_error_button_contact_support, + retryButtonText = R.string.jetpack_plugin_install_error_button_retry, + contactSupportButtonText = R.string.jetpack_plugin_install_error_button_contact_support, ) } diff --git a/WordPress/src/main/java/org/wordpress/android/ui/jpfullplugininstall/install/JetpackFullPluginInstallScreen.kt b/WordPress/src/main/java/org/wordpress/android/ui/jpfullplugininstall/install/JetpackPluginInstallScreen.kt similarity index 84% rename from WordPress/src/main/java/org/wordpress/android/ui/jpfullplugininstall/install/JetpackFullPluginInstallScreen.kt rename to WordPress/src/main/java/org/wordpress/android/ui/jpfullplugininstall/install/JetpackPluginInstallScreen.kt index 66a52814e7c8..738ed7eeb418 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/jpfullplugininstall/install/JetpackFullPluginInstallScreen.kt +++ b/WordPress/src/main/java/org/wordpress/android/ui/jpfullplugininstall/install/JetpackPluginInstallScreen.kt @@ -11,13 +11,13 @@ import org.wordpress.android.ui.jpfullplugininstall.install.compose.state.Initia import org.wordpress.android.ui.jpfullplugininstall.install.compose.state.InstallingState @Composable -fun JetpackFullPluginInstallScreen( +fun JetpackPluginInstallScreen( uiState: UiState, onDismissScreenClick: () -> Unit, - onContinueClick: () -> Unit, - onDoneClick: () -> Unit, - onRetryClick: () -> Unit, - onContactSupportClick: () -> Unit, + onInitialButtonClick: () -> Unit, + onDoneButtonClick: () -> Unit, + onRetryButtonClick: () -> Unit, + onContactSupportButtonClick: () -> Unit, onInitialShown: () -> Unit = {}, onInstallingShown: () -> Unit = {}, onErrorShown: () -> Unit = {}, @@ -36,7 +36,7 @@ fun JetpackFullPluginInstallScreen( is UiState.Initial -> { InitialState( uiState = this, - onContinueClick = onContinueClick, + onContinueClick = onInitialButtonClick, ) onInitialShown() } @@ -51,15 +51,15 @@ fun JetpackFullPluginInstallScreen( is UiState.Done -> { DoneState( uiState = this, - onDoneClick = onDoneClick, + onDoneClick = onDoneButtonClick, ) } is UiState.Error -> { ErrorState( uiState = this, - onRetryClick = onRetryClick, - onContactSupportClick = onContactSupportClick, + onRetryClick = onRetryButtonClick, + onContactSupportClick = onContactSupportButtonClick, ) onErrorShown() } diff --git a/WordPress/src/main/java/org/wordpress/android/ui/jpfullplugininstall/install/UiState.kt b/WordPress/src/main/java/org/wordpress/android/ui/jpfullplugininstall/install/UiState.kt index 9852ae23c283..458d30fb495b 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/jpfullplugininstall/install/UiState.kt +++ b/WordPress/src/main/java/org/wordpress/android/ui/jpfullplugininstall/install/UiState.kt @@ -17,28 +17,29 @@ sealed class UiState( ) : UiState( toolbarTitle = R.string.jetpack, image = R.drawable.ic_jetpack_logo_green_24dp, - imageContentDescription = R.string.jetpack_full_plugin_install_jp_logo_content_description, - title = R.string.jetpack_full_plugin_install_initial_title, - description = R.string.jetpack_full_plugin_install_initial_description, + imageContentDescription = R.string.jetpack_plugin_install_jp_logo_content_description, + title = R.string.jetpack_plugin_install_initial_title, + description = R.string.jetpack_plugin_install_initial_description, ) object Installing : UiState( toolbarTitle = R.string.jetpack, image = R.drawable.ic_jetpack_logo_green_24dp, - imageContentDescription = R.string.jetpack_full_plugin_install_jp_logo_content_description, - title = R.string.jetpack_full_plugin_install_initial_title, - description = R.string.jetpack_full_plugin_install_initial_description, + imageContentDescription = R.string.jetpack_plugin_install_jp_logo_content_description, + title = R.string.jetpack_plugin_install_installing_title, + description = R.string.jetpack_plugin_install_installing_description, showCloseButton = false, ) data class Done( + @StringRes val descriptionText: Int, @StringRes val buttonText: Int, ) : UiState( toolbarTitle = R.string.jetpack, image = R.drawable.ic_jetpack_logo_green_24dp, - imageContentDescription = R.string.jetpack_full_plugin_install_jp_logo_content_description, - title = R.string.jetpack_full_plugin_install_done_title, - description = R.string.jetpack_full_plugin_install_done_description, + imageContentDescription = R.string.jetpack_plugin_install_jp_logo_content_description, + title = R.string.jetpack_plugin_install_done_title, + description = descriptionText, showCloseButton = false, ) @@ -48,8 +49,8 @@ sealed class UiState( ) : UiState( toolbarTitle = R.string.jetpack, image = R.drawable.ic_warning, - imageContentDescription = R.string.jetpack_full_plugin_install_error_image_content_description, - title = R.string.jetpack_full_plugin_install_error_title, - description = R.string.jetpack_full_plugin_install_error_description, + imageContentDescription = R.string.jetpack_plugin_install_error_image_content_description, + title = R.string.jetpack_plugin_install_error_title, + description = R.string.jetpack_plugin_install_error_description, ) } diff --git a/WordPress/src/main/java/org/wordpress/android/ui/jpfullplugininstall/install/compose/state/DoneState.kt b/WordPress/src/main/java/org/wordpress/android/ui/jpfullplugininstall/install/compose/state/DoneState.kt index 92c0299e6c7a..a1d9659144fa 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/jpfullplugininstall/install/compose/state/DoneState.kt +++ b/WordPress/src/main/java/org/wordpress/android/ui/jpfullplugininstall/install/compose/state/DoneState.kt @@ -35,7 +35,8 @@ fun DoneState( private fun PreviewDoneState() { AppTheme { val uiState = UiState.Done( - buttonText = R.string.jetpack_full_plugin_install_done_button, + descriptionText = R.string.jetpack_plugin_install_full_plugin_done_description, + buttonText = R.string.jetpack_plugin_install_full_plugin_done_button, ) DoneState(uiState, {}) } diff --git a/WordPress/src/main/java/org/wordpress/android/ui/jpfullplugininstall/install/compose/state/ErrorState.kt b/WordPress/src/main/java/org/wordpress/android/ui/jpfullplugininstall/install/compose/state/ErrorState.kt index 79ef4b89016d..3a8f33394804 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/jpfullplugininstall/install/compose/state/ErrorState.kt +++ b/WordPress/src/main/java/org/wordpress/android/ui/jpfullplugininstall/install/compose/state/ErrorState.kt @@ -48,8 +48,8 @@ fun ErrorState( private fun PreviewErrorState() { AppTheme { val uiState = UiState.Error( - retryButtonText = R.string.jetpack_full_plugin_install_error_button_retry, - contactSupportButtonText = R.string.jetpack_full_plugin_install_error_button_contact_support, + retryButtonText = R.string.jetpack_plugin_install_error_button_retry, + contactSupportButtonText = R.string.jetpack_plugin_install_error_button_contact_support, ) ErrorState(uiState, {}, {}) } diff --git a/WordPress/src/main/java/org/wordpress/android/ui/jpfullplugininstall/install/compose/state/InitialState.kt b/WordPress/src/main/java/org/wordpress/android/ui/jpfullplugininstall/install/compose/state/InitialState.kt index f73aaf32ceca..6ec463139e75 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/jpfullplugininstall/install/compose/state/InitialState.kt +++ b/WordPress/src/main/java/org/wordpress/android/ui/jpfullplugininstall/install/compose/state/InitialState.kt @@ -35,7 +35,7 @@ fun InitialState( private fun PreviewInitialState() { AppTheme { val uiState = UiState.Initial( - buttonText = R.string.jetpack_full_plugin_install_initial_button, + buttonText = R.string.jetpack_plugin_install_full_plugin_initial_button, ) InitialState(uiState, {}) } diff --git a/WordPress/src/main/res/layout/jetpack_remote_install_activity.xml b/WordPress/src/main/res/layout/jetpack_remote_install_activity.xml deleted file mode 100644 index 1b1851cd152d..000000000000 --- a/WordPress/src/main/res/layout/jetpack_remote_install_activity.xml +++ /dev/null @@ -1,16 +0,0 @@ - - - - - - - - diff --git a/WordPress/src/main/res/layout/jetpack_remote_install_fragment.xml b/WordPress/src/main/res/layout/jetpack_remote_install_fragment.xml deleted file mode 100644 index bad5e74ce1a0..000000000000 --- a/WordPress/src/main/res/layout/jetpack_remote_install_fragment.xml +++ /dev/null @@ -1,67 +0,0 @@ - - - - - - - - - - - - - - - - - - - diff --git a/WordPress/src/main/res/values-ar/strings.xml b/WordPress/src/main/res/values-ar/strings.xml index 058977079c6a..5e85828c8cf9 100644 --- a/WordPress/src/main/res/values-ar/strings.xml +++ b/WordPress/src/main/res/values-ar/strings.xml @@ -1831,7 +1831,7 @@ Language: ar اجتماعي إحصاءات الموقع السنوية تسجيل نطاق - والآن بعد تثبيت Jetpack، ما علينا سوى مساعدتك على الإعداد. لن يستغرق هذا إلا دقيقة. + والآن بعد تثبيت Jetpack، ما علينا سوى مساعدتك على الإعداد. لن يستغرق هذا إلا دقيقة. تعذّر تحميل اقتراحات النطاق كتابة كلمة مفتاحية للحصول على مزيد من الأفكار لم يتم العثور على أي اقتراحات @@ -2111,7 +2111,7 @@ Language: ar يتعذر تنصيب Jetpack في الوقت الحالي. تنصيب Jetpack على موقعك. قد يستغرق هذا الأمر وقتًا يصل إلى بضع دقائق لاكتماله. لن يتم تخزين بيانات اعتمادك وستُستخدم فقط بغرض تنصيب Jetpack. - الإعداد + الإعداد لاستخدام الإحصاءات على موقع ووردبريس الخاص بك، سيتعين عليك تنصيب إضافة Jetpack. لا توجد سمات مطابقة لبحثك ما الذي ترغب في إيجاده؟ diff --git a/WordPress/src/main/res/values-cs/strings.xml b/WordPress/src/main/res/values-cs/strings.xml index 0a46ed1f7225..163fdb8a0d15 100644 --- a/WordPress/src/main/res/values-cs/strings.xml +++ b/WordPress/src/main/res/values-cs/strings.xml @@ -1777,7 +1777,7 @@ Language: cs_CZ Nahrávám koncept Koncepty Při obnovování příspěvku došlo k chybě - Nyní, když je nainstalován Jetpack, musíme vás ho nechat nastavit. Bude to trvat jen minutu. + Nyní, když je nainstalován Jetpack, musíme vás ho nechat nastavit. Bude to trvat jen minutu. Registrovat doménu Nebyly nalezeny žádné návrhy Napište klíčové slovo pro více nápadů @@ -2055,7 +2055,7 @@ Language: cs_CZ Jetpack FAQ Instalovat Jetpack Odpověď - Pokračovat + Pokračovat Instalování Jetpacku Vyskytl se problém Jetpack nainstalován diff --git a/WordPress/src/main/res/values-de/strings.xml b/WordPress/src/main/res/values-de/strings.xml index 04cbf0b29d64..47b2c89bbd14 100644 --- a/WordPress/src/main/res/values-de/strings.xml +++ b/WordPress/src/main/res/values-de/strings.xml @@ -1841,7 +1841,7 @@ Language: de Gib ein Stichwort ein, um weitere Ideen zu erhalten Keine Vorschläge gefunden Domain registrieren - Jetpack ist installiert. Jetzt müssen wir nur noch die Einrichtung abschließen. Dies dauert nur eine Minute. + Jetpack ist installiert. Jetzt müssen wir nur noch die Einrichtung abschließen. Dies dauert nur eine Minute. Aus Einsichten entfernen Nach unten verschieben Nach oben verschieben @@ -2117,7 +2117,7 @@ Language: de Jetpack installieren Jetpack Häufige Fragen zu Jetpack - Einrichten + Einrichten Wenn du Statistiken zu deiner WordPress-Website erhalten möchtest, musst du das Jetpack-Plugin installieren. Keine Themes entsprechen deiner Suche Was möchtest du finden? diff --git a/WordPress/src/main/res/values-en-rAU/strings.xml b/WordPress/src/main/res/values-en-rAU/strings.xml index cd1274341d97..f8260692780c 100644 --- a/WordPress/src/main/res/values-en-rAU/strings.xml +++ b/WordPress/src/main/res/values-en-rAU/strings.xml @@ -206,7 +206,7 @@ Language: en_AU Social Annual Site Stats Register Domain - Now that Jetpack is installed, we just need to get you set up. This will only take a minute. + Now that Jetpack is installed, we just need to get you set up. This will only take a minute. Domain suggestions couldn\'t be loaded Type a keyword for more ideas No suggestions found @@ -464,7 +464,7 @@ Language: en_AU Installing Jetpack Install Jetpack Your website credentials will not be stored and are used only for the purpose of installing Jetpack. - Set up + Set up Jetpack could not be installed at this time. Installing Jetpack on your site. This can take up to a few minutes to complete. To use Stats on your WordPress site, you\'ll need to install the Jetpack plugin. diff --git a/WordPress/src/main/res/values-en-rCA/strings.xml b/WordPress/src/main/res/values-en-rCA/strings.xml index 4c186dab3a85..94b0ffbdde46 100644 --- a/WordPress/src/main/res/values-en-rCA/strings.xml +++ b/WordPress/src/main/res/values-en-rCA/strings.xml @@ -1780,10 +1780,10 @@ Language: en_CA Social Annual Site Stats Register Domain - Now that Jetpack is installed, we just need to get you set up. This will only take a minute. Domain suggestions couldn\'t be loaded Type a keyword for more ideas No suggestions found + Now that Jetpack is installed, we just need to get you set up. This will only take a minute. Follower Totals Remove from insights Move down @@ -2051,13 +2051,13 @@ Language: en_CA Add topics here to find posts about your favourite topics Log in to the WordPress.com account you used to connect Jetpack. Retry + Set up There was a problem Jetpack installed Installing Jetpack Install Jetpack Jetpack Jetpack FAQ - Set up Jetpack could not be installed at this time. Installing Jetpack on your site. This can take up to a few minutes to complete. Your website credentials will not be stored and are used only for the purpose of installing Jetpack. diff --git a/WordPress/src/main/res/values-en-rGB/strings.xml b/WordPress/src/main/res/values-en-rGB/strings.xml index d1c8a18d73c1..6fb84f47e71f 100644 --- a/WordPress/src/main/res/values-en-rGB/strings.xml +++ b/WordPress/src/main/res/values-en-rGB/strings.xml @@ -1783,7 +1783,7 @@ Language: en_GB Type a keyword for more ideas No suggestions found Register Domain - Now that Jetpack is installed, we just need to get you set up. This will only take a minute. + Now that Jetpack is installed, we just need to get you set up. This will only take a minute. Follower totals Remove from insights Move down @@ -2057,7 +2057,7 @@ Language: en_GB Log in to the WordPress.com account you used to connect Jetpack. Retry There was a problem - Set up + Set up Jetpack could not be installed at this time. Installing Jetpack on your site. This can take up to a few minutes to complete. Your website credentials will not be stored and are used only for the purpose of installing Jetpack. diff --git a/WordPress/src/main/res/values-es-rCO/strings.xml b/WordPress/src/main/res/values-es-rCO/strings.xml index b1ad057f878e..9599419489e6 100644 --- a/WordPress/src/main/res/values-es-rCO/strings.xml +++ b/WordPress/src/main/res/values-es-rCO/strings.xml @@ -1635,7 +1635,7 @@ Language: es_CO Teclea una palabra clave para más ideas No se han encontrado sugerencias Registrar dominio - Ahora que está instalado Jetpack, solo necesitamos que lo configures. Esto solo te llevará un minuto. + Ahora que está instalado Jetpack, solo necesitamos que lo configures. Esto solo te llevará un minuto. Quitar de los detalles Mover abajo Mover arriba @@ -1899,7 +1899,7 @@ Language: es_CO Añade aquí temas para descubrir entradas sobre tus temáticas favoritas Accede a la cuenta de WordPress.com que usaste para conectar Jetpack. Reintentar - Configurar + Configurar Jetpack no se pudo instalar en este momento. Hubo un problema Jetpack instalado diff --git a/WordPress/src/main/res/values-es-rMX/strings.xml b/WordPress/src/main/res/values-es-rMX/strings.xml index 38651caba3c6..d1ab3e5d548a 100644 --- a/WordPress/src/main/res/values-es-rMX/strings.xml +++ b/WordPress/src/main/res/values-es-rMX/strings.xml @@ -869,7 +869,7 @@ Language: es_MX Estadísticas anuales del sitio Seguidores totales Registrar dominio - Ahora que está instalado Jetpack, solo necesitamos que lo configures. Esto solo te llevará un minuto. + Ahora que está instalado Jetpack, solo necesitamos que lo configures. Esto solo te llevará un minuto. Mover abajo Mover arriba Ajustes de los parámetros de las estadísticas @@ -1127,7 +1127,7 @@ Language: es_MX Instala Jetpack Jetpack FAQ de Jetpack - Configurar + Configurar Jetpack no se pudo instalar en este momento. Instalando Jetpack en tu sitio. Esto puede llevar unos minutos completarse. Las credenciales de tu web no se almacenarán, y solo se utilizan para instalar Jetpack. diff --git a/WordPress/src/main/res/values-es-rVE/strings.xml b/WordPress/src/main/res/values-es-rVE/strings.xml index 8451d2238bae..8e9ff32f506a 100644 --- a/WordPress/src/main/res/values-es-rVE/strings.xml +++ b/WordPress/src/main/res/values-es-rVE/strings.xml @@ -1655,7 +1655,7 @@ Language: es_VE Teclea una palabra clave para más ideas No se han encontrado sugerencias Registrar dominio - Ahora que está instalado Jetpack, solo necesitamos que lo configures. Esto solo te llevará un minuto. + Ahora que está instalado Jetpack, solo necesitamos que lo configures. Esto solo te llevará un minuto. Quitar de los detalles Mover abajo Mover arriba @@ -1919,7 +1919,7 @@ Language: es_VE Añade aquí temas para descubrir entradas sobre tus temáticas favoritas Accede a la cuenta de WordPress.com que usaste para conectar Jetpack. Reintentar - Configurar + Configurar Jetpack no se pudo instalar en este momento. Hubo un problema Jetpack instalado diff --git a/WordPress/src/main/res/values-es/strings.xml b/WordPress/src/main/res/values-es/strings.xml index 8ab339c95294..1ec7f5ac54fd 100644 --- a/WordPress/src/main/res/values-es/strings.xml +++ b/WordPress/src/main/res/values-es/strings.xml @@ -1833,12 +1833,12 @@ Language: es Solo ves las estadísticas más relevantes. Añade y organiza tus detalles abajo. Social Estadísticas anuales del sitio - Seguidores totales No se pudieron cargar las sugerencias de dominios + Seguidores totales Teclea una palabra clave para más ideas No se han encontrado sugerencias Registrar dominio - Ahora que está instalado Jetpack, solo necesitamos que lo configures. Esto solo te llevará un minuto. + Ahora que está instalado Jetpack, solo necesitamos que lo configures. Esto solo te llevará un minuto. Quitar de los detalles Mover abajo Mover arriba @@ -2105,7 +2105,7 @@ Language: es Añade aquí temas para descubrir entradas sobre tus temáticas favoritas Accede a la cuenta de WordPress.com que usaste para conectar Jetpack. Reintentar - Configurar + Configurar Jetpack no se pudo instalar en este momento. Hubo un problema Jetpack instalado diff --git a/WordPress/src/main/res/values-fr-rCA/strings.xml b/WordPress/src/main/res/values-fr-rCA/strings.xml index 7d9ad9e7e76d..0974fbeb834f 100644 --- a/WordPress/src/main/res/values-fr-rCA/strings.xml +++ b/WordPress/src/main/res/values-fr-rCA/strings.xml @@ -1824,7 +1824,7 @@ Language: fr Statistiques annuelles du site Impossible de charger les suggestions de domaine Enregistrer un domaine - Maintenant que Jetpack est installé, vous devez procéder à quelques réglages. Cela ne prendra qu\'une minute. + Maintenant que Jetpack est installé, vous devez procéder à quelques réglages. Cela ne prendra qu\'une minute. Saisissez un mot-clé pour obtenir davantage d\'idées Aucune suggestion n’a été trouvée Totaux des abonnés @@ -2100,7 +2100,7 @@ Language: fr Installer Jetpack Jetpack FAQ Jetpack - Configurer + Configurer Impossible d\'installer Jetpack pour le moment. Installation de Jetpack en cours sur votre site. Cette opération peut prendre quelques minutes. Vos informations d\'identification sur le site Web ne seront pas conservées. Elles sont utilisées uniquement pour installer Jetpack. diff --git a/WordPress/src/main/res/values-fr/strings.xml b/WordPress/src/main/res/values-fr/strings.xml index 7d9ad9e7e76d..0974fbeb834f 100644 --- a/WordPress/src/main/res/values-fr/strings.xml +++ b/WordPress/src/main/res/values-fr/strings.xml @@ -1824,7 +1824,7 @@ Language: fr Statistiques annuelles du site Impossible de charger les suggestions de domaine Enregistrer un domaine - Maintenant que Jetpack est installé, vous devez procéder à quelques réglages. Cela ne prendra qu\'une minute. + Maintenant que Jetpack est installé, vous devez procéder à quelques réglages. Cela ne prendra qu\'une minute. Saisissez un mot-clé pour obtenir davantage d\'idées Aucune suggestion n’a été trouvée Totaux des abonnés @@ -2100,7 +2100,7 @@ Language: fr Installer Jetpack Jetpack FAQ Jetpack - Configurer + Configurer Impossible d\'installer Jetpack pour le moment. Installation de Jetpack en cours sur votre site. Cette opération peut prendre quelques minutes. Vos informations d\'identification sur le site Web ne seront pas conservées. Elles sont utilisées uniquement pour installer Jetpack. diff --git a/WordPress/src/main/res/values-gl/strings.xml b/WordPress/src/main/res/values-gl/strings.xml index 0d5de1191ddc..6ddcc284b1e2 100644 --- a/WordPress/src/main/res/values-gl/strings.xml +++ b/WordPress/src/main/res/values-gl/strings.xml @@ -11,19 +11,19 @@ Language: gl_ES Pechar Contactar con soporte Termos e condicións - Contactar con soporte - Reintentar - Jetpack non se puido instalar neste momento. - Houbo un problema - Icona de erro - Feito - Jetpack instalado - Instalando Jetpack no teu sitio. Isto pode levar uns minutos completarse. - Instalando Jetpack - Continuar - As credenciais da túa web non se almacenarán, e só se utilizan para instalar Jetpack. - Instala Jetpack - Icona de Jetpack + Contactar con soporte + Reintentar + Jetpack non se puido instalar neste momento. + Houbo un problema + Icona de erro + Feito + Jetpack instalado + Instalando Jetpack no teu sitio. Isto pode levar uns minutos completarse. + Instalando Jetpack + Continuar + As credenciais da túa web non se almacenarán, e só se utilizan para instalar Jetpack. + Instala Jetpack + Icona de Jetpack Promocionar con Blaze Libera todo o potencial do teu sitio. Obtén estatísticas, notificacións e máis con Jetpack. O teu sitio ten o plugin de Jetpack @@ -1826,7 +1826,7 @@ Language: gl_ES Teclea unha palabra clave para máis ideas Non se encontraron suxerencias Rexistrar dominio - Agora que está instalado Jetpack, só necesitamos que o configures. Isto só che levará un minuto. + Agora que está instalado Jetpack, só necesitamos que o configures. Isto só che levará un minuto. Quitar dos detalles Mover abaixo Mover arriba @@ -2093,7 +2093,7 @@ Language: gl_ES Engade aquí temas para descubrir entradas sobre as túas temáticas favoritas Accede á conta de WordPress.com que usaches para conectar con Jetpack. Reintentar - Configurar + Configurar Jetpack non se puido instalar neste momento. Houbo un problema Jetpack instalado diff --git a/WordPress/src/main/res/values-he/strings.xml b/WordPress/src/main/res/values-he/strings.xml index 55c021e0235a..2a89dc53a028 100644 --- a/WordPress/src/main/res/values-he/strings.xml +++ b/WordPress/src/main/res/values-he/strings.xml @@ -1837,7 +1837,7 @@ Language: he_IL יש להקליד מילת מפתח לרעיונות נוספים לא נמצאו הצעות רישום דומיין - כעת, לאחר ההתקנה של Jetpack, צריך להגדיר את החשבון. התהליך יארך כדקה. + כעת, לאחר ההתקנה של Jetpack, צריך להגדיר את החשבון. התהליך יארך כדקה. הסרה מהתובנות העברה למטה העברה למעלה @@ -2104,7 +2104,7 @@ Language: he_IL אפשר להוסיף כאן נושאים כדי למצוא פוסטים על הנושאים המועדפים עליך יש להיכנס לחשבון WordPress.com שדרכו חיברת את Jetpack. יש לנסות שנית - הגדר + הגדר אין אפשרות להתקין את Jetpack כעת. הייתה בעיה Jetpack מותקן diff --git a/WordPress/src/main/res/values-id/strings.xml b/WordPress/src/main/res/values-id/strings.xml index a76057be19fb..1e2d7bd2ea93 100644 --- a/WordPress/src/main/res/values-id/strings.xml +++ b/WordPress/src/main/res/values-id/strings.xml @@ -26,7 +26,7 @@ Language: id Coba lagi Jetpack tidak dapat diinstal untuk saat ini. Terjadi kendala - Ikon eror + Ikon eror Selesai Situs ini siap digunakan dengan aplikasi. Jetpack sudah diinstal @@ -1838,7 +1838,7 @@ Language: id Ketikkan kata kunci untuk mendapatkan lebih banyak ide Saran tidak ditemukan Daftarkan Domain - Sekarang Jetpack telah terinstal, kami hanya perlu Anda menyiapkannya. Ini hanya memerlukan waktu satu menit. + Sekarang Jetpack telah terinstal, kami hanya perlu Anda menyiapkannya. Ini hanya memerlukan waktu satu menit. Hapus dari wawasan Geser bawah Geser atas @@ -2105,7 +2105,7 @@ Language: id Tambahkan topik di sini untuk menemukan pos tentang topik favorit Anda. Login ke akun WordPress.com yang Anda gunakan untuk menghubungkan Jetpack. Coba lagi - Siapkan + Siapkan Jetpack tidak dapat diinstal untuk saat ini. Ada masalah Jetpack sudah diinstal diff --git a/WordPress/src/main/res/values-it/strings.xml b/WordPress/src/main/res/values-it/strings.xml index 8b38140a3fca..586b433f26c8 100644 --- a/WordPress/src/main/res/values-it/strings.xml +++ b/WordPress/src/main/res/values-it/strings.xml @@ -1837,7 +1837,7 @@ Language: it Digita una parola chiave per ulteriori idee Nessun suggerimento trovato Registra dominio - Ora che Jetpack è installato, manca solo la configurazione. Ci vorrà soltanto un minuto. + Ora che Jetpack è installato, manca solo la configurazione. Ci vorrà soltanto un minuto. Rimuovi da Panoramica Sposta in basso Sposta in alto @@ -2104,7 +2104,7 @@ Language: it Aggiungi qui gli argomenti per trovare gli articoli con i tuoi temi preferiti Accedi all\'account WordPress.com che hai utilizzato per connettere Jetpack. Riprova - Continua + Continua Jetpack non può essere installato in questo momento Si è verificato un problema Jetpack installato diff --git a/WordPress/src/main/res/values-ja/strings.xml b/WordPress/src/main/res/values-ja/strings.xml index 10cfba2a9b02..ebc9d732dbcb 100644 --- a/WordPress/src/main/res/values-ja/strings.xml +++ b/WordPress/src/main/res/values-ja/strings.xml @@ -1837,7 +1837,7 @@ Language: ja_JP その他のアイデアについてはキーワードを入力します 提案が見つかりません ドメインを登録 - Jetpack がインストールされたので、あとはセットアップするだけです。ほんの1分ほどで済みます。 + Jetpack がインストールされたので、あとはセットアップするだけです。ほんの1分ほどで済みます。 統計概要から削除 下に移動 上に移動 @@ -2110,7 +2110,7 @@ Language: ja_JP Jetpack をインストール Jetpack Jetpack よくある質問 - 設定 + 設定 Jetpack は現在インストールできません。 サイトに Jetpack をインストールしています。完了まで数分かかることがあります。 サイトのログイン情報は保存されず、Jetpack インストールのためのみに使用されます。 diff --git a/WordPress/src/main/res/values-kmr/strings.xml b/WordPress/src/main/res/values-kmr/strings.xml index 26eea8efbb15..8cf12b9ca650 100644 --- a/WordPress/src/main/res/values-kmr/strings.xml +++ b/WordPress/src/main/res/values-kmr/strings.xml @@ -795,7 +795,7 @@ Language: ku_TR Pêşniyarên navperê(domain) nehatin barkirin Ji bo fikrên zêdetir, peyvkilîdekê binivîse Domain\'ê Tomar Bike - Va ye Jetpack hate sazkirin, îja divê em sazkariyên te temam bikin. Ev ê tenê xulekekê bigire. + Va ye Jetpack hate sazkirin, îja divê em sazkariyên te temam bikin. Ev ê tenê xulekekê bigire. Şandî hat vegerandin Şandî tê vegerandin Şandî tê jêbirin @@ -1046,7 +1046,7 @@ Language: ku_TR Mijarên şopandî tune ye Ji bo ku tu şandiyên têkildarî mijarên xwe yên favorî bibinî, mijaran tevlî vir bike Dîsa Biceribîne - Bidomîne + Bidomîne Pirsgirêkek hebû Jetpack tê sazkirin Jetpack diff --git a/WordPress/src/main/res/values-ko/strings.xml b/WordPress/src/main/res/values-ko/strings.xml index ff95173f4b22..2cbde4910daa 100644 --- a/WordPress/src/main/res/values-ko/strings.xml +++ b/WordPress/src/main/res/values-ko/strings.xml @@ -1834,7 +1834,7 @@ Language: ko_KR 추가 아이디어에 대한 키워드 입력 제안을 찾을 수 없음 도메인 등록 - 젯팩 설치되었으므로 설정해야 합니다. 이 작업은 1분 정도 소요됩니다. + 젯팩 설치되었으므로 설정해야 합니다. 이 작업은 1분 정도 소요됩니다. 인사이트에서 제거 아래로 이동 위로 이동 @@ -2108,7 +2108,7 @@ Language: ko_KR 젯팩 설치 젯팩 젯팩 자주 찾는 질문 - 설정 + 설정 지금은 젯팩을 설치할 수 없습니다 사이트에 젯팩을 설치하는 중입니다. 완료하는 데 몇 분 정도 걸릴 수 있습니다. 워드프레스 사이트에서 통계를 사용하려면 젯팩 플러그인을 설치해야 합니다. diff --git a/WordPress/src/main/res/values-lv/strings.xml b/WordPress/src/main/res/values-lv/strings.xml index cb81ede78fa5..2a3836f13a72 100644 --- a/WordPress/src/main/res/values-lv/strings.xml +++ b/WordPress/src/main/res/values-lv/strings.xml @@ -1800,7 +1800,7 @@ Language: lv Ierakstiet atslēgvārdu, lai iegūtu vairāk ideju Ieteikumi netika atrasti Reģistrēt domēnu - Tagad, kad Jetpack ir instalēts, mums ir jāveic iestatīšana. Tas prasīs tikai minūti. + Tagad, kad Jetpack ir instalēts, mums ir jāveic iestatīšana. Tas prasīs tikai minūti. Noņemt no ieskatiem Pārvietojieties uz leju Pārvietojieties uz augšu @@ -2067,7 +2067,7 @@ Language: lv Pievienojiet tematus šeit, lai atrastu ziņas par iecienītākajām tēmām Piesakieties WordPress.com kontā, kuru izmantojāt, lai izveidotu savienojumu ar Jetpack. Mēģiniet vēlreiz - Uzstādīt + Uzstādīt Jetpack pašlaik nebija iespējams instalēt. Radās problēma Jetpack uzstādīts diff --git a/WordPress/src/main/res/values-nb/strings.xml b/WordPress/src/main/res/values-nb/strings.xml index 256989dd3db1..5d77a553fbca 100644 --- a/WordPress/src/main/res/values-nb/strings.xml +++ b/WordPress/src/main/res/values-nb/strings.xml @@ -975,7 +975,7 @@ Language: nb_NO Skriv inn et nøkkelord for flere detaljer Ingen forslag funnet Registrer domene - Nå som Jetpack er installert trenger vi bare å få satt deg opp. Dette vil bare ta et minutt. + Nå som Jetpack er installert trenger vi bare å få satt deg opp. Dette vil bare ta et minutt. Fjern fra innsikter Flytt ned Flytt opp @@ -1238,7 +1238,7 @@ Language: nb_NO Legg til emner for å finne innlegg om dine favoritt-emner Logg inn på dem WordPres.com-kontoen du brukte til koble til Jetpack. Prøv på nytt - Sett opp + Sett opp Jetpack kunne ikke installeres nå. Det oppsto et problem Jetpack installert diff --git a/WordPress/src/main/res/values-nl/strings.xml b/WordPress/src/main/res/values-nl/strings.xml index 261f0ad768d6..f41d8c69599c 100644 --- a/WordPress/src/main/res/values-nl/strings.xml +++ b/WordPress/src/main/res/values-nl/strings.xml @@ -1805,7 +1805,7 @@ Language: nl Type een trefwoord voor meer ideeën Geen suggesties gevonden Registreer domein - Nu Jetpack is geïnstalleerd, hoeven we er alleen nog voor te zorgen dat alles goed ingesteld is. Dit duurt maar heel even. + Nu Jetpack is geïnstalleerd, hoeven we er alleen nog voor te zorgen dat alles goed ingesteld is. Dit duurt maar heel even. Verwijderen uit inzichten Omlaag verplaatsen Omhoog verplaatsen @@ -2072,7 +2072,7 @@ Language: nl Voeg hier onderwerpen toe om berichten te vinden over je favoriete onderwerpen Log in op het WordPress.com-account dat je gebruikte om verbinding te maken met Jetpack. Opnieuw proberen - Instellen + Instellen Jetpack kan momenteel niet geïnstalleerd worden. Er is een probleem opgetreden Jetpack geïnstalleerd diff --git a/WordPress/src/main/res/values-pl/strings.xml b/WordPress/src/main/res/values-pl/strings.xml index 91df4d05b24e..f754b449a9d6 100644 --- a/WordPress/src/main/res/values-pl/strings.xml +++ b/WordPress/src/main/res/values-pl/strings.xml @@ -1504,7 +1504,7 @@ Language: pl Suma obserwujących Datowany wstecznie dla: %s Zarejestruj domenę - Jetpack jest już zainstalowany, czas go skonfigurować. Zajmie to chwilę. + Jetpack jest już zainstalowany, czas go skonfigurować. Zajmie to chwilę. Nie można było wczytać sugestii dla nazwy domeny Wpisz słowo kluczowe aby uzyskać więcej pomysłów Nie znaleziono sugestii @@ -1785,7 +1785,7 @@ Language: pl Instalowanie Jetpacka na twojej witrynie. To może zająć do kilku minut. Spróbuj ponownie Najczęściej zadawane pytania Jetpacka - Skonfiguruj + Skonfiguruj Aby korzystać ze statystyk na swojej witrynie, musisz zainstalować wtyczkę Jetpack. Brak motywów spełniających kryteria wyszukiwania Co chciał(a)byś wyszukać? diff --git a/WordPress/src/main/res/values-pt-rBR/strings.xml b/WordPress/src/main/res/values-pt-rBR/strings.xml index 6ba153d2ea09..71fa4d8cb924 100644 --- a/WordPress/src/main/res/values-pt-rBR/strings.xml +++ b/WordPress/src/main/res/values-pt-rBR/strings.xml @@ -1784,7 +1784,7 @@ Language: pt_BR Digite uma palavra-chave para mais ideias Nenhuma sugestão encontrada Registrar domínio - Agora que o Jetpack está instalado, só precisamos configurá-lo. Isso levará apenas um minuto. + Agora que o Jetpack está instalado, só precisamos configurá-lo. Isso levará apenas um minuto. Remover do resumo Mover para baixo Mover para cima @@ -2051,7 +2051,7 @@ Language: pt_BR Adicione tópicos aqui para encontrar posts sobre seus assuntos favoritos Acesse a conta do WordPress.com usada para conectar o Jetpack. Tentar novamente - Continuar a configuração + Continuar a configuração Não foi possível instalar o Jetpack no momento. Houve um problema Jetpack instalado diff --git a/WordPress/src/main/res/values-ro/strings.xml b/WordPress/src/main/res/values-ro/strings.xml index 82ddfd1dd559..dfaaf539eeeb 100644 --- a/WordPress/src/main/res/values-ro/strings.xml +++ b/WordPress/src/main/res/values-ro/strings.xml @@ -39,24 +39,24 @@ Language: ro modulul %1$s module individuale Jetpack modulul complet Jetpack - Icon eroare - A fost o problemă - Jetpack nu a putut fi instalat în acest moment. - Reîncearcă - Contactează suportul + Icon eroare + A fost o problemă + Jetpack nu a putut fi instalat în acest moment. + Reîncearcă + Contactează suportul Acest site folosește un modul individual, care încă nu suportă toate funcționalitățile aplicației. Te rog instalează modulul complet Jetpack. Este disponibil un singur site, așadar nu poți modifica site-ul principal. Te rog instalează modulul complet Jetpack Promovează cu Blaze - Icon Jetpack - Instalează Jetpack - Datele de conectare ale site-ului tău web nu vor fi stocate și sunt folosite numai în scopul de a instala Jetpack. - Continuă - Instalez Jetpack - Instalez Jetpack pe site-ul tău. Poate dura câteva minute până la finalizare. - Jetpack a fost instalat - Gata pentru a folosi acest site în aplicație. - Gata + Icon Jetpack + Instalează Jetpack + Datele de conectare ale site-ului tău web nu vor fi stocate și sunt folosite numai în scopul de a instala Jetpack. + Continuă + Instalez Jetpack + Instalez Jetpack pe site-ul tău. Poate dura câteva minute până la finalizare. + Jetpack a fost instalat + Gata pentru a folosi acest site în aplicație. + Gata Deblochează întregul potențial al site-ului tău. Cu Jetpack, ai statistici, notificări și multe altele. Urmărești creșterea traficului cu informații generale utile și statistici comprehensive. Găsește, urmărește site-urile și comunitățile preferate și partajează conținutul tău. @@ -1849,7 +1849,7 @@ Language: ro Încarc ciorna Ciorne A apărut o eroare la restaurarea articolului - Acum, după ce ai instalat Jetpack, trebuie doar să te pregătim pentru inițializare. Nu va dura decât un minut. + Acum, după ce ai instalat Jetpack, trebuie doar să te pregătim pentru inițializare. Nu va dura decât un minut. Înregistrează domeniul Nicio sugestie găsită Introdu un cuvânt cheie pentru mai multe idei @@ -2131,7 +2131,7 @@ Language: ro A fost o problemă Reîncearcă Autentifică-te în contul WordPress.com pe care l-ai folosit pentru a conecta Jetpack. - Inițializează + Inițializează Jetpack nu a putut fi instalat în acest moment. Instalez Jetpack pe site-ul tău. Poate dura câteva minute până la finalizare. Datele de conectare ale site-ului tău web nu vor fi stocate și vor fi folosite numai pentru instalarea Jetpack. diff --git a/WordPress/src/main/res/values-ru/strings.xml b/WordPress/src/main/res/values-ru/strings.xml index 0eb34aa7148a..083a0f2db933 100644 --- a/WordPress/src/main/res/values-ru/strings.xml +++ b/WordPress/src/main/res/values-ru/strings.xml @@ -1838,7 +1838,7 @@ Language: ru Напишите ключевое слово для получения предложений Нет предложений Зарегистрировать домен - Теперь, когда Jetpack установлен, нам нужно настроить, это займет всего минуту. + Теперь, когда Jetpack установлен, нам нужно настроить, это займет всего минуту. Удалить с вкладки Вниз Вверх @@ -2105,7 +2105,7 @@ Language: ru Добавьте любимые темы здесь, чтобы найти по ним записи Войдите в учетную запись WordPress.com, с которой был подключен Jetpack. Повторить - Продолжить установку + Продолжить установку Сейчас Jetpack не может быть установлен. Возникла проблема Jetpack установлен diff --git a/WordPress/src/main/res/values-sq/strings.xml b/WordPress/src/main/res/values-sq/strings.xml index 88f453d05db0..90eaa7ae6524 100644 --- a/WordPress/src/main/res/values-sq/strings.xml +++ b/WordPress/src/main/res/values-sq/strings.xml @@ -1830,7 +1830,7 @@ Language: sq_AL Për më tepër ide, shtypni një fjalëkyç S’u gjetën sugjerime Regjistroni Përkatësi - Tani që Jetpack-u është instaluar, na duhet vetëm t’ju bëjmë gati. Kjo do të hajë vetëm një minutë. + Tani që Jetpack-u është instaluar, na duhet vetëm t’ju bëjmë gati. Kjo do të hajë vetëm një minutë. Hiqe prej tendencave Ule poshtë Ngjite sipër @@ -2097,7 +2097,7 @@ Language: sq_AL Shtoni këtu tema që të gjeni postime rreth temave tuaja të parapëlqyera Bëni hyrjen te llogaria WordPress.com që përdorët për t’ia përshoqëruar Jetpack-ut. Riprovoni - Ujdise + Ujdise Jetpack-u s’u instalua dot këtë herë. Pati një problem Jetpack-u u instalua diff --git a/WordPress/src/main/res/values-sr/strings.xml b/WordPress/src/main/res/values-sr/strings.xml index 56f2761b23d7..a2c7af3b0ca0 100644 --- a/WordPress/src/main/res/values-sr/strings.xml +++ b/WordPress/src/main/res/values-sr/strings.xml @@ -865,7 +865,7 @@ Language: sr_RS Jetpack није могуће инсталирати у овом тренутку. Jetpack се инсталира на Ваш сајт. Ово може да потраје неколико минута. Пријавите се на WordPress.com налог који сте користили за повезивање Jetpack-а. - Постави + Постави Одјавите се из Вордпреса? Направити ознаку Немате ниједну ознаку diff --git a/WordPress/src/main/res/values-sv/strings.xml b/WordPress/src/main/res/values-sv/strings.xml index b95205e3fb04..aef1824dc4bd 100644 --- a/WordPress/src/main/res/values-sv/strings.xml +++ b/WordPress/src/main/res/values-sv/strings.xml @@ -22,20 +22,20 @@ Language: sv_SE Installera det fullständiga Jetpack-tillägget Endast en webbplats är tillgänglig så du kan inte ändra din primära webbplats. Den här webbplatsen använder ett enskilt tillägg, som inte stöder alla funktioner i appen än. Installera det fullständiga Jetpack-tillägget. - Kontakta supporten - Försök igen - Jetpack kunde inte installeras just nu. - Det var ett problem - Felikon - Klar - Redo att använda denna webbplats med appen. - Jetpack har installerats - Installerar Jetpack på din webbplats. Detta kan ta upp till några minuter att slutföra. - Installerar Jetpack - Fortsätt + Kontakta supporten + Försök igen + Jetpack kunde inte installeras just nu. + Det var ett problem + Felikon + Klar + Redo att använda denna webbplats med appen. + Jetpack har installerats + Installerar Jetpack på din webbplats. Detta kan ta upp till några minuter att slutföra. + Installerar Jetpack + Fortsätt Din webbplats autentiseringsuppgifter används bara för att installera Jetpack säkert och kommer inte att sparas - Installera Jetpack - Jetpack-ikon + Installera Jetpack + Jetpack-ikon Marknadsför med Blaze Lås upp din webbplats fulla potential. Få statistik, aviseringar och mer med Jetpack. Din webbplats har Jetpack-tillägget @@ -1838,7 +1838,7 @@ Language: sv_SE Skriv in ett nyckelord för fler idéer Inga förslag hittades Registrera domän - Nu när Jetpack är installerat behöver vi hjälpa dig igång. Det tar bara någon minut. + Nu när Jetpack är installerat behöver vi hjälpa dig igång. Det tar bara någon minut. Ta bort från Insikter Flytta ned Flytta upp @@ -2105,7 +2105,7 @@ Language: sv_SE Lägg till ämnen här för att hitta inlägg om dina favoritämnen Logga in på WordPress.com-kontot du använde för att ansluta Jetpack. Försök igen - Konfigurera + Konfigurera Jetpack kunde inte installeras just nu. Det var ett problem Jetpack installerat diff --git a/WordPress/src/main/res/values-tr/strings.xml b/WordPress/src/main/res/values-tr/strings.xml index 95c511bb8e45..f68a3a5d2b5f 100644 --- a/WordPress/src/main/res/values-tr/strings.xml +++ b/WordPress/src/main/res/values-tr/strings.xml @@ -42,20 +42,20 @@ Language: tr Lütfen Jetpack eklentisinin tamamını yükleyin Yalnızca bir site kullanılabilir, bu nedenle birincil sitenizi değiştiremezsiniz. Bu site, uygulamanın tüm özelliklerini henüz desteklemeyen ayrı bir eklenti kullanmaktadır. Lütfen Jetpack eklentisinin tamamını kurun. - Destek ile iletişim kur - Yeniden dene - Jetpack şu anda kurulamıyor. - Bir sorun vardı - Hata simgesi - Bitti - Bu siteyi uygulama ile kullanmaya hazır. - Jetpack kuruldu - Sitenize Jetpack kuruluyor. Bu işlemin tamamlanması birkaç dakika sürebilir. - Jetpack kuruluyor - Devam et - Web sitesi kimlik bilgileriniz depolanmayacak ve yalnızca Jetpack\'i kurma amacıyla kullanılacak - Jetpack\'i kur - Jetpack simgesi + Destek ile iletişim kur + Yeniden dene + Jetpack şu anda kurulamıyor. + Bir sorun vardı + Hata simgesi + Bitti + Bu siteyi uygulama ile kullanmaya hazır. + Jetpack kuruldu + Sitenize Jetpack kuruluyor. Bu işlemin tamamlanması birkaç dakika sürebilir. + Jetpack kuruluyor + Devam et + Web sitesi kimlik bilgileriniz depolanmayacak ve yalnızca Jetpack\'i kurma amacıyla kullanılacak + Jetpack\'i kur + Jetpack simgesi Blaze ile Tanıt Sitenizin potansiyelinin tamamını ortaya çıkarın. Jetpack ile istatistikler, bildirimler ve daha fazlasını elde edin. Sitenizde Jetpack eklentisi var @@ -1858,7 +1858,7 @@ Language: tr Daha fazla fikir edinmek için anahtar sözcük girin Hiçir öneri bulunamadı Alan Adını Kaydet - Jetpack yüklendiğine göre artık sadece ayarlarınızı tamamlamanız yeterli. Bu işlem sadece bir dakika sürer. + Jetpack yüklendiğine göre artık sadece ayarlarınızı tamamlamanız yeterli. Bu işlem sadece bir dakika sürer. Tek bakıştan çıkar Aşağı taşı Yukarı taşı @@ -2125,7 +2125,7 @@ Language: tr En sevdiğiniz konularla ilgili yazıları bulmak için buraya konu ekleyin Jetpack\'i bağlamak için kullandığınız WordPress.com hesabına giriş yapın. Tekrar dene - Devam et + Devam et Jetpack şu anda yüklenemedi. Bir sorun vardı Jetpack kuruldu diff --git a/WordPress/src/main/res/values-vi/strings.xml b/WordPress/src/main/res/values-vi/strings.xml index 250a74299f2e..96abe4ad50c1 100644 --- a/WordPress/src/main/res/values-vi/strings.xml +++ b/WordPress/src/main/res/values-vi/strings.xml @@ -1614,7 +1614,7 @@ Language: vi_VN Nhập một từ khóa để có thêm ý tưởng Không có gợi ý Đăng ký tên miền - Đã cài đặt Jetpack, đang thiết lập mọi thứ. Điều này sẽ mất vài phút. + Đã cài đặt Jetpack, đang thiết lập mọi thứ. Điều này sẽ mất vài phút. Xóa khỏi phân tích Chuyển xuống Chuyển lên @@ -1878,7 +1878,7 @@ Language: vi_VN Thêm thẻ ở đây để tìm bài viết liên quan những đề tài mà bạn yêu thích Đăng nhập tài khoản WordPress.com mà bạn có kết nối Jetpack. Thử lại - Cài ngay + Cài ngay Không thể cài đặt Jetpack vào lúc này. Đã xảy ra lỗi Đã cài đặt Jetpack diff --git a/WordPress/src/main/res/values-zh-rCN/strings.xml b/WordPress/src/main/res/values-zh-rCN/strings.xml index f424cb0d415c..c1d00a9b5d9a 100644 --- a/WordPress/src/main/res/values-zh-rCN/strings.xml +++ b/WordPress/src/main/res/values-zh-rCN/strings.xml @@ -1832,7 +1832,7 @@ Language: zh_CN 请输入关键字以获取更多想法 未找到任何建议 注册域 - 安装 Jetpack 后,我们只需进行设置即可。这只需要一分钟时间。 + 安装 Jetpack 后,我们只需进行设置即可。这只需要一分钟时间。 从见解中删除 下移 上移 @@ -2099,7 +2099,7 @@ Language: zh_CN 在此处添加主题,以查找有关您喜爱的主题的博文 登录用于关联 Jetpack 的 WordPress.com 账户。 重试 - 设置 + 设置 目前无法安装 Jetpack。 出现问题 已安装 Jetpack diff --git a/WordPress/src/main/res/values-zh-rHK/strings.xml b/WordPress/src/main/res/values-zh-rHK/strings.xml index 6b8051e75caa..d3d05b65774a 100644 --- a/WordPress/src/main/res/values-zh-rHK/strings.xml +++ b/WordPress/src/main/res/values-zh-rHK/strings.xml @@ -1832,7 +1832,7 @@ Language: zh_TW 社交 年度網站統計 註冊網域 - 現在 Jetpack 已安裝完成,我們只需要協助你完成設定即可。這只需要一分鐘左右。 + 現在 Jetpack 已安裝完成,我們只需要協助你完成設定即可。這只需要一分鐘左右。 追蹤者總數 輸入關鍵字尋找更多想法 無法載入網域建議 @@ -2109,7 +2109,7 @@ Language: zh_TW 安裝 Jetpack Jetpack Jetpack 常見問題 - 設定 + 設定 目前無法安裝 Jetpack。 正在你的網站上安裝 Jetpack。這可能需要幾分鐘才能完成。 我們不會儲存你的網站憑證,而且只會將其用於安裝 Jetpack。 diff --git a/WordPress/src/main/res/values-zh-rTW/strings.xml b/WordPress/src/main/res/values-zh-rTW/strings.xml index a52dd2ba47e7..10da95f8f774 100644 --- a/WordPress/src/main/res/values-zh-rTW/strings.xml +++ b/WordPress/src/main/res/values-zh-rTW/strings.xml @@ -1836,7 +1836,7 @@ Language: zh_TW 輸入關鍵字尋找更多想法 找不到任何建議 註冊網域 - 現在 Jetpack 已安裝完成,我們只需要協助你完成設定即可。這只需要一分鐘左右。 + 現在 Jetpack 已安裝完成,我們只需要協助你完成設定即可。這只需要一分鐘左右。 從洞察報告中移除 向下移動 向上移動 @@ -2103,7 +2103,7 @@ Language: zh_TW 請在此處新增主題,以尋找你最愛的主題文章 請登入你用來連結 Jetpack 的 WordPress.com 帳號。 重試 - 設定 + 設定 目前無法安裝 Jetpack。 發生問題 已安裝 Jetpack diff --git a/WordPress/src/main/res/values/strings.xml b/WordPress/src/main/res/values/strings.xml index 8094389fbb6e..1889d8146cc9 100644 --- a/WordPress/src/main/res/values/strings.xml +++ b/WordPress/src/main/res/values/strings.xml @@ -1072,33 +1072,25 @@ No network available To view your stats, log in to the WordPress.com account. - + Jetpack - Install Jetpack - Your website credentials will not be stored and are used only for the purpose of installing Jetpack. - Installing Jetpack - Installing Jetpack on your site. This can take up to a few minutes to complete. - Jetpack installed - Now that Jetpack is installed, we just need to get you set up. This will only take a minute. - There was a problem - Jetpack could not be installed at this time. - Set up - Retry Log in to the WordPress.com account you used to connect Jetpack. - - - Jetpack icon - Install Jetpack - Your website credentials will not be stored and are used only for the purpose of installing Jetpack. - Continue - Jetpack installed - Ready to use this site with the app. - Done - Error icon - There was a problem - Jetpack could not be installed at this time. - Retry - Contact Support + Jetpack icon + Install Jetpack + Your website credentials will not be stored and are used only for the purpose of installing Jetpack. + Installing Jetpack + Installing Jetpack on your site. This can take up to a few minutes to complete. + Set up + Continue + Jetpack installed + Ready to use this site with the app. + Now that Jetpack is installed, we just need to get you set up. This will only take a minute. + Done + Error icon + There was a problem + Jetpack could not be installed at this time. + Retry + Contact Support Activity Log diff --git a/WordPress/src/test/java/org/wordpress/android/ui/JetpackRemoteInstallViewModelTest.kt b/WordPress/src/test/java/org/wordpress/android/ui/JetpackRemoteInstallViewModelTest.kt index 9051e83f74b1..3d7d520d7515 100644 --- a/WordPress/src/test/java/org/wordpress/android/ui/JetpackRemoteInstallViewModelTest.kt +++ b/WordPress/src/test/java/org/wordpress/android/ui/JetpackRemoteInstallViewModelTest.kt @@ -25,10 +25,7 @@ import org.wordpress.android.fluxc.store.JetpackStore.JetpackInstallErrorType import org.wordpress.android.fluxc.store.JetpackStore.OnJetpackInstalled import org.wordpress.android.fluxc.store.SiteStore import org.wordpress.android.ui.JetpackRemoteInstallViewModel.JetpackResultActionData -import org.wordpress.android.ui.JetpackRemoteInstallViewState.Error -import org.wordpress.android.ui.JetpackRemoteInstallViewState.Installed -import org.wordpress.android.ui.JetpackRemoteInstallViewState.Installing -import org.wordpress.android.ui.JetpackRemoteInstallViewState.Start +import org.wordpress.android.ui.jpfullplugininstall.install.UiState @ExperimentalCoroutinesApi @RunWith(MockitoJUnitRunner::class) @@ -51,7 +48,7 @@ class JetpackRemoteInstallViewModelTest : BaseUnitTest() { private val siteId = 1 private lateinit var viewModel: JetpackRemoteInstallViewModel - private val viewStates = mutableListOf() + private val viewStates = mutableListOf() private var jetpackResultActionData: JetpackResultActionData? = null @Before @@ -67,16 +64,16 @@ class JetpackRemoteInstallViewModelTest : BaseUnitTest() { @Test fun `on click starts jetpack install`() = test { - viewModel.start(site, null) + viewModel.initialize(site, null) - val startState = viewStates[0] - assertStartState(startState) + val initialState = viewStates[0] + initialState.assertInitialState() // Trigger install - startState.onClick() + viewModel.onInitialButtonClick() val installingState = viewStates[1] - assertInstallingState(installingState) + installingState.assertInstallingState() verify(dispatcher).dispatch(actionCaptor.capture()) assertThat(actionCaptor.lastValue.type).isEqualTo(JetpackAction.INSTALL_JETPACK) @@ -88,17 +85,17 @@ class JetpackRemoteInstallViewModelTest : BaseUnitTest() { val updatedSite = mock() whenever(siteStore.getSiteByLocalId(siteId)).thenReturn(updatedSite) whenever(accountStore.hasAccessToken()).thenReturn(true) - viewModel.start(site, null) + viewModel.initialize(site, null) - val startState = viewStates[0] - assertStartState(startState) + val initialState = viewStates[0] + initialState.assertInitialState() viewModel.onEventsUpdated(OnJetpackInstalled(true, JetpackAction.INSTALL_JETPACK)) val installedState = viewStates[1] - assertInstalledState(installedState) + installedState.assertDoneState() // Continue after Jetpack is installed - installedState.onClick() + viewModel.onDoneButtonClick() val connectionData = jetpackResultActionData!! assertThat(connectionData.loggedIn).isTrue @@ -109,17 +106,17 @@ class JetpackRemoteInstallViewModelTest : BaseUnitTest() { @Test fun `on error result shows failure`() = test { val installError = JetpackInstallError(JetpackInstallErrorType.GENERIC_ERROR, "error") - viewModel.start(site, null) + viewModel.initialize(site, null) - val startState = viewStates[0] - assertStartState(startState) + val initialState = viewStates[0] + initialState.assertInitialState() viewModel.onEventsUpdated(OnJetpackInstalled(installError, JetpackAction.INSTALL_JETPACK)) val errorState = viewStates[1] - assertErrorState(errorState) + errorState.assertErrorState() - errorState.onClick() + viewModel.onRetryButtonClick() verify(dispatcher).dispatch(actionCaptor.capture()) assertThat(actionCaptor.lastValue.type).isEqualTo(JetpackAction.INSTALL_JETPACK) @@ -133,10 +130,10 @@ class JetpackRemoteInstallViewModelTest : BaseUnitTest() { "INVALID_CREDENTIALS", message = "msg" ) - viewModel.start(site, null) + viewModel.initialize(site, null) - val startState = viewStates[0] - assertStartState(startState) + val initialState = viewStates[0] + initialState.assertInitialState() viewModel.onEventsUpdated(OnJetpackInstalled(installError, JetpackAction.INSTALL_JETPACK)) @@ -160,43 +157,34 @@ class JetpackRemoteInstallViewModelTest : BaseUnitTest() { assertThat(connectionData.site == updatedSite).isTrue } - private fun assertStartState(state: JetpackRemoteInstallViewState) { - assertThat(state).isInstanceOf(Start::class.java) - assertThat(state.type).isEqualTo(JetpackRemoteInstallViewState.Type.START) - assertThat(state.titleResource).isEqualTo(R.string.install_jetpack) - assertThat(state.messageResource).isEqualTo(R.string.install_jetpack_message) - assertThat(state.icon).isEqualTo(R.drawable.ic_plans_white_24dp) - assertThat(state.buttonResource).isEqualTo(R.string.install_jetpack_continue) - assertThat(state.progressBarVisible).isEqualTo(false) + private fun UiState.assertInitialState() { + assertThat(this).isInstanceOf(UiState.Initial::class.java) + + with(this as UiState.Initial) { + assertThat(buttonText).isEqualTo(R.string.jetpack_plugin_install_remote_plugin_button) + } } - private fun assertInstallingState(state: JetpackRemoteInstallViewState) { - assertThat(state).isInstanceOf(Installing::class.java) - assertThat(state.type).isEqualTo(JetpackRemoteInstallViewState.Type.INSTALLING) - assertThat(state.titleResource).isEqualTo(R.string.installing_jetpack) - assertThat(state.messageResource).isEqualTo(R.string.installing_jetpack_message) - assertThat(state.icon).isEqualTo(R.drawable.ic_plans_white_24dp) - assertThat(state.buttonResource).isNull() - assertThat(state.progressBarVisible).isEqualTo(true) + private fun UiState.assertInstallingState() { + assertThat(this).isInstanceOf(UiState.Installing::class.java) } - private fun assertInstalledState(state: JetpackRemoteInstallViewState) { - assertThat(state).isInstanceOf(Installed::class.java) - assertThat(state.type).isEqualTo(JetpackRemoteInstallViewState.Type.INSTALLED) - assertThat(state.titleResource).isEqualTo(R.string.jetpack_installed) - assertThat(state.messageResource).isEqualTo(R.string.jetpack_installed_message) - assertThat(state.icon).isEqualTo(R.drawable.ic_plans_white_24dp) - assertThat(state.buttonResource).isEqualTo(R.string.install_jetpack_continue) - assertThat(state.progressBarVisible).isEqualTo(false) + private fun UiState.assertDoneState() { + assertThat(this).isInstanceOf(UiState.Done::class.java) + + with(this as UiState.Done) { + assertThat(description).isEqualTo(R.string.jetpack_plugin_install_remote_plugin_done_description) + assertThat(buttonText).isEqualTo(R.string.jetpack_plugin_install_remote_plugin_button) + } } - private fun assertErrorState(state: JetpackRemoteInstallViewState) { - assertThat(state).isInstanceOf(Error::class.java) - assertThat(state.type).isEqualTo(JetpackRemoteInstallViewState.Type.ERROR) - assertThat(state.titleResource).isEqualTo(R.string.jetpack_installation_problem) - assertThat(state.messageResource).isEqualTo(R.string.jetpack_installation_problem_message) - assertThat(state.icon).isEqualTo(R.drawable.ic_warning) - assertThat(state.buttonResource).isEqualTo(R.string.install_jetpack_retry) - assertThat(state.progressBarVisible).isEqualTo(false) + private fun UiState.assertErrorState() { + assertThat(this).isInstanceOf(UiState.Error::class.java) + + with(this as UiState.Error) { + assertThat(retryButtonText).isEqualTo(R.string.jetpack_plugin_install_error_button_retry) + assertThat(contactSupportButtonText) + .isEqualTo(R.string.jetpack_plugin_install_error_button_contact_support) + } } } diff --git a/WordPress/src/test/java/org/wordpress/android/ui/jpfullplugininstall/install/JetpackFullPluginInstallUiStateMapperTest.kt b/WordPress/src/test/java/org/wordpress/android/ui/jpfullplugininstall/install/JetpackFullPluginInstallUiStateMapperTest.kt index 49dbc61fa32b..9f713c64a3ab 100644 --- a/WordPress/src/test/java/org/wordpress/android/ui/jpfullplugininstall/install/JetpackFullPluginInstallUiStateMapperTest.kt +++ b/WordPress/src/test/java/org/wordpress/android/ui/jpfullplugininstall/install/JetpackFullPluginInstallUiStateMapperTest.kt @@ -11,14 +11,14 @@ class JetpackFullPluginInstallUiStateMapperTest { fun `Should map Initial state correctly`() { val actual = classToTest.mapInitial() with(actual) { - assertThat(buttonText).isEqualTo(R.string.jetpack_full_plugin_install_initial_button) + assertThat(buttonText).isEqualTo(R.string.jetpack_plugin_install_full_plugin_initial_button) assertThat(toolbarTitle).isEqualTo(R.string.jetpack) assertThat(image).isEqualTo(R.drawable.ic_jetpack_logo_green_24dp) assertThat(imageContentDescription).isEqualTo( - R.string.jetpack_full_plugin_install_jp_logo_content_description + R.string.jetpack_plugin_install_jp_logo_content_description ) - assertThat(title).isEqualTo(R.string.jetpack_full_plugin_install_initial_title) - assertThat(description).isEqualTo(R.string.jetpack_full_plugin_install_initial_description) + assertThat(title).isEqualTo(R.string.jetpack_plugin_install_initial_title) + assertThat(description).isEqualTo(R.string.jetpack_plugin_install_initial_description) assertThat(showCloseButton).isTrue } } @@ -30,10 +30,10 @@ class JetpackFullPluginInstallUiStateMapperTest { assertThat(toolbarTitle).isEqualTo(R.string.jetpack) assertThat(image).isEqualTo(R.drawable.ic_jetpack_logo_green_24dp) assertThat(imageContentDescription).isEqualTo( - R.string.jetpack_full_plugin_install_jp_logo_content_description + R.string.jetpack_plugin_install_jp_logo_content_description ) - assertThat(title).isEqualTo(R.string.jetpack_full_plugin_install_initial_title) - assertThat(description).isEqualTo(R.string.jetpack_full_plugin_install_initial_description) + assertThat(title).isEqualTo(R.string.jetpack_plugin_install_installing_title) + assertThat(description).isEqualTo(R.string.jetpack_plugin_install_installing_description) assertThat(showCloseButton).isFalse } } @@ -42,14 +42,14 @@ class JetpackFullPluginInstallUiStateMapperTest { fun `Should map Done state correctly`() { val actual = classToTest.mapDone() with(actual) { - assertThat(buttonText).isEqualTo(R.string.jetpack_full_plugin_install_done_button) + assertThat(buttonText).isEqualTo(R.string.jetpack_plugin_install_full_plugin_done_button) assertThat(toolbarTitle).isEqualTo(R.string.jetpack) assertThat(image).isEqualTo(R.drawable.ic_jetpack_logo_green_24dp) assertThat(imageContentDescription).isEqualTo( - R.string.jetpack_full_plugin_install_jp_logo_content_description + R.string.jetpack_plugin_install_jp_logo_content_description ) - assertThat(title).isEqualTo(R.string.jetpack_full_plugin_install_done_title) - assertThat(description).isEqualTo(R.string.jetpack_full_plugin_install_done_description) + assertThat(title).isEqualTo(R.string.jetpack_plugin_install_done_title) + assertThat(description).isEqualTo(R.string.jetpack_plugin_install_full_plugin_done_description) assertThat(showCloseButton).isFalse } } @@ -58,17 +58,17 @@ class JetpackFullPluginInstallUiStateMapperTest { fun `Should map Error state correctly`() { val actual = classToTest.mapError() with(actual) { - assertThat(retryButtonText).isEqualTo(R.string.jetpack_full_plugin_install_error_button_retry) + assertThat(retryButtonText).isEqualTo(R.string.jetpack_plugin_install_error_button_retry) assertThat(contactSupportButtonText).isEqualTo( - R.string.jetpack_full_plugin_install_error_button_contact_support + R.string.jetpack_plugin_install_error_button_contact_support ) assertThat(toolbarTitle).isEqualTo(R.string.jetpack) assertThat(image).isEqualTo(R.drawable.ic_warning) assertThat(imageContentDescription).isEqualTo( - R.string.jetpack_full_plugin_install_error_image_content_description + R.string.jetpack_plugin_install_error_image_content_description ) - assertThat(title).isEqualTo(R.string.jetpack_full_plugin_install_error_title) - assertThat(description).isEqualTo(R.string.jetpack_full_plugin_install_error_description) + assertThat(title).isEqualTo(R.string.jetpack_plugin_install_error_title) + assertThat(description).isEqualTo(R.string.jetpack_plugin_install_error_description) assertThat(showCloseButton).isTrue } } From ff3d017820e00914749f29b7a1bbece4a88add1b Mon Sep 17 00:00:00 2001 From: Thomas Horta Date: Thu, 2 Mar 2023 17:12:11 -0300 Subject: [PATCH 054/856] reorganize jp plugin install packages --- WordPress/src/main/AndroidManifest.xml | 4 +-- .../android/ui/ActivityLauncher.java | 1 + .../android/ui/JetpackConnectionUtils.java | 4 +-- .../ui/JetpackConnectionWebViewActivity.java | 2 +- ...tpackFullPluginInstallOnboardingUseCase.kt | 2 +- .../fullplugin}/install/ActionEvent.kt | 2 +- .../JetpackFullPluginInstallActivity.kt | 9 ++++--- ...etpackFullPluginInstallAnalyticsTracker.kt | 20 +++++++------- .../JetpackFullPluginInstallUiStateMapper.kt | 3 ++- .../JetpackFullPluginInstallViewModel.kt | 26 ++++++++++--------- ...PluginInstallOnboardingAnalyticsTracker.kt | 2 +- ...llPluginInstallOnboardingDialogFragment.kt | 18 ++++++------- ...ullPluginInstallOnboardingUiStateMapper.kt | 4 +-- ...ackFullPluginInstallOnboardingViewModel.kt | 10 +++---- .../component/JPInstallFullPluginAnimation.kt | 2 +- .../compose/component/PluginDescription.kt | 2 +- .../compose/component/TermsAndConditions.kt | 2 +- .../onboarding/compose/state/LoadedState.kt | 10 +++---- .../install/UiState.kt | 2 +- .../compose}/JetpackPluginInstallScreen.kt | 12 ++++----- .../install/compose/state/BaseState.kt | 4 +-- .../install/compose/state/DoneState.kt | 4 +-- .../install/compose/state/ErrorState.kt | 4 +-- .../install/compose/state/InitialState.kt | 4 +-- .../install/compose/state/InstallingState.kt | 4 +-- .../JetpackRemoteInstallActivity.kt | 19 +++++++++----- .../JetpackRemoteInstallViewModel.kt | 22 ++++++++-------- .../android/ui/mysite/MySiteViewModel.kt | 2 +- .../JetpackInstallFullPluginCardViewHolder.kt | 2 +- .../ui/mysite/tabs/MySiteTabFragment.kt | 2 +- ...kFullPluginInstallOnboardingUseCaseTest.kt | 2 +- ...ckFullPluginInstallAnalyticsTrackerTest.kt | 4 +-- ...tpackFullPluginInstallUiStateMapperTest.kt | 2 +- .../JetpackFullPluginInstallViewModelTest.kt | 5 ++-- ...inInstallOnboardingAnalyticsTrackerTest.kt | 2 +- ...luginInstallOnboardingUiStateMapperTest.kt | 5 ++-- ...ullPluginInstallOnboardingViewModelTest.kt | 6 ++--- .../JetpackRemoteInstallViewModelTest.kt | 6 ++--- .../android/ui/mysite/MySiteViewModelTest.kt | 2 +- 39 files changed, 124 insertions(+), 114 deletions(-) rename WordPress/src/main/java/org/wordpress/android/ui/{jpfullplugininstall => jetpackplugininstall/fullplugin}/GetShowJetpackFullPluginInstallOnboardingUseCase.kt (92%) rename WordPress/src/main/java/org/wordpress/android/ui/{jpfullplugininstall => jetpackplugininstall/fullplugin}/install/ActionEvent.kt (80%) rename WordPress/src/main/java/org/wordpress/android/ui/{jpfullplugininstall => jetpackplugininstall/fullplugin}/install/JetpackFullPluginInstallActivity.kt (89%) rename WordPress/src/main/java/org/wordpress/android/ui/{jpfullplugininstall => jetpackplugininstall/fullplugin}/install/JetpackFullPluginInstallAnalyticsTracker.kt (62%) rename WordPress/src/main/java/org/wordpress/android/ui/{jpfullplugininstall => jetpackplugininstall/fullplugin}/install/JetpackFullPluginInstallUiStateMapper.kt (85%) rename WordPress/src/main/java/org/wordpress/android/ui/{jpfullplugininstall => jetpackplugininstall/fullplugin}/install/JetpackFullPluginInstallViewModel.kt (87%) rename WordPress/src/main/java/org/wordpress/android/ui/{jpfullplugininstall => jetpackplugininstall/fullplugin}/onboarding/JetpackFullPluginInstallOnboardingAnalyticsTracker.kt (91%) rename WordPress/src/main/java/org/wordpress/android/ui/{jpfullplugininstall => jetpackplugininstall/fullplugin}/onboarding/JetpackFullPluginInstallOnboardingDialogFragment.kt (78%) rename WordPress/src/main/java/org/wordpress/android/ui/{jpfullplugininstall => jetpackplugininstall/fullplugin}/onboarding/JetpackFullPluginInstallOnboardingUiStateMapper.kt (75%) rename WordPress/src/main/java/org/wordpress/android/ui/{jpfullplugininstall => jetpackplugininstall/fullplugin}/onboarding/JetpackFullPluginInstallOnboardingViewModel.kt (82%) rename WordPress/src/main/java/org/wordpress/android/ui/{jpfullplugininstall => jetpackplugininstall/fullplugin}/onboarding/compose/component/JPInstallFullPluginAnimation.kt (93%) rename WordPress/src/main/java/org/wordpress/android/ui/{jpfullplugininstall => jetpackplugininstall/fullplugin}/onboarding/compose/component/PluginDescription.kt (97%) rename WordPress/src/main/java/org/wordpress/android/ui/{jpfullplugininstall => jetpackplugininstall/fullplugin}/onboarding/compose/component/TermsAndConditions.kt (96%) rename WordPress/src/main/java/org/wordpress/android/ui/{jpfullplugininstall => jetpackplugininstall/fullplugin}/onboarding/compose/state/LoadedState.kt (89%) rename WordPress/src/main/java/org/wordpress/android/ui/{jpfullplugininstall => jetpackplugininstall}/install/UiState.kt (97%) rename WordPress/src/main/java/org/wordpress/android/ui/{jpfullplugininstall/install => jetpackplugininstall/install/compose}/JetpackPluginInstallScreen.kt (80%) rename WordPress/src/main/java/org/wordpress/android/ui/{jpfullplugininstall => jetpackplugininstall}/install/compose/state/BaseState.kt (96%) rename WordPress/src/main/java/org/wordpress/android/ui/{jpfullplugininstall => jetpackplugininstall}/install/compose/state/DoneState.kt (90%) rename WordPress/src/main/java/org/wordpress/android/ui/{jpfullplugininstall => jetpackplugininstall}/install/compose/state/ErrorState.kt (93%) rename WordPress/src/main/java/org/wordpress/android/ui/{jpfullplugininstall => jetpackplugininstall}/install/compose/state/InitialState.kt (90%) rename WordPress/src/main/java/org/wordpress/android/ui/{jpfullplugininstall => jetpackplugininstall}/install/compose/state/InstallingState.kt (88%) rename WordPress/src/main/java/org/wordpress/android/ui/{ => jetpackplugininstall/remoteplugin}/JetpackRemoteInstallActivity.kt (83%) rename WordPress/src/main/java/org/wordpress/android/ui/{ => jetpackplugininstall/remoteplugin}/JetpackRemoteInstallViewModel.kt (85%) rename WordPress/src/test/java/org/wordpress/android/ui/{jpfullplugininstall => jetpackplugininstall/fullplugin}/GetShowJetpackFullPluginInstallOnboardingUseCaseTest.kt (97%) rename WordPress/src/test/java/org/wordpress/android/ui/{jpfullplugininstall => jetpackplugininstall/fullplugin}/install/JetpackFullPluginInstallAnalyticsTrackerTest.kt (91%) rename WordPress/src/test/java/org/wordpress/android/ui/{jpfullplugininstall => jetpackplugininstall/fullplugin}/install/JetpackFullPluginInstallUiStateMapperTest.kt (97%) rename WordPress/src/test/java/org/wordpress/android/ui/{jpfullplugininstall => jetpackplugininstall/fullplugin}/install/JetpackFullPluginInstallViewModelTest.kt (96%) rename WordPress/src/test/java/org/wordpress/android/ui/{jpfullplugininstall => jetpackplugininstall/fullplugin}/onboarding/JetpackFullPluginInstallOnboardingAnalyticsTrackerTest.kt (94%) rename WordPress/src/test/java/org/wordpress/android/ui/{jpfullplugininstall => jetpackplugininstall/fullplugin/onboarding}/JetpackFullPluginInstallOnboardingUiStateMapperTest.kt (83%) rename WordPress/src/test/java/org/wordpress/android/ui/{jpfullplugininstall => jetpackplugininstall/fullplugin}/onboarding/JetpackFullPluginInstallOnboardingViewModelTest.kt (93%) rename WordPress/src/test/java/org/wordpress/android/ui/{ => jetpackplugininstall/remoteplugin}/JetpackRemoteInstallViewModelTest.kt (96%) diff --git a/WordPress/src/main/AndroidManifest.xml b/WordPress/src/main/AndroidManifest.xml index a714e365f593..55159a7af86b 100644 --- a/WordPress/src/main/AndroidManifest.xml +++ b/WordPress/src/main/AndroidManifest.xml @@ -319,7 +319,7 @@ @@ -773,7 +773,7 @@ diff --git a/WordPress/src/main/java/org/wordpress/android/ui/ActivityLauncher.java b/WordPress/src/main/java/org/wordpress/android/ui/ActivityLauncher.java index 7f06f94cc7a5..496f6a1ca5c5 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/ActivityLauncher.java +++ b/WordPress/src/main/java/org/wordpress/android/ui/ActivityLauncher.java @@ -69,6 +69,7 @@ import org.wordpress.android.ui.jetpack.scan.ScanActivity; import org.wordpress.android.ui.jetpack.scan.details.ThreatDetailsActivity; import org.wordpress.android.ui.jetpack.scan.history.ScanHistoryActivity; +import org.wordpress.android.ui.jetpackplugininstall.remoteplugin.JetpackRemoteInstallActivity; import org.wordpress.android.ui.main.MeActivity; import org.wordpress.android.ui.main.SitePickerActivity; import org.wordpress.android.ui.main.SitePickerAdapter.SitePickerMode; diff --git a/WordPress/src/main/java/org/wordpress/android/ui/JetpackConnectionUtils.java b/WordPress/src/main/java/org/wordpress/android/ui/JetpackConnectionUtils.java index b8fa46db4d97..b6c435982d9c 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/JetpackConnectionUtils.java +++ b/WordPress/src/main/java/org/wordpress/android/ui/JetpackConnectionUtils.java @@ -7,13 +7,13 @@ /** * Wraps utility methods for Jetpack */ -class JetpackConnectionUtils { +public class JetpackConnectionUtils { /** * Adds source as a parameter to the tracked Stat * @param stat to be tracked * @param source of tracking */ - static void trackWithSource(AnalyticsTracker.Stat stat, JetpackConnectionSource source) { + public static void trackWithSource(AnalyticsTracker.Stat stat, JetpackConnectionSource source) { HashMap sourceMap = new HashMap<>(); sourceMap.put("source", source.toString()); AnalyticsTracker.track(stat, sourceMap); diff --git a/WordPress/src/main/java/org/wordpress/android/ui/JetpackConnectionWebViewActivity.java b/WordPress/src/main/java/org/wordpress/android/ui/JetpackConnectionWebViewActivity.java index 921e49b36574..53ba39a6bc1a 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/JetpackConnectionWebViewActivity.java +++ b/WordPress/src/main/java/org/wordpress/android/ui/JetpackConnectionWebViewActivity.java @@ -44,7 +44,7 @@ public static void startJetpackConnectionFlow(Context context, JetpackConnection } } - static void startManualFlow(Context context, JetpackConnectionSource source, SiteModel site, boolean authorized) { + public static void startManualFlow(Context context, JetpackConnectionSource source, SiteModel site, boolean authorized) { String url = "https://wordpress.com/jetpack/connect?" + "url=" + site.getUrl() + "&mobile_redirect=" + JETPACK_CONNECTION_DEEPLINK diff --git a/WordPress/src/main/java/org/wordpress/android/ui/jpfullplugininstall/GetShowJetpackFullPluginInstallOnboardingUseCase.kt b/WordPress/src/main/java/org/wordpress/android/ui/jetpackplugininstall/fullplugin/GetShowJetpackFullPluginInstallOnboardingUseCase.kt similarity index 92% rename from WordPress/src/main/java/org/wordpress/android/ui/jpfullplugininstall/GetShowJetpackFullPluginInstallOnboardingUseCase.kt rename to WordPress/src/main/java/org/wordpress/android/ui/jetpackplugininstall/fullplugin/GetShowJetpackFullPluginInstallOnboardingUseCase.kt index 0bc6a3c2da67..74f4d71ab8a1 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/jpfullplugininstall/GetShowJetpackFullPluginInstallOnboardingUseCase.kt +++ b/WordPress/src/main/java/org/wordpress/android/ui/jetpackplugininstall/fullplugin/GetShowJetpackFullPluginInstallOnboardingUseCase.kt @@ -1,4 +1,4 @@ -package org.wordpress.android.ui.jpfullplugininstall +package org.wordpress.android.ui.jetpackplugininstall.fullplugin import org.wordpress.android.fluxc.model.SiteModel import org.wordpress.android.ui.prefs.AppPrefsWrapper diff --git a/WordPress/src/main/java/org/wordpress/android/ui/jpfullplugininstall/install/ActionEvent.kt b/WordPress/src/main/java/org/wordpress/android/ui/jetpackplugininstall/fullplugin/install/ActionEvent.kt similarity index 80% rename from WordPress/src/main/java/org/wordpress/android/ui/jpfullplugininstall/install/ActionEvent.kt rename to WordPress/src/main/java/org/wordpress/android/ui/jetpackplugininstall/fullplugin/install/ActionEvent.kt index bd982847b1db..9a348c219a9d 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/jpfullplugininstall/install/ActionEvent.kt +++ b/WordPress/src/main/java/org/wordpress/android/ui/jetpackplugininstall/fullplugin/install/ActionEvent.kt @@ -1,4 +1,4 @@ -package org.wordpress.android.ui.jpfullplugininstall.install +package org.wordpress.android.ui.jetpackplugininstall.fullplugin.install import org.wordpress.android.fluxc.model.SiteModel import org.wordpress.android.ui.accounts.HelpActivity diff --git a/WordPress/src/main/java/org/wordpress/android/ui/jpfullplugininstall/install/JetpackFullPluginInstallActivity.kt b/WordPress/src/main/java/org/wordpress/android/ui/jetpackplugininstall/fullplugin/install/JetpackFullPluginInstallActivity.kt similarity index 89% rename from WordPress/src/main/java/org/wordpress/android/ui/jpfullplugininstall/install/JetpackFullPluginInstallActivity.kt rename to WordPress/src/main/java/org/wordpress/android/ui/jetpackplugininstall/fullplugin/install/JetpackFullPluginInstallActivity.kt index 40bf6095857f..4cf7baf65be9 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/jpfullplugininstall/install/JetpackFullPluginInstallActivity.kt +++ b/WordPress/src/main/java/org/wordpress/android/ui/jetpackplugininstall/fullplugin/install/JetpackFullPluginInstallActivity.kt @@ -1,4 +1,4 @@ -package org.wordpress.android.ui.jpfullplugininstall.install +package org.wordpress.android.ui.jetpackplugininstall.fullplugin.install import android.content.Context import android.content.Intent @@ -13,6 +13,7 @@ import kotlinx.coroutines.flow.launchIn import kotlinx.coroutines.flow.onEach import org.wordpress.android.ui.ActivityLauncher import org.wordpress.android.ui.compose.theme.AppTheme +import org.wordpress.android.ui.jetpackplugininstall.install.compose.JetpackPluginInstallScreen import org.wordpress.android.util.extensions.exhaustive import org.wordpress.android.util.extensions.setContent @@ -35,8 +36,7 @@ class JetpackFullPluginInstallActivity : AppCompatActivity() { onInitialShown = viewModel::onInitialShown, onInstallingShown = viewModel::onInstallingShown, onErrorShown = viewModel::onErrorShown, - - ) + ) } } observeActionEvents() @@ -70,6 +70,7 @@ class JetpackFullPluginInstallActivity : AppCompatActivity() { companion object { @JvmStatic - fun createIntent(context: Context) = Intent(context, JetpackFullPluginInstallActivity::class.java) + fun createIntent(context: Context) = + Intent(context, JetpackFullPluginInstallActivity::class.java) } } diff --git a/WordPress/src/main/java/org/wordpress/android/ui/jpfullplugininstall/install/JetpackFullPluginInstallAnalyticsTracker.kt b/WordPress/src/main/java/org/wordpress/android/ui/jetpackplugininstall/fullplugin/install/JetpackFullPluginInstallAnalyticsTracker.kt similarity index 62% rename from WordPress/src/main/java/org/wordpress/android/ui/jpfullplugininstall/install/JetpackFullPluginInstallAnalyticsTracker.kt rename to WordPress/src/main/java/org/wordpress/android/ui/jetpackplugininstall/fullplugin/install/JetpackFullPluginInstallAnalyticsTracker.kt index 4d353f8a21c2..9446bf022143 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/jpfullplugininstall/install/JetpackFullPluginInstallAnalyticsTracker.kt +++ b/WordPress/src/main/java/org/wordpress/android/ui/jetpackplugininstall/fullplugin/install/JetpackFullPluginInstallAnalyticsTracker.kt @@ -1,40 +1,42 @@ -package org.wordpress.android.ui.jpfullplugininstall.install +package org.wordpress.android.ui.jetpackplugininstall.fullplugin.install -import org.wordpress.android.analytics.AnalyticsTracker.Stat +import org.wordpress.android.analytics.AnalyticsTracker import org.wordpress.android.util.analytics.AnalyticsTrackerWrapper import javax.inject.Inject +private const val KEY_STATUS_PARAMETER = "status" + class JetpackFullPluginInstallAnalyticsTracker @Inject constructor( private val analyticsTracker: AnalyticsTrackerWrapper ) { fun trackScreenShown(status: Status) { analyticsTracker.track( - Stat.JETPACK_INSTALL_FULL_PLUGIN_FLOW_VIEWED, + AnalyticsTracker.Stat.JETPACK_INSTALL_FULL_PLUGIN_FLOW_VIEWED, mapOf(KEY_STATUS_PARAMETER to status.trackingValue) ) } fun trackCancelButtonClicked(status: Status) { analyticsTracker.track( - Stat.JETPACK_INSTALL_FULL_PLUGIN_FLOW_CANCEL_TAPPED, + AnalyticsTracker.Stat.JETPACK_INSTALL_FULL_PLUGIN_FLOW_CANCEL_TAPPED, mapOf(KEY_STATUS_PARAMETER to status.trackingValue) ) } fun trackInstallButtonClicked() = analyticsTracker.track( - Stat.JETPACK_INSTALL_FULL_PLUGIN_FLOW_INSTALL_TAPPED, emptyMap() + AnalyticsTracker.Stat.JETPACK_INSTALL_FULL_PLUGIN_FLOW_INSTALL_TAPPED, emptyMap() ) fun trackRetryButtonClicked() = analyticsTracker.track( - Stat.JETPACK_INSTALL_FULL_PLUGIN_FLOW_RETRY_TAPPED, emptyMap() + AnalyticsTracker.Stat.JETPACK_INSTALL_FULL_PLUGIN_FLOW_RETRY_TAPPED, emptyMap() ) fun trackJetpackInstallationSuccess() = analyticsTracker.track( - Stat.JETPACK_INSTALL_FULL_PLUGIN_FLOW_SUCCESS, emptyMap() + AnalyticsTracker.Stat.JETPACK_INSTALL_FULL_PLUGIN_FLOW_SUCCESS, emptyMap() ) fun trackDoneButtonClicked() = analyticsTracker.track( - Stat.JETPACK_INSTALL_FULL_PLUGIN_FLOW_DONE_TAPPED, emptyMap() + AnalyticsTracker.Stat.JETPACK_INSTALL_FULL_PLUGIN_FLOW_DONE_TAPPED, emptyMap() ) sealed class Status(val trackingValue: String) { @@ -43,5 +45,3 @@ class JetpackFullPluginInstallAnalyticsTracker @Inject constructor( object Error : Status("error") } } - -private const val KEY_STATUS_PARAMETER = "status" diff --git a/WordPress/src/main/java/org/wordpress/android/ui/jpfullplugininstall/install/JetpackFullPluginInstallUiStateMapper.kt b/WordPress/src/main/java/org/wordpress/android/ui/jetpackplugininstall/fullplugin/install/JetpackFullPluginInstallUiStateMapper.kt similarity index 85% rename from WordPress/src/main/java/org/wordpress/android/ui/jpfullplugininstall/install/JetpackFullPluginInstallUiStateMapper.kt rename to WordPress/src/main/java/org/wordpress/android/ui/jetpackplugininstall/fullplugin/install/JetpackFullPluginInstallUiStateMapper.kt index 1325fb5df4a8..b1d4bc55ea47 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/jpfullplugininstall/install/JetpackFullPluginInstallUiStateMapper.kt +++ b/WordPress/src/main/java/org/wordpress/android/ui/jetpackplugininstall/fullplugin/install/JetpackFullPluginInstallUiStateMapper.kt @@ -1,6 +1,7 @@ -package org.wordpress.android.ui.jpfullplugininstall.install +package org.wordpress.android.ui.jetpackplugininstall.fullplugin.install import org.wordpress.android.R +import org.wordpress.android.ui.jetpackplugininstall.install.UiState import javax.inject.Inject class JetpackFullPluginInstallUiStateMapper @Inject constructor() { diff --git a/WordPress/src/main/java/org/wordpress/android/ui/jpfullplugininstall/install/JetpackFullPluginInstallViewModel.kt b/WordPress/src/main/java/org/wordpress/android/ui/jetpackplugininstall/fullplugin/install/JetpackFullPluginInstallViewModel.kt similarity index 87% rename from WordPress/src/main/java/org/wordpress/android/ui/jpfullplugininstall/install/JetpackFullPluginInstallViewModel.kt rename to WordPress/src/main/java/org/wordpress/android/ui/jetpackplugininstall/fullplugin/install/JetpackFullPluginInstallViewModel.kt index b660c95f13ef..712eaa50dc07 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/jpfullplugininstall/install/JetpackFullPluginInstallViewModel.kt +++ b/WordPress/src/main/java/org/wordpress/android/ui/jetpackplugininstall/fullplugin/install/JetpackFullPluginInstallViewModel.kt @@ -1,4 +1,4 @@ -package org.wordpress.android.ui.jpfullplugininstall.install +package org.wordpress.android.ui.jetpackplugininstall.fullplugin.install import dagger.hilt.android.lifecycle.HiltViewModel import kotlinx.coroutines.CoroutineDispatcher @@ -12,13 +12,11 @@ import org.wordpress.android.fluxc.Dispatcher import org.wordpress.android.fluxc.generated.PluginActionBuilder import org.wordpress.android.fluxc.generated.SiteActionBuilder import org.wordpress.android.fluxc.store.PluginStore -import org.wordpress.android.fluxc.store.PluginStore.InstallSitePluginPayload -import org.wordpress.android.fluxc.store.PluginStore.OnSitePluginConfigured -import org.wordpress.android.fluxc.store.PluginStore.OnSitePluginInstalled -import org.wordpress.android.fluxc.store.SiteStore.OnSiteChanged +import org.wordpress.android.fluxc.store.SiteStore import org.wordpress.android.modules.BG_THREAD import org.wordpress.android.ui.accounts.HelpActivity -import org.wordpress.android.ui.jpfullplugininstall.install.JetpackFullPluginInstallAnalyticsTracker.Status +import org.wordpress.android.ui.jetpackplugininstall.fullplugin.install.JetpackFullPluginInstallAnalyticsTracker.Status +import org.wordpress.android.ui.jetpackplugininstall.install.UiState import org.wordpress.android.ui.mysite.SelectedSiteRepository import org.wordpress.android.util.AppLog import org.wordpress.android.viewmodel.ScopedViewModel @@ -32,7 +30,7 @@ class JetpackFullPluginInstallViewModel @Inject constructor( private val selectedSiteRepository: SelectedSiteRepository, @Named(BG_THREAD) private val bgDispatcher: CoroutineDispatcher, // adding pluginStore seems needed to allow the events Subscribe to work - private val pluginStore: PluginStore, + @Suppress("unused") private val pluginStore: PluginStore, private val dispatcher: Dispatcher, private val analyticsTracker: JetpackFullPluginInstallAnalyticsTracker, ) : ScopedViewModel(bgDispatcher) { @@ -99,7 +97,7 @@ class JetpackFullPluginInstallViewModel @Inject constructor( @Suppress("unused") @Subscribe(threadMode = ThreadMode.MAIN) - fun onSitePluginInstalled(event: OnSitePluginInstalled) { + fun onSitePluginInstalled(event: PluginStore.OnSitePluginInstalled) { if (event.isError) { AppLog.d( AppLog.T.PLUGINS, @@ -115,7 +113,7 @@ class JetpackFullPluginInstallViewModel @Inject constructor( @Suppress("unused") @Subscribe(threadMode = ThreadMode.MAIN) - fun onSitePluginConfigured(event: OnSitePluginConfigured) { + fun onSitePluginConfigured(event: PluginStore.OnSitePluginConfigured) { if (event.isError) { AppLog.d( AppLog.T.PLUGINS, @@ -131,7 +129,7 @@ class JetpackFullPluginInstallViewModel @Inject constructor( @Suppress("unused") @Subscribe(threadMode = ThreadMode.MAIN) - fun onSiteChanged(event: OnSiteChanged) { + fun onSiteChanged(event: SiteStore.OnSiteChanged) { val success = if (event.isError) { AppLog.d( AppLog.T.PLUGINS, @@ -158,8 +156,12 @@ class JetpackFullPluginInstallViewModel @Inject constructor( private fun installJetpackPlugin() { val selectedSite = selectedSiteRepository.getSelectedSite() selectedSite?.let { - val payload = InstallSitePluginPayload(it, "jetpack") - dispatcher.dispatch(PluginActionBuilder.newInstallJpForIndividualPluginSiteAction(payload)) + val payload = PluginStore.InstallSitePluginPayload(it, "jetpack") + dispatcher.dispatch( + PluginActionBuilder.newInstallJpForIndividualPluginSiteAction( + payload + ) + ) } } diff --git a/WordPress/src/main/java/org/wordpress/android/ui/jpfullplugininstall/onboarding/JetpackFullPluginInstallOnboardingAnalyticsTracker.kt b/WordPress/src/main/java/org/wordpress/android/ui/jetpackplugininstall/fullplugin/onboarding/JetpackFullPluginInstallOnboardingAnalyticsTracker.kt similarity index 91% rename from WordPress/src/main/java/org/wordpress/android/ui/jpfullplugininstall/onboarding/JetpackFullPluginInstallOnboardingAnalyticsTracker.kt rename to WordPress/src/main/java/org/wordpress/android/ui/jetpackplugininstall/fullplugin/onboarding/JetpackFullPluginInstallOnboardingAnalyticsTracker.kt index db2f3ffcf4a2..8657da76750d 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/jpfullplugininstall/onboarding/JetpackFullPluginInstallOnboardingAnalyticsTracker.kt +++ b/WordPress/src/main/java/org/wordpress/android/ui/jetpackplugininstall/fullplugin/onboarding/JetpackFullPluginInstallOnboardingAnalyticsTracker.kt @@ -1,4 +1,4 @@ -package org.wordpress.android.ui.jpfullplugininstall.onboarding +package org.wordpress.android.ui.jetpackplugininstall.fullplugin.onboarding import org.wordpress.android.analytics.AnalyticsTracker import org.wordpress.android.util.analytics.AnalyticsTrackerWrapper diff --git a/WordPress/src/main/java/org/wordpress/android/ui/jpfullplugininstall/onboarding/JetpackFullPluginInstallOnboardingDialogFragment.kt b/WordPress/src/main/java/org/wordpress/android/ui/jetpackplugininstall/fullplugin/onboarding/JetpackFullPluginInstallOnboardingDialogFragment.kt similarity index 78% rename from WordPress/src/main/java/org/wordpress/android/ui/jpfullplugininstall/onboarding/JetpackFullPluginInstallOnboardingDialogFragment.kt rename to WordPress/src/main/java/org/wordpress/android/ui/jetpackplugininstall/fullplugin/onboarding/JetpackFullPluginInstallOnboardingDialogFragment.kt index f5941750ae07..c56ef0ef2159 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/jpfullplugininstall/onboarding/JetpackFullPluginInstallOnboardingDialogFragment.kt +++ b/WordPress/src/main/java/org/wordpress/android/ui/jetpackplugininstall/fullplugin/onboarding/JetpackFullPluginInstallOnboardingDialogFragment.kt @@ -1,4 +1,4 @@ -package org.wordpress.android.ui.jpfullplugininstall.onboarding +package org.wordpress.android.ui.jetpackplugininstall.fullplugin.onboarding import android.app.Dialog import android.os.Bundle @@ -20,14 +20,14 @@ import org.wordpress.android.R import org.wordpress.android.ui.ActivityLauncher import org.wordpress.android.ui.WPWebViewActivity import org.wordpress.android.ui.compose.theme.AppTheme -import org.wordpress.android.ui.jpfullplugininstall.install.JetpackFullPluginInstallActivity -import org.wordpress.android.ui.jpfullplugininstall.onboarding.JetpackFullPluginInstallOnboardingViewModel.ActionEvent -import org.wordpress.android.ui.jpfullplugininstall.onboarding.JetpackFullPluginInstallOnboardingViewModel.ActionEvent.ContactSupport -import org.wordpress.android.ui.jpfullplugininstall.onboarding.JetpackFullPluginInstallOnboardingViewModel.ActionEvent.Dismiss -import org.wordpress.android.ui.jpfullplugininstall.onboarding.JetpackFullPluginInstallOnboardingViewModel.ActionEvent.OpenInstallJetpackFullPlugin -import org.wordpress.android.ui.jpfullplugininstall.onboarding.JetpackFullPluginInstallOnboardingViewModel.ActionEvent.OpenTermsAndConditions -import org.wordpress.android.ui.jpfullplugininstall.onboarding.JetpackFullPluginInstallOnboardingViewModel.UiState -import org.wordpress.android.ui.jpfullplugininstall.onboarding.compose.state.LoadedState +import org.wordpress.android.ui.jetpackplugininstall.fullplugin.install.JetpackFullPluginInstallActivity +import org.wordpress.android.ui.jetpackplugininstall.fullplugin.onboarding.JetpackFullPluginInstallOnboardingViewModel.ActionEvent +import org.wordpress.android.ui.jetpackplugininstall.fullplugin.onboarding.JetpackFullPluginInstallOnboardingViewModel.ActionEvent.ContactSupport +import org.wordpress.android.ui.jetpackplugininstall.fullplugin.onboarding.JetpackFullPluginInstallOnboardingViewModel.ActionEvent.Dismiss +import org.wordpress.android.ui.jetpackplugininstall.fullplugin.onboarding.JetpackFullPluginInstallOnboardingViewModel.ActionEvent.OpenInstallJetpackFullPlugin +import org.wordpress.android.ui.jetpackplugininstall.fullplugin.onboarding.JetpackFullPluginInstallOnboardingViewModel.ActionEvent.OpenTermsAndConditions +import org.wordpress.android.ui.jetpackplugininstall.fullplugin.onboarding.JetpackFullPluginInstallOnboardingViewModel.UiState +import org.wordpress.android.ui.jetpackplugininstall.fullplugin.onboarding.compose.state.LoadedState import org.wordpress.android.util.WPUrlUtils import org.wordpress.android.util.extensions.exhaustive import org.wordpress.android.util.extensions.setStatusBarAsSurfaceColor diff --git a/WordPress/src/main/java/org/wordpress/android/ui/jpfullplugininstall/onboarding/JetpackFullPluginInstallOnboardingUiStateMapper.kt b/WordPress/src/main/java/org/wordpress/android/ui/jetpackplugininstall/fullplugin/onboarding/JetpackFullPluginInstallOnboardingUiStateMapper.kt similarity index 75% rename from WordPress/src/main/java/org/wordpress/android/ui/jpfullplugininstall/onboarding/JetpackFullPluginInstallOnboardingUiStateMapper.kt rename to WordPress/src/main/java/org/wordpress/android/ui/jetpackplugininstall/fullplugin/onboarding/JetpackFullPluginInstallOnboardingUiStateMapper.kt index fd546da0f8fb..3b41a3eee24f 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/jpfullplugininstall/onboarding/JetpackFullPluginInstallOnboardingUiStateMapper.kt +++ b/WordPress/src/main/java/org/wordpress/android/ui/jetpackplugininstall/fullplugin/onboarding/JetpackFullPluginInstallOnboardingUiStateMapper.kt @@ -1,6 +1,6 @@ -package org.wordpress.android.ui.jpfullplugininstall.onboarding +package org.wordpress.android.ui.jetpackplugininstall.fullplugin.onboarding -import org.wordpress.android.ui.jpfullplugininstall.onboarding.JetpackFullPluginInstallOnboardingViewModel.UiState +import org.wordpress.android.ui.jetpackplugininstall.fullplugin.onboarding.JetpackFullPluginInstallOnboardingViewModel.UiState import org.wordpress.android.ui.mysite.SelectedSiteRepository import org.wordpress.android.util.extensions.activeJetpackConnectionPluginNames import javax.inject.Inject diff --git a/WordPress/src/main/java/org/wordpress/android/ui/jpfullplugininstall/onboarding/JetpackFullPluginInstallOnboardingViewModel.kt b/WordPress/src/main/java/org/wordpress/android/ui/jetpackplugininstall/fullplugin/onboarding/JetpackFullPluginInstallOnboardingViewModel.kt similarity index 82% rename from WordPress/src/main/java/org/wordpress/android/ui/jpfullplugininstall/onboarding/JetpackFullPluginInstallOnboardingViewModel.kt rename to WordPress/src/main/java/org/wordpress/android/ui/jetpackplugininstall/fullplugin/onboarding/JetpackFullPluginInstallOnboardingViewModel.kt index 0e6c3b9122e4..8ba671a9fd1a 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/jpfullplugininstall/onboarding/JetpackFullPluginInstallOnboardingViewModel.kt +++ b/WordPress/src/main/java/org/wordpress/android/ui/jetpackplugininstall/fullplugin/onboarding/JetpackFullPluginInstallOnboardingViewModel.kt @@ -1,4 +1,4 @@ -package org.wordpress.android.ui.jpfullplugininstall.onboarding +package org.wordpress.android.ui.jetpackplugininstall.fullplugin.onboarding import dagger.hilt.android.lifecycle.HiltViewModel import kotlinx.coroutines.CoroutineDispatcher @@ -9,10 +9,10 @@ import kotlinx.coroutines.flow.update import org.wordpress.android.fluxc.model.SiteModel import org.wordpress.android.modules.BG_THREAD import org.wordpress.android.ui.accounts.HelpActivity -import org.wordpress.android.ui.jpfullplugininstall.onboarding.JetpackFullPluginInstallOnboardingViewModel.ActionEvent.ContactSupport -import org.wordpress.android.ui.jpfullplugininstall.onboarding.JetpackFullPluginInstallOnboardingViewModel.ActionEvent.Dismiss -import org.wordpress.android.ui.jpfullplugininstall.onboarding.JetpackFullPluginInstallOnboardingViewModel.ActionEvent.OpenInstallJetpackFullPlugin -import org.wordpress.android.ui.jpfullplugininstall.onboarding.JetpackFullPluginInstallOnboardingViewModel.ActionEvent.OpenTermsAndConditions +import org.wordpress.android.ui.jetpackplugininstall.fullplugin.onboarding.JetpackFullPluginInstallOnboardingViewModel.ActionEvent.ContactSupport +import org.wordpress.android.ui.jetpackplugininstall.fullplugin.onboarding.JetpackFullPluginInstallOnboardingViewModel.ActionEvent.Dismiss +import org.wordpress.android.ui.jetpackplugininstall.fullplugin.onboarding.JetpackFullPluginInstallOnboardingViewModel.ActionEvent.OpenInstallJetpackFullPlugin +import org.wordpress.android.ui.jetpackplugininstall.fullplugin.onboarding.JetpackFullPluginInstallOnboardingViewModel.ActionEvent.OpenTermsAndConditions import org.wordpress.android.ui.mysite.SelectedSiteRepository import org.wordpress.android.ui.prefs.AppPrefsWrapper import org.wordpress.android.viewmodel.ScopedViewModel diff --git a/WordPress/src/main/java/org/wordpress/android/ui/jpfullplugininstall/onboarding/compose/component/JPInstallFullPluginAnimation.kt b/WordPress/src/main/java/org/wordpress/android/ui/jetpackplugininstall/fullplugin/onboarding/compose/component/JPInstallFullPluginAnimation.kt similarity index 93% rename from WordPress/src/main/java/org/wordpress/android/ui/jpfullplugininstall/onboarding/compose/component/JPInstallFullPluginAnimation.kt rename to WordPress/src/main/java/org/wordpress/android/ui/jetpackplugininstall/fullplugin/onboarding/compose/component/JPInstallFullPluginAnimation.kt index 1814f4602b46..8de780ad6fb1 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/jpfullplugininstall/onboarding/compose/component/JPInstallFullPluginAnimation.kt +++ b/WordPress/src/main/java/org/wordpress/android/ui/jetpackplugininstall/fullplugin/onboarding/compose/component/JPInstallFullPluginAnimation.kt @@ -1,4 +1,4 @@ -package org.wordpress.android.ui.jpfullplugininstall.onboarding.compose.component +package org.wordpress.android.ui.jetpackplugininstall.fullplugin.onboarding.compose.component import android.content.res.Configuration import androidx.compose.runtime.Composable diff --git a/WordPress/src/main/java/org/wordpress/android/ui/jpfullplugininstall/onboarding/compose/component/PluginDescription.kt b/WordPress/src/main/java/org/wordpress/android/ui/jetpackplugininstall/fullplugin/onboarding/compose/component/PluginDescription.kt similarity index 97% rename from WordPress/src/main/java/org/wordpress/android/ui/jpfullplugininstall/onboarding/compose/component/PluginDescription.kt rename to WordPress/src/main/java/org/wordpress/android/ui/jetpackplugininstall/fullplugin/onboarding/compose/component/PluginDescription.kt index bffc00062ea3..a398168fc3b5 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/jpfullplugininstall/onboarding/compose/component/PluginDescription.kt +++ b/WordPress/src/main/java/org/wordpress/android/ui/jetpackplugininstall/fullplugin/onboarding/compose/component/PluginDescription.kt @@ -1,4 +1,4 @@ -package org.wordpress.android.ui.jpfullplugininstall.onboarding.compose.component +package org.wordpress.android.ui.jetpackplugininstall.fullplugin.onboarding.compose.component import android.content.res.Configuration import androidx.compose.material.Text diff --git a/WordPress/src/main/java/org/wordpress/android/ui/jpfullplugininstall/onboarding/compose/component/TermsAndConditions.kt b/WordPress/src/main/java/org/wordpress/android/ui/jetpackplugininstall/fullplugin/onboarding/compose/component/TermsAndConditions.kt similarity index 96% rename from WordPress/src/main/java/org/wordpress/android/ui/jpfullplugininstall/onboarding/compose/component/TermsAndConditions.kt rename to WordPress/src/main/java/org/wordpress/android/ui/jetpackplugininstall/fullplugin/onboarding/compose/component/TermsAndConditions.kt index 87746d54e801..ad0720082101 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/jpfullplugininstall/onboarding/compose/component/TermsAndConditions.kt +++ b/WordPress/src/main/java/org/wordpress/android/ui/jetpackplugininstall/fullplugin/onboarding/compose/component/TermsAndConditions.kt @@ -1,4 +1,4 @@ -package org.wordpress.android.ui.jpfullplugininstall.onboarding.compose.component +package org.wordpress.android.ui.jetpackplugininstall.fullplugin.onboarding.compose.component import android.content.res.Configuration import androidx.compose.foundation.clickable diff --git a/WordPress/src/main/java/org/wordpress/android/ui/jpfullplugininstall/onboarding/compose/state/LoadedState.kt b/WordPress/src/main/java/org/wordpress/android/ui/jetpackplugininstall/fullplugin/onboarding/compose/state/LoadedState.kt similarity index 89% rename from WordPress/src/main/java/org/wordpress/android/ui/jpfullplugininstall/onboarding/compose/state/LoadedState.kt rename to WordPress/src/main/java/org/wordpress/android/ui/jetpackplugininstall/fullplugin/onboarding/compose/state/LoadedState.kt index cf146e3ee1c4..9e68ae5815de 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/jpfullplugininstall/onboarding/compose/state/LoadedState.kt +++ b/WordPress/src/main/java/org/wordpress/android/ui/jetpackplugininstall/fullplugin/onboarding/compose/state/LoadedState.kt @@ -1,4 +1,4 @@ -package org.wordpress.android.ui.jpfullplugininstall.onboarding.compose.state +package org.wordpress.android.ui.jetpackplugininstall.fullplugin.onboarding.compose.state import android.content.res.Configuration import androidx.compose.foundation.layout.Arrangement @@ -27,10 +27,10 @@ import org.wordpress.android.ui.compose.components.buttons.SecondaryButton import org.wordpress.android.ui.compose.components.text.Title import org.wordpress.android.ui.compose.theme.AppTheme import org.wordpress.android.ui.compose.unit.Margin -import org.wordpress.android.ui.jpfullplugininstall.onboarding.JetpackFullPluginInstallOnboardingViewModel.UiState -import org.wordpress.android.ui.jpfullplugininstall.onboarding.compose.component.JPInstallFullPluginAnimation -import org.wordpress.android.ui.jpfullplugininstall.onboarding.compose.component.PluginDescription -import org.wordpress.android.ui.jpfullplugininstall.onboarding.compose.component.TermsAndConditions +import org.wordpress.android.ui.jetpackplugininstall.fullplugin.onboarding.JetpackFullPluginInstallOnboardingViewModel.UiState +import org.wordpress.android.ui.jetpackplugininstall.fullplugin.onboarding.compose.component.JPInstallFullPluginAnimation +import org.wordpress.android.ui.jetpackplugininstall.fullplugin.onboarding.compose.component.PluginDescription +import org.wordpress.android.ui.jetpackplugininstall.fullplugin.onboarding.compose.component.TermsAndConditions @Composable fun LoadedState( diff --git a/WordPress/src/main/java/org/wordpress/android/ui/jpfullplugininstall/install/UiState.kt b/WordPress/src/main/java/org/wordpress/android/ui/jetpackplugininstall/install/UiState.kt similarity index 97% rename from WordPress/src/main/java/org/wordpress/android/ui/jpfullplugininstall/install/UiState.kt rename to WordPress/src/main/java/org/wordpress/android/ui/jetpackplugininstall/install/UiState.kt index 458d30fb495b..c5c33a223115 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/jpfullplugininstall/install/UiState.kt +++ b/WordPress/src/main/java/org/wordpress/android/ui/jetpackplugininstall/install/UiState.kt @@ -1,4 +1,4 @@ -package org.wordpress.android.ui.jpfullplugininstall.install +package org.wordpress.android.ui.jetpackplugininstall.install import androidx.annotation.DrawableRes import androidx.annotation.StringRes diff --git a/WordPress/src/main/java/org/wordpress/android/ui/jpfullplugininstall/install/JetpackPluginInstallScreen.kt b/WordPress/src/main/java/org/wordpress/android/ui/jetpackplugininstall/install/compose/JetpackPluginInstallScreen.kt similarity index 80% rename from WordPress/src/main/java/org/wordpress/android/ui/jpfullplugininstall/install/JetpackPluginInstallScreen.kt rename to WordPress/src/main/java/org/wordpress/android/ui/jetpackplugininstall/install/compose/JetpackPluginInstallScreen.kt index 738ed7eeb418..334c51132fbc 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/jpfullplugininstall/install/JetpackPluginInstallScreen.kt +++ b/WordPress/src/main/java/org/wordpress/android/ui/jetpackplugininstall/install/compose/JetpackPluginInstallScreen.kt @@ -1,15 +1,15 @@ -package org.wordpress.android.ui.jpfullplugininstall.install +package org.wordpress.android.ui.jetpackplugininstall.install.compose import androidx.compose.material.Scaffold import androidx.compose.runtime.Composable import androidx.compose.ui.res.stringResource import org.wordpress.android.ui.compose.components.MainTopAppBar import org.wordpress.android.ui.compose.components.NavigationIcons -import org.wordpress.android.ui.jpfullplugininstall.install.compose.state.DoneState -import org.wordpress.android.ui.jpfullplugininstall.install.compose.state.ErrorState -import org.wordpress.android.ui.jpfullplugininstall.install.compose.state.InitialState -import org.wordpress.android.ui.jpfullplugininstall.install.compose.state.InstallingState - +import org.wordpress.android.ui.jetpackplugininstall.install.UiState +import org.wordpress.android.ui.jetpackplugininstall.install.compose.state.DoneState +import org.wordpress.android.ui.jetpackplugininstall.install.compose.state.ErrorState +import org.wordpress.android.ui.jetpackplugininstall.install.compose.state.InitialState +import org.wordpress.android.ui.jetpackplugininstall.install.compose.state.InstallingState @Composable fun JetpackPluginInstallScreen( uiState: UiState, diff --git a/WordPress/src/main/java/org/wordpress/android/ui/jpfullplugininstall/install/compose/state/BaseState.kt b/WordPress/src/main/java/org/wordpress/android/ui/jetpackplugininstall/install/compose/state/BaseState.kt similarity index 96% rename from WordPress/src/main/java/org/wordpress/android/ui/jpfullplugininstall/install/compose/state/BaseState.kt rename to WordPress/src/main/java/org/wordpress/android/ui/jetpackplugininstall/install/compose/state/BaseState.kt index dbef731d6f10..4cd0d6b292ca 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/jpfullplugininstall/install/compose/state/BaseState.kt +++ b/WordPress/src/main/java/org/wordpress/android/ui/jetpackplugininstall/install/compose/state/BaseState.kt @@ -1,4 +1,4 @@ -package org.wordpress.android.ui.jpfullplugininstall.install.compose.state +package org.wordpress.android.ui.jetpackplugininstall.install.compose.state import android.content.res.Configuration import androidx.compose.foundation.Image @@ -30,7 +30,7 @@ import org.wordpress.android.R import org.wordpress.android.ui.compose.components.ContentAlphaProvider import org.wordpress.android.ui.compose.theme.AppTheme import org.wordpress.android.ui.compose.unit.Margin -import org.wordpress.android.ui.jpfullplugininstall.install.UiState +import org.wordpress.android.ui.jetpackplugininstall.install.UiState import org.wordpress.android.util.extensions.fixWidows private val TitleTextStyle diff --git a/WordPress/src/main/java/org/wordpress/android/ui/jpfullplugininstall/install/compose/state/DoneState.kt b/WordPress/src/main/java/org/wordpress/android/ui/jetpackplugininstall/install/compose/state/DoneState.kt similarity index 90% rename from WordPress/src/main/java/org/wordpress/android/ui/jpfullplugininstall/install/compose/state/DoneState.kt rename to WordPress/src/main/java/org/wordpress/android/ui/jetpackplugininstall/install/compose/state/DoneState.kt index a1d9659144fa..dd8bbf92183e 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/jpfullplugininstall/install/compose/state/DoneState.kt +++ b/WordPress/src/main/java/org/wordpress/android/ui/jetpackplugininstall/install/compose/state/DoneState.kt @@ -1,4 +1,4 @@ -package org.wordpress.android.ui.jpfullplugininstall.install.compose.state +package org.wordpress.android.ui.jetpackplugininstall.install.compose.state import android.content.res.Configuration import androidx.compose.runtime.Composable @@ -9,7 +9,7 @@ import org.wordpress.android.R import org.wordpress.android.ui.compose.components.buttons.ButtonSize import org.wordpress.android.ui.compose.components.buttons.PrimaryButton import org.wordpress.android.ui.compose.theme.AppTheme -import org.wordpress.android.ui.jpfullplugininstall.install.UiState +import org.wordpress.android.ui.jetpackplugininstall.install.UiState @Composable fun DoneState( diff --git a/WordPress/src/main/java/org/wordpress/android/ui/jpfullplugininstall/install/compose/state/ErrorState.kt b/WordPress/src/main/java/org/wordpress/android/ui/jetpackplugininstall/install/compose/state/ErrorState.kt similarity index 93% rename from WordPress/src/main/java/org/wordpress/android/ui/jpfullplugininstall/install/compose/state/ErrorState.kt rename to WordPress/src/main/java/org/wordpress/android/ui/jetpackplugininstall/install/compose/state/ErrorState.kt index 3a8f33394804..33d3dab3d9fa 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/jpfullplugininstall/install/compose/state/ErrorState.kt +++ b/WordPress/src/main/java/org/wordpress/android/ui/jetpackplugininstall/install/compose/state/ErrorState.kt @@ -1,4 +1,4 @@ -package org.wordpress.android.ui.jpfullplugininstall.install.compose.state +package org.wordpress.android.ui.jetpackplugininstall.install.compose.state import android.content.res.Configuration import androidx.compose.foundation.layout.Spacer @@ -14,7 +14,7 @@ import org.wordpress.android.ui.compose.components.buttons.ButtonSize import org.wordpress.android.ui.compose.components.buttons.PrimaryButton import org.wordpress.android.ui.compose.components.buttons.SecondaryButton import org.wordpress.android.ui.compose.theme.AppTheme -import org.wordpress.android.ui.jpfullplugininstall.install.UiState +import org.wordpress.android.ui.jetpackplugininstall.install.UiState @Composable fun ErrorState( diff --git a/WordPress/src/main/java/org/wordpress/android/ui/jpfullplugininstall/install/compose/state/InitialState.kt b/WordPress/src/main/java/org/wordpress/android/ui/jetpackplugininstall/install/compose/state/InitialState.kt similarity index 90% rename from WordPress/src/main/java/org/wordpress/android/ui/jpfullplugininstall/install/compose/state/InitialState.kt rename to WordPress/src/main/java/org/wordpress/android/ui/jetpackplugininstall/install/compose/state/InitialState.kt index 6ec463139e75..69f376f6271c 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/jpfullplugininstall/install/compose/state/InitialState.kt +++ b/WordPress/src/main/java/org/wordpress/android/ui/jetpackplugininstall/install/compose/state/InitialState.kt @@ -1,4 +1,4 @@ -package org.wordpress.android.ui.jpfullplugininstall.install.compose.state +package org.wordpress.android.ui.jetpackplugininstall.install.compose.state import android.content.res.Configuration import androidx.compose.runtime.Composable @@ -9,7 +9,7 @@ import org.wordpress.android.R import org.wordpress.android.ui.compose.components.buttons.ButtonSize import org.wordpress.android.ui.compose.components.buttons.PrimaryButton import org.wordpress.android.ui.compose.theme.AppTheme -import org.wordpress.android.ui.jpfullplugininstall.install.UiState +import org.wordpress.android.ui.jetpackplugininstall.install.UiState @Composable fun InitialState( diff --git a/WordPress/src/main/java/org/wordpress/android/ui/jpfullplugininstall/install/compose/state/InstallingState.kt b/WordPress/src/main/java/org/wordpress/android/ui/jetpackplugininstall/install/compose/state/InstallingState.kt similarity index 88% rename from WordPress/src/main/java/org/wordpress/android/ui/jpfullplugininstall/install/compose/state/InstallingState.kt rename to WordPress/src/main/java/org/wordpress/android/ui/jetpackplugininstall/install/compose/state/InstallingState.kt index 9317bdd08269..e9dededb549e 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/jpfullplugininstall/install/compose/state/InstallingState.kt +++ b/WordPress/src/main/java/org/wordpress/android/ui/jetpackplugininstall/install/compose/state/InstallingState.kt @@ -1,4 +1,4 @@ -package org.wordpress.android.ui.jpfullplugininstall.install.compose.state +package org.wordpress.android.ui.jetpackplugininstall.install.compose.state import android.content.res.Configuration import androidx.compose.runtime.Composable @@ -7,7 +7,7 @@ import androidx.compose.ui.tooling.preview.Preview import org.wordpress.android.ui.compose.components.buttons.ButtonSize import org.wordpress.android.ui.compose.components.buttons.PrimaryButton import org.wordpress.android.ui.compose.theme.AppTheme -import org.wordpress.android.ui.jpfullplugininstall.install.UiState +import org.wordpress.android.ui.jetpackplugininstall.install.UiState @Composable fun InstallingState( diff --git a/WordPress/src/main/java/org/wordpress/android/ui/JetpackRemoteInstallActivity.kt b/WordPress/src/main/java/org/wordpress/android/ui/jetpackplugininstall/remoteplugin/JetpackRemoteInstallActivity.kt similarity index 83% rename from WordPress/src/main/java/org/wordpress/android/ui/JetpackRemoteInstallActivity.kt rename to WordPress/src/main/java/org/wordpress/android/ui/jetpackplugininstall/remoteplugin/JetpackRemoteInstallActivity.kt index e6f798526173..78248a48b74f 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/JetpackRemoteInstallActivity.kt +++ b/WordPress/src/main/java/org/wordpress/android/ui/jetpackplugininstall/remoteplugin/JetpackRemoteInstallActivity.kt @@ -1,4 +1,4 @@ -package org.wordpress.android.ui +package org.wordpress.android.ui.jetpackplugininstall.remoteplugin import android.app.Activity import android.content.Intent @@ -12,16 +12,21 @@ import org.wordpress.android.WordPress import org.wordpress.android.analytics.AnalyticsTracker.Stat.INSTALL_JETPACK_CANCELLED import org.wordpress.android.fluxc.model.SiteModel import org.wordpress.android.login.LoginMode +import org.wordpress.android.ui.ActivityLauncher +import org.wordpress.android.ui.JetpackConnectionSource import org.wordpress.android.ui.JetpackConnectionUtils.trackWithSource -import org.wordpress.android.ui.JetpackRemoteInstallViewModel.JetpackResultActionData.Action.CONNECT -import org.wordpress.android.ui.JetpackRemoteInstallViewModel.JetpackResultActionData.Action.CONTACT_SUPPORT -import org.wordpress.android.ui.JetpackRemoteInstallViewModel.JetpackResultActionData.Action.LOGIN -import org.wordpress.android.ui.JetpackRemoteInstallViewModel.JetpackResultActionData.Action.MANUAL_INSTALL +import org.wordpress.android.ui.JetpackConnectionWebViewActivity +import org.wordpress.android.ui.LocaleAwareActivity +import org.wordpress.android.ui.RequestCodes +import org.wordpress.android.ui.jetpackplugininstall.remoteplugin.JetpackRemoteInstallViewModel.JetpackResultActionData.Action.CONNECT +import org.wordpress.android.ui.jetpackplugininstall.remoteplugin.JetpackRemoteInstallViewModel.JetpackResultActionData.Action.CONTACT_SUPPORT +import org.wordpress.android.ui.jetpackplugininstall.remoteplugin.JetpackRemoteInstallViewModel.JetpackResultActionData.Action.LOGIN +import org.wordpress.android.ui.jetpackplugininstall.remoteplugin.JetpackRemoteInstallViewModel.JetpackResultActionData.Action.MANUAL_INSTALL import org.wordpress.android.ui.accounts.HelpActivity import org.wordpress.android.ui.accounts.LoginActivity import org.wordpress.android.ui.compose.theme.AppTheme -import org.wordpress.android.ui.jpfullplugininstall.install.JetpackPluginInstallScreen -import org.wordpress.android.ui.jpfullplugininstall.install.UiState +import org.wordpress.android.ui.jetpackplugininstall.install.compose.JetpackPluginInstallScreen +import org.wordpress.android.ui.jetpackplugininstall.install.UiState import org.wordpress.android.util.extensions.setContent @AndroidEntryPoint diff --git a/WordPress/src/main/java/org/wordpress/android/ui/JetpackRemoteInstallViewModel.kt b/WordPress/src/main/java/org/wordpress/android/ui/jetpackplugininstall/remoteplugin/JetpackRemoteInstallViewModel.kt similarity index 85% rename from WordPress/src/main/java/org/wordpress/android/ui/JetpackRemoteInstallViewModel.kt rename to WordPress/src/main/java/org/wordpress/android/ui/jetpackplugininstall/remoteplugin/JetpackRemoteInstallViewModel.kt index dc61c7b6770d..7a4cbf7acea0 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/JetpackRemoteInstallViewModel.kt +++ b/WordPress/src/main/java/org/wordpress/android/ui/jetpackplugininstall/remoteplugin/JetpackRemoteInstallViewModel.kt @@ -1,4 +1,4 @@ -package org.wordpress.android.ui +package org.wordpress.android.ui.jetpackplugininstall.remoteplugin import androidx.lifecycle.LiveData import androidx.lifecycle.MutableLiveData @@ -17,16 +17,16 @@ import org.wordpress.android.fluxc.store.AccountStore import org.wordpress.android.fluxc.store.JetpackStore import org.wordpress.android.fluxc.store.JetpackStore.OnJetpackInstalled import org.wordpress.android.fluxc.store.SiteStore -import org.wordpress.android.ui.JetpackRemoteInstallViewModel.JetpackResultActionData.Action -import org.wordpress.android.ui.JetpackRemoteInstallViewModel.JetpackResultActionData.Action.CONNECT -import org.wordpress.android.ui.JetpackRemoteInstallViewModel.JetpackResultActionData.Action.CONTACT_SUPPORT -import org.wordpress.android.ui.JetpackRemoteInstallViewModel.JetpackResultActionData.Action.LOGIN -import org.wordpress.android.ui.JetpackRemoteInstallViewModel.JetpackResultActionData.Action.MANUAL_INSTALL -import org.wordpress.android.ui.JetpackRemoteInstallViewModel.Type.ERROR -import org.wordpress.android.ui.JetpackRemoteInstallViewModel.Type.INSTALLED -import org.wordpress.android.ui.JetpackRemoteInstallViewModel.Type.INSTALLING -import org.wordpress.android.ui.JetpackRemoteInstallViewModel.Type.START -import org.wordpress.android.ui.jpfullplugininstall.install.UiState +import org.wordpress.android.ui.jetpackplugininstall.remoteplugin.JetpackRemoteInstallViewModel.JetpackResultActionData.Action +import org.wordpress.android.ui.jetpackplugininstall.remoteplugin.JetpackRemoteInstallViewModel.JetpackResultActionData.Action.CONNECT +import org.wordpress.android.ui.jetpackplugininstall.remoteplugin.JetpackRemoteInstallViewModel.JetpackResultActionData.Action.CONTACT_SUPPORT +import org.wordpress.android.ui.jetpackplugininstall.remoteplugin.JetpackRemoteInstallViewModel.JetpackResultActionData.Action.LOGIN +import org.wordpress.android.ui.jetpackplugininstall.remoteplugin.JetpackRemoteInstallViewModel.JetpackResultActionData.Action.MANUAL_INSTALL +import org.wordpress.android.ui.jetpackplugininstall.remoteplugin.JetpackRemoteInstallViewModel.Type.ERROR +import org.wordpress.android.ui.jetpackplugininstall.remoteplugin.JetpackRemoteInstallViewModel.Type.INSTALLED +import org.wordpress.android.ui.jetpackplugininstall.remoteplugin.JetpackRemoteInstallViewModel.Type.INSTALLING +import org.wordpress.android.ui.jetpackplugininstall.remoteplugin.JetpackRemoteInstallViewModel.Type.START +import org.wordpress.android.ui.jetpackplugininstall.install.UiState import org.wordpress.android.viewmodel.SingleLiveEvent import javax.inject.Inject diff --git a/WordPress/src/main/java/org/wordpress/android/ui/mysite/MySiteViewModel.kt b/WordPress/src/main/java/org/wordpress/android/ui/mysite/MySiteViewModel.kt index d4c53359bc05..5cb076aba978 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/mysite/MySiteViewModel.kt +++ b/WordPress/src/main/java/org/wordpress/android/ui/mysite/MySiteViewModel.kt @@ -45,7 +45,7 @@ import org.wordpress.android.ui.bloggingprompts.BloggingPromptsPostTagProvider import org.wordpress.android.ui.bloggingprompts.BloggingPromptsSettingsHelper import org.wordpress.android.ui.jetpackoverlay.JetpackFeatureRemovalOverlayUtil import org.wordpress.android.ui.jetpackoverlay.JetpackFeatureRemovalOverlayUtil.JetpackFeatureCollectionOverlaySource.FEATURE_CARD -import org.wordpress.android.ui.jpfullplugininstall.GetShowJetpackFullPluginInstallOnboardingUseCase +import org.wordpress.android.ui.jetpackplugininstall.fullplugin.GetShowJetpackFullPluginInstallOnboardingUseCase import org.wordpress.android.ui.mysite.MySiteCardAndItem.Card.DashboardCards import org.wordpress.android.ui.mysite.MySiteCardAndItem.Card.DomainRegistrationCard import org.wordpress.android.ui.mysite.MySiteCardAndItem.Card.JetpackFeatureCard diff --git a/WordPress/src/main/java/org/wordpress/android/ui/mysite/cards/jpfullplugininstall/JetpackInstallFullPluginCardViewHolder.kt b/WordPress/src/main/java/org/wordpress/android/ui/mysite/cards/jpfullplugininstall/JetpackInstallFullPluginCardViewHolder.kt index de38eac74dd6..5649a8d31daf 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/mysite/cards/jpfullplugininstall/JetpackInstallFullPluginCardViewHolder.kt +++ b/WordPress/src/main/java/org/wordpress/android/ui/mysite/cards/jpfullplugininstall/JetpackInstallFullPluginCardViewHolder.kt @@ -6,7 +6,7 @@ import androidx.appcompat.widget.PopupMenu import org.wordpress.android.R import org.wordpress.android.databinding.JpInstallFullPluginCardBinding import org.wordpress.android.ui.compose.theme.AppTheme -import org.wordpress.android.ui.jpfullplugininstall.onboarding.compose.component.PluginDescription +import org.wordpress.android.ui.jetpackplugininstall.fullplugin.onboarding.compose.component.PluginDescription import org.wordpress.android.ui.mysite.MySiteCardAndItem.Card.JetpackInstallFullPluginCard import org.wordpress.android.ui.mysite.MySiteCardAndItemViewHolder import org.wordpress.android.ui.utils.ListItemInteraction diff --git a/WordPress/src/main/java/org/wordpress/android/ui/mysite/tabs/MySiteTabFragment.kt b/WordPress/src/main/java/org/wordpress/android/ui/mysite/tabs/MySiteTabFragment.kt index 3bfa3ba7352f..e2aaec738564 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/mysite/tabs/MySiteTabFragment.kt +++ b/WordPress/src/main/java/org/wordpress/android/ui/mysite/tabs/MySiteTabFragment.kt @@ -36,7 +36,7 @@ import org.wordpress.android.ui.domains.DomainRegistrationActivity.Companion.RES import org.wordpress.android.ui.domains.DomainRegistrationActivity.DomainRegistrationPurpose.CTA_DOMAIN_CREDIT_REDEMPTION import org.wordpress.android.ui.jetpackoverlay.JetpackFeatureFullScreenOverlayFragment import org.wordpress.android.ui.jetpackoverlay.JetpackFeatureRemovalOverlayUtil.JetpackFeatureCollectionOverlaySource -import org.wordpress.android.ui.jpfullplugininstall.onboarding.JetpackFullPluginInstallOnboardingDialogFragment +import org.wordpress.android.ui.jetpackplugininstall.fullplugin.onboarding.JetpackFullPluginInstallOnboardingDialogFragment import org.wordpress.android.ui.main.SitePickerActivity import org.wordpress.android.ui.main.WPMainActivity import org.wordpress.android.ui.main.jetpack.migration.JetpackMigrationActivity diff --git a/WordPress/src/test/java/org/wordpress/android/ui/jpfullplugininstall/GetShowJetpackFullPluginInstallOnboardingUseCaseTest.kt b/WordPress/src/test/java/org/wordpress/android/ui/jetpackplugininstall/fullplugin/GetShowJetpackFullPluginInstallOnboardingUseCaseTest.kt similarity index 97% rename from WordPress/src/test/java/org/wordpress/android/ui/jpfullplugininstall/GetShowJetpackFullPluginInstallOnboardingUseCaseTest.kt rename to WordPress/src/test/java/org/wordpress/android/ui/jetpackplugininstall/fullplugin/GetShowJetpackFullPluginInstallOnboardingUseCaseTest.kt index e6198b5eda22..1ea37bbf86b8 100644 --- a/WordPress/src/test/java/org/wordpress/android/ui/jpfullplugininstall/GetShowJetpackFullPluginInstallOnboardingUseCaseTest.kt +++ b/WordPress/src/test/java/org/wordpress/android/ui/jetpackplugininstall/fullplugin/GetShowJetpackFullPluginInstallOnboardingUseCaseTest.kt @@ -1,4 +1,4 @@ -package org.wordpress.android.ui.jpfullplugininstall +package org.wordpress.android.ui.jetpackplugininstall.fullplugin import org.assertj.core.api.Assertions.assertThat import org.junit.Test diff --git a/WordPress/src/test/java/org/wordpress/android/ui/jpfullplugininstall/install/JetpackFullPluginInstallAnalyticsTrackerTest.kt b/WordPress/src/test/java/org/wordpress/android/ui/jetpackplugininstall/fullplugin/install/JetpackFullPluginInstallAnalyticsTrackerTest.kt similarity index 91% rename from WordPress/src/test/java/org/wordpress/android/ui/jpfullplugininstall/install/JetpackFullPluginInstallAnalyticsTrackerTest.kt rename to WordPress/src/test/java/org/wordpress/android/ui/jetpackplugininstall/fullplugin/install/JetpackFullPluginInstallAnalyticsTrackerTest.kt index 7d464e6f4257..5b5ce6bdc514 100644 --- a/WordPress/src/test/java/org/wordpress/android/ui/jpfullplugininstall/install/JetpackFullPluginInstallAnalyticsTrackerTest.kt +++ b/WordPress/src/test/java/org/wordpress/android/ui/jetpackplugininstall/fullplugin/install/JetpackFullPluginInstallAnalyticsTrackerTest.kt @@ -1,10 +1,10 @@ -package org.wordpress.android.ui.jpfullplugininstall.install +package org.wordpress.android.ui.jetpackplugininstall.fullplugin.install import org.junit.Test import org.mockito.kotlin.mock import org.mockito.kotlin.verify import org.wordpress.android.analytics.AnalyticsTracker.Stat -import org.wordpress.android.ui.jpfullplugininstall.install.JetpackFullPluginInstallAnalyticsTracker.Status +import org.wordpress.android.ui.jetpackplugininstall.fullplugin.install.JetpackFullPluginInstallAnalyticsTracker.Status import org.wordpress.android.util.analytics.AnalyticsTrackerWrapper class JetpackFullPluginInstallAnalyticsTrackerTest { diff --git a/WordPress/src/test/java/org/wordpress/android/ui/jpfullplugininstall/install/JetpackFullPluginInstallUiStateMapperTest.kt b/WordPress/src/test/java/org/wordpress/android/ui/jetpackplugininstall/fullplugin/install/JetpackFullPluginInstallUiStateMapperTest.kt similarity index 97% rename from WordPress/src/test/java/org/wordpress/android/ui/jpfullplugininstall/install/JetpackFullPluginInstallUiStateMapperTest.kt rename to WordPress/src/test/java/org/wordpress/android/ui/jetpackplugininstall/fullplugin/install/JetpackFullPluginInstallUiStateMapperTest.kt index 9f713c64a3ab..031206c793b1 100644 --- a/WordPress/src/test/java/org/wordpress/android/ui/jpfullplugininstall/install/JetpackFullPluginInstallUiStateMapperTest.kt +++ b/WordPress/src/test/java/org/wordpress/android/ui/jetpackplugininstall/fullplugin/install/JetpackFullPluginInstallUiStateMapperTest.kt @@ -1,4 +1,4 @@ -package org.wordpress.android.ui.jpfullplugininstall.install +package org.wordpress.android.ui.jetpackplugininstall.fullplugin.install import org.assertj.core.api.Assertions.assertThat import org.junit.Test diff --git a/WordPress/src/test/java/org/wordpress/android/ui/jpfullplugininstall/install/JetpackFullPluginInstallViewModelTest.kt b/WordPress/src/test/java/org/wordpress/android/ui/jetpackplugininstall/fullplugin/install/JetpackFullPluginInstallViewModelTest.kt similarity index 96% rename from WordPress/src/test/java/org/wordpress/android/ui/jpfullplugininstall/install/JetpackFullPluginInstallViewModelTest.kt rename to WordPress/src/test/java/org/wordpress/android/ui/jetpackplugininstall/fullplugin/install/JetpackFullPluginInstallViewModelTest.kt index ef8ecb8f8372..37cf988262b7 100644 --- a/WordPress/src/test/java/org/wordpress/android/ui/jpfullplugininstall/install/JetpackFullPluginInstallViewModelTest.kt +++ b/WordPress/src/test/java/org/wordpress/android/ui/jetpackplugininstall/fullplugin/install/JetpackFullPluginInstallViewModelTest.kt @@ -1,4 +1,4 @@ -package org.wordpress.android.ui.jpfullplugininstall.install +package org.wordpress.android.ui.jetpackplugininstall.fullplugin.install import kotlinx.coroutines.ExperimentalCoroutinesApi import kotlinx.coroutines.flow.collectLatest @@ -19,7 +19,8 @@ import org.wordpress.android.fluxc.annotations.action.Action import org.wordpress.android.fluxc.model.SiteModel import org.wordpress.android.fluxc.store.PluginStore import org.wordpress.android.ui.accounts.HelpActivity -import org.wordpress.android.ui.jpfullplugininstall.install.JetpackFullPluginInstallAnalyticsTracker.* +import org.wordpress.android.ui.jetpackplugininstall.fullplugin.install.JetpackFullPluginInstallAnalyticsTracker.Status +import org.wordpress.android.ui.jetpackplugininstall.install.UiState import org.wordpress.android.ui.mysite.SelectedSiteRepository @ExperimentalCoroutinesApi diff --git a/WordPress/src/test/java/org/wordpress/android/ui/jpfullplugininstall/onboarding/JetpackFullPluginInstallOnboardingAnalyticsTrackerTest.kt b/WordPress/src/test/java/org/wordpress/android/ui/jetpackplugininstall/fullplugin/onboarding/JetpackFullPluginInstallOnboardingAnalyticsTrackerTest.kt similarity index 94% rename from WordPress/src/test/java/org/wordpress/android/ui/jpfullplugininstall/onboarding/JetpackFullPluginInstallOnboardingAnalyticsTrackerTest.kt rename to WordPress/src/test/java/org/wordpress/android/ui/jetpackplugininstall/fullplugin/onboarding/JetpackFullPluginInstallOnboardingAnalyticsTrackerTest.kt index 20f13f7c0710..024b3a01e8c0 100644 --- a/WordPress/src/test/java/org/wordpress/android/ui/jpfullplugininstall/onboarding/JetpackFullPluginInstallOnboardingAnalyticsTrackerTest.kt +++ b/WordPress/src/test/java/org/wordpress/android/ui/jetpackplugininstall/fullplugin/onboarding/JetpackFullPluginInstallOnboardingAnalyticsTrackerTest.kt @@ -1,4 +1,4 @@ -package org.wordpress.android.ui.jpfullplugininstall.onboarding +package org.wordpress.android.ui.jetpackplugininstall.fullplugin.onboarding import org.junit.Test import org.mockito.kotlin.mock diff --git a/WordPress/src/test/java/org/wordpress/android/ui/jpfullplugininstall/JetpackFullPluginInstallOnboardingUiStateMapperTest.kt b/WordPress/src/test/java/org/wordpress/android/ui/jetpackplugininstall/fullplugin/onboarding/JetpackFullPluginInstallOnboardingUiStateMapperTest.kt similarity index 83% rename from WordPress/src/test/java/org/wordpress/android/ui/jpfullplugininstall/JetpackFullPluginInstallOnboardingUiStateMapperTest.kt rename to WordPress/src/test/java/org/wordpress/android/ui/jetpackplugininstall/fullplugin/onboarding/JetpackFullPluginInstallOnboardingUiStateMapperTest.kt index efa267f5310c..9e9a958f5916 100644 --- a/WordPress/src/test/java/org/wordpress/android/ui/jpfullplugininstall/JetpackFullPluginInstallOnboardingUiStateMapperTest.kt +++ b/WordPress/src/test/java/org/wordpress/android/ui/jetpackplugininstall/fullplugin/onboarding/JetpackFullPluginInstallOnboardingUiStateMapperTest.kt @@ -1,4 +1,4 @@ -package org.wordpress.android.ui.jpfullplugininstall +package org.wordpress.android.ui.jetpackplugininstall.fullplugin.onboarding import kotlinx.coroutines.ExperimentalCoroutinesApi import org.junit.Test @@ -6,8 +6,7 @@ import org.mockito.kotlin.mock import org.mockito.kotlin.whenever import org.wordpress.android.BaseUnitTest import org.wordpress.android.fluxc.model.SiteModel -import org.wordpress.android.ui.jpfullplugininstall.onboarding.JetpackFullPluginInstallOnboardingUiStateMapper -import org.wordpress.android.ui.jpfullplugininstall.onboarding.JetpackFullPluginInstallOnboardingViewModel.UiState +import org.wordpress.android.ui.jetpackplugininstall.fullplugin.onboarding.JetpackFullPluginInstallOnboardingViewModel.UiState import org.wordpress.android.ui.mysite.SelectedSiteRepository import kotlin.test.assertEquals diff --git a/WordPress/src/test/java/org/wordpress/android/ui/jpfullplugininstall/onboarding/JetpackFullPluginInstallOnboardingViewModelTest.kt b/WordPress/src/test/java/org/wordpress/android/ui/jetpackplugininstall/fullplugin/onboarding/JetpackFullPluginInstallOnboardingViewModelTest.kt similarity index 93% rename from WordPress/src/test/java/org/wordpress/android/ui/jpfullplugininstall/onboarding/JetpackFullPluginInstallOnboardingViewModelTest.kt rename to WordPress/src/test/java/org/wordpress/android/ui/jetpackplugininstall/fullplugin/onboarding/JetpackFullPluginInstallOnboardingViewModelTest.kt index 4cdd4375dea0..2c5c53c98265 100644 --- a/WordPress/src/test/java/org/wordpress/android/ui/jpfullplugininstall/onboarding/JetpackFullPluginInstallOnboardingViewModelTest.kt +++ b/WordPress/src/test/java/org/wordpress/android/ui/jetpackplugininstall/fullplugin/onboarding/JetpackFullPluginInstallOnboardingViewModelTest.kt @@ -1,4 +1,4 @@ -package org.wordpress.android.ui.jpfullplugininstall.onboarding +package org.wordpress.android.ui.jetpackplugininstall.fullplugin.onboarding import kotlinx.coroutines.ExperimentalCoroutinesApi import kotlinx.coroutines.flow.collectLatest @@ -11,8 +11,8 @@ import org.mockito.kotlin.whenever import org.wordpress.android.BaseUnitTest import org.wordpress.android.fluxc.model.SiteModel import org.wordpress.android.ui.accounts.HelpActivity -import org.wordpress.android.ui.jpfullplugininstall.onboarding.JetpackFullPluginInstallOnboardingViewModel.ActionEvent -import org.wordpress.android.ui.jpfullplugininstall.onboarding.JetpackFullPluginInstallOnboardingViewModel.UiState +import org.wordpress.android.ui.jetpackplugininstall.fullplugin.onboarding.JetpackFullPluginInstallOnboardingViewModel.ActionEvent +import org.wordpress.android.ui.jetpackplugininstall.fullplugin.onboarding.JetpackFullPluginInstallOnboardingViewModel.UiState import org.wordpress.android.ui.mysite.SelectedSiteRepository import org.wordpress.android.ui.prefs.AppPrefsWrapper diff --git a/WordPress/src/test/java/org/wordpress/android/ui/JetpackRemoteInstallViewModelTest.kt b/WordPress/src/test/java/org/wordpress/android/ui/jetpackplugininstall/remoteplugin/JetpackRemoteInstallViewModelTest.kt similarity index 96% rename from WordPress/src/test/java/org/wordpress/android/ui/JetpackRemoteInstallViewModelTest.kt rename to WordPress/src/test/java/org/wordpress/android/ui/jetpackplugininstall/remoteplugin/JetpackRemoteInstallViewModelTest.kt index 3d7d520d7515..918d97f8b727 100644 --- a/WordPress/src/test/java/org/wordpress/android/ui/JetpackRemoteInstallViewModelTest.kt +++ b/WordPress/src/test/java/org/wordpress/android/ui/jetpackplugininstall/remoteplugin/JetpackRemoteInstallViewModelTest.kt @@ -1,4 +1,4 @@ -package org.wordpress.android.ui +package org.wordpress.android.ui.jetpackplugininstall.remoteplugin import kotlinx.coroutines.ExperimentalCoroutinesApi import org.assertj.core.api.Assertions.assertThat @@ -24,8 +24,8 @@ import org.wordpress.android.fluxc.store.JetpackStore.JetpackInstallError import org.wordpress.android.fluxc.store.JetpackStore.JetpackInstallErrorType import org.wordpress.android.fluxc.store.JetpackStore.OnJetpackInstalled import org.wordpress.android.fluxc.store.SiteStore -import org.wordpress.android.ui.JetpackRemoteInstallViewModel.JetpackResultActionData -import org.wordpress.android.ui.jpfullplugininstall.install.UiState +import org.wordpress.android.ui.jetpackplugininstall.remoteplugin.JetpackRemoteInstallViewModel.JetpackResultActionData +import org.wordpress.android.ui.jetpackplugininstall.install.UiState @ExperimentalCoroutinesApi @RunWith(MockitoJUnitRunner::class) diff --git a/WordPress/src/test/java/org/wordpress/android/ui/mysite/MySiteViewModelTest.kt b/WordPress/src/test/java/org/wordpress/android/ui/mysite/MySiteViewModelTest.kt index a1592ef1ab18..c0c0d4f30fc8 100644 --- a/WordPress/src/test/java/org/wordpress/android/ui/mysite/MySiteViewModelTest.kt +++ b/WordPress/src/test/java/org/wordpress/android/ui/mysite/MySiteViewModelTest.kt @@ -57,7 +57,7 @@ import org.wordpress.android.ui.blaze.BlazeFlowSource import org.wordpress.android.ui.bloggingprompts.BloggingPromptsPostTagProvider import org.wordpress.android.ui.bloggingprompts.BloggingPromptsSettingsHelper import org.wordpress.android.ui.jetpackoverlay.JetpackFeatureRemovalOverlayUtil -import org.wordpress.android.ui.jpfullplugininstall.GetShowJetpackFullPluginInstallOnboardingUseCase +import org.wordpress.android.ui.jetpackplugininstall.fullplugin.GetShowJetpackFullPluginInstallOnboardingUseCase import org.wordpress.android.ui.mysite.MySiteCardAndItem.Card import org.wordpress.android.ui.mysite.MySiteCardAndItem.Card.DashboardCards import org.wordpress.android.ui.mysite.MySiteCardAndItem.Card.DashboardCards.DashboardCard From 746f0113fea0e065807a54ddaedbc2d1430d6557 Mon Sep 17 00:00:00 2001 From: Thomas Horta Date: Fri, 3 Mar 2023 12:23:31 -0300 Subject: [PATCH 055/856] fix checkstyle issues --- .../android/ui/JetpackConnectionWebViewActivity.java | 7 ++++++- .../install/JetpackFullPluginInstallViewModel.kt | 9 ++++++--- .../remoteplugin/JetpackRemoteInstallViewModel.kt | 2 +- 3 files changed, 13 insertions(+), 5 deletions(-) diff --git a/WordPress/src/main/java/org/wordpress/android/ui/JetpackConnectionWebViewActivity.java b/WordPress/src/main/java/org/wordpress/android/ui/JetpackConnectionWebViewActivity.java index 53ba39a6bc1a..6f9f1759c31f 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/JetpackConnectionWebViewActivity.java +++ b/WordPress/src/main/java/org/wordpress/android/ui/JetpackConnectionWebViewActivity.java @@ -44,7 +44,12 @@ public static void startJetpackConnectionFlow(Context context, JetpackConnection } } - public static void startManualFlow(Context context, JetpackConnectionSource source, SiteModel site, boolean authorized) { + public static void startManualFlow( + Context context, + JetpackConnectionSource source, + SiteModel site, + boolean authorized + ) { String url = "https://wordpress.com/jetpack/connect?" + "url=" + site.getUrl() + "&mobile_redirect=" + JETPACK_CONNECTION_DEEPLINK diff --git a/WordPress/src/main/java/org/wordpress/android/ui/jetpackplugininstall/fullplugin/install/JetpackFullPluginInstallViewModel.kt b/WordPress/src/main/java/org/wordpress/android/ui/jetpackplugininstall/fullplugin/install/JetpackFullPluginInstallViewModel.kt index 712eaa50dc07..d7938a780052 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/jetpackplugininstall/fullplugin/install/JetpackFullPluginInstallViewModel.kt +++ b/WordPress/src/main/java/org/wordpress/android/ui/jetpackplugininstall/fullplugin/install/JetpackFullPluginInstallViewModel.kt @@ -12,7 +12,10 @@ import org.wordpress.android.fluxc.Dispatcher import org.wordpress.android.fluxc.generated.PluginActionBuilder import org.wordpress.android.fluxc.generated.SiteActionBuilder import org.wordpress.android.fluxc.store.PluginStore +import org.wordpress.android.fluxc.store.PluginStore.OnSitePluginConfigured +import org.wordpress.android.fluxc.store.PluginStore.OnSitePluginInstalled import org.wordpress.android.fluxc.store.SiteStore +import org.wordpress.android.fluxc.store.SiteStore.OnSiteChanged import org.wordpress.android.modules.BG_THREAD import org.wordpress.android.ui.accounts.HelpActivity import org.wordpress.android.ui.jetpackplugininstall.fullplugin.install.JetpackFullPluginInstallAnalyticsTracker.Status @@ -97,7 +100,7 @@ class JetpackFullPluginInstallViewModel @Inject constructor( @Suppress("unused") @Subscribe(threadMode = ThreadMode.MAIN) - fun onSitePluginInstalled(event: PluginStore.OnSitePluginInstalled) { + fun onSitePluginInstalled(event: OnSitePluginInstalled) { if (event.isError) { AppLog.d( AppLog.T.PLUGINS, @@ -113,7 +116,7 @@ class JetpackFullPluginInstallViewModel @Inject constructor( @Suppress("unused") @Subscribe(threadMode = ThreadMode.MAIN) - fun onSitePluginConfigured(event: PluginStore.OnSitePluginConfigured) { + fun onSitePluginConfigured(event: OnSitePluginConfigured) { if (event.isError) { AppLog.d( AppLog.T.PLUGINS, @@ -129,7 +132,7 @@ class JetpackFullPluginInstallViewModel @Inject constructor( @Suppress("unused") @Subscribe(threadMode = ThreadMode.MAIN) - fun onSiteChanged(event: SiteStore.OnSiteChanged) { + fun onSiteChanged(event: OnSiteChanged) { val success = if (event.isError) { AppLog.d( AppLog.T.PLUGINS, diff --git a/WordPress/src/main/java/org/wordpress/android/ui/jetpackplugininstall/remoteplugin/JetpackRemoteInstallViewModel.kt b/WordPress/src/main/java/org/wordpress/android/ui/jetpackplugininstall/remoteplugin/JetpackRemoteInstallViewModel.kt index 7a4cbf7acea0..6e231b1b5dcc 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/jetpackplugininstall/remoteplugin/JetpackRemoteInstallViewModel.kt +++ b/WordPress/src/main/java/org/wordpress/android/ui/jetpackplugininstall/remoteplugin/JetpackRemoteInstallViewModel.kt @@ -59,7 +59,7 @@ class JetpackRemoteInstallViewModel private val dispatcher: Dispatcher, private val accountStore: AccountStore, private val siteStore: SiteStore, - //JetpackStore needs to be injected here as otherwise FluxC doesn't accept emitted events. + // JetpackStore needs to be injected here as otherwise FluxC doesn't accept emitted events. @Suppress("unused") private val jetpackStore: JetpackStore ) : ViewModel() { private val mutableViewState = MutableLiveData() From d108f8ae8d0f497ecb5a0aff60551816cdf82e0a Mon Sep 17 00:00:00 2001 From: Thomas Horta Date: Fri, 3 Mar 2023 14:32:39 -0300 Subject: [PATCH 056/856] fix lint and detekt issues --- .../install/JetpackFullPluginInstallViewModel.kt | 1 - .../src/main/res/drawable/bg_oval_white_24dp.xml | 11 ----------- WordPress/src/main/res/values/dimens.xml | 2 -- WordPress/src/main/res/values/stats_styles.xml | 9 --------- 4 files changed, 23 deletions(-) delete mode 100644 WordPress/src/main/res/drawable/bg_oval_white_24dp.xml diff --git a/WordPress/src/main/java/org/wordpress/android/ui/jetpackplugininstall/fullplugin/install/JetpackFullPluginInstallViewModel.kt b/WordPress/src/main/java/org/wordpress/android/ui/jetpackplugininstall/fullplugin/install/JetpackFullPluginInstallViewModel.kt index d7938a780052..c0785b902922 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/jetpackplugininstall/fullplugin/install/JetpackFullPluginInstallViewModel.kt +++ b/WordPress/src/main/java/org/wordpress/android/ui/jetpackplugininstall/fullplugin/install/JetpackFullPluginInstallViewModel.kt @@ -14,7 +14,6 @@ import org.wordpress.android.fluxc.generated.SiteActionBuilder import org.wordpress.android.fluxc.store.PluginStore import org.wordpress.android.fluxc.store.PluginStore.OnSitePluginConfigured import org.wordpress.android.fluxc.store.PluginStore.OnSitePluginInstalled -import org.wordpress.android.fluxc.store.SiteStore import org.wordpress.android.fluxc.store.SiteStore.OnSiteChanged import org.wordpress.android.modules.BG_THREAD import org.wordpress.android.ui.accounts.HelpActivity diff --git a/WordPress/src/main/res/drawable/bg_oval_white_24dp.xml b/WordPress/src/main/res/drawable/bg_oval_white_24dp.xml deleted file mode 100644 index f76c64025d50..000000000000 --- a/WordPress/src/main/res/drawable/bg_oval_white_24dp.xml +++ /dev/null @@ -1,11 +0,0 @@ - - - - - diff --git a/WordPress/src/main/res/values/dimens.xml b/WordPress/src/main/res/values/dimens.xml index ba8959fb0219..761bada9f00e 100644 --- a/WordPress/src/main/res/values/dimens.xml +++ b/WordPress/src/main/res/values/dimens.xml @@ -488,8 +488,6 @@ 250dp 290dp - 30dp - 88dp 64dp diff --git a/WordPress/src/main/res/values/stats_styles.xml b/WordPress/src/main/res/values/stats_styles.xml index ae4774f2c704..b7943b50bb21 100644 --- a/WordPress/src/main/res/values/stats_styles.xml +++ b/WordPress/src/main/res/values/stats_styles.xml @@ -12,15 +12,6 @@ @dimen/margin_extra_medium_large - - - - + + From 2f03ed5c3d45388aa5fc2d9e180804d397b094d4 Mon Sep 17 00:00:00 2001 From: Thomas Horta Date: Thu, 23 Mar 2023 20:06:35 -0300 Subject: [PATCH 371/856] show the fragment in site picker --- .../wordpress/android/ui/main/SitePickerActivity.java | 10 ++++++---- .../android/viewmodel/main/SitePickerViewModel.kt | 9 +++++++++ 2 files changed, 15 insertions(+), 4 deletions(-) diff --git a/WordPress/src/main/java/org/wordpress/android/ui/main/SitePickerActivity.java b/WordPress/src/main/java/org/wordpress/android/ui/main/SitePickerActivity.java index 7c92327a498c..308607a7400c 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/main/SitePickerActivity.java +++ b/WordPress/src/main/java/org/wordpress/android/ui/main/SitePickerActivity.java @@ -1,5 +1,6 @@ package org.wordpress.android.ui.main; +import dagger.hilt.android.AndroidEntryPoint; import android.app.Activity; import android.app.Dialog; import android.app.DialogFragment; @@ -43,6 +44,7 @@ import org.wordpress.android.ui.ActivityLauncher; import org.wordpress.android.ui.LocaleAwareActivity; import org.wordpress.android.ui.RequestCodes; +import org.wordpress.android.ui.jetpackoverlay.individualplugin.WPJetpackIndividualPluginFragment; import org.wordpress.android.ui.main.SitePickerAdapter.SiteList; import org.wordpress.android.ui.main.SitePickerAdapter.SitePickerMode; import org.wordpress.android.ui.main.SitePickerAdapter.SiteRecord; @@ -79,6 +81,7 @@ import static org.wordpress.android.util.WPSwipeToRefreshHelper.buildSwipeToRefreshHelper; +@AndroidEntryPoint public class SitePickerActivity extends LocaleAwareActivity implements SitePickerAdapter.OnSiteClickListener, SitePickerAdapter.OnSelectedCountChangedListener, @@ -221,11 +224,10 @@ public void onResume() { } private void onShowJetpackIndividualPluginOverlay(Boolean shouldShowJetpackIndividualPluginOverlay) { - // TODO thomashortadev temporary during development of #18114 if (shouldShowJetpackIndividualPluginOverlay) { - ToastUtils.showToast( - this, - "WP - Individual plugin overlay is enabled & user has sites with Individual plugins" + WPJetpackIndividualPluginFragment.newInstance().show( + getSupportFragmentManager(), + WPJetpackIndividualPluginFragment.TAG ); } } diff --git a/WordPress/src/main/java/org/wordpress/android/viewmodel/main/SitePickerViewModel.kt b/WordPress/src/main/java/org/wordpress/android/viewmodel/main/SitePickerViewModel.kt index 497df0dda413..4a7e57c0c6ed 100644 --- a/WordPress/src/main/java/org/wordpress/android/viewmodel/main/SitePickerViewModel.kt +++ b/WordPress/src/main/java/org/wordpress/android/viewmodel/main/SitePickerViewModel.kt @@ -4,6 +4,7 @@ import androidx.lifecycle.LiveData import androidx.lifecycle.MutableLiveData import androidx.lifecycle.ViewModel import androidx.lifecycle.viewModelScope +import kotlinx.coroutines.delay import kotlinx.coroutines.launch import org.wordpress.android.ui.jetpackoverlay.individualplugin.WPJetpackIndividualPluginHelper import org.wordpress.android.ui.main.SitePickerAdapter.SiteRecord @@ -31,7 +32,11 @@ class SitePickerViewModel @Inject constructor( private var siteForReblog: SiteRecord? = null fun checkJetpackIndividualPluginOverlayNeeded() { + // don't show if already shown + if (_showJetpackIndividualPluginOverlay.value == true) return + viewModelScope.launch { + delay(DELAY_BEFORE_SHOWING_JETPACK_INDIVIDUAL_PLUGIN_OVERLAY) _showJetpackIndividualPluginOverlay .postValue(wpJetpackIndividualPluginHelper.shouldShowJetpackIndividualPluginOverlay()) } @@ -88,4 +93,8 @@ class SitePickerViewModel @Inject constructor( object AskForSiteSelection : Action(ASK_FOR_SITE_SELECTION) } + + companion object { + private const val DELAY_BEFORE_SHOWING_JETPACK_INDIVIDUAL_PLUGIN_OVERLAY = 500L + } } From f50768ac1a7c925c6b0a50ca7ef0671f3217a0ae Mon Sep 17 00:00:00 2001 From: Thomas Horta Date: Thu, 23 Mar 2023 20:25:56 -0300 Subject: [PATCH 372/856] improve showing the overlay --- .../individualplugin/WPJetpackIndividualPluginFragment.kt | 6 ++++++ .../org/wordpress/android/ui/main/SitePickerActivity.java | 5 +---- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/WordPress/src/main/java/org/wordpress/android/ui/jetpackoverlay/individualplugin/WPJetpackIndividualPluginFragment.kt b/WordPress/src/main/java/org/wordpress/android/ui/jetpackoverlay/individualplugin/WPJetpackIndividualPluginFragment.kt index a3d94887a20e..71e3cb21c573 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/jetpackoverlay/individualplugin/WPJetpackIndividualPluginFragment.kt +++ b/WordPress/src/main/java/org/wordpress/android/ui/jetpackoverlay/individualplugin/WPJetpackIndividualPluginFragment.kt @@ -11,6 +11,7 @@ import androidx.compose.runtime.collectAsState import androidx.compose.runtime.getValue import androidx.compose.ui.platform.ComposeView import androidx.fragment.app.DialogFragment +import androidx.fragment.app.FragmentManager import androidx.fragment.app.viewModels import androidx.lifecycle.lifecycleScope import dagger.hilt.android.AndroidEntryPoint @@ -98,5 +99,10 @@ class WPJetpackIndividualPluginFragment : DialogFragment() { @JvmStatic fun newInstance(): WPJetpackIndividualPluginFragment = WPJetpackIndividualPluginFragment() + + @JvmStatic + fun show(fm: FragmentManager): WPJetpackIndividualPluginFragment = newInstance().also { + it.show(fm, TAG) + } } } diff --git a/WordPress/src/main/java/org/wordpress/android/ui/main/SitePickerActivity.java b/WordPress/src/main/java/org/wordpress/android/ui/main/SitePickerActivity.java index 308607a7400c..e10dba339980 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/main/SitePickerActivity.java +++ b/WordPress/src/main/java/org/wordpress/android/ui/main/SitePickerActivity.java @@ -225,10 +225,7 @@ public void onResume() { private void onShowJetpackIndividualPluginOverlay(Boolean shouldShowJetpackIndividualPluginOverlay) { if (shouldShowJetpackIndividualPluginOverlay) { - WPJetpackIndividualPluginFragment.newInstance().show( - getSupportFragmentManager(), - WPJetpackIndividualPluginFragment.TAG - ); + WPJetpackIndividualPluginFragment.show(getSupportFragmentManager()); } } From 9e49bcb458df89c29c0af9e73d1abb9b77d0a113 Mon Sep 17 00:00:00 2001 From: Thomas Horta Date: Fri, 24 Mar 2023 10:02:12 -0300 Subject: [PATCH 373/856] update import order to fix checkstyle --- .../java/org/wordpress/android/ui/main/SitePickerActivity.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/WordPress/src/main/java/org/wordpress/android/ui/main/SitePickerActivity.java b/WordPress/src/main/java/org/wordpress/android/ui/main/SitePickerActivity.java index e10dba339980..9ac414609a6c 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/main/SitePickerActivity.java +++ b/WordPress/src/main/java/org/wordpress/android/ui/main/SitePickerActivity.java @@ -1,6 +1,5 @@ package org.wordpress.android.ui.main; -import dagger.hilt.android.AndroidEntryPoint; import android.app.Activity; import android.app.Dialog; import android.app.DialogFragment; @@ -81,6 +80,8 @@ import static org.wordpress.android.util.WPSwipeToRefreshHelper.buildSwipeToRefreshHelper; +import dagger.hilt.android.AndroidEntryPoint; + @AndroidEntryPoint public class SitePickerActivity extends LocaleAwareActivity implements SitePickerAdapter.OnSiteClickListener, From 6e87961993a69d5d350a26f2e184c57b90c0ed3b Mon Sep 17 00:00:00 2001 From: Thomas Horta Date: Fri, 24 Mar 2023 10:08:22 -0300 Subject: [PATCH 374/856] fix breaking unit test --- .../wordpress/android/viewmodel/main/SitePickerViewModelTest.kt | 2 ++ 1 file changed, 2 insertions(+) diff --git a/WordPress/src/test/java/org/wordpress/android/viewmodel/main/SitePickerViewModelTest.kt b/WordPress/src/test/java/org/wordpress/android/viewmodel/main/SitePickerViewModelTest.kt index 71dfce3940be..658944ea65b1 100644 --- a/WordPress/src/test/java/org/wordpress/android/viewmodel/main/SitePickerViewModelTest.kt +++ b/WordPress/src/test/java/org/wordpress/android/viewmodel/main/SitePickerViewModelTest.kt @@ -99,6 +99,7 @@ class SitePickerViewModelTest : BaseUnitTest() { whenever(wpJetpackIndividualPluginHelper.shouldShowJetpackIndividualPluginOverlay()).thenReturn(true) viewModel.checkJetpackIndividualPluginOverlayNeeded() + advanceUntilIdle() assertThat(viewModel.showJetpackIndividualPluginOverlay.value).isTrue() } @@ -109,6 +110,7 @@ class SitePickerViewModelTest : BaseUnitTest() { whenever(wpJetpackIndividualPluginHelper.shouldShowJetpackIndividualPluginOverlay()).thenReturn(false) viewModel.checkJetpackIndividualPluginOverlayNeeded() + advanceUntilIdle() assertThat(viewModel.showJetpackIndividualPluginOverlay.value).isFalse() } From d11463a22abe8bb40073b358489c7bffec37395b Mon Sep 17 00:00:00 2001 From: Thomas Horta Date: Fri, 24 Mar 2023 11:33:36 -0300 Subject: [PATCH 375/856] create BottomSheetDialog extension for fillScreen --- .../util/extensions/DialogExtensions.kt | 24 +++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/WordPress/src/main/java/org/wordpress/android/util/extensions/DialogExtensions.kt b/WordPress/src/main/java/org/wordpress/android/util/extensions/DialogExtensions.kt index 64fc71f67118..93056c4071e7 100644 --- a/WordPress/src/main/java/org/wordpress/android/util/extensions/DialogExtensions.kt +++ b/WordPress/src/main/java/org/wordpress/android/util/extensions/DialogExtensions.kt @@ -2,6 +2,11 @@ package org.wordpress.android.util.extensions import android.app.Dialog import android.view.View +import android.view.ViewGroup +import android.view.WindowManager +import android.widget.FrameLayout +import com.google.android.material.bottomsheet.BottomSheetBehavior +import com.google.android.material.bottomsheet.BottomSheetDialog import org.wordpress.android.R import org.wordpress.android.R.attr @@ -26,3 +31,22 @@ fun Dialog.setStatusBarAsSurfaceColor() { } } } + +fun BottomSheetDialog.fillScreen(isDraggable: Boolean = false) { + setOnShowListener { + val bottomSheet: FrameLayout = findViewById( + com.google.android.material.R.id.design_bottom_sheet + ) ?: return@setOnShowListener + + val bottomSheetBehavior = BottomSheetBehavior.from(bottomSheet) + bottomSheetBehavior.maxWidth = ViewGroup.LayoutParams.MATCH_PARENT + bottomSheetBehavior.isDraggable = isDraggable + bottomSheetBehavior.skipCollapsed = true + bottomSheetBehavior.state = BottomSheetBehavior.STATE_EXPANDED + + bottomSheet.layoutParams?.let { layoutParams -> + layoutParams.height = WindowManager.LayoutParams.MATCH_PARENT + bottomSheet.layoutParams = layoutParams + } + } +} From 4b0af6b23c21e09f46b463d174c28109459318eb Mon Sep 17 00:00:00 2001 From: Thomas Horta Date: Fri, 24 Mar 2023 11:34:07 -0300 Subject: [PATCH 376/856] use the new extension in full screen BottomSheets --- .../ui/FullscreenBottomSheetDialogFragment.kt | 22 ++----------- ...JetpackFeatureFullScreenOverlayFragment.kt | 31 ++----------------- 2 files changed, 4 insertions(+), 49 deletions(-) diff --git a/WordPress/src/main/java/org/wordpress/android/ui/FullscreenBottomSheetDialogFragment.kt b/WordPress/src/main/java/org/wordpress/android/ui/FullscreenBottomSheetDialogFragment.kt index 60f5d0d95a43..93580ce380d6 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/FullscreenBottomSheetDialogFragment.kt +++ b/WordPress/src/main/java/org/wordpress/android/ui/FullscreenBottomSheetDialogFragment.kt @@ -2,11 +2,10 @@ package org.wordpress.android.ui import android.content.DialogInterface import android.os.Bundle -import android.view.View import android.view.WindowManager -import com.google.android.material.bottomsheet.BottomSheetBehavior import com.google.android.material.bottomsheet.BottomSheetDialog import com.google.android.material.bottomsheet.BottomSheetDialogFragment +import org.wordpress.android.util.extensions.fillScreen /** * Customises [BottomSheetDialogFragment] for fullscreen @@ -20,24 +19,7 @@ abstract class FullscreenBottomSheetDialogFragment : BottomSheetDialogFragment() } override fun onCreateDialog(savedInstanceState: Bundle?) = BottomSheetDialog(requireContext(), getTheme()).apply { - fillTheScreen(this) + this.fillScreen(isDraggable = true) window?.clearFlags(WindowManager.LayoutParams.FLAG_DIM_BEHIND) } - - private fun fillTheScreen(dialog: BottomSheetDialog) { - dialog.setOnShowListener { - dialog.findViewById(com.google.android.material.R.id.design_bottom_sheet)?.let { - val behaviour = BottomSheetBehavior.from(it) - setupFullHeight(it) - behaviour.skipCollapsed = true - behaviour.state = BottomSheetBehavior.STATE_EXPANDED - } - } - } - - private fun setupFullHeight(bottomSheet: View) { - val layoutParams = bottomSheet.layoutParams - layoutParams.height = WindowManager.LayoutParams.MATCH_PARENT - bottomSheet.layoutParams = layoutParams - } } diff --git a/WordPress/src/main/java/org/wordpress/android/ui/jetpackoverlay/JetpackFeatureFullScreenOverlayFragment.kt b/WordPress/src/main/java/org/wordpress/android/ui/jetpackoverlay/JetpackFeatureFullScreenOverlayFragment.kt index 7b8cdae5cb72..0f87850bff38 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/jetpackoverlay/JetpackFeatureFullScreenOverlayFragment.kt +++ b/WordPress/src/main/java/org/wordpress/android/ui/jetpackoverlay/JetpackFeatureFullScreenOverlayFragment.kt @@ -1,13 +1,10 @@ package org.wordpress.android.ui.jetpackoverlay -import android.content.res.Resources import android.os.Bundle import android.view.LayoutInflater import android.view.View import android.view.ViewGroup -import android.widget.FrameLayout import androidx.fragment.app.activityViewModels -import com.google.android.material.bottomsheet.BottomSheetBehavior import com.google.android.material.bottomsheet.BottomSheetDialog import com.google.android.material.bottomsheet.BottomSheetDialogFragment import dagger.hilt.android.AndroidEntryPoint @@ -27,6 +24,7 @@ import org.wordpress.android.ui.utils.UiHelpers import org.wordpress.android.util.RtlUtils import org.wordpress.android.util.UrlUtils import org.wordpress.android.util.extensions.exhaustive +import org.wordpress.android.util.extensions.fillScreen import org.wordpress.android.util.extensions.getSerializableCompat import org.wordpress.android.util.extensions.setVisible import javax.inject.Inject @@ -66,32 +64,7 @@ class JetpackFeatureFullScreenOverlayFragment : BottomSheetDialogFragment() { RtlUtils.isRtl(view.context) ) binding.setupObservers() - - (dialog as? BottomSheetDialog)?.apply { - setOnShowListener { - val bottomSheet: FrameLayout = dialog?.findViewById( - com.google.android.material.R.id.design_bottom_sheet - ) ?: return@setOnShowListener - val bottomSheetBehavior = BottomSheetBehavior.from(bottomSheet) - bottomSheetBehavior.maxWidth = ViewGroup.LayoutParams.MATCH_PARENT - bottomSheetBehavior.isDraggable = false - if (bottomSheet.layoutParams != null) { - showFullScreenBottomSheet(bottomSheet) - } - expandBottomSheet(bottomSheetBehavior) - } - } - } - - private fun showFullScreenBottomSheet(bottomSheet: FrameLayout) { - val layoutParams = bottomSheet.layoutParams - layoutParams.height = Resources.getSystem().displayMetrics.heightPixels - bottomSheet.layoutParams = layoutParams - } - - private fun expandBottomSheet(bottomSheetBehavior: BottomSheetBehavior) { - bottomSheetBehavior.skipCollapsed = true - bottomSheetBehavior.state = BottomSheetBehavior.STATE_EXPANDED + (dialog as? BottomSheetDialog)?.fillScreen() } private fun getSiteScreen() = arguments?.getSerializableCompat(OVERLAY_SCREEN_TYPE) From 78b24871b33ab86ad01dfb945a88baf9019d0bd7 Mon Sep 17 00:00:00 2001 From: Thomas Horta Date: Fri, 24 Mar 2023 11:38:40 -0300 Subject: [PATCH 377/856] make overlay extend BottomSheetDialogFragment --- .../WPJetpackIndividualPluginFragment.kt | 28 ++++++++----------- 1 file changed, 11 insertions(+), 17 deletions(-) diff --git a/WordPress/src/main/java/org/wordpress/android/ui/jetpackoverlay/individualplugin/WPJetpackIndividualPluginFragment.kt b/WordPress/src/main/java/org/wordpress/android/ui/jetpackoverlay/individualplugin/WPJetpackIndividualPluginFragment.kt index 71e3cb21c573..7620d77b110a 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/jetpackoverlay/individualplugin/WPJetpackIndividualPluginFragment.kt +++ b/WordPress/src/main/java/org/wordpress/android/ui/jetpackoverlay/individualplugin/WPJetpackIndividualPluginFragment.kt @@ -1,44 +1,38 @@ package org.wordpress.android.ui.jetpackoverlay.individualplugin import android.app.Dialog +import android.content.DialogInterface import android.os.Bundle import android.view.LayoutInflater import android.view.View import android.view.ViewGroup -import androidx.activity.ComponentDialog -import androidx.activity.addCallback import androidx.compose.runtime.collectAsState import androidx.compose.runtime.getValue import androidx.compose.ui.platform.ComposeView -import androidx.fragment.app.DialogFragment import androidx.fragment.app.FragmentManager import androidx.fragment.app.viewModels import androidx.lifecycle.lifecycleScope +import com.google.android.material.bottomsheet.BottomSheetDialog +import com.google.android.material.bottomsheet.BottomSheetDialogFragment import dagger.hilt.android.AndroidEntryPoint import kotlinx.coroutines.flow.launchIn import kotlinx.coroutines.flow.onEach -import org.wordpress.android.R import org.wordpress.android.ui.ActivityLauncherWrapper import org.wordpress.android.ui.compose.theme.AppTheme import org.wordpress.android.ui.jetpackoverlay.individualplugin.WPJetpackIndividualPluginViewModel.ActionEvent import org.wordpress.android.ui.jetpackoverlay.individualplugin.WPJetpackIndividualPluginViewModel.UiState import org.wordpress.android.ui.jetpackoverlay.individualplugin.compose.WPJetpackIndividualPluginOverlayScreen import org.wordpress.android.util.extensions.exhaustive -import org.wordpress.android.util.extensions.onBackPressedCompat -import org.wordpress.android.util.extensions.setStatusBarAsSurfaceColor +import org.wordpress.android.util.extensions.fillScreen import javax.inject.Inject @AndroidEntryPoint -class WPJetpackIndividualPluginFragment : DialogFragment() { +class WPJetpackIndividualPluginFragment : BottomSheetDialogFragment() { private val viewModel: WPJetpackIndividualPluginViewModel by viewModels() @Inject lateinit var activityLauncher: ActivityLauncherWrapper - override fun getTheme(): Int { - return R.style.WPJetpackIndividualPluginDialogFragment - } - override fun onCreateView( inflater: LayoutInflater, container: ViewGroup?, @@ -71,14 +65,14 @@ class WPJetpackIndividualPluginFragment : DialogFragment() { override fun onCreateDialog(savedInstanceState: Bundle?): Dialog = super.onCreateDialog(savedInstanceState).apply { - (this as ComponentDialog).onBackPressedDispatcher - .addCallback(this@WPJetpackIndividualPluginFragment) { - viewModel.onDismissScreenClick() - onBackPressedDispatcher.onBackPressedCompat(this) - } - setStatusBarAsSurfaceColor() + (this as? BottomSheetDialog)?.fillScreen() } + override fun onCancel(dialog: DialogInterface) { + // called when user hits the back button + viewModel.onDismissScreenClick() + } + private fun observeActionEvents() { viewModel.actionEvents.onEach(this::handleActionEvents).launchIn(lifecycleScope) } From 61a59fe3597fffd82fa0cf369571cc4e8b14c120 Mon Sep 17 00:00:00 2001 From: Thomas Horta Date: Fri, 24 Mar 2023 16:02:05 -0300 Subject: [PATCH 378/856] show the overlay on the LoginEpilogue scren --- .../ui/accounts/LoginEpilogueViewModel.kt | 27 +++++++++++++++++-- .../accounts/login/LoginEpilogueFragment.java | 15 +++++++++++ 2 files changed, 40 insertions(+), 2 deletions(-) diff --git a/WordPress/src/main/java/org/wordpress/android/ui/accounts/LoginEpilogueViewModel.kt b/WordPress/src/main/java/org/wordpress/android/ui/accounts/LoginEpilogueViewModel.kt index 565ef74fd283..29a5890bc752 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/accounts/LoginEpilogueViewModel.kt +++ b/WordPress/src/main/java/org/wordpress/android/ui/accounts/LoginEpilogueViewModel.kt @@ -3,21 +3,29 @@ package org.wordpress.android.ui.accounts import androidx.lifecycle.LiveData import androidx.lifecycle.MediatorLiveData import androidx.lifecycle.ViewModel +import androidx.lifecycle.viewModelScope +import kotlinx.coroutines.delay +import kotlinx.coroutines.launch import org.wordpress.android.fluxc.store.SiteStore +import org.wordpress.android.ui.jetpackoverlay.individualplugin.WPJetpackIndividualPluginHelper import org.wordpress.android.ui.prefs.AppPrefsWrapper import org.wordpress.android.util.BuildConfigWrapper import org.wordpress.android.viewmodel.Event - +import org.wordpress.android.viewmodel.SingleLiveEvent import javax.inject.Inject class LoginEpilogueViewModel @Inject constructor( private val appPrefsWrapper: AppPrefsWrapper, private val buildConfigWrapper: BuildConfigWrapper, - private val siteStore: SiteStore + private val siteStore: SiteStore, + private val wpJetpackIndividualPluginHelper: WPJetpackIndividualPluginHelper, ) : ViewModel() { private val _navigationEvents = MediatorLiveData>() val navigationEvents: LiveData> = _navigationEvents + private val _showJetpackIndividualPluginOverlay = SingleLiveEvent() + val showJetpackIndividualPluginOverlay: LiveData = _showJetpackIndividualPluginOverlay + fun onSiteClick(localId: Int) { _navigationEvents.postValue(Event(LoginNavigationEvents.SelectSite(localId))) } @@ -52,4 +60,19 @@ class LoginEpilogueViewModel @Inject constructor( fun onLoginFinished(doLoginUpdate: Boolean) { if (doLoginUpdate && !siteStore.hasSite()) handleNoSitesFound() } + + fun checkJetpackIndividualPluginOverlayNeeded() { + // don't show if already shown + if (_showJetpackIndividualPluginOverlay.value == true) return + + viewModelScope.launch { + delay(DELAY_BEFORE_SHOWING_JETPACK_INDIVIDUAL_PLUGIN_OVERLAY) + _showJetpackIndividualPluginOverlay + .postValue(wpJetpackIndividualPluginHelper.shouldShowJetpackIndividualPluginOverlay()) + } + } + + companion object { + private const val DELAY_BEFORE_SHOWING_JETPACK_INDIVIDUAL_PLUGIN_OVERLAY = 500L + } } diff --git a/WordPress/src/main/java/org/wordpress/android/ui/accounts/login/LoginEpilogueFragment.java b/WordPress/src/main/java/org/wordpress/android/ui/accounts/login/LoginEpilogueFragment.java index 345d10911ca3..736a89a08588 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/accounts/login/LoginEpilogueFragment.java +++ b/WordPress/src/main/java/org/wordpress/android/ui/accounts/login/LoginEpilogueFragment.java @@ -28,6 +28,7 @@ import org.wordpress.android.ui.accounts.UnifiedLoginTracker; import org.wordpress.android.ui.accounts.UnifiedLoginTracker.Click; import org.wordpress.android.ui.accounts.UnifiedLoginTracker.Step; +import org.wordpress.android.ui.jetpackoverlay.individualplugin.WPJetpackIndividualPluginFragment; import org.wordpress.android.ui.main.SitePickerAdapter; import org.wordpress.android.ui.main.SitePickerAdapter.OnDataLoadedListener; import org.wordpress.android.ui.main.SitePickerAdapter.OnSiteClickListener; @@ -168,6 +169,7 @@ public void onCreate(Bundle savedInstanceState) { public void onViewCreated(View view, @Nullable Bundle savedInstanceState) { super.onViewCreated(view, savedInstanceState); initViewModel(); + initObservers(); } @Override @@ -207,6 +209,11 @@ private void setNewAdapter() { setOnSiteClickListener(); } + private void initObservers() { + mParentViewModel.getShowJetpackIndividualPluginOverlay() + .observe(getViewLifecycleOwner(), this::onShowJetpackIndividualPluginOverlay); + } + @NonNull private OnDataLoadedListener dataLoadedListener() { return new OnDataLoadedListener() { @@ -228,6 +235,8 @@ public void onAfterLoad() { mBottomShadow.setVisibility(View.GONE); } } + + mParentViewModel.checkJetpackIndividualPluginOverlayNeeded(); }); } }; @@ -396,4 +405,10 @@ protected void onLoginFinished() { mParentViewModel.onLoginFinished(mDoLoginUpdate); } + + private void onShowJetpackIndividualPluginOverlay(Boolean shouldShowJetpackIndividualPluginOverlay) { + if (shouldShowJetpackIndividualPluginOverlay && getActivity() != null) { + WPJetpackIndividualPluginFragment.show(getActivity().getSupportFragmentManager()); + } + } } From 3d07665bb0d9448dd6f425f9c416739e5fc081ea Mon Sep 17 00:00:00 2001 From: Thomas Horta Date: Fri, 24 Mar 2023 16:05:47 -0300 Subject: [PATCH 379/856] update unit tests for LoginEpilogueViewModel --- .../ui/accounts/LoginEpilogueViewModelTest.kt | 33 ++++++++++++++++++- 1 file changed, 32 insertions(+), 1 deletion(-) diff --git a/WordPress/src/test/java/org/wordpress/android/ui/accounts/LoginEpilogueViewModelTest.kt b/WordPress/src/test/java/org/wordpress/android/ui/accounts/LoginEpilogueViewModelTest.kt index 173bcffa50b5..e4ee5e4fbf49 100644 --- a/WordPress/src/test/java/org/wordpress/android/ui/accounts/LoginEpilogueViewModelTest.kt +++ b/WordPress/src/test/java/org/wordpress/android/ui/accounts/LoginEpilogueViewModelTest.kt @@ -8,6 +8,7 @@ import org.mockito.Mock import org.mockito.kotlin.whenever import org.wordpress.android.BaseUnitTest import org.wordpress.android.fluxc.store.SiteStore +import org.wordpress.android.ui.jetpackoverlay.individualplugin.WPJetpackIndividualPluginHelper import org.wordpress.android.ui.prefs.AppPrefsWrapper import org.wordpress.android.util.BuildConfigWrapper @@ -24,9 +25,17 @@ class LoginEpilogueViewModelTest : BaseUnitTest() { @Mock lateinit var siteStore: SiteStore + @Mock + private lateinit var wpJetpackIndividualPluginHelper: WPJetpackIndividualPluginHelper + @Before fun setUp() { - viewModel = LoginEpilogueViewModel(appPrefsWrapper, buildConfigWrapper, siteStore) + viewModel = LoginEpilogueViewModel( + appPrefsWrapper, + buildConfigWrapper, + siteStore, + wpJetpackIndividualPluginHelper + ) } @Test @@ -262,6 +271,28 @@ class LoginEpilogueViewModelTest : BaseUnitTest() { assertThat(navigationEvents.last()).isInstanceOf(LoginNavigationEvents.ShowNoJetpackSites::class.java) } + @Test + fun `when checkJetpackIndividualPluginOverlayNeeded is invoked then showJetpackIndividualPluginOverlay is true`() = + test { + whenever(wpJetpackIndividualPluginHelper.shouldShowJetpackIndividualPluginOverlay()).thenReturn(true) + + viewModel.checkJetpackIndividualPluginOverlayNeeded() + advanceUntilIdle() + + assertThat(viewModel.showJetpackIndividualPluginOverlay.value).isTrue() + } + + @Test + fun `when checkJetpackIndividualPluginOverlayNeeded is invoked then showJetpackIndividualPluginOverlay is false`() = + test { + whenever(wpJetpackIndividualPluginHelper.shouldShowJetpackIndividualPluginOverlay()).thenReturn(false) + + viewModel.checkJetpackIndividualPluginOverlayNeeded() + advanceUntilIdle() + + assertThat(viewModel.showJetpackIndividualPluginOverlay.value).isFalse() + } + private data class Observers(val navigationEvents: List) private fun initObservers(): Observers { From f961c005a2724e2dfb7d1d7571fd61aa4ecddf62 Mon Sep 17 00:00:00 2001 From: Thomas Horta Date: Fri, 24 Mar 2023 17:01:46 -0300 Subject: [PATCH 380/856] refactor site picker to use existing event live data --- .../android/ui/main/SitePickerActivity.java | 113 +++++++++--------- .../viewmodel/main/SitePickerViewModel.kt | 35 +++--- .../viewmodel/main/SitePickerViewModelTest.kt | 13 +- 3 files changed, 80 insertions(+), 81 deletions(-) diff --git a/WordPress/src/main/java/org/wordpress/android/ui/main/SitePickerActivity.java b/WordPress/src/main/java/org/wordpress/android/ui/main/SitePickerActivity.java index 9ac414609a6c..12f9dcbce3ef 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/main/SitePickerActivity.java +++ b/WordPress/src/main/java/org/wordpress/android/ui/main/SitePickerActivity.java @@ -159,59 +159,59 @@ public void onCreate(Bundle savedInstanceState) { AnalyticsTracker.track(Stat.SITE_SWITCHER_DISPLAYED); } - if (mSitePickerMode.isReblogMode()) { - mViewModel.getOnActionTriggered().observe( - this, - unitEvent -> unitEvent.applyIfNotHandled(action -> { - switch (action.getActionType()) { - case NAVIGATE_TO_STATE: - switch (((NavigateToState) action).getNavigateState()) { - case TO_SITE_SELECTED: - mSitePickerMode = SitePickerMode.REBLOG_CONTINUE_MODE; - if (getAdapter().getIsInSearchMode()) { - disableSearchMode(); - } - - if (mReblogActionMode == null) { - startSupportActionMode(new ReblogActionModeCallback()); - } - - SiteRecord site = ((NavigateToState) action).getSiteForReblog(); - if (site != null) { - mReblogActionMode.setTitle(site.getBlogNameOrHomeURL()); - } - break; - case TO_NO_SITE_SELECTED: - mSitePickerMode = SitePickerMode.REBLOG_SELECT_MODE; - getAdapter().clearReblogSelection(); - break; - } - break; - case CONTINUE_REBLOG_TO: - SiteRecord siteToReblog = ((ContinueReblogTo) action).getSiteForReblog(); - selectSiteAndFinish(siteToReblog); - break; - case ASK_FOR_SITE_SELECTION: - if (BuildConfig.DEBUG) { - throw new IllegalStateException( - "SitePickerActivity > Selected site was null while attempting to reblog" - ); - } else { - AppLog.e( - AppLog.T.READER, - "SitePickerActivity > Selected site was null while attempting to reblog" - ); - ToastUtils.showToast(this, R.string.site_picker_ask_site_select); - } - break; - } - return null; - })); - } - - mViewModel.getShowJetpackIndividualPluginOverlay().observe(this, this::onShowJetpackIndividualPluginOverlay); - mViewModel.checkJetpackIndividualPluginOverlayNeeded(); - + mViewModel.getOnActionTriggered().observe( + this, + unitEvent -> unitEvent.applyIfNotHandled(action -> { + switch (action.getActionType()) { + case NAVIGATE_TO_STATE: + if (!mSitePickerMode.isReblogMode()) break; + switch (((NavigateToState) action).getNavigateState()) { + case TO_SITE_SELECTED: + mSitePickerMode = SitePickerMode.REBLOG_CONTINUE_MODE; + if (getAdapter().getIsInSearchMode()) { + disableSearchMode(); + } + + if (mReblogActionMode == null) { + startSupportActionMode(new ReblogActionModeCallback()); + } + + SiteRecord site = ((NavigateToState) action).getSiteForReblog(); + if (site != null) { + mReblogActionMode.setTitle(site.getBlogNameOrHomeURL()); + } + break; + case TO_NO_SITE_SELECTED: + mSitePickerMode = SitePickerMode.REBLOG_SELECT_MODE; + getAdapter().clearReblogSelection(); + break; + } + break; + case CONTINUE_REBLOG_TO: + if (!mSitePickerMode.isReblogMode()) break; + SiteRecord siteToReblog = ((ContinueReblogTo) action).getSiteForReblog(); + selectSiteAndFinish(siteToReblog); + break; + case ASK_FOR_SITE_SELECTION: + if (!mSitePickerMode.isReblogMode()) break; + if (BuildConfig.DEBUG) { + throw new IllegalStateException( + "SitePickerActivity > Selected site was null while attempting to reblog" + ); + } else { + AppLog.e( + AppLog.T.READER, + "SitePickerActivity > Selected site was null while attempting to reblog" + ); + ToastUtils.showToast(this, R.string.site_picker_ask_site_select); + } + break; + case SHOW_JETPACK_INDIVIDUAL_PLUGIN_OVERLAY: + WPJetpackIndividualPluginFragment.show(getSupportFragmentManager()); + break; + } + return null; + })); // If the picker is already in editing mode from previous configuration, re-enable the editing mode. if (mIsInEditMode) { startEditingVisibility(); @@ -224,12 +224,6 @@ public void onResume() { ActivityId.trackLastActivity(ActivityId.SITE_PICKER); } - private void onShowJetpackIndividualPluginOverlay(Boolean shouldShowJetpackIndividualPluginOverlay) { - if (shouldShowJetpackIndividualPluginOverlay) { - WPJetpackIndividualPluginFragment.show(getSupportFragmentManager()); - } - } - @Override protected void onSaveInstanceState(Bundle outState) { outState.putInt(KEY_SITE_LOCAL_ID, mCurrentLocalId); @@ -492,6 +486,7 @@ public void onAfterLoad() { mRecycleView.scrollToPosition(scrollPos); } } + mViewModel.onSiteListLoaded(); } }, mSitePickerMode, diff --git a/WordPress/src/main/java/org/wordpress/android/viewmodel/main/SitePickerViewModel.kt b/WordPress/src/main/java/org/wordpress/android/viewmodel/main/SitePickerViewModel.kt index 4a7e57c0c6ed..44aa163e863e 100644 --- a/WordPress/src/main/java/org/wordpress/android/viewmodel/main/SitePickerViewModel.kt +++ b/WordPress/src/main/java/org/wordpress/android/viewmodel/main/SitePickerViewModel.kt @@ -9,13 +9,14 @@ import kotlinx.coroutines.launch import org.wordpress.android.ui.jetpackoverlay.individualplugin.WPJetpackIndividualPluginHelper import org.wordpress.android.ui.main.SitePickerAdapter.SiteRecord import org.wordpress.android.viewmodel.Event -import org.wordpress.android.viewmodel.SingleLiveEvent import org.wordpress.android.viewmodel.main.SitePickerViewModel.Action.AskForSiteSelection import org.wordpress.android.viewmodel.main.SitePickerViewModel.Action.ContinueReblogTo import org.wordpress.android.viewmodel.main.SitePickerViewModel.Action.NavigateToState +import org.wordpress.android.viewmodel.main.SitePickerViewModel.Action.ShowJetpackIndividualPluginOverlay import org.wordpress.android.viewmodel.main.SitePickerViewModel.ActionType.ASK_FOR_SITE_SELECTION import org.wordpress.android.viewmodel.main.SitePickerViewModel.ActionType.CONTINUE_REBLOG_TO import org.wordpress.android.viewmodel.main.SitePickerViewModel.ActionType.NAVIGATE_TO_STATE +import org.wordpress.android.viewmodel.main.SitePickerViewModel.ActionType.SHOW_JETPACK_INDIVIDUAL_PLUGIN_OVERLAY import org.wordpress.android.viewmodel.main.SitePickerViewModel.NavigateState.TO_NO_SITE_SELECTED import org.wordpress.android.viewmodel.main.SitePickerViewModel.NavigateState.TO_SITE_SELECTED import javax.inject.Inject @@ -26,22 +27,8 @@ class SitePickerViewModel @Inject constructor( private val _onActionTriggered = MutableLiveData>() val onActionTriggered: LiveData> = _onActionTriggered - private val _showJetpackIndividualPluginOverlay = SingleLiveEvent() - val showJetpackIndividualPluginOverlay: LiveData = _showJetpackIndividualPluginOverlay - private var siteForReblog: SiteRecord? = null - fun checkJetpackIndividualPluginOverlayNeeded() { - // don't show if already shown - if (_showJetpackIndividualPluginOverlay.value == true) return - - viewModelScope.launch { - delay(DELAY_BEFORE_SHOWING_JETPACK_INDIVIDUAL_PLUGIN_OVERLAY) - _showJetpackIndividualPluginOverlay - .postValue(wpJetpackIndividualPluginHelper.shouldShowJetpackIndividualPluginOverlay()) - } - } - fun onSiteForReblogSelected(siteRecord: SiteRecord) { selectSite(siteRecord) } @@ -71,10 +58,24 @@ class SitePickerViewModel @Inject constructor( _onActionTriggered.value = Event(NavigateToState(TO_SITE_SELECTED, siteRecord)) } + fun onSiteListLoaded() { + // don't check if already shown + if (_onActionTriggered.value?.peekContent() == ShowJetpackIndividualPluginOverlay) return + + viewModelScope.launch { + val showOverlay = wpJetpackIndividualPluginHelper.shouldShowJetpackIndividualPluginOverlay() + if (showOverlay) { + delay(DELAY_BEFORE_SHOWING_JETPACK_INDIVIDUAL_PLUGIN_OVERLAY) + _onActionTriggered.postValue(Event(ShowJetpackIndividualPluginOverlay)) + } + } + } + enum class ActionType { NAVIGATE_TO_STATE, CONTINUE_REBLOG_TO, - ASK_FOR_SITE_SELECTION + ASK_FOR_SITE_SELECTION, + SHOW_JETPACK_INDIVIDUAL_PLUGIN_OVERLAY } enum class NavigateState { @@ -92,6 +93,8 @@ class SitePickerViewModel @Inject constructor( ) object AskForSiteSelection : Action(ASK_FOR_SITE_SELECTION) + + object ShowJetpackIndividualPluginOverlay : Action(SHOW_JETPACK_INDIVIDUAL_PLUGIN_OVERLAY) } companion object { diff --git a/WordPress/src/test/java/org/wordpress/android/viewmodel/main/SitePickerViewModelTest.kt b/WordPress/src/test/java/org/wordpress/android/viewmodel/main/SitePickerViewModelTest.kt index 658944ea65b1..b3d3088f2e6a 100644 --- a/WordPress/src/test/java/org/wordpress/android/viewmodel/main/SitePickerViewModelTest.kt +++ b/WordPress/src/test/java/org/wordpress/android/viewmodel/main/SitePickerViewModelTest.kt @@ -16,6 +16,7 @@ import org.wordpress.android.viewmodel.main.SitePickerViewModel.Action import org.wordpress.android.viewmodel.main.SitePickerViewModel.Action.AskForSiteSelection import org.wordpress.android.viewmodel.main.SitePickerViewModel.Action.ContinueReblogTo import org.wordpress.android.viewmodel.main.SitePickerViewModel.Action.NavigateToState +import org.wordpress.android.viewmodel.main.SitePickerViewModel.Action.ShowJetpackIndividualPluginOverlay import org.wordpress.android.viewmodel.main.SitePickerViewModel.NavigateState.TO_NO_SITE_SELECTED import org.wordpress.android.viewmodel.main.SitePickerViewModel.NavigateState.TO_SITE_SELECTED @@ -94,24 +95,24 @@ class SitePickerViewModelTest : BaseUnitTest() { } @Test - fun `when checkJetpackIndividualPluginOverlayNeeded is invoked then showJetpackIndividualPluginOverlay is true`() = + fun `when onSiteListLoaded is invoked then show jetpack individual plugin overlay`() = test { whenever(wpJetpackIndividualPluginHelper.shouldShowJetpackIndividualPluginOverlay()).thenReturn(true) - viewModel.checkJetpackIndividualPluginOverlayNeeded() + viewModel.onSiteListLoaded() advanceUntilIdle() - assertThat(viewModel.showJetpackIndividualPluginOverlay.value).isTrue() + assertThat(viewModel.onActionTriggered.value?.peekContent()).isEqualTo(ShowJetpackIndividualPluginOverlay) } @Test - fun `when checkJetpackIndividualPluginOverlayNeeded is invoked then showJetpackIndividualPluginOverlay is false`() = + fun `when onSiteListLoaded is invoked then don't show jetpack individual plugin overlay`() = test { whenever(wpJetpackIndividualPluginHelper.shouldShowJetpackIndividualPluginOverlay()).thenReturn(false) - viewModel.checkJetpackIndividualPluginOverlayNeeded() + viewModel.onSiteListLoaded() advanceUntilIdle() - assertThat(viewModel.showJetpackIndividualPluginOverlay.value).isFalse() + assertThat(viewModel.onActionTriggered.value?.peekContent()).isNull() } } From 02c8bb5e7e3640b91cd73b17b47aa852b257ecb0 Mon Sep 17 00:00:00 2001 From: Thomas Horta Date: Fri, 24 Mar 2023 17:06:04 -0300 Subject: [PATCH 381/856] refactor epilogue to use existing event live data --- .../ui/accounts/LoginEpilogueActivity.java | 8 ++++++++ .../ui/accounts/LoginEpilogueViewModel.kt | 18 ++++++++---------- .../ui/accounts/LoginNavigationEvents.kt | 1 + .../accounts/login/LoginEpilogueFragment.java | 15 +-------------- .../ui/accounts/LoginEpilogueViewModelTest.kt | 14 ++++++++------ 5 files changed, 26 insertions(+), 30 deletions(-) diff --git a/WordPress/src/main/java/org/wordpress/android/ui/accounts/LoginEpilogueActivity.java b/WordPress/src/main/java/org/wordpress/android/ui/accounts/LoginEpilogueActivity.java index 0271557de23d..8e31fe1a8e60 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/accounts/LoginEpilogueActivity.java +++ b/WordPress/src/main/java/org/wordpress/android/ui/accounts/LoginEpilogueActivity.java @@ -16,11 +16,13 @@ import org.wordpress.android.ui.accounts.LoginNavigationEvents.CloseWithResultOk; import org.wordpress.android.ui.accounts.LoginNavigationEvents.CreateNewSite; import org.wordpress.android.ui.accounts.LoginNavigationEvents.SelectSite; +import org.wordpress.android.ui.accounts.LoginNavigationEvents.ShowJetpackIndividualPluginOverlay; import org.wordpress.android.ui.accounts.LoginNavigationEvents.ShowNoJetpackSites; import org.wordpress.android.ui.accounts.LoginNavigationEvents.ShowPostSignupInterstitialScreen; import org.wordpress.android.ui.accounts.login.LoginEpilogueFragment; import org.wordpress.android.ui.accounts.login.LoginEpilogueListener; import org.wordpress.android.ui.accounts.login.jetpack.LoginNoSitesFragment; +import org.wordpress.android.ui.jetpackoverlay.individualplugin.WPJetpackIndividualPluginFragment; import org.wordpress.android.ui.main.SitePickerActivity; import org.wordpress.android.ui.mysite.SelectedSiteRepository; import org.wordpress.android.ui.sitecreation.misc.SiteCreationSource; @@ -80,6 +82,8 @@ private void initObservers() { closeWithResultOk(); } else if (loginEvent instanceof ShowNoJetpackSites) { showNoJetpackSites(); + } else if (loginEvent instanceof ShowJetpackIndividualPluginOverlay) { + showJetpackIndividualPluginOverlay(); } }); } @@ -150,6 +154,10 @@ private void showFragment(Fragment fragment, String tag, boolean applySlideAnima fragmentTransaction.commit(); } + private void showJetpackIndividualPluginOverlay() { + WPJetpackIndividualPluginFragment.show(getSupportFragmentManager()); + } + @Override protected void onActivityResult(int requestCode, int resultCode, Intent data) { super.onActivityResult(requestCode, resultCode, data); diff --git a/WordPress/src/main/java/org/wordpress/android/ui/accounts/LoginEpilogueViewModel.kt b/WordPress/src/main/java/org/wordpress/android/ui/accounts/LoginEpilogueViewModel.kt index 29a5890bc752..8d376dfa35be 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/accounts/LoginEpilogueViewModel.kt +++ b/WordPress/src/main/java/org/wordpress/android/ui/accounts/LoginEpilogueViewModel.kt @@ -11,7 +11,6 @@ import org.wordpress.android.ui.jetpackoverlay.individualplugin.WPJetpackIndivid import org.wordpress.android.ui.prefs.AppPrefsWrapper import org.wordpress.android.util.BuildConfigWrapper import org.wordpress.android.viewmodel.Event -import org.wordpress.android.viewmodel.SingleLiveEvent import javax.inject.Inject class LoginEpilogueViewModel @Inject constructor( @@ -23,9 +22,6 @@ class LoginEpilogueViewModel @Inject constructor( private val _navigationEvents = MediatorLiveData>() val navigationEvents: LiveData> = _navigationEvents - private val _showJetpackIndividualPluginOverlay = SingleLiveEvent() - val showJetpackIndividualPluginOverlay: LiveData = _showJetpackIndividualPluginOverlay - fun onSiteClick(localId: Int) { _navigationEvents.postValue(Event(LoginNavigationEvents.SelectSite(localId))) } @@ -61,14 +57,16 @@ class LoginEpilogueViewModel @Inject constructor( if (doLoginUpdate && !siteStore.hasSite()) handleNoSitesFound() } - fun checkJetpackIndividualPluginOverlayNeeded() { - // don't show if already shown - if (_showJetpackIndividualPluginOverlay.value == true) return + fun onSiteListLoaded() { + // don't check if already shown + if (_navigationEvents.value?.peekContent() == LoginNavigationEvents.ShowJetpackIndividualPluginOverlay) return viewModelScope.launch { - delay(DELAY_BEFORE_SHOWING_JETPACK_INDIVIDUAL_PLUGIN_OVERLAY) - _showJetpackIndividualPluginOverlay - .postValue(wpJetpackIndividualPluginHelper.shouldShowJetpackIndividualPluginOverlay()) + val showOverlay = wpJetpackIndividualPluginHelper.shouldShowJetpackIndividualPluginOverlay() + if (showOverlay) { + delay(DELAY_BEFORE_SHOWING_JETPACK_INDIVIDUAL_PLUGIN_OVERLAY) + _navigationEvents.postValue(Event(LoginNavigationEvents.ShowJetpackIndividualPluginOverlay)) + } } } diff --git a/WordPress/src/main/java/org/wordpress/android/ui/accounts/LoginNavigationEvents.kt b/WordPress/src/main/java/org/wordpress/android/ui/accounts/LoginNavigationEvents.kt index 7d6d7d9278d1..f40cdd64de71 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/accounts/LoginNavigationEvents.kt +++ b/WordPress/src/main/java/org/wordpress/android/ui/accounts/LoginNavigationEvents.kt @@ -13,4 +13,5 @@ sealed class LoginNavigationEvents { object CloseWithResultOk : LoginNavigationEvents() object ShowEmailLoginScreen : LoginNavigationEvents() object ShowLoginViaSiteAddressScreen : LoginNavigationEvents() + object ShowJetpackIndividualPluginOverlay : LoginNavigationEvents() } diff --git a/WordPress/src/main/java/org/wordpress/android/ui/accounts/login/LoginEpilogueFragment.java b/WordPress/src/main/java/org/wordpress/android/ui/accounts/login/LoginEpilogueFragment.java index 736a89a08588..3fb18dae8a21 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/accounts/login/LoginEpilogueFragment.java +++ b/WordPress/src/main/java/org/wordpress/android/ui/accounts/login/LoginEpilogueFragment.java @@ -28,7 +28,6 @@ import org.wordpress.android.ui.accounts.UnifiedLoginTracker; import org.wordpress.android.ui.accounts.UnifiedLoginTracker.Click; import org.wordpress.android.ui.accounts.UnifiedLoginTracker.Step; -import org.wordpress.android.ui.jetpackoverlay.individualplugin.WPJetpackIndividualPluginFragment; import org.wordpress.android.ui.main.SitePickerAdapter; import org.wordpress.android.ui.main.SitePickerAdapter.OnDataLoadedListener; import org.wordpress.android.ui.main.SitePickerAdapter.OnSiteClickListener; @@ -169,7 +168,6 @@ public void onCreate(Bundle savedInstanceState) { public void onViewCreated(View view, @Nullable Bundle savedInstanceState) { super.onViewCreated(view, savedInstanceState); initViewModel(); - initObservers(); } @Override @@ -209,11 +207,6 @@ private void setNewAdapter() { setOnSiteClickListener(); } - private void initObservers() { - mParentViewModel.getShowJetpackIndividualPluginOverlay() - .observe(getViewLifecycleOwner(), this::onShowJetpackIndividualPluginOverlay); - } - @NonNull private OnDataLoadedListener dataLoadedListener() { return new OnDataLoadedListener() { @@ -236,7 +229,7 @@ public void onAfterLoad() { } } - mParentViewModel.checkJetpackIndividualPluginOverlayNeeded(); + mParentViewModel.onSiteListLoaded(); }); } }; @@ -405,10 +398,4 @@ protected void onLoginFinished() { mParentViewModel.onLoginFinished(mDoLoginUpdate); } - - private void onShowJetpackIndividualPluginOverlay(Boolean shouldShowJetpackIndividualPluginOverlay) { - if (shouldShowJetpackIndividualPluginOverlay && getActivity() != null) { - WPJetpackIndividualPluginFragment.show(getActivity().getSupportFragmentManager()); - } - } } diff --git a/WordPress/src/test/java/org/wordpress/android/ui/accounts/LoginEpilogueViewModelTest.kt b/WordPress/src/test/java/org/wordpress/android/ui/accounts/LoginEpilogueViewModelTest.kt index e4ee5e4fbf49..95acc2d4f38c 100644 --- a/WordPress/src/test/java/org/wordpress/android/ui/accounts/LoginEpilogueViewModelTest.kt +++ b/WordPress/src/test/java/org/wordpress/android/ui/accounts/LoginEpilogueViewModelTest.kt @@ -272,25 +272,27 @@ class LoginEpilogueViewModelTest : BaseUnitTest() { } @Test - fun `when checkJetpackIndividualPluginOverlayNeeded is invoked then showJetpackIndividualPluginOverlay is true`() = + fun `when onSiteListLoaded is invoked then show jetpack individual plugin overlay`() = test { + val navigationEvents = initObservers().navigationEvents whenever(wpJetpackIndividualPluginHelper.shouldShowJetpackIndividualPluginOverlay()).thenReturn(true) - viewModel.checkJetpackIndividualPluginOverlayNeeded() + viewModel.onSiteListLoaded() advanceUntilIdle() - assertThat(viewModel.showJetpackIndividualPluginOverlay.value).isTrue() + assertThat(navigationEvents.last()).isEqualTo(LoginNavigationEvents.ShowJetpackIndividualPluginOverlay) } @Test - fun `when checkJetpackIndividualPluginOverlayNeeded is invoked then showJetpackIndividualPluginOverlay is false`() = + fun `when onSiteListLoaded is invoked then don't show jetpack individual plugin overlay`() = test { + val navigationEvents = initObservers().navigationEvents whenever(wpJetpackIndividualPluginHelper.shouldShowJetpackIndividualPluginOverlay()).thenReturn(false) - viewModel.checkJetpackIndividualPluginOverlayNeeded() + viewModel.onSiteListLoaded() advanceUntilIdle() - assertThat(viewModel.showJetpackIndividualPluginOverlay.value).isFalse() + assertThat(navigationEvents.lastOrNull()).isNull() } private data class Observers(val navigationEvents: List) From 7d8620c6657fc3979026e4f80cab21576bfb1d61 Mon Sep 17 00:00:00 2001 From: Thomas Horta Date: Fri, 24 Mar 2023 17:54:39 -0300 Subject: [PATCH 382/856] show overlay on SignUp Interstitial screen --- .../android/modules/AppComponent.java | 2 -- .../PostSignupInterstitialActivity.kt | 11 +++++-- .../PostSignupInterstitialViewModel.kt | 33 +++++++++++++++++-- .../PostSignupInterstitialViewModelTest.kt | 32 +++++++++++++++++- 4 files changed, 71 insertions(+), 7 deletions(-) diff --git a/WordPress/src/main/java/org/wordpress/android/modules/AppComponent.java b/WordPress/src/main/java/org/wordpress/android/modules/AppComponent.java index 0947e4604d6f..d86a548a8dbc 100644 --- a/WordPress/src/main/java/org/wordpress/android/modules/AppComponent.java +++ b/WordPress/src/main/java/org/wordpress/android/modules/AppComponent.java @@ -213,8 +213,6 @@ public interface AppComponent { void inject(SignupEpilogueFragment object); - void inject(PostSignupInterstitialActivity object); - void inject(JetpackConnectionResultActivity object); void inject(StatsConnectJetpackActivity object); diff --git a/WordPress/src/main/java/org/wordpress/android/ui/accounts/PostSignupInterstitialActivity.kt b/WordPress/src/main/java/org/wordpress/android/ui/accounts/PostSignupInterstitialActivity.kt index 7086e85b4116..bc86e7841c6e 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/accounts/PostSignupInterstitialActivity.kt +++ b/WordPress/src/main/java/org/wordpress/android/ui/accounts/PostSignupInterstitialActivity.kt @@ -4,19 +4,22 @@ import android.os.Bundle import androidx.activity.addCallback import androidx.lifecycle.ViewModelProvider import com.google.android.material.button.MaterialButton +import dagger.hilt.android.AndroidEntryPoint import org.wordpress.android.R -import org.wordpress.android.WordPress import org.wordpress.android.databinding.PostSignupInterstitialActivityBinding import org.wordpress.android.ui.ActivityLauncher import org.wordpress.android.ui.LocaleAwareActivity +import org.wordpress.android.ui.jetpackoverlay.individualplugin.WPJetpackIndividualPluginFragment import org.wordpress.android.ui.sitecreation.misc.SiteCreationSource import org.wordpress.android.viewmodel.accounts.PostSignupInterstitialViewModel import org.wordpress.android.viewmodel.accounts.PostSignupInterstitialViewModel.NavigationAction import org.wordpress.android.viewmodel.accounts.PostSignupInterstitialViewModel.NavigationAction.DISMISS +import org.wordpress.android.viewmodel.accounts.PostSignupInterstitialViewModel.NavigationAction.SHOW_JETPACK_INDIVIDUAL_PLUGIN_OVERLAY import org.wordpress.android.viewmodel.accounts.PostSignupInterstitialViewModel.NavigationAction.START_SITE_CONNECTION_FLOW import org.wordpress.android.viewmodel.accounts.PostSignupInterstitialViewModel.NavigationAction.START_SITE_CREATION_FLOW import javax.inject.Inject +@AndroidEntryPoint class PostSignupInterstitialActivity : LocaleAwareActivity() { @Inject lateinit var viewModelFactory: ViewModelProvider.Factory @@ -24,7 +27,6 @@ class PostSignupInterstitialActivity : LocaleAwareActivity() { override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) - (application as WordPress).component().inject(this) LoginFlowThemeHelper.injectMissingCustomAttributes(theme) @@ -57,6 +59,7 @@ class PostSignupInterstitialActivity : LocaleAwareActivity() { private fun executeAction(navigationAction: NavigationAction) = when (navigationAction) { START_SITE_CREATION_FLOW -> startSiteCreationFlow() START_SITE_CONNECTION_FLOW -> startSiteConnectionFlow() + SHOW_JETPACK_INDIVIDUAL_PLUGIN_OVERLAY -> showJetpackIndividualPluginOverlay() DISMISS -> dismiss() } @@ -74,4 +77,8 @@ class PostSignupInterstitialActivity : LocaleAwareActivity() { ActivityLauncher.viewReader(this) finish() } + + private fun showJetpackIndividualPluginOverlay() { + WPJetpackIndividualPluginFragment.show(supportFragmentManager) + } } diff --git a/WordPress/src/main/java/org/wordpress/android/viewmodel/accounts/PostSignupInterstitialViewModel.kt b/WordPress/src/main/java/org/wordpress/android/viewmodel/accounts/PostSignupInterstitialViewModel.kt index 3bed4a03c1ab..9a17663a40fd 100644 --- a/WordPress/src/main/java/org/wordpress/android/viewmodel/accounts/PostSignupInterstitialViewModel.kt +++ b/WordPress/src/main/java/org/wordpress/android/viewmodel/accounts/PostSignupInterstitialViewModel.kt @@ -1,6 +1,9 @@ package org.wordpress.android.viewmodel.accounts import androidx.lifecycle.ViewModel +import androidx.lifecycle.viewModelScope +import kotlinx.coroutines.delay +import kotlinx.coroutines.launch import org.wordpress.android.analytics.AnalyticsTracker.Stat.WELCOME_NO_SITES_INTERSTITIAL_ADD_SELF_HOSTED_SITE_TAPPED import org.wordpress.android.analytics.AnalyticsTracker.Stat.WELCOME_NO_SITES_INTERSTITIAL_CREATE_NEW_SITE_TAPPED import org.wordpress.android.analytics.AnalyticsTracker.Stat.WELCOME_NO_SITES_INTERSTITIAL_DISMISSED @@ -8,10 +11,12 @@ import org.wordpress.android.analytics.AnalyticsTracker.Stat.WELCOME_NO_SITES_IN import org.wordpress.android.ui.accounts.UnifiedLoginTracker import org.wordpress.android.ui.accounts.UnifiedLoginTracker.Click import org.wordpress.android.ui.accounts.UnifiedLoginTracker.Step.SUCCESS +import org.wordpress.android.ui.jetpackoverlay.individualplugin.WPJetpackIndividualPluginHelper import org.wordpress.android.ui.prefs.AppPrefsWrapper import org.wordpress.android.util.analytics.AnalyticsTrackerWrapper import org.wordpress.android.viewmodel.SingleLiveEvent import org.wordpress.android.viewmodel.accounts.PostSignupInterstitialViewModel.NavigationAction.DISMISS +import org.wordpress.android.viewmodel.accounts.PostSignupInterstitialViewModel.NavigationAction.SHOW_JETPACK_INDIVIDUAL_PLUGIN_OVERLAY import org.wordpress.android.viewmodel.accounts.PostSignupInterstitialViewModel.NavigationAction.START_SITE_CONNECTION_FLOW import org.wordpress.android.viewmodel.accounts.PostSignupInterstitialViewModel.NavigationAction.START_SITE_CREATION_FLOW import javax.inject.Inject @@ -20,7 +25,8 @@ class PostSignupInterstitialViewModel @Inject constructor( private val appPrefs: AppPrefsWrapper, private val unifiedLoginTracker: UnifiedLoginTracker, - private val analyticsTracker: AnalyticsTrackerWrapper + private val analyticsTracker: AnalyticsTrackerWrapper, + private val wpJetpackIndividualPluginHelper: WPJetpackIndividualPluginHelper, ) : ViewModel() { val navigationAction: SingleLiveEvent = SingleLiveEvent() @@ -28,6 +34,7 @@ class PostSignupInterstitialViewModel analyticsTracker.track(WELCOME_NO_SITES_INTERSTITIAL_SHOWN) unifiedLoginTracker.track(step = SUCCESS) appPrefs.shouldShowPostSignupInterstitial = false + checkJetpackIndividualPluginOverlayShouldShow() } fun onCreateNewSiteButtonPressed() { @@ -52,5 +59,27 @@ class PostSignupInterstitialViewModel navigationAction.value = DISMISS } - enum class NavigationAction { START_SITE_CREATION_FLOW, START_SITE_CONNECTION_FLOW, DISMISS } + private fun checkJetpackIndividualPluginOverlayShouldShow() { + // don't check if already shown + if (navigationAction.value == SHOW_JETPACK_INDIVIDUAL_PLUGIN_OVERLAY) return + + viewModelScope.launch { + val showOverlay = wpJetpackIndividualPluginHelper.shouldShowJetpackIndividualPluginOverlay() + if (showOverlay) { + delay(DELAY_BEFORE_SHOWING_JETPACK_INDIVIDUAL_PLUGIN_OVERLAY) + navigationAction.postValue(SHOW_JETPACK_INDIVIDUAL_PLUGIN_OVERLAY) + } + } + } + + enum class NavigationAction { + START_SITE_CREATION_FLOW, + START_SITE_CONNECTION_FLOW, + DISMISS, + SHOW_JETPACK_INDIVIDUAL_PLUGIN_OVERLAY + } + + companion object { + const val DELAY_BEFORE_SHOWING_JETPACK_INDIVIDUAL_PLUGIN_OVERLAY = 500L + } } diff --git a/WordPress/src/test/java/org/wordpress/android/viewmodel/accounts/PostSignupInterstitialViewModelTest.kt b/WordPress/src/test/java/org/wordpress/android/viewmodel/accounts/PostSignupInterstitialViewModelTest.kt index f027a3af04b2..09cc72d8ceb2 100644 --- a/WordPress/src/test/java/org/wordpress/android/viewmodel/accounts/PostSignupInterstitialViewModelTest.kt +++ b/WordPress/src/test/java/org/wordpress/android/viewmodel/accounts/PostSignupInterstitialViewModelTest.kt @@ -2,18 +2,21 @@ package org.wordpress.android.viewmodel.accounts import androidx.lifecycle.Observer import kotlinx.coroutines.ExperimentalCoroutinesApi +import org.assertj.core.api.Assertions.assertThat import org.junit.Before import org.junit.Test import org.junit.runner.RunWith import org.mockito.junit.MockitoJUnitRunner import org.mockito.kotlin.mock import org.mockito.kotlin.verify +import org.mockito.kotlin.whenever import org.wordpress.android.BaseUnitTest import org.wordpress.android.analytics.AnalyticsTracker.Stat.WELCOME_NO_SITES_INTERSTITIAL_ADD_SELF_HOSTED_SITE_TAPPED import org.wordpress.android.analytics.AnalyticsTracker.Stat.WELCOME_NO_SITES_INTERSTITIAL_CREATE_NEW_SITE_TAPPED import org.wordpress.android.analytics.AnalyticsTracker.Stat.WELCOME_NO_SITES_INTERSTITIAL_DISMISSED import org.wordpress.android.analytics.AnalyticsTracker.Stat.WELCOME_NO_SITES_INTERSTITIAL_SHOWN import org.wordpress.android.ui.accounts.UnifiedLoginTracker +import org.wordpress.android.ui.jetpackoverlay.individualplugin.WPJetpackIndividualPluginHelper import org.wordpress.android.ui.prefs.AppPrefsWrapper import org.wordpress.android.util.analytics.AnalyticsTrackerWrapper import org.wordpress.android.viewmodel.accounts.PostSignupInterstitialViewModel.NavigationAction @@ -27,13 +30,19 @@ class PostSignupInterstitialViewModelTest : BaseUnitTest() { private val appPrefs: AppPrefsWrapper = mock() private val unifiedLoginTracker: UnifiedLoginTracker = mock() private val analyticsTracker: AnalyticsTrackerWrapper = mock() + private val wpJetpackIndividualPluginHelper: WPJetpackIndividualPluginHelper = mock() private val observer: Observer = mock() private lateinit var viewModel: PostSignupInterstitialViewModel @Before fun setUp() { - viewModel = PostSignupInterstitialViewModel(appPrefs, unifiedLoginTracker, analyticsTracker) + viewModel = PostSignupInterstitialViewModel( + appPrefs, + unifiedLoginTracker, + analyticsTracker, + wpJetpackIndividualPluginHelper + ) viewModel.navigationAction.observeForever(observer) } @@ -45,6 +54,27 @@ class PostSignupInterstitialViewModelTest : BaseUnitTest() { verify(appPrefs).shouldShowPostSignupInterstitial = false } + @Test + fun `given overlay should show when interstitial is shown then show jetpack individual plugin overlay`() = test { + whenever(wpJetpackIndividualPluginHelper.shouldShowJetpackIndividualPluginOverlay()).thenReturn(true) + + viewModel.onInterstitialShown() + advanceUntilIdle() + + assertThat(viewModel.navigationAction.value).isEqualTo(NavigationAction.SHOW_JETPACK_INDIVIDUAL_PLUGIN_OVERLAY) + } + + @Test + fun `given overlay should not show when interstitial is shown then don't show jetpack individual plugin overlay`() = + test { + whenever(wpJetpackIndividualPluginHelper.shouldShowJetpackIndividualPluginOverlay()).thenReturn(false) + + viewModel.onInterstitialShown() + advanceUntilIdle() + + assertThat(viewModel.navigationAction.value).isNull() + } + @Test fun `when create new site button is pressed should start site creation flow`() { viewModel.onCreateNewSiteButtonPressed() From e48fb3745232a75ba79ca64c2caa63b6d5b4802a Mon Sep 17 00:00:00 2001 From: Thomas Horta Date: Fri, 24 Mar 2023 17:55:13 -0300 Subject: [PATCH 383/856] remove SitePickerActivity from AppComponent --- .../main/java/org/wordpress/android/modules/AppComponent.java | 2 -- .../java/org/wordpress/android/ui/main/SitePickerActivity.java | 1 - 2 files changed, 3 deletions(-) diff --git a/WordPress/src/main/java/org/wordpress/android/modules/AppComponent.java b/WordPress/src/main/java/org/wordpress/android/modules/AppComponent.java index d86a548a8dbc..b59d99c219c0 100644 --- a/WordPress/src/main/java/org/wordpress/android/modules/AppComponent.java +++ b/WordPress/src/main/java/org/wordpress/android/modules/AppComponent.java @@ -239,8 +239,6 @@ public interface AppComponent { void inject(AccountSettingsFragment object); - void inject(SitePickerActivity object); - void inject(SitePickerAdapter object); void inject(SiteSettingsFragment object); diff --git a/WordPress/src/main/java/org/wordpress/android/ui/main/SitePickerActivity.java b/WordPress/src/main/java/org/wordpress/android/ui/main/SitePickerActivity.java index 12f9dcbce3ef..96f1d84f00f7 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/main/SitePickerActivity.java +++ b/WordPress/src/main/java/org/wordpress/android/ui/main/SitePickerActivity.java @@ -143,7 +143,6 @@ public class SitePickerActivity extends LocaleAwareActivity @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); - ((WordPress) getApplication()).component().inject(this); mViewModel = new ViewModelProvider(this, mViewModelFactory).get(SitePickerViewModel.class); From fd58d821921c04084a7367b172c31fadf850742a Mon Sep 17 00:00:00 2001 From: Thomas Horta Date: Fri, 24 Mar 2023 18:18:54 -0300 Subject: [PATCH 384/856] improve actionableEmptyView visibility events --- .../org/wordpress/android/ui/mysite/MySiteFragment.kt | 8 ++++---- .../org/wordpress/android/ui/mysite/MySiteViewModel.kt | 10 ++++------ 2 files changed, 8 insertions(+), 10 deletions(-) diff --git a/WordPress/src/main/java/org/wordpress/android/ui/mysite/MySiteFragment.kt b/WordPress/src/main/java/org/wordpress/android/ui/mysite/MySiteFragment.kt index 386accb55434..42ce7a4876ed 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/mysite/MySiteFragment.kt +++ b/WordPress/src/main/java/org/wordpress/android/ui/mysite/MySiteFragment.kt @@ -204,9 +204,9 @@ class MySiteFragment : Fragment(R.layout.my_site_fragment), private fun MySiteFragmentBinding.loadData(state: State.SiteSelected) { tabLayout.setVisible(state.tabsUiState.showTabs) updateTabs(state.tabsUiState) - actionableEmptyView.setVisible(false) - viewModel.setActionableEmptyViewGone(actionableEmptyView.isVisible) { + if (actionableEmptyView.isVisible) { actionableEmptyView.setVisible(false) + viewModel.onActionableEmptyViewGone() } if (state.siteInfoHeaderState.hasUpdates || !header.isVisible) { siteInfo.loadMySiteDetails(state.siteInfoHeaderState.siteInfoHeader) @@ -259,11 +259,11 @@ class MySiteFragment : Fragment(R.layout.my_site_fragment), private fun MySiteFragmentBinding.loadEmptyView(state: State.NoSites) { tabLayout.setVisible(state.tabsUiState.showTabs) - viewModel.setActionableEmptyViewVisible(actionableEmptyView.isVisible) { + if (!actionableEmptyView.isVisible) { actionableEmptyView.setVisible(true) actionableEmptyView.image.setVisible(state.shouldShowImage) + viewModel.onActionableEmptyViewVisible() } - actionableEmptyView.image.setVisible(state.shouldShowImage) siteTitle = getString(R.string.my_site_section_screen_title) updateSiteInfoToolbarView(state.siteInfoToolbarViewParams) appbarMain.setExpanded(false, true) diff --git a/WordPress/src/main/java/org/wordpress/android/ui/mysite/MySiteViewModel.kt b/WordPress/src/main/java/org/wordpress/android/ui/mysite/MySiteViewModel.kt index 12c935202862..3aab97874b1d 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/mysite/MySiteViewModel.kt +++ b/WordPress/src/main/java/org/wordpress/android/ui/mysite/MySiteViewModel.kt @@ -1541,14 +1541,12 @@ class MySiteViewModel @Inject constructor( fun isRefreshing() = mySiteSourceManager.isRefreshing() - fun setActionableEmptyViewGone(isVisible: Boolean, setGone: () -> Unit) { - if (isVisible) analyticsTrackerWrapper.track(Stat.MY_SITE_NO_SITES_VIEW_HIDDEN) - setGone() + fun onActionableEmptyViewGone() { + analyticsTrackerWrapper.track(Stat.MY_SITE_NO_SITES_VIEW_HIDDEN) } - fun setActionableEmptyViewVisible(isVisible: Boolean, setVisible: () -> Unit) { - if (!isVisible) analyticsTrackerWrapper.track(Stat.MY_SITE_NO_SITES_VIEW_DISPLAYED) - setVisible() + fun onActionableEmptyViewVisible() { + analyticsTrackerWrapper.track(Stat.MY_SITE_NO_SITES_VIEW_DISPLAYED) } fun trackWithTabSource(event: MySiteTrackWithTabSource) { From 2f8e1062a034df67192d38be7c9c3e6cf0e294ac Mon Sep 17 00:00:00 2001 From: Thomas Horta Date: Fri, 24 Mar 2023 18:48:21 -0300 Subject: [PATCH 385/856] make delay private --- .../viewmodel/accounts/PostSignupInterstitialViewModel.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/WordPress/src/main/java/org/wordpress/android/viewmodel/accounts/PostSignupInterstitialViewModel.kt b/WordPress/src/main/java/org/wordpress/android/viewmodel/accounts/PostSignupInterstitialViewModel.kt index 9a17663a40fd..203416e5d8c0 100644 --- a/WordPress/src/main/java/org/wordpress/android/viewmodel/accounts/PostSignupInterstitialViewModel.kt +++ b/WordPress/src/main/java/org/wordpress/android/viewmodel/accounts/PostSignupInterstitialViewModel.kt @@ -80,6 +80,6 @@ class PostSignupInterstitialViewModel } companion object { - const val DELAY_BEFORE_SHOWING_JETPACK_INDIVIDUAL_PLUGIN_OVERLAY = 500L + private const val DELAY_BEFORE_SHOWING_JETPACK_INDIVIDUAL_PLUGIN_OVERLAY = 500L } } From cd0a6bd69a175106f780ff3dc72b31fb9801a9e0 Mon Sep 17 00:00:00 2001 From: Thomas Horta Date: Fri, 24 Mar 2023 19:16:36 -0300 Subject: [PATCH 386/856] add overlay on MySite fragment (when empty) --- .../android/ui/mysite/MySiteFragment.kt | 4 ++ .../android/ui/mysite/MySiteViewModel.kt | 43 ++++++++++++++++++- .../android/ui/mysite/MySiteViewModelTest.kt | 30 ++++++++++++- 3 files changed, 74 insertions(+), 3 deletions(-) diff --git a/WordPress/src/main/java/org/wordpress/android/ui/mysite/MySiteFragment.kt b/WordPress/src/main/java/org/wordpress/android/ui/mysite/MySiteFragment.kt index 42ce7a4876ed..0f1cd14db71e 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/mysite/MySiteFragment.kt +++ b/WordPress/src/main/java/org/wordpress/android/ui/mysite/MySiteFragment.kt @@ -22,6 +22,7 @@ import org.wordpress.android.WordPress import org.wordpress.android.databinding.MySiteFragmentBinding import org.wordpress.android.databinding.MySiteInfoHeaderCardBinding import org.wordpress.android.ui.ActivityLauncher +import org.wordpress.android.ui.jetpackoverlay.individualplugin.WPJetpackIndividualPluginFragment import org.wordpress.android.ui.main.SitePickerActivity import org.wordpress.android.ui.main.utils.MeGravatarLoader import org.wordpress.android.ui.mysite.MySiteCardAndItem.SiteInfoHeaderCard @@ -187,6 +188,9 @@ class MySiteFragment : Fragment(R.layout.my_site_fragment), viewModel.selectTab.observeEvent(viewLifecycleOwner) { navTarget -> viewPager.setCurrentItem(navTarget.position, navTarget.smoothAnimation) } + viewModel.onShowJetpackIndividualPluginOverlay.observeEvent(viewLifecycleOwner) { + WPJetpackIndividualPluginFragment.show(requireActivity().supportFragmentManager) + } } private fun MySiteFragmentBinding.loadGravatar(avatarUrl: String) = diff --git a/WordPress/src/main/java/org/wordpress/android/ui/mysite/MySiteViewModel.kt b/WordPress/src/main/java/org/wordpress/android/ui/mysite/MySiteViewModel.kt index 3aab97874b1d..d7f6b36796e7 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/mysite/MySiteViewModel.kt +++ b/WordPress/src/main/java/org/wordpress/android/ui/mysite/MySiteViewModel.kt @@ -15,6 +15,7 @@ import androidx.lifecycle.switchMap import androidx.lifecycle.viewModelScope import kotlinx.coroutines.CoroutineDispatcher import kotlinx.coroutines.delay +import kotlinx.coroutines.launch import org.greenrobot.eventbus.Subscribe import org.greenrobot.eventbus.ThreadMode.MAIN import org.wordpress.android.R @@ -39,13 +40,14 @@ import org.wordpress.android.models.ReaderTag import org.wordpress.android.modules.BG_THREAD import org.wordpress.android.modules.UI_THREAD import org.wordpress.android.ui.PagePostCreationSourcesDetail.STORY_FROM_MY_SITE -import org.wordpress.android.ui.blaze.BlazeFlowSource import org.wordpress.android.ui.blaze.BlazeFeatureUtils +import org.wordpress.android.ui.blaze.BlazeFlowSource import org.wordpress.android.ui.bloggingprompts.BloggingPromptsPostTagProvider import org.wordpress.android.ui.bloggingprompts.BloggingPromptsSettingsHelper import org.wordpress.android.ui.jetpackoverlay.JetpackFeatureRemovalOverlayUtil import org.wordpress.android.ui.jetpackoverlay.JetpackFeatureRemovalOverlayUtil.JetpackFeatureCollectionOverlaySource.FEATURE_CARD import org.wordpress.android.ui.jetpackoverlay.JetpackFeatureRemovalPhaseHelper +import org.wordpress.android.ui.jetpackoverlay.individualplugin.WPJetpackIndividualPluginHelper import org.wordpress.android.ui.jetpackplugininstall.fullplugin.GetShowJetpackFullPluginInstallOnboardingUseCase import org.wordpress.android.ui.mysite.MySiteCardAndItem.Card.DashboardCards import org.wordpress.android.ui.mysite.MySiteCardAndItem.Card.DomainRegistrationCard @@ -203,7 +205,8 @@ class MySiteViewModel @Inject constructor( private val getShowJetpackFullPluginInstallOnboardingUseCase: GetShowJetpackFullPluginInstallOnboardingUseCase, private val jetpackInstallFullPluginShownTracker: JetpackInstallFullPluginShownTracker, private val blazeFeatureUtils: BlazeFeatureUtils, - private val jetpackFeatureRemovalPhaseHelper: JetpackFeatureRemovalPhaseHelper + private val jetpackFeatureRemovalPhaseHelper: JetpackFeatureRemovalPhaseHelper, + private val wpJetpackIndividualPluginHelper: WPJetpackIndividualPluginHelper, ) : ScopedViewModel(mainDispatcher) { private var isDefaultTabSet: Boolean = false private val _onSnackbarMessage = MutableLiveData>() @@ -222,6 +225,7 @@ class MySiteViewModel @Inject constructor( private val _onBloggingPromptsViewMore = SingleLiveEvent>() private val _onBloggingPromptsRemoved = SingleLiveEvent>() private val _onOpenJetpackInstallFullPluginOnboarding = SingleLiveEvent>() + private val _onShowJetpackIndividualPluginOverlay = SingleLiveEvent>() private val tabsUiState: LiveData = quickStartRepository.onQuickStartTabStep .switchMap { quickStartSiteMenuStep -> @@ -296,6 +300,7 @@ class MySiteViewModel @Inject constructor( val onBloggingPromptsViewMore = _onBloggingPromptsViewMore as LiveData> val onBloggingPromptsRemoved = _onBloggingPromptsRemoved as LiveData> val onOpenJetpackInstallFullPluginOnboarding = _onOpenJetpackInstallFullPluginOnboarding as LiveData> + val onShowJetpackIndividualPluginOverlay = _onShowJetpackIndividualPluginOverlay as LiveData> val onTrackWithTabSource = _onTrackWithTabSource as LiveData> val selectTab: LiveData> = _selectTab private var shouldMarkUpdateSiteTitleTaskComplete = false @@ -704,6 +709,7 @@ class MySiteViewModel @Inject constructor( add(Type.QUICK_LINK_RIBBON) add(Type.JETPACK_INSTALL_FULL_PLUGIN_CARD) } + MySiteTabType.DASHBOARD -> mutableListOf().apply { if (defaultTab == MySiteTabType.SITE_MENU) { add(Type.QUICK_START_CARD) @@ -711,6 +717,7 @@ class MySiteViewModel @Inject constructor( add(Type.DOMAIN_REGISTRATION_CARD) add(Type.QUICK_ACTIONS_CARD) } + MySiteTabType.ALL -> emptyList() } @@ -825,6 +832,7 @@ class MySiteViewModel @Inject constructor( QuickStartNewSiteTask.UPDATE_SITE_TITLE, QuickStartNewSiteTask.UPLOAD_SITE_ICON, quickStartRepository.quickStartType.getTaskFromString(QUICK_START_VIEW_SITE_LABEL) -> true + else -> false } } @@ -854,17 +862,20 @@ class MySiteViewModel @Inject constructor( ListItemAction.PLAN -> { SiteNavigationAction.OpenPlan(selectedSite) } + ListItemAction.POSTS -> SiteNavigationAction.OpenPosts(selectedSite) ListItemAction.PAGES -> { quickStartRepository.completeTask(QuickStartNewSiteTask.REVIEW_PAGES) SiteNavigationAction.OpenPages(selectedSite) } + ListItemAction.ADMIN -> SiteNavigationAction.OpenAdmin(selectedSite) ListItemAction.PEOPLE -> SiteNavigationAction.OpenPeople(selectedSite) ListItemAction.SHARING -> { quickStartRepository.requestNextStepOfTask(QuickStartNewSiteTask.ENABLE_POST_SHARING) SiteNavigationAction.OpenSharing(selectedSite) } + ListItemAction.DOMAINS -> SiteNavigationAction.OpenDomains(selectedSite) ListItemAction.SITE_SETTINGS -> SiteNavigationAction.OpenSiteSettings(selectedSite) ListItemAction.THEMES -> SiteNavigationAction.OpenThemes(selectedSite) @@ -875,16 +886,19 @@ class MySiteViewModel @Inject constructor( ) getStatsNavigationActionForSite(selectedSite) } + ListItemAction.MEDIA -> { quickStartRepository.requestNextStepOfTask( quickStartRepository.quickStartType.getTaskFromString(QUICK_START_UPLOAD_MEDIA_LABEL) ) SiteNavigationAction.OpenMedia(selectedSite) } + ListItemAction.COMMENTS -> SiteNavigationAction.OpenUnifiedComments(selectedSite) ListItemAction.VIEW_SITE -> { SiteNavigationAction.OpenSite(selectedSite) } + ListItemAction.JETPACK_SETTINGS -> SiteNavigationAction.OpenJetpackSettings(selectedSite) ListItemAction.BLAZE -> { blazeFeatureUtils.trackEntryPointTapped(BlazeFlowSource.MENU_ITEM) @@ -960,9 +974,11 @@ class MySiteViewModel @Inject constructor( !selectedSite.isUsingWpComRestApi -> { R.string.my_site_icon_dialog_change_requires_jetpack_message } + hasIcon -> { R.string.my_site_icon_dialog_change_requires_permission_message } + else -> { R.string.my_site_icon_dialog_add_requires_permission_message } @@ -1116,21 +1132,26 @@ class MySiteViewModel @Inject constructor( ) ) } + TAG_REMOVE_NEXT_STEPS_DIALOG -> onRemoveNextStepsDialogPositiveButtonClicked() } + is Negative -> when (interaction.tag) { TAG_ADD_SITE_ICON_DIALOG -> { quickStartRepository.completeTask(QuickStartNewSiteTask.UPLOAD_SITE_ICON) quickStartRepository.checkAndShowQuickStartNotice() } + TAG_CHANGE_SITE_ICON_DIALOG -> { analyticsTrackerWrapper.track(Stat.MY_SITE_ICON_REMOVED) quickStartRepository.completeTask(QuickStartNewSiteTask.UPLOAD_SITE_ICON) quickStartRepository.checkAndShowQuickStartNotice() selectedSiteRepository.updateSiteIconMediaId(0, true) } + TAG_REMOVE_NEXT_STEPS_DIALOG -> onRemoveNextStepsDialogNegativeButtonClicked() } + is Dismissed -> when (interaction.tag) { TAG_ADD_SITE_ICON_DIALOG, TAG_CHANGE_SITE_ICON_DIALOG -> { quickStartRepository.completeTask(QuickStartNewSiteTask.UPLOAD_SITE_ICON) @@ -1382,8 +1403,10 @@ class MySiteViewModel @Inject constructor( when (params.postCardType) { PostCardType.CREATE_FIRST, PostCardType.CREATE_NEXT -> _onNavigation.value = Event(SiteNavigationAction.OpenEditorToCreateNewPost(site)) + PostCardType.DRAFT -> _onNavigation.value = Event(SiteNavigationAction.EditDraftPost(site, params.postId)) + PostCardType.SCHEDULED -> _onNavigation.value = Event(SiteNavigationAction.EditScheduledPost(site, params.postId)) } @@ -1400,6 +1423,7 @@ class MySiteViewModel @Inject constructor( _onNavigation.value = when (postCardType) { PostCardType.CREATE_FIRST, PostCardType.CREATE_NEXT -> Event(SiteNavigationAction.OpenEditorToCreateNewPost(site)) + PostCardType.DRAFT -> Event(SiteNavigationAction.OpenDraftsPosts(site)) PostCardType.SCHEDULED -> Event(SiteNavigationAction.OpenScheduledPosts(site)) } @@ -1547,6 +1571,20 @@ class MySiteViewModel @Inject constructor( fun onActionableEmptyViewVisible() { analyticsTrackerWrapper.track(Stat.MY_SITE_NO_SITES_VIEW_DISPLAYED) + checkJetpackIndividualPluginOverlayShouldShow() + } + + private fun checkJetpackIndividualPluginOverlayShouldShow() { + // don't check if already shown + if (_onShowJetpackIndividualPluginOverlay.value?.peekContent() == Unit) return + + viewModelScope.launch { + val showOverlay = wpJetpackIndividualPluginHelper.shouldShowJetpackIndividualPluginOverlay() + if (showOverlay) { + delay(DELAY_BEFORE_SHOWING_JETPACK_INDIVIDUAL_PLUGIN_OVERLAY) + _onShowJetpackIndividualPluginOverlay.value = Event(Unit) + } + } } fun trackWithTabSource(event: MySiteTrackWithTabSource) { @@ -1762,5 +1800,6 @@ class MySiteViewModel @Inject constructor( const val LIST_SCROLL_DELAY_MS = 500L const val MY_SITE_TAB = "tab" const val TAB_SOURCE = "tab_source" + private const val DELAY_BEFORE_SHOWING_JETPACK_INDIVIDUAL_PLUGIN_OVERLAY = 500L } } diff --git a/WordPress/src/test/java/org/wordpress/android/ui/mysite/MySiteViewModelTest.kt b/WordPress/src/test/java/org/wordpress/android/ui/mysite/MySiteViewModelTest.kt index 0d7f724b9f77..c58ff140134c 100644 --- a/WordPress/src/test/java/org/wordpress/android/ui/mysite/MySiteViewModelTest.kt +++ b/WordPress/src/test/java/org/wordpress/android/ui/mysite/MySiteViewModelTest.kt @@ -58,6 +58,7 @@ import org.wordpress.android.ui.bloggingprompts.BloggingPromptsPostTagProvider import org.wordpress.android.ui.bloggingprompts.BloggingPromptsSettingsHelper import org.wordpress.android.ui.jetpackoverlay.JetpackFeatureRemovalOverlayUtil import org.wordpress.android.ui.jetpackoverlay.JetpackFeatureRemovalPhaseHelper +import org.wordpress.android.ui.jetpackoverlay.individualplugin.WPJetpackIndividualPluginHelper import org.wordpress.android.ui.jetpackplugininstall.fullplugin.GetShowJetpackFullPluginInstallOnboardingUseCase import org.wordpress.android.ui.mysite.MySiteCardAndItem.Card import org.wordpress.android.ui.mysite.MySiteCardAndItem.Card.DashboardCards @@ -327,6 +328,9 @@ class MySiteViewModelTest : BaseUnitTest() { @Mock lateinit var jetpackFeatureRemovalPhaseHelper: JetpackFeatureRemovalPhaseHelper + @Mock + lateinit var wpJetpackIndividualPluginHelper: WPJetpackIndividualPluginHelper + private lateinit var viewModel: MySiteViewModel private lateinit var uiModels: MutableList private lateinit var snackbars: MutableList @@ -546,7 +550,8 @@ class MySiteViewModelTest : BaseUnitTest() { getShowJetpackFullPluginInstallOnboardingUseCase, jetpackInstallFullPluginShownTracker, blazeFeatureUtils, - jetpackFeatureRemovalPhaseHelper + jetpackFeatureRemovalPhaseHelper, + wpJetpackIndividualPluginHelper, ) uiModels = mutableListOf() snackbars = mutableListOf() @@ -3273,6 +3278,7 @@ class MySiteViewModelTest : BaseUnitTest() { verify(blazeFeatureUtils).trackEntryPointTapped(BlazeFlowSource.DASHBOARD_CARD) } + @Test fun `when promote with blaze card menu is accessed, then blaze card menu is accessed is tracked`() = test { initSelectedSite() @@ -3297,6 +3303,28 @@ class MySiteViewModelTest : BaseUnitTest() { ) } + @Test + fun `when onActionableEmptyViewVisible is invoked then show jetpack individual plugin overlay`() = + test { + whenever(wpJetpackIndividualPluginHelper.shouldShowJetpackIndividualPluginOverlay()).thenReturn(true) + + viewModel.onActionableEmptyViewVisible() + advanceUntilIdle() + + assertThat(viewModel.onShowJetpackIndividualPluginOverlay.value?.peekContent()).isEqualTo(Unit) + } + + @Test + fun `when onActionableEmptyViewVisible is invoked then don't show jetpack individual plugin overlay`() = + test { + whenever(wpJetpackIndividualPluginHelper.shouldShowJetpackIndividualPluginOverlay()).thenReturn(false) + + viewModel.onActionableEmptyViewVisible() + advanceUntilIdle() + + assertThat(viewModel.onShowJetpackIndividualPluginOverlay.value?.peekContent()).isNull() + } + private fun findQuickActionsCard() = getLastItems().find { it is QuickActionsCard } as QuickActionsCard? private fun findQuickStartDynamicCard() = getLastItems().find { it is DynamicCard } as DynamicCard? From 26c45f68f2c0d08d88bfd86f9edab922b47c8e7f Mon Sep 17 00:00:00 2001 From: Thomas Horta Date: Fri, 24 Mar 2023 19:51:22 -0300 Subject: [PATCH 387/856] remove unused imports --- .idea/codeStyles/Project.xml | 4 +--- .../main/java/org/wordpress/android/modules/AppComponent.java | 2 -- 2 files changed, 1 insertion(+), 5 deletions(-) diff --git a/.idea/codeStyles/Project.xml b/.idea/codeStyles/Project.xml index a145657e502b..5ee4f2b40452 100644 --- a/.idea/codeStyles/Project.xml +++ b/.idea/codeStyles/Project.xml @@ -35,8 +35,6 @@ - +