Skip to content

Commit

Permalink
feat: change to use buttons to show different ADs
Browse files Browse the repository at this point in the history
  • Loading branch information
dbi1463 committed Nov 1, 2024
1 parent 17336b0 commit a2838c3
Show file tree
Hide file tree
Showing 5 changed files with 81 additions and 58 deletions.
33 changes: 22 additions & 11 deletions .idea/other.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 1 addition & 11 deletions sdkdemo/src/main/java/io/tenmax/sdkdemo/MainActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,5 @@ protected void onCreate(Bundle savedInstanceState) {

binding = ActivityMainBinding.inflate(getLayoutInflater());
setContentView(binding.getRoot());

BottomNavigationView navView = findViewById(R.id.nav_view);
// Passing each menu ID as a set of Ids because each
// menu should be considered as top level destinations.
AppBarConfiguration appBarConfiguration = new AppBarConfiguration.Builder(
R.id.navigation_home, R.id.navigation_dashboard, R.id.navigation_notifications)
.build();
NavController navController = Navigation.findNavController(this, R.id.nav_host_fragment_activity_main);
NavigationUI.setupActionBarWithNavController(this, navController, appBarConfiguration);
NavigationUI.setupWithNavController(binding.navView, navController);
}
}
}
28 changes: 25 additions & 3 deletions sdkdemo/src/main/java/io/tenmax/sdkdemo/ui/home/HomeFragment.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,17 @@

import androidx.annotation.NonNull;
import androidx.fragment.app.Fragment;
import androidx.fragment.app.FragmentManager;
import androidx.lifecycle.ViewModelProvider;

import io.tenmax.mobilesdk.TenMaxAd;
import io.tenmax.sdkdemo.R;
import io.tenmax.sdkdemo.SupportedSpaces;
import io.tenmax.sdkdemo.databinding.FragmentHomeBinding;
import io.tenmax.sdkdemo.ui.SimpleAdSessionListener;
import io.tenmax.sdkdemo.ui.SimpleInitiationCallback;
import io.tenmax.sdkdemo.ui.dashboard.DashboardFragment;
import io.tenmax.sdkdemo.ui.notifications.NotificationsFragment;

public class HomeFragment extends Fragment {

Expand All @@ -30,18 +34,27 @@ public View onCreateView(@NonNull LayoutInflater inflater, ViewGroup container,
binding = FragmentHomeBinding.inflate(inflater, container, false);
View root = binding.getRoot();

final TextView textView = binding.textHome;
homeViewModel.getText().observe(getViewLifecycleOwner(), textView::setText);
SimpleAdSessionListener listener = new SimpleAdSessionListener(this.getContext());
SimpleInitiationCallback callback = new SimpleInitiationCallback(this.getContext());
this.fullscreenAd = interstitialAd(SupportedSpaces.interstitialId, this.getActivity(), listener, callback);
this.binding.showInterstitialAd.setOnClickListener((view) -> {
this.fullscreenAd.show();
});

this.binding.showInlineAd.setOnClickListener((view) -> {
Fragment dashboard = new DashboardFragment();
this.pushFragment(dashboard);
});
this.binding.showBannerAd.setOnClickListener((view) -> {
Fragment notifications = new NotificationsFragment();
this.pushFragment(notifications);
});
return root;
}

@Override
public void onResume() {
super.onResume();
this.fullscreenAd.show();
}

@Override
Expand All @@ -50,4 +63,13 @@ public void onDestroyView() {
binding = null;
cleanAd(this.fullscreenAd);
}

private void pushFragment(Fragment fragment) {
FragmentManager manager = getParentFragmentManager();
manager.beginTransaction()
.add(R.id.fragmentContainer, fragment)
.hide(this)
.addToBackStack("home")
.commit();
}
}
27 changes: 5 additions & 22 deletions sdkdemo/src/main/res/layout/activity_main.xml
Original file line number Diff line number Diff line change
@@ -1,29 +1,12 @@
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/container"
android:id="@+id/fragmentContainer"
android:layout_width="match_parent"
android:layout_height="match_parent">

<fragment
android:id="@+id/nav_host_fragment_activity_main"
android:name="androidx.navigation.fragment.NavHostFragment"
android:id="@+id/homeFragment"
android:name="io.tenmax.sdkdemo.ui.home.HomeFragment"
android:layout_width="match_parent"
android:layout_height="0dp"
app:defaultNavHost="true"
app:layout_constraintBottom_toTopOf="@id/nav_view"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:navGraph="@navigation/mobile_navigation" />

<com.google.android.material.bottomnavigation.BottomNavigationView
android:id="@+id/nav_view"
android:layout_width="0dp"
android:layout_height="56dp"
android:background="?android:attr/windowBackground"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:menu="@menu/bottom_nav_menu" />
</androidx.constraintlayout.widget.ConstraintLayout>
android:layout_height="match_parent" />
</androidx.constraintlayout.widget.ConstraintLayout>
39 changes: 28 additions & 11 deletions sdkdemo/src/main/res/layout/fragment_home.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,34 @@
android:layout_height="match_parent"
tools:context=".ui.home.HomeFragment">

<TextView
android:id="@+id/text_home"
android:layout_width="match_parent"
<Button
android:id="@+id/showInterstitialAd"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="8dp"
android:layout_marginTop="8dp"
android:layout_marginEnd="8dp"
android:textAlignment="center"
android:textSize="20sp"
app:layout_constraintBottom_toBottomOf="parent"
android:layout_marginTop="50dp"
app:flow_horizontalAlign="center"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
</androidx.constraintlayout.widget.ConstraintLayout>
app:layout_constraintTop_toTopOf="parent"
android:text="Show Interstitial AD" />
<Button
android:id="@+id/showInlineAd"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Show Inline AD"
android:layout_marginTop="20dp"
app:flow_horizontalAlign="center"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/showInterstitialAd" />
<Button
android:id="@+id/showBannerAd"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Show Banner AD"
android:layout_marginTop="20dp"
app:flow_horizontalAlign="center"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/showInlineAd"/>
</androidx.constraintlayout.widget.ConstraintLayout>

0 comments on commit a2838c3

Please sign in to comment.