3232import com .d4rk .androidtutorials .java .databinding .FragmentAndroidStudioBinding ;
3333import com .d4rk .androidtutorials .java .databinding .ItemAndroidStudioCategoryBinding ;
3434import com .d4rk .androidtutorials .java .databinding .ItemAndroidStudioLessonBinding ;
35- import com .d4rk .androidtutorials .java .utils .ConsentUtils ;
3635import com .google .android .gms .ads .AdListener ;
3736import com .google .android .gms .ads .LoadAdError ;
3837import com .google .android .material .card .MaterialCardView ;
@@ -57,7 +56,6 @@ public class AndroidStudioFragment extends Fragment {
5756 private static boolean mobileAdsInitialized = false ;
5857 private final List <Object > allItems = new ArrayList <>();
5958 private LessonsAdapter adapter ;
60- private boolean showAds ;
6159 private FragmentAndroidStudioBinding binding ;
6260
6361 @ Nullable
@@ -71,20 +69,15 @@ public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup c
7169 @ Override
7270 public void onViewCreated (@ NonNull View view , @ Nullable Bundle savedInstanceState ) {
7371 super .onViewCreated (view , savedInstanceState );
74- showAds = ConsentUtils .canShowPersonalizedAds (requireContext ());
75- if (showAds ) {
76- ensureMobileAdsInitialized ();
77- }
72+ ensureMobileAdsInitialized ();
7873 RecyclerView list = binding .lessonsList ;
7974 list .setLayoutManager (new LinearLayoutManager (requireContext ()));
8075 adapter = new LessonsAdapter ();
8176 list .setAdapter (adapter );
82- if (showAds ) {
83- list .addItemDecoration (new LessonAdSpacingDecoration (requireContext ()));
84- }
77+ list .addItemDecoration (new LessonAdSpacingDecoration (requireContext ()));
8578 allItems .clear ();
8679 allItems .addAll (loadItems ());
87- populateAdapter (allItems , showAds );
80+ populateAdapter (allItems );
8881
8982 MenuHost menuHost = requireActivity ();
9083 menuHost .addMenuProvider (new MenuProvider () {
@@ -208,7 +201,7 @@ private boolean isBrowserIntent(Intent intent) {
208201 && ("http" .equalsIgnoreCase (scheme ) || "https" .equalsIgnoreCase (scheme ));
209202 }
210203
211- private void populateAdapter (List <Object > source , boolean showAds ) {
204+ private void populateAdapter (List <Object > source ) {
212205 List <Object > items = new ArrayList <>();
213206 List <Integer > eligible = new ArrayList <>();
214207 int lessonCount = 0 ;
@@ -224,7 +217,7 @@ private void populateAdapter(List<Object> source, boolean showAds) {
224217 firstInCategory = false ;
225218 }
226219 }
227- int adCount = showAds ? lessonCount / 3 : 0 ;
220+ int adCount = lessonCount / 3 ;
228221 Collections .shuffle (eligible , new Random ());
229222 if (adCount > eligible .size ()) {
230223 adCount = eligible .size ();
@@ -248,7 +241,7 @@ private void populateAdapter(List<Object> source, boolean showAds) {
248241 private void filterLessons (String query ) {
249242 String lower = query == null ? "" : query .toLowerCase ();
250243 if (lower .isEmpty ()) {
251- populateAdapter (allItems , showAds );
244+ populateAdapter (allItems );
252245 return ;
253246 }
254247 List <Object > filtered = new ArrayList <>();
@@ -268,7 +261,7 @@ private void filterLessons(String query) {
268261 }
269262 }
270263 }
271- populateAdapter (filtered , showAds );
264+ populateAdapter (filtered );
272265 }
273266
274267 private static class AdItem {
0 commit comments