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

[Android] Brave news - disables default peeking card #12489

Merged
merged 1 commit into from
Mar 4, 2022
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 @@ -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 @@ -200,6 +200,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 @@ -218,10 +219,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>
<message name="IDS_NEWS_YOUR_SOURCES_SECTION" desc="Text for custom sources section">
Your sources
Expand Down