Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Re-organize calls sequence at P3aOnboardingActivity class (uplift to 1.31.x) #10593

Merged
merged 1 commit into from
Oct 21, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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