34
34
import com .d4rk .androidtutorials .java .databinding .ItemAndroidStudioLessonBinding ;
35
35
import com .google .android .gms .ads .AdListener ;
36
36
import com .google .android .gms .ads .LoadAdError ;
37
+ import com .google .android .material .button .MaterialButton ;
37
38
import com .google .android .material .card .MaterialCardView ;
38
39
import com .google .android .material .shape .CornerFamily ;
39
40
import com .google .android .material .shape .ShapeAppearanceModel ;
@@ -427,15 +428,15 @@ static class LessonHolder extends RecyclerView.ViewHolder {
427
428
final AppCompatImageView icon ;
428
429
final MaterialTextView title ;
429
430
final MaterialTextView summary ;
430
- final AppCompatImageView externalIcon ;
431
+ final MaterialButton externalButton ;
431
432
432
433
LessonHolder (@ NonNull ItemAndroidStudioLessonBinding binding ) {
433
434
super (binding .getRoot ());
434
435
card = binding .lessonCard ;
435
436
icon = binding .lessonIcon ;
436
437
title = binding .lessonTitle ;
437
438
summary = binding .lessonSummary ;
438
- externalIcon = binding .lessonExternalIcon ;
439
+ externalButton = binding .lessonExternalIcon ;
439
440
}
440
441
441
442
void bind (Lesson lesson , boolean first , boolean last ) {
@@ -452,7 +453,13 @@ void bind(Lesson lesson, boolean first, boolean last) {
452
453
} else {
453
454
summary .setVisibility (View .GONE );
454
455
}
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
+ }
456
463
itemView .setOnClickListener (v -> {
457
464
if (lesson .intent != null ) {
458
465
v .getContext ().startActivity (lesson .intent );
0 commit comments