4
4
import android .app .Activity ;
5
5
import android .app .ProgressDialog ;
6
6
import android .content .Intent ;
7
+ import android .content .SharedPreferences ;
7
8
import android .content .res .Configuration ;
8
9
import android .graphics .drawable .Drawable ;
9
10
import android .net .Uri ;
224
225
import org .wordpress .aztec .util .AztecLog ;
225
226
226
227
import java .io .File ;
228
+ import java .math .BigInteger ;
229
+ import java .security .MessageDigest ;
230
+ import java .security .NoSuchAlgorithmException ;
227
231
import java .util .ArrayList ;
228
232
import java .util .Collections ;
229
233
import java .util .HashMap ;
@@ -302,7 +306,7 @@ public class EditPostActivity extends LocaleAwareActivity implements
302
306
private static final int PAGE_SETTINGS = 1 ;
303
307
private static final int PAGE_PUBLISH_SETTINGS = 2 ;
304
308
private static final int PAGE_HISTORY = 3 ;
305
- private static final int EDITOR_ONBOARDING_PHASE_PERCENTAGE = 0 ;
309
+ private static final int EDITOR_ONBOARDING_PHASE_PERCENTAGE = 50 ;
306
310
307
311
private AztecImageLoader mAztecImageLoader ;
308
312
@@ -2296,7 +2300,7 @@ private GutenbergPropsBuilder getGutenbergPropsBuilder() {
2296
2300
boolean isFreeWPCom = mSite .isWPCom () && SiteUtils .onFreePlan (mSite );
2297
2301
boolean isWPComSite = mSite .isWPCom () || mSite .isWPComAtomic ();
2298
2302
2299
- boolean enableEditorOnboarding = canViewEditorOnboarding () && ! AppPrefs . hasLaunchedGutenbergEditor ();
2303
+ boolean enableEditorOnboarding = ! AppPrefs . hasLaunchedGutenbergEditor () && canViewEditorOnboarding ();
2300
2304
2301
2305
return new GutenbergPropsBuilder (
2302
2306
mContactInfoBlockFeatureConfig .isEnabled () && SiteUtils .supportsContactInfoFeature (mSite ),
@@ -2316,9 +2320,51 @@ private GutenbergPropsBuilder getGutenbergPropsBuilder() {
2316
2320
);
2317
2321
}
2318
2322
2319
- private Boolean canViewEditorOnboarding () {
2320
- return (mAccountStore .getAccount ().getUserId () % 100 >= (100 - EDITOR_ONBOARDING_PHASE_PERCENTAGE )
2321
- || BuildConfig .DEBUG );
2323
+ /**
2324
+ * Temporary method for the Editor Onboarding project to control the percentage
2325
+ * of users able to use this new editor onboarding tooltip feature. This will eventually
2326
+ * be removed when the functionality is opened to all users.
2327
+ */
2328
+ private boolean canViewEditorOnboarding () {
2329
+ // Get the userId for the logged in user. If not WPcom, use the anonymous userId
2330
+ // generated by tracks.
2331
+ long userAccountId = mAccountStore .getAccount ().getUserId ();
2332
+ String userId = String .valueOf (userAccountId );
2333
+ if (userAccountId == 0 ) {
2334
+ SharedPreferences preferences = PreferenceManager .getDefaultSharedPreferences (getApplicationContext ());
2335
+ userId = preferences .getString ("nosara_tracks_anon_id" , null );
2336
+ }
2337
+
2338
+ int hashedUserId = convertUserIdToHash (userId , "can_view_editor_onboarding" );
2339
+ return hashedUserId % 100 >= (100 - EDITOR_ONBOARDING_PHASE_PERCENTAGE ) || BuildConfig .DEBUG ;
2340
+ }
2341
+
2342
+ /**
2343
+ * Temporary method for the Editor Onboarding project to control the percentage
2344
+ * of users able to use this new editor onboarding tooltip feature. This will eventually
2345
+ * be removed when the functionality is opened to all users.
2346
+ *
2347
+ * Uses cryptography to hash a userId plus a seed containing the feature flag, converts
2348
+ * the result into a BigInteger, then divides that value by 100 and returns the remainder.
2349
+ * The value returned will be used to determine if a user should see the editor onboarding
2350
+ * tooltip.
2351
+ *
2352
+ * @param userId A unique ID for the logged in user.
2353
+ * @param seed The feature string to keep hashed value results between features unique.
2354
+ * @return An int between 1 and 100
2355
+ */
2356
+ private int convertUserIdToHash (String userId , String seed ) {
2357
+ String seededUserId = userId + seed ;
2358
+ int hashInt = 0 ;
2359
+ try {
2360
+ MessageDigest digest = MessageDigest .getInstance ("SHA-256" );
2361
+ byte [] hash = digest .digest (seededUserId .getBytes ());
2362
+ BigInteger value = new BigInteger (hash );
2363
+ hashInt = value .mod (BigInteger .valueOf (100 )).intValue ();
2364
+ } catch (NoSuchAlgorithmException e ) {
2365
+ AppLog .e (T .EDITOR , e );
2366
+ }
2367
+ return hashInt ;
2322
2368
}
2323
2369
2324
2370
// Moved from EditPostContentFragment
@@ -3216,7 +3262,6 @@ public Map<String, String> onAuthHeaderRequested(String url) {
3216
3262
3217
3263
@ Override
3218
3264
public void onEditorFragmentInitialized () {
3219
- boolean shouldFinishInit = true ;
3220
3265
// now that we have the Post object initialized,
3221
3266
// check whether we have media items to insert from the WRITE POST with media functionality
3222
3267
if (getIntent ().hasExtra (EXTRA_INSERT_MEDIA )) {
0 commit comments