@@ -176,6 +176,7 @@ private List<Object> loadItems() {
176176 String data = parser .getAttributeValue ("http://schemas.android.com/apk/res/android" , "data" );
177177 if (data != null ) intent .setData (Uri .parse (data ));
178178 currentLesson .intent = intent ;
179+ currentLesson .opensInBrowser = isBrowserIntent (intent );
179180 }
180181 } else if (event == XmlPullParser .END_TAG ) {
181182 String name = parser .getName ();
@@ -191,6 +192,22 @@ private List<Object> loadItems() {
191192 return items ;
192193 }
193194
195+ private boolean isBrowserIntent (Intent intent ) {
196+ if (intent .getComponent () != null ) {
197+ return false ;
198+ }
199+ Uri data = intent .getData ();
200+ if (data == null ) {
201+ return false ;
202+ }
203+ String scheme = data .getScheme ();
204+ if (scheme == null ) {
205+ return false ;
206+ }
207+ return Intent .ACTION_VIEW .equals (intent .getAction ())
208+ && ("http" .equalsIgnoreCase (scheme ) || "https" .equalsIgnoreCase (scheme ));
209+ }
210+ 194211 private void populateAdapter (List <Object > source , boolean showAds ) {
195212 List <Object > items = new ArrayList <>();
196213 List <Integer > eligible = new ArrayList <>();
@@ -262,6 +279,7 @@ private static class Lesson {
262279 String summary ;
263280 int iconRes ;
264281 Intent intent ;
282+ boolean opensInBrowser ;
265283 }
266284
267285 private static class Category {
@@ -329,7 +347,8 @@ public boolean areContentsTheSame(int oldItemPosition, int newItemPosition) {
329347 if (oldItem instanceof Lesson oldLesson && newItem instanceof Lesson newLesson ) {
330348 return Objects .equals (oldLesson .title , newLesson .title )
331349 && Objects .equals (oldLesson .summary , newLesson .summary )
332- && oldLesson .iconRes == newLesson .iconRes ;
350+ && oldLesson .iconRes == newLesson .iconRes
351+ && oldLesson .opensInBrowser == newLesson .opensInBrowser ;
333352 }
334353 if (oldItem instanceof Category oldCat && newItem instanceof Category newCat ) {
335354 return Objects .equals (oldCat .title , newCat .title )
@@ -415,13 +434,15 @@ static class LessonHolder extends RecyclerView.ViewHolder {
415434 final AppCompatImageView icon ;
416435 final MaterialTextView title ;
417436 final MaterialTextView summary ;
437+ final AppCompatImageView externalIcon ;
418438
419439 LessonHolder (@ NonNull ItemAndroidStudioLessonBinding binding ) {
420440 super (binding .getRoot ());
421441 card = binding .lessonCard ;
422442 icon = binding .lessonIcon ;
423443 title = binding .lessonTitle ;
424444 summary = binding .lessonSummary ;
445+ externalIcon = binding .lessonExternalIcon ;
425446 }
426447
427448 void bind (Lesson lesson , boolean first , boolean last ) {
@@ -438,6 +459,7 @@ void bind(Lesson lesson, boolean first, boolean last) {
438459 } else {
439460 summary .setVisibility (View .GONE );
440461 }
462+ externalIcon .setVisibility (lesson .opensInBrowser ? View .VISIBLE : View .GONE );
441463 itemView .setOnClickListener (v -> {
442464 if (lesson .intent != null ) {
443465 v .getContext ().startActivity (lesson .intent );
0 commit comments