Skip to content

Commit 55e73fb

Browse files
authored
Merge pull request #17187 from GitStartHQ/issue/16656-Quick_Start_Retain_Quick_Start_focus_point_after_device_rotation
Quick Start: Retain Quick Start focus point after device rotation #16656
2 parents 442227b + da767e3 commit 55e73fb

File tree

2 files changed

+22
-3
lines changed

2 files changed

+22
-3
lines changed

WordPress/src/main/java/org/wordpress/android/ui/main/WPMainActivity.java

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -209,6 +209,7 @@ public class WPMainActivity extends LocaleAwareActivity implements
209209
public static final String ARG_SELECTED_SITE = "SELECTED_SITE_ID";
210210
public static final String ARG_STAT_TO_TRACK = "stat_to_track";
211211
public static final String ARG_EDITOR_ORIGIN = "editor_origin";
212+
public static final String ARG_CURRENT_FOCUS = "CURRENT_FOCUS";
212213

213214
// Track the first `onResume` event for the current session so we can use it for Analytics tracking
214215
private static boolean mFirstResume = true;
@@ -228,6 +229,7 @@ public class WPMainActivity extends LocaleAwareActivity implements
228229
private static final String MAIN_BOTTOM_SHEET_TAG = "MAIN_BOTTOM_SHEET_TAG";
229230
private static final String BLOGGING_REMINDERS_BOTTOM_SHEET_TAG = "BLOGGING_REMINDERS_BOTTOM_SHEET_TAG";
230231
private final Handler mHandler = new Handler();
232+
private FocusPointInfo mCurrentActiveFocusPoint = null;
231233

232234
@Inject AccountStore mAccountStore;
233235
@Inject SiteStore mSiteStore;
@@ -383,6 +385,12 @@ && getIntent().getExtras().getBoolean(ARG_CONTINUE_JETPACK_CONNECT, false)) {
383385
}
384386
checkDismissNotification();
385387
checkTrackAnalyticsEvent();
388+
} else {
389+
FocusPointInfo current = (FocusPointInfo)
390+
savedInstanceState.getSerializable(ARG_CURRENT_FOCUS);
391+
if (current != null) {
392+
mHandler.post(() -> addOrRemoveQuickStartFocusPoint(current.getTask(), true));
393+
}
386394
}
387395

388396
// ensure the deep linking activity is enabled. It may have been disabled elsewhere and failed to get re-enabled
@@ -438,7 +446,6 @@ && getIntent().getExtras().getBoolean(ARG_CONTINUE_JETPACK_CONNECT, false)) {
438446
}
439447

440448
scheduleLocalNotifications();
441-
442449
initViewModel();
443450

444451
if (getIntent().getBooleanExtra(ARG_OPEN_BLOGGING_REMINDERS, false)) {
@@ -513,6 +520,12 @@ private void scheduleLocalNotifications() {
513520
mWeeklyRoundupScheduler.schedule();
514521
}
515522

523+
@Override
524+
protected void onSaveInstanceState(@NonNull Bundle outState) {
525+
outState.putSerializable(ARG_CURRENT_FOCUS, mCurrentActiveFocusPoint);
526+
super.onSaveInstanceState(outState);
527+
}
528+
516529
private void initViewModel() {
517530
mFloatingActionButton = findViewById(R.id.fab_button);
518531
mFabTooltip = findViewById(R.id.fab_tooltip);
@@ -1007,7 +1020,7 @@ public void onPageChanged(int position) {
10071020
mReaderTracker.onBottomNavigationTabChanged();
10081021
PageType pageType = WPMainNavigationView.getPageType(position);
10091022
trackLastVisiblePage(pageType, true);
1010-
1023+
mCurrentActiveFocusPoint = null;
10111024
if (pageType == PageType.READER) {
10121025
// MySite fragment might not be attached to activity, so we need to remove focus point from here
10131026
QuickStartUtils.removeQuickStartFocusPoint(findViewById(R.id.root_view_main));
@@ -1337,6 +1350,7 @@ private void addOrRemoveQuickStartFocusPoint(QuickStartTask activeTask, boolean
13371350
verticalOffset = 0;
13381351
}
13391352
if (targetView != null && shouldAdd) {
1353+
mCurrentActiveFocusPoint = new FocusPointInfo(activeTask, true);
13401354
QuickStartUtils.addQuickStartFocusPointAboveTheView(
13411355
parentView,
13421356
targetView,

WordPress/src/main/java/org/wordpress/android/viewmodel/main/WPMainActivityViewModel.kt

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ import org.wordpress.android.util.merge
4747
import org.wordpress.android.viewmodel.Event
4848
import org.wordpress.android.viewmodel.ScopedViewModel
4949
import org.wordpress.android.viewmodel.SingleLiveEvent
50+
import java.io.Serializable
5051
import java.util.Date
5152
import java.util.Locale
5253
import javax.inject.Inject
@@ -389,5 +390,9 @@ class WPMainActivityViewModel @Inject constructor(
389390
data class FocusPointInfo(
390391
val task: QuickStartTask,
391392
val isVisible: Boolean
392-
)
393+
) : Serializable {
394+
companion object {
395+
const val serialVersionUID = 1L
396+
}
397+
}
393398
}

0 commit comments

Comments
 (0)