22
22
import static com .android .launcher3 .allapps .BaseAllAppsAdapter .VIEW_TYPE_WORK_DISABLED_CARD ;
23
23
import static com .android .launcher3 .allapps .BaseAllAppsAdapter .VIEW_TYPE_WORK_EDU_CARD ;
24
24
import static com .android .launcher3 .logging .StatsLogManager .LauncherEvent .LAUNCHER_TURN_OFF_WORK_APPS_TAP ;
25
+ import static com .android .launcher3 .logging .StatsLogManager .LauncherEvent .LAUNCHER_TURN_ON_WORK_APPS_TAP ;
26
+ import static com .android .launcher3 .model .BgDataModel .Callbacks .FLAG_HAS_MULTIPLE_PROFILES ;
25
27
import static com .android .launcher3 .model .BgDataModel .Callbacks .FLAG_HAS_SHORTCUT_PERMISSION ;
26
28
import static com .android .launcher3 .model .BgDataModel .Callbacks .FLAG_QUIET_MODE_CHANGE_PERMISSION ;
27
29
import static com .android .launcher3 .model .BgDataModel .Callbacks .FLAG_QUIET_MODE_ENABLED ;
@@ -65,6 +67,8 @@ public class WorkProfileManager extends UserProfileManager
65
67
private final UserManager mUserManager ;
66
68
private final UserCache mUserCache ;
67
69
70
+ private boolean mHasMultipleProfiles ;
71
+
68
72
public WorkProfileManager (
69
73
UserManager userManager , ActivityAllAppsContainerView allApps ,
70
74
StatsLogManager statsLogManager , UserCache userCache ) {
@@ -92,7 +96,14 @@ private void updateWorkFAB(int page) {
92
96
if (mWorkModeSwitch != null ) {
93
97
if (page == MAIN || page == SEARCH ) {
94
98
mWorkModeSwitch .animateVisibility (false );
95
- } else if (page == WORK && getCurrentState () == STATE_ENABLED ) {
99
+ } else if (page == WORK && shouldShowWorkApps ()) {
100
+ if (getCurrentState () == STATE_ENABLED ) {
101
+ mWorkModeSwitch .setPauseMode (true /* doPause */ );
102
+ mWorkModeSwitch .setOnClickListener (this ::onWorkFabClickedTurnOff );
103
+ } else if (getCurrentState () == STATE_DISABLED ) {
104
+ mWorkModeSwitch .setPauseMode (false /* doPause */ );
105
+ mWorkModeSwitch .setOnClickListener (this ::onWorkFabClickedTurnOn );
106
+ }
96
107
mWorkModeSwitch .animateVisibility (true );
97
108
}
98
109
}
@@ -118,11 +129,12 @@ public void reset() {
118
129
}
119
130
120
131
private void updateCurrentState (@ UserProfileState int currentState ) {
132
+ mHasMultipleProfiles = mAllApps .getAppsStore ().hasModelFlag (FLAG_HAS_MULTIPLE_PROFILES );
121
133
setCurrentState (currentState );
122
134
if (getAH () != null ) {
123
135
getAH ().mAppsList .updateAdapterItems ();
124
136
}
125
- if (getCurrentState () == STATE_ENABLED ) {
137
+ if (shouldShowWorkApps () ) {
126
138
attachWorkModeSwitch ();
127
139
} else if (getCurrentState () == STATE_DISABLED ) {
128
140
detachWorkModeSwitch ();
@@ -154,7 +166,6 @@ public boolean attachWorkModeSwitch() {
154
166
if (getAH () != null ) {
155
167
getAH ().applyPadding ();
156
168
}
157
- mWorkModeSwitch .setOnClickListener (this ::onWorkFabClicked );
158
169
return true ;
159
170
}
160
171
/**
@@ -180,7 +191,8 @@ private ActivityAllAppsContainerView.AdapterHolder getAH() {
180
191
* returns whether or not work apps should be visible in work tab.
181
192
*/
182
193
public boolean shouldShowWorkApps () {
183
- return getCurrentState () != WorkProfileManager .STATE_DISABLED ;
194
+ return getCurrentState () != WorkProfileManager .STATE_DISABLED
195
+ || mHasMultipleProfiles ;
184
196
}
185
197
186
198
public boolean hasWorkApps () {
@@ -191,7 +203,7 @@ public boolean hasWorkApps() {
191
203
* Adds work profile specific adapter items to adapterItems and returns number of items added
192
204
*/
193
205
public int addWorkItems (ArrayList <AdapterItem > adapterItems ) {
194
- if (getCurrentState () == WorkProfileManager . STATE_DISABLED ) {
206
+ if (! shouldShowWorkApps () ) {
195
207
//add disabled card here.
196
208
adapterItems .add (new AdapterItem (VIEW_TYPE_WORK_DISABLED_CARD ));
197
209
} else if (getCurrentState () == WorkProfileManager .STATE_ENABLED && !isEduSeen ()) {
@@ -204,13 +216,20 @@ private boolean isEduSeen() {
204
216
return LauncherPrefs .get (mAllApps .getContext ()).get (WORK_EDU_STEP ) != 0 ;
205
217
}
206
218
207
- private void onWorkFabClicked (View view ) {
219
+ private void onWorkFabClickedTurnOff (View view ) {
208
220
if (getCurrentState () == STATE_ENABLED && mWorkModeSwitch .isEnabled ()) {
209
221
logEvents (LAUNCHER_TURN_OFF_WORK_APPS_TAP );
210
222
setWorkProfileEnabled (false );
211
223
}
212
224
}
213
225
226
+ private void onWorkFabClickedTurnOn (View view ) {
227
+ if (getCurrentState () == STATE_DISABLED && mWorkModeSwitch .isEnabled ()) {
228
+ logEvents (LAUNCHER_TURN_ON_WORK_APPS_TAP );
229
+ setWorkProfileEnabled (true );
230
+ }
231
+ }
232
+
214
233
public RecyclerView .OnScrollListener newScrollListener () {
215
234
return new RecyclerView .OnScrollListener () {
216
235
int totalDelta = 0 ;
0 commit comments