Skip to content

Commit 7124028

Browse files
authored
Merge pull request #14897 from wordpress-mobile/task/enable-tooltip-50-percent
Editor Onboarding: Enable tooltip for 50% of users
2 parents e462819 + 61a8fee commit 7124028

File tree

1 file changed

+51
-6
lines changed

1 file changed

+51
-6
lines changed

WordPress/src/main/java/org/wordpress/android/ui/posts/EditPostActivity.java

Lines changed: 51 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import android.app.Activity;
55
import android.app.ProgressDialog;
66
import android.content.Intent;
7+
import android.content.SharedPreferences;
78
import android.content.res.Configuration;
89
import android.graphics.drawable.Drawable;
910
import android.net.Uri;
@@ -224,6 +225,9 @@
224225
import org.wordpress.aztec.util.AztecLog;
225226

226227
import java.io.File;
228+
import java.math.BigInteger;
229+
import java.security.MessageDigest;
230+
import java.security.NoSuchAlgorithmException;
227231
import java.util.ArrayList;
228232
import java.util.Collections;
229233
import java.util.HashMap;
@@ -302,7 +306,7 @@ public class EditPostActivity extends LocaleAwareActivity implements
302306
private static final int PAGE_SETTINGS = 1;
303307
private static final int PAGE_PUBLISH_SETTINGS = 2;
304308
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;
306310

307311
private AztecImageLoader mAztecImageLoader;
308312

@@ -2296,7 +2300,7 @@ private GutenbergPropsBuilder getGutenbergPropsBuilder() {
22962300
boolean isFreeWPCom = mSite.isWPCom() && SiteUtils.onFreePlan(mSite);
22972301
boolean isWPComSite = mSite.isWPCom() || mSite.isWPComAtomic();
22982302

2299-
boolean enableEditorOnboarding = canViewEditorOnboarding() && !AppPrefs.hasLaunchedGutenbergEditor();
2303+
boolean enableEditorOnboarding = !AppPrefs.hasLaunchedGutenbergEditor() && canViewEditorOnboarding();
23002304

23012305
return new GutenbergPropsBuilder(
23022306
mContactInfoBlockFeatureConfig.isEnabled() && SiteUtils.supportsContactInfoFeature(mSite),
@@ -2316,9 +2320,51 @@ private GutenbergPropsBuilder getGutenbergPropsBuilder() {
23162320
);
23172321
}
23182322

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;
23222368
}
23232369

23242370
// Moved from EditPostContentFragment
@@ -3216,7 +3262,6 @@ public Map<String, String> onAuthHeaderRequested(String url) {
32163262

32173263
@Override
32183264
public void onEditorFragmentInitialized() {
3219-
boolean shouldFinishInit = true;
32203265
// now that we have the Post object initialized,
32213266
// check whether we have media items to insert from the WRITE POST with media functionality
32223267
if (getIntent().hasExtra(EXTRA_INSERT_MEDIA)) {

0 commit comments

Comments
 (0)