The VoucherSDK provides the VoucherListFragment to list Vouchers that the logged in user has sent or received.

Basic Setup

Provided a user has logged in, the simplest integration would be to create an activity and embed the fragment within it. The following is an example that displays a list of all the created Vouchers for the logged in user.

class CreatedVouchersActivity extends LoadingBaseActivity {

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_vouchers);
        showCreatedVoucher();
    }
    
    public void showCreatedVoucher() {
        VoucherListConfig config = VoucherListConfig.Builder.init()
                .feedType(VoucherListContract.FeedType.CREATED)
                .create();
        VoucherListFragment createdFragment = VoucherListFragment.newInstance(config);
        
        getSupportFragmentManager().beginTransaction()
                .replace(R.id.content_frame, createdFragment)
                .commit();
    }
}
class CreatedVouchersActivity : LoadingBaseActivity() {

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_vouchers)
        showCreatedVouchers()
    }

    fun showCreatedVouchers() {
        val config = VoucherListConfig.Builder.init()
            .feedType(VoucherListContract.FeedType.CREATED)
            .create()
        val createdFragment = VoucherListFragment.newInstance(config)

        supportFragmentManager.beginTransaction()
                .replace(R.id.contentFrame, createdFragment)
                .commit()
    }
}

Alternatively if you wish to see Vouchers that have been received by the logged in user, specify the FeedType in the config above to be RECEIVED as opposed to CREATED. The new config can be seen below.

VoucherListConfig config = VoucherListConfig.Builder.init()
                .feedType(VoucherListContract.FeedType.RECEIVED)
                .create();
val config = VoucherListConfig.Builder.init()
            .feedType(VoucherListContract.FeedType.RECEIVED)
            .create()

The remaining setup and configuration remains the same as viewing the created Vouchers, but will now be replaced with Vouchers that are sent to the user.

Customizations

There are many customizations that you can utilize to tweak the appearance/functionality of the VoucherListFragment in addition to the usual theming. These can be set by passing in a VoucherListConfig to the fragment during creation.

Feed Type

The FeedType determines what type of content is displayed within the fragment. CREATED displays the list of created Vouchers for the logged in user. RECEIVED displays the list of received Vouchers for the logged in user.

    builder.feedType(
        VoucherListContract.FeedType.RECEIVED | VoucherListContract.FeedType.CREATED);
    builder.feedType(
        VoucherListContract.FeedType.RECEIVED | VoucherListContract.FeedType.CREATED)

Listener

The listener allows you to control what action is taken when a user clicks on a Voucher. We provide the OpenClaimListener() which opens the Reveal/Claim screens for the selected Voucher. Additionally you can decide what happens for yourself by implementing the ItemClickedListener<FeedVoucher>.

    builder.listener(
        new OpenClaimListener() | custom implementation of ItemClickedListener<FeedVoucher>);
    builder.listener(
        OpenClaimListener() | custom implementation of ItemClickedListener<FeedVoucher>)

View Factory

The view factory controls how the Vouchers are displayed. We provide the SimpleVoucherItemViewFactory or you can implement your own.

    builder.viewFactory(
        new SimpleVoucherItemViewFactory() | custom implementation of VoucherFeedItemViewFactory)
    builder.viewFactory(
        SimpleVoucherItemViewFactory() | custom implementation of VoucherFeedItemViewFactory)