Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit e07dce9

Browse files
Merge pull request #247 from MihaiCristianCondrea/codex/add-open-new-icon-for-lessons
Add external icon for browser-based lessons
2 parents ee42f09 + 91c483b commit e07dce9

File tree

3 files changed

+42
-1
lines changed

3 files changed

+42
-1
lines changed

‎app/src/main/java/com/d4rk/androidtutorials/java/ui/screens/android/AndroidStudioFragment.java‎

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -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);
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
<vector xmlns:android="http://schemas.android.com/apk/res/android"
2+
android:width="24dp"
3+
android:height="24dp"
4+
android:viewportWidth="24"
5+
android:viewportHeight="24">
6+
<path
7+
android:fillColor="?attr/colorOnSurfaceVariant"
8+
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" />
9+
</vector>

‎app/src/main/res/layout/item_android_studio_lesson.xml‎

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,5 +44,15 @@
4444
android:layout_height="wrap_content"
4545
android:textAppearance="@style/TextAppearance.Material3.BodySmall" />
4646
</androidx.appcompat.widget.LinearLayoutCompat>
47+
48+
<androidx.appcompat.widget.AppCompatImageView
49+
android:id="@+id/lesson_external_icon"
50+
android:layout_width="24dp"
51+
android:layout_height="24dp"
52+
android:layout_marginStart="12dp"
53+
android:contentDescription="@null"
54+
android:importantForAccessibility="no"
55+
app:srcCompat="@drawable/ic_open_in_new"
56+
android:visibility="gone" />
4757
</androidx.appcompat.widget.LinearLayoutCompat>
4858
</com.google.android.material.card.MaterialCardView>

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /