RedeemPointByStaffView

TerraCore v0

Introduction#

Use this built-in view to allow your customers to spend loyalty points for shopping at stores/showrooms. The staff can click on it to open Scan QR screen and scan loyalty code of the customer.

Installation#

Using Gradle

Add loyalty-component to your project's build.gradle.kts

implement("vn.teko.loyalty:loyalty-component:$version")

Usage#

Prerequiresite#

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


Add LoyaltyRedeemPointByStaffView to your layout#

<vn.teko.loyalty.component.ui.staff.redeempoint.view.LoyaltyRedeemPointByStaffView
android:id="@+id/loyaltyRedeemPointByStaffView"
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 LoyaltyRedeemPointByStaffView. When we add that view to our screen, it will fetch data of your loyalty network 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 LoyaltyRedeemPointByStaffView by reload method.

class OurFancyActivity : AppCompatActivity() {
private lateinit var redeemPointViewController: LoyaltyRedeemPointByStaffViewController
private val onRedeemPointCallback by lazy {
object : OnRedeemPointByStaffCallback {
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 `redeemPointViewController` when user clicks retry
redeemPointViewController.reload()
}
.show()
}
}
}
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(/**....*/)
val loyaltyRedeemPointView =
findViewById<LoyaltyRedeemPointByStaffView>(R.id.loyaltyRedeemPointByStaffView)
redeemPointViewController =
LoyaltyRedeemPointByStaffViewController(
activity = this,
orderAmount = 10_000L,
terraApp = TerraApp.getInstance(),
callback = onRedeemPointCallback
)
redeemPointViewController.enable()
redeemPointViewController.setRedeemPointView(loyaltyRedeemPointView)
}
}
class OurFancyFragment : Fragment() {
private lateinit var redeemPointViewController: LoyaltyRedeemPointByStaffViewController
private val onRedeemPointCallback by lazy {
// create new OnRedeemPointByStaffCallback instance like something we have done in `OurFancyActivity`
}
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)
val loyaltyRedeemPointView =
findViewById<LoyaltyRedeemPointByStaffView>(R.id.loyaltyRedeemPointByStaffView)
loyaltyRedeemPointViewController =
LoyaltyRedeemPointByStaffViewController(
fragment = this,
orderAmount = 10_000L,
terraApp = TerraApp.getInstance(),
callback = onRedeemPointCallback
)
redeemPointViewController.enable()
redeemPointViewController.setRedeemPointView(loyaltyRedeemPointView)
}
}