Skip to content

Commit

Permalink
Merge pull request #12492 from brave/bravewnews-android-disables-defa…
Browse files Browse the repository at this point in the history
…ult-optincard-1.37.x

[Android] Brave news - disables default peeking card
  • Loading branch information
kjozwiak authored Mar 6, 2022
2 parents b386093 + 631a487 commit b486d94
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -661,6 +661,20 @@ private void initPreferenceObserver() {
}
}
refreshFeed();
} else if (TextUtils.equals(key, BravePreferenceKeys.BRAVE_NEWS_PREF_TURN_ON_NEWS)) {
mIsNewsOn = BravePrefServiceBridge.getInstance().getNewsOptIn();
SharedPreferences sharedPreferences = ContextUtils.getAppSharedPreferences();
mIsShowOptin =
sharedPreferences.getBoolean(BraveNewsPreferences.PREF_SHOW_OPTIN, false);
mIsShowNewsOn = BravePrefServiceBridge.getInstance().getShowNews();
if ((!mIsNewsOn && mIsShowOptin) || (mIsNewsOn && !mIsShowOptin)) {
SharedPreferences.Editor sharedPreferencesEditor = sharedPreferences.edit();
sharedPreferencesEditor.putBoolean(BraveNewsPreferences.PREF_SHOW_OPTIN, true);
sharedPreferencesEditor.apply();
mOptinLayout.setVisibility(View.VISIBLE);
mRecyclerView.setVisibility(View.GONE);
initNews();
}
}
};
}
Expand Down Expand Up @@ -880,12 +894,7 @@ public void run() {
}

private void refreshFeed() {
mAdapterFeedCard = new BraveNewsAdapterFeedCard(
mActivity, Glide.with(mActivity), mNewsItemsFeedCard, mBraveNewsController);
mRecyclerView.setAdapter(mAdapterFeedCard);
mIsShowNewsOn = BravePrefServiceBridge.getInstance().getShowNews();
mImageCreditLayout.setVisibility(View.VISIBLE);
mImageCreditLayout.setAlpha(1.0f);
if (!mIsShowNewsOn) {
correctPosition(false);
if (mRecyclerView != null) {
Expand All @@ -897,13 +906,21 @@ private void refreshFeed() {
mImageCreditLayout.setAlpha(1.0f);
return;
} else {
mAdapterFeedCard = new BraveNewsAdapterFeedCard(
mActivity, Glide.with(mActivity), mNewsItemsFeedCard, mBraveNewsController);
mRecyclerView.setAdapter(mAdapterFeedCard);

mImageCreditLayout.setVisibility(View.VISIBLE);
mImageCreditLayout.setAlpha(1.0f);
SharedPreferencesManager.getInstance().removeObserver(mPreferenceObserver);
initPreferenceObserver();
if (mPreferenceObserver != null) {
SharedPreferencesManager.getInstance().addObserver(mPreferenceObserver);
}
}
getFeed();
if (mIsShowNewsOn && BravePrefServiceBridge.getInstance().getNewsOptIn()) {
getFeed();
}
}

@SuppressLint("ClickableViewAccessibility")
Expand Down Expand Up @@ -973,10 +990,13 @@ private void initNews() {
SharedPreferences sharedPreferences = ContextUtils.getAppSharedPreferences();

mIsNewsOn = BravePrefServiceBridge.getInstance().getNewsOptIn();
mIsShowOptin = sharedPreferences.getBoolean(BraveNewsPreferences.PREF_SHOW_OPTIN, true);
mIsShowOptin = sharedPreferences.getBoolean(BraveNewsPreferences.PREF_SHOW_OPTIN, false);
mIsShowNewsOn = BravePrefServiceBridge.getInstance().getShowNews();

if ((!mIsNewsOn && mIsShowOptin)) {
if ((!mIsNewsOn && mIsShowOptin) || (mIsNewsOn && mIsShowOptin)) {
SharedPreferences.Editor sharedPreferencesEditor = sharedPreferences.edit();
sharedPreferencesEditor.putBoolean(BraveNewsPreferences.PREF_SHOW_OPTIN, true);
sharedPreferencesEditor.apply();
mOptinLayout.setVisibility(View.VISIBLE);
} else if (mIsShowNewsOn && mIsNewsOn) {
if (mOptinLayout != null) {
Expand Down Expand Up @@ -1375,7 +1395,6 @@ public void onScrolled(@NonNull RecyclerView recyclerView, int dx, int dy) {
}
});
}

if (mOptinLayout != null) {
mOptinClose.setOnClickListener(new View.OnClickListener() {
@Override
Expand All @@ -1393,10 +1412,7 @@ public void onClick(View v) {
mOptinLearnMore.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent browserIntent =
new Intent(Intent.ACTION_VIEW, Uri.parse(BRAVE_LEARN_MORE_URL));
browserIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
mActivity.startActivity(browserIntent);
TabUtils.openUrlInSameTab(BRAVE_LEARN_MORE_URL);
}
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ public final class BravePreferenceKeys {
public static final String BRAVE_NEWS_CHANGE_SOURCE = "brave_news_change_source";
public static final String BRAVE_NEWS_FEED_HASH = "brave_news_feed_hash";
public static final String BRAVE_NEWS_PREF_SHOW_NEWS = "kNewTabPageShowToday";
public static final String BRAVE_NEWS_PREF_TURN_ON_NEWS = "kBraveTodayOptedIn";
public static final String BRAVE_USE_BIOMETRICS_FOR_WALLET =
"org.chromium.chrome.browser.Brave_Use_Biometrics_For_Wallet";
public static final String BRAVE_BIOMETRICS_FOR_WALLET_IV =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,7 @@ public void onCreate(Bundle savedInstanceState) {
if (!isNewsOn) {
mTurnOnNews.setChecked(false);
mShowNews.setVisible(false);
setSourcesVisibility(BravePrefServiceBridge.getInstance().getNewsOptIn());
} else {
mTurnOnNews.setChecked(true);
mTurnOnNews.setVisible(false);
Expand All @@ -150,10 +151,10 @@ public boolean onPreferenceChange(Preference preference, Object newValue) {
String key = preference.getKey();
if (PREF_TURN_ON_NEWS.equals(key)) {
BravePrefServiceBridge.getInstance().setNewsOptIn((boolean) newValue);
BravePrefServiceBridge.getInstance().setShowNews(false);
if ((boolean) newValue) {
mShowNews.setVisible(true);
mShowNews.setChecked(true);
BravePrefServiceBridge.getInstance().setShowNews(true);
mShowNews.setChecked(false);
} else {
mShowNews.setVisible(false);
}
Expand Down
2 changes: 1 addition & 1 deletion browser/ui/android/strings/android_brave_strings.grd
Original file line number Diff line number Diff line change
Expand Up @@ -271,7 +271,7 @@ This file contains all "about" strings. It is set to NOT be translated, in tran
More Brave Offers
</message>
<message name="IDS_NEWS_TURN_ON_BUTTON" desc="Text for turn on button">
Show Brave News
Enable Brave News
</message>
<!-- // for RSS
<message name="IDS_NEWS_YOUR_SOURCES_SECTION" desc="Text for custom sources section">
Expand Down

0 comments on commit b486d94

Please sign in to comment.