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
2 changes: 1 addition & 1 deletion Java/app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ dependencies {
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk8:2.2.0"

//Taboola
implementation 'com.taboola:android-sdk:4.0.22'
implementation 'com.taboola:android-sdk:4.0.24'
implementation 'com.squareup.retrofit2:converter-gson:2.9.0'

}
5 changes: 5 additions & 0 deletions Java/app/src/main/java/com/taboola/sdk4example/Const.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,9 @@ public class Const {
//Explore More
public static final String EXPLORE_MORE_PLACEMENT_NAME = "Feed - Explore More";
public static final String EXPLORE_MORE_CUSTOM_SEGMENT_SUBSCRIBER = "subscriber";

//Interstitial
public static final String INTERSTITIAL_PLACEMENT_NAME = "Trigger Interstitial";
public static final String INTERSTITIAL_MODE = "full-screen-interstitial-test";
public static final String INTERSTITIAL_CUSTOM_SEGMENT_DEFAULT = "Vignette";
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import com.taboola.sdk4example.sdk_classic.FeedWithMiddleArticleInsideListViewFragment;
import com.taboola.sdk4example.sdk_classic.FeedWithMiddleArticleInsideRecyclerViewFragment;
import com.taboola.sdk4example.sdk_classic.FeedWithMiddleArticleInsideScrollViewFragment;
import com.taboola.sdk4example.sdk_classic.InterstitialFragment;
import com.taboola.sdk4example.sdk_classic.OCClickHandlerFragment;
import com.taboola.sdk4example.sdk_classic.PullToRefreshFragment;
import com.taboola.sdk4example.sdk_classic.RecyclerViewPreloadFragment;
Expand Down Expand Up @@ -68,6 +69,7 @@ public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceStat
addButton(getString(R.string.std_feed_lazy_loading_rv), R.id.std_feed_lazy_loading_rv, viewGroup);
addButton(getString(R.string.std_mid_article_with_feed_dark_mode_rv), R.id.std_mid_article_with_feed_dark_mode_rv, viewGroup);
addButton(getString(R.string.std_explore_more), R.id.std_explore_more, viewGroup);
addButton(getString(R.string.std_interstitial), R.id.std_interstitial, viewGroup);
}


Expand Down Expand Up @@ -114,6 +116,9 @@ public void onClick(View v) {
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK);
startActivity(intent);
break;
case R.id.std_interstitial:
fragmentToOpen = new InterstitialFragment();
break;
}

if (fragmentToOpen != null) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,124 @@
package com.taboola.sdk4example.sdk_classic;

import android.os.Bundle;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.LinearLayout;
import android.widget.Toast;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.fragment.app.Fragment;

import com.taboola.android.TBLClassicPage;
import com.taboola.android.Taboola;
import com.taboola.android.listeners.TBLClassicInterstitialListener;
import com.taboola.sdk4example.Const;
import com.taboola.sdk4example.R;

/**
* Shows a Taboola Classic interstitial flow.
* <p>
* This fragment initializes a Classic page and demonstrates how to load and present
* a full-screen interstitial using the Taboola SDK.
* <p>
* Interstitial implementation overview:
* <ul>
* <li>Creates a {@link TBLClassicPage} with the page URL/type from {@link Const}.</li>
* <li>Initializes the interstitial placement with placement name, mode, and custom segment.</li>
* <li>Loads the ad immediately; the loading UI is visible until {@code onInterstitialLoaded}.</li>
* <li>Enables the "show" button only after a successful load to avoid empty presentation.</li>
* <li>Presents the interstitial on user action and reacts to lifecycle callbacks
* (presented/dismissed/clicked) for UI updates and logging.</li>
* <li>If loading fails, the loading UI is hidden and the error is surfaced to the user.</li>
* </ul>
*/
public class InterstitialFragment extends Fragment {
Comment thread
sanjacurcic-taboola marked this conversation as resolved.

private static final String TAG = InterstitialFragment.class.getSimpleName();
private TBLClassicPage tblClassicPage;

@Nullable
@Override
public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
return inflater.inflate(R.layout.fragment_interstitial, container, false);
}

/**
* Initializes the Taboola Classic page, sets up callbacks, and loads the interstitial.
*/
@Override
public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) {
super.onViewCreated(view, savedInstanceState);

LinearLayout interstitialLoadingContainer = view.findViewById(R.id.interstitial_loading_container);
Button showInterstitialButton = view.findViewById(R.id.show_interstitial_btn);

tblClassicPage = Taboola.getClassicPage(Const.PAGE_URL, Const.PAGE_TYPE);
TBLClassicInterstitialListener tblClassicInterstitialListener = new TBLClassicInterstitialListener() {
@Override
public void onInterstitialLoaded() {
super.onInterstitialLoaded();
interstitialLoadingContainer.setVisibility(View.GONE);
showInterstitialButton.setVisibility(View.VISIBLE);
Log.d(TAG, "The Interstitial is loaded successfully.");
}

@Override
public void onInterstitialWillPresent() {
super.onInterstitialWillPresent();
Log.d(TAG, "The Interstitial will be presented.");
}

@Override
public void onInterstitialPresented() {
super.onInterstitialPresented();
showInterstitialButton.setVisibility(View.GONE);
Log.d(TAG, "The Interstitial is presented.");
}

@Override
public void onInterstitialWillDismiss() {
super.onInterstitialWillDismiss();
Log.d(TAG, "The Interstitial will be dismissed.");
}

@Override
public void onInterstitialDismissed() {
super.onInterstitialDismissed();
Log.d(TAG, "The Interstitial is dismissed.");
}

@Override
public void onInterstitialClicked() {
super.onInterstitialClicked();
Log.d(TAG, "The Interstitial is clicked.");
}

@Override
public void interstitialDidFailToLoadAdWithError(String error) {
super.interstitialDidFailToLoadAdWithError(error);
interstitialLoadingContainer.setVisibility(View.GONE);
Toast.makeText(requireContext(), error, Toast.LENGTH_SHORT).show();
Log.d(TAG, error);
}
};

tblClassicPage.initInterstitial(
Const.INTERSTITIAL_PLACEMENT_NAME,
Const.INTERSTITIAL_MODE,
Const.INTERSTITIAL_CUSTOM_SEGMENT_DEFAULT,
tblClassicInterstitialListener
);

tblClassicPage.loadInterstitial();

showInterstitialButton.setOnClickListener(v -> {
tblClassicPage.showInterstitial();
});
}
}

51 changes: 51 additions & 0 deletions Java/app/src/main/res/layout/fragment_interstitial.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">

<LinearLayout
android:id="@+id/main_lyt"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">

<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="10dp"
android:layout_marginBottom="10dp"
android:text="@string/fake_text" />

<LinearLayout
android:id="@+id/interstitial_loading_container"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="10dp"
android:gravity="center_vertical"
android:orientation="horizontal">

<ProgressBar
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginEnd="10dp" />

<TextView
android:id="@+id/loading_text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/interstitial_loading" />

</LinearLayout>

<Button
android:id="@+id/show_interstitial_btn"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="10dp"
android:text="@string/interstitial_show"
android:visibility="gone" />

</LinearLayout>

</ScrollView>

1 change: 1 addition & 0 deletions Java/app/src/main/res/values/ids.xml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
<item name="std_feed_lazy_loading_rv" type="id" />
<item name="std_mid_article_with_feed_dark_mode_rv" type="id" />
<item name="std_explore_more" type="id" />
<item name="std_interstitial" type="id" />
<item name="native_widget" type="id" />
<item name="native_feed" type="id" />

Expand Down
3 changes: 3 additions & 0 deletions Java/app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -107,9 +107,12 @@ These will help you remember what the consumer really wants to engage with and w
<string name="std_feed_lazy_loading_rv">Feed Lazy Loading (RecyclerView)</string>
<string name="std_mid_article_with_feed_dark_mode_rv">Feed with Dark Mode (RecyclerView)</string>
<string name="std_explore_more">Explore More</string>
<string name="std_interstitial">Interstitial</string>
<string name="show_explore_more">Show Explore More</string>
<string name="set_back_button_trigger">Set Back Button Trigger</string>
<string name="explore_more_loading">Explore More Loading</string>
<string name="interstitial_loading">Loading Interstitial</string>
<string name="interstitial_show">Show Interstitial</string>
<string name="native_widget">Native Widget</string>
<string name="native_feed">Native Feed</string>
<!-- TODO: Remove or change this placeholder text -->
Expand Down
2 changes: 1 addition & 1 deletion Kotlin/app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ android {

dependencies {
// Import Taboola SDK
implementation 'com.taboola:android-sdk:4.0.22'
implementation 'com.taboola:android-sdk:4.0.24'

implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
implementation 'androidx.core:core-ktx:1.3.2'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,9 @@ class MainActivity : AppCompatActivity() {
R.id.nav_native_widget,
R.id.nav_native_feed,
R.id.nav_classic_explore_more,
R.id.nav_classic_explore_more_compose
R.id.nav_classic_explore_more_compose,
R.id.nav_classic_interstitial,
R.id.nav_classic_interstitial_compose
)

// Fragments that should become root screens (back button exits app)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,14 @@ class PlacementInfo {
val customSegment = "subscriber"
}

class InterstitialProperties {
val placementName = "Trigger Interstitial"
val pageType = "article"
val pageUrl = "https://blog.taboola.com"
val mode = "full-screen-interstitial-test"
Comment thread
sanjacurcic-taboola marked this conversation as resolved.
val customSegment = "Vignette"
}

// Static access
companion object {
fun widgetProperties() = WidgetProperties()
Expand All @@ -54,6 +62,7 @@ class PlacementInfo {
fun nativeFeedProperties() = NativeFeedProperties()
fun webFeedProperties() = WebFeedProperties()
fun exploreMoreProperties() = ExploreMoreProperties()
fun interstitialProperties() = InterstitialProperties()
}


Expand Down
Loading