Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added ecomm widget example #10

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
.idea/deploymentTargetDropDown.xml
Java/.gradle/
Java/.idea/
Java/build/
Java/local.properties
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.taboola.sdk3example.sdk_classic.EcommWidgetBelowArticleFragment;
import com.taboola.sdk3example.sdk_classic.FeedInsideRecyclerViewCustomFragment;
import com.taboola.sdk3example.sdk_classic.FeedLazyLoadInsideRecyclerViewFragment;
import com.taboola.sdk3example.sdk_classic.FeedWithMiddleArticleDarkModeInsideRecyclerViewFragment;
Expand Down Expand Up @@ -64,6 +66,7 @@ public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceStat
addButton(getString(R.string.std_feed_pull_to_refresh), R.id.std_feed_pull_to_refresh, viewGroup);
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_below_article_ecomm_lv), R.id.std_below_article_ecomm_lv, viewGroup);
}


Expand Down Expand Up @@ -109,6 +112,9 @@ public void onClick(View v) {
case R.id.std_mid_article_with_feed_dark_mode_rv:
fragmentToOpen = new FeedWithMiddleArticleDarkModeInsideRecyclerViewFragment();
break;
case R.id.std_below_article_ecomm_lv:
fragmentToOpen = new EcommWidgetBelowArticleFragment();
break;
}

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

import android.content.Context;
import android.os.Bundle;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.ListView;
import android.widget.TextView;

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

import com.taboola.sdk3example.R;
import com.taboola.android.TBLClassicPage;
import com.taboola.android.TBLClassicUnit;
import com.taboola.android.Taboola;
import com.taboola.android.annotations.TBL_PLACEMENT_TYPE;
import com.taboola.android.listeners.TBLClassicListener;
import com.taboola.android.utils.TBLSdkDetailsHelper;


import java.util.List;

public class EcommWidgetBelowArticleFragment extends Fragment {

private static final String TAG = "EcommWidgetBelowArticle";

@Override
public void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
}

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

@Override
public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) {
super.onViewCreated(view, savedInstanceState);

TBLClassicPage tblClassicPage =
Taboola.getClassicPage("https://blog.taboola.com", "article");

TBLClassicUnit tblClassicUnitMiddle = createTaboolaWidget(tblClassicPage);

ListView listView = view.findViewById(R.id.feed_lv);
listView.setAdapter(new ListViewAdapter(tblClassicUnitMiddle));
}



public TBLClassicUnit createTaboolaWidget(TBLClassicPage tblClassicPage) {
String uiMode = "ecomm-carousel-1";
String placement = "Ecommerce widget";
TBLClassicUnit tblClassicUnit = tblClassicPage.build(getContext(), placement, uiMode,
TBL_PLACEMENT_TYPE.PAGE_BOTTOM, new TBLClassicListener() {
@Override
public boolean onItemClick(String placementName, String itemId, String clickUrl, boolean isOrganic, String customData) {
return super.onItemClick(placementName, itemId, clickUrl, isOrganic, customData);
}
@Override
public void onAdReceiveSuccess() {
super.onAdReceiveSuccess();
Log.d(TAG,"onAdReceiveSuccess");
}

@Override
public void onAdReceiveFail(String error) {
super.onAdReceiveFail(error);
Log.d(TAG,"onAdReceiveFail: " + error);
}
});
tblClassicUnit.fetchContent();
return tblClassicUnit;

}


@Override
public void onDestroy() {
super.onDestroy();
Log.d(TAG,"onDestroy");
}


static class ListViewAdapter extends BaseAdapter {

private final List<ListItemsGenerator.FeedListItem> mData;
private TBLClassicUnit tblClassicUnitMiddle;


ListViewAdapter(TBLClassicUnit tblClassicUnitmiddleWidget) {
mData = ListItemsGenerator.getGeneratedData(true);
tblClassicUnitMiddle = tblClassicUnitmiddleWidget;
}


@Override
public @ListItemsGenerator.FeedListItem.ItemType
int getItemViewType(int position) {
ListItemsGenerator.FeedListItem item = getItem(position);
return item.type;
}


@Override
public int getCount() {
return mData.size();
}

@Override
public ListItemsGenerator.FeedListItem getItem(int position) {
return mData.get(position);
}

@Override
public long getItemId(int position) {
return 0;
}


ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
switch (viewType) {
case ListItemsGenerator.FeedListItem.ItemType.TABOOLA_ITEM:
return new ViewHolderTaboola(tblClassicUnitMiddle, viewType);
default:
case ListItemsGenerator.FeedListItem.ItemType.RANDOM_ITEM:
View appCompatImageView = LayoutInflater.from(parent.getContext()).inflate(R.layout.random_item, parent, false);
return new RandomImageViewHolder(appCompatImageView, viewType);
}
}

@Override
public View getView(int position, View convertView, ViewGroup parent) {

@ListItemsGenerator.FeedListItem.ItemType int viewType = getItemViewType(position);
ViewHolder viewHolder;
if (convertView == null || convertView.getTag() == null || ((ViewHolder) convertView.getTag()).mViewType != viewType) {
viewHolder = onCreateViewHolder(parent, viewType);
convertView = viewHolder.mView;
} else {
viewHolder = (ViewHolder) convertView.getTag();
}


if (viewType == ListItemsGenerator.FeedListItem.ItemType.RANDOM_ITEM) {
RandomImageViewHolder vh = (RandomImageViewHolder) viewHolder;
ListItemsGenerator.FeedListItem item = getItem(position);
ListItemsGenerator.RandomItem randomItem = (ListItemsGenerator.RandomItem) item;
final ImageView imageView = vh.imageView;
imageView.setBackgroundColor(randomItem.color);
vh.textView.setText(randomItem.randomText);
}


return convertView;
}


static class RandomImageViewHolder extends ViewHolder {
private final ImageView imageView;
private final TextView textView;

RandomImageViewHolder(View view, int viewType) {
super(view, viewType);
imageView = view.findViewById(R.id.feed_item_iv);
textView = view.findViewById(R.id.feed_item_tv);
}
}

static abstract class ViewHolder {

private final @ListItemsGenerator.FeedListItem.ItemType
int mViewType;
View mView;

ViewHolder(View view, int viewType) {
mView = view;
this.mViewType = viewType;
view.setTag(this);
}
}

static class ViewHolderTaboola extends ViewHolder {
ViewHolderTaboola(View view, int viewType) {
super(view, viewType);
}
}

}
}


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_pull_to_refresh" type="id" />
<item name="std_feed_lazy_loading_rv" type="id" />
<item name="std_mid_article_with_feed_dark_mode_rv" type="id" />
<item name="std_below_article_ecomm_lv" type="id" />
<item name="native_widget" type="id" />
<item name="native_feed" type="id" />

Expand Down
1 change: 1 addition & 0 deletions Java/app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@ These will help you remember what the consumer really wants to engage with and w
<string name="std_feed_pull_to_refresh">Pull to refresh</string>
<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_below_article_ecomm_lv">Ecomm widget below article (ListView)</string>
<string name="native_widget">Native Widget</string>
<string name="native_feed">Native Feed</string>
<!-- TODO: Remove or change this placeholder text -->
Expand Down
8 changes: 0 additions & 8 deletions Java/local.properties

This file was deleted.