RedeemPointView

TerraCore v0

Introduction#

Use this built-in view to allow your users to spend loyalty points for shopping. Users can click on it to open RedeemPointPopup - which shows their loyalty account balance, and choose a number of points to use.

Usage#

Prerequiresite#

To use loyalty-component, the main app needs to use androidx component for its fragment/activity:


Add LoyaltyRedeemPointView to your layout#

<vn.teko.loyalty.component.ui.redeempoint.view.LoyaltyRedeemPointView
android:id="@+id/loyaltyRedeemPointView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="44dp"
app:layout_constraintBottom_toBottomOf="parent" />

Setting up the controller in activity/fragment#

There is a note when we use the LoyaltyRedeemPointView. When we add that view to our screen, it will fetch data of member automatically. This process can cause some errors like network connect... In these cases, that view will notify error to the client via callback. The client can show dialog or something for these errors and try to reload LoyaltyRedeemPointView by reload method.

class OurFancyActivity : AppCompatActivity() {
private lateinit var loyaltyRedeemPointViewController: LoyaltyRedeemPointViewController
private val onRedeemPointCallback by lazy {
object : OnRedeemPointCallback {
override fun onRedeemPointChange(data: RedeemPointData?) {
if (data == null) {
// User has not been used points yet
} else {
val points = data.points
}
}
override fun onReady() {
// The component has been ready to use
// In some cases, you will want to hide the component until it is ready
}
override fun onError(error: Throwable) {
// handle the given error
// ...
// Sample error handling: show an alert with retry button
AlertDialog.Builder(this@OurFancyActivity)
.setMessage("Error occurred when initializing RedeemPointView")
.setPositiveButton("Retry") { _, _ ->
// reload `loyaltyRedeemPointViewController` when user clicks retry
loyaltyRedeemPointViewController.reload()
}
.show()
}
}
}
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(/**....*/)
val loyaltyRedeemPointView =
findViewById<LoyaltyRedeemPointView>(R.id.loyaltyRedeemPointView)
loyaltyRedeemPointViewController =
LoyaltyRedeemPointViewController(
activity = this,
orderAmount = 10000L,
terraApp = TerraApp.getInstance(appName),
callback = onRedeemPointCallback
)
loyaltyRedeemPointViewController.enable()
loyaltyRedeemPointViewController.setRedeemPointView(loyaltyRedeemPointView)
}
}
class OurFancyFragment : Fragment() {
private lateinit var loyaltyRedeemPointViewController: LoyaltyRedeemPointViewController
private val onRedeemPointCallback by lazy {
// create new OnRedeemPointCallback instance like something we have done in `OurFancyActivity`
}
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)
val loyaltyRedeemPointView =
findViewById<LoyaltyRedeemPointView>(R.id.loyaltyRedeemPointView)
loyaltyRedeemPointViewController =
LoyaltyRedeemPointViewController(
fragment = this,
orderAmount = 10000L,
terraApp = TerraApp.getInstance(appName),
callback = onRedeemPointCallback
)
loyaltyRedeemPointViewController.enable()
loyaltyRedeemPointViewController.setRedeemPointView(loyaltyRedeemPointView)
}
}