Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,7 @@ private List<Object> loadItems() {
String data = parser.getAttributeValue("http://schemas.android.com/apk/res/android", "data");
if (data != null) intent.setData(Uri.parse(data));
currentLesson.intent = intent;
currentLesson.opensInBrowser = isBrowserIntent(intent);
}
} else if (event == XmlPullParser.END_TAG) {
String name = parser.getName();
Expand All @@ -191,6 +192,22 @@ private List<Object> loadItems() {
return items;
}

private boolean isBrowserIntent(Intent intent) {
if (intent.getComponent() != null) {
return false;
}
Uri data = intent.getData();
if (data == null) {
return false;
}
String scheme = data.getScheme();
if (scheme == null) {
return false;
}
return Intent.ACTION_VIEW.equals(intent.getAction())
&& ("http".equalsIgnoreCase(scheme) || "https".equalsIgnoreCase(scheme));
}

private void populateAdapter(List<Object> source, boolean showAds) {
List<Object> items = new ArrayList<>();
List<Integer> eligible = new ArrayList<>();
Expand Down Expand Up @@ -262,6 +279,7 @@ private static class Lesson {
String summary;
int iconRes;
Intent intent;
boolean opensInBrowser;
}

private static class Category {
Expand Down Expand Up @@ -329,7 +347,8 @@ public boolean areContentsTheSame(int oldItemPosition, int newItemPosition) {
if (oldItem instanceof Lesson oldLesson && newItem instanceof Lesson newLesson) {
return Objects.equals(oldLesson.title, newLesson.title)
&& Objects.equals(oldLesson.summary, newLesson.summary)
&& oldLesson.iconRes == newLesson.iconRes;
&& oldLesson.iconRes == newLesson.iconRes
&& oldLesson.opensInBrowser == newLesson.opensInBrowser;
}
if (oldItem instanceof Category oldCat && newItem instanceof Category newCat) {
return Objects.equals(oldCat.title, newCat.title)
Expand Down Expand Up @@ -415,13 +434,15 @@ static class LessonHolder extends RecyclerView.ViewHolder {
final AppCompatImageView icon;
final MaterialTextView title;
final MaterialTextView summary;
final AppCompatImageView externalIcon;

LessonHolder(@NonNull ItemAndroidStudioLessonBinding binding) {
super(binding.getRoot());
card = binding.lessonCard;
icon = binding.lessonIcon;
title = binding.lessonTitle;
summary = binding.lessonSummary;
externalIcon = binding.lessonExternalIcon;
}

void bind(Lesson lesson, boolean first, boolean last) {
Expand All @@ -438,6 +459,7 @@ void bind(Lesson lesson, boolean first, boolean last) {
} else {
summary.setVisibility(View.GONE);
}
externalIcon.setVisibility(lesson.opensInBrowser ? View.VISIBLE : View.GONE);
itemView.setOnClickListener(v -> {
if (lesson.intent != null) {
v.getContext().startActivity(lesson.intent);
Expand Down
9 changes: 9 additions & 0 deletions app/src/main/res/drawable-anydpi/ic_open_in_new.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:viewportWidth="24"
android:viewportHeight="24">
<path
android:fillColor="?attr/colorOnSurfaceVariant"
android:pathData="M14,3v2h3.59l-4.83,4.83 1.41,1.41L19,6.41V10h2V3h-7zM5,5h6V3H5c-1.1,0 -2,0.9 -2,2v14c0,1.1 0.9,2 2,2h14c1.1,0 2,-0.9 2,-2v-6h-2v6H5V5z" />
</vector>
10 changes: 10 additions & 0 deletions app/src/main/res/layout/item_android_studio_lesson.xml
Original file line number Diff line number Diff line change
Expand Up @@ -44,5 +44,15 @@
android:layout_height="wrap_content"
android:textAppearance="@style/TextAppearance.Material3.BodySmall" />
</androidx.appcompat.widget.LinearLayoutCompat>

<androidx.appcompat.widget.AppCompatImageView
android:id="@+id/lesson_external_icon"
android:layout_width="24dp"
android:layout_height="24dp"
android:layout_marginStart="12dp"
android:contentDescription="@null"
android:importantForAccessibility="no"
app:srcCompat="@drawable/ic_open_in_new"
android:visibility="gone" />
</androidx.appcompat.widget.LinearLayoutCompat>
</com.google.android.material.card.MaterialCardView>