3434import com .d4rk .androidtutorials .java .databinding .ItemAndroidStudioLessonBinding ;
3535import com .google .android .gms .ads .AdListener ;
3636import com .google .android .gms .ads .LoadAdError ;
37+ import com .google .android .material .button .MaterialButton ;
3738import com .google .android .material .card .MaterialCardView ;
3839import com .google .android .material .shape .CornerFamily ;
3940import com .google .android .material .shape .ShapeAppearanceModel ;
@@ -427,15 +428,15 @@ static class LessonHolder extends RecyclerView.ViewHolder {
427428 final AppCompatImageView icon ;
428429 final MaterialTextView title ;
429430 final MaterialTextView summary ;
430- final AppCompatImageView externalIcon ;
431+ final MaterialButton externalButton ;
431432
432433 LessonHolder (@ NonNull ItemAndroidStudioLessonBinding binding ) {
433434 super (binding .getRoot ());
434435 card = binding .lessonCard ;
435436 icon = binding .lessonIcon ;
436437 title = binding .lessonTitle ;
437438 summary = binding .lessonSummary ;
438- externalIcon = binding .lessonExternalIcon ;
439+ externalButton = binding .lessonExternalIcon ;
439440 }
440441
441442 void bind (Lesson lesson , boolean first , boolean last ) {
@@ -452,7 +453,13 @@ void bind(Lesson lesson, boolean first, boolean last) {
452453 } else {
453454 summary .setVisibility (View .GONE );
454455 }
455- externalIcon .setVisibility (lesson .opensInBrowser ? View .VISIBLE : View .GONE );
456+ boolean showExternalButton = lesson .opensInBrowser && lesson .intent != null ;
457+ externalButton .setVisibility (showExternalButton ? View .VISIBLE : View .GONE );
458+ if (showExternalButton ) {
459+ externalButton .setOnClickListener (v -> v .getContext ().startActivity (lesson .intent ));
460+ } else {
461+ externalButton .setOnClickListener (null );
462+ }
456463 itemView .setOnClickListener (v -> {
457464 if (lesson .intent != null ) {
458465 v .getContext ().startActivity (lesson .intent );
0 commit comments