Skip to content

Commit

Permalink
Re-organize calls sequence at P3aOnboardingActivity class
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexeyBarabash committed Oct 19, 2021
1 parent 8c5ed63 commit 76c878e
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import androidx.annotation.NonNull;

import org.chromium.base.Log;
import org.chromium.base.ThreadUtils;
import org.chromium.chrome.R;
import org.chromium.chrome.browser.BraveRewardsHelper;
import org.chromium.chrome.browser.app.BraveActivity;
Expand All @@ -36,13 +37,17 @@
import org.chromium.chrome.browser.util.PackageUtils;

public class P3aOnboardingActivity extends FirstRunActivityBase {
private boolean mNativeInitialized;
// mInitializeViewsDone and mInvokePostWorkAtInitializeViews are accessed
// from the same thread, so no need to use extra locks
private boolean mInitializeViewsDone;
private boolean mInvokePostWorkAtInitializeViews;
private boolean mIsP3aEnabled;
private FirstRunFlowSequencer mFirstRunFlowSequencer;
private CheckBox mP3aOnboardingCheckbox;
private Button mBtnContinue;

private void initializeViews() {
assert !mInitializeViewsDone;
setContentView(R.layout.activity_p3a_onboarding);

boolean isFirstInstall = PackageUtils.isFirstInstall(this);
Expand Down Expand Up @@ -110,14 +115,15 @@ public void updateDrawState(@NonNull TextPaint ds) {
Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
p3aOnboardingText.setMovementMethod(LinkMovementMethod.getInstance());
p3aOnboardingText.setText(productAnalysisTextSS);
}

@Override
public void finishNativeInitialization() {
super.finishNativeInitialization();
assert !mNativeInitialized;
mInitializeViewsDone = true;
if (mInvokePostWorkAtInitializeViews) {
finishNativeInitializationPostWork();
}
}

mNativeInitialized = true;
private void finishNativeInitializationPostWork() {
assert mInitializeViewsDone;

try {
mIsP3aEnabled = BravePrefServiceBridge.getInstance().getP3AEnabled();
Expand All @@ -137,6 +143,20 @@ public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
}
}
});

mBtnContinue.setEnabled(true);
}

@Override
public void finishNativeInitialization() {
ThreadUtils.assertOnUiThread();
super.finishNativeInitialization();

if (mInitializeViewsDone) {
finishNativeInitializationPostWork();
} else {
mInvokePostWorkAtInitializeViews = true;
}
}

@Override
Expand Down Expand Up @@ -165,12 +185,6 @@ private void exitOnboarding() {
}

private void accept() {
if (!mNativeInitialized) {
// Disable the "accept" button to indicate that "something is happening".
mBtnContinue.setEnabled(false);
return;
}

// Do not use existing function because it contains consent to Google crash report upload
SharedPreferencesManager.getInstance().writeBoolean(
ChromePreferenceKeys.FIRST_RUN_CACHED_TOS_ACCEPTED, true);
Expand Down
1 change: 1 addition & 0 deletions android/java/res/layout/activity_p3a_onboarding.xml
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@

<Button
android:id="@+id/btn_continue"
android:enabled="false"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
Expand Down

0 comments on commit 76c878e

Please sign in to comment.