Skip to content

Commit 65d477f

Browse files
Refactor ads and UI components
This commit introduces several changes: - Removes `styles.xml` as `Widget.App.ButtonGroup` is replaced by `Widget.Material3.MaterialButtonGroup`. - Implements fast scrolling in `HelpActivity` using `FastScrollerBuilder`. - Updates ad layouts: - `ad_about.xml`: Changes `MaterialButton` to `Chip` and applies `Widget.Material3.Chip.Assist.Elevated` style. - `ad_bottom_app_bar.xml`: Adjusts layout, padding, icon size, text appearances, and removes the card view. - `ad_help.xml`: Modifies card view style, padding, text appearances, and button style. Removes media view and AdChoices view. - `ad_support.xml`: Changes button style to `Widget.Material3.Button.OutlinedButton` and card view style to `Widget.Material3.CardView.Outlined`. - Modifies `item_promoted_app.xml`: Applies `Widget.Material3.MaterialButtonToggleGroup` style to the button. - Updates `HelpActivity` layout (`activity_help.xml`): - Changes root to `FastScrollScrollView`. - Adjusts padding, margins, and text appearances. - Modifies card view style and shape appearance. - Refactors `MainActivity` layout (`activity_main.xml`): - Removes `ad_container` FrameLayout and moves `NativeAdBannerView` directly. - Removes `CircularProgressIndicator`. - Simplifies `MainActivity.java`: - Removes `updateBottomBannerVisibility` and related logic. - Removes logic for handling `CircularProgressIndicator`. - Directly loads banner ad in `onResume` and when navigation rail is not used. - Updates `item_android_studio_lesson.xml`: - Increases lesson icon size and padding. - Changes `lesson_external_icon` style to `Widget.Material3Expressive.Button.IconButton.Tonal`. - Replaces `Widget.App.ButtonGroup` with `Widget.Material3.MaterialButtonGroup` in `fragment_home.xml`.
1 parent 76d21b0 commit 65d477f

27 files changed

+172
-301
lines changed

app/src/main/java/com/d4rk/androidtutorials/java/ui/screens/help/HelpActivity.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
import com.google.android.play.core.review.ReviewInfo;
2727

2828
import dagger.hilt.android.AndroidEntryPoint;
29+
import me.zhanghai.android.fastscroll.FastScrollerBuilder;
2930

3031
@AndroidEntryPoint
3132
public class HelpActivity extends BaseActivity {
@@ -40,7 +41,9 @@ protected void onCreate(Bundle savedInstanceState) {
4041
EdgeToEdgeDelegate.apply(this, binding.getRoot());
4142
AdUtils.loadBanner(binding.faqNativeAd);
4243
helpViewModel = new ViewModelProvider(this).get(HelpViewModel.class);
43-
44+
new FastScrollerBuilder(binding.scrollContainer)
45+
.useMd2Style()
46+
.build();
4447
getSupportFragmentManager().beginTransaction()
4548
.replace(R.id.frame_layout_faq, new FaqFragment())
4649
.commit();

app/src/main/java/com/d4rk/androidtutorials/java/ui/screens/main/MainActivity.java

Lines changed: 13 additions & 69 deletions
Original file line numberDiff line numberDiff line change
@@ -47,9 +47,7 @@
4747
import com.d4rk.androidtutorials.java.utils.ConsentUtils;
4848
import com.d4rk.androidtutorials.java.utils.EdgeToEdgeDelegate;
4949
import com.d4rk.androidtutorials.java.utils.ReviewHelper;
50-
import com.d4rk.androidtutorials.java.ads.views.NativeAdBannerView;
5150
import com.google.android.material.navigation.NavigationBarView;
52-
import com.google.android.material.progressindicator.CircularProgressIndicator;
5351
import com.google.android.material.snackbar.Snackbar;
5452
import com.google.android.play.core.appupdate.AppUpdateInfo;
5553
import com.google.android.play.core.appupdate.AppUpdateManager;
@@ -77,7 +75,14 @@ public class MainActivity extends AppCompatActivity {
7775
@Override
7876
public void onResume(@NonNull LifecycleOwner owner) {
7977
ConsentUtils.applyStoredConsent(MainActivity.this);
80-
updateBottomBannerVisibility(!shouldUseNavigationRail());
78+
ActivityMainBinding binding = mBinding;
79+
if (binding != null) {
80+
View adView = binding.adView;
81+
if (adView != null) {
82+
adView.setVisibility(View.VISIBLE);
83+
AdUtils.loadBanner(adView);
84+
}
85+
}
8186
}
8287
};
8388
private MainViewModel mainViewModel;
@@ -88,7 +93,6 @@ public void onResume(@NonNull LifecycleOwner owner) {
8893
private AppUpdateManager appUpdateManager;
8994
private InstallStateUpdatedListener installStateUpdatedListener;
9095
private long backPressedTime;
91-
private boolean bottomBannerLoading;
9296

9397
@Override
9498
protected void onCreate(Bundle savedInstanceState) {
@@ -209,17 +213,20 @@ private void observeViewModel() {
209213
navRail.setVisibility(View.VISIBLE);
210214
}
211215
navBarView.setVisibility(View.GONE);
212-
updateBottomBannerVisibility(false);
213216
WindowCompat.enableEdgeToEdge(this.getWindow());
214217
} else {
215218
if (navRail != null) {
216219
navRail.setVisibility(View.GONE);
217220
}
218221
navBarView.setVisibility(View.VISIBLE);
219-
updateBottomBannerVisibility(true);
220222
EdgeToEdgeDelegate.applyBottomBar(this, binding.container, navBarView);
221223

222224
navBarView.setLabelVisibilityMode(uiState.bottomNavVisibility());
225+
View adView = binding.adView;
226+
if (adView != null) {
227+
adView.setVisibility(View.VISIBLE);
228+
AdUtils.loadBanner(adView);
229+
}
223230
}
224231

225232
NavHostFragment navHostFragment = (NavHostFragment)
@@ -307,69 +314,6 @@ private void observeViewModel() {
307314
recreate();
308315
}
309316
});
310-
311-
mainViewModel.getLoadingState().observe(this, isLoading -> {
312-
ActivityMainBinding binding = mBinding;
313-
if (binding != null) {
314-
CircularProgressIndicator progressIndicator = binding.progressBar;
315-
if (progressIndicator != null) {
316-
if (Boolean.TRUE.equals(isLoading)) {
317-
progressIndicator.show();
318-
} else {
319-
progressIndicator.hide();
320-
}
321-
}
322-
}
323-
});
324-
}
325-
326-
private void updateBottomBannerVisibility(boolean showBanner) {
327-
ActivityMainBinding binding = mBinding;
328-
if (binding == null) {
329-
return;
330-
}
331-
View adContainer = binding.adContainer;
332-
if (adContainer != null) {
333-
adContainer.setVisibility(showBanner ? View.VISIBLE : View.GONE);
334-
}
335-
NativeAdBannerView adView = binding.adView;
336-
View adPlaceholder = binding.adPlaceholder;
337-
if (adView == null) {
338-
if (adPlaceholder != null) {
339-
adPlaceholder.setVisibility(View.GONE);
340-
}
341-
return;
342-
}
343-
if (!showBanner) {
344-
if (adPlaceholder != null) {
345-
adPlaceholder.setVisibility(View.GONE);
346-
}
347-
adView.setVisibility(View.GONE);
348-
adView.removeAllViews();
349-
bottomBannerLoading = false;
350-
return;
351-
}
352-
353-
if (adPlaceholder != null) {
354-
adPlaceholder.setVisibility(View.VISIBLE);
355-
}
356-
if (adView.getVisibility() != View.VISIBLE || adView.getChildCount() > 0) {
357-
bottomBannerLoading = false;
358-
}
359-
360-
adView.setVisibility(View.VISIBLE);
361-
if (adView.getChildCount() > 0) {
362-
if (adPlaceholder != null) {
363-
adPlaceholder.setVisibility(View.GONE);
364-
}
365-
bottomBannerLoading = false;
366-
return;
367-
}
368-
369-
if (!bottomBannerLoading) {
370-
bottomBannerLoading = true;
371-
AdUtils.loadBanner(adView);
372-
}
373317
}
374318

375319

Lines changed: 44 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -1,59 +1,55 @@
11
<?xml version="1.0" encoding="utf-8"?>
2-
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
2+
<me.zhanghai.android.fastscroll.FastScrollScrollView
3+
xmlns:android="http://schemas.android.com/apk/res/android"
34
xmlns:app="http://schemas.android.com/apk/res-auto"
4-
android:id="@+id/container"
5+
android:id="@+id/scroll_container"
56
android:layout_width="match_parent"
6-
android:layout_height="match_parent"
7-
android:paddingHorizontal="24dp"
8-
android:paddingVertical="24dp">
7+
android:layout_height="match_parent">
98

10-
<com.google.android.material.textview.MaterialTextView
11-
android:id="@+id/text_view_faq"
12-
android:layout_width="wrap_content"
9+
<LinearLayout
10+
android:id="@+id/container"
11+
android:layout_width="match_parent"
1312
android:layout_height="wrap_content"
14-
android:layout_marginBottom="24dp"
15-
android:text="@string/faq"
16-
app:layout_constraintStart_toStartOf="parent"
17-
app:layout_constraintTop_toTopOf="parent" />
13+
android:orientation="vertical">
1814

19-
<com.google.android.material.card.MaterialCardView
20-
android:id="@+id/card_view_faq"
21-
style="@style/Widget.Material3.CardView.Filled"
22-
android:layout_width="match_parent"
23-
android:layout_height="0dp"
24-
android:layout_marginBottom="24dp"
25-
app:layout_constraintBottom_toTopOf="@id/frame_layout_feedback"
26-
app:layout_constraintTop_toBottomOf="@id/text_view_faq">
15+
<com.google.android.material.textview.MaterialTextView
16+
android:id="@+id/text_view_faq"
17+
android:layout_width="wrap_content"
18+
android:layout_height="wrap_content"
19+
android:layout_marginBottom="16dp"
20+
android:text="@string/faq"
21+
android:textAppearance="@style/TextAppearance.Material3.TitleMedium" />
2722

28-
<androidx.constraintlayout.widget.ConstraintLayout
23+
<com.google.android.material.card.MaterialCardView
24+
android:id="@+id/card_view_faq"
25+
style="@style/Widget.Material3.CardView.Filled"
2926
android:layout_width="match_parent"
30-
android:layout_height="match_parent"
31-
android:padding="16dp">
32-
33-
<FrameLayout
34-
android:id="@+id/frame_layout_faq"
35-
android:layout_width="0dp"
36-
android:layout_height="0dp"
37-
app:layout_constraintBottom_toTopOf="@id/faq_native_ad"
38-
app:layout_constraintEnd_toEndOf="parent"
39-
app:layout_constraintStart_toStartOf="parent"
40-
app:layout_constraintTop_toTopOf="parent" />
27+
android:layout_height="wrap_content"
28+
app:shapeAppearance="@style/ShapeAppearanceOverlay.CardViewTopRoundedFilled">
4129

42-
<com.d4rk.androidtutorials.java.ads.views.NativeAdBannerView
43-
android:id="@+id/faq_native_ad"
44-
android:layout_width="0dp"
30+
<LinearLayout
31+
android:layout_width="match_parent"
4532
android:layout_height="wrap_content"
46-
android:layout_marginTop="16dp"
47-
app:layout_constraintBottom_toBottomOf="parent"
48-
app:layout_constraintEnd_toEndOf="parent"
49-
app:layout_constraintStart_toStartOf="parent"
50-
app:nativeAdLayout="@layout/ad_help" />
51-
</androidx.constraintlayout.widget.ConstraintLayout>
52-
</com.google.android.material.card.MaterialCardView>
33+
android:orientation="vertical"
34+
android:padding="12dp">
35+
<FrameLayout
36+
android:id="@+id/frame_layout_faq"
37+
android:layout_width="match_parent"
38+
android:layout_height="wrap_content" />
39+
</LinearLayout>
40+
</com.google.android.material.card.MaterialCardView>
5341

54-
<FrameLayout
55-
android:id="@+id/frame_layout_feedback"
56-
android:layout_width="match_parent"
57-
android:layout_height="wrap_content"
58-
app:layout_constraintBottom_toBottomOf="parent" />
59-
</androidx.constraintlayout.widget.ConstraintLayout>
42+
<com.d4rk.androidtutorials.java.ads.views.NativeAdBannerView
43+
android:id="@+id/faq_native_ad"
44+
android:layout_width="match_parent"
45+
android:layout_height="wrap_content"
46+
android:layout_marginTop="2dp"
47+
app:nativeAdLayout="@layout/ad_help" />
48+
49+
<FrameLayout
50+
android:id="@+id/frame_layout_feedback"
51+
android:layout_width="match_parent"
52+
android:layout_height="wrap_content" />
53+
54+
</LinearLayout>
55+
</me.zhanghai.android.fastscroll.FastScrollScrollView>

app/src/main/res/layout/activity_main.xml

Lines changed: 9 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
android:id="@+id/nav_rail"
2525
android:layout_width="wrap_content"
2626
android:layout_height="0dp"
27-
app:layout_constraintBottom_toTopOf="@+id/ad_container"
27+
app:layout_constraintBottom_toTopOf="@+id/ad_view"
2828
app:layout_constraintStart_toStartOf="parent"
2929
app:layout_constraintTop_toBottomOf="@id/app_bar_layout"
3030
app:menu="@menu/bottom_nav_menu" />
@@ -35,56 +35,24 @@
3535
android:layout_width="0dp"
3636
android:layout_height="0dp"
3737
app:defaultNavHost="true"
38-
app:layout_constraintBottom_toTopOf="@+id/ad_container"
38+
app:layout_constraintBottom_toTopOf="@+id/ad_view"
3939
app:layout_constraintEnd_toEndOf="parent"
4040
app:layout_constraintStart_toEndOf="@id/nav_rail"
4141
app:layout_constraintTop_toBottomOf="@id/app_bar_layout"
4242
app:navGraph="@navigation/mobile_navigation" />
4343

44+
<com.d4rk.androidtutorials.java.ads.views.NativeAdBannerView
45+
android:id="@+id/ad_view"
46+
android:layout_width="match_parent"
47+
android:layout_height="wrap_content"
48+
app:layout_constraintBottom_toTopOf="@+id/nav_view"
49+
app:nativeAdLayout="@layout/ad_bottom_app_bar" />
50+
4451
<com.google.android.material.bottomnavigation.BottomNavigationView
4552
android:id="@+id/nav_view"
4653
android:layout_width="match_parent"
4754
android:layout_height="wrap_content"
4855
app:labelVisibilityMode="labeled"
4956
app:layout_constraintBottom_toBottomOf="parent"
5057
app:menu="@menu/bottom_nav_menu" />
51-
52-
<FrameLayout
53-
android:id="@+id/ad_container"
54-
android:layout_width="match_parent"
55-
android:layout_height="wrap_content"
56-
android:clipChildren="false"
57-
android:clipToPadding="false"
58-
android:elevation="8dp"
59-
android:visibility="gone"
60-
app:layout_constraintBottom_toTopOf="@+id/nav_view"
61-
app:layout_constraintEnd_toEndOf="parent"
62-
app:layout_constraintStart_toStartOf="parent">
63-
64-
<View
65-
android:id="@+id/ad_placeholder"
66-
android:layout_width="match_parent"
67-
android:layout_height="match_parent"
68-
android:background="?attr/colorSurfaceContainer"
69-
android:visibility="gone" />
70-
71-
<com.d4rk.androidtutorials.java.ads.views.NativeAdBannerView
72-
android:id="@+id/ad_view"
73-
android:layout_width="match_parent"
74-
android:layout_height="wrap_content"
75-
android:visibility="gone"
76-
app:nativeAdLayout="@layout/ad_bottom_app_bar" />
77-
</FrameLayout>
78-
79-
<com.google.android.material.progressindicator.CircularProgressIndicator
80-
android:id="@+id/progress_bar"
81-
style="@style/Widget.Material3.CircularProgressIndicator"
82-
android:layout_width="wrap_content"
83-
android:layout_height="wrap_content"
84-
android:indeterminate="true"
85-
android:visibility="gone"
86-
app:layout_constraintBottom_toBottomOf="parent"
87-
app:layout_constraintEnd_toEndOf="parent"
88-
app:layout_constraintStart_toStartOf="parent"
89-
app:layout_constraintTop_toTopOf="parent" />
9058
</androidx.constraintlayout.widget.ConstraintLayout>

app/src/main/res/layout/ad_about.xml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
style="@style/Widget.Material3.CardView.Filled"
1010
android:layout_width="match_parent"
1111
android:layout_height="wrap_content"
12-
app:shapeAppearanceOverlay="@style/ShapeAppearanceOverlay.CardViewBottomRounded">
12+
app:shapeAppearanceOverlay="@style/ShapeAppearanceOverlay.CardViewBottomRoundedFilled">
1313

1414
<androidx.appcompat.widget.LinearLayoutCompat
1515
android:layout_width="match_parent"
@@ -88,7 +88,8 @@
8888
app:layout_constraintStart_toStartOf="@id/ad_headline"
8989
app:layout_constraintTop_toBottomOf="@id/ad_body" />
9090

91-
<com.google.android.material.button.MaterialButton
91+
<com.google.android.material.chip.Chip
92+
style="@style/Widget.Material3.Chip.Assist.Elevated"
9293
android:id="@+id/ad_call_to_action"
9394
android:layout_width="wrap_content"
9495
android:layout_height="40dp"

0 commit comments

Comments
 (0)