From 495c505f5a36704f467280ff04e4c83077be96ec Mon Sep 17 00:00:00 2001 From: Deep Pandya <5146988+deeppandya@users.noreply.github.com> Date: Mon, 8 Jul 2024 13:34:59 +0530 Subject: [PATCH] Merge pull request #24527 from brave/fix_gpc_crash_brave_news_settings_android [Android] fix gpc crash brave news settings --- .../browser/brave_news/BraveNewsUtils.java | 46 +++++++++++-------- 1 file changed, 27 insertions(+), 19 deletions(-) diff --git a/android/java/org/chromium/chrome/browser/brave_news/BraveNewsUtils.java b/android/java/org/chromium/chrome/browser/brave_news/BraveNewsUtils.java index 87f5dbb883e1..b08374e43867 100644 --- a/android/java/org/chromium/chrome/browser/brave_news/BraveNewsUtils.java +++ b/android/java/org/chromium/chrome/browser/brave_news/BraveNewsUtils.java @@ -219,11 +219,13 @@ public static List getSuggestionsPublisherList() { public static void setFollowingPublisherList() { List publisherList = new ArrayList<>(); - for (Publisher publisher : mGlobalPublisherList) { - if (publisher.userEnabledStatus == UserEnabled.ENABLED - || (publisher.type == PublisherType.DIRECT_SOURCE - && publisher.userEnabledStatus != UserEnabled.DISABLED)) { - publisherList.add(publisher); + if (mGlobalPublisherList != null && mGlobalPublisherList.size() > 0) { + for (Publisher publisher : mGlobalPublisherList) { + if (publisher.userEnabledStatus == UserEnabled.ENABLED + || (publisher.type == PublisherType.DIRECT_SOURCE + && publisher.userEnabledStatus != UserEnabled.DISABLED)) { + publisherList.add(publisher); + } } } mFollowingPublisherList = publisherList; @@ -244,11 +246,13 @@ public static List getFollowingPublisherList() { public static void setFollowingChannelList() { List channelList = new ArrayList<>(); - for (Channel channel : mChannelList) { - List subscribedLocalesList = - new ArrayList<>(Arrays.asList(channel.subscribedLocales)); - if (subscribedLocalesList.contains(mLocale)) { - channelList.add(channel); + if (mChannelList != null && mChannelList.size() > 0) { + for (Channel channel : mChannelList) { + List subscribedLocalesList = + new ArrayList<>(Arrays.asList(channel.subscribedLocales)); + if (subscribedLocalesList.contains(mLocale)) { + channelList.add(channel); + } } } mFollowingChannelList = channelList; @@ -260,9 +264,11 @@ public static List getFollowingChannelList() { public static List searchChannel(String search) { List channelList = new ArrayList<>(); - for (Channel channel : mChannelList) { - if (channel.channelName.toLowerCase(Locale.ROOT).contains(search)) { - channelList.add(channel); + if (mChannelList != null && mChannelList.size() > 0) { + for (Channel channel : mChannelList) { + if (channel.channelName.toLowerCase(Locale.ROOT).contains(search)) { + channelList.add(channel); + } } } return channelList; @@ -270,12 +276,14 @@ public static List searchChannel(String search) { public static List searchPublisher(String search) { List publisherList = new ArrayList<>(); - for (Publisher publisher : mGlobalPublisherList) { - if (publisher.publisherName.toLowerCase(Locale.ROOT).contains(search) - || publisher.categoryName.toLowerCase(Locale.ROOT).contains(search) - || publisher.feedSource.url.toLowerCase(Locale.ROOT).contains(search) - || publisher.siteUrl.url.toLowerCase(Locale.ROOT).contains(search)) { - publisherList.add(publisher); + if (mGlobalPublisherList != null && mGlobalPublisherList.size() > 0) { + for (Publisher publisher : mGlobalPublisherList) { + if (publisher.publisherName.toLowerCase(Locale.ROOT).contains(search) + || publisher.categoryName.toLowerCase(Locale.ROOT).contains(search) + || publisher.feedSource.url.toLowerCase(Locale.ROOT).contains(search) + || publisher.siteUrl.url.toLowerCase(Locale.ROOT).contains(search)) { + publisherList.add(publisher); + } } }